This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
forked from TadLeonard/tfatool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflashair-config
executable file
·110 lines (94 loc) · 4.94 KB
/
flashair-config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
import logging
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from tfatool import config, command, cgi, info
from tfatool.info import AuthMode
from tfatool.connection import Connection, DEFAULT_CONNECTION
from requests import RequestException
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, style="{",
format="{asctime} | {levelname} | {name} | {message}")
logging.getLogger("requests").setLevel(logging.WARNING)
parser = ArgumentParser()
parser.add_argument("-m", "--mastercode", default="BEEFBEEFBEEF",
help="12-digit hex mastercode to enable configuration "
"of the FlashAir device")
parser.add_argument("-v", "--verbose", action="store_true")
wifi = parser.add_argument_group("WiFi settings")
wifi.add_argument("-t", "--wifi-timeout", help="set WiFi timeout of device",
type=float)
wifi.add_argument("-w", "--wifi-mode", help="set WiFi mode of device",
choices=[mode.name for mode in info.WifiMode])
wifi.add_argument("-W", "--wifi-mode-on-boot", action="store_true",
help="set the WiFi mode on next boot, not immediately")
wifi.add_argument("-k", "--wifi-key", help="set WiFi security key")
wifi.add_argument("-K", "--passthrough-key",
help="set internet passthrough security key")
wifi.add_argument("-s", "--wifi-ssid", help="set WiFi SSID")
wifi.add_argument("-S", "--passthrough-ssid",
help="set internet passthrough SSID")
other = parser.add_argument_group("Misc settings")
other.add_argument("--app-info", help="set application-specific info")
other.add_argument("--bootscreen-path", help="set path to boot screen image")
other.add_argument("-M", "--clear-mastercode", action="store_true")
other.add_argument("--timezone", type=int,
help="set timezone in hours offset (e.g. -8)")
other.add_argument("-d", "--drive-mode", help="set WebDAV drive mode",
choices=[mode.name for mode in info.DriveMode])
show = parser.add_argument_group("Show configuration parameters")
show.add_argument("--show-wifi-ssid", action="store_true")
show.add_argument("--show-wifi-key", action="store_true")
show.add_argument("--show-mac", action="store_true")
show.add_argument("--show-fw-version", action="store_true")
show.add_argument("--show-wifi-mode", action="store_true")
connection = parser.add_argument_group("Connection")
connection.add_argument("-a", "--auth", choices=[mode.name for mode in AuthMode], default=DEFAULT_CONNECTION.auth.name, help="FlashAir web server authentication mode (default if user/password specified: basic)")
connection.add_argument("-u", "--user", default=DEFAULT_CONNECTION.user,
help="FlashAir web server username, if required (HTTPDUSER)")
connection.add_argument("-p", "--password", default=DEFAULT_CONNECTION.password,
help="FlashAir web server password, if required (HTTPDPASS)")
connection.add_argument("url", nargs="?", default=DEFAULT_CONNECTION.url,
help="Base URL of the FlashAir web server (default: {})".format(
DEFAULT_CONNECTION.url))
def run():
args = parser.parse_args()
if args.verbose:
logging.getLogger().setLevel(logging.DEBUG)
connection = Connection(url=args.url, user=args.user, password=args.password, auth_name=args.auth)
params = ((param, getattr(args, param.name))
for param in config.Config
if getattr(args, param.name) not in (False, None))
params = dict(params)
if args.wifi_mode_on_boot:
if args.wifi_mode:
params[info.Config.wifi_mode] = (
info.WifiModeOnBoot[args.wifi_mode])
else:
parser.error("-W doesn't make sense without -w option")
elif args.wifi_mode:
params[info.Config.wifi_mode] = (
info.WifiMode[args.wifi_mode])
# set config params with a POST
cgi_params = config.config(params)
if len(list(cgi_params.keys())) > 1:
logger.info("CGI params: {}".format(cgi_params))
response = config.post(cgi_params, connection=connection)
logger.info("Response: {}".format(response.status_code))
# show config params with a GET
if args.show_wifi_ssid:
print("SSID: {}".format(command.get_ssid(connection=connection)))
if args.show_wifi_key:
print("WiFi key: {}".format(command.get_password(connection=connection)))
if args.show_mac:
print("MAC address: {}".format(command.get_mac(connection=connection)))
if args.show_fw_version:
print("Firmware version: {}".format(command.get_fw_version(connection=connection)))
if args.show_wifi_mode:
mode = command.get_wifi_mode(connection=connection)
print("WiFi mode: {} ({:d})".format(mode.name, mode.value))
if __name__ == "__main__":
with cgi.session:
try:
run()
except RequestException as e:
print("\nHTTP request exception: {}".format(e))