From 5cbfd1ebff6845f2824f0086969b733346858d5a Mon Sep 17 00:00:00 2001 From: Nils Hesse Date: Thu, 8 Nov 2012 13:06:06 +0100 Subject: Added the reload.cc plugin --- module/plugins/accounts/ReloadCc.py | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 module/plugins/accounts/ReloadCc.py (limited to 'module/plugins/accounts/ReloadCc.py') diff --git a/module/plugins/accounts/ReloadCc.py b/module/plugins/accounts/ReloadCc.py new file mode 100644 index 000000000..1db5ba6af --- /dev/null +++ b/module/plugins/accounts/ReloadCc.py @@ -0,0 +1,47 @@ +from module.plugins.Account import Account + +from module.common.json_layer import json_loads + +class ReloadCc(Account): + __name__ = "ReloadCc" + __version__ = "0.1" + __type__ = "account" + __description__ = """Reload.Cc account plugin""" + + __author_name__ = ("Reload Team") + __author_mail__ = ("hello@reload.cc") + + def loadAccountInfo(self, user, req): + + # Get user data from premiumize.me + status = self.getAccountStatus(user, req) + + # Parse account info + account_info = {"validuntil": float(status['msg']['expires']), + "pwdhash": status['msg']['hash'], + "trafficleft": -1} + + return account_info + + def login(self, user, data, req): + + # Get user data from premiumize.me + status = self.getAccountStatus(user, req) + + # Check if user and password are valid + if status['status'] != "ok": + self.wrongPassword() + + + def getAccountStatus(self, user, req): + pwd = "pwd=%s" % self.accounts[user]['password'] + + try: + pwd = "hash=%s" % self.accounts[user]['pwdhash'] + except Exception: + pass + + # Use reload.cc API v1 to retrieve account info and return the parsed json answer + answer = req.load("https://api.reload.cc/login?via=pyload&v=1&get_traffic=true&user=%s&%s" % (user, pwd)) + return json_loads(answer) + \ No newline at end of file -- cgit v1.2.3 From 676b45df1589ce6bce14999f1753484c4f0d7f53 Mon Sep 17 00:00:00 2001 From: Nils Hesse Date: Thu, 8 Nov 2012 13:17:28 +0100 Subject: Added some error codes to the reload.cc hoster plugin Removed some leftover comments from account plugin --- module/plugins/accounts/ReloadCc.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'module/plugins/accounts/ReloadCc.py') diff --git a/module/plugins/accounts/ReloadCc.py b/module/plugins/accounts/ReloadCc.py index 1db5ba6af..c1efd05c5 100644 --- a/module/plugins/accounts/ReloadCc.py +++ b/module/plugins/accounts/ReloadCc.py @@ -13,7 +13,7 @@ class ReloadCc(Account): def loadAccountInfo(self, user, req): - # Get user data from premiumize.me + # Get user data from reload.cc status = self.getAccountStatus(user, req) # Parse account info @@ -25,7 +25,7 @@ class ReloadCc(Account): def login(self, user, data, req): - # Get user data from premiumize.me + # Get user data from reload.cc status = self.getAccountStatus(user, req) # Check if user and password are valid @@ -43,5 +43,4 @@ class ReloadCc(Account): # Use reload.cc API v1 to retrieve account info and return the parsed json answer answer = req.load("https://api.reload.cc/login?via=pyload&v=1&get_traffic=true&user=%s&%s" % (user, pwd)) - return json_loads(answer) - \ No newline at end of file + return json_loads(answer) \ No newline at end of file -- cgit v1.2.3 From 26b79c227ac13bcad686bec6670f585b2d202e33 Mon Sep 17 00:00:00 2001 From: Nils Hesse Date: Thu, 8 Nov 2012 23:27:10 +0100 Subject: Change self.accounts to self.info for getting the cached password hash --- module/plugins/accounts/ReloadCc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/accounts/ReloadCc.py') diff --git a/module/plugins/accounts/ReloadCc.py b/module/plugins/accounts/ReloadCc.py index c1efd05c5..dbccd8f8f 100644 --- a/module/plugins/accounts/ReloadCc.py +++ b/module/plugins/accounts/ReloadCc.py @@ -37,7 +37,7 @@ class ReloadCc(Account): pwd = "pwd=%s" % self.accounts[user]['password'] try: - pwd = "hash=%s" % self.accounts[user]['pwdhash'] + pwd = "hash=%s" % self.infos[user]['pwdhash'] except Exception: pass -- cgit v1.2.3 From a0217bf6ef37f5ee57b2bf04baa6568adb69247a Mon Sep 17 00:00:00 2001 From: Nils Hesse Date: Thu, 8 Nov 2012 23:46:51 +0100 Subject: Use a dictionary to supply HTTP requests with the GET parameters (ensure proper URL encoding) --- module/plugins/accounts/ReloadCc.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'module/plugins/accounts/ReloadCc.py') diff --git a/module/plugins/accounts/ReloadCc.py b/module/plugins/accounts/ReloadCc.py index dbccd8f8f..e0eb5df6e 100644 --- a/module/plugins/accounts/ReloadCc.py +++ b/module/plugins/accounts/ReloadCc.py @@ -4,7 +4,7 @@ from module.common.json_layer import json_loads class ReloadCc(Account): __name__ = "ReloadCc" - __version__ = "0.1" + __version__ = "0.2" __type__ = "account" __description__ = """Reload.Cc account plugin""" @@ -34,13 +34,18 @@ class ReloadCc(Account): def getAccountStatus(self, user, req): - pwd = "pwd=%s" % self.accounts[user]['password'] + # Use reload.cc API v1 to retrieve account info and return the parsed json answer + query_params = dict( + via='pyload', + v=1, + get_traffic='true', + user=user + ) try: - pwd = "hash=%s" % self.infos[user]['pwdhash'] + query_params.update(dict(hash=self.infos[user]['pwdhash'])) except Exception: - pass + query_params.update(dict(pwd=self.accounts[user]['password'])) - # Use reload.cc API v1 to retrieve account info and return the parsed json answer - answer = req.load("https://api.reload.cc/login?via=pyload&v=1&get_traffic=true&user=%s&%s" % (user, pwd)) + answer = req.load("https://api.reload.cc/login", get=query_params) return json_loads(answer) \ No newline at end of file -- cgit v1.2.3 From 883371e41d81cc45abd986a50610d04026ed71c6 Mon Sep 17 00:00:00 2001 From: Nils Hesse Date: Wed, 13 Feb 2013 22:09:05 +0100 Subject: Enable better error handling for the Reload.cc plugin --- module/plugins/accounts/ReloadCc.py | 38 +++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'module/plugins/accounts/ReloadCc.py') diff --git a/module/plugins/accounts/ReloadCc.py b/module/plugins/accounts/ReloadCc.py index e0eb5df6e..0916499e8 100644 --- a/module/plugins/accounts/ReloadCc.py +++ b/module/plugins/accounts/ReloadCc.py @@ -2,20 +2,22 @@ from module.plugins.Account import Account from module.common.json_layer import json_loads +from module.network.HTTPRequest import BadHeader + class ReloadCc(Account): __name__ = "ReloadCc" __version__ = "0.2" __type__ = "account" __description__ = """Reload.Cc account plugin""" - + __author_name__ = ("Reload Team") __author_mail__ = ("hello@reload.cc") def loadAccountInfo(self, user, req): - + # Get user data from reload.cc status = self.getAccountStatus(user, req) - + # Parse account info account_info = {"validuntil": float(status['msg']['expires']), "pwdhash": status['msg']['hash'], @@ -24,15 +26,18 @@ class ReloadCc(Account): return account_info def login(self, user, data, req): - + # Get user data from reload.cc status = self.getAccountStatus(user, req) - + + if not status: + raise Exception("There was an error upon logging in to Reload.cc!") + # Check if user and password are valid if status['status'] != "ok": self.wrongPassword() - + def getAccountStatus(self, user, req): # Use reload.cc API v1 to retrieve account info and return the parsed json answer query_params = dict( @@ -47,5 +52,22 @@ class ReloadCc(Account): except Exception: query_params.update(dict(pwd=self.accounts[user]['password'])) - answer = req.load("https://api.reload.cc/login", get=query_params) - return json_loads(answer) \ No newline at end of file + try: + answer = req.load("http://api.reload.cc/login", get=query_params) + except BadHeader as e: + if e.code == 400: + raise Exception("There was an unknown error within the Reload.cc plugin.") + elif e.code == 401: + self.wrongPassword() + elif e.code == 402: + self.expired(user) + elif e.code == 403: + raise Exception("Your account is disabled. Please contact the Reload.cc support!") + elif e.code == 409: + self.empty(user) + elif e.code == 503: + self.logInfo("Reload.cc is currently in maintenance mode! Please check again later.") + self.wrongPassword() + return None + + return json_loads(answer) -- cgit v1.2.3 From 752c9297529a6eca2df50b5a5ef4011388d849dd Mon Sep 17 00:00:00 2001 From: Nils Hesse Date: Wed, 13 Feb 2013 23:09:24 +0100 Subject: Change exception handling to Python 2.5 compatible syntax. Increase version numbers of the plugins. --- module/plugins/accounts/ReloadCc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/accounts/ReloadCc.py') diff --git a/module/plugins/accounts/ReloadCc.py b/module/plugins/accounts/ReloadCc.py index 0916499e8..e4cb32c42 100644 --- a/module/plugins/accounts/ReloadCc.py +++ b/module/plugins/accounts/ReloadCc.py @@ -6,7 +6,7 @@ from module.network.HTTPRequest import BadHeader class ReloadCc(Account): __name__ = "ReloadCc" - __version__ = "0.2" + __version__ = "0.3" __type__ = "account" __description__ = """Reload.Cc account plugin""" @@ -54,7 +54,7 @@ class ReloadCc(Account): try: answer = req.load("http://api.reload.cc/login", get=query_params) - except BadHeader as e: + except BadHeader, e: if e.code == 400: raise Exception("There was an unknown error within the Reload.cc plugin.") elif e.code == 401: -- cgit v1.2.3