From a9584b06d956f887c2e0f5b3f5d5d92a12154961 Mon Sep 17 00:00:00 2001 From: Denny Cave Date: Sat, 22 Jul 2023 00:07:49 -0500 Subject: [PATCH] Renaming manifest --- instant-login.yaml | 78 ---------------------------- manifest-auto-get-first-admin.jps | 43 ++++++++++++++++ manifest-configure-experiment.jps | 85 +++++++++++++++++++++++++++++++ manifest.jps | 50 ++++++++++++++++++ 4 files changed, 178 insertions(+), 78 deletions(-) delete mode 100644 instant-login.yaml create mode 100644 manifest-auto-get-first-admin.jps create mode 100644 manifest-configure-experiment.jps create mode 100644 manifest.jps diff --git a/instant-login.yaml b/instant-login.yaml deleted file mode 100644 index 8ebfa9c..0000000 --- a/instant-login.yaml +++ /dev/null @@ -1,78 +0,0 @@ -type: update -name: Instant Login -description: Login to your WordPress site as an administrator with a single click. - -targetNodes: - nodeGroup: cp - -onInstall: - cmd [cp]: - - cd /var/www/webroot/ROOT/ - - wp package install aaemnnosttv/wp-cli-login-command - - wp login install --yes --activate - - setGlobals: - userToLoginAs: 1 - -actions: - instant_login: - #log: ${placeholders} - - cmd [cp]: - - cd /var/www/webroot/ROOT/ - - wp login create ${globals.userToLoginAs} --url-only - #- user=$(wp user list --field=user_login --format=csv) - #- wp login create $user --url-only - return: - type: success - message: | - [Click to login](${response.out}) - *(Link will expire in 15 minutes)* - - save_config: - #empty method to allow userToLoginAs to save - #log: ${placeholders} - # lookup user that was entered - cmd [cp]: - - cd /var/www/webroot/ROOT/ - - user=$(wp user get ${settings.userToLoginAs} --field=ID) - # see if number (user ID) returned or not. Return 1 if yes. - - re='^[0-9]+$' - - if ! [[ $user =~ $re ]]; then echo 0; else echo 1; fi - - #check if the user was found - # returns ID if so - # returns 'Error: Invalid user ID, email or login: '24342'' - if (response.out == 0): - script: | - return {"result": "error", "message": "User not found. Try again."} - else: - - setGlobals: - userToLoginAs: ${settings.userToLoginAs} - - script: | - return {"result": "success", "message": "User saved!"} - - -settings: - configure: - fields: - - type: string - name: userToLoginAs - caption: User to login as - placeholder: Enter user ID, user email, or user login - -buttons: - - caption: Instant Login - loadingText: Generating login... - confirmText: Generate a login link for the configured user? This will log you out of any existing sessions. - action: instant_login - - caption: Configure - action: save_config - settings: configure - -# problem - only saves the user name/id/email on initial creation. Since adding custom code to save_config, it will not update with new user value after saving again - -# tried to use setGlobals but doesn't seem like that works any better - - -#SOLUTION: Combine these two options into one button - the button shows the input form, filled out with the username that was previously used. Then upon saving, it checks to see if that's a real user and if so it generates the login for that user. diff --git a/manifest-auto-get-first-admin.jps b/manifest-auto-get-first-admin.jps new file mode 100644 index 0000000..2be4635 --- /dev/null +++ b/manifest-auto-get-first-admin.jps @@ -0,0 +1,43 @@ +type: update +name: Instant Login +id: instant-login +description: Login to your WordPress site as an administrator with a single click. + +targetNodes: + nodeGroup: cp + +onInstall: + cmd[${nodes.cp.master.id}]: + - cd /var/www/webroot/ROOT/ + - wp package install aaemnnosttv/wp-cli-login-command + - mkdir -p /var/www/webroot/ROOT/wp-content/mu-plugins + - cd /var/www/webroot/ROOT/wp-content/mu-plugins + - wget https://raw.githubusercontent.com/aaemnnosttv/wp-cli-login-server/master/wp-cli-login-server.php + + setGlobals: + userToLoginAs: 1 + +onUninstall: + cmd[${nodes.cp.master.id}]: rm -f /var/www/webroot/ROOT/wp-content/mu-plugins/wp-cli-login-server.php + +actions: + + instant_login: + + cmd[${nodes.cp.master.id}]: + - cd /var/www/webroot/ROOT/ + #- user=$(wp user list --field=user_login --role=administrator --format=csv --number=1) + - user=$(wp user list --field=ID --role=administrator --format=csv --number=1 --orderby=ID) + - wp login create $user --url-only + + return: + type: success + message: | + [Click to login](${response.out}) + *(Link will expire in 15 minutes)* + +buttons: + - caption: Instant Login + loadingText: Generating login... + confirmText: Generate a login link for the first admin user? This will log you out of any existing sessions. + action: instant_login \ No newline at end of file diff --git a/manifest-configure-experiment.jps b/manifest-configure-experiment.jps new file mode 100644 index 0000000..dc1be6d --- /dev/null +++ b/manifest-configure-experiment.jps @@ -0,0 +1,85 @@ +type: update +name: Instant Login +description: Login to your WordPress site as an administrator with a single click. + +targetNodes: + nodeGroup: cp + +onInstall: + cmd[${nodes.cp.master.id}]: + - cd /var/www/webroot/ROOT/ + - wp package install aaemnnosttv/wp-cli-login-command + - mkdir -p /var/www/webroot/ROOT/wp-content/mu-plugins + - cd /var/www/webroot/ROOT/wp-content/mu-plugins + - wget https://raw.githubusercontent.com/aaemnnosttv/wp-cli-login-server/master/wp-cli-login-server.php + + setGlobals: + userToLoginAs: 1 + +onUninstall: + cmd[${nodes.cp.master.id}]: rm -f /var/www/webroot/ROOT/wp-content/mu-plugins/wp-cli-login-server.php + +actions: + + instant_login: + + cmd[${nodes.cp.master.id}]: + - cd /var/www/webroot/ROOT/ + - wp login create ${globals.userToLoginAs} --url-only + #- user=$(wp user list --field=user_login --format=csv) + #- wp login create $user --url-only + + return: + type: success + message: | + [Click to login as user ${globals.userToLoginAs}](${response.out}) + *(Link will expire in 15 minutes)* + + save_config: + cmd[${nodes.cp.master.id}]: + - cd /var/www/webroot/ROOT/ + - user=$(wp user get ${settings.userToLoginAs} --field=ID) + # see if number (user ID) returned or not. Return 1 if yes. + - re='^[0-9]+$' + - if ! [[ $user =~ $re ]]; then echo 0; else echo 1; fi + + #check if the user was found + # returns ID if so + # returns 'Error: Invalid user ID, email or login: '24342'' + if (response.out == 0): + return: + type: error + message: User '${settings.userToLoginAs}' not found. Try again. + else: + setGlobals: + userToLoginAs: ${settings.userToLoginAs} + return: + type: success + message: | + settings.userToLoginAs: ${settings.userToLoginAs} + globals.userToLoginAs: ${globals.userToLoginAs} + + +settings: + configure: + fields: + - type: string + name: userToLoginAs + caption: User to login as + placeholder: Enter user ID, user email, or user login + +buttons: + - caption: Instant Login + loadingText: Generating login... + confirmText: Generate a login link for the configured user? This will log you out of any existing sessions. + action: instant_login + - caption: Configure + action: save_config + settings: configure + +# problem - only saves the user name/id/email on initial creation. Since adding custom code to save_config, it will not update with new user value after saving again + +# tried to use setGlobals but doesn't seem like that works any better + + +#SOLUTION: Combine these two options into one button - the button shows the input form, filled out with the username that was previously used. Then upon saving, it checks to see if that's a real user and if so it generates the login for that user. diff --git a/manifest.jps b/manifest.jps new file mode 100644 index 0000000..e98f6e5 --- /dev/null +++ b/manifest.jps @@ -0,0 +1,50 @@ +type: update +name: Instant Login +id: instant-login +description: Login to your WordPress site as an administrator with a single click. + +targetNodes: + nodeGroup: cp + +onInstall: + cmd[${nodes.cp.master.id}]: + - cd /var/www/webroot/ROOT/ + - wp package install aaemnnosttv/wp-cli-login-command + - mkdir -p /var/www/webroot/ROOT/wp-content/mu-plugins + - cd /var/www/webroot/ROOT/wp-content/mu-plugins + - wget https://raw.githubusercontent.com/aaemnnosttv/wp-cli-login-server/master/wp-cli-login-server.php + + setGlobals: + userToLoginAs: 1 + +onUninstall: + cmd[${nodes.cp.master.id}]: rm -f /var/www/webroot/ROOT/wp-content/mu-plugins/wp-cli-login-server.php + +actions: + instant_login: + #log: ${placeholders} + + cmd[${nodes.cp.master.id}]: + - cd /var/www/webroot/ROOT/ + - wp login create ${globals.userToLoginAs} --url-only + #- user=$(wp user list --field=user_login --format=csv) + #- wp login create $user --url-only + return: + type: success + message: | + [Click to login as user ${globals.userToLoginAs}](${response.out}) + *(Link will expire in 15 minutes)* + +settings: + configure: + fields: + - type: string + name: userToLoginAs + caption: User to login as + placeholder: Enter user ID, user email, or user login + +buttons: + - caption: Instant Login + loadingText: Generating login... + confirmText: Generate a login link for the configured user? This will log you out of any existing sessions. + action: instant_login \ No newline at end of file