airos-tui 2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. airos_simulator/__init__.py +87 -0
  2. airos_simulator/__main__.py +11 -0
  3. airos_simulator/cfgfile.py +29 -0
  4. airos_simulator/cli.py +137 -0
  5. airos_simulator/data.py +459 -0
  6. airos_simulator/device.py +895 -0
  7. airos_simulator/frames.py +49 -0
  8. airos_simulator/i18n.py +43 -0
  9. airos_simulator/server.py +220 -0
  10. airos_simulator/web6.py +157 -0
  11. airos_simulator/web8.py +440 -0
  12. airos_tui/__init__.py +7 -0
  13. airos_tui/__main__.py +10 -0
  14. airos_tui/cli.py +694 -0
  15. airos_tui/core/__init__.py +3 -0
  16. airos_tui/core/config.py +315 -0
  17. airos_tui/core/debuglog.py +164 -0
  18. airos_tui/core/errors.py +37 -0
  19. airos_tui/core/i18n.py +66 -0
  20. airos_tui/core/validation.py +145 -0
  21. airos_tui/device/__init__.py +6 -0
  22. airos_tui/device/advnet.py +370 -0
  23. airos_tui/device/airview.py +523 -0
  24. airos_tui/device/client.py +1245 -0
  25. airos_tui/device/dhcp.py +298 -0
  26. airos_tui/device/discovery.py +1058 -0
  27. airos_tui/device/firewall.py +380 -0
  28. airos_tui/device/firmware.py +354 -0
  29. airos_tui/device/graphs.py +180 -0
  30. airos_tui/device/limits.py +423 -0
  31. airos_tui/device/netmode.py +455 -0
  32. airos_tui/device/network.py +483 -0
  33. airos_tui/device/services.py +479 -0
  34. airos_tui/device/stations.py +122 -0
  35. airos_tui/device/status.py +554 -0
  36. airos_tui/device/system.py +619 -0
  37. airos_tui/device/templates.py +378 -0
  38. airos_tui/device/tools.py +430 -0
  39. airos_tui/device/wireless.py +1175 -0
  40. airos_tui/locales/es.json +1802 -0
  41. airos_tui/screens/__init__.py +4 -0
  42. airos_tui/screens/airview.py +59 -0
  43. airos_tui/screens/app.py +573 -0
  44. airos_tui/screens/apply.py +750 -0
  45. airos_tui/screens/discovery.py +178 -0
  46. airos_tui/screens/firmware.py +452 -0
  47. airos_tui/screens/nettools.py +315 -0
  48. airos_tui/screens/network.py +978 -0
  49. airos_tui/screens/network_advanced.py +339 -0
  50. airos_tui/screens/router.py +726 -0
  51. airos_tui/screens/services.py +700 -0
  52. airos_tui/screens/stations.py +151 -0
  53. airos_tui/screens/system.py +943 -0
  54. airos_tui/screens/tools.py +307 -0
  55. airos_tui/screens/ui.py +653 -0
  56. airos_tui/screens/wireless.py +1071 -0
  57. airos_tui/screens/wireless_advanced.py +199 -0
  58. airos_tui/screens/wireless_security.py +323 -0
  59. airos_tui-2.0.dist-info/METADATA +264 -0
  60. airos_tui-2.0.dist-info/RECORD +63 -0
  61. airos_tui-2.0.dist-info/WHEEL +4 -0
  62. airos_tui-2.0.dist-info/entry_points.txt +3 -0
  63. airos_tui-2.0.dist-info/licenses/LICENSE +674 -0
@@ -0,0 +1,87 @@
1
+ """Simulator of an airOS 8 or airOS 6 antenna to test airos-tui without hardware.
2
+
3
+ It only mimics the HTTP paths airos-tui uses, with the behavior seen on the real firmware:
4
+ cookie session, X-CSRF-ID (airOS 8), hidden token in the POSTs (airOS 6), masked passwords,
5
+ a test mode that reverts by itself and a soft restart during which the device does not
6
+ answer. It is not a real airOS.
7
+
8
+ airos-tui-simulator --airos 8 --port 8080
9
+ python3 -m airos_tui http://127.0.0.1:8080 (user ubnt, password ubnt)
10
+
11
+ In router mode (--mode router) the WAN can move to PPPoE: the simulated "provider" accepts
12
+ the user "customer" with the password "secret" and does not support MPPE encryption.
13
+ With --mgmt-ip the simulator answers at the IPs the real device would be reached at
14
+ (management in bridge mode; LAN and, unless management is blocked, WAN in router mode), so
15
+ the network mode change can be tested. --station makes it a client (CPE) instead of an AP.
16
+ With --discovery 10001 it answers discovery on 127.0.0.1, at the real port:
17
+ python3 -m airos_tui --discover --target 127.0.0.1
18
+ With --announce IFACE it also sends CDP (if discovery.cdp.status is enabled) and LLDP (airOS 8,
19
+ unless discovery.lldp.status disables it) through that interface, which needs root: try it in
20
+ a network namespace, for example with unshare -rn and a veth pair.
21
+ With --fw-update v8.7.20, "Check Now" (System → Firmware) finds that firmware, whose notes,
22
+ license and download the simulator itself serves (nothing goes to Ubiquiti), so the whole
23
+ update can be followed; with --fw-update offline it fails as a device without internet does.
24
+ Its airView (airOS 8) hears a made-up spectrum, a new read every second (--airview-period).
25
+
26
+ Its messages follow --lang, AIROS_LANG or the system locale, like airos-tui.
27
+
28
+ The modules, by layers (each one only uses the ones above it):
29
+
30
+ i18n the messages, with airos-tui's own catalog
31
+ data, frames the sample data; the CDP and LLDP announcements
32
+ cfgfile system.cfg as each web reads and writes it; the password hashes
33
+ device the simulated device: its configuration, its restarts, its pages' data
34
+ web8, web6 its HTTP paths, as airOS 8's and airOS 6's web answer them
35
+ server the Handler (web8 and web6 together), the servers and the discovery
36
+ cli the command line (airos-tui-simulator, or python3 -m airos_simulator)
37
+ """
38
+ from __future__ import annotations
39
+
40
+ from .cfgfile import cfg_text, parse_cfg, sim_hash
41
+ from .cli import fw_update_arg, main
42
+ from .data import (BOARD, COMMON_CFG, COUNTRIES, FIRMWARE, LEASES, MAC, MODEL, NET_BRIDGE,
43
+ NET_ROUTER, NEIGHBORS, PPPOE_PASSWORD, PPPOE_SESSION, PPPOE_USER, SURVEY_APS,
44
+ airview_payload, regdomain_v6, regdomain_v8)
45
+ from .device import Device
46
+ from .frames import _checksum, cdp_frame, lldp_frame
47
+ from .i18n import detect_language, set_language, tr
48
+ from .server import (AnnounceError, Cluster, Handler, make_server, serve_announcements,
49
+ serve_discovery)
50
+
51
+ __all__ = [
52
+ "BOARD",
53
+ "COMMON_CFG",
54
+ "COUNTRIES",
55
+ "FIRMWARE",
56
+ "LEASES",
57
+ "MAC",
58
+ "MODEL",
59
+ "NEIGHBORS",
60
+ "NET_BRIDGE",
61
+ "NET_ROUTER",
62
+ "PPPOE_PASSWORD",
63
+ "PPPOE_SESSION",
64
+ "PPPOE_USER",
65
+ "SURVEY_APS",
66
+ "AnnounceError",
67
+ "Cluster",
68
+ "Device",
69
+ "Handler",
70
+ "_checksum",
71
+ "airview_payload",
72
+ "cdp_frame",
73
+ "cfg_text",
74
+ "detect_language",
75
+ "fw_update_arg",
76
+ "lldp_frame",
77
+ "main",
78
+ "make_server",
79
+ "parse_cfg",
80
+ "regdomain_v6",
81
+ "regdomain_v8",
82
+ "serve_announcements",
83
+ "serve_discovery",
84
+ "set_language",
85
+ "sim_hash",
86
+ "tr",
87
+ ]
@@ -0,0 +1,11 @@
1
+ """python3 -m airos_simulator: the same as airos-tui-simulator (the tests run this file)."""
2
+ import os
3
+ import sys
4
+
5
+ if __package__: # python3 -m airos_simulator
6
+ from .cli import main
7
+ else: # python3 airos_simulator/__main__.py
8
+ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
+ from airos_simulator.cli import main
10
+
11
+ sys.exit(main())
@@ -0,0 +1,29 @@
1
+ """system.cfg as each web reads and writes it, and this simulator's password hashes
2
+ (with the password behind each, so that a backup applied to another device logs in)."""
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+
7
+
8
+ def parse_cfg(text: str) -> dict[str, str]:
9
+ out = {}
10
+ for line in text.replace("\r", "").split("\n"):
11
+ if "=" in line and line.strip():
12
+ k, v = line.split("=", 1)
13
+ out[k.strip()] = v
14
+ return out
15
+
16
+
17
+ def cfg_text(cfg: dict[str, str]) -> str:
18
+ return "".join(f"{k}={v}\n" for k, v in sorted(cfg.items()))
19
+
20
+ SIM_PASSWORDS: dict[str, str] = {} # (each hash of sim_hash, and its password)
21
+
22
+
23
+ def sim_hash(password: str) -> str:
24
+ """This simulator's password hash (as an MD5-crypt one looks, $1$…, with no salt); it
25
+ remembers whose it is: once a backup of another simulated device is applied, its password
26
+ logs in."""
27
+ digest = "$1$simulated$" + hashlib.md5(password.encode()).hexdigest()[:22]
28
+ SIM_PASSWORDS[digest] = password
29
+ return digest
airos_simulator/cli.py ADDED
@@ -0,0 +1,137 @@
1
+ """The simulator's command line (airos-tui-simulator, or python3 -m airos_simulator)."""
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import re
6
+ import sys
7
+ from .i18n import LANGUAGES, detect_language, set_language, tr
8
+ from .data import PPPOE_PASSWORD, PPPOE_USER
9
+ from .server import AnnounceError, make_server
10
+
11
+
12
+ def _lang_arg(argv) -> str | None:
13
+ """--lang LANG or --lang=LANG, read before parsing so that --help comes out translated."""
14
+ args = list(sys.argv[1:] if argv is None else argv)
15
+ for i, a in enumerate(args):
16
+ if a == "--lang" and i + 1 < len(args):
17
+ return args[i + 1]
18
+ if a.startswith("--lang="):
19
+ return a.split("=", 1)[1]
20
+ return None
21
+
22
+
23
+ def fw_update_arg(value: str) -> str:
24
+ """--fw-update: "offline", or the firmware the update check finds as the simulated server
25
+ gives it (WA.v8.7.20, from v8.7.20, 8.7.20 or WA.v8.7.20). ValueError if it is neither."""
26
+ text = value.strip()
27
+ if text.lower() == "offline":
28
+ return "offline"
29
+ m = re.fullmatch(r"(?:WA\.)?v?([0-9]+\.[0-9]+\.[0-9]+)", text, re.I)
30
+ if not m:
31
+ raise ValueError(value)
32
+ return f"WA.v{m.group(1)}"
33
+
34
+
35
+ def main(argv=None) -> None:
36
+ set_language(detect_language(_lang_arg(argv)))
37
+ ap = argparse.ArgumentParser(description=tr("airOS antenna simulator to test airos-tui."))
38
+ ap.add_argument("--airos", type=int, choices=(6, 8), default=8)
39
+ ap.add_argument("--port", type=int, default=8080, metavar=tr("PORT"))
40
+ ap.add_argument("--user", default="ubnt", metavar=tr("USER"))
41
+ ap.add_argument("--password", default="ubnt", metavar=tr("PASSWORD"))
42
+ ap.add_argument("--restart", type=float, default=8.0, metavar=tr("SEC"),
43
+ help=tr("seconds without answering after applying (default 8)"))
44
+ ap.add_argument("--test-time", type=int, default=180, metavar=tr("SEC"),
45
+ help=tr("test mode length in seconds (default 180)"))
46
+ ap.add_argument("--mode", choices=("bridge", "router"), default="bridge",
47
+ help=tr("network mode of the initial configuration"))
48
+ ap.add_argument("--mgmt-ip", metavar="127.0.0.X",
49
+ help=tr("management IP (or the LAN IP in router mode) within 127.0.0.0/8: "
50
+ "the simulator answers there and moves if you change it"))
51
+ ap.add_argument("--dhcp-ip", default="127.0.0.77", metavar="127.0.0.X",
52
+ help=tr('IP it "gets" over DHCP with --mgmt-ip (default 127.0.0.77)'))
53
+ ap.add_argument("--advanced", action="store_true",
54
+ help=tr("the advanced network configuration of the airOS 8 web (where it "
55
+ "has the firewall and the DHCP reservations)"))
56
+ ap.add_argument("--station", action="store_true",
57
+ help=tr("station (client, CPE) instead of access point"))
58
+ ap.add_argument("--web-follow", action="store_true",
59
+ help=tr("airOS 8: its web answers at the port of its configuration "
60
+ "(httpd.port, PORT at first) and moves if you change it, as the "
61
+ "real one does (over HTTP only)"))
62
+ ap.add_argument("--discovery", type=int, metavar=tr("PORT"),
63
+ help=tr("answer Ubiquiti discovery on 127.0.0.1:PORT"))
64
+ ap.add_argument("--announce", metavar=tr("IFACE"),
65
+ help=tr("send CDP and LLDP announcements through IFACE as the device would "
66
+ "(it needs root or CAP_NET_RAW: use it inside a network namespace)"))
67
+ ap.add_argument("--announce-every", type=float, default=60.0, metavar=tr("SEC"),
68
+ help=tr("seconds between announcements (default 60)"))
69
+ ap.add_argument("--emergency", type=int, choices=(0, 1, 2, 3), metavar=tr("CODE"),
70
+ help=tr("the notice the device has as it starts (airOS 8): 0 a reboot by "
71
+ "the ping watchdog, 1 a flash memory failure, 2 or 3 a crash"))
72
+ ap.add_argument("--fw-update", metavar=tr("VERSION"),
73
+ help=tr('what "Check Now" finds (airOS 8): a newer firmware, for example '
74
+ 'v8.7.20, which the simulator itself serves, or "offline" to fail '
75
+ 'as a device without internet does'))
76
+ ap.add_argument("--no-setup-wizard", action="store_true",
77
+ help=tr("an airOS 8 older than its first setup: after a reset, user and "
78
+ "password ubnt (by default, as 8.7.x, it waits for its first setup: "
79
+ "the country, its terms and a new administrator)"))
80
+ ap.add_argument("--first-setup", action="store_true",
81
+ help=tr("airOS 8 waiting for its first setup now, as just reset (--user and "
82
+ "--password: the factory ones)"))
83
+ ap.add_argument("--factory-password", action="store_true",
84
+ help=tr("airOS 8 set up, but with the factory password still: its web asks "
85
+ "for a new administrator, or a backup (--user and --password: the "
86
+ "factory ones)"))
87
+ ap.add_argument("--airview-period", type=float, default=1.0, metavar=tr("SEC"),
88
+ help=tr("seconds between the reads of its airView (airOS 8, default 1; a "
89
+ "real one gives one every 6 or so)"))
90
+ ap.add_argument("-v", "--verbose", action="store_true",
91
+ help=tr("log every request to stderr"))
92
+ ap.add_argument("--lang", choices=LANGUAGES,
93
+ help=tr("interface language (default: AIROS_LANG or the system locale)"))
94
+ a = ap.parse_args(argv)
95
+ if a.lang:
96
+ set_language(a.lang)
97
+ if a.mgmt_ip and not a.mgmt_ip.startswith("127."):
98
+ ap.error(tr("--mgmt-ip must be within 127.0.0.0/8"))
99
+ fw_update = None
100
+ if a.fw_update is not None:
101
+ if a.airos != 8:
102
+ ap.error(tr("--fw-update only applies to airOS 8"))
103
+ try:
104
+ fw_update = fw_update_arg(a.fw_update)
105
+ except ValueError:
106
+ ap.error(tr('--fw-update: "{value}" is not a version such as v8.7.20, nor "offline"',
107
+ value=a.fw_update))
108
+ try:
109
+ srv = make_server(a.airos, a.port, a.user, a.password, a.restart, a.test_time,
110
+ verbose=a.verbose, mode=a.mode, mgmt_ip=a.mgmt_ip,
111
+ dhcp_ip=a.dhcp_ip, discovery_port=a.discovery, station=a.station,
112
+ announce=a.announce, announce_every=a.announce_every,
113
+ emergency=-1 if a.emergency is None else a.emergency,
114
+ fw_update=fw_update, web_follow=a.web_follow,
115
+ setup_wizard=not a.no_setup_wizard, first_setup=a.first_setup,
116
+ factory_password=a.factory_password)
117
+ except AnnounceError as e:
118
+ ap.error(tr("--announce needs root or CAP_NET_RAW ({error})", error=e))
119
+ if a.advanced:
120
+ for cfg in (srv.dev.running, srv.dev.saved, srv.dev.system):
121
+ cfg["gui.network.advanced.status"] = "enabled"
122
+ srv.dev.airview_period = a.airview_period
123
+ host = a.mgmt_ip or "127.0.0.1"
124
+ print(tr("airOS {version} simulator ({mode}) at http://{host}:{port} (user {user}, "
125
+ "password {password}). Ctrl+C to exit.", version=a.airos, mode=a.mode, host=host,
126
+ port=a.port, user=a.user, password=a.password))
127
+ if fw_update == "offline":
128
+ print(tr('"Check Now" fails, as on a device without internet.'))
129
+ elif fw_update:
130
+ print(tr('"Check Now" finds the firmware {version}.', version=fw_update))
131
+ if a.mode == "router":
132
+ print(tr("PPPoE on the WAN: the simulated provider accepts {user} / {password}.",
133
+ user=PPPOE_USER, password=PPPOE_PASSWORD))
134
+ try:
135
+ srv.serve_forever()
136
+ except KeyboardInterrupt:
137
+ pass