2021-11-22 21:15:48 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2022-01-06 00:04:23 +00:00
|
|
|
from subprocess import run, check_output
|
2021-11-22 21:15:48 +00:00
|
|
|
from json import loads
|
|
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
2022-01-25 02:15:49 +00:00
|
|
|
from adduser import adduser
|
2022-01-06 01:01:32 +00:00
|
|
|
|
2022-01-06 00:38:44 +00:00
|
|
|
|
2021-11-30 04:17:26 +00:00
|
|
|
class Server(BaseHTTPRequestHandler):
|
2022-01-14 00:21:28 +00:00
|
|
|
"""Registration HTTP server"""
|
|
|
|
|
2021-11-22 21:15:48 +00:00
|
|
|
def do_POST(self):
|
2022-01-14 00:21:28 +00:00
|
|
|
"""Handle registration POST requests"""
|
|
|
|
|
2021-11-22 21:15:48 +00:00
|
|
|
content_length = int(self.headers['Content-Length'])
|
|
|
|
data = loads(self.rfile.read(content_length).decode('utf-8'))
|
2022-01-06 00:38:44 +00:00
|
|
|
# Print data
|
2022-01-06 01:01:32 +00:00
|
|
|
print([data[key] for key in data.keys() if key != 'password'])
|
2021-12-04 01:46:51 +00:00
|
|
|
|
2021-11-30 04:17:26 +00:00
|
|
|
if data['code'] != code:
|
|
|
|
print('Incorrect code')
|
|
|
|
return
|
2022-01-14 00:21:28 +00:00
|
|
|
if not all(c.isdigit() or c.islower()
|
|
|
|
for c in data['username']) or data['username'][0].isdigit():
|
2021-11-30 04:17:26 +00:00
|
|
|
print('Bad username')
|
2021-11-23 21:58:25 +00:00
|
|
|
return
|
2022-01-14 00:21:28 +00:00
|
|
|
|
2022-01-06 00:38:44 +00:00
|
|
|
# Add the user
|
2022-01-06 01:01:32 +00:00
|
|
|
adduser.adduser(data['username'], data['firstname'].capitalize(), data['lastname'].capitalize(),
|
|
|
|
data['email'], data['password'], ldap_pass)
|
2021-11-22 21:15:48 +00:00
|
|
|
|
|
|
|
self.send_response(200)
|
|
|
|
self.send_header('Content-type', 'text/html')
|
|
|
|
self.end_headers()
|
2021-12-04 01:46:51 +00:00
|
|
|
|
2021-11-22 21:15:48 +00:00
|
|
|
|
|
|
|
ldap_pass = input('LDAP password: ')
|
2021-11-23 21:58:25 +00:00
|
|
|
code = input('Registration code: ')
|
2021-11-30 04:17:26 +00:00
|
|
|
|
2022-01-16 22:35:05 +00:00
|
|
|
httpd = HTTPServer(('localhost', 1337), Server)
|
2021-11-30 04:17:26 +00:00
|
|
|
httpd.serve_forever()
|