-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
fpms.py
executable file
·1351 lines (1113 loc) · 45.9 KB
/
fpms.py
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
"""
FPMS
~~~~
Front Panel Menu System
"""
import dbus
import dbus.mainloop.glib
from gi.repository import GLib
import syslog
import configparser
import getopt
import gpiod
import os
import os.path
import random
import signal
import socket
import subprocess
import sys
import termios
import threading
import time
import tty
import types
from PIL import Image, ImageDraw, ImageFont
from gpiod.line import Bias, Edge
from datetime import timedelta
# Check we're running as root
if not os.geteuid()==0:
print("fpms must be run as root ... exiting ...")
sys.exit(-1)
from .__version__ import __title__, __version__
from .modules import wlanpi_oled as oled
from .modules.apps.kismet import *
from .modules.apps.profiler import *
from .modules.apps.scanner import *
from .modules.bluetooth import *
from .modules.cloud_tests import CloudUtils
from .modules.constants import *
from .modules.env_utils import EnvUtils
from .modules.modes import *
from .modules.nav.buttons import Button
from .modules.network import *
from .modules.pages.display import Display
from .modules.pages.homepage import HomePage
from .modules.pages.page import Page
from .modules.pages.pagedtable import PagedTable
from .modules.pages.simpletable import SimpleTable
from .modules.system import *
from .modules.battery import *
from .modules.utils import *
from .modules.reg_domain import *
from .modules.time_zone import *
FPMS_CONF_FILE = "/etc/wlanpi-fpms.conf"
#######################################
# Initialize various global variables
#######################################
g_vars = {
##################################################
# Shared status signals (may be changed anywhere)
##################################################
# This variable is shared between activities and is set to True if a
# drawing action in already if progress (e.g. by another activity). An activity
# happens during each cycle of the main while loop or when a button is pressed
# (This does not appear to be threading or process spawning)
'display_orientation': DISPLAY_ORIENTATION_NORMAL, # Display module orientation
'drawing_in_progress': False, # True when page being painted on screen
'shutdown_in_progress': False, # True when shutdown or reboot started
'screen_cleared': False, # True when display cleared (e.g. screen save)
'display_state': 'page', # current display state: 'page' or 'menu'
'sig_fired': False, # Set to True when button handler fired
'option_selected': 0, # Content of currently selected menu level
'current_menu_location': [0], # Pointer to current location in menu structure
'current_scroll_selection': 0, # where we currently are in scrolling table
'current_mode': 'classic', # Currently selected mode (e.g. wconsole/classic)
'start_up': True, # True if in initial (home page) start-up state
'disable_keys': False, # Set to true when need to ignore key presses
'table_list_length': 0, # Total length of currently displayed table
'table_pages': 1, # pages in current table
'result_cache': False, # used to cache results when paging info
'speedtest_result_text': '', # tablulated speedtest result data
'button_press_count': 0, # global count of button pressses
'last_button_press_count': -1, # copy of count of button pressses used in main loop
'pageSleepCountdown': PAGE_SLEEP, # Set page sleep control
'home_page_name': "Home", # Display name for top level menu
'home_page_alternate': False, # True if in alternate home page state
'blinker_status': False, # Blinker status
'eth_carrier_status': 0, # Eth0 physical link status
'eth_last_known_address_set': None,# Last known ethernet addresses
'eth_last_reachability_test': 0, # Number of seconds elapsed since last reachability test
'eth_last_reachability_result' : False,# Last reachability state
'scan_file' : '', # Location to save scans
'profiler_beaconing' : False, # Indicates if the profiler is running
'profiler_last_profile_date': None, # The date of the last profile
'timezones_available' : [], # The list of Timezones the system can support
'timezone_selected' : None # The timezone selected from the menu for use in other functions
}
def log_to_syslog(message, level=syslog.LOG_INFO):
syslog.openlog(ident="fpms", logoption=syslog.LOG_PID, facility=syslog.LOG_USER)
syslog.syslog(level, message)
syslog.closelog()
def handle_reboot_or_shutdown(shutdown=False):
global g_vars
log_to_syslog(f"shutdown_in_progress: {g_vars['shutdown_in_progress']}")
if not g_vars['shutdown_in_progress']:
g_vars['shutdown_in_progress'] = True
log_to_syslog("Drawing shutdown/reboot image")
if shutdown == True:
oled.drawImage(g_vars['shutdown_image'])
else:
oled.drawImage(g_vars['reboot_image'])
log_to_syslog("Shutdown/reboot image drawn")
# Handler for PrepareForShutdown signal
def handle_prepare_for_shutdown(arg):
log_to_syslog("PrepareForShutdown signal received")
handle_reboot_or_shutdown()
# Handler for JobNew signal
def handle_jobnew(*args):
log_to_syslog("JobNew signal received")
for arg in args:
if isinstance(arg, str):
if ("reboot.target" in arg):
handle_reboot_or_shutdown()
elif ("halt.target" in arg) or ("poweroff.target" in arg):
handle_reboot_or_shutdown(True)
def run_dbus_loop():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
# Connect to the system bus
bus = dbus.SystemBus()
# Get the org.freedesktop.login1.Manager interface
login1_proxy = bus.get_object('org.freedesktop.login1', '/org/freedesktop/login1')
login1 = dbus.Interface(login1_proxy, 'org.freedesktop.login1.Manager')
# Take an inhibitor lock to receive the PrepareForShutdown signal
fd = login1.Inhibit("shutdown", "fpms", "Delaying shutdown", "delay")
# Add a signal receiver for the "PrepareForShutdown" signal from login1.Manager
# Handles systemctl reboot
bus.add_signal_receiver(
handle_prepare_for_shutdown,
signal_name="PrepareForShutdown",
dbus_interface="org.freedesktop.login1.Manager",
bus_name="org.freedesktop.login1",
path="/org/freedesktop/login1"
)
# Add a signal receiver for JobNew signal from systemd1.Manager
# Handles (legacy) reboot
bus.add_signal_receiver(
handle_jobnew,
dbus_interface="org.freedesktop.systemd1.Manager",
signal_name="JobNew"
)
log_to_syslog(f"event handlers added")
# Run indefinitely to handle D-Bus signals
loop = GLib.MainLoop()
loop.run()
# Function to read a value from a section in the .conf file
def read_value(section, key, default_value):
config = configparser.ConfigParser()
config.read(FPMS_CONF_FILE)
# Read the value from the specified section and key
if config.has_section(section) and config.has_option(section, key):
value = config.get(section, key)
return value
else:
return default_value
# Function to modify and save a value in the specified section and key
def save_value(section, key, new_value):
config = configparser.ConfigParser()
config.read(FPMS_CONF_FILE)
# Check if the section exists, if not, create it
if not config.has_section(section):
config.add_section(section)
# Modify or add the value
config.set(section, key, new_value)
# Write the updated config back to the file
with open(FPMS_CONF_FILE, 'w') as f:
config.write(f)
def main():
# Run D-Bus main loop in a separate thread
dbus_thread = threading.Thread(target=run_dbus_loop)
dbus_thread.daemon = True
dbus_thread.start()
log_to_syslog(f"fpms starting after dbus thread setup")
global g_vars
global running
####################################
# Parse arguments
####################################
def authors():
authors = os.path.realpath(os.path.join(os.getcwd(), "AUTHORS.md"))
if not os.path.isfile(authors):
# Couldn't find authors
print(authors)
return ""
else:
with open(authors) as f:
return "\n".join(filter(None, [line if line.startswith('*') else "" for line in f.read().splitlines()]))
def usage():
return """
usage: fpms [-a] [-h] [-e] [-v]
wlanpi-fpms drives the Front Panel Menu System on the WLAN Pi
optional options:
-a print authors
-e emulate buttons from keyboard
-h show this message and exit
-v show module version and exit
"""
try:
opts, _args = getopt.getopt(sys.argv[1:], ":ahev", ["authors", "help", "emulate-buttons", "version"])
except getopt.GetoptError as error:
print("{0} ... ".format(error))
print(usage())
sys.exit(2)
emulate = False
for opt, arg in opts:
if opt in ['-e', "--emulate-buttons"]:
emulate = True
elif opt in ("-a", "--authors"):
print(authors())
sys.exit()
elif opt in ("-h", "--help"):
print(usage())
sys.exit()
elif opt in ("-v", "--version"):
print("{0} {1}".format(__title__, __version__))
sys.exit()
else:
assert False, "unhandled option"
####################################
# Initialize the SEED OLED display
####################################
oled.init()
g_vars['display_orientation'] = read_value("display", "orientation", DISPLAY_ORIENTATION_NORMAL)
oled.orientation = g_vars['display_orientation']
############################
# shared objects
############################
g_vars['image'] = Image.new(DISPLAY_MODE, (PAGE_WIDTH, PAGE_HEIGHT))
g_vars['draw'] = ImageDraw.Draw(g_vars['image'])
g_vars['reboot_image'] = Image.open(IMAGE_DIR + '/reboot.png').convert(DISPLAY_MODE)
g_vars['shutdown_image'] = Image.open(IMAGE_DIR + '/shutdown.png').convert(DISPLAY_MODE)
#####################################
# check our current operating mode
#####################################
env_utils = EnvUtils()
g_vars['current_mode'] = env_utils.get_mode(MODE_FILE)
##################################
# Static info we want to get once
##################################
# get & the current version of WLANPi image
g_vars['wlanpi_ver'] = env_utils.get_image_ver(WLANPI_IMAGE_FILE)
# ################################
# Other state initialization
# ################################
profiler = Profiler(g_vars)
g_vars['profiler_last_profile_date'] = profiler.profiler_last_profile_date()
g_vars['profiler_beaconing'] = profiler.profiler_beaconing()
timezone = TimeZone(g_vars)
timezones_available = timezone.get_timezones_menu_format()
###########################
# Network menu area utils
###########################
def show_interfaces():
network_obj = Network(g_vars)
network_obj.show_interfaces(g_vars)
def show_wlan_interfaces():
network_obj = Network(g_vars)
network_obj.show_wlan_interfaces(g_vars)
def show_eth0_ipconfig():
network_obj = Network(g_vars)
network_obj.show_eth0_ipconfig(g_vars)
def show_vlan():
network_obj = Network(g_vars)
network_obj.show_vlan(g_vars)
def show_lldp_neighbour():
network_obj = Network(g_vars)
network_obj.show_lldp_neighbour(g_vars)
def show_cdp_neighbour():
network_obj = Network(g_vars)
network_obj.show_cdp_neighbour(g_vars)
def show_publicip():
network_obj = Network(g_vars)
network_obj.show_publicip(g_vars)
def show_publicip6():
network_obj = Network(g_vars)
network_obj.show_publicip(g_vars, ip_version=6)
###########################
# Bluetooth menu area
###########################
def bluetooth_status():
bluetooth_obj = Bluetooth(g_vars)
bluetooth_obj.bluetooth_status(g_vars)
def bluetooth_pair():
bluetooth_obj = Bluetooth(g_vars)
bluetooth_obj.bluetooth_pair(g_vars)
def bluetooth_on():
bluetooth_obj = Bluetooth(g_vars)
bluetooth_obj.bluetooth_on(g_vars)
def bluetooth_off():
bluetooth_obj = Bluetooth(g_vars)
bluetooth_obj.bluetooth_off(g_vars)
###########################
# Utils menu area
###########################
def show_reachability():
utils_obj = Utils(g_vars)
utils_obj.show_reachability(g_vars)
def show_speedtest():
utils_obj = Utils(g_vars)
utils_obj.show_speedtest(g_vars)
def show_ruckus_test():
utils_obj = CloudUtils(g_vars)
utils_obj.test_ruckus_cloud(g_vars)
def show_mist_test():
utils_obj = CloudUtils(g_vars)
utils_obj.test_mist_cloud(g_vars)
def show_aruba_test():
utils_obj = CloudUtils(g_vars)
utils_obj.test_aruba_cloud(g_vars)
def show_extreme_test():
utils_obj = CloudUtils(g_vars)
utils_obj.test_extreme_cloud(g_vars)
def show_blinker():
utils_obj = Utils(g_vars)
utils_obj.show_blinker(g_vars)
def stop_blinker():
utils_obj = Utils(g_vars)
utils_obj.stop_blinker(g_vars)
def show_ssid_passphrase():
utils_obj = Utils(g_vars)
utils_obj.show_ssid_passphrase(g_vars)
def show_usb():
utils_obj = Utils(g_vars)
utils_obj.show_usb(g_vars)
def show_ufw():
utils_obj = Utils(g_vars)
utils_obj.show_ufw(g_vars)
############################
# Modes area
############################
def wconsole_switcher():
mode_obj = Mode(g_vars)
mode_obj.wconsole_switcher(g_vars)
def hotspot_switcher():
mode_obj = Mode(g_vars)
mode_obj.hotspot_switcher(g_vars)
def wiperf_switcher():
mode_obj = Mode(g_vars)
mode_obj.wiperf_switcher(g_vars)
def server_switcher():
mode_obj = Mode(g_vars)
mode_obj.server_switcher(g_vars)
def bridge_switcher():
mode_obj = Mode(g_vars)
mode_obj.bridge_switcher(g_vars)
###########################
# Apps area
###########################
def kismet_start():
app_obj = Kismet(g_vars)
app_obj.kismet_start(g_vars)
def kismet_stop():
app_obj = Kismet(g_vars)
app_obj.kismet_stop(g_vars)
def profiler_status():
app_obj = Profiler(g_vars)
app_obj.profiler_status(g_vars)
def profiler_stop():
app_obj = Profiler(g_vars)
app_obj.profiler_stop(g_vars)
def profiler_start():
app_obj = Profiler(g_vars)
app_obj.profiler_start(g_vars)
def profiler_start_2dot4ghz():
app_obj = Profiler(g_vars)
app_obj.profiler_start_2dot4ghz(g_vars)
def profiler_start_5ghz_unii1():
app_obj = Profiler(g_vars)
app_obj.profiler_start_5ghz_unii1(g_vars)
def profiler_start_5ghz_unii3():
app_obj = Profiler(g_vars)
app_obj.profiler_start_5ghz_unii3(g_vars)
def profiler_start_no11r():
app_obj = Profiler(g_vars)
app_obj.profiler_start_no11r(g_vars)
def profiler_start_no11ax():
app_obj = Profiler(g_vars)
app_obj.profiler_start_no11ax(g_vars)
def profiler_purge_reports():
app_obj = Profiler(g_vars)
app_obj.profiler_purge_reports(g_vars)
def profiler_purge_files():
app_obj = Profiler(g_vars)
app_obj.profiler_purge_files(g_vars)
def scanner_scan():
app_obj = Scanner(g_vars)
app_obj.scanner_scan(g_vars)
def scanner_scan_nohidden():
app_obj = Scanner(g_vars)
app_obj.scanner_scan_nohidden(g_vars)
def scanner_scan_tofile_csv():
app_obj = Scanner(g_vars)
app_obj.scanner_scan_tofile_csv(g_vars)
def scanner_scan_tofile_pcap_start():
app_obj = Scanner(g_vars)
app_obj.scanner_scan_tofile_pcap_start(g_vars)
def scanner_scan_tofile_pcap_stop():
app_obj = Scanner(g_vars)
app_obj.scanner_scan_tofile_pcap_stop(g_vars)
###########################
# System menu area utils
###########################
def shutdown():
system_obj = System(g_vars)
system_obj.shutdown(g_vars)
def reboot():
system_obj = System(g_vars)
system_obj.reboot(g_vars)
def show_summary():
system_obj = System(g_vars)
system_obj.show_summary(g_vars)
def show_battery():
system_obj = Battery(g_vars)
system_obj.show_battery(g_vars)
def show_reg_domain():
system_obj = RegDomain(g_vars)
system_obj.show_reg_domain(g_vars)
def set_reg_domain_us():
system_obj = RegDomain(g_vars)
system_obj.set_reg_domain_us(g_vars)
def set_reg_domain_ca():
system_obj = RegDomain(g_vars)
system_obj.set_reg_domain_ca(g_vars)
def set_reg_domain_gb():
system_obj = RegDomain(g_vars)
system_obj.set_reg_domain_gb(g_vars)
def set_reg_domain_br():
system_obj = RegDomain(g_vars)
system_obj.set_reg_domain_br(g_vars)
def set_reg_domain_fr():
system_obj = RegDomain(g_vars)
system_obj.set_reg_domain_fr(g_vars)
def set_reg_domain_cz():
system_obj = RegDomain(g_vars)
system_obj.set_reg_domain_cz(g_vars)
def set_reg_domain_nl():
system_obj = RegDomain(g_vars)
system_obj.set_reg_domain_nl(g_vars)
def set_reg_domain_de():
system_obj = RegDomain(g_vars)
system_obj.set_reg_domain_de(g_vars)
def rotate_display():
if g_vars['display_orientation'] == DISPLAY_ORIENTATION_NORMAL:
g_vars['display_orientation'] = DISPLAY_ORIENTATION_FLIPPED
else:
g_vars['display_orientation'] = DISPLAY_ORIENTATION_NORMAL
oled.orientation = g_vars['display_orientation']
save_value("display", "orientation", g_vars['display_orientation'])
g_vars['sig_fired'] = True
menu_left()
g_vars['sig_fired'] = False
def show_date():
system_obj = System(g_vars)
system_obj.show_date(g_vars)
def set_time_zone_auto():
system_obj = TimeZone(g_vars)
system_obj.set_time_zone_auto(g_vars)
def set_time_zone():
g_vars['timezone_selected'] = (timezones_available[g_vars['current_menu_location'][5]]['country'] +
"/" +
timezones_available[g_vars['current_menu_location'][5]]['timezones'][g_vars['current_menu_location'][6]])
system_obj = TimeZone(g_vars)
system_obj.set_time_zone_from_gvars(g_vars)
def show_about():
system_obj = System(g_vars)
system_obj.show_about(g_vars)
def show_help():
system_obj = System(g_vars)
system_obj.show_help(g_vars)
def check_for_updates():
system_obj = System(g_vars)
system_obj.check_for_updates(g_vars)
def install_updates():
system_obj = System(g_vars)
system_obj.install_updates(g_vars)
#############################
# Button presses & home page
#############################
def home_page():
homepage_obj = HomePage(g_vars)
homepage_obj.home_page(g_vars, menu)
def menu_down():
button_obj = Button(g_vars, menu)
button_obj.menu_down(g_vars, menu)
def menu_up():
button_obj = Button(g_vars, menu)
button_obj.menu_up(g_vars, menu)
def menu_left():
button_obj = Button(g_vars, menu)
button_obj.menu_left(g_vars, menu)
def menu_right():
button_obj = Button(g_vars, menu)
button_obj.menu_right(g_vars, menu)
def menu_center():
button_obj = Button(g_vars, menu)
button_obj.menu_center(g_vars, menu)
def menu_key1():
shortcuts = [
create_shortcut(menu, ["Utils", "Reachability"]),
create_shortcut(menu, ["Network", "LLDP Neighbour"]),
create_shortcut(menu, ["Network", "Eth0 IP Config"])
]
option_selected = g_vars['option_selected']
option_index = 0
option_found = False
if g_vars['display_state'] == 'page':
for shortcut in shortcuts:
if option_selected == shortcut[-1]:
option_found = True
break
option_index += 1
next_index = 0
if option_found:
next_index = (option_index + 1) % len(shortcuts)
next_shortcut = shortcuts[next_index]
button_obj = Button(g_vars, menu)
button_obj.shortcut(g_vars, menu, next_shortcut)
def menu_key2():
shortcut = create_shortcut(menu, ["Mode", "Classic Mode"])
if g_vars['current_mode'] == "classic":
shortcut = create_shortcut(menu, ["Modes", "Hotspot"])
# Switch to menu item
button_obj = Button(g_vars, menu)
button_obj.shortcut(g_vars, menu, shortcut)
def menu_key3():
index = 0
reboot_shortcut = create_shortcut(menu, ["System", "Reboot"])
shutdown_shortcut = create_shortcut(menu, ["System", "Shutdown"])
# Select the next path
next_shortcut = reboot_shortcut
if g_vars['current_menu_location'][:-1] == reboot_shortcut:
next_shortcut = shutdown_shortcut
# Switch to menu
button_obj = Button(g_vars, menu)
button_obj.shortcut(g_vars, menu, next_shortcut)
def create_shortcut(menu, path, location=[]):
if isinstance(menu, types.FunctionType):
if len(path) > 0:
raise Exception("invalid path")
return [menu]
if len(path) > 0:
index = 0
for item in menu:
if item["name"] == path[0]:
return [index] + create_shortcut(item["action"], path[1:], location)
index += 1
return []
#######################
# menu structure here
#######################
# translate the timezone list into menu items (needs to be after definition of set_time_zone)
for timezones_country in timezones_available:
g_vars['timezones_available'].append({"name": timezones_country['country'], "action": []})
for timezone in timezones_country['timezones']:
g_vars['timezones_available'][-1]['action'].append({"name": timezone, "action": set_time_zone})
# assume classic mode menu initially...
menu = [
{"name": "Network", "action": [
{"name": "Interfaces", "action": show_interfaces},
{"name": "WLAN Interfaces", "action": show_wlan_interfaces},
{"name": "Eth0 IP Config", "action": show_eth0_ipconfig},
{"name": "Eth0 VLAN", "action": show_vlan},
{"name": "LLDP Neighbour", "action": show_lldp_neighbour},
{"name": "CDP Neighbour", "action": show_cdp_neighbour},
{"name": "Public IPv4", "action": show_publicip},
{"name": "Public IPv6", "action": show_publicip6},
]
},
{"name": "Bluetooth", "action": [
{"name": "Status", "action": bluetooth_status},
{"name": "Turn On", "action": bluetooth_on},
{"name": "Turn Off", "action": bluetooth_off},
{"name": "Pair Device", "action": bluetooth_pair},
]
},
{"name": "Utils", "action": [
{"name": "Reachability", "action": show_reachability},
{"name": "Speedtest", "action": [
{"name": "Run Test", "action": show_speedtest},
]
},
{"name": "Cloud Tests", "action": [
{"name": "Aruba Central", "action": show_aruba_test},
{"name": "ExtremeCloud IQ", "action": show_extreme_test},
{"name": "Mist Cloud", "action": show_mist_test},
{"name": "RUCKUS Cloud", "action": show_ruckus_test},
]
},
{"name": "Port Blinker", "action": [
{"name": "Start", "action": show_blinker},
{"name": "Stop", "action": stop_blinker},
]
},
{"name": "SSID/Passphrase", "action": show_ssid_passphrase},
{"name": "USB Devices", "action": show_usb},
{"name": "UFW Ports", "action": show_ufw},
]
},
{"name": "Modes", "action": [
{"name": "Wi-Fi Console", "action": [
{"name": "Confirm", "action": wconsole_switcher},
]
},
{"name": "Hotspot", "action": [
{"name": "Confirm", "action": hotspot_switcher},
]
},
#{"name": "Wiperf", "action": [
# {"name": "Confirm", "action": wiperf_switcher},
#]
#},
{"name": "Server", "action": [
{"name": "Confirm", "action": server_switcher},
]
},
{"name": "Bridge", "action": [
{"name": "Confirm", "action": bridge_switcher},
]
},
]
},
{"name": "Apps", "action": [
{"name": "Kismet", "action": [
{"name": "Start", "action": kismet_start},
{"name": "Stop", "action": kismet_stop},
]
},
{"name": "Profiler", "action": [
{"name": "Status", "action": profiler_status},
{"name": "Stop", "action": profiler_stop},
{"name": "Start", "action": profiler_start},
{"name": "Start Other", "action": [
{"name": "Start 2.4 GHz", "action": profiler_start_2dot4ghz},
{"name": "Start 5 GHz 36", "action": profiler_start_5ghz_unii1},
{"name": "Start 5 GHz 149", "action": profiler_start_5ghz_unii3},
{"name": "Start (no 11r)", "action": profiler_start_no11r},
{"name": "Start (no 11ax)", "action": profiler_start_no11ax}
]
},
{"name": "Purge Reports", "action": [
{"name": "Confirm", "action": profiler_purge_reports},
]
},
{"name": "Purge Files", "action": [
{"name": "Confirm", "action": profiler_purge_files},
]
}
]
},
{"name": "Scanner", "action": [
{"name": "Scan", "action": scanner_scan},
{"name": "Scan (no hidden)", "action": scanner_scan_nohidden},
{"name": "Scan to CSV", "action": scanner_scan_tofile_csv},
{"name": "Scan to PCAP", "action": [
{"name": "Start", "action" : scanner_scan_tofile_pcap_start},
{"name": "Stop", "action" : scanner_scan_tofile_pcap_stop}
]}
]
},
]
},
{"name": "System", "action": [
{"name": "About", "action": show_about},
{"name": "Help", "action": show_help},
{"name": "Summary", "action": show_summary},
{"name": "Battery", "action": show_battery},
{"name": "Settings", "action": [
{"name": "Date & Time", "action": [
{"name": "Show Time & Zone", "action": show_date},
{"name": "Set Timezone", "action": [
{"name": "Auto", "action" : set_time_zone_auto},
{"name": "Manual", "action": g_vars['timezones_available']}
]},
]},
{"name": "RF Domain", "action": [
{"name": "Show Domain", "action": show_reg_domain},
{"name": "Set Domain US", "action": [
{"name": "Confirm & Reboot", "action": set_reg_domain_us},]},
{"name": "Set Domain CA", "action": [
{"name": "Confirm & Reboot", "action": set_reg_domain_ca},]},
{"name": "Set Domain GB", "action": [
{"name": "Confirm & Reboot", "action": set_reg_domain_gb},]},
{"name": "Set Domain BR", "action": [
{"name": "Confirm & Reboot", "action": set_reg_domain_br},]},
{"name": "Set Domain FR", "action": [
{"name": "Confirm & Reboot", "action": set_reg_domain_fr},]},
{"name": "Set Domain CZ", "action": [
{"name": "Confirm & Reboot", "action": set_reg_domain_cz},]},
{"name": "Set Domain NL", "action": [
{"name": "Confirm & Reboot", "action": set_reg_domain_nl},]},
{"name": "Set Domain DE", "action": [
{"name": "Confirm & Reboot", "action": set_reg_domain_de},]},
]},
{"name": "Rotate Display", "action": rotate_display}
]},
{"name": "Reboot", "action": [
{"name": "Confirm", "action": reboot},
]
},
{"name": "Shutdown", "action": [
{"name": "Confirm", "action": shutdown},
]
},
]
},
]
# update menu options data structure if we're in non-classic mode
if g_vars['current_mode'] == "wconsole":
switcher_dispatcher = wconsole_switcher
g_vars['home_page_name'] = "Wi-Fi Console"
if g_vars['current_mode'] == "hotspot":
switcher_dispatcher = hotspot_switcher
g_vars['home_page_name'] = "Hotspot"
if g_vars['current_mode'] == "wiperf":
switcher_dispatcher = wiperf_switcher
g_vars['home_page_name'] = "Wiperf"
if g_vars['current_mode'] == "server":
switcher_dispatcher = server_switcher
g_vars['home_page_name'] = "Server"
if g_vars['current_mode'] == "bridge":
switcher_dispatcher = bridge_switcher
g_vars['home_page_name'] = "Bridge"
if g_vars['current_mode'] == "classic":
# Remove Utils > SSID/Passphrase
for item in menu:
if item["name"] == "Utils":
for action in item["action"]:
if action["name"] == "SSID/Passphrase":
item["action"].remove(action)
break
else:
# Adjust Modes menu
for item in menu:
if item["name"] == "Modes":
item["name"] = "Mode"
item["action"] = [
{"name": "Classic Mode", "action": [
{"name": "Confirm", "action": switcher_dispatcher},
]
},
]
break
# Remove Apps menu
for item in menu:
if item["name"] == "Apps":
menu.remove(item)
# Set up handlers to process key presses
def button_press(gpio_pin, g_vars=g_vars):
DOWN_KEY = BUTTONS_PINS['down']
UP_KEY = BUTTONS_PINS['up']
RIGHT_KEY = BUTTONS_PINS['right']
LEFT_KEY = BUTTONS_PINS['left']
CENTER_KEY = BUTTONS_PINS['center']
KEY1 = None
KEY2 = None
KEY3 = None
if 'key1' in BUTTONS_PINS:
KEY1 = BUTTONS_PINS['key1']
if 'key2' in BUTTONS_PINS:
KEY2 = BUTTONS_PINS['key2']
if 'key3' in BUTTONS_PINS:
KEY3 = BUTTONS_PINS['key3']
if g_vars['disable_keys'] == True:
# someone disabled the front panel keys as they don't want to be interrupted
return
if (g_vars['sig_fired']):
# signal handler already in progress, ignore this one
return
# user pressed a button, reset the sleep counter
g_vars['pageSleepCountdown'] = PAGE_SLEEP
g_vars['start_up'] = False
if g_vars['drawing_in_progress'] or g_vars['shutdown_in_progress']:
return
# increment the button press counter to indicate the something has been done
# and a page refresh is required
g_vars['button_press_count'] += 1
# if display has been switched off to save screen, power back on and show home menu
if g_vars['screen_cleared']:
wakeup_screen()
return
# Down key pressed
if gpio_pin == DOWN_KEY:
g_vars['sig_fired'] = True
menu_down()
g_vars['sig_fired'] = False
return
# Down key pressed
if gpio_pin == UP_KEY:
g_vars['sig_fired'] = True
menu_up()
g_vars['sig_fired'] = False
return
# Right/Selection key pressed
if gpio_pin == RIGHT_KEY:
g_vars['sig_fired'] = True
menu_right()
g_vars['sig_fired'] = False
return
# Left/Back key
if gpio_pin == LEFT_KEY:
g_vars['sig_fired'] = True
menu_left()
g_vars['sig_fired'] = False
return
# Center key
if gpio_pin == CENTER_KEY:
g_vars['sig_fired'] = True
menu_center()
g_vars['sig_fired'] = False
return
# Key 1
if gpio_pin == KEY1:
g_vars['sig_fired'] = True
menu_key1()
g_vars['sig_fired'] = False
return