From 2cbb09b472209d15a0004bfc5d462568f626f786 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Thu, 8 Feb 2024 01:52:42 -0300 Subject: [PATCH 01/23] feat(Installation script): Simple bash script installation Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 install.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..177d8a4 --- /dev/null +++ b/install.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +INSTALLATION_DIRECTORY="/usr/local/share/pwnagotchi/custom-plugins" +CONFIG_FILE="/etc/pwnagotchi/config.toml" + +function user_sleep() { + sleep 0.5 +} + +function check_toml_key_exists() { + local key="$1" + local config_file="$2" + + if grep -q "^${key}" "$config_file"; then + echo "The '$key' already exists on $config_file." + else + echo "Creating '$key' on $config_file." + echo "${key} = \"test\" " >>"$config_file" + fi +} + +function edit_configuration_values() { + local key="$1" + local value="$2" + local config_file="$3" + + # Escape slashes and dots in the value to avoid issues with sed + value=$(echo "$value" | sed 's/\//\\\//g') + value=$(echo "$value" | sed 's/\./\\\./g') + # Use sed to insert or replace the configuration value + sed -i "/^${key}/c ${key} = \"${value}\"" "$config_file" +} + +function modify_config_files() { + # TODO If you know a simple method to write on toml files, please submit a change + check_toml_key_exists "main.plugins.display-password.enabled" "$CONFIG_FILE" + check_toml_key_exists "main.plugins.display-password.orientation" "$CONFIG_FILE" + + # Set the configuration values + edit_configuration_values "main.plugins.display-password.enabled" "$CONFIG_FILE" + edit_configuration_values "main.plugins.display-password.orientation" "$CONFIG_FILE" +} + +# Main + +echo "[ ~ ] We may need sudo permissions..." +sleep 0.5 +echo "[ + ] Creating symbolic link to ${INSTALLATION_DIRECTORY}" +sudo ln -sf "$(pwd)/display-password.py" "${INSTALLATION_DIRECTORY}/display-password.py" +echo "[ + ] Backing up configuration files..." +sudo cp "${CONFIG_FILE}" "${CONFIG_FILE}.bak" +echo "[ ~ ] Modifying configuration files..." +modify_config_files +echo "[ * ] Done! Please restart your pwnagotchi daemon to apply changes" +echo "[ * ] You can do so with" +echo "[ > ] sudo systemctl restart pwnagotchi" From 2e58c3a896cf40a45e4990835eb363ffcf4cfe91 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Thu, 8 Feb 2024 01:54:01 -0300 Subject: [PATCH 02/23] refactor(Formatting): Just simple formatting Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- display-password.py | 55 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/display-password.py b/display-password.py index fbc6aac..72f74ad 100644 --- a/display-password.py +++ b/display-password.py @@ -1,26 +1,16 @@ -# display-password shows recently cracked passwords on the pwnagotchi display -# -# -############################################################### -# -# Inspired by, and code shamelessly yoinked from -# the pwnagotchi memtemp.py plugin by https://github.com/xenDE -# -############################################################### from pwnagotchi.ui.components import LabeledValue from pwnagotchi.ui.view import BLACK import pwnagotchi.ui.fonts as fonts import pwnagotchi.plugins as plugins -import pwnagotchi import logging import os class DisplayPassword(plugins.Plugin): - __author__ = '@nagy_craig' - __version__ = '1.0.0' - __license__ = 'GPL3' - __description__ = 'A plugin to display recently cracked passwords' + __author__ = "@nagy_craig" + __version__ = "1.0.0" + __license__ = "GPL3" + __description__ = "A plugin to display recently cracked passwords" def on_loaded(self): logging.info("display-password loaded") @@ -45,21 +35,36 @@ def on_ui_setup(self, ui): h_pos = (0, 91) v_pos = (180, 61) - if self.options['orientation'] == "vertical": - ui.add_element('display-password', LabeledValue(color=BLACK, label='', value='', - position=v_pos, - label_font=fonts.Bold, text_font=fonts.Small)) + if self.options["orientation"] == "vertical": + ui.add_element( + "display-password", + LabeledValue( + color=BLACK, + label="", + value="", + position=v_pos, + label_font=fonts.Bold, + text_font=fonts.Small, + ), + ) else: # default to horizontal - ui.add_element('display-password', LabeledValue(color=BLACK, label='', value='', - position=h_pos, - label_font=fonts.Bold, text_font=fonts.Small)) + ui.add_element( + "display-password", + LabeledValue( + color=BLACK, + label="", + value="", + position=h_pos, + label_font=fonts.Bold, + text_font=fonts.Small, + ), + ) def on_unload(self, ui): with ui._lock: - ui.remove_element('display-password') + ui.remove_element("display-password") def on_ui_update(self, ui): - last_line = 'tail -n 1 /root/handshakes/wpa-sec.cracked.potfile | awk -F: \'{print $3 " - " $4}\'' - ui.set('display-password', - "%s" % (os.popen(last_line).read().rstrip())) + last_line = "tail -n 1 /root/handshakes/wpa-sec.cracked.potfile | awk -F: '{print $3 \" - \" $4}'" + ui.set("display-password", "%s" % (os.popen(last_line).read().rstrip())) From 0cbac58dab313787dd403471852073667bed6cd6 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Thu, 8 Feb 2024 02:04:08 -0300 Subject: [PATCH 03/23] feat(*potfile): All potfiles are welcome! Also add support for the Waveshare 1.54 inch V2 Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- display-password.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/display-password.py b/display-password.py index 72f74ad..56f3886 100644 --- a/display-password.py +++ b/display-password.py @@ -2,6 +2,7 @@ from pwnagotchi.ui.view import BLACK import pwnagotchi.ui.fonts as fonts import pwnagotchi.plugins as plugins +from time import sleep import logging import os @@ -31,6 +32,9 @@ def on_ui_setup(self, ui): elif ui.is_waveshare27inch(): h_pos = (0, 153) v_pos = (216, 122) + elif ui.is_waveshare1in54V2(): + h_pos = (0, 92) + v_pos = (78, 67) else: h_pos = (0, 91) v_pos = (180, 61) @@ -66,5 +70,9 @@ def on_unload(self, ui): ui.remove_element("display-password") def on_ui_update(self, ui): - last_line = "tail -n 1 /root/handshakes/wpa-sec.cracked.potfile | awk -F: '{print $3 \" - \" $4}'" - ui.set("display-password", "%s" % (os.popen(last_line).read().rstrip())) + for file in os.listdir('/root/handshakes'): + if file.endswith(".potfile"): + with open('/root/handshakes/*.potfile', 'r') as file: + lines = file.readlines() + last_line = lines[-1].split(":")[2:] + ui.set("display-password", f"{last_line}") From e2cca6e35718cd0c5d15e6d99d2da53cf471a126 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:01:54 -0300 Subject: [PATCH 04/23] refactor(Try, except, logs, position): Added logs, and some try except blocks for traceability Also change a little the position for the 1.54inch display Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- display-password.py | 121 ++++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 55 deletions(-) diff --git a/display-password.py b/display-password.py index 56f3886..ce282de 100644 --- a/display-password.py +++ b/display-password.py @@ -2,7 +2,6 @@ from pwnagotchi.ui.view import BLACK import pwnagotchi.ui.fonts as fonts import pwnagotchi.plugins as plugins -from time import sleep import logging import os @@ -17,62 +16,74 @@ def on_loaded(self): logging.info("display-password loaded") def on_ui_setup(self, ui): - if ui.is_waveshare_v2(): - h_pos = (0, 95) - v_pos = (180, 61) - elif ui.is_waveshare_v1(): - h_pos = (0, 95) - v_pos = (170, 61) - elif ui.is_waveshare144lcd(): - h_pos = (0, 92) - v_pos = (78, 67) - elif ui.is_inky(): - h_pos = (0, 83) - v_pos = (165, 54) - elif ui.is_waveshare27inch(): - h_pos = (0, 153) - v_pos = (216, 122) - elif ui.is_waveshare1in54V2(): - h_pos = (0, 92) - v_pos = (78, 67) - else: - h_pos = (0, 91) - v_pos = (180, 61) + try: + if ui.is_waveshare_v2(): + h_pos = (0, 95) + v_pos = (180, 61) + elif ui.is_waveshare_v1(): + h_pos = (0, 95) + v_pos = (170, 61) + elif ui.is_waveshare144lcd(): + h_pos = (0, 92) + v_pos = (78, 67) + elif ui.is_inky(): + h_pos = (0, 83) + v_pos = (165, 54) + elif ui.is_waveshare2in7(): + h_pos = (0, 153) + v_pos = (216, 122) + elif ui.is_waveshare1in54V2(): + h_pos = (0, 92) + v_pos = (70, 170) + else: + h_pos = (0, 91) + v_pos = (180, 61) - if self.options["orientation"] == "vertical": - ui.add_element( - "display-password", - LabeledValue( - color=BLACK, - label="", - value="", - position=v_pos, - label_font=fonts.Bold, - text_font=fonts.Small, - ), - ) - else: - # default to horizontal - ui.add_element( - "display-password", - LabeledValue( - color=BLACK, - label="", - value="", - position=h_pos, - label_font=fonts.Bold, - text_font=fonts.Small, - ), - ) + if self.options["orientation"] == "vertical": + ui.add_element( + "display-password", + LabeledValue( + color=BLACK, + label="", + value="", + position=v_pos, + label_font=fonts.Bold, + text_font=fonts.Small, + ), + ) + else: + # default to horizontal + ui.add_element( + "display-password", + LabeledValue( + color=BLACK, + label="", + value="", + position=h_pos, + label_font=fonts.Bold, + text_font=fonts.Small, + ), + ) + except Exception as e: + logging.error(f"[DISPLAY-PASSWORD] {e}") def on_unload(self, ui): - with ui._lock: - ui.remove_element("display-password") + try: + with ui._lock: + ui.remove_element("display-password") + except Exception as e: + logging.error(f"[DISPLAY-PASSWORD] {e}") def on_ui_update(self, ui): - for file in os.listdir('/root/handshakes'): - if file.endswith(".potfile"): - with open('/root/handshakes/*.potfile', 'r') as file: - lines = file.readlines() - last_line = lines[-1].split(":")[2:] - ui.set("display-password", f"{last_line}") + logging.debug("[DISPLAY-PASSWORD] Actualizando UI") + try: + for file in os.listdir("/root/handshakes"): + if file.endswith(".potfile"): + with open(f'/root/handshakes/{file}', 'r') as file: + lines = file.readlines() + if len(lines) > 0: + last_line = lines[-1].split(":")[2:] + last_line = ":".join(last_line) + ui.set("display-password", f"{last_line}") + except Exception as e: + logging.error(f"[DISPLAY-PASSWORD] {e}") From 872097ed97070344a0d972ef89f21f0173899a06 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:03:51 -0300 Subject: [PATCH 05/23] refactor(repeated code): refactor some repeteated code Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- display-password.py | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/display-password.py b/display-password.py index ce282de..9aeaf8b 100644 --- a/display-password.py +++ b/display-password.py @@ -40,30 +40,20 @@ def on_ui_setup(self, ui): v_pos = (180, 61) if self.options["orientation"] == "vertical": - ui.add_element( - "display-password", - LabeledValue( - color=BLACK, - label="", - value="", - position=v_pos, - label_font=fonts.Bold, - text_font=fonts.Small, - ), - ) + selected_position = v_pos else: - # default to horizontal - ui.add_element( - "display-password", - LabeledValue( - color=BLACK, - label="", - value="", - position=h_pos, - label_font=fonts.Bold, - text_font=fonts.Small, - ), - ) + selected_position = h_pos + ui.add_element( + "display-password", + LabeledValue( + color=BLACK, + label="", + value="", + position=selected_position, + label_font=fonts.Bold, + text_font=fonts.Small, + ), + ) except Exception as e: logging.error(f"[DISPLAY-PASSWORD] {e}") From bc3617fe3d06b665f3851e2bc3356e463f9218b5 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:06:09 -0300 Subject: [PATCH 06/23] fix(Root installation): Installation script needs to be runned as root Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 177d8a4..707c72a 100755 --- a/install.sh +++ b/install.sh @@ -15,7 +15,7 @@ function check_toml_key_exists() { echo "The '$key' already exists on $config_file." else echo "Creating '$key' on $config_file." - echo "${key} = \"test\" " >>"$config_file" + echo "${key} = true " >>"$config_file" fi } @@ -43,12 +43,16 @@ function modify_config_files() { # Main -echo "[ ~ ] We may need sudo permissions..." -sleep 0.5 +# Check that the script is running as root + +if [ "$EUID" -ne 0 ]; then + echo "[ ! ] This script need to be run as root" + exit 0 +fi echo "[ + ] Creating symbolic link to ${INSTALLATION_DIRECTORY}" -sudo ln -sf "$(pwd)/display-password.py" "${INSTALLATION_DIRECTORY}/display-password.py" +ln -sf "$(pwd)/display-password.py" "${INSTALLATION_DIRECTORY}/display-password.py" echo "[ + ] Backing up configuration files..." -sudo cp "${CONFIG_FILE}" "${CONFIG_FILE}.bak" +cp "${CONFIG_FILE}" "${CONFIG_FILE}.bak" echo "[ ~ ] Modifying configuration files..." modify_config_files echo "[ * ] Done! Please restart your pwnagotchi daemon to apply changes" From 74584f8787fb7ea9ee69118bd81675ab13a6b4c7 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:11:13 -0300 Subject: [PATCH 07/23] fix(installation script): Values on toml Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 707c72a..f2152be 100755 --- a/install.sh +++ b/install.sh @@ -37,8 +37,8 @@ function modify_config_files() { check_toml_key_exists "main.plugins.display-password.orientation" "$CONFIG_FILE" # Set the configuration values - edit_configuration_values "main.plugins.display-password.enabled" "$CONFIG_FILE" - edit_configuration_values "main.plugins.display-password.orientation" "$CONFIG_FILE" + edit_configuration_values "main.plugins.display-password.enabled" true "$CONFIG_FILE" + edit_configuration_values "main.plugins.display-password.orientation" "horizontal" "$CONFIG_FILE" } # Main From 0269854da37d4702bf97c169e6e0edd70bc088be Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:14:29 -0300 Subject: [PATCH 08/23] fix(installation script): If the value is true, its not a string Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index f2152be..706672d 100755 --- a/install.sh +++ b/install.sh @@ -27,8 +27,14 @@ function edit_configuration_values() { # Escape slashes and dots in the value to avoid issues with sed value=$(echo "$value" | sed 's/\//\\\//g') value=$(echo "$value" | sed 's/\./\\\./g') - # Use sed to insert or replace the configuration value - sed -i "/^${key}/c ${key} = \"${value}\"" "$config_file" + # If the value is true, replace it with the lowercase version and without quotes + if [ "$value" = "true" ]; then + sed -i "s/^${key} = .*/${key} = ${value}/" "$config_file" + else + # Use sed to insert or replace the configuration value + sed -i "/^${key}/c ${key} = \"${value}\"" "$config_file" + fi + } function modify_config_files() { From 20d53fe46453dc3af2324d987146b20a486640e5 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:19:34 -0300 Subject: [PATCH 09/23] feat(installation script): Added choose between vertical and horizontal Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 706672d..2ae4a10 100755 --- a/install.sh +++ b/install.sh @@ -38,13 +38,14 @@ function edit_configuration_values() { } function modify_config_files() { + orientation="$1" # TODO If you know a simple method to write on toml files, please submit a change check_toml_key_exists "main.plugins.display-password.enabled" "$CONFIG_FILE" check_toml_key_exists "main.plugins.display-password.orientation" "$CONFIG_FILE" # Set the configuration values edit_configuration_values "main.plugins.display-password.enabled" true "$CONFIG_FILE" - edit_configuration_values "main.plugins.display-password.orientation" "horizontal" "$CONFIG_FILE" + edit_configuration_values "main.plugins.display-password.orientation" "$orientation" "$CONFIG_FILE" } # Main @@ -59,8 +60,14 @@ echo "[ + ] Creating symbolic link to ${INSTALLATION_DIRECTORY}" ln -sf "$(pwd)/display-password.py" "${INSTALLATION_DIRECTORY}/display-password.py" echo "[ + ] Backing up configuration files..." cp "${CONFIG_FILE}" "${CONFIG_FILE}.bak" +read -r -p "Do you want the horizontal or vertical orientation? [H/v] " orientation +if [ "$orientation" = "v" ]; then + orientation="vertical" +else + orientation="horizontal" +fi echo "[ ~ ] Modifying configuration files..." -modify_config_files +modify_config_files orientation echo "[ * ] Done! Please restart your pwnagotchi daemon to apply changes" echo "[ * ] You can do so with" echo "[ > ] sudo systemctl restart pwnagotchi" From 7154fb6070f4ebe82ea7480fbd9d2b2de4247725 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:24:17 -0300 Subject: [PATCH 10/23] fix(installation script): Any case selection Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 2ae4a10..56190bc 100755 --- a/install.sh +++ b/install.sh @@ -61,13 +61,13 @@ ln -sf "$(pwd)/display-password.py" "${INSTALLATION_DIRECTORY}/display-password. echo "[ + ] Backing up configuration files..." cp "${CONFIG_FILE}" "${CONFIG_FILE}.bak" read -r -p "Do you want the horizontal or vertical orientation? [H/v] " orientation -if [ "$orientation" = "v" ]; then +if [ "${orientation^^}" = "V" ]; then orientation="vertical" else orientation="horizontal" fi echo "[ ~ ] Modifying configuration files..." -modify_config_files orientation +modify_config_files $orientation echo "[ * ] Done! Please restart your pwnagotchi daemon to apply changes" echo "[ * ] You can do so with" echo "[ > ] sudo systemctl restart pwnagotchi" From 12ee34a08b8fca4488d1b197e18baddc362a23f3 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:41:59 -0300 Subject: [PATCH 11/23] feat(installation script): configurable custom plugins directory Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 56190bc..e1a3be1 100755 --- a/install.sh +++ b/install.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -INSTALLATION_DIRECTORY="/usr/local/share/pwnagotchi/custom-plugins" CONFIG_FILE="/etc/pwnagotchi/config.toml" function user_sleep() { @@ -56,8 +55,18 @@ if [ "$EUID" -ne 0 ]; then echo "[ ! ] This script need to be run as root" exit 0 fi -echo "[ + ] Creating symbolic link to ${INSTALLATION_DIRECTORY}" -ln -sf "$(pwd)/display-password.py" "${INSTALLATION_DIRECTORY}/display-password.py" + +installation_dir=$(awk '/^main.custom_plugins = / {print $3}' "$CONFIG_FILE") +if [ -z "$installation_dir" ]; then + echo "[ ! ] The installation directory was not found in the configuration file" + read -r -p "Please enter the installation directory: [/usr/local/share/custom_plugins]" installation_dir +fi +if [ -z "$installation_dir" ]; then + installation_dir="/usr/local/share/custom_plugins" +fi +echo "[ + ] Creating symbolic link to ${installation_dir}" +ln -sf "$(pwd)/display-password.py" "${installation_dir}/display-password.py" + echo "[ + ] Backing up configuration files..." cp "${CONFIG_FILE}" "${CONFIG_FILE}.bak" read -r -p "Do you want the horizontal or vertical orientation? [H/v] " orientation From 6e25baf3ffeca6c8032f87629cbd108c7f22cc14 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:43:32 -0300 Subject: [PATCH 12/23] fix(installation script): Changed default installation path Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index e1a3be1..da61193 100755 --- a/install.sh +++ b/install.sh @@ -59,10 +59,10 @@ fi installation_dir=$(awk '/^main.custom_plugins = / {print $3}' "$CONFIG_FILE") if [ -z "$installation_dir" ]; then echo "[ ! ] The installation directory was not found in the configuration file" - read -r -p "Please enter the installation directory: [/usr/local/share/custom_plugins]" installation_dir + read -r -p "Please enter the installation directory: [/usr/local/share/pwnagotchi/custom_plugins]" installation_dir fi if [ -z "$installation_dir" ]; then - installation_dir="/usr/local/share/custom_plugins" + installation_dir="/usr/local/share/pwnagotchi/custom_plugins" fi echo "[ + ] Creating symbolic link to ${installation_dir}" ln -sf "$(pwd)/display-password.py" "${installation_dir}/display-password.py" From 57205d391a91e0c0fc4d2d52ac1544e07c7a66e2 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:46:29 -0300 Subject: [PATCH 13/23] fix(installation script): Remove double quotes from path Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index da61193..2926942 100755 --- a/install.sh +++ b/install.sh @@ -64,6 +64,7 @@ fi if [ -z "$installation_dir" ]; then installation_dir="/usr/local/share/pwnagotchi/custom_plugins" fi +installation_dir=${installation_dir//\"/} echo "[ + ] Creating symbolic link to ${installation_dir}" ln -sf "$(pwd)/display-password.py" "${installation_dir}/display-password.py" From 863d557b1dfa1fb5b50acc23183bee1fdce1376e Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:51:45 -0300 Subject: [PATCH 14/23] fix(installation script): Always remove double quotes from installation path Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 2926942..993129c 100755 --- a/install.sh +++ b/install.sh @@ -57,11 +57,11 @@ if [ "$EUID" -ne 0 ]; then fi installation_dir=$(awk '/^main.custom_plugins = / {print $3}' "$CONFIG_FILE") -if [ -z "$installation_dir" ]; then +if [ -z "${installation_dir//\"}" ]; then echo "[ ! ] The installation directory was not found in the configuration file" read -r -p "Please enter the installation directory: [/usr/local/share/pwnagotchi/custom_plugins]" installation_dir fi -if [ -z "$installation_dir" ]; then +if [ -z "${installation_dir//\"}" ]; then installation_dir="/usr/local/share/pwnagotchi/custom_plugins" fi installation_dir=${installation_dir//\"/} From 7145217d5d1ad2399fbdc1928be41ef9e309fb66 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:53:21 -0300 Subject: [PATCH 15/23] fix(installation script): Default path is with - not _ Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 993129c..a914e31 100755 --- a/install.sh +++ b/install.sh @@ -59,10 +59,10 @@ fi installation_dir=$(awk '/^main.custom_plugins = / {print $3}' "$CONFIG_FILE") if [ -z "${installation_dir//\"}" ]; then echo "[ ! ] The installation directory was not found in the configuration file" - read -r -p "Please enter the installation directory: [/usr/local/share/pwnagotchi/custom_plugins]" installation_dir + read -r -p "Please enter the installation directory: [/usr/local/share/pwnagotchi/custom-plugins]" installation_dir fi if [ -z "${installation_dir//\"}" ]; then - installation_dir="/usr/local/share/pwnagotchi/custom_plugins" + installation_dir="/usr/local/share/pwnagotchi/custom-plugins" fi installation_dir=${installation_dir//\"/} echo "[ + ] Creating symbolic link to ${installation_dir}" From a52b1540904aaf0ab8fd8110d523dbe948fbe8be Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 22:03:13 -0300 Subject: [PATCH 16/23] feat(installation script): Add the value, key of custom plugins on config.toml if not exists Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index a914e31..8136440 100755 --- a/install.sh +++ b/install.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash +set -e + CONFIG_FILE="/etc/pwnagotchi/config.toml" +CONFIG_FILE="config.toml" function user_sleep() { sleep 0.5 @@ -11,9 +14,9 @@ function check_toml_key_exists() { local config_file="$2" if grep -q "^${key}" "$config_file"; then - echo "The '$key' already exists on $config_file." + echo "[ + ] The '$key' already exists on $config_file." else - echo "Creating '$key' on $config_file." + echo "[ ~ ] Creating '$key' on $config_file." echo "${key} = true " >>"$config_file" fi } @@ -47,6 +50,20 @@ function modify_config_files() { edit_configuration_values "main.plugins.display-password.orientation" "$orientation" "$CONFIG_FILE" } +function get_installation_path() { + check_toml_key_exists "main.custom_plugins" "$CONFIG_FILE" + installation_dir=$(awk '/^main.custom_plugins = / {print $3}' "$CONFIG_FILE") + if [ -z "${installation_dir//\"/}" ] || [ "$installation_dir" = true ]; then + echo "[ ! ] The installation directory was not found in the configuration file" + read -r -p "Please enter the installation directory, press Enter to set '/usr/local/share/pwnagotchi/custom-plugins' or specify yours with absolute path: " installation_dir + fi + if [ -z "${installation_dir//\"/}" ]; then + installation_dir="/usr/local/share/pwnagotchi/custom-plugins" + fi + edit_configuration_values "main.custom_plugins" "${installation_dir}" "$CONFIG_FILE" + installation_dir="${installation_dir//\"/}" +} + # Main # Check that the script is running as root @@ -55,19 +72,10 @@ if [ "$EUID" -ne 0 ]; then echo "[ ! ] This script need to be run as root" exit 0 fi - -installation_dir=$(awk '/^main.custom_plugins = / {print $3}' "$CONFIG_FILE") -if [ -z "${installation_dir//\"}" ]; then - echo "[ ! ] The installation directory was not found in the configuration file" - read -r -p "Please enter the installation directory: [/usr/local/share/pwnagotchi/custom-plugins]" installation_dir -fi -if [ -z "${installation_dir//\"}" ]; then - installation_dir="/usr/local/share/pwnagotchi/custom-plugins" -fi -installation_dir=${installation_dir//\"/} +echo "[ + ] Getting installation path..." +get_installation_path echo "[ + ] Creating symbolic link to ${installation_dir}" ln -sf "$(pwd)/display-password.py" "${installation_dir}/display-password.py" - echo "[ + ] Backing up configuration files..." cp "${CONFIG_FILE}" "${CONFIG_FILE}.bak" read -r -p "Do you want the horizontal or vertical orientation? [H/v] " orientation From 38f91ef4f868302d3ecc57b69830e52ad8e8695b Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 22:07:21 -0300 Subject: [PATCH 17/23] fix(installation script): Forgot to delete test variable jeje Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/install.sh b/install.sh index 8136440..b134923 100755 --- a/install.sh +++ b/install.sh @@ -3,7 +3,6 @@ set -e CONFIG_FILE="/etc/pwnagotchi/config.toml" -CONFIG_FILE="config.toml" function user_sleep() { sleep 0.5 From b81693466a61df09f0e39ec855493587ad773d82 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Fri, 9 Feb 2024 22:13:55 -0300 Subject: [PATCH 18/23] feat(README): Added the automated installation script option. Also if you restart the daemon the changes will be applied Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- README.md | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 20f29e4..b9a5d38 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,43 @@ Displays the most recent cracked password on the Pwnagotchi display. It currentl # Installation +## Via installation script + +This script will execute the same steps as the manual installation. + +1. SSH into your Pwnagotchi and run the following command: +``` bash +git clone https://github.com/c-nagy/pwnagotchi-display-password-plugin +cd pwnagotchi-display-password-plugin +``` +2. Run the installation script as root: +``` bash +sudo ./install.sh + +``` +It will install the plugin to your configured `main.custom_plugins` variable on `/etc/pwnagotchi/config.toml`. If you don't have a `main.custom_plugins` variable, it will add it to the end of the file and then ask you to declare it + +3. Reboot the Pwnagotchi daemon to ensure all changes are applied, you can do so with the following command: +``` bash +sudo systemctl restart pwnagotchi +``` + +This also allow you to update the plugin by running ```git pull``` on the plugin repo directory. + +## Manual + 1. SSH into your Pwnagotchi and create a new folder for third-party Pwnagotchi plugins. I use `/root/custom_plugins/` but it doesn't really matter: `mkdir /root/custom_plugins/` -1. Grab the `display-password.py` and `display-password.toml` file from this Github repo and put it into that custom plugins directory. -1. Edit `/etc/pwnagotchi/config.toml` and change the `main.custom_plugins` variable to point to the custom plugins directory you just created: `main.custom_plugins = "/root/custom_plugins/"` -1. In the same `/etc/pwnagotchi/config.toml` file, add the following lines to enable the plugin: +2. Grab the `display-password.py` and `display-password.toml` file from this Github repo and put it into that custom plugins directory. +3. Edit `/etc/pwnagotchi/config.toml` and change the `main.custom_plugins` variable to point to the custom plugins directory you just created: `main.custom_plugins = "/root/custom_plugins/"` +4. In the same `/etc/pwnagotchi/config.toml` file, add the following lines to enable the plugin: ``` main.plugins.display-password.enabled = true main.plugins.display-password.orientation = "horizontal" ``` -Once the above steps are completed, reboot the Pwnagotchi to ensure all changes are applied. +Once the above steps are completed, reboot the Pwnagotchi daemon to ensure all changes are applied, you can do so with the following command: +``` bash +sudo systemctl restart pwnagotchi +``` # Screenshot: From 1852e40e2f108f71d3446b2b726296ee866c7341 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:00:46 -0300 Subject: [PATCH 19/23] feat(config): Configurable position Now the position can be configured via the config.toml file Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- display-password.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/display-password.py b/display-password.py index 9aeaf8b..ccbe34c 100644 --- a/display-password.py +++ b/display-password.py @@ -17,7 +17,10 @@ def on_loaded(self): def on_ui_setup(self, ui): try: - if ui.is_waveshare_v2(): + if self.options["position_x"] and self.options["position_y"]: + h_pos = (self.options["position_x"], self.options["position_y"]) + v_pos = (self.options["position_x"], self.options["position_y"]) + elif ui.is_waveshare_v2(): h_pos = (0, 95) v_pos = (180, 61) elif ui.is_waveshare_v1(): From 964f23c1ca045095d9b70f9be4e806825dab90a4 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:07:39 -0300 Subject: [PATCH 20/23] fix(position): Position configuration with str The configuration now needs to be configured with a string separated with commas Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- display-password.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/display-password.py b/display-password.py index ccbe34c..f155813 100644 --- a/display-password.py +++ b/display-password.py @@ -18,8 +18,8 @@ def on_loaded(self): def on_ui_setup(self, ui): try: if self.options["position_x"] and self.options["position_y"]: - h_pos = (self.options["position_x"], self.options["position_y"]) - v_pos = (self.options["position_x"], self.options["position_y"]) + h_pos = self.options["h_pos"].split(",") + v_pos = self.options["v_pos"].split(",") elif ui.is_waveshare_v2(): h_pos = (0, 95) v_pos = (180, 61) From f93ed3c78652bcfb5008b288654914af40d0889d Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:19:46 -0300 Subject: [PATCH 21/23] fix(position): Fix validation on position This error force the user to declare position_x and position_y when that variables are not used Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- display-password.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/display-password.py b/display-password.py index f155813..af733f4 100644 --- a/display-password.py +++ b/display-password.py @@ -17,9 +17,19 @@ def on_loaded(self): def on_ui_setup(self, ui): try: +<<<<<<< Updated upstream if self.options["position_x"] and self.options["position_y"]: h_pos = self.options["h_pos"].split(",") v_pos = self.options["v_pos"].split(",") +||||||| Stash base + if self.options["position_x"] and self.options["position_y"]: + h_pos = (self.options["position_x"], self.options["position_y"]) + v_pos = (self.options["position_x"], self.options["position_y"]) +======= + if self.options["h_pos"] or self.options["v_pos"]: + h_pos = self.options["h_pos"].split(",") + v_pos = self.options["v_pos"].split(",") +>>>>>>> Stashed changes elif ui.is_waveshare_v2(): h_pos = (0, 95) v_pos = (180, 61) From c633377ae28a78d8920ce461bd8a56ced06e9fc2 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:24:30 -0300 Subject: [PATCH 22/23] fix(position): Delete de git differences I really mess up the differences trying to make an amend :( Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- display-password.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/display-password.py b/display-password.py index af733f4..5f38219 100644 --- a/display-password.py +++ b/display-password.py @@ -17,19 +17,9 @@ def on_loaded(self): def on_ui_setup(self, ui): try: -<<<<<<< Updated upstream - if self.options["position_x"] and self.options["position_y"]: - h_pos = self.options["h_pos"].split(",") - v_pos = self.options["v_pos"].split(",") -||||||| Stash base - if self.options["position_x"] and self.options["position_y"]: - h_pos = (self.options["position_x"], self.options["position_y"]) - v_pos = (self.options["position_x"], self.options["position_y"]) -======= if self.options["h_pos"] or self.options["v_pos"]: h_pos = self.options["h_pos"].split(",") v_pos = self.options["v_pos"].split(",") ->>>>>>> Stashed changes elif ui.is_waveshare_v2(): h_pos = (0, 95) v_pos = (180, 61) From 682686b13bb35088669a73fe77dd42da8774ed25 Mon Sep 17 00:00:00 2001 From: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> Date: Tue, 27 Feb 2024 00:04:20 -0300 Subject: [PATCH 23/23] feat(Configurable Position): Add position on .toml After a lot of testing, I think this is the best way to add the position to the config.toml file Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com> --- display-password.py | 17 ++++++++++++----- display-password.toml | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/display-password.py b/display-password.py index 5f38219..f4e65ea 100644 --- a/display-password.py +++ b/display-password.py @@ -17,10 +17,7 @@ def on_loaded(self): def on_ui_setup(self, ui): try: - if self.options["h_pos"] or self.options["v_pos"]: - h_pos = self.options["h_pos"].split(",") - v_pos = self.options["v_pos"].split(",") - elif ui.is_waveshare_v2(): + if ui.is_waveshare_v2(): h_pos = (0, 95) v_pos = (180, 61) elif ui.is_waveshare_v1(): @@ -46,6 +43,16 @@ def on_ui_setup(self, ui): selected_position = v_pos else: selected_position = h_pos + + if self.options["position"]: + try: + position_values = str(self.options["position"]).split(",") + position_x = int(position_values[0]) + position_y = int(position_values[1]) + selected_position = (position_x, position_y) + except Exception as e: + logging.error(f"Error reading configuration: {e}") + ui.add_element( "display-password", LabeledValue( @@ -72,7 +79,7 @@ def on_ui_update(self, ui): try: for file in os.listdir("/root/handshakes"): if file.endswith(".potfile"): - with open(f'/root/handshakes/{file}', 'r') as file: + with open(f"/root/handshakes/{file}", "r") as file: lines = file.readlines() if len(lines) > 0: last_line = lines[-1].split(":")[2:] diff --git a/display-password.toml b/display-password.toml index 2fa8d81..76e1d72 100644 --- a/display-password.toml +++ b/display-password.toml @@ -1,2 +1,3 @@ main.plugins.display-password.enabled = true -main.plugins.display-password.orientation = "horizontal" \ No newline at end of file +main.plugins.display-password.orientation = "horizontal" +main.plugins.display-password.position = "30,160"