forked from leovan/SciHubEVA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscihub_fake_server.py
65 lines (46 loc) · 1.63 KB
/
scihub_fake_server.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tempfile import TemporaryFile
from flask import Flask, request, send_file
app = Flask(__name__)
@app.route('/', methods=['POST'])
def pdf_url_query():
post_request = request.form.get('request')
if post_request:
return pdf_url_response(request.host_url, post_request)
else:
return 'UNKNOWN', 400
def pdf_url_response(host_url: str, request: str):
return '''
<html>
<body>
<iframe id="pdf" src="{host_url}{request}.pdf"></iframe>
</body>
</html>
'''.format(host_url=host_url, request=request)
@app.route('/<pdf>', methods=['GET'])
def pdf_query(pdf: str):
if pdf.find('captcha') != -1:
return captcha_response(request.host_url, pdf)
return send_file(TemporaryFile(), mimetype='application/pdf', attachment_filename=pdf)
@app.route('/<pdf>', methods=['POST'])
def pdf_captcha_query(pdf: str):
post_answer = request.form.get('answer', '')
if not post_answer.lower() in ['eva', 'evangelion']:
return 'WRONG CAPTCHA!'
else:
return send_file(TemporaryFile(), mimetype='application/pdf', attachment_filename=pdf)
def captcha_response(host_url: str, pdf: str):
return '''
<html>
<body>
<img id="captcha" src="{host_url}evangelion.png" />
<input name="id" value="{pdf}"/>
</body>
</html>
'''.format(host_url=host_url, pdf=pdf.split('.')[0])
@app.route('/evangelion.png', methods=['GET'])
def evangelion_img():
return send_file('images/evangelion.png', mimetype='image/png')
if __name__ == '__main__':
app.run(host='0.0.0.0', port='8080', debug=True)