mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
import logging
|
|
import threading
|
|
import json
|
|
from queue import Queue
|
|
from flask import Flask, jsonify, request
|
|
from waitress import serve
|
|
|
|
HOST_ADDRESS = "192.168.1.191"
|
|
PORT_ADDRESS = 5000
|
|
OUT_COMM_Q = Queue()
|
|
IN_COMM_Q = Queue()
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/conjurer", methods=["POST"])
|
|
def answer_external_command():
|
|
record = json.loads(request.data)
|
|
app.logger.info(record)
|
|
#if "UUID" in record and "QUERY" in record and "AUTHOR" in record:
|
|
# answer_data = "Query logged"
|
|
#return_data = (
|
|
# jsonify(isError=False, message="Success", statusCode=200, data=answer_data),
|
|
# 200,
|
|
#)
|
|
#return return_data
|
|
IN_COMM_Q.put("Test")
|
|
return jsonify("SUCCESS")
|
|
|
|
@app.route("/conjurer", methods=["GET"])
|
|
def check_alive():
|
|
return jsonify("ALIVE")
|
|
|
|
def flask_debug(_logger):
|
|
"""
|
|
The `flask_debug` function starts a Flask application in debug mode without using the reloader.
|
|
Do not use for production for fucks sake.
|
|
"""
|
|
_logger.info("Attempt debug")
|
|
# trunk-ignore(bandit/B201)
|
|
app.run(debug=True, use_reloader=False, host=HOST_ADDRESS, port=PORT_ADDRESS)
|
|
|
|
|
|
def waitress_run(_logger):
|
|
"""
|
|
The `waitress_run` function serves the `app` on host "0.0.0.0"
|
|
and port 5000 using the Waitress WSGI server.
|
|
"""
|
|
_logger.info("Attempt waitress")
|
|
serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS)
|
|
|
|
def scan_queue():
|
|
while True:
|
|
data = OUT_COMM_Q.get()
|
|
print(data)
|
|
IN_COMM_Q.put("Test")
|
|
|
|
|
|
def comm_subroutine():
|
|
logger = logging.getLogger('conjurer_musician')
|
|
logger.setLevel(logging.DEBUG)
|
|
logger.info("Started")
|
|
threads = []
|
|
threads.append(threading.Thread(target=waitress_run, args=(logger,)))
|
|
threads.append(threading.Thread(target=scan_queue,))
|
|
|
|
for worker in threads:
|
|
worker.start()
|
|
for worker in threads:
|
|
worker.join()
|
|
|
|
if __name__ == "__main__":
|
|
comm_subroutine() |