Ejemplo n.º 1
0
def add_package():
    name = request.forms.get("add_name", "New Package").strip()
    queue = int(request.forms['add_dest'])
    links = decode(request.forms['add_links'])
    links = links.split("\n")
    pw = request.forms.get("add_password", "").strip("\n\r")

    try:
        f = request.files['add_file']

        if not name or name == "New Package":
            name = f.name

        fpath = join(PYLOAD.getConfigValue("general", "download_folder"), "tmp_" + f.filename)
        with open(fpath, 'wb') as destination:
            shutil.copyfileobj(f.file, destination)
        links.insert(0, fpath)
    except Exception:
        pass

    name = name.decode("utf8", "ignore")

    links = map(lambda x: x.strip(), links)
    links = filter(lambda x: x != "", links)

    pack = PYLOAD.addPackage(name, links, queue)
    if pw:
        pw = pw.decode("utf8", "ignore")
        data = {"password": pw}
        PYLOAD.setPackageData(pack, data)
Ejemplo n.º 2
0
def add_package():
    name = request.forms.get("add_name", "New Package").strip()
    queue = int(request.forms['add_dest'])
    links = decode(request.forms['add_links'])
    links = links.split("\n")
    pw = request.forms.get("add_password", "").strip("\n\r")

    try:
        f = request.files['add_file']

        if not name or name == "New Package":
            name = f.name

        fpath = join(PYLOAD.getConfigValue("general", "download_folder"),
                     "tmp_" + f.filename)
        destination = open(fpath, 'wb')
        copyfileobj(f.file, destination)
        destination.close()
        links.insert(0, fpath)
    except Exception:
        pass

    name = name.decode("utf8", "ignore")

    links = map(lambda x: x.strip(), links)
    links = filter(lambda x: x != "", links)

    pack = PYLOAD.addPackage(name, links, queue)
    if pw:
        pw = pw.decode("utf8", "ignore")
        data = {"password": pw}
        PYLOAD.setPackageData(pack, data)
Ejemplo n.º 3
0
def load_config(category, section):
    conf = None
    if category == "general":
        conf = PYLOAD.getConfigDict()
    elif category == "plugin":
        conf = PYLOAD.getPluginConfigDict()

    for key, option in conf[section].iteritems():
        if key in ("desc", "outline"):
            continue

        if ";" in option['type']:
            option['list'] = option['type'].split(";")

        option['value'] = decode(option['value'])

    return render_to_response(
        "settings_item.html", {
            "sorted_conf":
            lambda c: sorted(c.items(),
                             key=lambda i: i[1]['idx'] if i[0] not in
                             ("desc", "outline") else 0),
            "skey":
            section,
            "section":
            conf[section]
        })
Ejemplo n.º 4
0
 def eval(self, script):
     script = "print(eval(unescape('%s')))" % quote(script)
     args = ["java", "-cp", self.path, "org.mozilla.javascript.tools.shell.Main", "-e", script]
     res = decode(self._eval(args))
     try:
         return res.encode("ISO-8859-1")
     finally:
         return res
Ejemplo n.º 5
0
def save_config(category):
    for key, value in request.POST.iteritems():
        try:
            section, option = key.split("|")
        except Exception:
            continue

        if category == "general": category = "core"

        PYLOAD.setConfigValue(section, option, decode(value), category)
Ejemplo n.º 6
0
    def _pluginSet(self, plugins):
        regexp  = re.compile(r'^[\w\-.^_]{3,63}\.[a-zA-Z]{2,}$', re.U)
        plugins = [decode(p.strip()).lower() for p in plugins if regexp.match(p.strip())]

        for r in self.DOMAIN_REPLACEMENTS:
            rf, rt  = r
            repr    = re.compile(rf, re.I | re.U)
            plugins = [re.sub(rf, rt, p) if repr.match(p) else p for p in plugins]

        return set(plugins)
Ejemplo n.º 7
0
    def _pluginSet(self, plugins):
        regexp  = re.compile(r'^[\w\-.^_]{3,63}\.[a-zA-Z]{2,}$', re.U)
        plugins = [decode(p.strip()).lower() for p in plugins if regexp.match(p.strip())]

        for r in self.DOMAIN_REPLACEMENTS:
            rf, rt  = r
            repr    = re.compile(rf, re.I|re.U)
            plugins = [re.sub(rf, rt, p) if repr.match(p) else p for p in plugins]

        return set(plugins)
Ejemplo n.º 8
0
def save_config(category):
    for key, value in request.POST.iteritems():
        try:
            section, option = key.split("|")
        except Exception:
            continue

        if category == "general": category = "core"

        PYLOAD.setConfigValue(section, option, decode(value), category)
Ejemplo n.º 9
0
    def decryptAttr(self, data, key):
        k, iv, meta_mac = self.getCipherKey(key)
        cbc = Crypto.Cipher.AES.new(k, Crypto.Cipher.AES.MODE_CBC, "\0" * 16)
        attr = decode(cbc.decrypt(self.b64_decode(data)))

        self.logDebug("Decrypted Attr: %s" % attr)
        if not attr.startswith("MEGA"):
            self.fail(_("Decryption failed"))

        # Data is padded, 0-bytes must be stripped
        return json_loads(re.search(r'{.+?}', attr).group(0))
Ejemplo n.º 10
0
    def decryptAttr(self, data, key):
        k, iv, meta_mac = self.getCipherKey(key)
        cbc             = AES.new(k, AES.MODE_CBC, "\0" * 16)
        attr            = decode(cbc.decrypt(self.b64_decode(data)))

        self.logDebug("Decrypted Attr: %s" % attr)
        if not attr.startswith("MEGA"):
            self.fail(_("Decryption failed"))

        # Data is padded, 0-bytes must be stripped
        return json_loads(re.search(r'{.+?}', attr).group(0))
Ejemplo n.º 11
0
def load_config(category, section):
    conf = None
    if category == "general":
        conf = PYLOAD.getConfigDict()
    elif category == "plugin":
        conf = PYLOAD.getPluginConfigDict()

    for key, option in conf[section].iteritems():
        if key in ("desc", "outline"): continue

        if ";" in option['type']:
            option['list'] = option['type'].split(";")

        option['value'] = decode(option['value'])

    return render_to_response("settings_item.html", {"skey": section, "section": conf[section]})
Ejemplo n.º 12
0
    def renderFooter(self, line):
        """ prints out the input line with input """
        println(line, "")
        line += 1

        println(line, white(" Input: ") + decode(self.input))

        # clear old output
        if line < self.lastLowestLine:
            for i in xrange(line + 1, self.lastLowestLine + 1):
                println(i, "")

        self.lastLowestLine = line

        # set cursor to position
        print "\033[" + str(self.inputline) + ";0H"
Ejemplo n.º 13
0
    def _log(self, level, *args, **kwargs):
        if "sep" in kwargs:
            sep = "%s" % kwargs["sep"]
        else:
            sep = " | "

        strings = []
        for obj in args:
            if type(obj) == unicode:
                strings.append(obj)
            elif type(obj) == str:
                strings.append(decode(obj))
            else:
                strings.append(str(obj))

        getattr(self.log, level)("%s: %s" % (self.__name__, sep.join(strings)))
Ejemplo n.º 14
0
    def _log(self, level, *args, **kwargs):
        if "sep" in kwargs:
            sep = "%s" % kwargs["sep"]
        else:
            sep = " | "

        strings = []
        for obj in args:
            if type(obj) == unicode:
                strings.append(obj)
            elif type(obj) == str:
                strings.append(decode(obj))
            else:
                strings.append(str(obj))

        getattr(self.log, level)("%s: %s" % (self.__name__, sep.join(strings)))
Ejemplo n.º 15
0
    def renderFooter(self, line):
        """ prints out the input line with input """
        println(line, "")
        line += 1

        println(line, white(" Input: ") + decode(self.input))

        #clear old output
        if line < self.lastLowestLine:
            for i in range(line + 1, self.lastLowestLine + 1):
                println(i, "")

        self.lastLowestLine = line

        #set cursor to position
        print "\033[" + str(self.inputline) + ";0H"
Ejemplo n.º 16
0
def from_string(value, typ=None):
    """ cast value to given type, unicode for strings """

    # value is no string
    if not isinstance(value, basestring):
        return value

    value = decode(value)

    if typ == InputType.Int:
        return int(value)
    elif typ == InputType.Bool:
        return to_bool(value)
    elif typ == InputType.Time:
        if not value: value = "0:00"
        if not ":" in value: value += ":00"
        return value
    else:
        return value
Ejemplo n.º 17
0
def load_config(category, section):
    conf = None
    if category == "general":
        conf = PYLOAD.getConfigDict()
    elif category == "plugin":
        conf = PYLOAD.getPluginConfigDict()

    for key, option in conf[section].iteritems():
        if key in ("desc", "outline"): continue

        if ";" in option["type"]:
            option["list"] = option["type"].split(";")

        option["value"] = decode(option["value"])

    return render_to_response("settings_item.html", {
        "skey": section,
        "section": conf[section]
    })
Ejemplo n.º 18
0
def from_string(value, typ=None):
    """ cast value to given type, unicode for strings """

    # value is no string
    if not isinstance(value, basestring):
        return value

    value = decode(value)

    if typ == InputType.Int:
        return int(value)
    elif typ == InputType.Bool:
        return to_bool(value)
    elif typ == InputType.Time:
        if not value: value = "0:00"
        if not ":" in value: value += ":00"
        return value
    else:
        return value
Ejemplo n.º 19
0
 def parsePackages(self, startNode):
     return [(decode(node.getAttribute("name")).decode('base64'), self.parseLinks(node)) \
             for node in startNode.getElementsByTagName("package")]
Ejemplo n.º 20
0
 def get(self, section, option):
     """get value"""
     value = self.config[section][option]["value"]
     return decode(value)
Ejemplo n.º 21
0
 def get(self, section, option):
     """get value"""
     value = self.config[section][option]['value']
     return decode(value)