forked from slooppe/RedFile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredFile.py
56 lines (50 loc) · 1.34 KB
/
redFile.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
#!/usr/bin/env python
# Part of RedFile
#
# Author: Outflank B.V. / Mark Bergman / @xychix
#
# License : BSD3
from flask import Flask, abort
import werkzeug.exceptions as ex
from flask import make_response, send_file
import random
import jinja2
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
from io import BytesIO
import importlib
from flask import request
import os,sys
### add CWD to path
#cwd = os.path.dirname(os.path.realpath(__file__))
#sys.path.insert(0, cwd)
app = Flask(__name__)
#app.logger.setLevel(logging.DEBUG)
@app.route('/<hash>/<key>/<filename>')
def genFile(hash,key,filename):
try:
m = importlib.import_module('m.%s'%hash)
except:
app.logger.error('Module %s not found'%(hash))
app.logger.error('Went looking in %s'%sys.path)
abort(404)
r = m.f(key,hash,request)
response = make_response(r.fileContent())
response.headers['Content-Type'] = r.fileType()
return response
@app.route('/static/')
def staticlst():
from os import walk
lst = []
for (a,b,c) in walk('static'):
lst.extend(c)
lst.extend(b)
html="<html>"
for i in lst:
html += "<a href='static/%s'>%s</a><br>"%(i,i)
html += "</html>"
return(html)
if __name__ == '__main__':
app.run(host='0.0.0.0',port=18080,debug=True)