Last active
July 3, 2024 09:02
-
-
Save sunflsks/124e671bc847179c1df45c0dc757fe16 to your computer and use it in GitHub Desktop.
pubgist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import http.server | |
import socketserver | |
import subprocess | |
import json | |
PORT = 80 | |
COMMAND = "systemctl is-active automator" | |
class RequestHandler(http.server.SimpleHTTPRequestHandler): | |
def do_GET(self): | |
result = subprocess.run(COMMAND, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
output = result.stdout.decode('utf-8').strip() | |
returncode = result.returncode | |
response = {'return_code': returncode, 'output': output} | |
self.send_response(200) | |
# Send headers | |
self.send_header('Content-type', 'application/json') | |
self.end_headers() | |
# Send the response | |
self.wfile.write(json.dumps(response).encode('utf-8')) | |
handler_object = RequestHandler | |
with socketserver.TCPServer(("", PORT), handler_object) as httpd: | |
print("Serving on port", PORT) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment