diff --git a/adduser.py b/adduser.py index 4cafa72..ac1f836 100644 --- a/adduser.py +++ b/adduser.py @@ -1,4 +1,4 @@ -from os import rename, remove, chown +from os import remove from subprocess import run, call, check_output from crypt import crypt from ldappass import ldappass diff --git a/api.py b/api.py index 72ad272..dd0dbca 100644 --- a/api.py +++ b/api.py @@ -1,4 +1,4 @@ -from subprocess import run, check_output +from subprocess import check_output from urllib.parse import parse_qsl from http.server import BaseHTTPRequestHandler @@ -35,10 +35,27 @@ class api(BaseHTTPRequestHandler): 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""" - self.send(200, 'Hey there, you\'ve reached the top secret API') + 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"""