maintain a list of static routes
This commit is contained in:
parent
bdbd463aa8
commit
377bb2b25a
18
main.py
18
main.py
|
@ -120,6 +120,9 @@ def post_gateways():
|
|||
with open('/data/ovpn/clients/' + name, 'w') as f:
|
||||
f.write(staticclient)
|
||||
|
||||
with open('/data/ip/routes', 'a') as f:
|
||||
f.write(network + ' via ' + address + '\n')
|
||||
|
||||
db.commit()
|
||||
return jsonify({'status': 'ok'})
|
||||
except KeyError as e:
|
||||
|
@ -170,6 +173,21 @@ def delete_gateway(fqdn):
|
|||
# TODO sanity check for this parameter! Possible system command injection
|
||||
db = sqlite3.connect(DATABASE)
|
||||
cu = db.cursor()
|
||||
for row in cu.execute('SELECT u.id, g.subid FROM gateway AS g INNER JOIN user AS u ON u.id = g.user WHERE g.name = ?', [str(fqdn,)]):
|
||||
userid = row[0]
|
||||
subid = row[1]
|
||||
ipid = '{:x}{:x}'.format(userid, subid)
|
||||
break
|
||||
|
||||
address = '2001:470:c844::' + ipid + '0/64'
|
||||
network = '2001:470:c844:' + ipid + '0::/60'
|
||||
|
||||
sedrm = "sed -i '\\_^" + network + " via " + address + "$_d' /data/ip/routes"
|
||||
print('[sedrm] ' + sedrm)
|
||||
r = os.system(sedrm)
|
||||
if r != 0:
|
||||
raise Ex(500, 'exit: {} cannot sed-out ip route'.format(r))
|
||||
|
||||
cu.execute('DELETE FROM gateway AS g WHERE g.name = ?', [str(fqdn,)])
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue