From bdb5f78670a54a10626e8f566d4a352ae1aed67b Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Wed, 11 Oct 2023 10:27:39 +0200 Subject: [PATCH 001/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- .../etc/systemd/system/pwnagotchi.service | 2 +- builder/data/etc/update-motd.d/01-motd | 4 +-- pwnagotchi/ai/__init__.py | 26 +++++++++---------- pwnagotchi/ai/gym.py | 8 +++--- pwnagotchi/plugins/cmd.py | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/builder/data/etc/systemd/system/pwnagotchi.service b/builder/data/etc/systemd/system/pwnagotchi.service index 5b7a153e..b48f7dfe 100644 --- a/builder/data/etc/systemd/system/pwnagotchi.service +++ b/builder/data/etc/systemd/system/pwnagotchi.service @@ -6,7 +6,7 @@ After=pwngrid-peer.service [Service] Type=simple -WorkingDirectory=/tmp +WorkingDirectory=~ ExecStart=/usr/bin/pwnagotchi-launcher Restart=always RestartSec=30 diff --git a/builder/data/etc/update-motd.d/01-motd b/builder/data/etc/update-motd.d/01-motd index 0f26121b..f549cd6d 100755 --- a/builder/data/etc/update-motd.d/01-motd +++ b/builder/data/etc/update-motd.d/01-motd @@ -23,9 +23,9 @@ echo " - sudo pwnagotchi --donate, to see how you can donate to this project" echo " - sudo pwnagotchi --check-update, to see if there is a new version available" echo echo " If you want to know if I'm running, you can use" -echo " systemctl status pwnagotchi" +echo " sudo systemctl status pwnagotchi" echo echo " You can restart me using" -echo " systemctl restart pwnagotchi" +echo " sudo systemctl restart pwnagotchi" echo echo " You learn more about me at https://pwnagotchi.ai/" \ No newline at end of file diff --git a/pwnagotchi/ai/__init__.py b/pwnagotchi/ai/__init__.py index 1c56d630..ba458651 100644 --- a/pwnagotchi/ai/__init__.py +++ b/pwnagotchi/ai/__init__.py @@ -3,7 +3,7 @@ import time import logging # https://stackoverflow.com/questions/40426502/is-there-a-way-to-suppress-the-messages-tensorflow-prints/40426709 -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # or any {'0', '1', '2'} +# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # or any {'0', '1', '2'} def load(config, agent, epoch, from_disk=True): @@ -15,47 +15,47 @@ def load(config, agent, epoch, from_disk=True): try: begin = time.time() - logging.info("[ai] bootstrapping dependencies ...") + logging.info("[AI] bootstrapping dependencies ...") start = time.time() SB_BACKEND = "stable_baselines3" from stable_baselines3 import A2C - logging.debug("[ai] A2C imported in %.2fs" % (time.time() - start)) + logging.debug("[AI] A2C imported in %.2fs" % (time.time() - start)) start = time.time() from stable_baselines3.a2c import MlpPolicy - logging.debug("[ai] MlpPolicy imported in %.2fs" % (time.time() - start)) + logging.debug("[AI] MlpPolicy imported in %.2fs" % (time.time() - start)) SB_A2C_POLICY = MlpPolicy start = time.time() from stable_baselines3.common.vec_env import DummyVecEnv - logging.debug("[ai] DummyVecEnv imported in %.2fs" % (time.time() - start)) + logging.debug("[AI] DummyVecEnv imported in %.2fs" % (time.time() - start)) start = time.time() import pwnagotchi.ai.gym as wrappers - logging.debug("[ai] gym wrapper imported in %.2fs" % (time.time() - start)) + logging.debug("[AI] gym wrapper imported in %.2fs" % (time.time() - start)) env = wrappers.Environment(agent, epoch) env = DummyVecEnv([lambda: env]) - logging.info("[ai] creating model ...") + logging.info("[AI] creating model ...") start = time.time() a2c = A2C(SB_A2C_POLICY, env, **config['params']) - logging.debug("[ai] A2C created in %.2fs" % (time.time() - start)) + logging.debug("[AI] A2C created in %.2fs" % (time.time() - start)) if from_disk and os.path.exists(config['path']): - logging.info("[ai] loading %s ..." % config['path']) + logging.info("[AI] loading %s ..." % config['path']) start = time.time() a2c.load(config['path'], env) - logging.debug("[ai] A2C loaded in %.2fs" % (time.time() - start)) + logging.debug("[AI] A2C loaded in %.2fs" % (time.time() - start)) else: - logging.info("[ai] model created:") + logging.info("[AI] model created:") for key, value in config['params'].items(): logging.info(" %s: %s" % (key, value)) - logging.debug("[ai] total loading time is %.2fs" % (time.time() - begin)) + logging.debug("[AI] total loading time is %.2fs" % (time.time() - begin)) return a2c except Exception as e: @@ -63,5 +63,5 @@ def load(config, agent, epoch, from_disk=True): logging.info("[AI] Deleting brain and restarting.") os.system("rm /root/brain.nn && service pwnagotchi restart") - logging.warning("[ai] AI not loaded!") + logging.warning("[AI] AI not loaded!") return False diff --git a/pwnagotchi/ai/gym.py b/pwnagotchi/ai/gym.py index 2af64f5f..6179e76e 100644 --- a/pwnagotchi/ai/gym.py +++ b/pwnagotchi/ai/gym.py @@ -138,13 +138,13 @@ class Environment(gym.Env): self._last_render = self._epoch_num - logging.info("[ai] --- training epoch %d/%d ---" % (self._epoch_num, self._agent.training_epochs())) - logging.info("[ai] REWARD: %f" % self.last['reward']) + logging.info("[AI] --- training epoch %d/%d ---" % (self._epoch_num, self._agent.training_epochs())) + logging.info("[AI] REWARD: %f" % self.last['reward']) logging.debug( - "[ai] policy: %s" % ', '.join("%s:%s" % (name, value) for name, value in self.last['params'].items())) + "[AI] policy: %s" % ', '.join("%s:%s" % (name, value) for name, value in self.last['params'].items())) - logging.info("[ai] observation:") + logging.info("[AI] observation:") for name, value in self.last['state'].items(): if 'histogram' in name: logging.info(" %s" % name.replace('_histogram', '')) diff --git a/pwnagotchi/plugins/cmd.py b/pwnagotchi/plugins/cmd.py index 6b159902..b0b9bf9e 100644 --- a/pwnagotchi/plugins/cmd.py +++ b/pwnagotchi/plugins/cmd.py @@ -271,7 +271,7 @@ def _get_installed(config): Get all installed plugins """ installed = dict() - search_dirs = [ default_path, config['main']['custom_plugins'] ] + search_dirs = [default_path, config['main']['custom_plugins']] for search_dir in search_dirs: if search_dir: for filename in glob.glob(os.path.join(search_dir, "*.py")): From ab9ea1743e311fc48549fde0f8ec9712d0c97b22 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Wed, 11 Oct 2023 10:29:39 +0200 Subject: [PATCH 002/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index decdc195..32e9a958 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,7 @@ dbus-python toml python-dateutil websockets -torch -torchvision +torch==2.0.1 +torchvision==0.15.2 stable_baselines3 RPi.GPIO From a151465c90e42d2ddebeaba84a13a0c9da8fcc0b Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 16:17:08 +0200 Subject: [PATCH 003/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 1 + pwnagotchi/google/cmd.py | 60 ++++++++ pwnagotchi/plugins/default/gdrivesync.py | 178 +++++++++++++++++++++++ pwnagotchi/plugins/default/webcfg.py | 7 +- 4 files changed, 243 insertions(+), 3 deletions(-) create mode 100644 pwnagotchi/google/cmd.py create mode 100644 pwnagotchi/plugins/default/gdrivesync.py diff --git a/bin/pwnagotchi b/bin/pwnagotchi index f3e3aad5..2dd34b3a 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -98,6 +98,7 @@ def do_auto_mode(agent): if __name__ == '__main__': parser = argparse.ArgumentParser() parser = plugins_cmd.add_parsers(parser) + parser = google_cmd.add_parsers(parser) parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', help='Main configuration file.') diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py new file mode 100644 index 00000000..0ddb6137 --- /dev/null +++ b/pwnagotchi/google/cmd.py @@ -0,0 +1,60 @@ +# Handles the commandline stuff + +import os +import logging +import glob +import re +import shutil +from fnmatch import fnmatch +from pwnagotchi.utils import download_file, unzip, save_config, parse_version, md5 +from pwnagotchi.plugins import default_path + + +def add_parsers(parser): + """ + Adds the plugins subcommand to a given argparse.ArgumentParser + """ + subparsers = parser.add_subparsers() + # pwnagotchi google + parser_plugins = subparsers.add_parser('google') + plugin_subparsers = parser_plugins.add_subparsers(dest='googlecmd') + + # pwnagotchi plugins search + parser_plugins_search = plugin_subparsers.add_parser('search', help='Search for pwnagotchi plugins') + parser_plugins_search.add_argument('pattern', type=str, help="Search expression (wildcards allowed)") + + return parser + + +def used_plugin_cmd(args): + """ + Checks if the plugins subcommand was used + """ + return hasattr(args, 'plugincmd') + + +def handle_cmd(args, config): + """ + Parses the arguments and does the thing the user wants + """ + if args.plugincmd == 'update': + return update(config) + elif args.plugincmd == 'search': + args.installed = True # also search in installed plugins + return list_plugins(args, config, args.pattern) + elif args.plugincmd == 'install': + return install(args, config) + elif args.plugincmd == 'uninstall': + return uninstall(args, config) + elif args.plugincmd == 'list': + return list_plugins(args, config) + elif args.plugincmd == 'enable': + return enable(args, config) + elif args.plugincmd == 'disable': + return disable(args, config) + elif args.plugincmd == 'upgrade': + return upgrade(args, config, args.pattern) + elif args.plugincmd == 'edit': + return edit(args, config) + + raise NotImplementedError() \ No newline at end of file diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py new file mode 100644 index 00000000..5b376fb6 --- /dev/null +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -0,0 +1,178 @@ +import logging +import os +import shutil +import time +import pwnagotchi.plugins as plugins +import pwnagotchi +import pydrive2 +from pydrive2.auth import GoogleAuth +from pydrive2.drive import GoogleDrive + + +class GdriveSync(plugins.Plugin): + __author__ = '@jayofelony' + __version__ = '1.0' + __license__ = 'GPL3' + __description__ = 'A plugin to backup various pwnagotchi files and folders to Google Drive. Once every hour from loading plugin.' + __dependencies__ = { + 'pip': ['pydrive2'] + } + + def __init__(self): + self.internet = False + self.ready = False + self.drive = None + self.last_upload_timestamp = time.time() + self.backup = True + self.backupfiles = [ + '/root/brain.nn', + '/root/brain.json', + '/root/.api-report.json', + '/root/handshakes', + '/root/peers', + '/etc/pwnagotchi' + ] + + # Function to get the folder ID by its name + def get_folder_id_by_name(self, drive, folder_name): + file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + for file in file_list: + if file['title'] == folder_name: + return file['id'] + return None + + def on_loaded(self): + # client_secrets.json needs to be in /root + if not os.path.exists("/root/client_secrets.json"): + logging.error("client_secrets.json not found in /root. Please RTFM!") + return + # backup file, so we know if there has been a backup made at least once before. + if not os.path.exists("/root/.gdrive-backup"): + self.backup = False + + try: + gauth = GoogleAuth() + + gauth.Authorize() + + # Create GoogleDrive instance + self.drive = GoogleDrive(gauth) + + # if backup file does not exist, we will check for PwnagotchiBackups on gdrive. + if not self.backup: + # Assume 'PwnagotchiBackups' is the folder ID where backups are stored + backup_folder_id = 'PwnagotchiBackups' + + # Get the list of files in the folder + file_list = self.drive.ListFile({'q': f"'{self.get_folder_id_by_name(self.drive, backup_folder_id)}" + f"' in parents and trashed=false"}).GetList() + if not file_list: + # Handle the case where no files were found + logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") + if self.config['backupfiles'] is not None: + self.backupfiles = self.backupfiles + self.config['backupfiles'] + self.backup_files(self.backupfiles, '/backup') + + self.upload_to_gdrive('/backup', 'PwnagotchiBackups') + self.backup = True + + # Specify the local backup path + local_backup_path = '/' + + # Create the local backup directory if it doesn't exist + os.makedirs(local_backup_path, exist_ok=True) + + # Download each file in the folder + for file in file_list: + local_file_path = os.path.join(local_backup_path, file['title']) + file.GetContentFile(local_file_path) + logging.info(f"[gDriveSync] Downloaded {file['title']} from Google Drive") + + # Optionally, you can use the downloaded files as needed + # For example, you can copy them to the corresponding directories + self.backup = True + with open("/root/.gdrive-backup", "w").close(): + pass # Create an empty file + pwnagotchi.reboot() + + # all set, gdriveSync is ready to run + self.ready = True + logging.info("[gdrivesync] loaded") + except Exception as e: + logging.error(f"Error: {e}") + self.ready = False + + def on_unload(self, ui): + logging.info("[gdrivesync] unloaded") + + def on_internet_available(self, agent): + self.internet = True + + def on_handshake(self, agent): + if not self.ready: + return + try: + if self.internet: + current_timestamp = time.time() + # Check if an hour has passed since the last upload + if current_timestamp - self.last_upload_timestamp >= 3600: + self.last_upload_timestamp = current_timestamp + logging.info("[gdrivesync] new handshake captured, backing up to gdrive") + if self.config['backupfiles'] is not None: + self.backupfiles = self.backupfiles + self.config['backupfiles'] + self.backup_files(self.backupfiles, '/backup') + + self.upload_to_gdrive('/backup', 'PwnagotchiBackups') + display = agent.view() + display.update(force=True, new_data={'Backing up to gdrive ...'}) + except Exception as e: + logging.error(f"Error during handshake processing: {e}") + + def backup_files(self, paths, dest_path): + for src_path in paths: + self.backup_path(src_path, dest_path) + + def backup_path(self, src_path, dest_path): + try: + if os.path.exists(src_path): + dest = os.path.join(dest_path, os.path.basename(src_path)) + if os.path.isdir(src_path): + shutil.copytree(src_path, dest) + else: + shutil.copy2(src_path, dest) + except Exception as e: + logging.error(f"Error during backup_path: {e}") + + def upload_to_gdrive(self, backup_path, gdrive_folder): + try: + existing_folder = self.get_folder_id_by_name(self.drive, gdrive_folder) + if existing_folder: + folder = self.drive.CreateFile({'id': existing_folder}) + else: + # Create a folder on Google Drive if it doesn't exist + folder = self.drive.CreateFile({'title': gdrive_folder, 'mimeType': 'application/vnd.google-apps.folder'}) + folder.Upload() + + # Upload files to the created folder + for root, dirs, files in os.walk(backup_path): + for filename in files: + file_path = os.path.join(root, filename) + gdrive_file = self.drive.CreateFile({'title': filename, 'parents': [{'id': folder['id']}]}) + gdrive_file.Upload() + logging.info(f"[gDriveSync] Uploaded {file_path} to Google Drive") + + logging.info(f"[gDriveSync] Backup uploaded to Google Drive") + except pydrive2.files.ApiRequestError as api_error: + self.handle_upload_error(api_error, backup_path, gdrive_folder) + + except Exception as e: + logging.error(f"Error during upload_to_gdrive: {e}") + + def handle_upload_error(self, api_error, backup_path, gdrive_folder): + if 'Rate Limit Exceeded' in str(api_error): + logging.warning("[gDriveSync] Rate limit exceeded. Waiting for some time before retrying...") + # We set to 100 seconds, because there is a limit 20k requests per 100s per user + time.sleep(100) # You can adjust the sleep duration based on your needs + self.upload_to_gdrive(backup_path, gdrive_folder) + else: + logging.error(f"[gDriveSync] API Request Error: {api_error}") diff --git a/pwnagotchi/plugins/default/webcfg.py b/pwnagotchi/plugins/default/webcfg.py index 39df44b4..2bf018a6 100644 --- a/pwnagotchi/plugins/default/webcfg.py +++ b/pwnagotchi/plugins/default/webcfg.py @@ -479,11 +479,13 @@ INDEX = """ {% endblock %} """ + def serializer(obj): if isinstance(obj, set): return list(obj) raise TypeError + class WebConfig(plugins.Plugin): __author__ = '33197631+dadav@users.noreply.github.com' __version__ = '1.0.0' @@ -513,7 +515,6 @@ class WebConfig(plugins.Plugin): """ logging.info("webcfg: Plugin loaded.") - def on_webhook(self, path, request): """ Serves the current configuration @@ -532,7 +533,7 @@ class WebConfig(plugins.Plugin): elif request.method == "POST": if path == "save-config": try: - save_config(request.get_json(), '/etc/pwnagotchi/config.toml') # test + save_config(request.get_json(), '/etc/pwnagotchi/config.toml') # test _thread.start_new_thread(restart, (self.mode,)) return "success" except Exception as ex: @@ -547,7 +548,7 @@ class WebConfig(plugins.Plugin): self._agent._config = merge_config(request.get_json(), self._agent._config) logging.debug(" Agent CONFIG:\n%s" % repr(self._agent._config)) logging.debug(" Updated CONFIG:\n%s" % request.get_json()) - save_config(request.get_json(), '/etc/pwnagotchi/config.toml') # test + save_config(request.get_json(), '/etc/pwnagotchi/config.toml') # test return "success" except Exception as ex: logging.error("[webcfg mergesave] %s" % ex) From 88b688209eccac4bf383fd42c6e32f14cd9d7eb3 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 17:59:38 +0200 Subject: [PATCH 004/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 6 +- builder/data/root/settings.yaml | 0 pwnagotchi/google/cmd.py | 101 +++++++++++++++-------- pwnagotchi/plugins/cmd.py | 2 +- pwnagotchi/plugins/default/gdrivesync.py | 3 +- requirements.txt | 1 + 6 files changed, 75 insertions(+), 38 deletions(-) create mode 100644 builder/data/root/settings.yaml diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 2dd34b3a..bc0cc1f0 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -10,6 +10,7 @@ import os import pwnagotchi from pwnagotchi import utils +from pwnagotchi.google import cmd as google_cmd from pwnagotchi.plugins import cmd as plugins_cmd from pwnagotchi import log from pwnagotchi import restart @@ -98,7 +99,7 @@ def do_auto_mode(agent): if __name__ == '__main__': parser = argparse.ArgumentParser() parser = plugins_cmd.add_parsers(parser) - parser = google_cmd.add_parsers(parser) + parser2 = google_cmd.add_parsers(parser) parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', help='Main configuration file.') @@ -134,6 +135,9 @@ if __name__ == '__main__': log.setup_logging(args, config) rc = plugins_cmd.handle_cmd(args, config) sys.exit(rc) + elif google_cmd.used_google_cmd(args): + rc = google_cmd.handle_cmd(args) + sys.exit(rc) if args.version: print(pwnagotchi.__version__) diff --git a/builder/data/root/settings.yaml b/builder/data/root/settings.yaml new file mode 100644 index 00000000..e69de29b diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 0ddb6137..040c7ad0 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -1,13 +1,8 @@ # Handles the commandline stuff -import os +import pydrive2 +from pydrive2.auth import GoogleAuth import logging -import glob -import re -import shutil -from fnmatch import fnmatch -from pwnagotchi.utils import download_file, unzip, save_config, parse_version, md5 -from pwnagotchi.plugins import default_path def add_parsers(parser): @@ -16,45 +11,83 @@ def add_parsers(parser): """ subparsers = parser.add_subparsers() # pwnagotchi google - parser_plugins = subparsers.add_parser('google') - plugin_subparsers = parser_plugins.add_subparsers(dest='googlecmd') + parser_google = subparsers.add_parser('google') + google_subparsers = parser_google.add_subparsers(dest='googlecmd') # pwnagotchi plugins search - parser_plugins_search = plugin_subparsers.add_parser('search', help='Search for pwnagotchi plugins') - parser_plugins_search.add_argument('pattern', type=str, help="Search expression (wildcards allowed)") + parser_google_auth = google_subparsers.add_parser('auth', help='Google Authentication') + parser_google_auth.add_argument('true', type=str, help="This will start the authentication process") return parser -def used_plugin_cmd(args): +def used_google_cmd(args): """ Checks if the plugins subcommand was used """ - return hasattr(args, 'plugincmd') + return hasattr(args, 'googlecmd') -def handle_cmd(args, config): +def handle_cmd(args): """ Parses the arguments and does the thing the user wants """ - if args.plugincmd == 'update': - return update(config) - elif args.plugincmd == 'search': - args.installed = True # also search in installed plugins - return list_plugins(args, config, args.pattern) - elif args.plugincmd == 'install': - return install(args, config) - elif args.plugincmd == 'uninstall': - return uninstall(args, config) - elif args.plugincmd == 'list': - return list_plugins(args, config) - elif args.plugincmd == 'enable': - return enable(args, config) - elif args.plugincmd == 'disable': - return disable(args, config) - elif args.plugincmd == 'upgrade': - return upgrade(args, config, args.pattern) - elif args.plugincmd == 'edit': - return edit(args, config) + if args.plugincmd == 'auth': + return auth(args) + elif args.plugincmd == 'refresh': + return refresh(args) + raise NotImplementedError() - raise NotImplementedError() \ No newline at end of file + +def auth(args): + if args == "true": + # start authentication process + user_input = input("By completing these steps you give pwnagotchi access to your personal Google Drive!\n" + "Personal credentials will be stored only locally for automated verification in the future.\n" + "No one else but you have access to these.\n" + "Do you agree? \n\n[y(es)/n(o)]") + if user_input.lower() in ('y', 'yes'): + try: + gauth = GoogleAuth(settings_file="settings.yaml") + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.") + gauth.Auth(user_input) + gauth.SaveCredentialsFile("credentials.json") + except Exception as e: + logging.error(f"Error: {e}") + return + + +def refresh(args): + if int(args): + # refresh token for x amount of time (seconds) + gauth = GoogleAuth(settings_file="settings.yaml") + try: + # Try to load saved client credentials + gauth.LoadCredentialsFile("credentials.json") + except pydrive2.auth.InvalidCredentialsError: + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.") + gauth.Auth(user_input) + + if gauth.access_token_expired: + if gauth.credentials is not None: + try: + # Refresh the token + gauth.Refresh() + except pydrive2.auth.RefreshError: + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.") + gauth.Auth(user_input) + else: + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.") + gauth.Auth(user_input) + gauth.Authorize() + gauth.SaveCredentialsFile("credentials.json") + print("No refresh is required.") + return diff --git a/pwnagotchi/plugins/cmd.py b/pwnagotchi/plugins/cmd.py index b0b9bf9e..ee752010 100644 --- a/pwnagotchi/plugins/cmd.py +++ b/pwnagotchi/plugins/cmd.py @@ -75,7 +75,7 @@ def handle_cmd(args, config): if args.plugincmd == 'update': return update(config) elif args.plugincmd == 'search': - args.installed = True # also search in installed plugins + args.installed = True # also search in installed plugins return list_plugins(args, config, args.pattern) elif args.plugincmd == 'install': return install(args, config) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 5b376fb6..493c972d 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -51,8 +51,7 @@ class GdriveSync(plugins.Plugin): self.backup = False try: - gauth = GoogleAuth() - + gauth = GoogleAuth(settings_file="settings.yaml") gauth.Authorize() # Create GoogleDrive instance diff --git a/requirements.txt b/requirements.txt index 32e9a958..e30135e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,3 +22,4 @@ torch==2.0.1 torchvision==0.15.2 stable_baselines3 RPi.GPIO +pydrive2 \ No newline at end of file From 34997bb8cf498b31ee2718d5f101bb5d5a847794 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:05:13 +0200 Subject: [PATCH 005/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- builder/data/root/client_secrets.json | 11 +++++++++++ builder/data/root/settings.yaml | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 builder/data/root/client_secrets.json diff --git a/builder/data/root/client_secrets.json b/builder/data/root/client_secrets.json new file mode 100644 index 00000000..19ba0b8e --- /dev/null +++ b/builder/data/root/client_secrets.json @@ -0,0 +1,11 @@ +{ + "installed":{ + "client_id":"339036094194-a9334tmer2d8tjq0enr6gi1n23bej09t.apps.googleusercontent.com", + "project_id":"pwnagotchi-401519", + "auth_uri":"https://accounts.google.com/o/oauth2/auth", + "token_uri":"https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs", + "client_secret":"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", + "redirect_uris":["http://localhost"] + } +} \ No newline at end of file diff --git a/builder/data/root/settings.yaml b/builder/data/root/settings.yaml index e69de29b..680c6a06 100644 --- a/builder/data/root/settings.yaml +++ b/builder/data/root/settings.yaml @@ -0,0 +1,14 @@ +client_config_backend: file +client_config: + client_id: 339036094194-a9334tmer2d8tjq0enr6gi1n23bej09t.apps.googleusercontent.com + client_secret: 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 + +save_credentials: True +save_credentials_backend: file +save_credentials_file: credentials.json + +get_refresh_token: True + +oauth_scope: + - https://www.googleapis.com/auth/drive + - https://www.googleapis.com/auth/drive.install \ No newline at end of file From db631d0d430b42056b857b950c81a1aff524ddcc Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:06:49 +0200 Subject: [PATCH 006/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index bc0cc1f0..58f3ab0f 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -98,8 +98,9 @@ def do_auto_mode(agent): if __name__ == '__main__': parser = argparse.ArgumentParser() + parser2 = argparse.ArgumentParser() parser = plugins_cmd.add_parsers(parser) - parser2 = google_cmd.add_parsers(parser) + parser2 = google_cmd.add_parsers(parser2) parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', help='Main configuration file.') From 884778eb4c9481b32b6e43ac3873c46fe46591ee Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:07:24 +0200 Subject: [PATCH 007/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 58f3ab0f..ee347af7 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -130,6 +130,7 @@ if __name__ == '__main__': help="How to donate to this project.") args = parser.parse_args() + args2 = parser2.parse_args() if plugins_cmd.used_plugin_cmd(args): config = utils.load_config(args) From 206ed6fad88710812fbaa52b62a6d235cc6870e8 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:07:42 +0200 Subject: [PATCH 008/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index ee347af7..d07a089c 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -137,8 +137,8 @@ if __name__ == '__main__': log.setup_logging(args, config) rc = plugins_cmd.handle_cmd(args, config) sys.exit(rc) - elif google_cmd.used_google_cmd(args): - rc = google_cmd.handle_cmd(args) + elif google_cmd.used_google_cmd(args2): + rc = google_cmd.handle_cmd(args2) sys.exit(rc) if args.version: From c1e0d16b67126775d48730a2ef8ecd6a5f247c11 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:12:07 +0200 Subject: [PATCH 009/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index d07a089c..c4e39ced 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -137,7 +137,7 @@ if __name__ == '__main__': log.setup_logging(args, config) rc = plugins_cmd.handle_cmd(args, config) sys.exit(rc) - elif google_cmd.used_google_cmd(args2): + if google_cmd.used_google_cmd(args2): rc = google_cmd.handle_cmd(args2) sys.exit(rc) From 85562a2f7c49ccd15f0240b41ab1ea1d833e537d Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:14:35 +0200 Subject: [PATCH 010/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 040c7ad0..3c9d2741 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -56,7 +56,7 @@ def auth(args): gauth.SaveCredentialsFile("credentials.json") except Exception as e: logging.error(f"Error: {e}") - return + return 0 def refresh(args): @@ -90,4 +90,4 @@ def refresh(args): gauth.Authorize() gauth.SaveCredentialsFile("credentials.json") print("No refresh is required.") - return + return 0 From 41c53584af725bcb823010c34c6b82601adfe4d8 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:18:55 +0200 Subject: [PATCH 011/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 3c9d2741..5f3f0914 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -16,7 +16,7 @@ def add_parsers(parser): # pwnagotchi plugins search parser_google_auth = google_subparsers.add_parser('auth', help='Google Authentication') - parser_google_auth.add_argument('true', type=str, help="This will start the authentication process") + parser_google_auth.add_argument('bool', type=bool, help="This will start the authentication process") return parser @@ -33,7 +33,7 @@ def handle_cmd(args): Parses the arguments and does the thing the user wants """ if args.plugincmd == 'auth': - return auth(args) + return auth(args.bool) elif args.plugincmd == 'refresh': return refresh(args) raise NotImplementedError() From 436bec86e0c44b5155140ab3b6c527e2b791b01a Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:20:32 +0200 Subject: [PATCH 012/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index c4e39ced..cc5c2c64 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -99,7 +99,7 @@ def do_auto_mode(agent): if __name__ == '__main__': parser = argparse.ArgumentParser() parser2 = argparse.ArgumentParser() - parser = plugins_cmd.add_parsers(parser) + parser = google_cmd.add_parsers(parser) parser2 = google_cmd.add_parsers(parser2) parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', From fe0645379d0701c2659a564a022ca57e3228fd76 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:21:34 +0200 Subject: [PATCH 013/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index cc5c2c64..b8b35732 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -97,9 +97,8 @@ def do_auto_mode(agent): if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser2 = argparse.ArgumentParser() - parser = google_cmd.add_parsers(parser) + parser, parser2 = argparse.ArgumentParser() + parser = plugins_cmd.add_parsers(parser) parser2 = google_cmd.add_parsers(parser2) parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', From 8b55af4f00164572e66df7cd4262794577484223 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:23:00 +0200 Subject: [PATCH 014/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index b8b35732..e973d990 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -97,9 +97,9 @@ def do_auto_mode(agent): if __name__ == '__main__': - parser, parser2 = argparse.ArgumentParser() + parser = argparse.ArgumentParser() parser = plugins_cmd.add_parsers(parser) - parser2 = google_cmd.add_parsers(parser2) + parser2 = google_cmd.add_parsers(parser) parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', help='Main configuration file.') From e43bd8dd747bb74f5124b770c71466ec6b2dc48b Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:41:30 +0200 Subject: [PATCH 015/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index e973d990..2bbda425 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -97,38 +97,42 @@ def do_auto_mode(agent): if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser = plugins_cmd.add_parsers(parser) - parser2 = google_cmd.add_parsers(parser) + parent_parser = argparse.ArgumentParser() - parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', + parent_parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', help='Main configuration file.') - parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/etc/pwnagotchi/config.toml', + parent_parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/etc/pwnagotchi/config.toml', help='If this file exists, configuration will be merged and this will override default values.') - parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.") - parser.add_argument('--skip-session', dest="skip_session", action="store_true", default=False, + parent_parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.") + parent_parser.add_argument('--skip-session', dest="skip_session", action="store_true", default=False, help="Skip last session parsing in manual mode.") - parser.add_argument('--clear', dest="do_clear", action="store_true", default=False, + parent_parser.add_argument('--clear', dest="do_clear", action="store_true", default=False, help="Clear the ePaper display and exit.") - parser.add_argument('--debug', dest="debug", action="store_true", default=False, + parent_parser.add_argument('--debug', dest="debug", action="store_true", default=False, help="Enable debug logs.") - parser.add_argument('--version', dest="version", action="store_true", default=False, + parent_parser.add_argument('--version', dest="version", action="store_true", default=False, help="Print the version.") - parser.add_argument('--print-config', dest="print_config", action="store_true", default=False, + parent_parser.add_argument('--print-config', dest="print_config", action="store_true", default=False, help="Print the configuration.") # Jayofelony added these - parser.add_argument('--check-update', dest="check_update", action="store_true", default=False, + parent_parser.add_argument('--check-update', dest="check_update", action="store_true", default=False, help="Check for updates on Pwnagotchi. And tells current version.") - parser.add_argument('--donate', dest="donate", action="store_true", default=False, + parent_parser.add_argument('--donate', dest="donate", action="store_true", default=False, help="How to donate to this project.") - args = parser.parse_args() + # sub parser plugins + parser = parent_parser.add_subparsers(title="actions") + parser1 = plugins_cmd.add_parsers(parser) + args = parser1.parse_args() + + # sub parser google + parser2 = google_cmd.add_parsers(parser) args2 = parser2.parse_args() if plugins_cmd.used_plugin_cmd(args): @@ -136,9 +140,6 @@ if __name__ == '__main__': log.setup_logging(args, config) rc = plugins_cmd.handle_cmd(args, config) sys.exit(rc) - if google_cmd.used_google_cmd(args2): - rc = google_cmd.handle_cmd(args2) - sys.exit(rc) if args.version: print(pwnagotchi.__version__) From 29e9abfbf7afdfcf6e60e15df7984cbdd65a1889 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:44:45 +0200 Subject: [PATCH 016/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 2bbda425..9d36a06a 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -97,43 +97,38 @@ def do_auto_mode(agent): if __name__ == '__main__': - parent_parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser() - parent_parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', + parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', help='Main configuration file.') - parent_parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/etc/pwnagotchi/config.toml', + parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/etc/pwnagotchi/config.toml', help='If this file exists, configuration will be merged and this will override default values.') - parent_parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.") - parent_parser.add_argument('--skip-session', dest="skip_session", action="store_true", default=False, + parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.") + parser.add_argument('--skip-session', dest="skip_session", action="store_true", default=False, help="Skip last session parsing in manual mode.") - parent_parser.add_argument('--clear', dest="do_clear", action="store_true", default=False, + parser.add_argument('--clear', dest="do_clear", action="store_true", default=False, help="Clear the ePaper display and exit.") - parent_parser.add_argument('--debug', dest="debug", action="store_true", default=False, + parser.add_argument('--debug', dest="debug", action="store_true", default=False, help="Enable debug logs.") - parent_parser.add_argument('--version', dest="version", action="store_true", default=False, + parser.add_argument('--version', dest="version", action="store_true", default=False, help="Print the version.") - parent_parser.add_argument('--print-config', dest="print_config", action="store_true", default=False, + parser.add_argument('--print-config', dest="print_config", action="store_true", default=False, help="Print the configuration.") # Jayofelony added these - parent_parser.add_argument('--check-update', dest="check_update", action="store_true", default=False, + parser.add_argument('--check-update', dest="check_update", action="store_true", default=False, help="Check for updates on Pwnagotchi. And tells current version.") - parent_parser.add_argument('--donate', dest="donate", action="store_true", default=False, + parser.add_argument('--donate', dest="donate", action="store_true", default=False, help="How to donate to this project.") # sub parser plugins - parser = parent_parser.add_subparsers(title="actions") - parser1 = plugins_cmd.add_parsers(parser) - args = parser1.parse_args() - - # sub parser google - parser2 = google_cmd.add_parsers(parser) - args2 = parser2.parse_args() + parser = plugins_cmd.add_parsers(parser) + args = parser.parse_args() if plugins_cmd.used_plugin_cmd(args): config = utils.load_config(args) From 685b0f4e1b472ea1827c7b2e8ec26ed1a8db97b9 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:47:08 +0200 Subject: [PATCH 017/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 9d36a06a..9a00de20 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -97,37 +97,37 @@ def do_auto_mode(agent): if __name__ == '__main__': - parser = argparse.ArgumentParser() + parent_parser = argparse.ArgumentParser() - parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', + parent_parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', help='Main configuration file.') - parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/etc/pwnagotchi/config.toml', + parent_parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/etc/pwnagotchi/config.toml', help='If this file exists, configuration will be merged and this will override default values.') - parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.") - parser.add_argument('--skip-session', dest="skip_session", action="store_true", default=False, + parent_parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.") + parent_parser.add_argument('--skip-session', dest="skip_session", action="store_true", default=False, help="Skip last session parsing in manual mode.") - parser.add_argument('--clear', dest="do_clear", action="store_true", default=False, + parent_parser.add_argument('--clear', dest="do_clear", action="store_true", default=False, help="Clear the ePaper display and exit.") - parser.add_argument('--debug', dest="debug", action="store_true", default=False, + parent_parser.add_argument('--debug', dest="debug", action="store_true", default=False, help="Enable debug logs.") - parser.add_argument('--version', dest="version", action="store_true", default=False, + parent_parser.add_argument('--version', dest="version", action="store_true", default=False, help="Print the version.") - parser.add_argument('--print-config', dest="print_config", action="store_true", default=False, + parent_parser.add_argument('--print-config', dest="print_config", action="store_true", default=False, help="Print the configuration.") # Jayofelony added these - parser.add_argument('--check-update', dest="check_update", action="store_true", default=False, + parent_parser.add_argument('--check-update', dest="check_update", action="store_true", default=False, help="Check for updates on Pwnagotchi. And tells current version.") - parser.add_argument('--donate', dest="donate", action="store_true", default=False, + parent_parser.add_argument('--donate', dest="donate", action="store_true", default=False, help="How to donate to this project.") # sub parser plugins - parser = plugins_cmd.add_parsers(parser) + parser = plugins_cmd.add_parsers(parent_parser) args = parser.parse_args() if plugins_cmd.used_plugin_cmd(args): From 78069157af00e7281d7fbafaaece5dc7957da9a3 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:51:27 +0200 Subject: [PATCH 018/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 9a00de20..9fafb839 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -126,8 +126,15 @@ if __name__ == '__main__': parent_parser.add_argument('--donate', dest="donate", action="store_true", default=False, help="How to donate to this project.") + # create subparsers + subparsers = parent_parser.add_subparsers(title="Actions") + # sub parser plugins - parser = plugins_cmd.add_parsers(parent_parser) + parser_plugin = subparsers.add_parser("plugins", parents=[parent_parser], + add_help=False, + description="The plugins parser", + help="custom plugins") + parser = plugins_cmd.add_parsers(parser_plugin) args = parser.parse_args() if plugins_cmd.used_plugin_cmd(args): From 09cfb29827e8afe5e56815c2e299d17510e8f4ac Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:53:42 +0200 Subject: [PATCH 019/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 9fafb839..e171253f 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -130,10 +130,7 @@ if __name__ == '__main__': subparsers = parent_parser.add_subparsers(title="Actions") # sub parser plugins - parser_plugin = subparsers.add_parser("plugins", parents=[parent_parser], - add_help=False, - description="The plugins parser", - help="custom plugins") + parser_plugin = subparsers.add_parser(plugins_cmd.add_parsers(subparsers), parents=[parent_parser]) parser = plugins_cmd.add_parsers(parser_plugin) args = parser.parse_args() From 930c8e84b2a6794bb653aa6c66a72e6ae101aa61 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:54:56 +0200 Subject: [PATCH 020/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index e171253f..9d36a06a 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -97,41 +97,37 @@ def do_auto_mode(agent): if __name__ == '__main__': - parent_parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser() - parent_parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', + parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', help='Main configuration file.') - parent_parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/etc/pwnagotchi/config.toml', + parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/etc/pwnagotchi/config.toml', help='If this file exists, configuration will be merged and this will override default values.') - parent_parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.") - parent_parser.add_argument('--skip-session', dest="skip_session", action="store_true", default=False, + parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.") + parser.add_argument('--skip-session', dest="skip_session", action="store_true", default=False, help="Skip last session parsing in manual mode.") - parent_parser.add_argument('--clear', dest="do_clear", action="store_true", default=False, + parser.add_argument('--clear', dest="do_clear", action="store_true", default=False, help="Clear the ePaper display and exit.") - parent_parser.add_argument('--debug', dest="debug", action="store_true", default=False, + parser.add_argument('--debug', dest="debug", action="store_true", default=False, help="Enable debug logs.") - parent_parser.add_argument('--version', dest="version", action="store_true", default=False, + parser.add_argument('--version', dest="version", action="store_true", default=False, help="Print the version.") - parent_parser.add_argument('--print-config', dest="print_config", action="store_true", default=False, + parser.add_argument('--print-config', dest="print_config", action="store_true", default=False, help="Print the configuration.") # Jayofelony added these - parent_parser.add_argument('--check-update', dest="check_update", action="store_true", default=False, + parser.add_argument('--check-update', dest="check_update", action="store_true", default=False, help="Check for updates on Pwnagotchi. And tells current version.") - parent_parser.add_argument('--donate', dest="donate", action="store_true", default=False, + parser.add_argument('--donate', dest="donate", action="store_true", default=False, help="How to donate to this project.") - # create subparsers - subparsers = parent_parser.add_subparsers(title="Actions") - # sub parser plugins - parser_plugin = subparsers.add_parser(plugins_cmd.add_parsers(subparsers), parents=[parent_parser]) - parser = plugins_cmd.add_parsers(parser_plugin) + parser = plugins_cmd.add_parsers(parser) args = parser.parse_args() if plugins_cmd.used_plugin_cmd(args): From 62c4302f36ecd889c322a7dbacd4a6f74d526231 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 20:56:02 +0200 Subject: [PATCH 021/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 9d36a06a..05c11bab 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -98,7 +98,7 @@ def do_auto_mode(agent): if __name__ == '__main__': parser = argparse.ArgumentParser() - + # pwnagotchi --help parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', help='Main configuration file.') parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/etc/pwnagotchi/config.toml', @@ -126,7 +126,7 @@ if __name__ == '__main__': parser.add_argument('--donate', dest="donate", action="store_true", default=False, help="How to donate to this project.") - # sub parser plugins + # pwnagotchi plugins --help parser = plugins_cmd.add_parsers(parser) args = parser.parse_args() From c7cea85f9c4bc2e317a536db9a94764d711e500d Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 21:22:33 +0200 Subject: [PATCH 022/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- builder/data/root/client_secrets.json | 11 ----------- builder/data/root/settings.yaml | 14 -------------- 2 files changed, 25 deletions(-) delete mode 100644 builder/data/root/client_secrets.json delete mode 100644 builder/data/root/settings.yaml diff --git a/builder/data/root/client_secrets.json b/builder/data/root/client_secrets.json deleted file mode 100644 index 19ba0b8e..00000000 --- a/builder/data/root/client_secrets.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "installed":{ - "client_id":"339036094194-a9334tmer2d8tjq0enr6gi1n23bej09t.apps.googleusercontent.com", - "project_id":"pwnagotchi-401519", - "auth_uri":"https://accounts.google.com/o/oauth2/auth", - "token_uri":"https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs", - "client_secret":"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", - "redirect_uris":["http://localhost"] - } -} \ No newline at end of file diff --git a/builder/data/root/settings.yaml b/builder/data/root/settings.yaml deleted file mode 100644 index 680c6a06..00000000 --- a/builder/data/root/settings.yaml +++ /dev/null @@ -1,14 +0,0 @@ -client_config_backend: file -client_config: - client_id: 339036094194-a9334tmer2d8tjq0enr6gi1n23bej09t.apps.googleusercontent.com - client_secret: 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 - -save_credentials: True -save_credentials_backend: file -save_credentials_file: credentials.json - -get_refresh_token: True - -oauth_scope: - - https://www.googleapis.com/auth/drive - - https://www.googleapis.com/auth/drive.install \ No newline at end of file From 4343ff808fe6d26c38df4f3cea45e4ed28becfb8 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 23:45:26 +0200 Subject: [PATCH 023/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 05c11bab..c6099a18 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -97,7 +97,7 @@ def do_auto_mode(agent): if __name__ == '__main__': - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser(prog="pwnagotchi") # pwnagotchi --help parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', help='Main configuration file.') From 4424f1651ee2ca884175d7c065b4271e109044d4 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 23:54:53 +0200 Subject: [PATCH 024/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index c6099a18..ec57bfa3 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -127,8 +127,11 @@ if __name__ == '__main__': help="How to donate to this project.") # pwnagotchi plugins --help - parser = plugins_cmd.add_parsers(parser) - args = parser.parse_args() + parser_plugins = plugins_cmd.add_parsers(parser) + args = parser_plugins.parse_args() + + # pwnagotchi google --help + parser_google = google_cmd.add_parsers(parser) if plugins_cmd.used_plugin_cmd(args): config = utils.load_config(args) From 93f8067db807ca10d251ea918ad9d1d472b90484 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 23:55:48 +0200 Subject: [PATCH 025/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index ec57bfa3..5562662b 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -138,6 +138,9 @@ if __name__ == '__main__': log.setup_logging(args, config) rc = plugins_cmd.handle_cmd(args, config) sys.exit(rc) + if google_cmd.used_google_cmd(args): + rc = google_cmd.handle_cmd(args) + sys.exit(rc) if args.version: print(pwnagotchi.__version__) From 739448af5da0061d7b8c7cb3040f87d27cf5700d Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Thu, 12 Oct 2023 23:57:55 +0200 Subject: [PATCH 026/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 5562662b..1fcdd81f 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -139,6 +139,8 @@ if __name__ == '__main__': rc = plugins_cmd.handle_cmd(args, config) sys.exit(rc) if google_cmd.used_google_cmd(args): + config = utils.load_config(args) + log.setup_logging(args, config) rc = google_cmd.handle_cmd(args) sys.exit(rc) From 522f07b0d8d15b39c54eb1c4f2b88eff1584d33f Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 00:04:32 +0200 Subject: [PATCH 027/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 18 +++++++++++++----- pwnagotchi/google/cmd.py | 4 ++-- pwnagotchi/plugins/cmd.py | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 1fcdd81f..034c4efe 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -97,6 +97,17 @@ def do_auto_mode(agent): if __name__ == '__main__': + def add_parsers(parser): + """ + Adds the plugins and google subcommands to a given argparse.ArgumentParser + """ + subparsers = parser.add_subparsers() + + # Add parsers from plugins_cmd + plugins_cmd.add_parsers(subparsers) + + # Add parsers from google_cmd + google_cmd.add_parsers(subparsers) parser = argparse.ArgumentParser(prog="pwnagotchi") # pwnagotchi --help parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', @@ -127,11 +138,8 @@ if __name__ == '__main__': help="How to donate to this project.") # pwnagotchi plugins --help - parser_plugins = plugins_cmd.add_parsers(parser) - args = parser_plugins.parse_args() - - # pwnagotchi google --help - parser_google = google_cmd.add_parsers(parser) + add_parsers(parser) + args = parser.parse_args() if plugins_cmd.used_plugin_cmd(args): config = utils.load_config(args) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 5f3f0914..47d76f03 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -5,11 +5,11 @@ from pydrive2.auth import GoogleAuth import logging -def add_parsers(parser): +def add_parsers(subparsers): """ Adds the plugins subcommand to a given argparse.ArgumentParser """ - subparsers = parser.add_subparsers() + #subparsers = parser.add_subparsers() # pwnagotchi google parser_google = subparsers.add_parser('google') google_subparsers = parser_google.add_subparsers(dest='googlecmd') diff --git a/pwnagotchi/plugins/cmd.py b/pwnagotchi/plugins/cmd.py index ee752010..690dd85e 100644 --- a/pwnagotchi/plugins/cmd.py +++ b/pwnagotchi/plugins/cmd.py @@ -14,11 +14,11 @@ SAVE_DIR = '/usr/local/share/pwnagotchi/available-plugins/' DEFAULT_INSTALL_PATH = '/usr/local/share/pwnagotchi/installed-plugins/' -def add_parsers(parser): +def add_parsers(subparsers): """ Adds the plugins subcommand to a given argparse.ArgumentParser """ - subparsers = parser.add_subparsers() + #subparsers = parser.add_subparsers() # pwnagotchi plugins parser_plugins = subparsers.add_parser('plugins') plugin_subparsers = parser_plugins.add_subparsers(dest='plugincmd') From 731932c9e324adbcfe838b56ac890316bb777ceb Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 00:05:06 +0200 Subject: [PATCH 028/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 2 +- pwnagotchi/plugins/cmd.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 47d76f03..8b9cccb4 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -18,7 +18,7 @@ def add_parsers(subparsers): parser_google_auth = google_subparsers.add_parser('auth', help='Google Authentication') parser_google_auth.add_argument('bool', type=bool, help="This will start the authentication process") - return parser + return subparsers def used_google_cmd(args): diff --git a/pwnagotchi/plugins/cmd.py b/pwnagotchi/plugins/cmd.py index 690dd85e..05a056aa 100644 --- a/pwnagotchi/plugins/cmd.py +++ b/pwnagotchi/plugins/cmd.py @@ -58,7 +58,7 @@ def add_parsers(subparsers): parser_plugins_edit = plugin_subparsers.add_parser('edit', help='Edit the options') parser_plugins_edit.add_argument('name', type=str, help='Name of the plugin') - return parser + return subparsers def used_plugin_cmd(args): From 09639fd5c99f9fe414b547b6e7f295b8ee52b0d2 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 00:08:49 +0200 Subject: [PATCH 029/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- bin/pwnagotchi | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 034c4efe..4ad489a7 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -108,6 +108,7 @@ if __name__ == '__main__': # Add parsers from google_cmd google_cmd.add_parsers(subparsers) + parser = argparse.ArgumentParser(prog="pwnagotchi") # pwnagotchi --help parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml', From 4c7f5b6c9a88a2a1435e72584beb65f5f13bfeb0 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 00:10:39 +0200 Subject: [PATCH 030/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 8b9cccb4..a520e7ef 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -16,7 +16,6 @@ def add_parsers(subparsers): # pwnagotchi plugins search parser_google_auth = google_subparsers.add_parser('auth', help='Google Authentication') - parser_google_auth.add_argument('bool', type=bool, help="This will start the authentication process") return subparsers @@ -33,29 +32,28 @@ def handle_cmd(args): Parses the arguments and does the thing the user wants """ if args.plugincmd == 'auth': - return auth(args.bool) + return auth() elif args.plugincmd == 'refresh': return refresh(args) raise NotImplementedError() -def auth(args): - if args == "true": - # start authentication process - user_input = input("By completing these steps you give pwnagotchi access to your personal Google Drive!\n" - "Personal credentials will be stored only locally for automated verification in the future.\n" - "No one else but you have access to these.\n" - "Do you agree? \n\n[y(es)/n(o)]") - if user_input.lower() in ('y', 'yes'): - try: - gauth = GoogleAuth(settings_file="settings.yaml") - print(gauth.GetAuthUrl()) - user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.") - gauth.Auth(user_input) - gauth.SaveCredentialsFile("credentials.json") - except Exception as e: - logging.error(f"Error: {e}") +def auth(): + # start authentication process + user_input = input("By completing these steps you give pwnagotchi access to your personal Google Drive!\n" + "Personal credentials will be stored only locally for automated verification in the future.\n" + "No one else but you have access to these.\n" + "Do you agree? \n\n[y(es)/n(o)]") + if user_input.lower() in ('y', 'yes'): + try: + gauth = GoogleAuth(settings_file="settings.yaml") + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.") + gauth.Auth(user_input) + gauth.SaveCredentialsFile("credentials.json") + except Exception as e: + logging.error(f"Error: {e}") return 0 From 8ee11a691d1c80b6f60bc07900440e67fc9656f2 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 00:11:41 +0200 Subject: [PATCH 031/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 53 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index a520e7ef..36bcb7f2 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -34,7 +34,7 @@ def handle_cmd(args): if args.plugincmd == 'auth': return auth() elif args.plugincmd == 'refresh': - return refresh(args) + return refresh() raise NotImplementedError() @@ -57,35 +57,34 @@ def auth(): return 0 -def refresh(args): - if int(args): - # refresh token for x amount of time (seconds) - gauth = GoogleAuth(settings_file="settings.yaml") - try: - # Try to load saved client credentials - gauth.LoadCredentialsFile("credentials.json") - except pydrive2.auth.InvalidCredentialsError: - print(gauth.GetAuthUrl()) - user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.") - gauth.Auth(user_input) +def refresh(): + # refresh token for x amount of time (seconds) + gauth = GoogleAuth(settings_file="settings.yaml") + try: + # Try to load saved client credentials + gauth.LoadCredentialsFile("credentials.json") + except pydrive2.auth.InvalidCredentialsError: + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.") + gauth.Auth(user_input) - if gauth.access_token_expired: - if gauth.credentials is not None: - try: - # Refresh the token - gauth.Refresh() - except pydrive2.auth.RefreshError: - print(gauth.GetAuthUrl()) - user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.") - gauth.Auth(user_input) - else: + if gauth.access_token_expired: + if gauth.credentials is not None: + try: + # Refresh the token + gauth.Refresh() + except pydrive2.auth.RefreshError: print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " "complete the verification and then copy/paste the code from addressbar.") gauth.Auth(user_input) - gauth.Authorize() - gauth.SaveCredentialsFile("credentials.json") - print("No refresh is required.") + else: + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.") + gauth.Auth(user_input) + gauth.Authorize() + gauth.SaveCredentialsFile("credentials.json") + print("No refresh is required.") return 0 From 3390a1b8a9bb02c98e808d66fa5a5d9337a6a2ab Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 00:12:42 +0200 Subject: [PATCH 032/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 36bcb7f2..3bef854a 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -14,9 +14,11 @@ def add_parsers(subparsers): parser_google = subparsers.add_parser('google') google_subparsers = parser_google.add_subparsers(dest='googlecmd') - # pwnagotchi plugins search + # pwnagotchi google auth parser_google_auth = google_subparsers.add_parser('auth', help='Google Authentication') + # pwnagotchi google refresh token + parser_google_refresh = google_subparsers.add_parser('refresh', help="Refresh Google authentication token") return subparsers From 0f17891cd47f8f508deda632f5c84bdbfd916ad6 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 00:14:06 +0200 Subject: [PATCH 033/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 3bef854a..7e6986db 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -33,9 +33,9 @@ def handle_cmd(args): """ Parses the arguments and does the thing the user wants """ - if args.plugincmd == 'auth': + if args.googlecmd == 'auth': return auth() - elif args.plugincmd == 'refresh': + elif args.googlecmd == 'refresh': return refresh() raise NotImplementedError() From fb138855438c6ade8fbb15ea55081dbafe913dbd Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 00:15:18 +0200 Subject: [PATCH 034/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 7e6986db..2122badc 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -3,6 +3,7 @@ import pydrive2 from pydrive2.auth import GoogleAuth import logging +import os def add_parsers(subparsers): @@ -49,6 +50,9 @@ def auth(): if user_input.lower() in ('y', 'yes'): try: gauth = GoogleAuth(settings_file="settings.yaml") + if not os.path.exists("/root/client_secrets.json"): + logging.error("client_secrets.json not found in /root. Please RTFM!") + return 0 print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " "complete the verification and then copy/paste the code from addressbar.") From 1c33c830d5aa4b593b595ec314944ba21cfc59a9 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 00:16:17 +0200 Subject: [PATCH 035/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 2122badc..ec2c8fa7 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -48,11 +48,11 @@ def auth(): "No one else but you have access to these.\n" "Do you agree? \n\n[y(es)/n(o)]") if user_input.lower() in ('y', 'yes'): + if not os.path.exists("/root/client_secrets.json"): + logging.error("client_secrets.json not found in /root. Please RTFM!") + return 0 try: gauth = GoogleAuth(settings_file="settings.yaml") - if not os.path.exists("/root/client_secrets.json"): - logging.error("client_secrets.json not found in /root. Please RTFM!") - return 0 print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " "complete the verification and then copy/paste the code from addressbar.") From 7d27680edac98fa0f05efd0e3a0257eb33ef2a13 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 07:21:17 +0200 Subject: [PATCH 036/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index ec2c8fa7..af17d0a1 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -68,7 +68,7 @@ def refresh(): gauth = GoogleAuth(settings_file="settings.yaml") try: # Try to load saved client credentials - gauth.LoadCredentialsFile("credentials.json") + gauth.LoadCredentialsFile("/root/credentials.json") except pydrive2.auth.InvalidCredentialsError: print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " From d5763786b951c24e752fb403634c0b1440c398a5 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 07:22:35 +0200 Subject: [PATCH 037/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index af17d0a1..e82ee4bd 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -48,7 +48,7 @@ def auth(): "No one else but you have access to these.\n" "Do you agree? \n\n[y(es)/n(o)]") if user_input.lower() in ('y', 'yes'): - if not os.path.exists("/root/client_secrets.json"): + if not os.path.exists("client_secrets.json"): logging.error("client_secrets.json not found in /root. Please RTFM!") return 0 try: @@ -68,7 +68,7 @@ def refresh(): gauth = GoogleAuth(settings_file="settings.yaml") try: # Try to load saved client credentials - gauth.LoadCredentialsFile("/root/credentials.json") + gauth.LoadCredentialsFile("credentials.json") except pydrive2.auth.InvalidCredentialsError: print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " From b52ac84ef1cc5219cc687e23275cbfd5342fe7ce Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 08:43:40 +0200 Subject: [PATCH 038/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index e82ee4bd..086685a8 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -16,7 +16,7 @@ def add_parsers(subparsers): google_subparsers = parser_google.add_subparsers(dest='googlecmd') # pwnagotchi google auth - parser_google_auth = google_subparsers.add_parser('auth', help='Google Authentication') + parser_google_auth = google_subparsers.add_parser('login', help='Login to Google') # pwnagotchi google refresh token parser_google_refresh = google_subparsers.add_parser('refresh', help="Refresh Google authentication token") @@ -34,7 +34,7 @@ def handle_cmd(args): """ Parses the arguments and does the thing the user wants """ - if args.googlecmd == 'auth': + if args.googlecmd == 'login': return auth() elif args.googlecmd == 'refresh': return refresh() @@ -42,13 +42,14 @@ def handle_cmd(args): def auth(): + print(os.getcwd()) # start authentication process user_input = input("By completing these steps you give pwnagotchi access to your personal Google Drive!\n" "Personal credentials will be stored only locally for automated verification in the future.\n" "No one else but you have access to these.\n" "Do you agree? \n\n[y(es)/n(o)]") if user_input.lower() in ('y', 'yes'): - if not os.path.exists("client_secrets.json"): + if not os.path.exists("/rootclient_secrets.json"): logging.error("client_secrets.json not found in /root. Please RTFM!") return 0 try: From 5a854dc4344221592494547fda393661a481ef2f Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 08:44:46 +0200 Subject: [PATCH 039/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 086685a8..e30628b4 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -42,7 +42,6 @@ def handle_cmd(args): def auth(): - print(os.getcwd()) # start authentication process user_input = input("By completing these steps you give pwnagotchi access to your personal Google Drive!\n" "Personal credentials will be stored only locally for automated verification in the future.\n" From 61124d30cb505ef9f89f2b9e337fe0a577b8850d Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 08:46:30 +0200 Subject: [PATCH 040/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index e30628b4..eda927bb 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -48,7 +48,7 @@ def auth(): "No one else but you have access to these.\n" "Do you agree? \n\n[y(es)/n(o)]") if user_input.lower() in ('y', 'yes'): - if not os.path.exists("/rootclient_secrets.json"): + if not os.path.exists("/root/client_secrets.json"): logging.error("client_secrets.json not found in /root. Please RTFM!") return 0 try: From cb3fbd530ae05d75448e40dc35d3ef12709c9724 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 08:47:24 +0200 Subject: [PATCH 041/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index eda927bb..76700627 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -52,6 +52,7 @@ def auth(): logging.error("client_secrets.json not found in /root. Please RTFM!") return 0 try: + print(os.getcwd()) gauth = GoogleAuth(settings_file="settings.yaml") print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " From d18c694e32f0b58487b29ca098daa7d10863be7c Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 08:48:08 +0200 Subject: [PATCH 042/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 76700627..cd16ee9b 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -52,8 +52,7 @@ def auth(): logging.error("client_secrets.json not found in /root. Please RTFM!") return 0 try: - print(os.getcwd()) - gauth = GoogleAuth(settings_file="settings.yaml") + gauth = GoogleAuth(settings_file="/root/settings.yaml") print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " "complete the verification and then copy/paste the code from addressbar.") From 474a1ddc464b50aeb2c4dd6875661f16d5417da7 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 08:55:13 +0200 Subject: [PATCH 043/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index cd16ee9b..09d07a24 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -46,16 +46,18 @@ def auth(): user_input = input("By completing these steps you give pwnagotchi access to your personal Google Drive!\n" "Personal credentials will be stored only locally for automated verification in the future.\n" "No one else but you have access to these.\n" - "Do you agree? \n\n[y(es)/n(o)]") + "Do you agree? \n\n[y(es)/n(o)]\n" + "Answer: ") if user_input.lower() in ('y', 'yes'): if not os.path.exists("/root/client_secrets.json"): logging.error("client_secrets.json not found in /root. Please RTFM!") return 0 try: - gauth = GoogleAuth(settings_file="/root/settings.yaml") + gauth = GoogleAuth(settings_file="settings.yaml") print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.") + "complete the verification and then copy/paste the code from addressbar.\n\n" + "Code: ") gauth.Auth(user_input) gauth.SaveCredentialsFile("credentials.json") except Exception as e: From 73e22121a9db0513c090a785aa3823b6ddc6412b Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:01:25 +0200 Subject: [PATCH 044/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 09d07a24..4cb05d94 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -53,7 +53,7 @@ def auth(): logging.error("client_secrets.json not found in /root. Please RTFM!") return 0 try: - gauth = GoogleAuth(settings_file="settings.yaml") + gauth = GoogleAuth(settings_file="/root/settings.yaml") print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " "complete the verification and then copy/paste the code from addressbar.\n\n" From 451c14dae906309abb5bfeccd3a8541505de5e08 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:09:34 +0200 Subject: [PATCH 045/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- builder/data/root/client_secrets.json | 0 builder/data/root/settings.yaml | 0 pwnagotchi/plugins/default/gdrivesync.py | 2 +- setup.py | 3 ++- 4 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 builder/data/root/client_secrets.json create mode 100644 builder/data/root/settings.yaml diff --git a/builder/data/root/client_secrets.json b/builder/data/root/client_secrets.json new file mode 100644 index 00000000..e69de29b diff --git a/builder/data/root/settings.yaml b/builder/data/root/settings.yaml new file mode 100644 index 00000000..e69de29b diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 493c972d..09101089 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -51,7 +51,7 @@ class GdriveSync(plugins.Plugin): self.backup = False try: - gauth = GoogleAuth(settings_file="settings.yaml") + gauth = GoogleAuth(settings_file="/root/settings.yaml") gauth.Authorize() # Create GoogleDrive instance diff --git a/setup.py b/setup.py index 5591f8a4..4e28dd6f 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,8 @@ import re def install_file(source_filename, dest_filename): # do not overwrite network configuration if it exists already # https://github.com/evilsocket/pwnagotchi/issues/483 - if dest_filename.startswith('/etc/network/interfaces.d/') and os.path.exists(dest_filename): + if (dest_filename.startswith('/etc/network/interfaces.d/') or dest_filename.startswith('/root/') + and os.path.exists(dest_filename)): print("%s exists, skipping ..." % dest_filename) return From 570482ee4f793ea8f8c072f1dfb107efcd206931 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:12:43 +0200 Subject: [PATCH 046/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 09101089..2485468a 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -52,6 +52,7 @@ class GdriveSync(plugins.Plugin): try: gauth = GoogleAuth(settings_file="/root/settings.yaml") + gauth = gauth.LoadCredentialsFile("/root/credentials.json") gauth.Authorize() # Create GoogleDrive instance From 12e184df9672eae4965730f7919f0f67a4d2652d Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:14:19 +0200 Subject: [PATCH 047/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 2485468a..eca516a7 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -52,9 +52,10 @@ class GdriveSync(plugins.Plugin): try: gauth = GoogleAuth(settings_file="/root/settings.yaml") - gauth = gauth.LoadCredentialsFile("/root/credentials.json") + gauth.LoadCredentialsFile("/root/credentials.json") gauth.Authorize() + # Create GoogleDrive instance self.drive = GoogleDrive(gauth) From 228d924e2c727fb0fec4c264e3ff71941ff60f60 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:19:35 +0200 Subject: [PATCH 048/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 4 ++-- pwnagotchi/plugins/default/gdrivesync.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 4cb05d94..d436c334 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -67,10 +67,10 @@ def auth(): def refresh(): # refresh token for x amount of time (seconds) - gauth = GoogleAuth(settings_file="settings.yaml") + gauth = GoogleAuth(settings_file="/root/settings.yaml") try: # Try to load saved client credentials - gauth.LoadCredentialsFile("credentials.json") + gauth.LoadCredentialsFile("/root/credentials.json") except pydrive2.auth.InvalidCredentialsError: print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index eca516a7..91bf33be 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -53,9 +53,14 @@ class GdriveSync(plugins.Plugin): try: gauth = GoogleAuth(settings_file="/root/settings.yaml") gauth.LoadCredentialsFile("/root/credentials.json") + if gauth.credentials is None: + # Authenticate if they're not there + gauth.LocalWebserverAuth() + elif gauth.access_token_expired: + # Refresh them if expired + gauth.Refresh() gauth.Authorize() - # Create GoogleDrive instance self.drive = GoogleDrive(gauth) From fd75e12d8af6926b6f9f87ac5867b173e1c021d3 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:20:32 +0200 Subject: [PATCH 049/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index d436c334..c436983a 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -74,7 +74,8 @@ def refresh(): except pydrive2.auth.InvalidCredentialsError: print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.") + "complete the verification and then copy/paste the code from addressbar.\n\n" + "Code: ") gauth.Auth(user_input) if gauth.access_token_expired: From 0ac2524d3ef0529feef685ee62adbf50a7c14ea8 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:21:08 +0200 Subject: [PATCH 050/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index c436983a..4b06e469 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -86,14 +86,15 @@ def refresh(): except pydrive2.auth.RefreshError: print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.") + "complete the verification and then copy/paste the code from addressbar.\n\n" + "Code: ") gauth.Auth(user_input) else: print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.") + "complete the verification and then copy/paste the code from addressbar.\n\n" + "Code: ") gauth.Auth(user_input) gauth.Authorize() - gauth.SaveCredentialsFile("credentials.json") print("No refresh is required.") return 0 From 23adb50f3a11d761c73e5ea01cdc064a29bc5a3a Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:22:13 +0200 Subject: [PATCH 051/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 4b06e469..217e6783 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -71,6 +71,23 @@ def refresh(): try: # Try to load saved client credentials gauth.LoadCredentialsFile("/root/credentials.json") + if gauth.access_token_expired: + if gauth.credentials is not None: + try: + # Refresh the token + gauth.Refresh() + except pydrive2.auth.RefreshError: + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.\n\n" + "Code: ") + gauth.Auth(user_input) + else: + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.\n\n" + "Code: ") + gauth.Auth(user_input) except pydrive2.auth.InvalidCredentialsError: print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " @@ -78,23 +95,6 @@ def refresh(): "Code: ") gauth.Auth(user_input) - if gauth.access_token_expired: - if gauth.credentials is not None: - try: - # Refresh the token - gauth.Refresh() - except pydrive2.auth.RefreshError: - print(gauth.GetAuthUrl()) - user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.\n\n" - "Code: ") - gauth.Auth(user_input) - else: - print(gauth.GetAuthUrl()) - user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.\n\n" - "Code: ") - gauth.Auth(user_input) gauth.Authorize() print("No refresh is required.") return 0 From 653bf7f05bb2831b41191dd5ffe63c7bae81cab3 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:28:03 +0200 Subject: [PATCH 052/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 217e6783..323b1628 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -96,5 +96,5 @@ def refresh(): gauth.Auth(user_input) gauth.Authorize() - print("No refresh is required.") + print("Succesfully refresh access token ..") return 0 From 7179ca6652514771b47bc46b2a8f1017b010d261 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:32:10 +0200 Subject: [PATCH 053/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 4 ++-- pwnagotchi/plugins/default/gdrivesync.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index 323b1628..a5c7f012 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -59,7 +59,7 @@ def auth(): "complete the verification and then copy/paste the code from addressbar.\n\n" "Code: ") gauth.Auth(user_input) - gauth.SaveCredentialsFile("credentials.json") + gauth.SaveCredentialsFile("/root/credentials.json") except Exception as e: logging.error(f"Error: {e}") return 0 @@ -94,7 +94,7 @@ def refresh(): "complete the verification and then copy/paste the code from addressbar.\n\n" "Code: ") gauth.Auth(user_input) - + gauth.SaveCredentialsFile("/root/credentials.json") gauth.Authorize() print("Succesfully refresh access token ..") return 0 diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 91bf33be..45b36a5c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -59,6 +59,7 @@ class GdriveSync(plugins.Plugin): elif gauth.access_token_expired: # Refresh them if expired gauth.Refresh() + gauth.SaveCredentialsFile("/root/credentials.json") gauth.Authorize() # Create GoogleDrive instance From 4cc17b0894f25c47ffa168b9c3c544a9248c21cf Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:34:11 +0200 Subject: [PATCH 054/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index a5c7f012..442b3e52 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -76,6 +76,7 @@ def refresh(): try: # Refresh the token gauth.Refresh() + print("Succesfully refresh access token ..") except pydrive2.auth.RefreshError: print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " @@ -96,5 +97,5 @@ def refresh(): gauth.Auth(user_input) gauth.SaveCredentialsFile("/root/credentials.json") gauth.Authorize() - print("Succesfully refresh access token ..") + print("No refresh required ..") return 0 From 5d6122a67dd2833753bd926255c36fbb52c154b7 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:41:32 +0200 Subject: [PATCH 055/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 45b36a5c..16c206ac 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -68,11 +68,12 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for PwnagotchiBackups on gdrive. if not self.backup: # Assume 'PwnagotchiBackups' is the folder ID where backups are stored - backup_folder_id = 'PwnagotchiBackups' + backup_folder_name = 'PwnagotchiBackups' + backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) # Get the list of files in the folder - file_list = self.drive.ListFile({'q': f"'{self.get_folder_id_by_name(self.drive, backup_folder_id)}" - f"' in parents and trashed=false"}).GetList() + file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' in parents and trashed=false"}).GetList() + if not file_list: # Handle the case where no files were found logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") From 66b304d34c6cca60dc45ec3ce975850c2de94389 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 09:45:01 +0200 Subject: [PATCH 056/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 16c206ac..ca34ca93 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -71,7 +71,15 @@ class GdriveSync(plugins.Plugin): backup_folder_name = 'PwnagotchiBackups' backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) - # Get the list of files in the folder + if not backup_folder_id: + # If the folder doesn't exist, create it + folder = self.drive.CreateFile( + {'title': backup_folder_name, 'mimeType': 'application/vnd.google-apps.folder'}) + folder.Upload() + backup_folder_id = folder['id'] + print(f"Created folder '{backup_folder_name}' with ID: {backup_folder_id}") + + # Continue with the rest of the code using backup_folder_id file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' in parents and trashed=false"}).GetList() if not file_list: From 2dc192518954e33378bd2a404b3bd8547bebb3e0 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 10:42:00 +0200 Subject: [PATCH 057/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- builder/data/etc/pwnagotchi/conf.d/age.toml | 5 + .../etc/pwnagotchi/conf.d/auto-update.toml | 3 + .../data/etc/pwnagotchi/conf.d/bt-tether.toml | 23 +++++ .../etc/pwnagotchi/conf.d/fix_services.toml | 1 + .../etc/pwnagotchi/conf.d/gdrivesync.toml | 3 + .../etc/pwnagotchi/conf.d/gpio_buttons.toml | 1 + builder/data/etc/pwnagotchi/conf.d/gps.toml | 3 + builder/data/etc/pwnagotchi/conf.d/grid.toml | 5 + .../data/etc/pwnagotchi/conf.d/logtail.toml | 2 + .../data/etc/pwnagotchi/conf.d/memtemp.toml | 3 + .../data/etc/pwnagotchi/conf.d/net-pos.toml | 2 + .../etc/pwnagotchi/conf.d/onlinehascrack.toml | 5 + .../data/etc/pwnagotchi/conf.d/paw-gps.toml | 2 + .../data/etc/pwnagotchi/conf.d/pisugar2.toml | 3 + .../etc/pwnagotchi/conf.d/session-stats.toml | 2 + .../data/etc/pwnagotchi/conf.d/ups_hat_c.toml | 5 + .../data/etc/pwnagotchi/conf.d/ups_lite.toml | 2 + .../data/etc/pwnagotchi/conf.d/webcfg.toml | 1 + .../data/etc/pwnagotchi/conf.d/webgpsmap.toml | 1 + builder/data/etc/pwnagotchi/conf.d/wigle.toml | 4 + .../data/etc/pwnagotchi/conf.d/wpa-sec.toml | 5 + builder/pwnagotchi.yml | 10 ++ pwnagotchi/defaults.toml | 99 +------------------ pwnagotchi/plugins/default/gdrivesync.py | 6 +- 24 files changed, 95 insertions(+), 101 deletions(-) create mode 100644 builder/data/etc/pwnagotchi/conf.d/age.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/auto-update.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/bt-tether.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/fix_services.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/gdrivesync.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/gpio_buttons.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/gps.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/grid.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/logtail.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/memtemp.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/net-pos.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/onlinehascrack.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/paw-gps.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/pisugar2.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/session-stats.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/ups_hat_c.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/ups_lite.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/webcfg.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/webgpsmap.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/wigle.toml create mode 100644 builder/data/etc/pwnagotchi/conf.d/wpa-sec.toml diff --git a/builder/data/etc/pwnagotchi/conf.d/age.toml b/builder/data/etc/pwnagotchi/conf.d/age.toml new file mode 100644 index 00000000..4ca7e8ea --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/age.toml @@ -0,0 +1,5 @@ +main.plugins.age.enabled = false +main.plugins.age.age_x_coord = 0 +main.plugins.age.age_y_coord = 32 +main.plugins.age.str_x_coord = 67 +main.plugins.age.str_y_coord = 32 \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/auto-update.toml b/builder/data/etc/pwnagotchi/conf.d/auto-update.toml new file mode 100644 index 00000000..e073dbb9 --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/auto-update.toml @@ -0,0 +1,3 @@ +main.plugins.auto-update.enabled = true +main.plugins.auto-update.install = true +main.plugins.auto-update.interval = 1 \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/bt-tether.toml b/builder/data/etc/pwnagotchi/conf.d/bt-tether.toml new file mode 100644 index 00000000..64d1691a --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/bt-tether.toml @@ -0,0 +1,23 @@ +main.plugins.bt-tether.enabled = false + +main.plugins.bt-tether.devices.android-phone.enabled = false +main.plugins.bt-tether.devices.android-phone.search_order = 1 +main.plugins.bt-tether.devices.android-phone.mac = "" +main.plugins.bt-tether.devices.android-phone.ip = "192.168.44.44" +main.plugins.bt-tether.devices.android-phone.netmask = 24 +main.plugins.bt-tether.devices.android-phone.interval = 1 +main.plugins.bt-tether.devices.android-phone.scantime = 10 +main.plugins.bt-tether.devices.android-phone.max_tries = 10 +main.plugins.bt-tether.devices.android-phone.share_internet = false +main.plugins.bt-tether.devices.android-phone.priority = 1 + +main.plugins.bt-tether.devices.ios-phone.enabled = false +main.plugins.bt-tether.devices.ios-phone.search_order = 2 +main.plugins.bt-tether.devices.ios-phone.mac = "" +main.plugins.bt-tether.devices.ios-phone.ip = "172.20.10.6" +main.plugins.bt-tether.devices.ios-phone.netmask = 24 +main.plugins.bt-tether.devices.ios-phone.interval = 5 +main.plugins.bt-tether.devices.ios-phone.scantime = 20 +main.plugins.bt-tether.devices.ios-phone.max_tries = 0 +main.plugins.bt-tether.devices.ios-phone.share_internet = false +main.plugins.bt-tether.devices.ios-phone.priority = 999 \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/fix_services.toml b/builder/data/etc/pwnagotchi/conf.d/fix_services.toml new file mode 100644 index 00000000..9af7b6e1 --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/fix_services.toml @@ -0,0 +1 @@ +main.plugins.fix_services.enabled = true \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/gdrivesync.toml b/builder/data/etc/pwnagotchi/conf.d/gdrivesync.toml new file mode 100644 index 00000000..a599372c --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/gdrivesync.toml @@ -0,0 +1,3 @@ +main.plugins.gdrivesync.enabled = false +main.plugins.gdrivesync.backupfiles = [''] +main.plugins.gdrivesync.backup_folder = "PwnagotchiBackups" \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/gpio_buttons.toml b/builder/data/etc/pwnagotchi/conf.d/gpio_buttons.toml new file mode 100644 index 00000000..3567b22b --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/gpio_buttons.toml @@ -0,0 +1 @@ +main.plugins.gpio_buttons.enabled = false \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/gps.toml b/builder/data/etc/pwnagotchi/conf.d/gps.toml new file mode 100644 index 00000000..e975b538 --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/gps.toml @@ -0,0 +1,3 @@ +main.plugins.gps.enabled = false +main.plugins.gps.speed = 19200 +main.plugins.gps.device = "/dev/ttyUSB0" \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/grid.toml b/builder/data/etc/pwnagotchi/conf.d/grid.toml new file mode 100644 index 00000000..0ec2ab52 --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/grid.toml @@ -0,0 +1,5 @@ +main.plugins.grid.enabled = true +main.plugins.grid.report = true +main.plugins.grid.exclude = [ + "YourHomeNetworkHere" +] \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/logtail.toml b/builder/data/etc/pwnagotchi/conf.d/logtail.toml new file mode 100644 index 00000000..55393368 --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/logtail.toml @@ -0,0 +1,2 @@ +main.plugins.logtail.enabled = false +main.plugins.logtail.max-lines = 10000 \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/memtemp.toml b/builder/data/etc/pwnagotchi/conf.d/memtemp.toml new file mode 100644 index 00000000..d3521d5f --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/memtemp.toml @@ -0,0 +1,3 @@ +main.plugins.memtemp.enabled = false +main.plugins.memtemp.scale = "celsius" +main.plugins.memtemp.orientation = "horizontal" \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/net-pos.toml b/builder/data/etc/pwnagotchi/conf.d/net-pos.toml new file mode 100644 index 00000000..bdf22f1c --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/net-pos.toml @@ -0,0 +1,2 @@ +main.plugins.net-pos.enabled = false +main.plugins.net-pos.api_key = "test" \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/onlinehascrack.toml b/builder/data/etc/pwnagotchi/conf.d/onlinehascrack.toml new file mode 100644 index 00000000..b1170d0a --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/onlinehascrack.toml @@ -0,0 +1,5 @@ +main.plugins.onlinehashcrack.enabled = false +main.plugins.onlinehashcrack.email = "" +main.plugins.onlinehashcrack.dashboard = "" +main.plugins.onlinehashcrack.single_files = false +main.plugins.onlinehashcrack.whitelist = [] \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/paw-gps.toml b/builder/data/etc/pwnagotchi/conf.d/paw-gps.toml new file mode 100644 index 00000000..b5e0cfee --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/paw-gps.toml @@ -0,0 +1,2 @@ +main.plugins.paw-gps.enabled = false +main.plugins.paw-gps.ip = "192.168.44.1:8080" \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/pisugar2.toml b/builder/data/etc/pwnagotchi/conf.d/pisugar2.toml new file mode 100644 index 00000000..424c8873 --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/pisugar2.toml @@ -0,0 +1,3 @@ +main.plugins.pisugar2.enabled = false +main.plugins.pisugar2.shutdown = 5 +main.plugins.pisugar2.sync_rtc_on_boot = false \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/session-stats.toml b/builder/data/etc/pwnagotchi/conf.d/session-stats.toml new file mode 100644 index 00000000..ef57f4c8 --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/session-stats.toml @@ -0,0 +1,2 @@ +main.plugins.session-stats.enabled = true +main.plugins.session-stats.save_directory = "/var/tmp/pwnagotchi/sessions/" \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/ups_hat_c.toml b/builder/data/etc/pwnagotchi/conf.d/ups_hat_c.toml new file mode 100644 index 00000000..5a0e405d --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/ups_hat_c.toml @@ -0,0 +1,5 @@ +main.plugins.ups_hat_c.enabled = false +main.plugins.ups_hat_c.label_on = true # show BAT label or just percentage +main.plugins.ups_hat_c.shutdown = 5 # battery percent at which the device will turn off +main.plugins.ups_hat_c.bat_x_coord = 140 +main.plugins.ups_hat_c.bat_y_coord = 0 \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/ups_lite.toml b/builder/data/etc/pwnagotchi/conf.d/ups_lite.toml new file mode 100644 index 00000000..7b6a43fc --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/ups_lite.toml @@ -0,0 +1,2 @@ +main.plugins.ups_lite.enabled = false +main.plugins.ups_lite.shutdown = 2 \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/webcfg.toml b/builder/data/etc/pwnagotchi/conf.d/webcfg.toml new file mode 100644 index 00000000..d57b403e --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/webcfg.toml @@ -0,0 +1 @@ +main.plugins.webcfg.enabled = true \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/webgpsmap.toml b/builder/data/etc/pwnagotchi/conf.d/webgpsmap.toml new file mode 100644 index 00000000..6a22d55c --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/webgpsmap.toml @@ -0,0 +1 @@ +main.plugins.webgpsmap.enabled = false \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/wigle.toml b/builder/data/etc/pwnagotchi/conf.d/wigle.toml new file mode 100644 index 00000000..8f612473 --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/wigle.toml @@ -0,0 +1,4 @@ +main.plugins.wigle.enabled = false +main.plugins.wigle.api_key = "" +main.plugins.wigle.whitelist = [] +main.plugins.wigle.donate = true \ No newline at end of file diff --git a/builder/data/etc/pwnagotchi/conf.d/wpa-sec.toml b/builder/data/etc/pwnagotchi/conf.d/wpa-sec.toml new file mode 100644 index 00000000..bdd91e4b --- /dev/null +++ b/builder/data/etc/pwnagotchi/conf.d/wpa-sec.toml @@ -0,0 +1,5 @@ +main.plugins.wpa-sec.enabled = false +main.plugins.wpa-sec.api_key = "" +main.plugins.wpa-sec.api_url = "https://wpa-sec.stanev.org" +main.plugins.wpa-sec.download_results = false +main.plugins.wpa-sec.whitelist = [] \ No newline at end of file diff --git a/builder/pwnagotchi.yml b/builder/pwnagotchi.yml index d2773369..2afe510b 100644 --- a/builder/pwnagotchi.yml +++ b/builder/pwnagotchi.yml @@ -381,6 +381,11 @@ path: /usr/local/share/pwnagotchi/custom-plugins/ state: directory + - name: Create custom config directory + file: + path: /etc/pwnagotchi/conf.d/ + state: directory + - name: clone pwnagotchi repository git: repo: https://github.com/jayofelony/pwnagotchi.git @@ -627,6 +632,11 @@ autoclean: true when: removed.changed + - name: apt clean + shell: "apt clean" + args: + executable: /bin/bash + - name: remove dependencies that are no longer required apt: autoremove: yes diff --git a/pwnagotchi/defaults.toml b/pwnagotchi/defaults.toml index ea8fc151..1e2f5caa 100644 --- a/pwnagotchi/defaults.toml +++ b/pwnagotchi/defaults.toml @@ -7,9 +7,8 @@ main.custom_plugin_repos = [ "https://github.com/tisboyo/pwnagotchi-pisugar2-plugin/archive/master.zip", "https://github.com/nullm0ose/pwnagotchi-plugin-pisugar3/archive/master.zip" ] -main.custom_plugins = "/usr/local/share/pwnagotchi/custom-plugins/" -main.plugins.fix_services.enabled = true +main.custom_plugins = "/usr/local/share/pwnagotchi/custom-plugins/" main.iface = "wlan0mon" main.mon_start_cmd = "/usr/bin/monstart" @@ -24,102 +23,6 @@ main.whitelist = [ ] main.filter = "" -main.plugins.age.enabled = false -main.plugins.age.age_x_coord = 0 -main.plugins.age.age_y_coord = 32 -main.plugins.age.str_x_coord = 67 -main.plugins.age.str_y_coord = 32 - -main.plugins.ups_hat_c.enabled = false -main.plugins.ups_hat_c.label_on = true # show BAT label or just percentage -main.plugins.ups_hat_c.shutdown = 5 # battery percent at which the device will turn off -main.plugins.ups_hat_c.bat_x_coord = 140 -main.plugins.ups_hat_c.bat_y_coord = 0 - -main.plugins.pisugar2.enabled = false -main.plugins.pisugar2.shutdown = 5 -main.plugins.pisugar2.sync_rtc_on_boot = false - -main.plugins.grid.enabled = true -main.plugins.grid.report = true -main.plugins.grid.exclude = [ - "YourHomeNetworkHere" -] - -main.plugins.auto-update.enabled = true -main.plugins.auto-update.install = true -main.plugins.auto-update.interval = 1 - -main.plugins.net-pos.enabled = false -main.plugins.net-pos.api_key = "test" - -main.plugins.gps.enabled = false -main.plugins.gps.speed = 19200 -main.plugins.gps.device = "/dev/ttyUSB0" - -main.plugins.webgpsmap.enabled = false - -main.plugins.onlinehashcrack.enabled = false -main.plugins.onlinehashcrack.email = "" -main.plugins.onlinehashcrack.dashboard = "" -main.plugins.onlinehashcrack.single_files = false -main.plugins.onlinehashcrack.whitelist = [] - -main.plugins.wpa-sec.enabled = false -main.plugins.wpa-sec.api_key = "" -main.plugins.wpa-sec.api_url = "https://wpa-sec.stanev.org" -main.plugins.wpa-sec.download_results = false -main.plugins.wpa-sec.whitelist = [] - -main.plugins.wigle.enabled = false -main.plugins.wigle.api_key = "" -main.plugins.wigle.whitelist = [] -main.plugins.wigle.donate = true - -main.plugins.bt-tether.enabled = false - -main.plugins.bt-tether.devices.android-phone.enabled = false -main.plugins.bt-tether.devices.android-phone.search_order = 1 -main.plugins.bt-tether.devices.android-phone.mac = "" -main.plugins.bt-tether.devices.android-phone.ip = "192.168.44.44" -main.plugins.bt-tether.devices.android-phone.netmask = 24 -main.plugins.bt-tether.devices.android-phone.interval = 1 -main.plugins.bt-tether.devices.android-phone.scantime = 10 -main.plugins.bt-tether.devices.android-phone.max_tries = 10 -main.plugins.bt-tether.devices.android-phone.share_internet = false -main.plugins.bt-tether.devices.android-phone.priority = 1 - -main.plugins.bt-tether.devices.ios-phone.enabled = false -main.plugins.bt-tether.devices.ios-phone.search_order = 2 -main.plugins.bt-tether.devices.ios-phone.mac = "" -main.plugins.bt-tether.devices.ios-phone.ip = "172.20.10.6" -main.plugins.bt-tether.devices.ios-phone.netmask = 24 -main.plugins.bt-tether.devices.ios-phone.interval = 5 -main.plugins.bt-tether.devices.ios-phone.scantime = 20 -main.plugins.bt-tether.devices.ios-phone.max_tries = 0 -main.plugins.bt-tether.devices.ios-phone.share_internet = false -main.plugins.bt-tether.devices.ios-phone.priority = 999 - -main.plugins.memtemp.enabled = false -main.plugins.memtemp.scale = "celsius" -main.plugins.memtemp.orientation = "horizontal" - -main.plugins.paw-gps.enabled = false -main.plugins.paw-gps.ip = "192.168.44.1:8080" - -main.plugins.ups_lite.enabled = false -main.plugins.ups_lite.shutdown = 2 - -main.plugins.gpio_buttons.enabled = false - -main.plugins.webcfg.enabled = true - -main.plugins.logtail.enabled = false -main.plugins.logtail.max-lines = 10000 - -main.plugins.session-stats.enabled = true -main.plugins.session-stats.save_directory = "/var/tmp/pwnagotchi/sessions/" - main.log.path = "/var/log/pwnagotchi.log" main.log.rotation.enabled = true main.log.rotation.size = "10M" diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index ca34ca93..ce70e437 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -68,7 +68,7 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for PwnagotchiBackups on gdrive. if not self.backup: # Assume 'PwnagotchiBackups' is the folder ID where backups are stored - backup_folder_name = 'PwnagotchiBackups' + backup_folder_name = self.options['backup_folder'] backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) if not backup_folder_id: @@ -85,8 +85,8 @@ class GdriveSync(plugins.Plugin): if not file_list: # Handle the case where no files were found logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") - if self.config['backupfiles'] is not None: - self.backupfiles = self.backupfiles + self.config['backupfiles'] + if self.options['backupfiles'] is not None: + self.backupfiles = self.backupfiles + self.options['backupfiles'] self.backup_files(self.backupfiles, '/backup') self.upload_to_gdrive('/backup', 'PwnagotchiBackups') From 3fa7cb6a8c959184863fd509bda5d0f724e574bf Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 10:47:32 +0200 Subject: [PATCH 058/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index ce70e437..98ec28d2 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -39,7 +39,7 @@ class GdriveSync(plugins.Plugin): for file in file_list: if file['title'] == folder_name: return file['id'] - return None + return None def on_loaded(self): # client_secrets.json needs to be in /root From d7d4cdf814151094e2c0d385c7f2a7f2e1a97846 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 10:49:13 +0200 Subject: [PATCH 059/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 98ec28d2..a1f7f77c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,7 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "'"+folder_name+"' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From c3d0bc1a37f4387897c9d138ed8df07a02e3f854 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 10:50:05 +0200 Subject: [PATCH 060/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index a1f7f77c..1d94abe0 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,7 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "'"+folder_name+"' and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "'"+folder_name+"' in parents and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From 933807c5a7b5e08aa2cd0e24030b8acf52d5d238 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 10:54:21 +0200 Subject: [PATCH 061/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 1d94abe0..2ecd047c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,7 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "'"+folder_name+"' in parents and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' in parent and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From 2f8f709dea13a98149a0b8420018afb3c9b70b38 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 11:38:17 +0200 Subject: [PATCH 062/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 2ecd047c..1a04e061 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,7 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' in parent and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "'"+folder_name+"' in parents and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] @@ -65,9 +65,9 @@ class GdriveSync(plugins.Plugin): # Create GoogleDrive instance self.drive = GoogleDrive(gauth) - # if backup file does not exist, we will check for PwnagotchiBackups on gdrive. + # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: - # Assume 'PwnagotchiBackups' is the folder ID where backups are stored + # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_name = self.options['backup_folder'] backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) From 1e6ed109a6ee25e394df83089cb1155bc8708194 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 11:39:18 +0200 Subject: [PATCH 063/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 1a04e061..7a563dae 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,7 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "'"+folder_name+"' in parents and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "'"+folder_name+"' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From e3f9b75f22753ea37934aa3a8e71190a720e0edc Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 11:40:07 +0200 Subject: [PATCH 064/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 7a563dae..6ca64f22 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,7 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "'"+folder_name+"' and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' in parent and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From 21efbace3405b37e6d9043b02c690f49f71ccff8 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 11:45:52 +0200 Subject: [PATCH 065/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 6ca64f22..8c5119a5 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,7 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' in parent and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' '"+folder_name+"' in parent and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From 8452c865fcd1eceb723f6866c05532ba9d2d7348 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 11:47:22 +0200 Subject: [PATCH 066/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 8c5119a5..b03c41ba 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,7 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' '"+folder_name+"' in parent and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From 5c38203648602caf8fd65b5cdca92a594009df51 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 13:14:19 +0200 Subject: [PATCH 067/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index b03c41ba..51aedd6d 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -40,11 +40,12 @@ class GdriveSync(plugins.Plugin): if file['title'] == folder_name: return file['id'] return None + return None def on_loaded(self): - # client_secrets.json needs to be in /root - if not os.path.exists("/root/client_secrets.json"): - logging.error("client_secrets.json not found in /root. Please RTFM!") + # client_secrets.json needs to be not empty + if os.stat("/root/client_secrets.json").st_size == 0: + logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") return # backup file, so we know if there has been a backup made at least once before. if not os.path.exists("/root/.gdrive-backup"): @@ -109,6 +110,7 @@ class GdriveSync(plugins.Plugin): self.backup = True with open("/root/.gdrive-backup", "w").close(): pass # Create an empty file + # reboot so we can start opwngrid with backup id pwnagotchi.reboot() # all set, gdriveSync is ready to run From 0fe6030d81e01fa3148091db6de333e3b2f78d6b Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 13:18:56 +0200 Subject: [PATCH 068/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 51aedd6d..48c5c4fb 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,8 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "mimeType = 'application/vnd.google-apps.folder' " + "and name = '"+folder_name+"' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From a08740142c292d88fd15fb72a5f9afe32ec27b1f Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 13:33:21 +0200 Subject: [PATCH 069/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 48c5c4fb..af8814d1 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,13 +35,11 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType = 'application/vnd.google-apps.folder' " - "and name = '"+folder_name+"' and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] return None - return None def on_loaded(self): # client_secrets.json needs to be not empty From 918ce36ad7a7899b4babb23fdded4e4db4193290 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 14:46:01 +0200 Subject: [PATCH 070/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index af8814d1..8fa4b958 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,7 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "name="+folder_name+" and mimetype='application/vnd.google-apps.folder' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From 78a56fc083f0027814c145446a6bf8abc52ff0ea Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 14:48:29 +0200 Subject: [PATCH 071/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 8fa4b958..00e117aa 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -36,10 +36,9 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile({'q': "name="+folder_name+" and mimetype='application/vnd.google-apps.folder' and trashed=false"}).GetList() - for file in file_list: - if file['title'] == folder_name: - return file['id'] - return None + if 'files' in file_list and len(file_list['files']) > 0: + return file_list['files'][0]['id'] + return None def on_loaded(self): # client_secrets.json needs to be not empty From bfbba15fee0f39f89c48084846ecd0519465bb0e Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 14:50:18 +0200 Subject: [PATCH 072/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 00e117aa..203e0720 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,9 +35,12 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "name="+folder_name+" and mimetype='application/vnd.google-apps.folder' and trashed=false"}).GetList() - if 'files' in file_list and len(file_list['files']) > 0: - return file_list['files'][0]['id'] + try: + file_list = drive.ListFile({'q': "name="+folder_name+" and mimetype='application/vnd.google-apps.folder' and trashed=false"}).GetList() + if 'files' in file_list and len(file_list['files']) > 0: + return file_list['files'][0]['id'] + except Exception as e: + print(f"Error in get_folder_id_by_name: {e}") return None def on_loaded(self): From 1e7b3208e37a018e9b22c049a64f7abc0897c627 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 14:50:36 +0200 Subject: [PATCH 073/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 203e0720..823345b3 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -40,7 +40,7 @@ class GdriveSync(plugins.Plugin): if 'files' in file_list and len(file_list['files']) > 0: return file_list['files'][0]['id'] except Exception as e: - print(f"Error in get_folder_id_by_name: {e}") + logging.error(f"Error in get_folder_id_by_name: {e}") return None def on_loaded(self): From 6b64e9914660dbdd43ad8b6ea6dcf08c81dd8adc Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 14:51:59 +0200 Subject: [PATCH 074/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 823345b3..2d64b036 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -69,6 +69,7 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: + logging.info("test") # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_name = self.options['backup_folder'] backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) From f79efd37ddd71cb808aacdc9b61299ccfa0e6d15 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 14:52:37 +0200 Subject: [PATCH 075/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 2d64b036..d3027442 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -69,12 +69,12 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: - logging.info("test") # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_name = self.options['backup_folder'] backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) if not backup_folder_id: + logging.info("test") # If the folder doesn't exist, create it folder = self.drive.CreateFile( {'title': backup_folder_name, 'mimeType': 'application/vnd.google-apps.folder'}) From d24a6cd4e472c9a3daae5e83bbce6d77b53fdb1b Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 14:53:58 +0200 Subject: [PATCH 076/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index d3027442..e3605730 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -69,12 +69,13 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: + logging.info("test1") # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_name = self.options['backup_folder'] backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) + logging.info("test1.1") if not backup_folder_id: - logging.info("test") # If the folder doesn't exist, create it folder = self.drive.CreateFile( {'title': backup_folder_name, 'mimeType': 'application/vnd.google-apps.folder'}) From a08a14ac0d22931d24d62bc8f935ad619b93bb5c Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 14:55:39 +0200 Subject: [PATCH 077/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index e3605730..f2f53a0d 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -69,11 +69,9 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: - logging.info("test1") # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_name = self.options['backup_folder'] backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) - logging.info("test1.1") if not backup_folder_id: # If the folder doesn't exist, create it @@ -84,7 +82,7 @@ class GdriveSync(plugins.Plugin): print(f"Created folder '{backup_folder_name}' with ID: {backup_folder_id}") # Continue with the rest of the code using backup_folder_id - file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' in parents and trashed=false"}).GetList() + file_list = self.drive.ListFile({'q': f"name='{backup_folder_id}' and trashed=false"}).GetList() if not file_list: # Handle the case where no files were found From f1abd0495c1eb9d08a80cf3bf1a03f9eea12f768 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 14:57:46 +0200 Subject: [PATCH 078/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index f2f53a0d..80acfe91 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,13 +35,11 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - try: - file_list = drive.ListFile({'q': "name="+folder_name+" and mimetype='application/vnd.google-apps.folder' and trashed=false"}).GetList() - if 'files' in file_list and len(file_list['files']) > 0: - return file_list['files'][0]['id'] - except Exception as e: - logging.error(f"Error in get_folder_id_by_name: {e}") - return None + file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + for file in file_list: + if file['title'] == folder_name: + return file['id'] + return None def on_loaded(self): # client_secrets.json needs to be not empty @@ -82,7 +80,7 @@ class GdriveSync(plugins.Plugin): print(f"Created folder '{backup_folder_name}' with ID: {backup_folder_id}") # Continue with the rest of the code using backup_folder_id - file_list = self.drive.ListFile({'q': f"name='{backup_folder_id}' and trashed=false"}).GetList() + file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' and trashed=false"}).GetList() if not file_list: # Handle the case where no files were found From 76b34a147be999da2677adcfeca249b9f9d69cda Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:00:26 +0200 Subject: [PATCH 079/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 80acfe91..2df91d2c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -39,7 +39,7 @@ class GdriveSync(plugins.Plugin): for file in file_list: if file['title'] == folder_name: return file['id'] - return None + return None def on_loaded(self): # client_secrets.json needs to be not empty From fdf3eb195fa7c5ffc0398f63cbd46f45dc410fcc Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:02:16 +0200 Subject: [PATCH 080/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 2df91d2c..b7b7b928 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -68,7 +68,7 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored - backup_folder_name = self.options['backup_folder'] + backup_folder_name = "PwnagotchiBackups" # self.options['backup_folder'] backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) if not backup_folder_id: From 8b7088493d74a8fcf598835f2a6ad713aa9fc16d Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:03:18 +0200 Subject: [PATCH 081/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index b7b7b928..2df91d2c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -68,7 +68,7 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored - backup_folder_name = "PwnagotchiBackups" # self.options['backup_folder'] + backup_folder_name = self.options['backup_folder'] backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) if not backup_folder_id: From 2e47746f4b7226fbb33f39433b6c80dbc7ee3cd2 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:03:52 +0200 Subject: [PATCH 082/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 2df91d2c..d2c58302 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -69,6 +69,7 @@ class GdriveSync(plugins.Plugin): if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_name = self.options['backup_folder'] + logging.info(self.options['backup_folder']) backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) if not backup_folder_id: From 387cbb42cb1a400c8aeda52649457b1d53d22f93 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:04:45 +0200 Subject: [PATCH 083/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index d2c58302..10ffa124 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,6 +35,7 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): + logging.info(self.options['backup_folder']) file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: @@ -69,7 +70,6 @@ class GdriveSync(plugins.Plugin): if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_name = self.options['backup_folder'] - logging.info(self.options['backup_folder']) backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) if not backup_folder_id: From e55f08d87c5071d9282ffb7de2488bd96a420c3e Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:06:37 +0200 Subject: [PATCH 084/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 10ffa124..bd0a7282 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -35,7 +35,6 @@ class GdriveSync(plugins.Plugin): # Function to get the folder ID by its name def get_folder_id_by_name(self, drive, folder_name): - logging.info(self.options['backup_folder']) file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: @@ -43,6 +42,7 @@ class GdriveSync(plugins.Plugin): return None def on_loaded(self): + logging.info(self.options['backup_folder']) # client_secrets.json needs to be not empty if os.stat("/root/client_secrets.json").st_size == 0: logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") From e1a9a9a92deea5cf419762fe093a7f5339c4202a Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:08:19 +0200 Subject: [PATCH 085/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index bd0a7282..2df91d2c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -42,7 +42,6 @@ class GdriveSync(plugins.Plugin): return None def on_loaded(self): - logging.info(self.options['backup_folder']) # client_secrets.json needs to be not empty if os.stat("/root/client_secrets.json").st_size == 0: logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") From c839a7a4117e82d6191f673baa4667624767734f Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:09:13 +0200 Subject: [PATCH 086/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 2df91d2c..878de7a8 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -43,7 +43,7 @@ class GdriveSync(plugins.Plugin): def on_loaded(self): # client_secrets.json needs to be not empty - if os.stat("/root/client_secrets.json").st_size == 0: + if os.stat("/root/client_secrets.jso").st_size == 0: logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") return # backup file, so we know if there has been a backup made at least once before. From f9871ed7eebb157db23ef31546d68c078fb99ffc Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:12:25 +0200 Subject: [PATCH 087/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 878de7a8..5637055e 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -43,7 +43,7 @@ class GdriveSync(plugins.Plugin): def on_loaded(self): # client_secrets.json needs to be not empty - if os.stat("/root/client_secrets.jso").st_size == 0: + if os.stat("/root/client_secrets.json").st_size == 0: logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") return # backup file, so we know if there has been a backup made at least once before. @@ -135,11 +135,11 @@ class GdriveSync(plugins.Plugin): if current_timestamp - self.last_upload_timestamp >= 3600: self.last_upload_timestamp = current_timestamp logging.info("[gdrivesync] new handshake captured, backing up to gdrive") - if self.config['backupfiles'] is not None: - self.backupfiles = self.backupfiles + self.config['backupfiles'] + if self.options['backupfiles'] is not None: + self.backupfiles = self.backupfiles + self.options['backupfiles'] self.backup_files(self.backupfiles, '/backup') - self.upload_to_gdrive('/backup', 'PwnagotchiBackups') + self.upload_to_gdrive('/backup', self.options['backup_folder']) display = agent.view() display.update(force=True, new_data={'Backing up to gdrive ...'}) except Exception as e: From 1f0b6b759003120b2f3664050067cf1048361d06 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:13:42 +0200 Subject: [PATCH 088/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 5637055e..13572d87 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -163,7 +163,7 @@ class GdriveSync(plugins.Plugin): def upload_to_gdrive(self, backup_path, gdrive_folder): try: existing_folder = self.get_folder_id_by_name(self.drive, gdrive_folder) - if existing_folder: + if existing_folder is not None: folder = self.drive.CreateFile({'id': existing_folder}) else: # Create a folder on Google Drive if it doesn't exist From c37f56bbf0fe44a7a310ff7f4ae736945934c1e0 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:13:58 +0200 Subject: [PATCH 089/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 13572d87..d388ca9d 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -165,10 +165,9 @@ class GdriveSync(plugins.Plugin): existing_folder = self.get_folder_id_by_name(self.drive, gdrive_folder) if existing_folder is not None: folder = self.drive.CreateFile({'id': existing_folder}) - else: - # Create a folder on Google Drive if it doesn't exist - folder = self.drive.CreateFile({'title': gdrive_folder, 'mimeType': 'application/vnd.google-apps.folder'}) - folder.Upload() + # Create a folder on Google Drive if it doesn't exist + folder = self.drive.CreateFile({'title': gdrive_folder, 'mimeType': 'application/vnd.google-apps.folder'}) + folder.Upload() # Upload files to the created folder for root, dirs, files in os.walk(backup_path): From ae4f1340ad5dc87d4c47427ab7eab2693443ae49 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:15:32 +0200 Subject: [PATCH 090/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index d388ca9d..c94393c9 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -68,16 +68,15 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored - backup_folder_name = self.options['backup_folder'] - backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) + backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) if not backup_folder_id: # If the folder doesn't exist, create it folder = self.drive.CreateFile( - {'title': backup_folder_name, 'mimeType': 'application/vnd.google-apps.folder'}) + {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) folder.Upload() backup_folder_id = folder['id'] - print(f"Created folder '{backup_folder_name}' with ID: {backup_folder_id}") + print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") # Continue with the rest of the code using backup_folder_id file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' and trashed=false"}).GetList() @@ -89,7 +88,7 @@ class GdriveSync(plugins.Plugin): self.backupfiles = self.backupfiles + self.options['backupfiles'] self.backup_files(self.backupfiles, '/backup') - self.upload_to_gdrive('/backup', 'PwnagotchiBackups') + self.upload_to_gdrive('/backup', self.options['backup_folder']) self.backup = True # Specify the local backup path From 9b5fc8a9b38f0d1610b212c6f38fb9aac1dddf5e Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:20:54 +0200 Subject: [PATCH 091/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 114 +++++++++++------------ 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index c94393c9..3f204eab 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -50,73 +50,69 @@ class GdriveSync(plugins.Plugin): if not os.path.exists("/root/.gdrive-backup"): self.backup = False - try: - gauth = GoogleAuth(settings_file="/root/settings.yaml") - gauth.LoadCredentialsFile("/root/credentials.json") - if gauth.credentials is None: - # Authenticate if they're not there - gauth.LocalWebserverAuth() - elif gauth.access_token_expired: - # Refresh them if expired - gauth.Refresh() - gauth.SaveCredentialsFile("/root/credentials.json") - gauth.Authorize() + gauth = GoogleAuth(settings_file="/root/settings.yaml") + gauth.LoadCredentialsFile("/root/credentials.json") + if gauth.credentials is None: + # Authenticate if they're not there + gauth.LocalWebserverAuth() + elif gauth.access_token_expired: + # Refresh them if expired + gauth.Refresh() + gauth.SaveCredentialsFile("/root/credentials.json") + gauth.Authorize() - # Create GoogleDrive instance - self.drive = GoogleDrive(gauth) + # Create GoogleDrive instance + self.drive = GoogleDrive(gauth) - # if backup file does not exist, we will check for backup folder on gdrive. - if not self.backup: - # Use self.options['backup_folder'] as the folder ID where backups are stored - backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) + # if backup file does not exist, we will check for backup folder on gdrive. + if not self.backup: + # Use self.options['backup_folder'] as the folder ID where backups are stored + backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) - if not backup_folder_id: - # If the folder doesn't exist, create it - folder = self.drive.CreateFile( - {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) - folder.Upload() - backup_folder_id = folder['id'] - print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") + if not backup_folder_id: + # If the folder doesn't exist, create it + folder = self.drive.CreateFile( + {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) + folder.Upload() + backup_folder_id = folder['id'] + print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") - # Continue with the rest of the code using backup_folder_id - file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' and trashed=false"}).GetList() + # Continue with the rest of the code using backup_folder_id + file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' and trashed=false"}).GetList() - if not file_list: - # Handle the case where no files were found - logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") - if self.options['backupfiles'] is not None: - self.backupfiles = self.backupfiles + self.options['backupfiles'] - self.backup_files(self.backupfiles, '/backup') + if not file_list: + # Handle the case where no files were found + logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") + if self.options['backupfiles'] is not None: + self.backupfiles = self.backupfiles + self.options['backupfiles'] + self.backup_files(self.backupfiles, '/backup') - self.upload_to_gdrive('/backup', self.options['backup_folder']) - self.backup = True - - # Specify the local backup path - local_backup_path = '/' - - # Create the local backup directory if it doesn't exist - os.makedirs(local_backup_path, exist_ok=True) - - # Download each file in the folder - for file in file_list: - local_file_path = os.path.join(local_backup_path, file['title']) - file.GetContentFile(local_file_path) - logging.info(f"[gDriveSync] Downloaded {file['title']} from Google Drive") - - # Optionally, you can use the downloaded files as needed - # For example, you can copy them to the corresponding directories + self.upload_to_gdrive('/backup', self.options['backup_folder']) self.backup = True - with open("/root/.gdrive-backup", "w").close(): - pass # Create an empty file - # reboot so we can start opwngrid with backup id - pwnagotchi.reboot() - # all set, gdriveSync is ready to run - self.ready = True - logging.info("[gdrivesync] loaded") - except Exception as e: - logging.error(f"Error: {e}") - self.ready = False + # Specify the local backup path + local_backup_path = '/' + + # Create the local backup directory if it doesn't exist + os.makedirs(local_backup_path, exist_ok=True) + + # Download each file in the folder + for file in file_list: + local_file_path = os.path.join(local_backup_path, file['title']) + file.GetContentFile(local_file_path) + logging.info(f"[gDriveSync] Downloaded {file['title']} from Google Drive") + + # Optionally, you can use the downloaded files as needed + # For example, you can copy them to the corresponding directories + self.backup = True + with open("/root/.gdrive-backup", "w").close(): + pass # Create an empty file + # reboot so we can start opwngrid with backup id + pwnagotchi.reboot() + + # all set, gdriveSync is ready to run + self.ready = True + logging.info("[gdrivesync] loaded") def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From b6b365d624e9a4db6152505e75fba0dfdf349a0e Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:22:07 +0200 Subject: [PATCH 092/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 114 ++++++++++++----------- 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 3f204eab..c94393c9 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -50,69 +50,73 @@ class GdriveSync(plugins.Plugin): if not os.path.exists("/root/.gdrive-backup"): self.backup = False - gauth = GoogleAuth(settings_file="/root/settings.yaml") - gauth.LoadCredentialsFile("/root/credentials.json") - if gauth.credentials is None: - # Authenticate if they're not there - gauth.LocalWebserverAuth() - elif gauth.access_token_expired: - # Refresh them if expired - gauth.Refresh() - gauth.SaveCredentialsFile("/root/credentials.json") - gauth.Authorize() + try: + gauth = GoogleAuth(settings_file="/root/settings.yaml") + gauth.LoadCredentialsFile("/root/credentials.json") + if gauth.credentials is None: + # Authenticate if they're not there + gauth.LocalWebserverAuth() + elif gauth.access_token_expired: + # Refresh them if expired + gauth.Refresh() + gauth.SaveCredentialsFile("/root/credentials.json") + gauth.Authorize() - # Create GoogleDrive instance - self.drive = GoogleDrive(gauth) + # Create GoogleDrive instance + self.drive = GoogleDrive(gauth) - # if backup file does not exist, we will check for backup folder on gdrive. - if not self.backup: - # Use self.options['backup_folder'] as the folder ID where backups are stored - backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) + # if backup file does not exist, we will check for backup folder on gdrive. + if not self.backup: + # Use self.options['backup_folder'] as the folder ID where backups are stored + backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) - if not backup_folder_id: - # If the folder doesn't exist, create it - folder = self.drive.CreateFile( - {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) - folder.Upload() - backup_folder_id = folder['id'] - print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") + if not backup_folder_id: + # If the folder doesn't exist, create it + folder = self.drive.CreateFile( + {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) + folder.Upload() + backup_folder_id = folder['id'] + print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") - # Continue with the rest of the code using backup_folder_id - file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' and trashed=false"}).GetList() + # Continue with the rest of the code using backup_folder_id + file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' and trashed=false"}).GetList() - if not file_list: - # Handle the case where no files were found - logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") - if self.options['backupfiles'] is not None: - self.backupfiles = self.backupfiles + self.options['backupfiles'] - self.backup_files(self.backupfiles, '/backup') + if not file_list: + # Handle the case where no files were found + logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") + if self.options['backupfiles'] is not None: + self.backupfiles = self.backupfiles + self.options['backupfiles'] + self.backup_files(self.backupfiles, '/backup') - self.upload_to_gdrive('/backup', self.options['backup_folder']) + self.upload_to_gdrive('/backup', self.options['backup_folder']) + self.backup = True + + # Specify the local backup path + local_backup_path = '/' + + # Create the local backup directory if it doesn't exist + os.makedirs(local_backup_path, exist_ok=True) + + # Download each file in the folder + for file in file_list: + local_file_path = os.path.join(local_backup_path, file['title']) + file.GetContentFile(local_file_path) + logging.info(f"[gDriveSync] Downloaded {file['title']} from Google Drive") + + # Optionally, you can use the downloaded files as needed + # For example, you can copy them to the corresponding directories self.backup = True + with open("/root/.gdrive-backup", "w").close(): + pass # Create an empty file + # reboot so we can start opwngrid with backup id + pwnagotchi.reboot() - # Specify the local backup path - local_backup_path = '/' - - # Create the local backup directory if it doesn't exist - os.makedirs(local_backup_path, exist_ok=True) - - # Download each file in the folder - for file in file_list: - local_file_path = os.path.join(local_backup_path, file['title']) - file.GetContentFile(local_file_path) - logging.info(f"[gDriveSync] Downloaded {file['title']} from Google Drive") - - # Optionally, you can use the downloaded files as needed - # For example, you can copy them to the corresponding directories - self.backup = True - with open("/root/.gdrive-backup", "w").close(): - pass # Create an empty file - # reboot so we can start opwngrid with backup id - pwnagotchi.reboot() - - # all set, gdriveSync is ready to run - self.ready = True - logging.info("[gdrivesync] loaded") + # all set, gdriveSync is ready to run + self.ready = True + logging.info("[gdrivesync] loaded") + except Exception as e: + logging.error(f"Error: {e}") + self.ready = False def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From dbe772a43d2d5cf92e34c9f472b85c040579c8fb Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:23:21 +0200 Subject: [PATCH 093/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index c94393c9..99e216c5 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -42,6 +42,7 @@ class GdriveSync(plugins.Plugin): return None def on_loaded(self): + print("loading ...") # client_secrets.json needs to be not empty if os.stat("/root/client_secrets.json").st_size == 0: logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") From ec68cbef7a33784b59c63ff6d9babdbce9116a49 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:23:36 +0200 Subject: [PATCH 094/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 99e216c5..90aad376 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -43,6 +43,7 @@ class GdriveSync(plugins.Plugin): def on_loaded(self): print("loading ...") + logging.info("loading ..") # client_secrets.json needs to be not empty if os.stat("/root/client_secrets.json").st_size == 0: logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") From 4be6253a03636e54276b4509502b97f3645572d6 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:24:30 +0200 Subject: [PATCH 095/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 90aad376..c94393c9 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -42,8 +42,6 @@ class GdriveSync(plugins.Plugin): return None def on_loaded(self): - print("loading ...") - logging.info("loading ..") # client_secrets.json needs to be not empty if os.stat("/root/client_secrets.json").st_size == 0: logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") From cbbda89abdfe0f9ec3e1a1712bc003c91781efc2 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:25:13 +0200 Subject: [PATCH 096/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index c94393c9..500b0dea 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -33,14 +33,6 @@ class GdriveSync(plugins.Plugin): '/etc/pwnagotchi' ] - # Function to get the folder ID by its name - def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() - for file in file_list: - if file['title'] == folder_name: - return file['id'] - return None - def on_loaded(self): # client_secrets.json needs to be not empty if os.stat("/root/client_secrets.json").st_size == 0: @@ -118,6 +110,13 @@ class GdriveSync(plugins.Plugin): logging.error(f"Error: {e}") self.ready = False + def get_folder_id_by_name(self, drive, folder_name): + file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + for file in file_list: + if file['title'] == folder_name: + return file['id'] + return None + def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From 406365a44a2bd420925325494fbf596a3e2850b2 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:29:26 +0200 Subject: [PATCH 097/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 500b0dea..33fc0d1c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -43,6 +43,7 @@ class GdriveSync(plugins.Plugin): self.backup = False try: + logging.error("TEST!!") gauth = GoogleAuth(settings_file="/root/settings.yaml") gauth.LoadCredentialsFile("/root/credentials.json") if gauth.credentials is None: From 2dab188525e1d6a8099ebcb01f144b136a2f3df2 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:30:15 +0200 Subject: [PATCH 098/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 33fc0d1c..500b0dea 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -43,7 +43,6 @@ class GdriveSync(plugins.Plugin): self.backup = False try: - logging.error("TEST!!") gauth = GoogleAuth(settings_file="/root/settings.yaml") gauth.LoadCredentialsFile("/root/credentials.json") if gauth.credentials is None: From a06ac41c486b819eb43f74ff15fd307f9c5cfa8e Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:30:56 +0200 Subject: [PATCH 099/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 76 +----------------------- 1 file changed, 1 insertion(+), 75 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 500b0dea..a6c62837 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -34,81 +34,7 @@ class GdriveSync(plugins.Plugin): ] def on_loaded(self): - # client_secrets.json needs to be not empty - if os.stat("/root/client_secrets.json").st_size == 0: - logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") - return - # backup file, so we know if there has been a backup made at least once before. - if not os.path.exists("/root/.gdrive-backup"): - self.backup = False - - try: - gauth = GoogleAuth(settings_file="/root/settings.yaml") - gauth.LoadCredentialsFile("/root/credentials.json") - if gauth.credentials is None: - # Authenticate if they're not there - gauth.LocalWebserverAuth() - elif gauth.access_token_expired: - # Refresh them if expired - gauth.Refresh() - gauth.SaveCredentialsFile("/root/credentials.json") - gauth.Authorize() - - # Create GoogleDrive instance - self.drive = GoogleDrive(gauth) - - # if backup file does not exist, we will check for backup folder on gdrive. - if not self.backup: - # Use self.options['backup_folder'] as the folder ID where backups are stored - backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) - - if not backup_folder_id: - # If the folder doesn't exist, create it - folder = self.drive.CreateFile( - {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) - folder.Upload() - backup_folder_id = folder['id'] - print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") - - # Continue with the rest of the code using backup_folder_id - file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' and trashed=false"}).GetList() - - if not file_list: - # Handle the case where no files were found - logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") - if self.options['backupfiles'] is not None: - self.backupfiles = self.backupfiles + self.options['backupfiles'] - self.backup_files(self.backupfiles, '/backup') - - self.upload_to_gdrive('/backup', self.options['backup_folder']) - self.backup = True - - # Specify the local backup path - local_backup_path = '/' - - # Create the local backup directory if it doesn't exist - os.makedirs(local_backup_path, exist_ok=True) - - # Download each file in the folder - for file in file_list: - local_file_path = os.path.join(local_backup_path, file['title']) - file.GetContentFile(local_file_path) - logging.info(f"[gDriveSync] Downloaded {file['title']} from Google Drive") - - # Optionally, you can use the downloaded files as needed - # For example, you can copy them to the corresponding directories - self.backup = True - with open("/root/.gdrive-backup", "w").close(): - pass # Create an empty file - # reboot so we can start opwngrid with backup id - pwnagotchi.reboot() - - # all set, gdriveSync is ready to run - self.ready = True - logging.info("[gdrivesync] loaded") - except Exception as e: - logging.error(f"Error: {e}") - self.ready = False + logging.info("[gdrivesync] loaded") def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() From 09552c89e6b2cb625baf57536f52bc5d2bf1cad8 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:31:48 +0200 Subject: [PATCH 100/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 76 +++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index a6c62837..500b0dea 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -34,7 +34,81 @@ class GdriveSync(plugins.Plugin): ] def on_loaded(self): - logging.info("[gdrivesync] loaded") + # client_secrets.json needs to be not empty + if os.stat("/root/client_secrets.json").st_size == 0: + logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") + return + # backup file, so we know if there has been a backup made at least once before. + if not os.path.exists("/root/.gdrive-backup"): + self.backup = False + + try: + gauth = GoogleAuth(settings_file="/root/settings.yaml") + gauth.LoadCredentialsFile("/root/credentials.json") + if gauth.credentials is None: + # Authenticate if they're not there + gauth.LocalWebserverAuth() + elif gauth.access_token_expired: + # Refresh them if expired + gauth.Refresh() + gauth.SaveCredentialsFile("/root/credentials.json") + gauth.Authorize() + + # Create GoogleDrive instance + self.drive = GoogleDrive(gauth) + + # if backup file does not exist, we will check for backup folder on gdrive. + if not self.backup: + # Use self.options['backup_folder'] as the folder ID where backups are stored + backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) + + if not backup_folder_id: + # If the folder doesn't exist, create it + folder = self.drive.CreateFile( + {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) + folder.Upload() + backup_folder_id = folder['id'] + print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") + + # Continue with the rest of the code using backup_folder_id + file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' and trashed=false"}).GetList() + + if not file_list: + # Handle the case where no files were found + logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") + if self.options['backupfiles'] is not None: + self.backupfiles = self.backupfiles + self.options['backupfiles'] + self.backup_files(self.backupfiles, '/backup') + + self.upload_to_gdrive('/backup', self.options['backup_folder']) + self.backup = True + + # Specify the local backup path + local_backup_path = '/' + + # Create the local backup directory if it doesn't exist + os.makedirs(local_backup_path, exist_ok=True) + + # Download each file in the folder + for file in file_list: + local_file_path = os.path.join(local_backup_path, file['title']) + file.GetContentFile(local_file_path) + logging.info(f"[gDriveSync] Downloaded {file['title']} from Google Drive") + + # Optionally, you can use the downloaded files as needed + # For example, you can copy them to the corresponding directories + self.backup = True + with open("/root/.gdrive-backup", "w").close(): + pass # Create an empty file + # reboot so we can start opwngrid with backup id + pwnagotchi.reboot() + + # all set, gdriveSync is ready to run + self.ready = True + logging.info("[gdrivesync] loaded") + except Exception as e: + logging.error(f"Error: {e}") + self.ready = False def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() From 708e670a13d3ad4b1d16f7e1b327a215a54cf1e8 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:34:52 +0200 Subject: [PATCH 101/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 500b0dea..9a26afb8 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -34,6 +34,7 @@ class GdriveSync(plugins.Plugin): ] def on_loaded(self): + logging.info("TEST") # client_secrets.json needs to be not empty if os.stat("/root/client_secrets.json").st_size == 0: logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") From 4ebdbc2205d66e19e975c3839662b02c67e97bf6 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:37:36 +0200 Subject: [PATCH 102/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 9a26afb8..500b0dea 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -34,7 +34,6 @@ class GdriveSync(plugins.Plugin): ] def on_loaded(self): - logging.info("TEST") # client_secrets.json needs to be not empty if os.stat("/root/client_secrets.json").st_size == 0: logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") From 0c9c83eaba790d0397676bb87aaad85047be8b3d Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:39:14 +0200 Subject: [PATCH 103/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 500b0dea..0f46cdd4 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -114,7 +114,7 @@ class GdriveSync(plugins.Plugin): file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: - return file['id'] + return "test" return None def on_unload(self, ui): From 2bbc18b6938d37c65c3e47c6aa7975ee5faa3f07 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:40:10 +0200 Subject: [PATCH 104/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 0f46cdd4..500b0dea 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -114,7 +114,7 @@ class GdriveSync(plugins.Plugin): file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: - return "test" + return file['id'] return None def on_unload(self, ui): From c2ba09d3dfb318b09e48515c67374348072c1c93 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:42:44 +0200 Subject: [PATCH 105/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 500b0dea..b933397b 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,11 +111,11 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "name="+folder_name+" and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] - return None + return None def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From d6f5cefe32e19a166dc0ebe7e27dc0822f218098 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:45:40 +0200 Subject: [PATCH 106/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index b933397b..d3f36e3a 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -115,7 +115,7 @@ class GdriveSync(plugins.Plugin): for file in file_list: if file['title'] == folder_name: return file['id'] - return None + return None def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From c3e5b3ea716dcaae43dd2b4fc1b64c10c47c97d6 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:46:48 +0200 Subject: [PATCH 107/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index d3f36e3a..3661ea28 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,8 +111,11 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "name="+folder_name+" and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + query = f"name='{folder_name}' and mimeType='application/vnd.google-apps.folder' and trashed=false" + file_list = drive.ListFile({'q': query}).GetList() + print(f"Query: {query}") for file in file_list: + print(f"File Title: {file['title']}, Expected Folder Name: {folder_name}") if file['title'] == folder_name: return file['id'] return None From 48f658a0591bfd09619b76f3b527b8dd5c3b8150 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:47:51 +0200 Subject: [PATCH 108/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 3661ea28..facd41d5 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,7 +111,7 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - query = f"name='{folder_name}' and mimeType='application/vnd.google-apps.folder' and trashed=false" + query = f"name=\"{folder_name}\" and mimeType='application/vnd.google-apps.folder' and trashed=false" file_list = drive.ListFile({'q': query}).GetList() print(f"Query: {query}") for file in file_list: From 37dd828377a031debd5356c311a64277539588f4 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:49:53 +0200 Subject: [PATCH 109/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index facd41d5..50d7433b 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,7 +111,7 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - query = f"name=\"{folder_name}\" and mimeType='application/vnd.google-apps.folder' and trashed=false" + query = f"'{folder_name}' in title and mimeType='application/vnd.google-apps.folder' and trashed=false" file_list = drive.ListFile({'q': query}).GetList() print(f"Query: {query}") for file in file_list: From f2eb90501e24d8907766aa2c6e9300f070ad1423 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:51:25 +0200 Subject: [PATCH 110/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 50d7433b..930840b6 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,14 +111,11 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - query = f"'{folder_name}' in title and mimeType='application/vnd.google-apps.folder' and trashed=false" - file_list = drive.ListFile({'q': query}).GetList() - print(f"Query: {query}") - for file in file_list: - print(f"File Title: {file['title']}, Expected Folder Name: {folder_name}") - if file['title'] == folder_name: - return file['id'] - return None + try: + folder = drive.ListFile({'q': f"title='{folder_name}' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList()[0] + return folder['id'] + except IndexError: + return None def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From 75b16b602da6b8f65a9a8bbd6f9b06c0231a329f Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:52:37 +0200 Subject: [PATCH 111/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 930840b6..d3f36e3a 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,11 +111,11 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - try: - folder = drive.ListFile({'q': f"title='{folder_name}' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList()[0] - return folder['id'] - except IndexError: - return None + file_list = drive.ListFile({'q': "name="+folder_name+" and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + for file in file_list: + if file['title'] == folder_name: + return file['id'] + return None def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From 5061b884a49e0a0d194b13166dc2f3c6392b6c73 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 15:52:47 +0200 Subject: [PATCH 112/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index d3f36e3a..500b0dea 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,7 +111,7 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "name="+folder_name+" and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From 463aa0bcab8ae002a247e0c426e3e78cf54be8b7 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:02:00 +0200 Subject: [PATCH 113/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 500b0dea..a40ee2ca 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,10 +111,15 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() - for file in file_list: - if file['title'] == folder_name: - return file['id'] + file_list = drive.ListFile( + { + 'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false", + 'corpora': 'allDrives', + 'includeItemsFromAllDrives': True, + 'supportsAllDrives': True, + }).GetList() + if file_list: + return file_list[0]['id'] return None def on_unload(self, ui): From 1a2c6e84b44ab3cf129a5b3af55e292f0f7bf64b Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:03:10 +0200 Subject: [PATCH 114/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index a40ee2ca..64c14292 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -112,12 +112,7 @@ class GdriveSync(plugins.Plugin): def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile( - { - 'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false", - 'corpora': 'allDrives', - 'includeItemsFromAllDrives': True, - 'supportsAllDrives': True, - }).GetList() + {'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() if file_list: return file_list[0]['id'] return None From 63635c9b9b6f4455be214ca435cf33e860c45309 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:06:23 +0200 Subject: [PATCH 115/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 64c14292..109e56e3 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -112,8 +112,13 @@ class GdriveSync(plugins.Plugin): def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile( - {'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() - if file_list: + { + 'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false", + 'corpora': 'allDrives', + 'includeItemsFromAllDrives': True, + 'supportsAllDrives': True, + }).GetList() + if file_list != []: return file_list[0]['id'] return None From 07a58b039a07b397c027c3dad1ec8728685aa2c0 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:07:13 +0200 Subject: [PATCH 116/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 109e56e3..64c14292 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -112,13 +112,8 @@ class GdriveSync(plugins.Plugin): def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile( - { - 'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false", - 'corpora': 'allDrives', - 'includeItemsFromAllDrives': True, - 'supportsAllDrives': True, - }).GetList() - if file_list != []: + {'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + if file_list: return file_list[0]['id'] return None From 1b0ca1b3273e7170f803fead0093494a174c3c4e Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:07:53 +0200 Subject: [PATCH 117/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 64c14292..1157a609 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,8 +111,10 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): + logging.info("test") file_list = drive.ListFile( {'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + logging.info("test2") if file_list: return file_list[0]['id'] return None From 8e90cd0d1c3a69082272aa541bfa0f187a0c362a Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:09:26 +0200 Subject: [PATCH 118/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 1157a609..579bf90c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,12 +111,12 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - logging.info("test") file_list = drive.ListFile( {'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() - logging.info("test2") if file_list: + logging.info("test") return file_list[0]['id'] + logging.info("test2") return None def on_unload(self, ui): From 3d28d1eac0a8f382f2a27da4af5f5954e1f203ac Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:12:49 +0200 Subject: [PATCH 119/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 579bf90c..7c8e7376 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -61,6 +61,7 @@ class GdriveSync(plugins.Plugin): if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) + logging.info("test1") if not backup_folder_id: # If the folder doesn't exist, create it @@ -114,9 +115,7 @@ class GdriveSync(plugins.Plugin): file_list = drive.ListFile( {'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() if file_list: - logging.info("test") return file_list[0]['id'] - logging.info("test2") return None def on_unload(self, ui): From 4a91d698c9fe59eea8f78d440f8dab9c16ea7dff Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:14:06 +0200 Subject: [PATCH 120/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 7c8e7376..e2827ea4 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -61,12 +61,13 @@ class GdriveSync(plugins.Plugin): if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) - logging.info("test1") if not backup_folder_id: # If the folder doesn't exist, create it + logging.info("test") folder = self.drive.CreateFile( {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) + logging.info("test2") folder.Upload() backup_folder_id = folder['id'] print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") From 125f3976f50367969bf5e9936e705659d4168572 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:16:10 +0200 Subject: [PATCH 121/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index e2827ea4..793ab87d 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -61,13 +61,13 @@ class GdriveSync(plugins.Plugin): if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) - - if not backup_folder_id: + logging.info("test1") + if backup_folder_id is None: # If the folder doesn't exist, create it - logging.info("test") + logging.info("test2") folder = self.drive.CreateFile( {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) - logging.info("test2") + logging.info("test3") folder.Upload() backup_folder_id = folder['id'] print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") From d5c914b19b546b0d8c7ef0b3c245fc283c186661 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:18:57 +0200 Subject: [PATCH 122/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 793ab87d..93f096a9 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -61,13 +61,10 @@ class GdriveSync(plugins.Plugin): if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) - logging.info("test1") if backup_folder_id is None: # If the folder doesn't exist, create it - logging.info("test2") folder = self.drive.CreateFile( {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) - logging.info("test3") folder.Upload() backup_folder_id = folder['id'] print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") From b25887f0811df405d8524d4f68ea0dc6ea1780f8 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:21:25 +0200 Subject: [PATCH 123/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 93f096a9..0c784ae9 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -61,6 +61,7 @@ class GdriveSync(plugins.Plugin): if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) + logging.info(self.options['backup_folder']) if backup_folder_id is None: # If the folder doesn't exist, create it folder = self.drive.CreateFile( From 568a863490f50f6d301698f61757f4b568a2b4ba Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:22:12 +0200 Subject: [PATCH 124/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 0c784ae9..93f096a9 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -61,7 +61,6 @@ class GdriveSync(plugins.Plugin): if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) - logging.info(self.options['backup_folder']) if backup_folder_id is None: # If the folder doesn't exist, create it folder = self.drive.CreateFile( From bf03039df020b615a4546c2f032165c74833715f Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:25:22 +0200 Subject: [PATCH 125/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 93f096a9..049ab015 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -61,7 +61,7 @@ class GdriveSync(plugins.Plugin): if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) - if backup_folder_id is None: + if not backup_folder_id: # If the folder doesn't exist, create it folder = self.drive.CreateFile( {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) From 919e0c07f23869b79a61a8622cafea7fae6de00e Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:25:34 +0200 Subject: [PATCH 126/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 049ab015..93f096a9 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -61,7 +61,7 @@ class GdriveSync(plugins.Plugin): if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) - if not backup_folder_id: + if backup_folder_id is None: # If the folder doesn't exist, create it folder = self.drive.CreateFile( {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) From 8f8406164e05bb8431963c0bdfabd6a8ce42e40c Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 18:26:51 +0200 Subject: [PATCH 127/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 93f096a9..68893c3f 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,7 +111,7 @@ class GdriveSync(plugins.Plugin): def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile( - {'q': "title='" + folder_name + "' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + {'q': "title='"+folder_name+"' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() if file_list: return file_list[0]['id'] return None From 70d9de09801ee4a7584869563dbcf40e5c418acc Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 20:28:10 +0200 Subject: [PATCH 128/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 68893c3f..b1158899 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -67,7 +67,7 @@ class GdriveSync(plugins.Plugin): {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) folder.Upload() backup_folder_id = folder['id'] - print(f"Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") + logging.info(f"[gDriveSync] Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") # Continue with the rest of the code using backup_folder_id file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' and trashed=false"}).GetList() @@ -140,7 +140,7 @@ class GdriveSync(plugins.Plugin): display = agent.view() display.update(force=True, new_data={'Backing up to gdrive ...'}) except Exception as e: - logging.error(f"Error during handshake processing: {e}") + logging.error(f"[gDriveSync] Error during handshake processing: {e}") def backup_files(self, paths, dest_path): for src_path in paths: @@ -155,7 +155,7 @@ class GdriveSync(plugins.Plugin): else: shutil.copy2(src_path, dest) except Exception as e: - logging.error(f"Error during backup_path: {e}") + logging.error(f"[gDriveSync] Error during backup_path: {e}") def upload_to_gdrive(self, backup_path, gdrive_folder): try: @@ -179,7 +179,7 @@ class GdriveSync(plugins.Plugin): self.handle_upload_error(api_error, backup_path, gdrive_folder) except Exception as e: - logging.error(f"Error during upload_to_gdrive: {e}") + logging.error(f"[gDriveSync] Error during upload_to_gdrive: {e}") def handle_upload_error(self, api_error, backup_path, gdrive_folder): if 'Rate Limit Exceeded' in str(api_error): From 23779543ed25bd6eb11e18a5f07e51c4d5bd8444 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 20:33:06 +0200 Subject: [PATCH 129/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index b1158899..f15e4125 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,7 +111,7 @@ class GdriveSync(plugins.Plugin): def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile( - {'q': "title='"+folder_name+"' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() if file_list: return file_list[0]['id'] return None From 902c49437e2d454c1ef8b4b9f432fe237105c183 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 20:34:03 +0200 Subject: [PATCH 130/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index f15e4125..ee943398 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,7 +111,7 @@ class GdriveSync(plugins.Plugin): def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile( - {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + {'q': "'"+folder_name+"' mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() if file_list: return file_list[0]['id'] return None From 5ec31f3febc593224accbb6e183e55646088e9c9 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 20:34:52 +0200 Subject: [PATCH 131/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index ee943398..9ce16893 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,7 +111,7 @@ class GdriveSync(plugins.Plugin): def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile( - {'q': "'"+folder_name+"' mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + {'q': "'"+folder_name+"' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() if file_list: return file_list[0]['id'] return None From 4c8267796a1a82af9c770950e1346d8e3b4659a5 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 20:35:54 +0200 Subject: [PATCH 132/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 9ce16893..f15e4125 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -111,7 +111,7 @@ class GdriveSync(plugins.Plugin): def get_folder_id_by_name(self, drive, folder_name): file_list = drive.ListFile( - {'q': "'"+folder_name+"' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() if file_list: return file_list[0]['id'] return None From 1344330eee3761773cd243736e7240d7f07330d2 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 20:43:38 +0200 Subject: [PATCH 133/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index f15e4125..1b18cd0c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -110,11 +110,14 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile( - {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() - if file_list: - return file_list[0]['id'] - return None + try: + file_list = drive.ListFile( + {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + if file_list: + return file_list[0]['id'] + except pydrive2.files.FileNotDownloadableError: + logging.warning("Folder does not exist ..") + return None def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From a6e66ce3ff66c921c7dc2156f57d17a824318d05 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 20:44:54 +0200 Subject: [PATCH 134/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 1b18cd0c..87c07066 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -113,11 +113,11 @@ class GdriveSync(plugins.Plugin): try: file_list = drive.ListFile( {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() - if file_list: - return file_list[0]['id'] except pydrive2.files.FileNotDownloadableError: logging.warning("Folder does not exist ..") return None + if file_list: + return file_list[0]['id'] def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From 6734018d3c1fa7a39dd0a5d68482f2842efb3a25 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 20:45:55 +0200 Subject: [PATCH 135/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 87c07066..f15e4125 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -110,14 +110,11 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - try: - file_list = drive.ListFile( - {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() - except pydrive2.files.FileNotDownloadableError: - logging.warning("Folder does not exist ..") - return None + file_list = drive.ListFile( + {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() if file_list: return file_list[0]['id'] + return None def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From 864847f4190b7ca32fee02ef69c33c81c731edea Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 20:56:28 +0200 Subject: [PATCH 136/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index f15e4125..674981fd 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -7,6 +7,7 @@ import pwnagotchi import pydrive2 from pydrive2.auth import GoogleAuth from pydrive2.drive import GoogleDrive +from pwnagotchi.google import cmd as google_cmd class GdriveSync(plugins.Plugin): @@ -45,14 +46,8 @@ class GdriveSync(plugins.Plugin): try: gauth = GoogleAuth(settings_file="/root/settings.yaml") gauth.LoadCredentialsFile("/root/credentials.json") - if gauth.credentials is None: - # Authenticate if they're not there - gauth.LocalWebserverAuth() - elif gauth.access_token_expired: - # Refresh them if expired - gauth.Refresh() - gauth.SaveCredentialsFile("/root/credentials.json") gauth.Authorize() + gauth.SaveCredentialsFile("/root/credentials.json") # Create GoogleDrive instance self.drive = GoogleDrive(gauth) From c6dc22a5100451ab1c30b1d20958dbf90ab5d502 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 20:59:18 +0200 Subject: [PATCH 137/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 674981fd..ef47fc26 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -105,10 +105,10 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile( - {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() - if file_list: - return file_list[0]['id'] + file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList() + for file in file_list: + if file['title'] == folder_name: + return file['id'] return None def on_unload(self, ui): From 1bf9d1cb54a31a521fd6eb440120bc04a3a6d298 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 21:00:28 +0200 Subject: [PATCH 138/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index ef47fc26..36f1403a 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -105,7 +105,7 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From 2b08fa9ffb143c3334a31a42c3e6aaede3143e94 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 21:01:21 +0200 Subject: [PATCH 139/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 36f1403a..ef47fc26 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -105,7 +105,7 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] From c9de33b6e0ffbb3b8214470002195d082a8cd0cc Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 21:03:38 +0200 Subject: [PATCH 140/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index ef47fc26..674981fd 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -105,10 +105,10 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList() - for file in file_list: - if file['title'] == folder_name: - return file['id'] + file_list = drive.ListFile( + {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + if file_list: + return file_list[0]['id'] return None def on_unload(self, ui): From b98c1e10e34cf4d6ff31c0cdfa1b3b386ebdd2e0 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 21:17:21 +0200 Subject: [PATCH 141/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 674981fd..10c5834e 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -105,10 +105,10 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile( - {'q': "'"+folder_name+"' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() - if file_list: - return file_list[0]['id'] + file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + for file in file_list: + if file['title'] == folder_name: + return file['id'] return None def on_unload(self, ui): From eab3f1c222d0f16b688dd333c2fdeb8bbff7edcd Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 14 Oct 2023 07:43:34 +0200 Subject: [PATCH 142/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 10c5834e..faa46d5e 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -7,7 +7,6 @@ import pwnagotchi import pydrive2 from pydrive2.auth import GoogleAuth from pydrive2.drive import GoogleDrive -from pwnagotchi.google import cmd as google_cmd class GdriveSync(plugins.Plugin): @@ -46,8 +45,14 @@ class GdriveSync(plugins.Plugin): try: gauth = GoogleAuth(settings_file="/root/settings.yaml") gauth.LoadCredentialsFile("/root/credentials.json") - gauth.Authorize() + if gauth.credentials is None: + # Authenticate if they're not there + gauth.LocalWebserverAuth() + elif gauth.access_token_expired: + # Refresh them if expired + gauth.Refresh() gauth.SaveCredentialsFile("/root/credentials.json") + gauth.Authorize() # Create GoogleDrive instance self.drive = GoogleDrive(gauth) @@ -109,7 +114,7 @@ class GdriveSync(plugins.Plugin): for file in file_list: if file['title'] == folder_name: return file['id'] - return None + return None def on_unload(self, ui): logging.info("[gdrivesync] unloaded") From 6362ea5aed7cabb8214c609f65f7c5f338cb83e5 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 14 Oct 2023 19:59:10 +0200 Subject: [PATCH 143/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- .../etc/pwnagotchi/conf.d/gdrivesync.toml | 3 +- pwnagotchi/plugins/default/gdrivesync.py | 51 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/builder/data/etc/pwnagotchi/conf.d/gdrivesync.toml b/builder/data/etc/pwnagotchi/conf.d/gdrivesync.toml index a599372c..f5a3b65c 100644 --- a/builder/data/etc/pwnagotchi/conf.d/gdrivesync.toml +++ b/builder/data/etc/pwnagotchi/conf.d/gdrivesync.toml @@ -1,3 +1,4 @@ main.plugins.gdrivesync.enabled = false main.plugins.gdrivesync.backupfiles = [''] -main.plugins.gdrivesync.backup_folder = "PwnagotchiBackups" \ No newline at end of file +main.plugins.gdrivesync.backup_folder = "PwnagotchiBackups" +main.plugin.gdrivesync.interval = 1 \ No newline at end of file diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index faa46d5e..11b8df6c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -7,6 +7,8 @@ import pwnagotchi import pydrive2 from pydrive2.auth import GoogleAuth from pydrive2.drive import GoogleDrive +from threading import Lock +from pwnagotchi.utils import StatusFile, parse_version as version_to_tuple class GdriveSync(plugins.Plugin): @@ -19,17 +21,14 @@ class GdriveSync(plugins.Plugin): } def __init__(self): + self.lock = Lock() self.internet = False self.ready = False self.drive = None - self.last_upload_timestamp = time.time() + self.status = StatusFile('/root/.gdrive-backup') self.backup = True self.backupfiles = [ - '/root/brain.nn', - '/root/brain.json', - '/root/.api-report.json', - '/root/handshakes', - '/root/peers', + '/root', '/etc/pwnagotchi' ] @@ -70,7 +69,7 @@ class GdriveSync(plugins.Plugin): logging.info(f"[gDriveSync] Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") # Continue with the rest of the code using backup_folder_id - file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' and trashed=false"}).GetList() + file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() if not file_list: # Handle the case where no files were found @@ -97,8 +96,7 @@ class GdriveSync(plugins.Plugin): # Optionally, you can use the downloaded files as needed # For example, you can copy them to the corresponding directories self.backup = True - with open("/root/.gdrive-backup", "w").close(): - pass # Create an empty file + self.status.update() # reboot so we can start opwngrid with backup id pwnagotchi.reboot() @@ -123,24 +121,27 @@ class GdriveSync(plugins.Plugin): self.internet = True def on_handshake(self, agent): - if not self.ready: + if self.lock.locked(): return - try: - if self.internet: - current_timestamp = time.time() - # Check if an hour has passed since the last upload - if current_timestamp - self.last_upload_timestamp >= 3600: - self.last_upload_timestamp = current_timestamp - logging.info("[gdrivesync] new handshake captured, backing up to gdrive") - if self.options['backupfiles'] is not None: - self.backupfiles = self.backupfiles + self.options['backupfiles'] - self.backup_files(self.backupfiles, '/backup') + with self.lock: + if not self.ready and not self.internet: + return + try: + if self.status.newer_then_hours(self.options['interval']): + logging.debug("[update] last check happened less than %d hours ago" % self.options['interval']) + return - self.upload_to_gdrive('/backup', self.options['backup_folder']) - display = agent.view() - display.update(force=True, new_data={'Backing up to gdrive ...'}) - except Exception as e: - logging.error(f"[gDriveSync] Error during handshake processing: {e}") + logging.info("[gdrivesync] new handshake captured, backing up to gdrive") + if self.options['backupfiles'] is not None: + self.backupfiles = self.backupfiles + self.options['backupfiles'] + self.backup_files(self.backupfiles, '/backup') + + self.upload_to_gdrive('/backup', self.options['backup_folder']) + self.status.update() + display = agent.view() + display.update(force=True, new_data={'Backing up to gdrive ...'}) + except Exception as e: + logging.error(f"[gDriveSync] Error during handshake processing: {e}") def backup_files(self, paths, dest_path): for src_path in paths: From 26228766dbbb58f2ad788fa317f4a38df7bfbf82 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 14 Oct 2023 20:09:59 +0200 Subject: [PATCH 144/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 11b8df6c..6f003d36 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -163,19 +163,20 @@ class GdriveSync(plugins.Plugin): existing_folder = self.get_folder_id_by_name(self.drive, gdrive_folder) if existing_folder is not None: folder = self.drive.CreateFile({'id': existing_folder}) - # Create a folder on Google Drive if it doesn't exist - folder = self.drive.CreateFile({'title': gdrive_folder, 'mimeType': 'application/vnd.google-apps.folder'}) - folder.Upload() # Upload files to the created folder + uploaded_files_count = 0 for root, dirs, files in os.walk(backup_path): for filename in files: file_path = os.path.join(root, filename) - gdrive_file = self.drive.CreateFile({'title': filename, 'parents': [{'id': folder['id']}]}) + relative_path = os.path.relpath(file_path, backup_path) + gdrive_file = self.drive.CreateFile( + {'title': os.path.join(gdrive_folder, relative_path), 'parents': [{'id': folder['id']}]}) gdrive_file.Upload() - logging.info(f"[gDriveSync] Uploaded {file_path} to Google Drive") + uploaded_files_count += 1 + # Print the number of uploaded files + logging.info(f"[gDriveSync] Uploaded {uploaded_files_count} files to Google Drive") - logging.info(f"[gDriveSync] Backup uploaded to Google Drive") except pydrive2.files.ApiRequestError as api_error: self.handle_upload_error(api_error, backup_path, gdrive_folder) From ba58e84aa7b20b92b919fc61bf91e04813c74070 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 14 Oct 2023 20:18:50 +0200 Subject: [PATCH 145/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 6f003d36..69687860 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -73,7 +73,7 @@ class GdriveSync(plugins.Plugin): if not file_list: # Handle the case where no files were found - logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") + # logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") if self.options['backupfiles'] is not None: self.backupfiles = self.backupfiles + self.options['backupfiles'] self.backup_files(self.backupfiles, '/backup') @@ -164,16 +164,18 @@ class GdriveSync(plugins.Plugin): if existing_folder is not None: folder = self.drive.CreateFile({'id': existing_folder}) - # Upload files to the created folder + # Upload Files to the Created Folder uploaded_files_count = 0 for root, dirs, files in os.walk(backup_path): for filename in files: file_path = os.path.join(root, filename) relative_path = os.path.relpath(file_path, backup_path) - gdrive_file = self.drive.CreateFile( - {'title': os.path.join(gdrive_folder, relative_path), 'parents': [{'id': folder['id']}]}) + # Remove the directory part from the filename + relative_filename = os.path.join(gdrive_folder, relative_path, filename) + gdrive_file = self.drive.CreateFile({'title': relative_filename, 'parents': [{'id': folder['id']}]}) gdrive_file.Upload() uploaded_files_count += 1 + # Print the number of uploaded files logging.info(f"[gDriveSync] Uploaded {uploaded_files_count} files to Google Drive") From 8e8d95fc2b28352decab55be6be3e8c8190ca8ac Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 14 Oct 2023 20:19:40 +0200 Subject: [PATCH 146/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 69687860..a1bc4fb1 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -174,6 +174,7 @@ class GdriveSync(plugins.Plugin): relative_filename = os.path.join(gdrive_folder, relative_path, filename) gdrive_file = self.drive.CreateFile({'title': relative_filename, 'parents': [{'id': folder['id']}]}) gdrive_file.Upload() + logging.info(f"[gDriveSync] Uploaded {file_path} to Google Drive") uploaded_files_count += 1 # Print the number of uploaded files From a3be7989add96dc9c66efe06cb4b21088f92579a Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 14 Oct 2023 22:50:51 +0200 Subject: [PATCH 147/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 78 ++++++++++++++++-------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index a1bc4fb1..2ad3e8b3 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -28,9 +28,13 @@ class GdriveSync(plugins.Plugin): self.status = StatusFile('/root/.gdrive-backup') self.backup = True self.backupfiles = [ - '/root', - '/etc/pwnagotchi' - ] + '/root/brain.nn', + '/root/brain.json', + '/root/.api-report.json', + '/root/handshakes', + '/root/peers', + '/etc/pwnagotchi' + ] def on_loaded(self): # client_secrets.json needs to be not empty @@ -59,21 +63,14 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored - backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder']) - if backup_folder_id is None: - # If the folder doesn't exist, create it - folder = self.drive.CreateFile( - {'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'}) - folder.Upload() - backup_folder_id = folder['id'] - logging.info(f"[gDriveSync] Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}") + backup_folder_id = self.create_folder_if_not_exists(self.options['backup_folder']) # Continue with the rest of the code using backup_folder_id file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() if not file_list: # Handle the case where no files were found - # logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") + logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") if self.options['backupfiles'] is not None: self.backupfiles = self.backupfiles + self.options['backupfiles'] self.backup_files(self.backupfiles, '/backup') @@ -114,6 +111,43 @@ class GdriveSync(plugins.Plugin): return file['id'] return None + def create_folder_if_not_exists(self, backup_folder_name): + # First, create or retrieve the *BACKUP_FOLDER* folder + backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) + if backup_folder_id is None: + # Now create /*BACKUP_FOLDER* + backup_folder = self.drive.CreateFile( + {'title': 'PwnagotchiBackups', 'mimeType': 'application/vnd.google-apps.folder'}) + backup_folder.Upload() + backup_folder_id = backup_folder['id'] + logging.info(f"[gDriveSync] Created folder 'PwnagotchiBackups' with ID: {backup_folder_id}") + + # Now, create /*BACKUP_FOLDER*/root + root_folder = self.drive.CreateFile( + {'title': 'root', 'mimeType': 'application/vnd.google-apps.folder', + 'parents': [{'id': backup_folder_id}]}) + root_folder.Upload() + root_folder_id = root_folder['id'] + logging.info(f"[gDriveSync] Created folder 'root' with ID: {root_folder_id}") + + # Now, create /*BACKUP_FOLDER*/etc + etc_folder = self.drive.CreateFile( + {'title': 'etc', 'mimeType': 'application/vnd.google-apps.folder', + 'parents': [{'id': backup_folder_id}]}) + etc_folder.Upload() + etc_folder_id = etc_folder['id'] + logging.info(f"[gDriveSync] Created folder 'etc' with ID: {etc_folder_id}") + + # Now, create /*BACKUP_FOLDER*/etc/pwnagotchi + pwnagotchi_folder = self.drive.CreateFile( + {'title': 'pwnagotchi', 'mimeType': 'application/vnd.google-apps.folder', + 'parents': [{'id': etc_folder_id}]}) + pwnagotchi_folder.Upload() + pwnagotchi_folder_id = pwnagotchi_folder['id'] + logging.info(f"[gDriveSync] Created folder 'pwnagotchi' under 'etc' with ID: {pwnagotchi_folder_id}") + + return root_folder_id, pwnagotchi_folder_id # Return the IDs of both root and pwnagotchi folders + def on_unload(self, ui): logging.info("[gdrivesync] unloaded") @@ -160,29 +194,21 @@ class GdriveSync(plugins.Plugin): def upload_to_gdrive(self, backup_path, gdrive_folder): try: - existing_folder = self.get_folder_id_by_name(self.drive, gdrive_folder) - if existing_folder is not None: - folder = self.drive.CreateFile({'id': existing_folder}) + # Get the ID of the main backup folder + backup_folder_id = self.get_folder_id_by_name(self.drive, gdrive_folder) + folder = self.drive.CreateFile({'id': backup_folder_id}) - # Upload Files to the Created Folder - uploaded_files_count = 0 + # Upload files and folders to the created folder for root, dirs, files in os.walk(backup_path): for filename in files: file_path = os.path.join(root, filename) - relative_path = os.path.relpath(file_path, backup_path) - # Remove the directory part from the filename - relative_filename = os.path.join(gdrive_folder, relative_path, filename) - gdrive_file = self.drive.CreateFile({'title': relative_filename, 'parents': [{'id': folder['id']}]}) + gdrive_file = self.drive.CreateFile({'title': filename, 'parents': [{'id': folder['id']}]}) gdrive_file.Upload() logging.info(f"[gDriveSync] Uploaded {file_path} to Google Drive") - uploaded_files_count += 1 - - # Print the number of uploaded files - logging.info(f"[gDriveSync] Uploaded {uploaded_files_count} files to Google Drive") + logging.info(f"[gDriveSync] Backup uploaded to Google Drive") except pydrive2.files.ApiRequestError as api_error: self.handle_upload_error(api_error, backup_path, gdrive_folder) - except Exception as e: logging.error(f"[gDriveSync] Error during upload_to_gdrive: {e}") From f7f869736b27afadaaaf6c8a754a7b29da2749c6 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 14 Oct 2023 23:21:27 +0200 Subject: [PATCH 148/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 133 ++++++++++++++--------- 1 file changed, 83 insertions(+), 50 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 2ad3e8b3..60929afb 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -63,19 +63,21 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored - backup_folder_id = self.create_folder_if_not_exists(self.options['backup_folder']) + backup_folder, root_folder, pwnagotchi_folder = self.create_folder_if_not_exists(self.options['backup_folder']) # Continue with the rest of the code using backup_folder_id - file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() + root_file_list = self.drive.ListFile({ + 'q': f"'{root_folder}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() + pwnagotchi_file_list = self.drive.ListFile({'q': f"'{pwnagotchi_folder}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() - if not file_list: + if not (root_file_list or pwnagotchi_file_list): # Handle the case where no files were found - logging.warning(f"[gDriveSync] No files found in the folder with ID {backup_folder_id}") + # logging.warning(f"[gDriveSync] No files found in the folder with ID {root_file_list} and {pwnagotchi_file_list}") if self.options['backupfiles'] is not None: self.backupfiles = self.backupfiles + self.options['backupfiles'] self.backup_files(self.backupfiles, '/backup') - self.upload_to_gdrive('/backup', self.options['backup_folder']) + self.upload_to_gdrive('/backup', self.options['backup_folder'],backup_folder, root_folder, pwnagotchi_folder) self.backup = True # Specify the local backup path @@ -84,11 +86,17 @@ class GdriveSync(plugins.Plugin): # Create the local backup directory if it doesn't exist os.makedirs(local_backup_path, exist_ok=True) - # Download each file in the folder - for file in file_list: - local_file_path = os.path.join(local_backup_path, file['title']) - file.GetContentFile(local_file_path) - logging.info(f"[gDriveSync] Downloaded {file['title']} from Google Drive") + # Download each file in the /root folder + for root_file in root_file_list: + local_file_path = os.path.join(local_backup_path, root_file['title']) + root_file.GetContentFile(local_file_path) + logging.info(f"[gDriveSync] Downloaded {root_file['title']} from Google Drive") + + # Download each file in the /etc/pwnagotchi folder + for pwnagotchi_file in pwnagotchi_file_list: + local_file_path = os.path.join(local_backup_path, pwnagotchi_file['title']) + pwnagotchi_file.GetContentFile(local_file_path) + logging.info(f"[gDriveSync] Downloaded {pwnagotchi_file['title']} from Google Drive") # Optionally, you can use the downloaded files as needed # For example, you can copy them to the corresponding directories @@ -104,49 +112,65 @@ class GdriveSync(plugins.Plugin): logging.error(f"Error: {e}") self.ready = False - def get_folder_id_by_name(self, drive, folder_name): - file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList() + def get_folder_id_by_name(self, drive, folder_name, parent_folder_id=None): + query = "mimeType='application/vnd.google-apps.folder' and trashed=false" + if parent_folder_id: + query += f" and '{parent_folder_id}' in parents" + + file_list = drive.ListFile({'q': query}).GetList() for file in file_list: if file['title'] == folder_name: return file['id'] - return None + return None def create_folder_if_not_exists(self, backup_folder_name): - # First, create or retrieve the *BACKUP_FOLDER* folder + # First, try to retrieve the existing *BACKUP_FOLDER* folder backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_name) + if backup_folder_id is None: - # Now create /*BACKUP_FOLDER* + # If not found, create *BACKUP_FOLDER* backup_folder = self.drive.CreateFile( - {'title': 'PwnagotchiBackups', 'mimeType': 'application/vnd.google-apps.folder'}) + {'title': backup_folder_name, 'mimeType': 'application/vnd.google-apps.folder'}) backup_folder.Upload() backup_folder_id = backup_folder['id'] - logging.info(f"[gDriveSync] Created folder 'PwnagotchiBackups' with ID: {backup_folder_id}") + logging.info(f"[gDriveSync] Created folder '{backup_folder_name}' with ID: {backup_folder_id}") - # Now, create /*BACKUP_FOLDER*/root - root_folder = self.drive.CreateFile( - {'title': 'root', 'mimeType': 'application/vnd.google-apps.folder', - 'parents': [{'id': backup_folder_id}]}) - root_folder.Upload() - root_folder_id = root_folder['id'] - logging.info(f"[gDriveSync] Created folder 'root' with ID: {root_folder_id}") + # Now, try to retrieve or create /*BACKUP_FOLDER*/root + root_folder_id = self.get_or_create_subfolder('root', backup_folder_id) - # Now, create /*BACKUP_FOLDER*/etc - etc_folder = self.drive.CreateFile( - {'title': 'etc', 'mimeType': 'application/vnd.google-apps.folder', - 'parents': [{'id': backup_folder_id}]}) - etc_folder.Upload() - etc_folder_id = etc_folder['id'] - logging.info(f"[gDriveSync] Created folder 'etc' with ID: {etc_folder_id}") + # Now, try to retrieve or create /*BACKUP_FOLDER*/etc + etc_folder_id = self.get_or_create_subfolder('etc', backup_folder_id) - # Now, create /*BACKUP_FOLDER*/etc/pwnagotchi - pwnagotchi_folder = self.drive.CreateFile( - {'title': 'pwnagotchi', 'mimeType': 'application/vnd.google-apps.folder', - 'parents': [{'id': etc_folder_id}]}) - pwnagotchi_folder.Upload() - pwnagotchi_folder_id = pwnagotchi_folder['id'] - logging.info(f"[gDriveSync] Created folder 'pwnagotchi' under 'etc' with ID: {pwnagotchi_folder_id}") + # Now, try to retrieve or create /*BACKUP_FOLDER*/etc/pwnagotchi + pwnagotchi_folder_id = self.get_or_create_subfolder('pwnagotchi', etc_folder_id) - return root_folder_id, pwnagotchi_folder_id # Return the IDs of both root and pwnagotchi folders + return backup_folder_id, root_folder_id, pwnagotchi_folder_id # Return the IDs of both root and pwnagotchi folders + else: + # If found, also try to retrieve or create /*BACKUP_FOLDER*/root + root_folder_id = self.get_or_create_subfolder('root', backup_folder_id) + + # Also, try to retrieve or create /*BACKUP_FOLDER*/etc + etc_folder_id = self.get_or_create_subfolder('etc', backup_folder_id) + + # Also, try to retrieve or create /*BACKUP_FOLDER*/etc/pwnagotchi + pwnagotchi_folder_id = self.get_or_create_subfolder('pwnagotchi', etc_folder_id) + + return backup_folder_id, root_folder_id, pwnagotchi_folder_id # Return the IDs of both root and pwnagotchi folders + + def get_or_create_subfolder(self, subfolder_name, parent_folder_id): + # Try to retrieve the subfolder + subfolder_id = self.get_folder_id_by_name(self.drive, subfolder_name, parent_folder_id) + + if subfolder_id is None: + # If not found, create the subfolder + subfolder = self.drive.CreateFile( + {'title': subfolder_name, 'mimeType': 'application/vnd.google-apps.folder', + 'parents': [{'id': parent_folder_id}]}) + subfolder.Upload() + subfolder_id = subfolder['id'] + logging.info(f"[gDriveSync] Created folder '{subfolder_name}' with ID: {subfolder_id}") + + return subfolder_id def on_unload(self, ui): logging.info("[gdrivesync] unloaded") @@ -192,19 +216,28 @@ class GdriveSync(plugins.Plugin): except Exception as e: logging.error(f"[gDriveSync] Error during backup_path: {e}") - def upload_to_gdrive(self, backup_path, gdrive_folder): + def upload_to_gdrive(self, backup_path, gdrive_folder, root_folder_id, pwnagotchi_folder_id): try: - # Get the ID of the main backup folder - backup_folder_id = self.get_folder_id_by_name(self.drive, gdrive_folder) - folder = self.drive.CreateFile({'id': backup_folder_id}) + # Upload files to the /root folder + if root_folder_id is not None: + root_folder = self.drive.CreateFile({'id': root_folder_id}) + for root, dirs, files in os.walk('/root'): + for filename in files: + file_path = os.path.join(root, filename) + gdrive_file = self.drive.CreateFile({'title': filename, 'parents': [{'id': root_folder['id']}]}) + gdrive_file.Upload() + logging.info(f"[gDriveSync] Uploaded {file_path} to Google Drive") - # Upload files and folders to the created folder - for root, dirs, files in os.walk(backup_path): - for filename in files: - file_path = os.path.join(root, filename) - gdrive_file = self.drive.CreateFile({'title': filename, 'parents': [{'id': folder['id']}]}) - gdrive_file.Upload() - logging.info(f"[gDriveSync] Uploaded {file_path} to Google Drive") + # Upload files to the /etc/pwnagotchi folder + if pwnagotchi_folder_id is not None: + pwnagotchi_folder = self.drive.CreateFile({'id': pwnagotchi_folder_id}) + for root, dirs, files in os.walk('/etc/pwnagotchi'): + for filename in files: + file_path = os.path.join(root, filename) + gdrive_file = self.drive.CreateFile( + {'title': filename, 'parents': [{'id': pwnagotchi_folder['id']}]}) + gdrive_file.Upload() + logging.info(f"[gDriveSync] Uploaded {file_path} to Google Drive") logging.info(f"[gDriveSync] Backup uploaded to Google Drive") except pydrive2.files.ApiRequestError as api_error: From 31394398f1b9efa52d4a57cac7fea4691affd631 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 14 Oct 2023 23:26:13 +0200 Subject: [PATCH 149/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 60929afb..2448fab0 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -37,6 +37,9 @@ class GdriveSync(plugins.Plugin): ] def on_loaded(self): + """ + + """ # client_secrets.json needs to be not empty if os.stat("/root/client_secrets.json").st_size == 0: logging.error("[gDriveSync] /root/client_secrets.json is empty. Please RTFM!") @@ -77,7 +80,7 @@ class GdriveSync(plugins.Plugin): self.backupfiles = self.backupfiles + self.options['backupfiles'] self.backup_files(self.backupfiles, '/backup') - self.upload_to_gdrive('/backup', self.options['backup_folder'],backup_folder, root_folder, pwnagotchi_folder) + self.upload_to_gdrive('/backup', self.options['backup_folder'], root_folder, pwnagotchi_folder) self.backup = True # Specify the local backup path @@ -241,15 +244,15 @@ class GdriveSync(plugins.Plugin): logging.info(f"[gDriveSync] Backup uploaded to Google Drive") except pydrive2.files.ApiRequestError as api_error: - self.handle_upload_error(api_error, backup_path, gdrive_folder) + self.handle_upload_error(api_error, backup_path, gdrive_folder, root_folder_id, pwnagotchi_folder_id) except Exception as e: logging.error(f"[gDriveSync] Error during upload_to_gdrive: {e}") - def handle_upload_error(self, api_error, backup_path, gdrive_folder): + def handle_upload_error(self, api_error, backup_path, gdrive_folder, root_folder_id, pwnagotchi_folder_id): if 'Rate Limit Exceeded' in str(api_error): logging.warning("[gDriveSync] Rate limit exceeded. Waiting for some time before retrying...") # We set to 100 seconds, because there is a limit 20k requests per 100s per user time.sleep(100) # You can adjust the sleep duration based on your needs - self.upload_to_gdrive(backup_path, gdrive_folder) + self.upload_to_gdrive(backup_path, gdrive_folder, root_folder_id, pwnagotchi_folder_id) else: logging.error(f"[gDriveSync] API Request Error: {api_error}") From 463fcccbf4934b1a7b171e9b61ebfa198576c2ea Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 14 Oct 2023 23:35:11 +0200 Subject: [PATCH 150/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 2448fab0..810effbe 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -69,8 +69,7 @@ class GdriveSync(plugins.Plugin): backup_folder, root_folder, pwnagotchi_folder = self.create_folder_if_not_exists(self.options['backup_folder']) # Continue with the rest of the code using backup_folder_id - root_file_list = self.drive.ListFile({ - 'q': f"'{root_folder}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() + root_file_list = self.drive.ListFile({'q': f"'{root_folder}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() pwnagotchi_file_list = self.drive.ListFile({'q': f"'{pwnagotchi_folder}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() if not (root_file_list or pwnagotchi_file_list): From b32bdd1eda6b593aef12f3ebf51c8a82407108e3 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 18:52:31 +0200 Subject: [PATCH 151/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 32 +++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 810effbe..5d3f1e80 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -38,7 +38,7 @@ class GdriveSync(plugins.Plugin): def on_loaded(self): """ - + Called when the plugin is loaded """ # client_secrets.json needs to be not empty if os.stat("/root/client_secrets.json").st_size == 0: @@ -175,9 +175,15 @@ class GdriveSync(plugins.Plugin): return subfolder_id def on_unload(self, ui): + """ + Called when the plugin is unloaded + """ logging.info("[gdrivesync] unloaded") def on_internet_available(self, agent): + """ + Called when internet is available + """ self.internet = True def on_handshake(self, agent): @@ -205,18 +211,20 @@ class GdriveSync(plugins.Plugin): def backup_files(self, paths, dest_path): for src_path in paths: - self.backup_path(src_path, dest_path) + try: + if os.path.exists(src_path): + dest_relative_path = os.path.relpath(src_path, '/') + dest = os.path.join(dest_path, dest_relative_path) - def backup_path(self, src_path, dest_path): - try: - if os.path.exists(src_path): - dest = os.path.join(dest_path, os.path.basename(src_path)) - if os.path.isdir(src_path): - shutil.copytree(src_path, dest) - else: - shutil.copy2(src_path, dest) - except Exception as e: - logging.error(f"[gDriveSync] Error during backup_path: {e}") + if os.path.isfile(src_path): + # If it's a file, copy it to the destination preserving the directory structure + os.makedirs(os.path.dirname(dest), exist_ok=True) + shutil.copy2(src_path, dest) + elif os.path.isdir(src_path): + # If it's a directory, copy the entire directory to the destination + shutil.copytree(src_path, dest) + except Exception as e: + logging.error(f"[gDriveSync] Error during backup_path: {e}") def upload_to_gdrive(self, backup_path, gdrive_folder, root_folder_id, pwnagotchi_folder_id): try: From f93bb6bec7e79ca86e999b6a1c9b3a7d7e74abd5 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 19:44:42 +0200 Subject: [PATCH 152/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 131 ++++++++++------------- 1 file changed, 59 insertions(+), 72 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 5d3f1e80..1655b762 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -9,6 +9,7 @@ from pydrive2.auth import GoogleAuth from pydrive2.drive import GoogleDrive from threading import Lock from pwnagotchi.utils import StatusFile, parse_version as version_to_tuple +import zipfile class GdriveSync(plugins.Plugin): @@ -66,54 +67,59 @@ class GdriveSync(plugins.Plugin): # if backup file does not exist, we will check for backup folder on gdrive. if not self.backup: # Use self.options['backup_folder'] as the folder ID where backups are stored - backup_folder, root_folder, pwnagotchi_folder = self.create_folder_if_not_exists(self.options['backup_folder']) + backup_folder = self.create_folder_if_not_exists(self.options['backup_folder']) # Continue with the rest of the code using backup_folder_id - root_file_list = self.drive.ListFile({'q': f"'{root_folder}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() - pwnagotchi_file_list = self.drive.ListFile({'q': f"'{pwnagotchi_folder}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() - - if not (root_file_list or pwnagotchi_file_list): + backup_folder_file_list = self.drive.ListFile({'q': f"'{backup_folder}' and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() + if not backup_folder_file_list: # Handle the case where no files were found # logging.warning(f"[gDriveSync] No files found in the folder with ID {root_file_list} and {pwnagotchi_file_list}") if self.options['backupfiles'] is not None: self.backupfiles = self.backupfiles + self.options['backupfiles'] self.backup_files(self.backupfiles, '/backup') - self.upload_to_gdrive('/backup', self.options['backup_folder'], root_folder, pwnagotchi_folder) + self.upload_to_gdrive('/backup', self.options['backup_folder']) self.backup = True - # Specify the local backup path - local_backup_path = '/' + # Specify the local backup path + local_backup_path = '/home/pi' - # Create the local backup directory if it doesn't exist - os.makedirs(local_backup_path, exist_ok=True) + # Create the local backup directory if it doesn't exist + os.makedirs(local_backup_path, exist_ok=True) - # Download each file in the /root folder - for root_file in root_file_list: - local_file_path = os.path.join(local_backup_path, root_file['title']) - root_file.GetContentFile(local_file_path) - logging.info(f"[gDriveSync] Downloaded {root_file['title']} from Google Drive") + # Download the zip archive from Google Drive + zip_file_id = self.get_latest_backup_file_id(self.options['backup_folder']) + if zip_file_id: + zip_file = self.drive.CreateFile({'id': zip_file_id}) + zip_file.GetContentFile(os.path.join(local_backup_path, 'backup.zip')) + logging.info("[gDriveSync] Downloaded backup.zip from Google Drive") - # Download each file in the /etc/pwnagotchi folder - for pwnagotchi_file in pwnagotchi_file_list: - local_file_path = os.path.join(local_backup_path, pwnagotchi_file['title']) - pwnagotchi_file.GetContentFile(local_file_path) - logging.info(f"[gDriveSync] Downloaded {pwnagotchi_file['title']} from Google Drive") + # Extract the zip archive to the root directory + with zipfile.ZipFile(os.path.join(local_backup_path, 'backup.zip'), 'r') as zip_ref: + zip_ref.extractall('/') - # Optionally, you can use the downloaded files as needed - # For example, you can copy them to the corresponding directories - self.backup = True - self.status.update() - # reboot so we can start opwngrid with backup id - pwnagotchi.reboot() + self.status.update() + # Reboot so we can start opwngrid with the backup id + pwnagotchi.reboot() - # all set, gdriveSync is ready to run - self.ready = True - logging.info("[gdrivesync] loaded") + # all set, gdriveSync is ready to run + self.ready = True + logging.info("[gdrivesync] loaded") except Exception as e: logging.error(f"Error: {e}") self.ready = False + def get_latest_backup_file_id(self, backup_folder_id): + # Retrieve the latest backup file in the Google Drive folder + file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' in parents and trashed=false"}).GetList() + + if file_list: + # Sort the files by creation date in descending order + latest_backup = max(file_list, key=lambda file: file['createdDate']) + return latest_backup['id'] + else: + return None + def get_folder_id_by_name(self, drive, folder_name, parent_folder_id=None): query = "mimeType='application/vnd.google-apps.folder' and trashed=false" if parent_folder_id: @@ -137,27 +143,7 @@ class GdriveSync(plugins.Plugin): backup_folder_id = backup_folder['id'] logging.info(f"[gDriveSync] Created folder '{backup_folder_name}' with ID: {backup_folder_id}") - # Now, try to retrieve or create /*BACKUP_FOLDER*/root - root_folder_id = self.get_or_create_subfolder('root', backup_folder_id) - - # Now, try to retrieve or create /*BACKUP_FOLDER*/etc - etc_folder_id = self.get_or_create_subfolder('etc', backup_folder_id) - - # Now, try to retrieve or create /*BACKUP_FOLDER*/etc/pwnagotchi - pwnagotchi_folder_id = self.get_or_create_subfolder('pwnagotchi', etc_folder_id) - - return backup_folder_id, root_folder_id, pwnagotchi_folder_id # Return the IDs of both root and pwnagotchi folders - else: - # If found, also try to retrieve or create /*BACKUP_FOLDER*/root - root_folder_id = self.get_or_create_subfolder('root', backup_folder_id) - - # Also, try to retrieve or create /*BACKUP_FOLDER*/etc - etc_folder_id = self.get_or_create_subfolder('etc', backup_folder_id) - - # Also, try to retrieve or create /*BACKUP_FOLDER*/etc/pwnagotchi - pwnagotchi_folder_id = self.get_or_create_subfolder('pwnagotchi', etc_folder_id) - - return backup_folder_id, root_folder_id, pwnagotchi_folder_id # Return the IDs of both root and pwnagotchi folders + return backup_folder_id def get_or_create_subfolder(self, subfolder_name, parent_folder_id): # Try to retrieve the subfolder @@ -202,7 +188,20 @@ class GdriveSync(plugins.Plugin): self.backupfiles = self.backupfiles + self.options['backupfiles'] self.backup_files(self.backupfiles, '/backup') - self.upload_to_gdrive('/backup', self.options['backup_folder']) + # Create a zip archive of the /backup folder + zip_file_path = os.path.join('/home/pi', 'backup.zip') + with zipfile.ZipFile(zip_file_path, 'w') as zip_ref: + for root, dirs, files in os.walk('/backup'): + for file in files: + file_path = os.path.join(root, file) + arcname = os.path.relpath(file_path, '/backup') + zip_ref.write(file_path, arcname=arcname) + + # Upload the zip archive to Google Drive + self.upload_to_gdrive(zip_file_path, self.options['backup_folder']) + + # Cleanup the local zip file + os.remove(zip_file_path) self.status.update() display = agent.view() display.update(force=True, new_data={'Backing up to gdrive ...'}) @@ -226,32 +225,20 @@ class GdriveSync(plugins.Plugin): except Exception as e: logging.error(f"[gDriveSync] Error during backup_path: {e}") - def upload_to_gdrive(self, backup_path, gdrive_folder, root_folder_id, pwnagotchi_folder_id): + def upload_to_gdrive(self, backup_path, gdrive_folder): try: - # Upload files to the /root folder - if root_folder_id is not None: - root_folder = self.drive.CreateFile({'id': root_folder_id}) - for root, dirs, files in os.walk('/root'): - for filename in files: - file_path = os.path.join(root, filename) - gdrive_file = self.drive.CreateFile({'title': filename, 'parents': [{'id': root_folder['id']}]}) - gdrive_file.Upload() - logging.info(f"[gDriveSync] Uploaded {file_path} to Google Drive") + # Upload zip-file to google drive + # Create a GoogleDriveFile instance for the zip file + zip_file = self.drive.CreateFile({'title': 'backup.zip', 'parents': [{'id': gdrive_folder}]}) - # Upload files to the /etc/pwnagotchi folder - if pwnagotchi_folder_id is not None: - pwnagotchi_folder = self.drive.CreateFile({'id': pwnagotchi_folder_id}) - for root, dirs, files in os.walk('/etc/pwnagotchi'): - for filename in files: - file_path = os.path.join(root, filename) - gdrive_file = self.drive.CreateFile( - {'title': filename, 'parents': [{'id': pwnagotchi_folder['id']}]}) - gdrive_file.Upload() - logging.info(f"[gDriveSync] Uploaded {file_path} to Google Drive") + # Set the content of the file to the zip file + zip_file.SetContentFile(backup_path) + # Upload the file to Google Drive + zip_file.Upload() logging.info(f"[gDriveSync] Backup uploaded to Google Drive") except pydrive2.files.ApiRequestError as api_error: - self.handle_upload_error(api_error, backup_path, gdrive_folder, root_folder_id, pwnagotchi_folder_id) + self.handle_upload_error(api_error, backup_path, gdrive_folder) except Exception as e: logging.error(f"[gDriveSync] Error during upload_to_gdrive: {e}") From 179d09a70a3461584111b3c8b93acb8c5cf73c99 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 19:50:59 +0200 Subject: [PATCH 153/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 1655b762..0e661a81 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -70,7 +70,7 @@ class GdriveSync(plugins.Plugin): backup_folder = self.create_folder_if_not_exists(self.options['backup_folder']) # Continue with the rest of the code using backup_folder_id - backup_folder_file_list = self.drive.ListFile({'q': f"'{backup_folder}' and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() + backup_folder_file_list = self.drive.ListFile({'q': f"'{backup_folder}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList() if not backup_folder_file_list: # Handle the case where no files were found # logging.warning(f"[gDriveSync] No files found in the folder with ID {root_file_list} and {pwnagotchi_file_list}") @@ -145,21 +145,6 @@ class GdriveSync(plugins.Plugin): return backup_folder_id - def get_or_create_subfolder(self, subfolder_name, parent_folder_id): - # Try to retrieve the subfolder - subfolder_id = self.get_folder_id_by_name(self.drive, subfolder_name, parent_folder_id) - - if subfolder_id is None: - # If not found, create the subfolder - subfolder = self.drive.CreateFile( - {'title': subfolder_name, 'mimeType': 'application/vnd.google-apps.folder', - 'parents': [{'id': parent_folder_id}]}) - subfolder.Upload() - subfolder_id = subfolder['id'] - logging.info(f"[gDriveSync] Created folder '{subfolder_name}' with ID: {subfolder_id}") - - return subfolder_id - def on_unload(self, ui): """ Called when the plugin is unloaded From 70e8a46a439c4252d090ef04b98835b478a9719a Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 19:52:55 +0200 Subject: [PATCH 154/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 0e661a81..50c25737 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -227,11 +227,11 @@ class GdriveSync(plugins.Plugin): except Exception as e: logging.error(f"[gDriveSync] Error during upload_to_gdrive: {e}") - def handle_upload_error(self, api_error, backup_path, gdrive_folder, root_folder_id, pwnagotchi_folder_id): + def handle_upload_error(self, api_error, backup_path, gdrive_folder): if 'Rate Limit Exceeded' in str(api_error): logging.warning("[gDriveSync] Rate limit exceeded. Waiting for some time before retrying...") # We set to 100 seconds, because there is a limit 20k requests per 100s per user time.sleep(100) # You can adjust the sleep duration based on your needs - self.upload_to_gdrive(backup_path, gdrive_folder, root_folder_id, pwnagotchi_folder_id) + self.upload_to_gdrive(backup_path, gdrive_folder) else: logging.error(f"[gDriveSync] API Request Error: {api_error}") From 59c5d02db3d7de0a22a81c366cce7c333dc18b58 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 19:58:53 +0200 Subject: [PATCH 155/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 50c25737..7193c14b 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -217,7 +217,7 @@ class GdriveSync(plugins.Plugin): zip_file = self.drive.CreateFile({'title': 'backup.zip', 'parents': [{'id': gdrive_folder}]}) # Set the content of the file to the zip file - zip_file.SetContentFile(backup_path) + zip_file.SetContentFile(os.path.join(backup_path, 'backup.zip')) # Upload the file to Google Drive zip_file.Upload() From 3a9b3c1d168aa593c106bd893a277bdb0108e2c2 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:00:07 +0200 Subject: [PATCH 156/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 7193c14b..fdeb4a20 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -203,7 +203,10 @@ class GdriveSync(plugins.Plugin): if os.path.isfile(src_path): # If it's a file, copy it to the destination preserving the directory structure os.makedirs(os.path.dirname(dest), exist_ok=True) - shutil.copy2(src_path, dest) + # Check if the destination file already exists + if os.path.exists(dest): + # If it exists, remove it to overwrite + os.remove(dest) elif os.path.isdir(src_path): # If it's a directory, copy the entire directory to the destination shutil.copytree(src_path, dest) @@ -217,7 +220,7 @@ class GdriveSync(plugins.Plugin): zip_file = self.drive.CreateFile({'title': 'backup.zip', 'parents': [{'id': gdrive_folder}]}) # Set the content of the file to the zip file - zip_file.SetContentFile(os.path.join(backup_path, 'backup.zip')) + zip_file.SetContentFile(backup_path) # Upload the file to Google Drive zip_file.Upload() From e48b852d514123232676cb47de3813df5963e054 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:01:41 +0200 Subject: [PATCH 157/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index fdeb4a20..8416e324 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -82,7 +82,7 @@ class GdriveSync(plugins.Plugin): self.backup = True # Specify the local backup path - local_backup_path = '/home/pi' + local_backup_path = '/' # Create the local backup directory if it doesn't exist os.makedirs(local_backup_path, exist_ok=True) From d8a3d133da5d69c7d72d06c36fb3d93a636a4493 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:02:03 +0200 Subject: [PATCH 158/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 8416e324..3655dbdc 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -84,9 +84,6 @@ class GdriveSync(plugins.Plugin): # Specify the local backup path local_backup_path = '/' - # Create the local backup directory if it doesn't exist - os.makedirs(local_backup_path, exist_ok=True) - # Download the zip archive from Google Drive zip_file_id = self.get_latest_backup_file_id(self.options['backup_folder']) if zip_file_id: From abf20ce9ed3e20d3a2d6eddfc90acb66df9a1c90 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:04:42 +0200 Subject: [PATCH 159/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 3655dbdc..2c77182c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -217,7 +217,7 @@ class GdriveSync(plugins.Plugin): zip_file = self.drive.CreateFile({'title': 'backup.zip', 'parents': [{'id': gdrive_folder}]}) # Set the content of the file to the zip file - zip_file.SetContentFile(backup_path) + zip_file.SetContentFile(os.path.join(backup_path, 'backup.zip')) # Upload the file to Google Drive zip_file.Upload() From 1d556ed58208ce3f2e48508d273e819afc959818 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:07:08 +0200 Subject: [PATCH 160/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 2c77182c..c3c179b6 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -78,7 +78,17 @@ class GdriveSync(plugins.Plugin): self.backupfiles = self.backupfiles + self.options['backupfiles'] self.backup_files(self.backupfiles, '/backup') - self.upload_to_gdrive('/backup', self.options['backup_folder']) + # Create a zip archive of the /backup folder + zip_file_path = os.path.join('/home/pi', 'backup.zip') + with zipfile.ZipFile(zip_file_path, 'w') as zip_ref: + for root, dirs, files in os.walk('/backup'): + for file in files: + file_path = os.path.join(root, file) + arcname = os.path.relpath(file_path, '/backup') + zip_ref.write(file_path, arcname=arcname) + + # Upload the zip archive to Google Drive + self.upload_to_gdrive(zip_file_path, self.options['backup_folder']) self.backup = True # Specify the local backup path From 19dbcbeb33bb5f5ba70de5df487c624cf5b14500 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:08:35 +0200 Subject: [PATCH 161/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index c3c179b6..9e917c5c 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -227,7 +227,7 @@ class GdriveSync(plugins.Plugin): zip_file = self.drive.CreateFile({'title': 'backup.zip', 'parents': [{'id': gdrive_folder}]}) # Set the content of the file to the zip file - zip_file.SetContentFile(os.path.join(backup_path, 'backup.zip')) + zip_file.SetContentFile(backup_path) # Upload the file to Google Drive zip_file.Upload() From 73beac95175cbd4074c5ecba51f469f3bc7d538f Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:15:29 +0200 Subject: [PATCH 162/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 9e917c5c..8028aec3 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -88,7 +88,7 @@ class GdriveSync(plugins.Plugin): zip_ref.write(file_path, arcname=arcname) # Upload the zip archive to Google Drive - self.upload_to_gdrive(zip_file_path, self.options['backup_folder']) + self.upload_to_gdrive(zip_file_path, self.get_folder_id_by_name(self.drive, self.options['backup_folder'])) self.backup = True # Specify the local backup path @@ -190,7 +190,7 @@ class GdriveSync(plugins.Plugin): zip_ref.write(file_path, arcname=arcname) # Upload the zip archive to Google Drive - self.upload_to_gdrive(zip_file_path, self.options['backup_folder']) + self.upload_to_gdrive(zip_file_path, self.get_folder_id_by_name(self.drive, self.options['backup_folder'])) # Cleanup the local zip file os.remove(zip_file_path) From 4d21b86f64edf3503cbdcd10d124e424d0ba8bea Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:18:13 +0200 Subject: [PATCH 163/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 8028aec3..0a993bdb 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -117,6 +117,7 @@ class GdriveSync(plugins.Plugin): self.ready = False def get_latest_backup_file_id(self, backup_folder_id): + backup_folder_id = self.get_folder_id_by_name(self.drive, backup_folder_id) # Retrieve the latest backup file in the Google Drive folder file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' in parents and trashed=false"}).GetList() From a49ccbeaa16c61dd15506464485af204769f2c39 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:19:45 +0200 Subject: [PATCH 164/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 0a993bdb..6be80972 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -91,27 +91,27 @@ class GdriveSync(plugins.Plugin): self.upload_to_gdrive(zip_file_path, self.get_folder_id_by_name(self.drive, self.options['backup_folder'])) self.backup = True - # Specify the local backup path - local_backup_path = '/' + # Specify the local backup path + local_backup_path = '/' - # Download the zip archive from Google Drive - zip_file_id = self.get_latest_backup_file_id(self.options['backup_folder']) - if zip_file_id: - zip_file = self.drive.CreateFile({'id': zip_file_id}) - zip_file.GetContentFile(os.path.join(local_backup_path, 'backup.zip')) - logging.info("[gDriveSync] Downloaded backup.zip from Google Drive") + # Download the zip archive from Google Drive + zip_file_id = self.get_latest_backup_file_id(self.options['backup_folder']) + if zip_file_id: + zip_file = self.drive.CreateFile({'id': zip_file_id}) + zip_file.GetContentFile(os.path.join(local_backup_path, 'backup.zip')) + logging.info("[gDriveSync] Downloaded backup.zip from Google Drive") - # Extract the zip archive to the root directory - with zipfile.ZipFile(os.path.join(local_backup_path, 'backup.zip'), 'r') as zip_ref: - zip_ref.extractall('/') + # Extract the zip archive to the root directory + with zipfile.ZipFile(os.path.join(local_backup_path, 'backup.zip'), 'r') as zip_ref: + zip_ref.extractall('/') - self.status.update() - # Reboot so we can start opwngrid with the backup id - pwnagotchi.reboot() + self.status.update() + # Reboot so we can start opwngrid with the backup id + pwnagotchi.reboot() - # all set, gdriveSync is ready to run - self.ready = True - logging.info("[gdrivesync] loaded") + # all set, gdriveSync is ready to run + self.ready = True + logging.info("[gdrivesync] loaded") except Exception as e: logging.error(f"Error: {e}") self.ready = False From 3a02e3ddc8c85d3d8d50db7e57c990ae4c8ddb8a Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:20:25 +0200 Subject: [PATCH 165/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 6be80972..db6f109e 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -90,6 +90,7 @@ class GdriveSync(plugins.Plugin): # Upload the zip archive to Google Drive self.upload_to_gdrive(zip_file_path, self.get_folder_id_by_name(self.drive, self.options['backup_folder'])) self.backup = True + self.status.update() # Specify the local backup path local_backup_path = '/' From dde5e0396752abc895cb0ed93dc4ad0ddcf74241 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:27:20 +0200 Subject: [PATCH 166/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 49 +++++++++++------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index db6f109e..a02c5e27 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -8,7 +8,7 @@ import pydrive2 from pydrive2.auth import GoogleAuth from pydrive2.drive import GoogleDrive from threading import Lock -from pwnagotchi.utils import StatusFile, parse_version as version_to_tuple +from pwnagotchi.utils import StatusFile import zipfile @@ -172,35 +172,32 @@ class GdriveSync(plugins.Plugin): with self.lock: if not self.ready and not self.internet: return - try: - if self.status.newer_then_hours(self.options['interval']): - logging.debug("[update] last check happened less than %d hours ago" % self.options['interval']) - return + if self.status.newer_then_hours(self.options['interval']): + logging.debug("[update] last check happened less than %d hours ago" % self.options['interval']) + return - logging.info("[gdrivesync] new handshake captured, backing up to gdrive") - if self.options['backupfiles'] is not None: - self.backupfiles = self.backupfiles + self.options['backupfiles'] - self.backup_files(self.backupfiles, '/backup') + logging.info("[gdrivesync] new handshake captured, backing up to gdrive") + if self.options['backupfiles'] is not None: + self.backupfiles = self.backupfiles + self.options['backupfiles'] + self.backup_files(self.backupfiles, '/backup') - # Create a zip archive of the /backup folder - zip_file_path = os.path.join('/home/pi', 'backup.zip') - with zipfile.ZipFile(zip_file_path, 'w') as zip_ref: - for root, dirs, files in os.walk('/backup'): - for file in files: - file_path = os.path.join(root, file) - arcname = os.path.relpath(file_path, '/backup') - zip_ref.write(file_path, arcname=arcname) + # Create a zip archive of the /backup folder + zip_file_path = os.path.join('/home/pi', 'backup.zip') + with zipfile.ZipFile(zip_file_path, 'w') as zip_ref: + for root, dirs, files in os.walk('/backup'): + for file in files: + file_path = os.path.join(root, file) + arcname = os.path.relpath(file_path, '/backup') + zip_ref.write(file_path, arcname=arcname) - # Upload the zip archive to Google Drive - self.upload_to_gdrive(zip_file_path, self.get_folder_id_by_name(self.drive, self.options['backup_folder'])) + # Upload the zip archive to Google Drive + self.upload_to_gdrive(zip_file_path, self.get_folder_id_by_name(self.drive, self.options['backup_folder'])) - # Cleanup the local zip file - os.remove(zip_file_path) - self.status.update() - display = agent.view() - display.update(force=True, new_data={'Backing up to gdrive ...'}) - except Exception as e: - logging.error(f"[gDriveSync] Error during handshake processing: {e}") + # Cleanup the local zip file + os.remove(zip_file_path) + self.status.update() + display = agent.view() + display.update(force=True, new_data={'Backing up to gdrive ...'}) def backup_files(self, paths, dest_path): for src_path in paths: From c95cabe5efe45dc2bb48f08a5f7fcc9cb9af587f Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:30:49 +0200 Subject: [PATCH 167/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index a02c5e27..e39ebf22 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -167,11 +167,11 @@ class GdriveSync(plugins.Plugin): self.internet = True def on_handshake(self, agent): + if not self.ready and not self.internet: + return if self.lock.locked(): return with self.lock: - if not self.ready and not self.internet: - return if self.status.newer_then_hours(self.options['interval']): logging.debug("[update] last check happened less than %d hours ago" % self.options['interval']) return From a09415df67cf8e40d34594f2c4d9394b1913d91c Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sun, 15 Oct 2023 22:35:27 +0200 Subject: [PATCH 168/168] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index e39ebf22..2180846a 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -107,6 +107,7 @@ class GdriveSync(plugins.Plugin): zip_ref.extractall('/') self.status.update() + os.remove("/backup") # Reboot so we can start opwngrid with the backup id pwnagotchi.reboot() @@ -195,6 +196,7 @@ class GdriveSync(plugins.Plugin): # Cleanup the local zip file os.remove(zip_file_path) + os.remove("/backup") self.status.update() display = agent.view() display.update(force=True, new_data={'Backing up to gdrive ...'})