commit 05145b7b5a86210f1ae638dce5ddf642048061fd Author: Denny Cave Date: Sat Jan 21 22:11:01 2023 -0600 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/instant-login-successs.md b/instant-login-successs.md new file mode 100644 index 0000000..4938e9b --- /dev/null +++ b/instant-login-successs.md @@ -0,0 +1,3 @@ +[Click to login](${response.out}) + +*(Link will expire in 15 minutes)* \ No newline at end of file diff --git a/instant-login.yaml b/instant-login.yaml new file mode 100644 index 0000000..8ebfa9c --- /dev/null +++ b/instant-login.yaml @@ -0,0 +1,78 @@ +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/old-manifest.jps b/old-manifest.jps new file mode 100644 index 0000000..2e22ef8 --- /dev/null +++ b/old-manifest.jps @@ -0,0 +1,31 @@ +jpsType: update +jpsVersion: '1.7.2' +id: wp-instant-login +name: Instant Login +description: Login to your WordPress site as an administrator with a single click. +baseUrl: https://deploy.mightybox.site/instant-login/ + +targetNodes: + nodeGroup: cp + +onInstall: + cmd [nodes.cp[0]]: + - cd /var/www/webroot/ROOT + - touch newfile.txt + - wp package install aaemnnosttv/wp-cli-login-command + - wp login install --yes --activate + +actions: + instant_login: + cmd [cp]: + - cd /var/www/webroot/ROOT + - user=$(wp user list --fields=user_login --format=csv | sed -n '2 p') + - wp login create $user --url-only + return: + type: success + message: Yes! + +buttons: + - caption: Instant Login + loadingText: Generating login... + action: instant_login \ No newline at end of file diff --git a/old-wp-cli-login copy.yaml b/old-wp-cli-login copy.yaml new file mode 100644 index 0000000..bde862e --- /dev/null +++ b/old-wp-cli-login copy.yaml @@ -0,0 +1,100 @@ +type: update +name: One-Click Admin + +targetNodes: + nodeGroup: cp + +onInstall: + cmd [nodes.cp[0]]: + - cd /var/www/webroot/ROOT/wp-content + - mkdir mu-plugins -p + - cd mu-plugins + - wget https://raw.githubusercontent.com/aaemnnosttv/wp-cli-login-command/master/plugin/wp-cli-login-server.php + - cd /var/www/webroot/ROOT + - wp package install aaemnnosttv/wp-cli-login-command + + +actions: + instantlogin: + cmd [cp]: + - cd /var/www/webroot/ROOT + - wp user list --fields=user_login,user_email --format=json + choose_admin_login: + cmd [cp]: + - cd /var/www/webroot/ROOT + - wp user list --fields=user_login,user_email --format=json + +buttons: + - confirmText: Custom confirm text + loadingText: Load text while waiting + action: instantlogin + caption: Instant Login + successText: Configuration saved successfully! + - confirmText: Custom confirm text + loadingText: Load text while waiting + action: choose_admin_login + caption: Choose Admin + successText: Configuration saved successfully! + + +# onUninstall - remove mu-plugin + + +# to make a button open a prompt and choose the admin users use a settings page: +# settings: +# main: +# fields: +# - type: text +# caption: Main form +# config: +# fields: +# - type: text +# caption: Custom form from button action +# +# buttons: +# - settings: config +# action: customAction +# caption: Configure +# submitButtonText: Button Text +# logsPath: "/var/lib/jelastic/keys/111" + + + +# old style - copy directly to mu-plugins + +- cd /var/www/webroot/ROOT/wp-content +- mkdir mu-plugins -p +- cd mu-plugins +- wget https://raw.githubusercontent.com/aaemnnosttv/wp-cli-login-command/master/plugin/wp-cli-login-server.php + + + +# type: update +# name: Custom buttons +# +# targetNodes: +# nodeGroup: bl +# +# actions: +# - "..." +# +# buttons: +# - confirmText: Custom confirm text +# loadingText: Load text while waiting +# action: "{String}" +# caption: Configure +# successText: Configuration saved successfully! +# href: http://example.com/ +# +# type: install +# name: Addon installation +# +# onInstall: +# installAddon: +# id: wp-automatic-login +# +# addons: +# - id: wp-automatic-login +# name: Automatic WP Login +# onInstall: +# createFile [cp]: /var/log/test.log \ No newline at end of file diff --git a/scratchpad_input_admin.yaml b/scratchpad_input_admin.yaml new file mode 100644 index 0000000..9a25f46 --- /dev/null +++ b/scratchpad_input_admin.yaml @@ -0,0 +1,47 @@ +type: update +name: Load admins +description: Testing grounds for dynamically loading admins from the CP[0] node. + +targetNodes: + nodeGroup: cp + +settings: + configure: + fields: + - type: string + name: userToLoginAs + caption: User to login as + placeholder: Enter user ID, user email, or user login + default: 1 + +actions: + save_config: + #empty method to allow userToLoginAs to save + + # 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: + script: | + return {"result": "success", "message": "User saved!"} + + +buttons: + - caption: Configure + settings: configure + action: save_config + + +# can't seem to get the field to save unless it's input during admin + \ No newline at end of file diff --git a/scratchpad_load_admins.yaml b/scratchpad_load_admins.yaml new file mode 100644 index 0000000..144b41e --- /dev/null +++ b/scratchpad_load_admins.yaml @@ -0,0 +1,77 @@ +type: update +name: Load admins +description: Testing grounds for dynamically loading admins from the CP[0] node. + +targetNodes: + nodeGroup: cp + +globals: + admin_users: denny + +OnInstall: + settings: + userToLoginAs: ${settings.jelastic_email} + + +settings: + main: + fields: + - type: string + name: userToLoginAs + caption: User to login as + default: ${settings.userToLoginAs} + + +buttons: + - caption: Configure + settings: main + +# settings: +# main: +# fields: +# - type: list +# caption: List +# values: +# one: ${fn.password} +# required: true +# forceSelection: true + + + +------- +# returns user login without header +wp user list --field=user_login --format=csv + +can we save a value between addon loads/opens? +Yes - Lets encrypt does it. But how? It always shows the same value for me. + +can I just have plain text input field to type email, ID, username you want to login as? + +can I create a static placeholder with manually-defined values and even get that to load in "values" for listbox instead of a manaully-defined list inline? + + + +# how to populate list with values: + + onBeforeInit: | + var zones = toNative(java.time.ZoneId.getAvailableZoneIds()).sort(); + var serverTimeZone = toNative(java.time.ZoneId.systemDefault()); + var values = {}; + for (var i = 0, n = zones.length; i < n; i++) { + values[zones[i]] = zones[i]; + } + + return { + result: 0, + settings: { + fields: [{ + name: "timeZone", + caption: "TimeZone Name", + type: "list", + required: true, + editable: true, + "default": serverTimeZone, + values: values + }] + } + } \ No newline at end of file