| 123456789101112131415161718192021222324252627282930313233 |
- #!/usr/bin/python3
- import os
- import subprocess
- from flask import Flask, Response, json, request
- from cron.Parser import Parser
- api = Flask(__name__)
- @api.route('/version', methods=['GET'])
- def get_version():
- return Response(json.dumps({ "version": "1.0" }), mimetype="application/json")
- @api.route('/section/<string:name>', methods=['GET'])
- def get_section(name):
- cronFile = Parser().parse()
- return Response(cronFile.get_section(name), mimetype="text/plain")
- @api.route('/section/<string:name>', methods=['POST'])
- def set_section(name):
- parser = Parser()
- cronFile = parser.parse()
- cronFile.set_section(name, request.data.decode())
- parser.update(cronFile)
- cronFile = Parser().parse()
- return Response(cronFile.get_section(name), mimetype="text/plain")
- if __name__ == "__main__":
- print("Running as user:")
- subprocess.run("whoami")
- print("Checking crontab access with 'crontab -l'")
- print(subprocess.run(["crontab", "-l"], capture_output = True, text = True).stdout.count('\n'))
- api.run(host = "0.0.0.0", port = 5000)
|