Implement /api/server/{info,packages}
This commit is contained in:
parent
f6056797c1
commit
a5e5af4cde
|
@ -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
|
||||
|
|
21
api.py
21
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"""
|
||||
|
|
Loading…
Reference in a new issue