Compare commits
2 commits
cf559d1e2e
...
f6056797c1
Author | SHA1 | Date | |
---|---|---|---|
f6056797c1 | |||
f1e01dc348 |
|
@ -6,7 +6,7 @@ from ldappass import ldappass
|
|||
|
||||
def configure(username):
|
||||
"""Configure user"""
|
||||
|
||||
|
||||
run(['sudo', 'mkhomedir_helper', username, '077'])
|
||||
run(['sudo', '-u', username, 'mkdir', '/home/' + username + '/.config'])
|
||||
# Set up Flatpak
|
||||
|
@ -52,7 +52,7 @@ gidNumber: {uid}'''.format(username=username,
|
|||
lastname=lastname,
|
||||
email=email,
|
||||
uid=uid,
|
||||
hashedpassword=crypt(password))
|
||||
hashedpassword=crypt(password))
|
||||
|
||||
# Write to file
|
||||
filename = username + '.ldif'
|
||||
|
@ -67,4 +67,3 @@ gidNumber: {uid}'''.format(username=username,
|
|||
return
|
||||
|
||||
configure(username)
|
||||
|
||||
|
|
21
api.py
21
api.py
|
@ -11,7 +11,7 @@ class api(BaseHTTPRequestHandler):
|
|||
|
||||
def send(self, code, body):
|
||||
"""Send HTTP response and body"""
|
||||
|
||||
|
||||
print(code, body)
|
||||
self.send_response(code)
|
||||
self.send_header('Content-Type', 'text/plain')
|
||||
|
@ -21,31 +21,32 @@ class api(BaseHTTPRequestHandler):
|
|||
|
||||
def usernew(self, data):
|
||||
"""Register a new user"""
|
||||
|
||||
|
||||
if data['code'] != code():
|
||||
self.send(403, 'Nice try, but that secret code is totally wrong')
|
||||
return
|
||||
|
||||
|
||||
if not all(c.isdigit() or c.islower() for c in data['username']) or data['username'][0].isdigit():
|
||||
self.send(403, 'I don\'t like that username')
|
||||
return
|
||||
|
||||
|
||||
# Add the user
|
||||
adduser(data['username'], data['firstname'].capitalize(), data['lastname'].capitalize(),
|
||||
data['email'], data['password'])
|
||||
adduser(data['username'], data['firstname'],
|
||||
data['lastname'], data['email'], data['password'])
|
||||
self.send(200, 'Well I think it worked...')
|
||||
|
||||
def do_GET(self):
|
||||
"""Handle GET requests"""
|
||||
|
||||
|
||||
self.send(200, 'Hey there, you\'ve reached the top secret API')
|
||||
|
||||
|
||||
def do_POST(self):
|
||||
"""Handle API POST requests"""
|
||||
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
try:
|
||||
data = dict(parse_qsl(self.rfile.read(content_length).decode('utf-8')))
|
||||
data = dict(parse_qsl(self.rfile.read(
|
||||
content_length).decode('utf-8')))
|
||||
except:
|
||||
self.send(400, 'Oops, that request doesn\'t look quite right')
|
||||
|
||||
|
@ -58,5 +59,5 @@ class api(BaseHTTPRequestHandler):
|
|||
if self.path == '/api/user/new':
|
||||
self.usernew(data)
|
||||
return
|
||||
|
||||
|
||||
self.send(501, 'We don\'t know how to do that yet')
|
||||
|
|
|
@ -8,6 +8,6 @@ def deluser(username):
|
|||
# Delete from LDAP server
|
||||
run(['ldapdelete', '-w', ldappass(), '-D', 'cn=Manager,dc=exozy,dc=me', 'uid=' + username +
|
||||
',ou=People,dc=exozy,dc=me', 'cn=' + username + ',ou=Group,dc=exozy,dc=me'])
|
||||
|
||||
|
||||
# Cleanup
|
||||
run(['sudo', 'rm', '-rf', '/home/' + username])
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
def ldappass():
|
||||
return open('/etc/ldappass', 'r').read().split()[0]
|
||||
|
||||
|
||||
def code():
|
||||
return open('/etc/ldappass', 'r').read().split()[1]
|
||||
|
|
Loading…
Reference in a new issue