scripts/register

37 lines
1.4 KiB
Python
Executable file

#!/usr/bin/python
import os
from json import loads
from http.server import BaseHTTPRequestHandler, HTTPServer
class S(BaseHTTPRequestHandler):
def do_POST(self):
content_length = int(self.headers['Content-Length'])
data = loads(self.rfile.read(content_length).decode('utf-8'))
data['password'] = os.popen('slappasswd -s ' + data['password']).read()[:-1]
print(data)
bad = False
if data['code'] != code: bad = True
if not all(c.isdigit() or c.islower() for c in data['username']): bad = True
if not all(c.islower() or c.isupper() for c in data['firstname']): bad = True
if not all(c.islower() or c.isupper() for c in data['lastname']): bad = True
if not all(c.islower() or c.isupper() or c == '@' or c == '.' for c in data['email']): bad = True
if bad:
return
os.system('adduser ' + data['username'] + ' ' + data['firstname'] + ' ' + data['lastname'] + ' ' + data['email'] + ' ' + data['password'] + ' "' + ldap_pass + '"')
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def run(server_class=HTTPServer, handler_class=S):
server_address = ('localhost', 6789)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
ldap_pass = input('LDAP password: ')
code = input('Registration code: ')
run()