-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite_conf_wlan.py
More file actions
108 lines (98 loc) · 3.62 KB
/
site_conf_wlan.py
File metadata and controls
108 lines (98 loc) · 3.62 KB
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
import mlib as mist_lib
from mlib import cli
import json
from tabulate import tabulate
#### PARAMETERS #####
csv_separator = ","
def add_wlan():
wlan_file = input("Path to the WLAN configuration JSON file (default: ./site_conf_wlan_settings.json): ")
if wlan_file == "":
wlan_file = "./site_conf_wlan_settings.json"
try:
with open(wlan_file, "r") as f:
wlan = json.load(f)
except:
print("Error while loading the configuration file... exiting...")
exit(255)
try:
wlan_json = json.dumps(wlan)
except:
print("Error while loading the wlan settings from the file... exiting...")
exit(255)
mist_lib.requests.sites.wlans.create(mist, site_id, wlan_json)
def remove_wlan(site_id):
wlans = mist_lib.requests.sites.wlans.get(mist, site_id)['result']
resp = -1
while True:
print()
print("Available WLANs:")
i = -1
for wlan in wlans:
i+=1
print("%s) %s (id: %s)" % (i, wlan["ssid"], wlan["id"]))
print()
resp = input("Which WLAN do you want to delete (0-%s, or q to quit)? " %i)
if resp.lower() == "q":
exit(0)
else:
try:
resp_num = int(resp)
if resp_num >= 0 and resp_num <= i:
wlan = wlans[resp_num]
print()
confirmation = input("Are you sure you want to delete WLAN %s (y/N)? " % wlan["ssid"])
if confirmation.lower() == "y":
break
else:
print("%s is not part of the possibilities." % resp_num)
except:
print("Only numbers are allowed.")
mist_lib.requests.sites.wlans.delete(mist, site_id, wlan["id"])
def display_wlan(site_id):
fields = ["id","ssid", "enabled", "auth", "auth_servers", "acct_servers", "band", "interface", "vlan_id", "dynamic_vlan", "hide_ssid"]
site_wlans = mist_lib.requests.sites.wlans.report(mist, site_id, fields)
print(tabulate(site_wlans, fields))
mist = mist_lib.Mist_Session("./session.py")
#mist.save()
site_id = cli.select_site(mist, allow_many=False)
while True:
print()
print(" ===================")
print(" == CURRENT WLANS ==")
display_wlan(site_id)
print(" ===================")
print()
actions = ["add WLAN", "remove WLAN"]
print("What do you want to do:")
i = -1
for action in actions:
i+= 1
print("%s) %s" % (i, action))
print()
resp = input("Choice (0-%s, q to quit): " %i)
if resp.lower() == "q":
exit(0)
else:
try:
resp_num = int(resp)
if resp_num >= 0 and resp_num <= len(actions):
if actions[resp_num] == "add WLAN":
add_wlan()
print()
print(" ========================")
print(" == WLANS AFTER CHANGE ==")
display_wlan(site_id)
print(" ========================")
break
elif actions[resp_num] == "remove WLAN":
remove_wlan(site_id)
print()
print(" ========================")
print(" == WLANS AFTER CHANGE ==")
display_wlan(site_id)
print(" ========================")
break
else:
print("%s is not part of the possibilities." % resp_num)
except:
print("Only numbers are allowed.")