diff options
Diffstat (limited to 'module')
| -rw-r--r-- | module/JsEngine.py | 87 | ||||
| -rwxr-xr-x | module/network/Request.py | 3 | ||||
| -rw-r--r-- | module/plugins/Plugin.py | 3 | ||||
| -rw-r--r-- | module/plugins/hoster/BasePlugin.py | 4 | ||||
| -rw-r--r-- | module/setup.py | 4 | ||||
| -rw-r--r-- | module/web/cnl/views.py | 41 | ||||
| -rw-r--r-- | module/web/settings.py | 9 | 
7 files changed, 113 insertions, 38 deletions
diff --git a/module/JsEngine.py b/module/JsEngine.py new file mode 100644 index 000000000..ca5bfe4fc --- /dev/null +++ b/module/JsEngine.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +    This program is free software; you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation; either version 3 of the License, +    or (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +    See the GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program; if not, see <http://www.gnu.org/licenses/>. + +    @author: RaNaN +""" + +ENGINE = "" + +try: +    import spidermonkey +    ENGINE = "spidermonkey" +except: +    pass + +if not ENGINE: +    try: +        import PyV8 +        ENGINE = "pyv8" +    except: +        pass + +if not ENGINE: +    try: +        import subprocess +        subprocess.Popen(["js", "-v"], bufsize=-1,stdout=subprocess.PIPE, stderr=subprocess.PIPE) +        ENGINE = "js" +    except: +        pass + +class JsEngine(): +    def __init__(self): +        self.engine = ENGINE + +    def __nonzero__(self): +        return False if not ENGINE else True + +    def eval(self, script): +        if not ENGINE: +            raise Exception("No JS Engine") +        elif ENGINE == "spidermonkey": +            return self.eval_spidermonkey(script) +        elif ENGINE == "pyv8": +            return self.eval_pyv8(script) +        elif ENGINE == "js": +            return self.eval_js(script) + + +    def eval_spidermonkey(self, script): +        rt = spidermonkey.Runtime() +        cx = rt.new_context() +        return cx.execute(script) + +    def eval_pyv8(self, script): +        rt = PyV8.JSContext() +        rt.enter() +        return rt.eval(script) + +    def eval_js(self, script): +        script = "print(eval('%s'))" % script.replace("'",'"') +        p = subprocess.Popen(["js", "-e", script], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1) +        res = p.stdout.read().strip() +        return res + +if __name__ == "__main__": +    js = JsEngine() +    import subprocess +    import spidermonkey +    import PyV8 + +    test = '"a"+"b"' + +    print js.eval_js(test) +    print js.eval_spidermonkey(test) +    print js.eval_pyv8(test)
\ No newline at end of file diff --git a/module/network/Request.py b/module/network/Request.py index 21159dde1..7c1e468eb 100755 --- a/module/network/Request.py +++ b/module/network/Request.py @@ -17,7 +17,6 @@      @author: spoob      @author: RaNaN      @author: mkaay -    @version: v0.3.2  """  import base64 @@ -361,7 +360,7 @@ class Request:      def progress(self, dl_t, dl_d, up_t, up_d):          if self.abort: -            return False +            raise Exception          self.dl_arrived = int(dl_d)          self.dl_size = int(dl_t) diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index 04df13978..1568b0917 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -105,7 +105,8 @@ class Plugin(object):          self.pyfile = pyfile          self.thread = None # holds thread in future -        self.lastDownload = "" #location where the last call to download was saved +        self.lastDownload = ""  # location where the last call to download was saved +        self.js = self.core.js  # js engine          self.setup() diff --git a/module/plugins/hoster/BasePlugin.py b/module/plugins/hoster/BasePlugin.py index 09545d493..4701f82ca 100644 --- a/module/plugins/hoster/BasePlugin.py +++ b/module/plugins/hoster/BasePlugin.py @@ -16,9 +16,9 @@ class BasePlugin(Hoster):      def process(self, pyfile):          """main function""" -        if pyfile.url.startswith("http://"): +        if pyfile.url.startswith("http"): -            pyfile.name = re.findall("([^\/=]+)", pyfile.url)[-1] +            pyfile.name = re.findall("([^/=]+)", pyfile.url)[-1]              self.download(pyfile.url)          else: diff --git a/module/setup.py b/module/setup.py index e2b87e781..1991f0af4 100644 --- a/module/setup.py +++ b/module/setup.py @@ -244,7 +244,9 @@ class Setup():          self.print_dep("django", web)          web = web and sqlite -        js = self.check_prog(["js", "-v"]) +        from module import JsEngine + +        js = True if JsEngine.ENGINE else False          self.print_dep(_("JS engine"), js)          return (basic, ssl, captcha, gui, web, js) diff --git a/module/web/cnl/views.py b/module/web/cnl/views.py index c2e95151c..516a67442 100644 --- a/module/web/cnl/views.py +++ b/module/web/cnl/views.py @@ -90,36 +90,27 @@ def addcrypted2(request):      jk = request.POST["jk"]      crypted = base64.standard_b64decode(unquote(crypted.replace(" ", "+"))) -    try: -        import spidermonkey -        rt = spidermonkey.Runtime() -        cx = rt.new_context() -        jk = cx.execute("%s f()" % jk) -    except ImportError: -        if settings.JS: -            import subprocess -            jk = jk.replace("'", '"') -            cmd = settings.JS + ["-e", "%s ;print(f());" % jk ] -            p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1) -            jk = p.stdout.read().strip() +    if settings.JS: +        jk = "%s f()" % jk +        jk = settings.JS.eval(jk) -        else: -            try: -                jk = re.findall(r"return ('|\")(.+)('|\")", jk)[0][1] -            except: -            ## Test for some known js functions to decode -                if jk.find("dec") > -1 and jk.find("org") > -1: -                    org = re.findall(r"var org = ('|\")([^\"']+)", jk)[0][1] -                    jk = list(org) -                    jk.reverse() -                    jk = "".join(jk) -                else: -                    print "Could not decrypt key, please install py-spidermonkey or other js engine" +    else: +        try: +            jk = re.findall(r"return ('|\")(.+)('|\")", jk)[0][1] +        except: +        ## Test for some known js functions to decode +            if jk.find("dec") > -1 and jk.find("org") > -1: +                org = re.findall(r"var org = ('|\")([^\"']+)", jk)[0][1] +                jk = list(org) +                jk.reverse() +                jk = "".join(jk) +            else: +                print "Could not decrypt key, please install py-spidermonkey or ossp-js"      try:          Key = binascii.unhexlify(jk)      except: -        print "Could not decrypt key, please install py-spidermonkey or other js engine" +        print "Could not decrypt key, please install py-spidermonkey or ossp-js"          return JsonResponse("failed", request)      IV = Key diff --git a/module/web/settings.py b/module/web/settings.py index 515117860..4dfe50fdc 100644 --- a/module/web/settings.py +++ b/module/web/settings.py @@ -55,13 +55,8 @@ except:      PYLOAD = xmlrpclib.ServerProxy(server_url, allow_none=True)
 -try:
 -    import subprocess
 -    subprocess.Popen(["js", "-v"], bufsize=-1,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 -    JS = ["js"]
 -except:
 -    JS = []
 -
 +from module.JsEngine import JsEngine
 +JS = JsEngine()
  TEMPLATE = config.get('webinterface','template')
  DL_ROOT = os.path.join(PYLOAD_DIR, config.get('general','download_folder'))
  | 
