-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathcreate_vap.py
More file actions
executable file
·287 lines (254 loc) · 9.33 KB
/
create_vap.py
File metadata and controls
executable file
·287 lines (254 loc) · 9.33 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
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
#!/usr/bin/env python3
"""
NAME: create_vap.py
PURPOSE:
create_vap.py will create a variable number of VAPs.
EXAMPLE:
./create_vap.py
--lfmgr <lanforge ip>
--port <lanforge port 8080>
--upstream_port eth1
--radio wiphy0
--num_vaps 3
--security open
--ssid netgear
--passwd BLANK
--debug
NOTES:
Tested on 03/21/2023:
kernel version: 5.19.17+
gui version: 5.4.6
COPYRIGHT:
Copyright 2023 Candela Technologies Inc
License: Free to distribute and modify. LANforge systems must be licensed.
"""
import sys
import os
import importlib
import argparse
import pprint
import logging
logger = logging.getLogger(__name__)
if sys.version_info[0] != 3:
logger.critical("This script requires Python 3")
exit(1)
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
lfcli_base = importlib.import_module("py-json.LANforge.lfcli_base")
LFCliBase = lfcli_base.LFCliBase
LFUtils = importlib.import_module("py-json.LANforge.LFUtils")
realm = importlib.import_module("py-json.realm")
Realm = realm.Realm
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
class CreateVAP(Realm):
def __init__(self,
_ssid=None,
_security=None,
_password=None,
_mac=None,
_host=None,
_port=None,
_vap_list=None,
_resource=None,
_vap_flags=None,
_mode=None,
_number_template="00000",
_radio=None,
_channel=36,
_country_code=0,
_proxy_str=None,
_debug_on=False,
_exit_on_error=False,
_exit_on_fail=False,
_dhcp=True):
super().__init__(_host, _port, debug_=_debug_on)
self.host = _host
self.port = _port
self.ssid = _ssid
self.security = _security
self.password = _password
self.vap_list = _vap_list
self.resource = _resource
if _vap_flags is None:
self.vap_flags = [
"wpa2_enable",
"80211u_enable",
"create_admin_down"]
else:
self.vap_flags = _vap_flags
self.mode = _mode
self.radio = _radio
self.channel = _channel
self.country_code = _country_code
self.timeout = 120
self.number_template = _number_template
self.debug = _debug_on
self.dhcp = _dhcp
self.vap_profile = self.new_vap_profile()
self.vap_profile.vap_name = self.vap_list
self.vap_profile.ssid = self.ssid
self.vap_profile.security = self.security
self.vap_profile.ssid_pass = self.password
self.vap_profile.dhcp = self.dhcp
self.vap_profile.mode = self.mode
self.vap_profile.desired_add_vap_flags = self.vap_flags + \
["80211u_enable", "create_admin_down"]
self.vap_profile.desired_add_vap_flags_mask = self.vap_flags + \
["80211u_enable", "create_admin_down"]
if self.debug:
print("----- VAP List ----- ----- ----- ----- ----- ----- \n")
pprint.pprint(self.vap_list)
print("---- ~VAP List ----- ----- ----- ----- ----- ----- \n")
def build(self):
# Build VAPs
self.vap_profile.use_security(
self.security, self.ssid, passwd=self.password)
logger.info("Creating VAPs")
# TODO: Add cmd line arguments to control the various options of the VAP profile.
if self.vap_profile.create(resource=self.resource,
radio=self.radio,
channel=self.channel,
up=True,
debug=self.debug,
use_ht40=True,
use_ht80=True,
use_ht160=False,
suppress_related_commands_=True,
use_radius=False,
hs20_enable=False):
self._pass("PASS: VAP build finished")
return True
else:
self._fail("VAP profile creation failed.")
return False
def main():
help_summary = '''\
This script will create a variable number(N) of VAP as specified by the user.
'''
# /home/lanforge-scripts/py-json/LANforge/lfcli_base.py - for base args parser
parser = LFCliBase.create_basic_argparse(
prog='create_vap.py',
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
Create VAPs
''',
description='''\
--------------------
NAME: create_vap.py
PURPOSE:
create_vap.py will create a variable number of VAPs.
EXAMPLE:
./create_vap.py
--lfmgr <lanforge ip>
--port <lanforge port 8080>
--upstream_port eth1
--radio wiphy0
--num_vaps 3
--security open
--ssid netgear
--passwd BLANK
--debug
NOTES:
Tested on 03/21/2023:
kernel version: 5.19.17+
gui version: 5.4.6
''')
optional = parser.add_argument_group('optional arguments')
optional.add_argument(
'--num_vaps',
help='Number of VAPs to Create',
required=False,
default=1)
optional.add_argument(
'--vap_flag',
help='VAP flags to add',
required=False,
default=None,
action='append')
optional.add_argument(
'--mac',
help='Custom mac address',
default="xx:xx:xx:xx:*:xx")
optional.add_argument('--mode', default='0') # 0 means auto # TODO: Add help for other available modes.
optional.add_argument('--channel', default=36)
optional.add_argument('--country_code', default=0)
optional.add_argument('--resource', default=1)
optional.add_argument('--start_id', default=0)
optional.add_argument('--vap_suffix', default=None, help='The numeric suffix, like the 005 in vap005')
args = parser.parse_args()
if args.help_summary:
print(help_summary)
exit(0)
logger_config = lf_logger_config.lf_logger_config()
# set the logger level to requested value
logger_config.set_level(level=args.log_level)
logger_config.set_json(json_file=args.lf_logger_config_json)
# if args.debug:
# pprint.pprint(args)
# time.sleep(5)
if args.radio is None:
raise ValueError("--radio required")
num_vap = int(args.num_vaps)
vap_list = LFUtils.port_name_series(prefix="vap",
start_id=int(args.start_id),
end_id=int(args.start_id) + num_vap - 1,
padding_number=10000,
radio=args.radio)
# print(args.passwd)
# print(args.ssid)
create_vaps = []
if args.vap_suffix is None:
for vap in vap_list:
create_vap = CreateVAP(_host=args.mgr,
_port=args.mgr_port,
_ssid=args.ssid,
_password=args.passwd,
_security=args.security,
_mode=args.mode,
_vap_list=vap,
_resource=args.resource,
_vap_flags=args.vap_flag,
_radio=args.radio,
_channel=args.channel,
_country_code=args.country_code,
_proxy_str=args.proxy,
_debug_on=args.debug)
logger.info('Creating VAP')
if create_vap.build():
create_vap._pass("VAP %s created." % (vap))
else:
create_vap._fail("VAP %s was not created." % (vap))
create_vaps.append(create_vap)
else:
vap_name = "vap" + args.vap_suffix
create_vap = CreateVAP(_host=args.mgr,
_port=args.mgr_port,
_ssid=args.ssid,
_password=args.passwd,
_security=args.security,
_mode=args.mode,
_vap_list=vap_name,
_resource=args.resource,
_vap_flags=args.vap_flag,
_radio=args.radio,
_channel=args.channel,
_country_code=args.country_code,
_proxy_str=args.proxy,
_debug_on=args.debug)
logger.info('Creating VAP')
if create_vap.build():
create_vap._pass("VAP %s created." % (vap))
else:
create_vap._fail("VAP %s was not created." % (vap))
create_vaps.append(create_vap)
# TODO: Add logic to clean up vap, unless --no_cleanup option is specified.
# TODO: Set radio back to previous channel.
any_failed = False
for v in create_vaps:
if not v.passes():
any_failed = True
v.print_pass_fail()
if any_failed:
exit(1)
exit(0)
if __name__ == "__main__":
main()