Skip to content
This repository has been archived by the owner on Mar 4, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jat001 committed Jan 20, 2014
1 parent fdf57c0 commit 6815c64
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions handlers/add_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def post(self, anonymous):
anonymous = True if anonymous else False
render_path = "add_task_anonymous.html" if anonymous else "add_task.html"
email = self.current_user['email']
verifycode = self.get_argument("verifycode", None)
verifykey = self.get_cookie("verifykey") or None
# verifycode = self.get_argument("verifycode", None)
# verifykey = self.get_cookie("verifykey") or None

if anonymous and not self.has_permission("add_anonymous_task"):
raise HTTPError(403, "You might not have permission to add anonymous task.")
Expand Down
22 changes: 14 additions & 8 deletions libs/lixian_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import requests
import xml.sax.saxutils
from hashlib import md5
from random import random, sample
from random import random, sample, randint
from urlparse import urlparse
from pprint import pformat
from jsfunctionParser import parser_js_function_call
Expand Down Expand Up @@ -210,8 +210,11 @@ def add_bt_task_with_dict(self, url, info, verifycode=None, verifykey=None):
)
data["from"] = 0
DEBUG(pformat(data))
if verifycode and verifykey:
self.session.cookies = self.update_verifykey(self.session.cookies, verifykey)
# if verifycode and verifykey:
# self.session.cookies = self.update_verifykey(self.session.cookies, 'VERIFY_KEY', verifykey)
# Thank @torta https://github.com/iambus/xunlei-lixian/pull/380
userid = '0' * randint(0, 3000) + str(int(self.session.cookies['userid']))
self.session.cookies = self.update_cookie(self.session.cookies, 'userid', userid)
DEBUG(pformat(self.session.cookies))
r = self.session.post(self.BT_TASK_COMMIT_URL, data=data)
r.raise_for_status()
Expand Down Expand Up @@ -279,8 +282,11 @@ def add_task_with_dict(self, url, info, verifycode=None, verifykey=None):
verify_code = verifycode
)
DEBUG(pformat(params))
if verifycode and verifykey:
self.session.cookies = self.update_verifykey(self.session.cookies, verifykey)
# if verifycode and verifykey:
# self.session.cookies = self.update_cookie(self.session.cookies, 'VERIFY_KEY', verifykey)
# Thank @torta https://github.com/iambus/xunlei-lixian/pull/380
userid = '0' * randint(0, 3000) + str(int(self.session.cookies['userid']))
self.session.cookies = self.update_cookie(self.session.cookies, 'userid', userid)
DEBUG(pformat(self.session.cookies))
r = self.session.get(self.TASK_COMMIT_URL, params=params)
r.raise_for_status()
Expand Down Expand Up @@ -410,10 +416,10 @@ def add(self, url, title=None):
else:
return self.add_batch_task([url, ])

def update_verifykey(self, cookiejar, verifykey):
def update_cookie(self, cookiejar, cookie_name, cookie_value):
_cookies = requests.cookies
_cookies.remove_cookie_by_name(cookiejar, 'VERIFY_KEY')
cookiejar.set_cookie(_cookies.create_cookie('VERIFY_KEY', verifykey, **{'domain': '.xunlei.com'}))
_cookies.remove_cookie_by_name(cookiejar, cookie_name)
cookiejar.set_cookie(_cookies.create_cookie(cookie_name, cookie_value, **{'domain': '.xunlei.com'}))
return cookiejar

FILL_BT_LIST = "http://dynamic.cloud.vip.xunlei.com/interface/fill_bt_list"
Expand Down
3 changes: 2 additions & 1 deletion static/css/add_task.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ input, textarea {
clear: both;
overflow: hidden;
width: 410px;
padding: 20px 0 0 150px;
/* padding: 20px 0 0 150px; */
padding: 20px 0 0 90px;
}
.CAPTCHA {
float: left;
Expand Down
4 changes: 2 additions & 2 deletions templates/add_task.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
</div>

<div class="addtask_button">
<div class="CAPTCHA">
<!-- <div class="CAPTCHA">
<img src="/verifycode.jpg?timestamp={{ timestamp }}" title="点击刷新验证码" onclick="this.src='/verifycode.jpg?timestamp='+new Date().getTime()" />
<input type="text" name="verifycode" id="verify_code" maxlength="4" value="" />
</div>
</div> -->
<div class="addtask_submit">
{% if options.using_xsrf %}{% raw handler.xsrf_form_html() %}{% end %}
<input class="button" name="b" type="submit" value="提交" />
Expand Down
7 changes: 4 additions & 3 deletions templates/add_task_anonymous.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
}
.addtask_button {
width: 410px;
padding-left: 195px;
/* padding-left: 195px; */
padding-left: 125px;
}
.up {
margin: 5px 0 3px 80px;
Expand Down Expand Up @@ -60,10 +61,10 @@
</div>

<div class="addtask_button">
<div class="CAPTCHA">
<!-- <div class="CAPTCHA">
<img src="/verifycode.jpg?timestamp={{ timestamp }}" title="点击刷新验证码" onclick="this.src='/verifycode.jpg?timestamp='+new Date().getTime()" />
<input type="text" name="verifycode" id="verify_code" maxlength="4" value="" />
</div>
</div> -->
<div class="addtask_submit">
{% if options.using_xsrf %}{% raw handler.xsrf_form_html() %}{% end %}
<input type="hidden" name="anonymous" value="1" />
Expand Down

0 comments on commit 6815c64

Please sign in to comment.