mirror of
https://github.com/Ysurac/openmptcprouter-vps-admin.git
synced 2025-03-09 15:40:05 +00:00
Check if json not empty before writing config file
This commit is contained in:
parent
8e3a334acc
commit
58171a876c
1 changed files with 21 additions and 14 deletions
|
@ -160,6 +160,7 @@ def check_username_serial(username, serial):
|
|||
return True
|
||||
if 'serial' not in data['users'][0][username]:
|
||||
data['users'][0][username]['serial'] = serial
|
||||
if data:
|
||||
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as outfile:
|
||||
json.dump(data, outfile, indent=4)
|
||||
return True
|
||||
|
@ -169,6 +170,7 @@ def check_username_serial(username, serial):
|
|||
data['users'][0][username]['serial_error'] = 1
|
||||
else:
|
||||
data['users'][0][username]['serial_error'] = int(data['users'][0][username]['serial_error']) + 1
|
||||
if data:
|
||||
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as outfile:
|
||||
json.dump(data, outfile, indent=4)
|
||||
return False
|
||||
|
@ -182,6 +184,7 @@ def set_global_param(key, value):
|
|||
except ValueError as e:
|
||||
return {'error': 'Config file not readable', 'route': 'global_param'}
|
||||
data[key] = value
|
||||
if data:
|
||||
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as outfile:
|
||||
json.dump(data, outfile, indent=4)
|
||||
|
||||
|
@ -189,6 +192,7 @@ def modif_config_user(user, changes):
|
|||
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json') as f:
|
||||
content = json.load(f)
|
||||
content['users'][0][user].update(changes)
|
||||
if data:
|
||||
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as f:
|
||||
json.dump(content, f, indent=4)
|
||||
|
||||
|
@ -749,6 +753,7 @@ def set_lastchange(sync=0):
|
|||
except ValueError as e:
|
||||
return {'error': 'Config file not readable', 'route': 'lastchange'}
|
||||
data["lastchange"] = time.time() + sync
|
||||
if data:
|
||||
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as outfile:
|
||||
json.dump(data, outfile, indent=4)
|
||||
|
||||
|
@ -2312,6 +2317,7 @@ def add_user(*, params: NewUser, current_user: User = Depends(get_current_user))
|
|||
if params.vpn is not None:
|
||||
user_json[params.username].update({"vpn": params.vpn})
|
||||
content['users'][0].update(user_json)
|
||||
if content:
|
||||
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as f:
|
||||
json.dump(content, f, indent=4)
|
||||
# Create VPNs configuration
|
||||
|
@ -2336,6 +2342,7 @@ def remove_user(*, params: RemoveUser, current_user: User = Depends(get_current_
|
|||
userid = int(content['users'][0][params.username]['userid'])
|
||||
del content['users'][0][params.username]
|
||||
remove_ss_user(str(shadowsocks_port))
|
||||
if content:
|
||||
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as f:
|
||||
json.dump(content, f, indent=4)
|
||||
os.system('cd /etc/openvpn/ca && ./easyrsa --batch revoke ' + params.username)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue