This repository has been archived by the owner on Jul 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
71 lines (51 loc) · 1.63 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from wpvulscan import wpscan
import requests
import re
from rq import Queue
from rq.job import Job
from worker import conn
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
q = Queue(connection=conn)
def githubify(text):
text = '```console\n' + text + '```\n'
r = requests.post('https://api.github.com/markdown/raw', data=text, headers={'Content-Type': 'text/x-markdown'})
return r.text
def escape_ansi(text):
ansi_escape = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
return ansi_escape.sub('', text)
@app.route('/', methods=['GET'])
def index():
return render_template('form.html')
@app.route('/enqueue', methods=['POST'])
def enqueue():
task = q.enqueue_call(func=wpscan, args=(request.form['url'],), result_ttl=5000, timeout=3600)
response = {
'status': 'success',
'data': {
'task_id': task.get_id()
}
}
return jsonify(response), 202
@app.route('/tasks/<task_id>', methods=['GET'])
def get_status(task_id):
task = q.fetch_job(task_id)
if task:
response = {
'status': 'success',
'data': {
'task_id': task.get_id(),
'task_status': task.get_status(),
}
}
else:
response = {'status': 'error'}
return jsonify(response)
@app.route('/results/<task_id>', methods=['GET'])
def result(task_id):
task = q.fetch_job(task_id)
result = escape_ansi(task.result)
url = result.splitlines()[0][9:]
return render_template('result.html', results=[{'url': url, 'content': githubify(result)}])
if __name__=='__main__':
app.run()