From a321e0d4ab22373933c7d9c0a0d26996889004a5 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 31 Aug 2011 15:30:33 +0200 Subject: closed #357, #384 --- module/plugins/accounts/FileserveCom.py | 113 +++++++------------------------- 1 file changed, 23 insertions(+), 90 deletions(-) (limited to 'module/plugins/accounts') diff --git a/module/plugins/accounts/FileserveCom.py b/module/plugins/accounts/FileserveCom.py index e8b4547c5..316c2446e 100644 --- a/module/plugins/accounts/FileserveCom.py +++ b/module/plugins/accounts/FileserveCom.py @@ -17,113 +17,46 @@ @author: mkaay """ -import re -from base64 import standard_b64decode - -from Crypto.Cipher import AES +from time import mktime, strptime from module.plugins.Account import Account -def decrypt(data): - data = standard_b64decode(data) - key = standard_b64decode("L3hpTDJGaFNPVVlnc2FUdg==") - - obj = AES.new(key, AES.MODE_ECB) - - return obj.decrypt(data) - - -def parse(data): - ret = {} - for line in data.splitlines(): - line = line.strip() - k, none, v = line.partition("=") - ret[k] = v - - return ret - -def loadSoap(req, soap): - req.putHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.4952)") - req.putHeader("SOAPAction", "\"urn:FileserveAPIWebServiceAction\"") - - ret = req.load("http://api.fileserve.com/api/fileserveAPIServer.php", post=soap, cookies=False, referer=False) - - req.clearHeaders() - - return ret +try: + from json import loads as json_loads +except ImportError: + from module.lib.simplejson import loads as json_loads class FileserveCom(Account): __name__ = "FileserveCom" - __version__ = "0.11" + __version__ = "0.2" __type__ = "account" __description__ = """fileserve.com account plugin""" __author_name__ = ("mkaay") __author_mail__ = ("mkaay@mkaay.de") - LOGIN_RE = re.compile(r"(.*?)(.*?)(.*?)%s%s" % ( - user, data["password"]) - - rep = loadSoap(req, soap) - - match = self.LOGIN_RE.search(rep) - if not match: - return False - - data = parse(decrypt(match.group(1))) - - self.logDebug("Login: %s" % data) - - return data - - - def getShorten(self, req, token, fileid): - soap = "%s%s" % ( - token, fileid) - - rep = loadSoap(req, soap) - - match = self.SHORTEN_RE.search(rep) - data = parse(decrypt(match.group(1))) - self.logDebug("Shorten: %s" % data) - - return data - - - def getDirectLink(self, req, token): - soap = "%s" % token - - rep = loadSoap(req, soap) - - match = self.DIRECT_RE.search(rep) - data = parse(decrypt(match.group(1))) - self.logDebug("getDirect: %s" % data) - - return data - - def loadAccountInfo(self, user, req): - data = self.loginApi(user, req) + data = self.getAccountData(user) + + page = req.load("http://app.fileserve.com/api/login/", post={"username": user, "password": data["password"], + "submit": "Submit+Query"}) + res = json_loads(page) - if data["user_type"] == "PREMIUM": - validuntil = int(data["expiry_date"]) - return {"trafficleft": -1, "validuntil": validuntil} + if res["type"] == "premium": + validuntil = mktime(strptime(res["expireTime"], "%Y-%m-%d %H:%M:%S")) + return {"trafficleft": res["traffic"], "validuntil": validuntil} else: return {"premium": False, "trafficleft": None, "validuntil": None} def login(self, user, data, req): - ret = self.loginApi(user, req, data) - if not ret: - self.wrongPassword() - elif ret["error"] == "LOGIN_FAIL": + page = req.load("http://app.fileserve.com/api/login/", post={"username": user, "password": data["password"], + "submit": "Submit+Query"}) + res = json_loads(page) + + if not res["type"]: self.wrongPassword() + #login at fileserv page + req.load("http://www.fileserve.com/login.php", + post={"loginUserName": user, "loginUserPassword": data["password"], "autoLogin": "checked", + "loginFormSubmit": "Login"}) -- cgit v1.2.3