-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.py
126 lines (86 loc) · 3.87 KB
/
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import json
import os
import tornado.web
import tornado.ioloop
import captcha
class login_handle(tornado.web.RequestHandler) :
def post(self) :
tick_id = self.get_argument('tick')
valid_state = captcha.captcha.check_tick(tick_id)
if captcha.tick_result.tick_state_success == valid_state :
guest_code = self.get_argument('guest_code')
if '514230' == guest_code :
result = 'Pass Success'
else :
result = 'Pass Error'
elif captcha.tick_result.tick_state_expire == valid_state :
result = 'Captcha Expire ..'
else :
result = 'Captcha Error ..'
self.write(json.dumps({
'status' : result
}))
class main_handle(tornado.web.RequestHandler) :
def get(self) :
page = '''
<html>
<title>Aurora CAPTCHA Demo by LCatro</title>
<script src="/captcha/aurora_ui.js"></script>
<script>
function build_url_argument_string(url_argument_list) {
var url_argument_string='';
if (undefined == url_argument_list)
return '';
for (var url_argument_index in url_argument_list)
eval('url_argument_string+="'+url_argument_index+'="+url_argument_list.'+url_argument_index+'+"&"');
if (url_argument_string.length)
url_argument_string=url_argument_string.substr(0,url_argument_string.length-1);
return url_argument_string;
}
function request_post(request_url,request_argument_list) {
var request = new XMLHttpRequest();
request.open('post',request_url,false);
request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
request.send(build_url_argument_string(request_argument_list));
if (4 == request.readyState)
return JSON.parse(request.responseText);
return false;
}
function submit() {
if (undefined == window.pass_tick) {
alert('Please Click CAPTCHA ..');
return 'No Click Captcha';
}
guest_code = document.getElementById('guest_code');
post_data = {
'guest_code' : guest_code.value ,
'tick' : window.pass_tick
}
check_state = request_post('/login',post_data);
alert(check_state['status']);
return check_state;
}
</script>
<body>
Guest Code: <input id="guest_code" type="text" value="" />
<br/>
<img id="captcha" src="/captcha_picture/start.png" onload="captcha_load()" />
<br/>
<input type="button" value="submit" onclick="submit()" />
</body>
</html>
'''
self.write(page)
def start_server(local_port) :
handler = [
('/get_captcha',captcha.get_captcha_handle) ,
('/valid_captcha',captcha.valid_captcha_handle) ,
('/captcha/(.*)',tornado.web.StaticFileHandler,{'path':'captcha'}) ,
('/captcha_picture/(.*)',tornado.web.StaticFileHandler,{'path':'captcha_picture'}) ,
('/login',login_handle) ,
('/',main_handle) ,
]
http_server = tornado.web.Application(handlers = handler)
http_server.listen(local_port)
tornado.ioloop.IOLoop.current().start()
start_server(80)