-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·78 lines (72 loc) · 2.29 KB
/
main.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
'''
File: main.py
Author: github.com/HydroGest
Description: See who are peeping screens.
'''
from flask import Flask, render_template, request, send_from_directory
import os,time,json
app = Flask(__name__)
def SearchObject(groupId,info):
fileName='./data/'+groupId+'.json'
if os.path.isfile(fileName)==False:
createdTime= int(time.time())
with open(fileName,"w",encoding="utf-8") as f:
f.write('{"createdTime":'+str(createdTime)+',"peeperList":[]}')
fileContents=''
with open(fileName,'r') as f:
fileContents=fileContents+f.read()
groupDict = json.loads(fileContents)
if int(time.time())-int(groupDict['createdTime'])>300:
createdTime=time.time()
groupDict={
"createdTime":createdTime,
"peeperList":[]
}
if (info in groupDict['peeperList'])==False:
groupDict['peeperList'].append(info)
with open(fileName,"w",encoding="utf-8") as f:
f.write(json.dumps(groupDict))
return {
'groupId': groupId,
'createdTime': groupDict['createdTime'],
'peeperList': groupDict['peeperList']
}
@app.route('/')
def index():
return render_template('index.html')
@app.route('/search')
def search():
#groupId = request.form['GroupId']
groupId = request.args.get('GroupId', '')
ip= request.remote_addr
userAgent = request.headers.get("User-Agent")
groupInfo = SearchObject(groupId,{
'ip':ip,
'userAgent': userAgent
})
return render_template(
'group.html',
currentTime=time.time(),
GroupId=groupId,
createdTime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(groupInfo['createdTime'])),
peeperList=groupInfo['peeperList']
)
@app.route('/api/search/')
def api():
groupId = request.form('GroupId', '')
ip = request.remote_addr
userAgent = request.headers.get("User-Agent")
groupInfo = SearchObject(groupId,{
'ip':ip,
'userAgent': userAgent
})
return groupInfo
@app.route('/api/getimg/<groupId>/<string>/icon.jpg')
def imgget(groupId,string):
ip = request.remote_addr
userAgent = request.headers.get("User-Agent")
groupInfo = SearchObject(groupId,{
'ip':ip,
'userAgent': userAgent
})
return send_from_directory('','icon128.jpg')