dnsmasq files written and HUP sent
This commit is contained in:
parent
ef67c18135
commit
69314b2c7f
5 changed files with 63 additions and 39 deletions
|
@ -11,7 +11,7 @@ ff:ff:ff:ff:ff:fe,10.6.122.10
|
|||
ff:ff:ff:ff:ff:fe,10.6.122.11
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.12
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.13
|
||||
# { "reserved-by": "WiFi dpto2", "locked": true }
|
||||
# {"locked": true, "reserved-by": "WiFi dpto2"}
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.14
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.15
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.16
|
||||
|
@ -96,12 +96,14 @@ ff:ff:ff:ff:ff:fe,10.6.122.94
|
|||
ff:ff:ff:ff:ff:fe,10.6.122.95
|
||||
# {"reserved-by": "Andy"}
|
||||
00:23:54:8c:65:13,10.6.122.96,set:client0023548c6513
|
||||
# {"reserved-by": "Somoza"}
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.97
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.98
|
||||
# {"reserved-by": "Zelda"}
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.99
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.100
|
||||
# {"reserved-by": "Andy"}
|
||||
aa:bb:cc:dd:ee:ff,10.6.122.101,set:clientaabbccddeeff
|
||||
12:24:42:23:24:45,10.6.122.101,set:client122442232445
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.102
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.103
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.104
|
||||
|
@ -240,4 +242,3 @@ ff:ff:ff:ff:ff:fe,10.6.122.251
|
|||
ff:ff:ff:ff:ff:fe,10.6.122.252
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.253
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.254
|
||||
ff:ff:ff:ff:ff:fe,10.6.122.255
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
tag:client5cf9ffffffff,option:router,10.0.0.1
|
||||
tag:clientaabbccddeeff,option:router,10.6.122.96
|
||||
tag:client0023548c6513,option:router,10.6.122.2
|
||||
tag:client0023548c6513,option:router,10.6.122.96
|
||||
tag:client122442232445,option:router,10.6.122.2
|
||||
|
|
34
main.py
34
main.py
|
@ -46,7 +46,10 @@ exclusive_lock = Lock(lock_file)
|
|||
shared_lock = SharedLock(lock_file)
|
||||
|
||||
def reload_freeradius():
|
||||
call("./reload_freeradius")
|
||||
call("./sendhup freeradius")
|
||||
|
||||
def reload_dnsmasq():
|
||||
call("./sendhup dnsmasq")
|
||||
|
||||
def delete_user(deluser):
|
||||
f = open(users_file)
|
||||
|
@ -303,9 +306,11 @@ def parse_macs(macs):
|
|||
return r
|
||||
|
||||
def write_dhcp_files(ipmap):
|
||||
timestamp = time.time()
|
||||
tempfile = "{}.{}".format(dhcp_hosts_file, timestamp)
|
||||
f = open(tempfile,"w")
|
||||
with open(tempfile,"w") as f:
|
||||
prefix = ipmap["prefix"]
|
||||
gws = {}
|
||||
for i in range(1,255):
|
||||
ip = ipmap[i]
|
||||
if ip.dhcp_pool:
|
||||
|
@ -316,18 +321,30 @@ def write_dhcp_files(ipmap):
|
|||
meta['reserved-by'] = ip.reserved_by
|
||||
if ip.locked:
|
||||
meta['locked'] = True
|
||||
print("# " + json.dumps(meta))
|
||||
print("# " + json.dumps(meta), file=f)
|
||||
if len(ip.macs) == 0:
|
||||
macs = impossible_mac
|
||||
else:
|
||||
macs = ",".join(ip.macs)
|
||||
tag = ""
|
||||
settag = ""
|
||||
if ip.gw and len(ip.macs) > 0:
|
||||
tag = ",set:client" + ip.macs[0].replace(":","").lower()
|
||||
print("{},{}.{}{}".format(macs,prefix,i,tag))
|
||||
f.close()
|
||||
tag = "client" + ip.macs[0].replace(":","").lower()
|
||||
settag = ",set:" + tag
|
||||
gws[tag] = ip.gw
|
||||
print("{},{}.{}{}".format(macs,prefix,i,settag), file=f)
|
||||
shutil.move(tempfile, dhcp_hosts_file)
|
||||
shutil.copy(dhcp_hosts_file, tempfile)
|
||||
|
||||
# Write custom gateways file
|
||||
tempfile = "{}.{}".format(dhcp_opts_file, timestamp)
|
||||
with open(tempfile,"w") as f:
|
||||
for tag in gws:
|
||||
print(
|
||||
"tag:{},option:router,{}".format(tag,gws[tag]),
|
||||
file=f,
|
||||
)
|
||||
shutil.move(tempfile, dhcp_opts_file)
|
||||
shutil.copy(dhcp_opts_file, tempfile)
|
||||
|
||||
@app.route("/ip/<int:last_byte>", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
|
@ -347,7 +364,7 @@ def ip(last_byte):
|
|||
dhcp_pool = request.form.get('dhcp-client', '') == 'pool'
|
||||
macs = parse_macs(request.form.get('dhcp-client-mac', ''))
|
||||
gw = request.form.get('dhcp-gw','')[:15]
|
||||
gw = gw if ip_re.match(gw) else ''
|
||||
gw = gw if ip_re.match(gw) else None
|
||||
|
||||
with exclusive_lock:
|
||||
ipmap = load_ips()
|
||||
|
@ -360,6 +377,7 @@ def ip(last_byte):
|
|||
gw=gw,
|
||||
)
|
||||
write_dhcp_files(ipmap)
|
||||
reload_dnsmasq()
|
||||
|
||||
return redirect(url_for('ips'))
|
||||
else:
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
//system("/etc/init.d/freeradius reload");
|
||||
system("pkill -HUP freeradius");
|
||||
}
|
13
sendhup.cpp
Normal file
13
sendhup.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
return 0;
|
||||
std::ostringstream s;
|
||||
s << "pkill -HUP " << argv[1];
|
||||
//system("/etc/init.d/freeradius reload");
|
||||
system(s.str().c_str());
|
||||
}
|
Loading…
Reference in a new issue