Created
August 18, 2025 19:10
-
-
Save j4velin/397f40996d48509985bcab1b9d23f25a to your computer and use it in GitHub Desktop.
This file contains hidden or 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/python | |
| from flask import Flask | |
| from flask import request | |
| import subprocess | |
| import datetime | |
| http_server = Flask(__name__) | |
| scan = None | |
| @http_server.route('/next', methods=['GET']) | |
| def next(): | |
| if scan is not None: | |
| scan.stdin.write(b'\n') | |
| scan.stdin.flush() | |
| return "Ok" | |
| @http_server.route('/<int:count>', methods=['GET']) | |
| def doScan(count): | |
| global scan | |
| scan = subprocess.Popen('/root/scan.sh ' + str(count), stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True) | |
| if count > 1: | |
| return scan.stdout.readline() | |
| out, err = scan.communicate() | |
| if scan.returncode == 0: | |
| return "scanned " + str(count) + " pages" | |
| else: | |
| with open('/tmp/scan.log', 'a') as log: | |
| log.write(str(datetime.datetime.now()) + '\n') | |
| log.write(out + '\n') | |
| return "error trying to scan, error code: " + str(scan.returncode) + "\n" + out, 500 | |
| if __name__ == '__main__': | |
| http_server.run(host='0.0.0.0', port=8080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment