-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontact_list_creator.py
executable file
·158 lines (142 loc) · 4.62 KB
/
contact_list_creator.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
#!/usr/bin/env python
# SPDX-License-Identifier: BSD-2-Clause
import json
import re
from collections import defaultdict
"""
This tool helps to create nginx update lists for Freifunk migrations.
Those are needed when wanting to migrate a community efficiently by first finding all the independent nodes
Then updating the leaf nodes and finally all other nodes.
It is recommended to use ffac-scheduled-sysupgrade and ffac-autoupdater-wifi-fallback packages in the firmware to help with the migration.
"""
# take the /var/lib/yanic/state.json and open it
with open("state.json") as f:
d = json.load(f)
addresses = defaultdict(list)
local_addresses = defaultdict(list)
deprecated = [
"A5-V11",
"AP121",
"AP121U",
"D-Link DIR-615",
"D-Link DIR-615 D",
"AVM FRITZ!Box 7320",
"AVM FRITZ!Box 7330",
"AVM FRITZ!Box 7330 SL",
"TP-Link TL-MR13U v1",
"TP-Link TL-MR3020 v1",
"TP-Link TL-MR3040 v1",
"TP-Link TL-MR3040 v2",
"TP-Link TL-MR3220 v1",
"TP-Link TL-MR3220 v2",
"TP-Link TL-MR3420 v1",
"TP-Link TL-MR3420 v2",
"TP-Link TL-WA701N/ND v1",
"TP-Link TL-WA701N/ND v2",
"TP-Link TL-WA730RE v1",
"TP-Link TL-WA750RE v1",
"TP-Link TL-WA801N/ND v1",
"TP-Link TL-WA801N/ND v2",
"TP-Link TL-WA801N/ND v3",
"TP-Link TL-WA830RE v1",
"TP-Link TL-WA830RE v2",
"TP-Link TL-WA850RE v1",
"TP-Link TL-WA860RE v1",
"TP-Link TL-WA901N/ND v1",
"TP-Link TL-WA901N/ND v2",
"TP-Link TL-WA901N/ND v3",
"TP-Link TL-WA901N/ND v4",
"TP-Link TL-WA901N/ND v5",
"TP-Link TL-WA7210N v2",
"TP-Link TL-WA7510N v1",
"TP-Link TL-WR703N v1",
"TP-Link TL-WR710N v1",
"TP-Link TL-WR710N v2",
"TP-Link TL-WR710N v2.1",
"TP-Link TL-WR740N/ND v1",
"TP-Link TL-WR740N/ND v3",
"TP-Link TL-WR740N/ND v4",
"TP-Link TL-WR740N/ND v5",
"TP-Link TL-WR741N/ND v1",
"TP-Link TL-WR741N/ND v3",
"TP-Link TL-WR741N/ND v4",
"TP-Link TL-WR741N/ND v5",
"TP-Link TL-WR743N/ND v1",
"TP-Link TL-WR743N/ND v2",
"TP-Link TL-WR840N v2",
"TP-Link TL-WR841N/ND v3",
"TP-Link TL-WR841N/ND v5",
"TP-Link TL-WR841N/ND v7",
"TP-Link TL-WR841N/ND v8",
"TP-Link TL-WR841N/ND v9",
"TP-Link TL-WR841N/ND v10",
"TP-Link TL-WR841N/ND v11",
"TP-Link TL-WR841N/ND v12",
"TP-Link TL-WR841N/ND Mod (16M) v11",
"TP-Link TL-WR841N/ND Mod (16M) v10",
"TP-Link TL-WR841N/ND Mod (16M) v8",
"TP-Link TL-WR841N/ND Mod (16M) v9",
"TP-Link TL-WR841N/ND Mod (8M) v10",
"TP-Link TL-WR842N/ND v1",
"TP-Link TL-WR842N/ND v2",
"TP-Link TL-WR843N/ND v1",
"TP-Link TL-WR940N v1",
"TP-Link TL-WR940N v2",
"TP-Link TL-WR940N v3",
"TP-Link TL-WR940N v4",
"TP-Link TL-WR940N v5",
"TP-Link TL-WR940N v6",
"TP-Link TL-WR941N/ND v2",
"TP-Link TL-WR941N/ND v3",
"TP-Link TL-WR941N/ND v4",
"TP-Link TL-WR941N/ND v5",
"TP-Link TL-WR941N/ND v6",
"TP-Link TL-WR1043N/ND v1",
"D-Link DIR-615 D1",
"D-Link DIR-615 D2",
"D-Link DIR-615 D3",
"D-Link DIR-615 D4",
"D-Link DIR-615 H1",
"Ubiquiti NanoStation loco M2",
"Ubiquiti NanoStation M2",
"Ubiquiti PicoStation M2",
"Ubiquiti Bullet M",
"Ubiquiti Bullet M2",
"Ubiquiti AirRouter",
"VoCore 8M",
"VoCore 16M",
]
for node, info in d["nodes"].items():
if not info["online"]:
continue
owner = info["nodeinfo"]["owner"]
if not owner:
continue
owner = owner.get("contact", "").strip()
model = info["nodeinfo"]["hardware"].get("model")
hostname = info["nodeinfo"]["hostname"]
node_id = info["nodeinfo"]["node_id"]
owner = owner.replace(" (ät) ", "@")
owner = owner.replace(" dot ", ".")
owner = owner.replace(" at ", "@")
owner = owner.replace(" punkt ", ".")
# only match deprecated
if model not in deprecated:
continue
if re.match(r"[^@]+@[^@]+\.[^@]+", owner):
addresses[owner].append((model, hostname, node_id))
else:
local_addresses[owner].append((model, hostname, node_id))
single_node_addresses = {}
multi_node_addresses = {}
for address, old_nodes in addresses.items():
if len(old_nodes) == 1:
single_node_addresses[address] = old_nodes
else:
multi_node_addresses[address] = old_nodes
with open("contact_addresses_single.json", "w") as f:
json.dump(sorted(single_node_addresses.items()), f, indent=4, ensure_ascii=False)
with open("contact_addresses_multi.json", "w") as f:
json.dump(sorted(multi_node_addresses.items()), f, indent=4, ensure_ascii=False)
with open("local_addresses.json", "w") as f:
json.dump(sorted(local_addresses.items()), f, indent=4, ensure_ascii=False)