Discontinue the API
This commit is contained in:
parent
33647c34a0
commit
1eadc49cf0
|
@ -7,9 +7,6 @@ Scripts for managing Arch Linux servers
|
|||
|
||||
The `adduser`, `deluser`, and `moduser` scripts are convenience wrappers around `ldapadd`, `ldapdel`, and `ldapvi`.
|
||||
|
||||
### API
|
||||
A simple and extensible web API.
|
||||
|
||||
### upgrade
|
||||
Upgrades the system, all AUR packages, and Nextcloud.
|
||||
|
||||
|
|
5
adduser
5
adduser
|
@ -66,7 +66,4 @@ gidNumber: {uid}'''
|
|||
configure(username)
|
||||
|
||||
|
||||
if len(argv):
|
||||
adduser(*[argv[i] for i in range(1, 6)])
|
||||
else:
|
||||
adduser(os.environ['USERNAME'], os.environ['FIRSTNAME'], os.environ['LASTNAME'], os.environ['EMAIL'], os.environ['PASSWORD'])
|
||||
adduser(*[argv[i] for i in range(1, 6)])
|
||||
|
|
86
api
86
api
|
@ -1,86 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from sys import argv
|
||||
from subprocess import check_output
|
||||
from urllib.parse import parse_qsl
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
|
||||
|
||||
class api(BaseHTTPRequestHandler):
|
||||
"""User management HTTP server"""
|
||||
|
||||
def send(self, code, body):
|
||||
"""Send HTTP response and body"""
|
||||
|
||||
print(code, body)
|
||||
self.send_response(code)
|
||||
self.send_header('Content-Type', 'text/plain')
|
||||
self.send_header('Content-Length', str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body.encode('utf-8'))
|
||||
|
||||
def usernew(self, data):
|
||||
"""Register a new user"""
|
||||
|
||||
if data['code'] != open('/etc/ldappass', 'r').read().split()[1]:
|
||||
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'],
|
||||
data['lastname'], data['email'], data['password'])
|
||||
self.send(200, 'Well I think it worked...')
|
||||
|
||||
def info(self):
|
||||
"""Return info about the server"""
|
||||
|
||||
self.send(200, check_output('neofetch | sed \'s/\\x1B\\[[0-9;\\?]*[a-zA-Z]//g\'', shell=True).decode('utf-8'))
|
||||
|
||||
def packages(self):
|
||||
"""Return the packages installed on the server"""
|
||||
|
||||
self.send(200, check_output(['pacman', '-Q']).decode('utf-8'))
|
||||
|
||||
def do_GET(self):
|
||||
"""Handle GET requests"""
|
||||
|
||||
if self.path == '/api/server/info':
|
||||
self.info()
|
||||
return
|
||||
elif self.path == '/api/server/packages':
|
||||
self.packages()
|
||||
return
|
||||
|
||||
self.send(501, 'We don\'t know how to do that yet')
|
||||
|
||||
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')))
|
||||
except:
|
||||
self.send(400, 'Oops, that request doesn\'t look quite right')
|
||||
|
||||
# Print debug data
|
||||
debug = data.copy()
|
||||
debug.pop('password')
|
||||
debug.pop('confirmpassword')
|
||||
print(debug)
|
||||
|
||||
if self.path == '/api/user/new':
|
||||
self.usernew(data)
|
||||
return
|
||||
|
||||
self.send(501, 'We don\'t know how to do that yet')
|
||||
|
||||
|
||||
# Create and run server
|
||||
print('Starting server')
|
||||
httpd = HTTPServer(('localhost', 1337), api)
|
||||
httpd.serve_forever()
|
Loading…
Reference in a new issue