add in backup incase of no connect

This commit is contained in:
Skillet 2023-08-02 23:21:26 -04:00
parent fdbe11b673
commit 17716b880e

View File

@ -36,6 +36,8 @@ class serveRA(http.server.SimpleHTTPRequestHandler):
if firstline.startswith('remotelist='):
remote = firstline.split('=')[1].strip()
response = requests.get(remote, headers={'Accept': 'text/html,*/*'})
print(f"remote list came back with status code {response.status_code}")
if response.status_code == 200:
responsetext = response.text
config = file.read().decode('utf-8')
confgrps = re.findall(r"^permissions/(.+)=(.+)", config, flags=re.M)
@ -44,6 +46,13 @@ class serveRA(http.server.SimpleHTTPRequestHandler):
for congrp in confgrps:
responsetext = re.sub(rf"^Group=({congrp[0]}):(.+)", rf"Group=\1:{congrp[1]}", responsetext, flags=re.M)
self.wfile.write(responsetext.encode('utf-8'))
backupfile = open(f"./wlgrps/backup-{grpName}.cfg", 'wb')
backupfile.write(responsetext.encode('utf-8'))
backupfile.close()
else:
backupfile = open(f"./wlgrps/backup-{grpName}.cfg", 'rb')
self.copyfile(backupfile, self.wfile)
backupfile.close()
else:
self.copyfile(file, self.wfile)
file.close()