scripts/register

38 lines
1.4 KiB
Text
Raw Normal View History

2021-11-22 21:15:48 +00:00
#!/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'))
2021-11-24 03:53:28 +00:00
data['password'] = os.popen('slappasswd -s ' + data['password']).read()[:-1]
2021-11-22 21:15:48 +00:00
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
2021-11-29 23:52:51 +00:00
if not all(c.isdigit() or c.islower() or c.isupper() or c == '@' or c == '.' for c in data['email']): bad = True
if bad:
2021-11-29 23:52:51 +00:00
print('Bad')
2021-11-23 21:58:25 +00:00
return
2021-11-24 03:53:28 +00:00
os.system('adduser ' + data['username'] + ' ' + data['firstname'] + ' ' + data['lastname'] + ' ' + 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()
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: ')
2021-11-23 21:58:25 +00:00
code = input('Registration code: ')
2021-11-22 21:15:48 +00:00
run()