-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathreport_generator5.py
1285 lines (1153 loc) · 46.9 KB
/
report_generator5.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 -*-
# HTML5
import os
import re
import sys
import glob
import json
import pickle
import platform
import requests
import subprocess
import configparser
from string import Template
from datetime import datetime
from importlib.metadata import version
from collections import Counter, defaultdict
# global variables
LOG_PATH = '/opt/meshing-around/logs' # override path to log files (defaults to ../log)
W3_PATH = '/var/www/html/' # override path to web server root (defaults to ../www)
multiLogReader = False # set to True to read all meshbot logs in ../log
shameWordList = ['password', 'combo', 'key', 'hidden', 'secret', 'pass', 'token', 'login', 'username', 'admin', 'root', 'base64:', '==' ]
# system variables
script_dir = os.path.dirname(os.path.realpath(__file__))
www_dir = os.path.join(script_dir, 'www')
config_file = os.path.join(script_dir, 'web_reporter.cfg')
# set up report.cfg as ini file
config = configparser.ConfigParser()
try:
config.read(config_file)
except Exception as e:
print(f"Error reading web_reporter.cfg: {str(e)} generating default config")
if config.sections() == []:
print(f"web_reporter.cfg is empty or does not exist, generating default config")
shameWordList = shameWordList_str = ', '.join(shameWordList)
config['reporting'] = {'log_path': script_dir, 'w3_path': www_dir, 'multi_log_reader': 'False', 'shame_word_list': shameWordList}
with open(config_file, 'w') as configfile:
config.write(configfile)
# read config file
LOG_PATH = config['reporting'].get('log_path', LOG_PATH)
W3_PATH = config['reporting'].get('w3_path', W3_PATH)
multiLogReader = config['reporting'].getboolean('multi_log_reader', multiLogReader)
# config['reporting']['shame_word_list'] is a comma-separated string
shameWordList = config['reporting'].get('shame_word_list', '')
if isinstance(shameWordList, str):
shameWordList = shameWordList.split(', ')
def parse_log_file(file_path):
global log_data
lines = ['']
# see if many logs are present
if multiLogReader:
# set file_path to the cwd of the default project ../log
log_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'logs')
log_files = glob.glob(os.path.join(log_dir, 'meshbot.log.*'))
print(f"Checking log files: {log_files}")
if log_files:
log_files.sort()
for logFile in log_files:
with open(os.path.join(log_dir, logFile), 'r') as file:
lines += file.readlines()
else:
try:
print(f"Checking log file: {file_path}")
with open(file_path, 'r') as file:
lines = file.readlines()
except FileNotFoundError:
print(f"Error: File not found at {file_path}")
sys.exit(1)
if multiLogReader:
print(f"Consumed {len(lines)} lines from {len(log_files)} log files")
else:
print(f"Consumed {len(lines)} lines from {file_path}")
log_data = {
'command_counts': Counter(),
'message_types': Counter(),
'llm_queries': Counter(),
'unique_users': set(),
'warnings': [],
'errors': [],
'hourly_activity': defaultdict(int),
'bbs_messages': 0,
'messages_waiting': 0,
'total_messages': 0,
'gps_coordinates': defaultdict(list),
'command_timestamps': [],
'message_timestamps': [],
'firmware1_version': "N/A",
'firmware2_version': "N/A",
'node1_uptime': "N/A",
'node2_uptime': "N/A",
'node1_name': "N/A",
'node2_name': "N/A",
'node1_ID': "N/A",
'node2_ID': "N/A",
'shameList': []
}
for line in lines:
timestamp_match = re.match(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}),\d+', line)
if timestamp_match:
timestamp = datetime.strptime(timestamp_match.group(1), '%Y-%m-%d %H:%M:%S')
log_data['hourly_activity'][timestamp.strftime('%Y-%m-%d %H:00:00')] += 1
if 'Bot detected Commands' in line or 'LLM Query:' in line or 'PlayingGame' in line:
# get the command and user from the line
command = re.search(r"'cmd': '(\w+)'", line)
user = re.search(r"From: (.+)$", line)
if 'LLM Query:' in line:
log_data['command_counts']['LLM Query'] += 1
log_data['command_timestamps'].append((timestamp.isoformat(), 'LLM Query'))
if 'PlayingGame' in line:
#log line looks like this. 2024-10-04 20:24:53,381 | DEBUG | System: 862418040 PlayingGame BlackJack last_cmd: new
game = re.search(r'PlayingGame (\w+)', line)
user = re.search(r'System: (\d+)', line)
log_data['command_counts'][game.group(1)] += 1
log_data['command_timestamps'].append((timestamp.isoformat(), game))
if user:
user = user.group(1)
if command:
cmd = command.group(1)
log_data['command_counts'][cmd] += 1
# include the user who sent the command
log_data['command_timestamps'].append((timestamp.isoformat(), cmd + f' from {user}'))
if 'Sending DM:' in line or 'Sending Multi-Chunk DM:' in line or 'SendingChannel:' in line or 'Sending Multi-Chunk Message:' in line:
log_data['message_types']['Outgoing DM'] += 1
log_data['total_messages'] += 1
log_data['message_timestamps'].append((timestamp.isoformat(), 'Outgoing DM'))
if 'Received DM:' in line or 'Ignoring DM:' in line or 'Ignoring Message:' in line or 'ReceivedChannel:' in line or 'LLM Query:' in line:
log_data['message_types']['Incoming DM'] += 1
log_data['total_messages'] += 1
# include a little of the message
if 'Ignoring Message:' in line:
log_data['message_timestamps'].append((timestamp.isoformat(), f'Incoming: {line.split("Ignoring Message:")[1][:90]}'))
elif 'Ignoring DM:' in line:
log_data['message_timestamps'].append((timestamp.isoformat(), f'Incoming: {line.split("Ignoring DM:")[1][:90]}'))
elif 'LLM Query:' in line:
log_data['message_timestamps'].append((timestamp.isoformat(), f'Incoming: {line.split("LLM Query:")[1][:90]}'))
else:
log_data['message_timestamps'].append((timestamp.isoformat(), 'Incoming:'))
# check for shame words in the message
for word in shameWordList:
if word in line.lower():
if line not in log_data['shameList']:
line = line.replace('Ignoring Message:', '')
line = line.replace('|', '')
line = line.replace('INFO', '')
line = line.replace('DEBUG', '')
log_data['shameList'].insert(0, line)
# get the user who sent the message
if 'To: ' in line:
user_match = re.search(r"From: '([^']+)'(?: To:|$)", line)
else:
user_match = re.search(r"From: (.+)$", line)
if user_match:
log_data['unique_users'].add(user_match.group(1))
# Error Logs
if 'WARNING |' in line:
# remove some junk from the line
line = line.replace('|', '')
line = line.replace(' ', ' ')
log_data['warnings'].insert(0, line)
if 'ERROR |' in line or 'CRITICAL |' in line:
# remove some junk from the line
line = line.replace('System:', '')
line = line.replace('|', '')
line = line.replace(' ', ' ')
log_data['errors'].insert(0, line)
# bbs messages
bbs_match = re.search(r'📡BBSdb has (\d+) messages.*?Messages waiting: (\d+)', line)
if bbs_match:
bbs_messages = int(bbs_match.group(1))
messages_waiting = int(bbs_match.group(2))
log_data['bbs_messages'] = bbs_messages
log_data['messages_waiting'] = messages_waiting
gps_match = re.search(r'location data for (\d+) is ([-\d.]+),([-\d.]+)', line)
if gps_match:
node_id = None
node_id, lat, lon = gps_match.groups()
log_data['gps_coordinates'][node_id].append((float(lat), float(lon)))
# get telemetry data
if '| Telemetry:' in line:
telemetry_match = re.search(r'Telemetry:(\d+) numPacketsRx:(\d+) numPacketsRxErr:(\d+) numPacketsTx:(\d+) numPacketsTxErr:(\d+) ChUtil%:(\d+\.\d+) AirTx%:(\d+\.\d+) totalNodes:(\d+) Online:(\d+) Uptime:(\d+d) Volt:(\d+\.\d+) Firmware:(\d+\.\d+\.\d+\.\w+)', line)
if telemetry_match:
interface_number, numPacketsRx, numPacketsRxErr, numPacketsTx, numPacketsTxErr, ChUtil, AirTx, totalNodes, online, uptime, volt, firmware_version = telemetry_match.groups()
data = f"Tx: {numPacketsTx} Rx: {numPacketsRx} Uptime: {uptime} Volt: {volt} numPacketsRxErr: {numPacketsRxErr} numPacketsTxErr: {numPacketsTxErr} ChUtil: {ChUtil} AirTx: {AirTx} totalNodes: {totalNodes} Online: {online}"
if interface_number == '1':
log_data['firmware1_version'] = firmware_version
log_data['node1_uptime'] = data
log_data['nodeCount1'] = totalNodes
log_data['nodeCountOnline1'] = online
log_data['tx1'] = numPacketsTx
log_data['rx1'] = numPacketsRx
elif interface_number == '2':
log_data['firmware2_version'] = firmware_version
log_data['node2_uptime'] = data
log_data['nodeCount2'] = totalNodes
log_data['nodeCountOnline2'] = online
log_data['tx2'] = numPacketsTx
log_data['rx2'] = numPacketsRx
# get name and nodeID for devices
if 'Autoresponder Started for Device' in line:
device_match = re.search(r'Autoresponder Started for Device(\d+)\s+([^\s,]+).*?NodeID: (\d+)', line)
if device_match:
device_id = device_match.group(1)
device_name = device_match.group(2)
node_id = device_match.group(3)
if device_id == '1':
log_data['node1_name'] = device_name
log_data['node1_ID'] = node_id
elif device_id == '2':
log_data['node2_name'] = device_name
log_data['node2_ID'] = node_id
log_data['unique_users'] = list(log_data['unique_users'])
log_data['unique_users'].reverse()
return log_data
def get_system_info():
def get_command_output(command):
try:
return subprocess.check_output(command, shell=True).decode('utf-8').strip()
except subprocess.CalledProcessError:
return "N/A"
# Capture some system information from log_data
firmware1_version = log_data['firmware1_version']
firmware2_version = log_data['firmware2_version']
node1_uptime = log_data['node1_uptime']
node2_uptime = log_data['node2_uptime']
node1_name = log_data['node1_name']
node2_name = log_data['node2_name']
node1_ID = log_data['node1_ID']
node2_ID = log_data['node2_ID']
print(f"Node1: {node1_name} {node1_ID} {firmware1_version}")
print(f"Node2: {node2_name} {node2_ID} {firmware2_version}")
# get Meshtastic CLI version on web
try:
url = "https://pypi.org/pypi/meshtastic/json"
data = requests.get(url, timeout=5).json()
pypi_version = data["info"]["version"]
cli_web = f"v{pypi_version}"
except Exception:
pass
# get Meshtastic CLI version on local
try:
if "importlib.metadata" in sys.modules:
cli_local = version("meshtastic")
except:
pass # Python 3.7 and below, meh..
if platform.system() == "Linux":
uptime = get_command_output("uptime -p")
memory_total = get_command_output("free -m | awk '/Mem:/ {print $2}'")
memory_available = get_command_output("free -m | awk '/Mem:/ {print $7}'")
disk_total = get_command_output("df -h / | awk 'NR==2 {print $2}'")
disk_free = get_command_output("df -h / | awk 'NR==2 {print $4}'")
elif platform.system() == "Darwin": # macOS
uptime = get_command_output("uptime | awk '{print $3,$4,$5}'")
memory_total = get_command_output("sysctl -n hw.memsize | awk '{print $0/1024/1024}'")
memory_available = "N/A" # Not easily available on macOS without additional tools
disk_total = get_command_output("df -h / | awk 'NR==2 {print $2}'")
disk_free = get_command_output("df -h / | awk 'NR==2 {print $4}'")
else:
return {
'uptime': "N/A",
'memory_total': "N/A",
'memory_available': "N/A",
'disk_total': "N/A",
'disk_free': "N/A",
'interface1_version': "N/A",
'interface2_version': "N/A",
'node1_uptime': "N/A",
'node2_uptime': "N/A",
'node1_name': "N/A",
'node2_name': "N/A",
'node1_ID': "N/A",
'node2_ID': "N/A",
'cli_web': "N/A",
'cli_local': "N/A"
}
return {
'uptime': uptime,
'memory_total': f"{memory_total} MB",
'memory_available': f"{memory_available} MB" if memory_available != "N/A" else "N/A",
'disk_total': disk_total,
'disk_free': disk_free,
'interface1_version': firmware1_version,
'interface2_version': firmware2_version,
'node1_uptime': node1_uptime,
'node2_uptime': node2_uptime,
'node1_name': node1_name,
'node2_name': node2_name,
'node1_ID': node1_ID,
'node2_ID': node2_ID,
'cli_web': cli_web,
'cli_local': cli_local
}
def get_wall_of_shame():
# Get the wall of shame out of the log data
logShameList = log_data['shameList']
# future space for other ideas
return {
'shame': ', '.join(shameWordList),
'shameList': '\n'.join(f'<li>{line}</li>' for line in logShameList),
}
def get_database_info():
# ../config.ini location to script path
config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'config.ini')
# get config.ini variables
config = configparser.ConfigParser()
config.read(config_path)
# for section in config.sections():
# print(f"Section: {section}")
# for key in config[section]:
# print(f"Key: {key}, Value: {config[section][key]}")
banList = config['bbs'].get('bbs_ban_list', 'none')
adminList = config['bbs'].get('bbs_admin_list', 'none')
sentryIgnoreList = config['sentry'].get('sentryIgnoreList', 'none')
# Define the base directory
base_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'data'))
# data files
databaseFiles = [os.path.join(base_dir, 'lemonstand_hs.pkl'),
os.path.join(base_dir, 'dopewar_hs.pkl'),
os.path.join(base_dir, 'blackjack_hs.pkl'),
os.path.join(base_dir, 'videopoker_hs.pkl'),
os.path.join(base_dir, 'mmind_hs.pkl'),
os.path.join(base_dir, 'golfsim_hs.pkl'),
os.path.join(base_dir, 'bbsdb.pkl'),
os.path.join(base_dir, 'bbsdm.pkl')]
for file in databaseFiles:
try:
with open(file, 'rb') as f:
if 'lemonstand' in file:
lemon_score = pickle.load(f)
elif 'dopewar' in file:
dopewar_score = pickle.load(f)
elif 'blackjack' in file:
blackjack_score = pickle.load(f)
elif 'videopoker' in file:
videopoker_score = pickle.load(f)
elif 'mmind' in file:
mmind_score = pickle.load(f)
elif 'golfsim' in file:
golfsim_score = pickle.load(f)
elif 'bbsdb' in file:
bbsdb = pickle.load(f)
elif 'bbsdm' in file:
bbsdm = pickle.load(f)
except Exception as e:
print(f"Warning issue reading database file: {str(e)}")
if 'lemonstand' in file:
lemon_score = "no data"
elif 'dopewar' in file:
dopewar_score = "no data"
elif 'blackjack' in file:
blackjack_score = "no data"
elif 'videopoker' in file:
videopoker_score = "no data"
elif 'mmind' in file:
mmind_score = "no data"
elif 'golfsim' in file:
golfsim_score = "no data"
elif 'bbsdb' in file:
bbsdb = "no data"
elif 'bbsdm' in file:
bbsdm = "no data"
# pretty print the bbsdb
prettyBBSdb = ""
try:
for i in range(len(bbsdb)):
prettyBBSdb += f'<li>{bbsdb[i]}</li>'
except Exception as e:
print(f"Error with database: {str(e)}")
pass
# pretty print the bbsdm
prettyBBSdm = ""
try:
for i in range(len(bbsdm)):
prettyBBSdm += f'<li>{bbsdm[i]}</li>'
except Exception as e:
print(f"Error with database: {str(e)}")
pass
if 'no data' in [lemon_score, dopewar_score, blackjack_score, videopoker_score, mmind_score, golfsim_score]:
database = "Error(s) Detected"
else:
database = " Online"
return {
'database': database,
"bbsdb": prettyBBSdb,
"bbsdm": prettyBBSdm,
'lemon_score': lemon_score,
'dopewar_score': dopewar_score,
'blackjack_score': blackjack_score,
'videopoker_score': videopoker_score,
'mmind_score': mmind_score,
'golfsim_score': golfsim_score,
'banList': banList,
'adminList': adminList,
'sentryIgnoreList': sentryIgnoreList
}
def generate_main_html(log_data, system_info):
html_template = """
<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MeshBot (BBS) Web Dashboard</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #2c3e50;
--secondary-color: #3498db;
--background-color: #ecf0f1;
--card-background: #ffffff;
--text-color: #34495e;
--sidebar-text-color: #ecf0f1;
--accent-color-1: #e74c3c;
--accent-color-2: #2ecc71;
--accent-color-3: #f39c12;
--shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
--transition: all 0.3s ease;
}
[data-theme="dark"] {
--primary-color: #1a2639;
--secondary-color: #2980b9;
--background-color: #2c3e50;
--card-background: #34495e;
--text-color: #ecf0f1;
--sidebar-text-color: #ecf0f1;
--accent-color-1: #c0392b;
--accent-color-2: #27ae60;
--accent-color-3: #d35400;
--shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}
[data-theme="high-contrast"] {
--primary-color: #000000;
--secondary-color: #000000;
--background-color: #000000;
--card-background: #000000;
--text-color: #ffffff;
--sidebar-text-color: #ffffff;
--accent-color-1: #ff0000;
--accent-color-2: #00ff00;
--accent-color-3: #ffff00;
--shadow: 0 0 0 2px #ffffff;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--background-color);
color: var(--text-color) !important;
line-height: 1.6;
transition: var(--transition);
}
.header {
background-color: var(--secondary-color);
color: var(--sidebar-text-color);
padding: 1rem;
font-size: 1.5rem;
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1000;
box-shadow: var(--shadow);
}
.main-container {
display: flex;
margin-top: 3.5rem;
}
.sidebar {
width: 250px;
background-color: var(--secondary-color);
padding: 1rem;
height: calc(100vh - 3.5rem);
position: fixed;
overflow-y: auto;
display: flex;
flex-direction: column;
justify-content: space-between;
box-shadow: var(--shadow);
transition: var(--transition);
}
.sidebar:hover {
width: 270px;
}
.sidebar-nav ul {
list-style-type: none;
}
.sidebar-nav li {
margin-bottom: 1rem;
}
.sidebar-nav a {
color: var(--sidebar-text-color);
text-decoration: none;
font-weight: 400;
transition: var(--transition);
display: block;
padding: 0.5rem;
border-radius: 4px;
}
.sidebar-nav a:hover {
background-color: rgba(255, 255, 255, 0.1);
transform: translateX(5px);
}
.sidebar-footer {
font-size: 0.75rem;
color: var(--sidebar-text-color);
opacity: 0.8;
}
.content {
margin-left: 250px;
padding: 1rem;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 1.5rem;
flex-grow: 1;
background-color: var(--background-color);
transition: var(--transition);
color: var(--text-color);
}
.chart-container {
background-color: var(--card-background);
border-radius: 8px;
padding: 1.5rem;
height: 400px;
display: flex;
flex-direction: column;
box-shadow: var(--shadow);
transition: var(--transition);
}
.chart-container:hover {
transform: translateY(-5px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
.chart-title {
font-size: 1.1rem;
font-weight: 600;
margin-bottom: 1rem;
color: var(--text-color);
}
#map, .chart-content {
flex-grow: 1;
width: 100%;
border-radius: 4px;
overflow: hidden;
}
.list-container {
background-color: var(--card-background);
border-radius: 8px;
padding: 1.5rem;
height: 400px;
overflow-y: auto;
box-shadow: var(--shadow);
transition: var(--transition);
}
.list-container:hover {
transform: translateY(-5px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
ul {
list-style-type: none;
}
li {
padding: 0.75rem 0;
border-bottom: 1px solid var(--background-color);
transition: var(--transition);
}
li:last-child {
border-bottom: none;
}
li:hover {
background-color: rgba(255, 255, 255, 0.05);
padding-left: 0.5rem;
}
#iframe-content {
display: none;
position: fixed;
top: 3.5rem;
left: 250px;
right: 0;
bottom: 0;
background: var(--card-background);
background-color: var(--card-background);
z-index: 900;
box-shadow: var(--shadow);
color: var(--text-color);
}
iframe {
width: 100%;
height: 100%;
border: none;
background-color: var(--card-background);
color: var(--text-color);
}
.timestamp-list {
height: 400px;
overflow-y: auto;
font-size: 0.85rem;
}
.theme-switch {
display: flex;
align-items: center;
margin-top: 1rem;
}
.theme-switch-label {
margin-right: 10px;
color: var(--sidebar-text-color);
}
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
transition: .4s;
background-color: white;
border-radius: 50%;
}
input:checked + .slider {
background-color: var(--accent-color-2);
}
input:checked + .slider:before {
transform: translateX(26px);
}
@media (max-width: 768px) {
.sidebar {
width: 100%;
height: auto;
position: static;
}
.content {
margin-left: 0;
grid-template-columns: 1fr;
}
#iframe-content {
left: 0;
}
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.chart-container, .list-container {
animation: fadeIn 0.5s ease-out;
}
</style>
</head>
<body>
<header class="header">MeshBot (BBS) Web Dashboard</header>
<div class="main-container">
<nav class="sidebar">
<div class="sidebar-nav">
<ul>
<li><a href="#" onclick="showDashboard(); return false;">Dashboard</a></li>
<li><a href="#" onclick="showIframe('network_map_${date}.html'); return false;">Network Map</a></li>
<li><a href="#" onclick="showIframe('wall_of_shame_${date}.html'); return false;">Wall of Shame</a></li>
<li><a href="#" onclick="showIframe('database_${date}.html'); return false;">Database Info</a></li>
<li><a href="#" onclick="showIframe('hosts_${date}.html'); return false;">Host</a></li>
</ul>
<div class="theme-switch">
<span class="theme-switch-label">Theme:</span>
<label class="switch">
<input type="checkbox" id="theme-toggle">
<span class="slider"></span>
</label>
</div>
</div>
<div class="sidebar-footer">
<p>© 2024 MeshBot Dashboard</p>
<p>Version 1.0</p>
</div>
</nav>
<main class="content" id="dashboard-content">
<section class="chart-container">
<h2 class="chart-title">Node Locations</h2>
<div id="map"></div>
</section>
<section class="chart-container">
<h2 class="chart-title">Network Activity</h2>
<div class="chart-content">
<canvas id="activityChart"></canvas>
</div>
</section>
<section class="chart-container">
<h2 class="chart-title">Command Usage</h2>
<div class="chart-content">
<canvas id="commandChart"></canvas>
</div>
</section>
<section class="chart-container">
<h2 class="chart-title">Message Types</h2>
<div class="chart-content">
<canvas id="messageChart"></canvas>
</div>
</section>
<section class="chart-container">
<h2 class="chart-title">Message Counts</h2>
<div class="chart-content">
<canvas id="messageCountChart"></canvas>
</div>
</section>
<section class="chart-container">
<h2 class="chart-title">Recent Commands</h2>
<div class="timestamp-list">
<ul>
${command_timestamps}
</ul>
</div>
</section>
<section class="chart-container">
<h2 class="chart-title">Recent Messages</h2>
<div class="timestamp-list">
<ul>
${message_timestamps}
</ul>
</div>
</section>
<section class="list-container">
<h2 class="chart-title">Unique Users</h2>
<ul>
${unique_users}
</ul>
</section>
<section class="list-container">
<h2 class="chart-title">Warnings</h2>
<ul>
${warnings}
</ul>
</section>
<section class="list-container">
<h2 class="chart-title">Errors</h2>
<ul>
${errors}
</ul>
</section>
</main>
<div id="iframe-content">
<iframe id="content-iframe" src=""></iframe>
</div>
</div>
<script>
const commandData = ${command_data};
const messageData = ${message_data};
const activityData = ${activity_data};
const messageCountData = {
labels: ['BBSdm Messages', 'BBSdb Messages', 'Channel Messages'],
datasets: [{
label: 'Message Counts',
data: [${messages_waiting}, ${bbs_messages}, ${total_messages}],
backgroundColor: ['rgba(255, 206, 86, 0.6)', 'rgba(75, 192, 192, 0.6)', 'rgba(54, 162, 235, 0.6)']
}]
};
const chartOptions = {
responsive: true,
maintainAspectRatio: false
};
function createCharts() {
new Chart(document.getElementById('commandChart'), {
type: 'bar',
data: {
labels: Object.keys(commandData),
datasets: [{
label: 'Command Usage',
data: Object.values(commandData),
backgroundColor: 'rgba(75, 192, 192, 0.6)'
}]
},
options: chartOptions
});
new Chart(document.getElementById('messageChart'), {
type: 'pie',
data: {
labels: Object.keys(messageData),
datasets: [{
data: Object.values(messageData),
backgroundColor: ['rgba(255, 99, 132, 0.6)', 'rgba(54, 162, 235, 0.6)']
}]
},
options: chartOptions
});
new Chart(document.getElementById('activityChart'), {
type: 'line',
data: {
labels: Object.keys(activityData),
datasets: [{
label: 'Hourly Activity',
data: Object.entries(activityData).map(([time, count]) => ({x: new Date(time), y: count})),
borderColor: 'rgba(153, 102, 255, 1)',
fill: false
}]
},
options: {
...chartOptions,
scales: {
x: {
type: 'time',
time: {
unit: 'hour',
displayFormats: {
hour: 'MMM d, HH:mm'
}
},
title: {
display: true,
text: 'Time'
}
},
y: {
beginAtZero: true,
title: {
display: true,
text: 'Activity Count'
}
}
}
}
});
new Chart(document.getElementById('messageCountChart'), {
type: 'bar',
data: messageCountData,
options: {
...chartOptions,
scales: {
y: {
beginAtZero: true
}
}
}
});
}
function initMap() {
var map = L.map('map').setView([0, 0], 2);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
var gpsCoordinates = ${gps_coordinates};
var bounds = [];
var defaultCoordinate = [0, 0]; // Set your default coordinate here
for (var nodeId in gpsCoordinates) {
if (gpsCoordinates[nodeId] && gpsCoordinates[nodeId][0]) {
var coords = gpsCoordinates[nodeId][0];
L.marker(coords).addTo(map)
.bindPopup("Node ID: " + nodeId);
bounds.push(coords);
} else {
// Optionally, handle the case where coordinates are missing
// bounds.push(defaultCoordinate);
}
}
if (bounds.length > 0) {
map.fitBounds(bounds);
} else {
// Optionally, set the view to the default coordinate if no valid bounds are found
map.setView(defaultCoordinate, 2);
}
}
function showIframe(src) {
document.getElementById('dashboard-content').style.display = 'none';
document.getElementById('iframe-content').style.display = 'block';
document.getElementById('content-iframe').src = src;
}
function showDashboard() {
document.getElementById('dashboard-content').style.display = 'grid';
document.getElementById('iframe-content').style.display = 'none';
document.getElementById('content-iframe').src = '';
}
const themes = ['light', 'dark', 'high-contrast'];
let currentThemeIndex = themes.indexOf(localStorage.getItem('theme') || 'light');
function cycleTheme() {
currentThemeIndex = (currentThemeIndex + 1) % themes.length;
const newTheme = themes[currentThemeIndex];
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateCharts();
updateSwitchState();