-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py.single.file.process.backup
95 lines (84 loc) · 3.7 KB
/
index.py.single.file.process.backup
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from flask import Flask
import os
from flask import render_template,request, redirect,make_response,send_file
from werkzeug import secure_filename
import analyze
import datetime
app = Flask(__name__)
UPLOAD_FOLDER = 'cache/'
ALLOWED_EXTENSIONS = set(['txt','',' '])
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/index')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/result')
@app.route('/result/<pocessid>')
def result(pocessid=""):
if pocessid == "":
return render_template('result.html',NAME="pwmfilename",RESULT="tablestr",FILENAME="pfilename")
try:
print 'pocessid=',pocessid
f = open("cache/output/"+pocessid)
data = f.read()
f.close()
print 'file found!'
tablestr = analyze.generateTable(data)
return render_template('result.html',NAME=pocessid[19:],RESULT=tablestr,FILENAME=pocessid,PWMFILE=pocessid,DOMAINFILE=pocessid[0:19]+"domain.txt",PLK="/result/"+pocessid)
#return render_template('result.html',NAME=pwmfilename,RESULT=tablestr,FILENAME=pfilename,PWMFILE=pfilename,DOMAINFILE=dfilename,PLK="/result/"+pfilename)
except Exception as e:
return e.message
return "ERROR: Invaild ID"
@app.route('/download/<ftype>/<filename>')
def downloadresult(ftype,filename):
if ftype == "result":
try:
response = make_response(send_file("cache/output/"+filename))
response.headers["Content-Disposition"] = "attachment; filename=result_" + filename + ".txt;"
return response
except:
return "ERROR: File Not Found"
elif ftype == "raw":
try:
response = make_response(send_file("cache/"+filename))
response.headers["Content-Disposition"] = "attachment; filename=src_" + filename + ".txt;"
return response
except:
return "ERROR: File Not Found"
elif ftype == "test":
response = make_response(send_file("cache/test/TestDataset.zip"))
response.headers["Content-Disposition"] = "attachment; filename=TestDataset.zip;"
return response
return "ERROR: Unknow Error"
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
print("check request type")
if request.method == 'POST':
print("querying file")
pwmfile = request.files['pwmfile']
dofile = request.files['domainfile']
#if pwmfile and allowed_file(pwmfile.filename):
if True:
pwmfilename = secure_filename(pwmfile.filename)
dofilename = secure_filename(dofile.filename)
timesuffix = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
pfilename = timesuffix + pwmfilename
dfilename = timesuffix + dofilename
pwmfile.save(os.path.join(app.config['UPLOAD_FOLDER'], pfilename))
dofile.save(os.path.join(app.config['UPLOAD_FOLDER'], dfilename))
analyze.CallAnalyze(pfilename,dfilename)
#after operation above,data had been put into cache/output/pwmfilename
f = open("cache/output/"+pfilename)
data = f.read()
f.close()
tablestr = analyze.generateTable(data)
return render_template('result.html',NAME=pwmfilename,RESULT=tablestr,FILENAME=pfilename,PWMFILE=pfilename,DOMAINFILE=dfilename,PLK="/result/"+pfilename)
#return analyze.formateData(data)
#return redirect("result")
print("error: not POST")
return "YOU ARE NOT ALLOWED TO VISIT THIS PAGE"
if __name__ == '__main__':
app.run(host='172.31.26.26',port=1996,debug=True)
#app.run(debug=True)