Остання активність 1 month ago

nuno ревизій цього gist 1 month ago. До ревизії

1 file changed, 33 insertions

gistfile1.txt(файл створено)

@@ -0,0 +1,33 @@
1 + ed -n '/^def fw_events/,/^def [a-z]/p' /etc/wireguard/wgctl/core/json_helper.py
2 + def fw_events(file, filter_ip, filter_type, clients_dir, net_file, limit):
3 + """
4 + Format firewall drop events with dedup, counts, and service annotation.
5 + Output per line: ts|client|dest_ip|dest_port|proto|service_name|count
6 + """
7 + import glob
8 + from datetime import datetime
9 + proto_map = {1: 'icmp', 6: 'tcp', 17: 'udp'}
10 +
11 + # Build ip->name map
12 + ip_to_name = {}
13 + for conf in glob.glob(f"{clients_dir}/*.conf"):
14 + name = os.path.basename(conf).replace('.conf', '')
15 + try:
16 + with open(conf) as f:
17 + for line in f:
18 + if line.startswith('Address'):
19 + ip = line.split('=')[1].strip().split('/')[0]
20 + ip_to_name[ip] = name
21 + except Exception:
22 + pass
23 +
24 + # Load net services for reverse lookup
25 + net_data = {}
26 + if os.path.exists(net_file):
27 + try:
28 + with open(net_file) as f:
29 + net_data = json.load(f)
30 + except Exception:
31 + pass
32 +
33 +
Новіше Пізніше