38 lines
1.2 KiB
Python
Executable file
38 lines
1.2 KiB
Python
Executable file
#!/usr/bin/python
|
|
|
|
from subprocess import run, check_output
|
|
from json import loads
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
|
|
from adduser import adduser
|
|
|
|
|
|
# Registration HTTP server
|
|
class Server(BaseHTTPRequestHandler):
|
|
def do_POST(self):
|
|
content_length = int(self.headers['Content-Length'])
|
|
data = loads(self.rfile.read(content_length).decode('utf-8'))
|
|
# Print data
|
|
print([data[key] for key in keys(data) if key != 'password'])
|
|
|
|
if data['code'] != code:
|
|
print('Incorrect code')
|
|
return
|
|
if not all(c.isdigit() or c.islower() for c in data['username']) or data['username'][0].isdigit():
|
|
print('Bad username')
|
|
return
|
|
|
|
# Add the user
|
|
adduser(data['username'], data['firstname'].capitalize(), data['lastname'].capitalize(),
|
|
data['email'], data['password'], ldap_pass)
|
|
|
|
self.send_response(200)
|
|
self.send_header('Content-type', 'text/html')
|
|
self.end_headers()
|
|
|
|
|
|
ldap_pass = input('LDAP password: ')
|
|
code = input('Registration code: ')
|
|
|
|
httpd = HTTPServer(('localhost', 6789), Server)
|
|
httpd.serve_forever()
|