-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwizard-tester.py
executable file
·264 lines (218 loc) · 9.01 KB
/
wizard-tester.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
#!/usr/bin/env python3
from io import SEEK_CUR
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
import argparse
from argparse import RawTextHelpFormatter
from time import sleep
import json
import sys
## config ##
luci_webaddress = "http://frei.funk"
luci_timeout_long = 12
luci_timeout = 2
# standard values. They apply, if no other values (via config file or cmd-option) were provided
configs = {
"location": "somewhere in (maybe) Berlin",
"lat": "52.4875104819595",
"lon": "13.214267492294312",
"sharenet_off": False,
"download": "25",
"upload": "12",
"monitoring_off": False
}
##############################
# Argument-paser stuff #
##############################
parser = argparse.ArgumentParser(
description="""A tool for testing Freifunk-Berlin-Wizard fast and easy.
It's also very useful, if you want to configure nodes seamlessly quick.
If you give a value via cmdl-options, they will overide those values from the configuration-file.
If you are in a hurry, you may only provide this information to the script:
* password
* hostname
* your contact (email or web-form)
* IP for DHCP
* IP for meshing on radio0
For the rest, the script will insert some standart-values. Have a look in the code.""", formatter_class=RawTextHelpFormatter)
parser.add_argument(
'path', nargs='?', help="path to configuration file in json-format (optional)")
parser.add_argument('-p', '--passwd', type=str, help="Passwort for user root.")
parser.add_argument('-n', '--hostname', type=str,
help="hostname of your new freifunk router. Please have a look at RFC1178.")
parser.add_argument('--nickname', type=str, help="your nickname")
parser.add_argument('--realname', type=str, help="your real name")
parser.add_argument('-c', '--contact', type=str,
help="""contact data of the operator. Give an e-mail-address or the link for
your personal e-mail-form from config.berlin.freifunk.net""")
parser.add_argument('--community', type=str,
help="select another community-profile than standard")
parser.add_argument('-l', '--location', type=str,
help="description of routers location (e.g. address)")
parser.add_argument('-x', '--lat', type=str,
help="latitude of routers position (decimal)")
parser.add_argument('-y', '--lon', type=str,
help="longintude of routers postition (decimal)")
parser.add_argument('--sharenet-off', action="store_true",
help="deactivate sharing off your own internet to others")
parser.add_argument('--upload', type=str,
help="bandwidth-limit for sharing your net")
parser.add_argument('--download', type=str,
help="bandwidth-limit for sharing your net")
parser.add_argument('--monitoring-off', action="store_true",
help="deactivate sending statistics to monitor.berlin.freifunk.net")
parser.add_argument('--adhoc', action="store_true",
help="use deprecated ad-hoc as mesh-technology")
parser.add_argument('-d', '--dhcp', type=str,
help="ip-address of DHCP-Network from the mail.")
parser.add_argument('-r', '--radio0', type=str,
help="mesh-ip-address for radio0")
parser.add_argument('-s', '--radio1', type=str,
help="mesh-ip-address for radio1")
args = parser.parse_args()
# read configs from file (if any). If value is not defined in config, preserve standard value.
if args.path:
conf = {}
with open(args.path) as f:
conf = json.loads(f.read())
for option in conf.keys():
configs[option] = conf.get(option)
# read commandline arguments into config
opt = vars(args)
for option in opt:
if option == "path":
continue
else:
if opt.get(option):
configs[option] = opt.get(option)
# check, if all mandatory values were given
mandatory = ["passwd", "hostname", "radio0", "dhcp"]
for param in mandatory:
if not opt.get(param) and not configs.get(param):
print("Didn't get enough information for configuring your freifunk-node.\nI need at least:\n\t* passwd\n\t* hostname\n\t* mesh-ip-radio0\n\t* ip-dhcp\n\nThe rest, I'll fill with standard-values.")
exit(1)
##############################
# Play around with LuCI #
##############################
def click_next(browser):
button = browser.find_element(
by=By.CLASS_NAME, value="cbi-button.cbi-button-save")
button.click()
opt = Options()
opt.set_preference("intl.accept_languages", "de-DE")
browser = webdriver.Firefox(options=opt)
browser.implicitly_wait(1)
# call LuCI-interface and wait unti its loaded
browser.get(luci_webaddress)
# figure out success via checking pagetitle fo "LuCI"
error_count = 0
while "LuCI" not in browser.title:
sleep(2)
error_count += 1
if error_count > 12:
print("connecting to " + luci_webaddress + " failed!")
print("exiting...")
exit(1)
# password field appears slightly late
pw_0, pw_1 = None, None
while not pw_0:
try:
pw_0 = browser.find_element(by=By.NAME, value="cbid.ffwizward.1.pw1")
pw_1 = browser.find_element(by=By.NAME, value="cbid.ffwizward.1.pw2")
except:
sleep(luci_timeout)
pw_0.send_keys(configs.get("passwd"))
pw_1.send_keys(configs.get("passwd"))
browser.save_screenshot('01_password.png')
click_next(browser)
sleep(2)
# select community
if args.community or configs.get("community"):
community = args.community or configs.get("community")
dropdown = Select(browser.find_element(
by=By.ID, value="widget.cbid.ffwizward.1.net"))
dropdown.select_by_value(community)
# put data into fields
hostname = browser.find_element(by=By.NAME, value="cbid.ffwizward.1.hostname")
nickname = browser.find_element(by=By.NAME, value="cbid.ffwizward.1.nickname")
realname = browser.find_element(by=By.NAME, value="cbid.ffwizward.1.realname")
contact = browser.find_element(by=By.NAME, value="cbid.ffwizward.1.mail")
location = browser.find_element(by=By.NAME, value="cbid.ffwizward.1.location")
lat = browser.find_element(by=By.NAME, value="cbid.ffwizward.1.lat")
lon = browser.find_element(by=By.NAME, value="cbid.ffwizward.1.lon")
hostname.clear()
hostname.send_keys(configs.get("hostname"))
if configs.get("nickname"):
nickname.send_keys(configs.get("nickname"))
if configs.get("realname"):
realname.send_keys(configs.get("realname"))
if configs.get("contact"):
contact.send_keys(configs.get("contact"))
if configs.get("location"):
location.send_keys(configs.get("location"))
if configs.get("lat"):
lat.send_keys(configs.get("lat"))
if configs.get("lon"):
lon.send_keys(configs.get("lon"))
browser.save_screenshot('02_general_settings.png')
click_next(browser)
# decide on dsl yes/no
browser.save_screenshot('03_share_inet.png')
if configs.get("sharenet_off"):
# click "Am Freifunknetz teilnehmen"
try:
browser.find_element(
by=By.LINK_TEXT, value="Am Freifunk-Netz teilnehmen").click()
except:
browser.find_element(
by=By.LINK_TEXT, value="Participate in the Freifunk-Network").click()
else:
# click "Am Freifunknetz teilnehmen und Internet teilen"
try:
elem = browser.find_element(
by=By.LINK_TEXT, value="Am Freifunk-Netz teilnehmen und Internet teilen").click()
except:
elem = browser.find_element(
by=By.LINK_TEXT, value="Participate in the Freifunk-Network and share Internet").click()
# configure bandwidth of sharenet
bw_down = browser.find_element(
by=By.NAME, value="cbid.ffuplink.1.usersBandwidthDown")
bw_up = browser.find_element(
by=By.NAME, value="cbid.ffuplink.1.usersBandwidthUp")
bw_down.send_keys(configs.get("download"))
bw_up.send_keys(configs.get("upload"))
browser.save_screenshot('03a_share_bandwidth.png')
click_next(browser)
# monitoring yes/no
if not configs.get("monitoring_off"):
elem = browser.find_element(by=By.NAME, value="cbid.ffwizard.1.stats")
elem.click()
browser.save_screenshot('04_monitoring.png')
click_next(browser)
# set ip-adresses
sleep(2)
radio0 = browser.find_element(
by=By.NAME, value="cbid.ffwizard.1.meship_radio0")
dhcp = browser.find_element(by=By.NAME, value="cbid.ffwizard.1.dhcpmesh")
radio0.send_keys(configs.get("radio0"))
# radio1 is not present on all routers
try:
radio1 = browser.find_element(
by=By.NAME, value="cbid.ffwizard.1.meship_radio1")
radio1.send_keys(configs.get("radio1"))
except:
print("There was no radio1 in LuCI-Wizard. Therefore radio1-IP-Adress not set.")
dhcp.send_keys(configs.get("dhcp"))
# configure mesh mode ad-hoc
if args.adhoc:
browser.find_element_by_id("cbid.ffwizard.1.mode_radio0-adhoc").click
browser.save_screenshot('05_ipaddr.png')
click_next(browser)
sleep(2)
print("Configuration of your test-node seems to be successfully done.")
browser.save_screenshot('06_finished.png')
browser.close()
exit()