-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
492 lines (372 loc) · 18.7 KB
/
main.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
# Create a qt5 gui application
from src.rsu_testing_app import Ui_CV2X_Automated_Tester
from PyQt6 import QtWidgets
from PyQt6 import QtCore
import sys
import ipaddress
import os
import src.fill_gui as fill_gui
from yaml import load, dump, FullLoader
# Create a class for the application
class ApplicationWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(ApplicationWindow, self).__init__()
self.ui = Ui_CV2X_Automated_Tester()
self.ui.setupUi(self)
self.ui.rsuCount_spinBox.valueChanged.connect(self.rsuCountChanged)
self.RSUs = [[],[],[],[],[]]
self.tabs = [[],[],[]]
self.data = {}
self.ui.SAVE_pushButton.clicked.connect(self.save)
self.ui.IMPORT_pushButton.clicked.connect(self.import_data)
self.top_mesh_port = self.ui.mesh_top_comboBox.currentText()
self.ui.mesh_top_comboBox.currentIndexChanged.connect(lambda: self.update_ports(self.ui.mesh_top_comboBox.currentText(),
self.top_mesh_port))
self.ui.mesh_top_comboBox.currentIndexChanged.connect(lambda: self.ui.mesh_tabWidget.setEnabled(self.ui.mesh_top_comboBox.currentText() != "---"))
self.ui.mesh_top_comboBox.currentIndexChanged.connect(lambda: self.ui.mesh_test_pushButton.setEnabled(self.ui.mesh_top_comboBox.currentText() != "---"))
self.ui.mesh_tabWidget.setEnabled(False)
self.ui.mesh_test_pushButton.setEnabled(False)
def save(self):
try:
file = open("src/data_.yaml", "w")
file.write("# This file is automatically generated by the CV2X Automated Tester.\n")
file.write("# Do not edit the keys of this file manually!!!\n")
# If password check box is unchecked, remove the password from the data
if self.ui.SAVE_checkBox.isChecked() == False:
data_safe_copy = self.data.copy()
for rsu in data_safe_copy:
data_safe_copy[rsu]["snmp_info"]["-A"] = ""
data_safe_copy[rsu]["snmp_info"]["-X"] = ""
data_safe_copy[rsu]["ssh_info"]["password"] = ""
dump(data_safe_copy, file)
else:
dump(self.data, file)
file.close()
os.system("mv data_.yaml data.yaml")
except Exception as e:
print("Error saving to src/data.yaml")
def import_data(self):
try:
file = open("src/data.yaml", "r")
data_ = load(file, Loader=FullLoader).copy()
file.close()
## Only continue if the data is valid; exception was thrown otherwise
## Currently, the only way to safely add or delete RSUs is to clear the
## current contents one-by-one and add new rows in, again one-by-one
# Clear current contents
for j in range(len(self.RSUs[0]), 0, -1):
self.ui.rsuCount_spinBox.setValue(j-1)
# Put in new data
self.data = data_.copy()
for j in range(len(self.data)):
self.ui.rsuCount_spinBox.setValue(j+1)
except Exception as e:
print("Error importing src/data.yaml")
for rsu in self.data:
# RSU Tab Information
self.RSUs[0][rsu].setText(self.data[rsu]["name"])
self.RSUs[1][rsu].setText(self.data[rsu]["ip_address"])
# Fuzzer Tab Information
# ssh_lineEdits = self.tabs[0][rsu].findChildren(QtWidgets.QLineEdit)
# ssh_lineEdits[0].setText(self.data[rsu]["ssh_info"]["username"])
# ssh_lineEdits[1].setText(self.data[rsu]["ssh_info"]["password"])
# ssh_lineEdits[2].setText(str(self.data[rsu]["ssh_info"]["port"]))
fuzzer_checkBoxes = self.tabs[0][rsu].findChildren(QtWidgets.QCheckBox)
fuzzer_checkBoxes[0].setChecked(self.data[rsu]["fuzzer_info"]["enabled"])
# SNMP Tab Information
snmp_tabs = self.tabs[1][rsu].findChildren(QtWidgets.QTabWidget)
# SNMP - SNMP Tab Information
snmp_lineEdits = snmp_tabs[0].findChildren(QtWidgets.QLineEdit)
snmp_lineEdits[3].setText(self.data[rsu]["snmp_info"]["version"])
snmp_lineEdits[4].setText(self.data[rsu]["snmp_info"]["-u"])
snmp_lineEdits[5].setText(self.data[rsu]["snmp_info"]["-l"])
snmp_lineEdits[6].setText(self.data[rsu]["snmp_info"]["-a"])
snmp_lineEdits[7].setText(self.data[rsu]["snmp_info"]["-A"])
snmp_lineEdits[8].setText(self.data[rsu]["snmp_info"]["-x"])
snmp_lineEdits[9].setText(self.data[rsu]["snmp_info"]["-X"])
snmp_lineEdits[10].setText(str(self.data[rsu]["snmp_info"]["-p"]))
snmp_checkBoxes = self.tabs[1][rsu].findChildren(QtWidgets.QCheckBox)
snmp_checkBoxes[3].setChecked(self.data[rsu]["snmp_info"]["enabled"]
or self.data[rsu]["ssh_info"]["enabled"])
# SNMP - SSH Tab Information
ssh_lineEdits = snmp_tabs[0].findChildren(QtWidgets.QLineEdit)
ssh_lineEdits[0].setText(self.data[rsu]["ssh_info"]["username"])
ssh_lineEdits[1].setText(self.data[rsu]["ssh_info"]["password"])
ssh_lineEdits[2].setText(str(self.data[rsu]["ssh_info"]["port"]))
# SNMP - SSH - Choose tab
if self.data[rsu]["snmp_info"]["enabled"]:
snmp_tabs[0].setCurrentIndex(0)
elif self.data[rsu]["ssh_info"]["enabled"]:
snmp_tabs[0].setCurrentIndex(1)
# Mesh Tab Information
mesh_lineEdits = self.tabs[2][rsu].findChildren(QtWidgets.QLineEdit)
# mesh_lineEdits[0].setText(str(self.data[rsu]["mesh_info"]["port"]))
mesh_lineEdits[0].setText(str(self.data[rsu]["mesh_info"]["static_attenuation"]))
mesh_lineEdits[1].setText(str(self.data[rsu]["mesh_info"]["receiving_port"]))
mesh_checkBoxes = self.tabs[2][rsu].findChildren(QtWidgets.QCheckBox)
mesh_checkBoxes[0].setChecked(self.data[rsu]["mesh_info"]["enabled"])
mesh_combo_boxes = self.tabs[2][rsu].findChildren(QtWidgets.QComboBox)
index = self.data[rsu]["mesh_info"]["port"] if self.data[rsu]["mesh_info"]["port"] != '' else '---'
for i in range(mesh_combo_boxes[0].count()):
if mesh_combo_boxes[0].itemText(i) == index:
mesh_combo_boxes[0].setCurrentIndex(i)
break
# Update RSU Line
self.rsu_line_edit_update(rsu)
def rsuCountChanged(self):
# print(self.ui.rsuCount_spinBox.value())
# For each RSU, create two line edits and a check box on tab 1
for i in range(self.ui.rsuCount_spinBox.value()):
if i < len(self.RSUs[0]):
continue
row = i
if not i in self.data:
self.data[i] = {
"name": "",
"ip_address": "",
"ssh_info": {
"username": "",
"password": "",
"port": 22,
"enabled" : False
},
"snmp_info": {
"version": "-v3",
"-u": "",
"-l": "",
"-a": "",
"-A": "",
"-x": "",
"-X": "",
"-p": 161,
"enabled" : True
},
"mesh_info": {
"port": "",
"receiving_port": "",
"static_attenuation": "",
"enabled" : True
},
"fuzzer_info":{
"enabled": True
}
}
# Create the RSU name line edit
rsu = QtWidgets.QLineEdit(self.ui.rsu_frame)
rsu.setGeometry(QtCore.QRect(20, 40 + (i * 30), 113, 20))
rsu.setObjectName("rsu_lineEdit_" + str(i))
rsu.textChanged.connect(lambda: self.rsu_line_edit_update(row))
rsu.show()
self.RSUs[0].append(rsu)
# Create the RSU host line edit
host = QtWidgets.QLineEdit(self.ui.rsu_frame)
host.setGeometry(QtCore.QRect(150, 40 + (i * 30), 113, 20))
host.setObjectName("host_lineEdit_" + str(i))
host.textChanged.connect(lambda: self.rsu_line_edit_update(row))
host.show()
self.RSUs[1].append(host)
# Create the "Valid RSU IP Address" check box
check = QtWidgets.QCheckBox(self.ui.rsu_frame)
check.setGeometry(QtCore.QRect(310, 40 + (i * 30), 113, 20))
check.setObjectName("check_checkBox_" + str(i))
check.setEnabled(False)
check.show()
self.RSUs[2].append(check)
# Create the ping button
ping_button = QtWidgets.QPushButton(self.ui.rsu_frame)
ping_button.setGeometry(QtCore.QRect(400, 40 + (i * 30), 41, 20))
ping_button.setObjectName("ping_button_" + str(i))
ping_button.setText(">>")
ping_button.clicked.connect(lambda: self.ping(row))
ping_button.setEnabled(False)
ping_button.show()
self.RSUs[3].append(ping_button)
# Create the ping result label
ping_label = QtWidgets.QLabel(self.ui.rsu_frame)
ping_label.setGeometry(QtCore.QRect(460, 40 + (i * 30), 141, 20))
ping_label.setObjectName("ping_label_" + str(i))
ping_label.show()
self.RSUs[4].append(ping_label)
# Add the tabs
self.add_tabs(i)
# Remove line edits that are no longer needed
for i in range(len(self.RSUs[0])):
if i >= self.ui.rsuCount_spinBox.value():
# print("Deleting RSU " + str(i))
# Delete the line edits
for j in range(len(self.RSUs)):
self.RSUs[j][i].deleteLater()
self.RSUs[j].pop(i)
# Delete the tabs
free_mesh_port = self.tabs[2][i].findChildren(QtWidgets.QComboBox)[0].currentText()
self.update_ports('---', free_mesh_port)
for j in range(len(self.tabs)):
self.tabs[j][i].deleteLater()
self.tabs[j].pop(i)
# Delete the dictionary data
self.data[i].clear()
self.data.pop(i)
def rsu_line_edit_update(self, row):
# print("RSU " + str(row) + " changed")
try:
ipaddress.ip_address(self.RSUs[1][row].text())
if self.RSUs[0][row].text():
self.RSUs[2][row].setChecked(True)
self.RSUs[3][row].setEnabled(True)
self.RSUs[4][row].setEnabled(True)
self.data[row]["name"] = self.RSUs[0][row].text()
self.data[row]["ip_address"] = self.RSUs[1][row].text()
# Enable the tabs
for tab in [self.ui.fuzzer_tabWidget, self.ui.snmp_tabWidget, self.ui.mesh_tabWidget]:
tab.setTabEnabled(row, True)
tab.setTabText(row, self.RSUs[0][row].text())
else:
raise Exception("RSU name is empty")
except Exception as e:
self.RSUs[2][row].setChecked(False)
self.RSUs[3][row].setEnabled(False)
self.RSUs[4][row].setEnabled(False)
for tab in [self.ui.fuzzer_tabWidget, self.ui.snmp_tabWidget, self.ui.mesh_tabWidget]:
tab.setTabEnabled(row, False)
# print(e)
return
def ping(self, row):
# print("Pinging RSU " + str(row))
ping = os.system("ping -c 1 " + self.RSUs[1][row].text() + " > /dev/null 2>&1")
if ping == 0:
self.RSUs[4][row].setText("Success")
self.RSUs[4][row].setStyleSheet("color: green")
else:
self.RSUs[4][row].setText("Failed")
self.RSUs[4][row].setStyleSheet("color: red")
def add_tabs(self, row):
self.add_fuzzer_tab(row)
self.add_snmp_tab(row)
self.add_mesh_tab(row)
def add_fuzzer_tab(self, row):
fuzzer_tab = QtWidgets.QWidget()
fuzzer_tab.setObjectName("fuzzer_tab_" + str(row))
# Call external function to populate tab
fuzzer_tab = fill_gui.fill_fuzzer_tab(self, fuzzer_tab, row)
self.tabs[0].append(fuzzer_tab)
self.ui.fuzzer_tabWidget.addTab(fuzzer_tab, "")
self.ui.fuzzer_tabWidget.setTabEnabled(row, False)
def add_snmp_tab(self, row):
snmp_tab = QtWidgets.QWidget()
snmp_tab.setObjectName("snmp_tab_" + str(row))
# Call external function to populate tab
snmp_tab = fill_gui.fill_snmp_tab(self, snmp_tab, row)
self.tabs[1].append(snmp_tab)
self.ui.snmp_tabWidget.addTab(snmp_tab, "")
self.ui.snmp_tabWidget.setTabEnabled(row, False)
def add_mesh_tab(self, row):
mesh_tab = QtWidgets.QWidget()
mesh_tab.setObjectName("mesh_tab_" + str(row))
# Call external function to populate tab
mesh_tab = fill_gui.fill_mesh_tab(self, mesh_tab, row)
self.tabs[2].append(mesh_tab)
self.ui.mesh_tabWidget.addTab(mesh_tab, "")
self.ui.mesh_tabWidget.setTabEnabled(row, False)
# def show_password(self, pwd_check, pwd_lineEdit):
# if pwd_check.isChecked():
# pwd_lineEdit.setEchoMode(QtWidgets.QLineEdit.Normal)
# else:
# pwd_lineEdit.setEchoMode(QtWidgets.QLineEdit.Password)
def update_fuzzer_dict(self, row, key, value):
self.data[row]["fuzzer_info"][key] = value
def update_ssh_dict(self, row, key, value):
self.data[row]["ssh_info"][key] = value
def update_snmp_dict(self, row, key, value):
self.data[row]["snmp_info"][key] = value
def update_mesh_dict(self, row, key, value):
if key == "port":
prev_port = self.data[row]["mesh_info"]["port"]
self.update_ports(value, prev_port)
self.data[row]["mesh_info"][key] = value
def update_ports(self, new_port, prev_port):
combo_boxes = [self.ui.mesh_top_comboBox]
for tab in self.tabs[2]:
combo_boxes += tab.findChildren(QtWidgets.QComboBox)
for combo_box in combo_boxes:
for i in range(combo_box.count()):
if combo_box.itemText(i) == prev_port:
combo_box.model().item(i).setEnabled(True)
if combo_box.itemText(i) == new_port and new_port != "---":
combo_box.model().item(i).setEnabled(False)
self.top_mesh_port = self.ui.mesh_top_comboBox.currentText()
def run_fuzzer_test(self, row):
# print("Running fuzzer test on RSU " + str(row))
"""
Assemble the necessary config information and parameters.
- Read the RSU's parameters
- Read the host testing machine's IP address and forwarding port.
- IP address is in `mesh_ip.yml`
- Port is in `data.yml` -> mesh_info -> receiving_port
- Read or generate an appropriate message_list. Initial release just uses the included `exampleTims.csv`
"""
from v2xFuzzyTester import main as fuzzyTesterMain
rsus = {}
for i in range(len(self.data)):
if not (self.data[i]["fuzzer_info"]["enabled"] and
self.tabs[1].findChild(QtWidgets.QCheckBox, "snmp_enabled_checkBox").isChecked()):
continue # Skip the RSU if disabled.
# Construct a Dictionary representing the RSU with corresponding params.
rsus[i] = {}
rsus[i]["name"] = self.data[i]["name"]
rsus[i]["ip_address"] = self.data[i]["ip_address"]
rsus[i]["receiving_port"] = self.data[i]["mesh_info"]["receiving_port"]
if self.data["ssh_info"]["enabled"]:
rsus[i]["ssh_info"] = self.data[i]["ssh_info"].copy()
elif self.data["snmp_info"]["enabled"]:
rsus[i]["snmp_info"] = self.data[i]["snmp_info"].copy()
# Call the fuzzer with the RSU dictionary.
# output = self.tabs[0].findChild(QtWidgets.QTextEdit, "fuzzer_output_textEdit")
output_file = ".fuzzer_output.txt"
message_file = "./v2xFuzzyTester/exampleTims.csv"
# self.function(message_list='', config=rsus, tx_rsu=row, gui_output=output_file)
# TODO Add ip address for host machine
fuzzyTesterMain.try_list_msgs_with_config(message_file, rsus, row, NotImplemented("host_ip"), output_file)
def run_ssh_test(self, row):
# print("Running SSH test on RSU " + str(row))
pass
def run_snmp_test(self, row):
# print("Running SNMP test on RSU " + str(row))
pass
def run_mesh_test(self, row):
# print("Running mesh test on RSU " + str(row))
data_to_send = {}
if row == -1:
for i in range(len(self.data)):
data_to_send[i] = self.get_mesh_info(i)
else:
data_to_send[row] = self.get_mesh_info(row)
def get_fuzzer_info(self, row):
fuzzer_info = {}
fuzzer_info["fuzzer_info"] = self.data[row]["fuzzer_info"].copy()
fuzzer_info["name"] = self.data[row]["name"]
fuzzer_info["ip_address"] = self.data[row]["ip_address"]
fuzzer_info["output"] = self.tabs[0][row].findChild(QtWidgets.QTextEdit, "fuzzer_output_textEdit")
return fuzzer_info
def get_snmp_info(self, row):
if not self.tabs[1][row].findChild(QtWidgets.QCheckBox, "snmp_checkBox").isChecked():
return
snmp_info = self.data[row]["snmp_info"].copy()
snmp_info["name"] = self.data[row]["name"]
snmp_info["ip_address"] = self.data[row]["ip_address"]
snmp_info["output"] = self.tabs[1][row].findChild(QtWidgets.QTextEdit, "snmp_output_textEdit")
return snmp_info
def get_mesh_info(self, row):
mesh_info = self.data[row]["mesh_info"].copy()
mesh_info["name"] = self.data[row]["name"]
mesh_info["ip_address"] = self.data[row]["ip_address"]
mesh_info["output"] = self.tabs[2][row].findChild(QtWidgets.QTextEdit, "mesh_output_textEdit")
return mesh_info
def main():
app = QtWidgets.QApplication(sys.argv)
application = ApplicationWindow()
application.show()
ret = app.exec()
#application.check_signOut()
sys.exit(ret)
if __name__ == "__main__":
main()