forked from oooldtoy/SSTAP_ip_crawl_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_server.py
105 lines (93 loc) · 3.78 KB
/
web_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
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
96
97
98
99
100
101
102
103
104
105
from flask import *
from datetime import timedelta
import sqlite3,time,os
import config
app = Flask(__name__)
app.config['SECRET_KEY'] = os.urandom(24)
data_base = config.data_base
@app.route('/')
def hello_world():
return 'hello world'
user_list = [[config.password,config.username]]
def timenow(timepoint):#转换时间戳
timeArray = time.localtime(timepoint)
timetranslate = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
return timetranslate
@app.route('/rules/')
def rules():
con = sqlite3.connect(data_base)
cu = con.cursor()
data = cu.execute("select rules,process,ip,time from rules")
data_list = []
for rules,process,ip,time in data:
rules = rules.replace('\n','<br/>')
ip = ip.split('.')
ip[2] = '*'
ip[3] = '*'
ip = '.'.join(ip)
time = timenow(time)
data_list.append([rules,process,ip,time])
cu.close()
con.close()
data_list = list(reversed(data_list))#反转列表,最新的在最前面
return render_template('rules.html',data=data_list)
@app.route('/rules/login/',methods=['POST','GET'])
def rules_login():
if session.get('username'):
return redirect(url_for('rules_modify'))
else:
if request.method=='GET':
return render_template('rules_login.html')
else:
username = request.form.get('username')
password = request.form.get('password')
print(username,password)
if [password,username] in user_list:
session['username'] = username#登陆成功设置session
session.permanent = True#
app.permanent_session_lifetime = timedelta(minutes=10)#设置session到期时间
return redirect(url_for('rules_modify'))
else:
return render_template('rules_login.html')
@app.route('/rules/modify/',methods=['POST','GET'])
def rules_modify():
if session.get('username'):
con = sqlite3.connect(data_base)
cu = con.cursor()
data = cu.execute("select rules,process,ip,time,version from rules")
data_list = []
for rules,process,ip,time,version in data:
rules = rules.replace('\n','<br/>')
data_list.append([rules,process,ip,time,version])
cu.close()
con.close()
if request.method=='GET':
data_list = list(reversed(data_list))#反转列表,最新的在最前面
return render_template('rules_modify.html',data=data_list)
else:
#print(data_list)
data_post = str(request.form) # 如果是get请求就用args
data_post = data_post.replace('ImmutableMultiDict', '')
data_post = tuple(eval(data_post))
data_temp = []
for i in data_post:
data_temp.append(i[0])
print(data_temp)
for i in data_temp:
con = sqlite3.connect(data_base)
cu = con.cursor()
data = cu.execute("delete from rules where time = {}".format(i))
con.commit()
data = cu.execute("select rules,process,ip,time,version from rules")
data_list = []
for rules,process,ip,time,version in data:
rules = rules.replace('\n','<br/>')
data_list.append([rules,process,ip,time,version])
cu.close()
con.close()
data_list = list(reversed(data_list))#反转列表,最新的在最前面
return render_template('rules_modify.html',data=data_list)
else:
return redirect(url_for('rules_login'))
if __name__=='__main__':
app.run(host='0.0.0.0',port=config.web_port)