2021-01-01 17:28:34 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-12-28 11:55:33 +00:00
|
|
|
from flask import Flask, jsonify, request
|
|
|
|
from flask_restful import Resource, Api, reqparse
|
2021-01-04 14:49:01 +00:00
|
|
|
import base64
|
2020-12-28 11:55:33 +00:00
|
|
|
import pandas as pd
|
|
|
|
import ast
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
|
|
api = Api(app)
|
|
|
|
@app.route("/systemVersion", methods=["GET"])
|
|
|
|
def uname():
|
|
|
|
uname = subprocess.check_output(["uname", "-arm"])
|
|
|
|
return jsonify(uname)
|
|
|
|
@app.route("/getDKIM", methods=["GET"])
|
|
|
|
def getDkimKey():
|
2021-01-04 14:00:44 +00:00
|
|
|
with open("/var/domain") as domainFile:
|
2021-01-01 18:38:10 +00:00
|
|
|
domain = domainFile.readline()
|
2021-01-01 18:42:03 +00:00
|
|
|
domain = domain.rstrip("\n")
|
2021-01-04 14:40:32 +00:00
|
|
|
catProcess = subprocess.Popen(["cat", "/var/dkim/" + domain + ".selector.txt"], stdout=subprocess.PIPE)
|
|
|
|
dkim = catProcess.communicate()[0]
|
2021-01-05 11:27:00 +00:00
|
|
|
dkim = base64.b64encode(dkim)
|
2021-01-05 11:31:22 +00:00
|
|
|
print(dkim)
|
|
|
|
return "1" #jsonify(dkim)
|
2020-12-28 11:55:33 +00:00
|
|
|
@app.route("/pythonVersion", methods=["GET"])
|
|
|
|
def getPythonVersion():
|
|
|
|
pythonVersion = subprocess.check_output(["python","--version"])
|
|
|
|
return jsonify(pythonVersion)
|
|
|
|
@app.route("/apply", methods=["GET"])
|
|
|
|
def rebuildSystem():
|
|
|
|
rebuildResult = subprocess.Popen(["nixos-rebuild","switch"])
|
|
|
|
rebuildResult.communicate()[0]
|
|
|
|
return jsonify(rebuildResult.returncode)
|
|
|
|
@app.route("/rollback", methods=["GET"])
|
|
|
|
def rollbackSystem():
|
|
|
|
rollbackResult = subprocess.Popen(["nixos-rebuild","switch","--rollback"])
|
|
|
|
rollbackResult.communicate()[0]
|
|
|
|
return jsonify(rollbackResult.returncode)
|
|
|
|
@app.route("/upgrade", methods=["GET"])
|
|
|
|
def upgradeSystem():
|
|
|
|
upgradeResult = subprocess.Popen(["nixos-rebuild","switch","--upgrade"])
|
|
|
|
upgradeResult.communicate()[0]
|
|
|
|
return jsonify(upgradeResult.returncode)
|
|
|
|
@app.route("/createUser", methods=["GET"])
|
|
|
|
def createUser():
|
|
|
|
user = subprocess.Popen(["useradd","-m",request.headers.get("X-User")])
|
|
|
|
user.communicate()[0]
|
|
|
|
return jsonify(user.returncode)
|
|
|
|
@app.route("/deleteUser", methods=["DELETE"])
|
|
|
|
def deleteUser():
|
|
|
|
user = subprocess.Popen(["userdel",request.headers.get("X-User")])
|
|
|
|
user.communicate()[0]
|
|
|
|
return jsonify(user.returncode)
|
|
|
|
@app.route("/serviceStatus", methods=["GET"])
|
|
|
|
def getServiceStatus():
|
|
|
|
imapService = subprocess.Popen(["systemctl", "status", "dovecot2.service"])
|
|
|
|
imapService.communicate()[0]
|
|
|
|
smtpService = subprocess.Popen(["systemctl", "status", "postfix.service"])
|
|
|
|
smtpService.communicate()[0]
|
|
|
|
httpService = subprocess.Popen(["systemctl", "status", "nginx.service"])
|
|
|
|
httpService.communicate()[0]
|
|
|
|
return jsonify(
|
|
|
|
imap=imapService.returncode,
|
|
|
|
smtp=smtpService.returncode,
|
|
|
|
http=httpService.returncode
|
|
|
|
)
|
|
|
|
if __name__ == '__main__':
|
2021-01-01 18:17:21 +00:00
|
|
|
app.run(port=5050, debug=False)
|