-
Notifications
You must be signed in to change notification settings - Fork 2
/
controller.py
62 lines (47 loc) · 1.66 KB
/
controller.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
#!/usr/bin/env python
# coding:utf-8
from bottle import get, route, static_file
from bottle import request, jinja2_template
from setting import Config
from storager import MysqlStorager
db = MysqlStorager()
@get('/favicon.ico')
def favicon():
return static_file("favicon.ico", root=Config.StaticRoot)
@get('/static/:filepath#(img|css|js|fonts)\/.+#')
def server_static(filepath):
return static_file(filepath, root=Config.StaticRoot)
@route('/')
def home():
rows = db.fetchall('select ip, port, lastcheck from http where failtimes<1 order by lastcheck desc limit 100')
proxies = list()
for row in rows:
p = dict()
p['ip'] = row[0]
p['port'] = row[1]
p['check'] = row[2]
proxies.append(p)
j = dict()
j['proxies'] = proxies
return jinja2_template('home.html', j)
@route('/chk.php')
def chk():
# it was replaced by nginx
x_real_ip = request.environ.get('HTTP_X_REAL_IP')
via = request.environ.get('HTTP_VIA')
x_forward_for = request.environ.get('HTTP_X_FORWARDED_FOR')
user_agent = request.environ.get('HTTP_USER_AGENT')
accept_language = request.environ.get('HTTP_ACCEPT_LANGUAGE')
result = {'remote_addr': x_real_ip, 'user_agent': user_agent, 'accept_language': accept_language}
if via:
result['via'] = via
if x_forward_for:
result['x_forward_for'] = x_forward_for
ip = ','.join([x for x in (via, x_forward_for) if x])
level = 'high anonymous'
if ip:
level = 'anonymous'
if ip != x_real_ip:
level = 'transparent'
result['level'] = level
return result