mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
@ -10,6 +10,7 @@ import os
|
|||||||
|
|
||||||
import pwnagotchi
|
import pwnagotchi
|
||||||
from pwnagotchi import utils
|
from pwnagotchi import utils
|
||||||
|
from pwnagotchi.google import cmd as google_cmd
|
||||||
from pwnagotchi.plugins import cmd as plugins_cmd
|
from pwnagotchi.plugins import cmd as plugins_cmd
|
||||||
from pwnagotchi import log
|
from pwnagotchi import log
|
||||||
from pwnagotchi import restart
|
from pwnagotchi import restart
|
||||||
@ -98,7 +99,7 @@ def do_auto_mode(agent):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser = plugins_cmd.add_parsers(parser)
|
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',
|
parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.toml',
|
||||||
help='Main configuration file.')
|
help='Main configuration file.')
|
||||||
@ -134,6 +135,9 @@ if __name__ == '__main__':
|
|||||||
log.setup_logging(args, config)
|
log.setup_logging(args, config)
|
||||||
rc = plugins_cmd.handle_cmd(args, config)
|
rc = plugins_cmd.handle_cmd(args, config)
|
||||||
sys.exit(rc)
|
sys.exit(rc)
|
||||||
|
elif google_cmd.used_google_cmd(args):
|
||||||
|
rc = google_cmd.handle_cmd(args)
|
||||||
|
sys.exit(rc)
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
print(pwnagotchi.__version__)
|
print(pwnagotchi.__version__)
|
||||||
|
0
builder/data/root/settings.yaml
Normal file
0
builder/data/root/settings.yaml
Normal file
@ -1,13 +1,8 @@
|
|||||||
# Handles the commandline stuff
|
# Handles the commandline stuff
|
||||||
|
|
||||||
import os
|
import pydrive2
|
||||||
|
from pydrive2.auth import GoogleAuth
|
||||||
import logging
|
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):
|
def add_parsers(parser):
|
||||||
@ -16,45 +11,83 @@ def add_parsers(parser):
|
|||||||
"""
|
"""
|
||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers()
|
||||||
# pwnagotchi google
|
# pwnagotchi google
|
||||||
parser_plugins = subparsers.add_parser('google')
|
parser_google = subparsers.add_parser('google')
|
||||||
plugin_subparsers = parser_plugins.add_subparsers(dest='googlecmd')
|
google_subparsers = parser_google.add_subparsers(dest='googlecmd')
|
||||||
|
|
||||||
# pwnagotchi plugins search
|
# pwnagotchi plugins search
|
||||||
parser_plugins_search = plugin_subparsers.add_parser('search', help='Search for pwnagotchi plugins')
|
parser_google_auth = google_subparsers.add_parser('auth', help='Google Authentication')
|
||||||
parser_plugins_search.add_argument('pattern', type=str, help="Search expression (wildcards allowed)")
|
parser_google_auth.add_argument('true', type=str, help="This will start the authentication process")
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def used_plugin_cmd(args):
|
def used_google_cmd(args):
|
||||||
"""
|
"""
|
||||||
Checks if the plugins subcommand was used
|
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
|
Parses the arguments and does the thing the user wants
|
||||||
"""
|
"""
|
||||||
if args.plugincmd == 'update':
|
if args.plugincmd == 'auth':
|
||||||
return update(config)
|
return auth(args)
|
||||||
elif args.plugincmd == 'search':
|
elif args.plugincmd == 'refresh':
|
||||||
args.installed = True # also search in installed plugins
|
return refresh(args)
|
||||||
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()
|
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}")
|
||||||
|
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
|
||||||
|
@ -75,7 +75,7 @@ def handle_cmd(args, config):
|
|||||||
if args.plugincmd == 'update':
|
if args.plugincmd == 'update':
|
||||||
return update(config)
|
return update(config)
|
||||||
elif args.plugincmd == 'search':
|
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)
|
return list_plugins(args, config, args.pattern)
|
||||||
elif args.plugincmd == 'install':
|
elif args.plugincmd == 'install':
|
||||||
return install(args, config)
|
return install(args, config)
|
||||||
|
@ -51,8 +51,7 @@ class GdriveSync(plugins.Plugin):
|
|||||||
self.backup = False
|
self.backup = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
gauth = GoogleAuth()
|
gauth = GoogleAuth(settings_file="settings.yaml")
|
||||||
|
|
||||||
gauth.Authorize()
|
gauth.Authorize()
|
||||||
|
|
||||||
# Create GoogleDrive instance
|
# Create GoogleDrive instance
|
||||||
|
@ -22,3 +22,4 @@ torch==2.0.1
|
|||||||
torchvision==0.15.2
|
torchvision==0.15.2
|
||||||
stable_baselines3
|
stable_baselines3
|
||||||
RPi.GPIO
|
RPi.GPIO
|
||||||
|
pydrive2
|
Reference in New Issue
Block a user