コード例 #1
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def downloads():
    root = PYLOAD.getConfigValue("general", "download_folder")

    if not os.path.isdir(root):
        return base([_('Download directory not found.')])
    data = {
        'folder': [],
        'files': []
    }

    items = os.listdir(fs_encode(root))

    for item in sorted([fs_decode(x) for x in items]):
        if os.path.isdir(fs_join(root, item)):
            folder = {
                'name': item,
                'path': item,
                'files': []
            }
            files = os.listdir(fs_join(root, item))
            for file in sorted([fs_decode(x) for x in files]):
                try:
                    if os.path.isfile(fs_join(root, item, file)):
                        folder['files'].append(file)
                except Exception:
                    pass

            data['folder'].append(folder)
        elif os.path.isfile(os.path.join(root, item)):
            data['files'].append(item)

    return render_to_response('downloads.html', {'files': data}, [pre_processor])
コード例 #2
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def downloads():
    root = PYLOAD.getConfigValue("general", "download_folder")

    if not os.path.isdir(root):
        return base([_('Download directory not found.')])
    data = {'folder': [], 'files': []}

    items = os.listdir(fs_encode(root))

    for item in sorted([fs_decode(x) for x in items]):
        if os.path.isdir(fs_join(root, item)):
            folder = {'name': item, 'path': item, 'files': []}
            files = os.listdir(fs_join(root, item))
            for file in sorted([fs_decode(x) for x in files]):
                try:
                    if os.path.isfile(fs_join(root, item, file)):
                        folder['files'].append(file)
                except Exception:
                    pass

            data['folder'].append(folder)
        elif os.path.isfile(os.path.join(root, item)):
            data['files'].append(item)

    return render_to_response('downloads.html', {'files': data},
                              [pre_processor])
コード例 #3
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def admin():
    # convert to dict
    user = dict((name, toDict(y)) for name, y in PYLOAD.getAllUserData().iteritems())
    perms = permlist()

    for data in user.itervalues():
        data['perms'] = {}
        get_permission(data['perms'], data['permission'])
        data['perms']['admin'] = data['role'] is 0

    s = bottle.request.environ.get('beaker.session')
    if bottle.request.environ.get('REQUEST_METHOD', "GET") == "POST":
        for name in user:
            if bottle.request.POST.get("%s|admin" % name, False):
                user[name]['role'] = 0
                user[name]['perms']['admin'] = True
            elif name != s['name']:
                user[name]['role'] = 1
                user[name]['perms']['admin'] = False

            # set all perms to false
            for perm in perms:
                user[name]['perms'][perm] = False

            for perm in bottle.request.POST.getall("%s|perms" % name):
                user[name]['perms'][perm] = True

            user[name]['permission'] = set_permission(user[name]['perms'])

            PYLOAD.setUserPermission(name, user[name]['permission'], user[name]['role'])

    return render_to_response("admin.html", {"users": user, "permlist": perms}, [pre_processor])
コード例 #4
0
ファイル: json.py プロジェクト: Arisharr/Download-Manager
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]
        })
コード例 #5
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def collector():
    queue = PYLOAD.getCollector()

    queue.sort(key=operator.attrgetter("order"))

    return render_to_response('queue.html', {
        'content': queue,
        'target': 0
    }, [pre_processor])
コード例 #6
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def login_post():
    user = bottle.request.forms.get("username")
    password = bottle.request.forms.get("password")

    info = PYLOAD.checkAuth(user, password)

    if not info:
        return render_to_response("login.html", {"errors": True}, [pre_processor])

    set_session(info)
    return bottle.redirect("/")
コード例 #7
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def config():
    conf = PYLOAD.getConfig()
    plugin = PYLOAD.getPluginConfig()
    conf_menu = []
    plugin_menu = []

    for entry in sorted(conf.keys()):
        conf_menu.append((entry, conf[entry].description))

    last_name = None
    for entry in sorted(plugin.keys()):
        desc = plugin[entry].description
        name, none, type = desc.partition("_")

        if type in PYLOAD.core.pluginManager.TYPES:
            if name == last_name or len([a for a, b in plugin.iteritems() if b.description.startswith(name + "_")]) > 1:
                desc = name + " (" + type.title() + ")"
            else:
                desc = name
            last_name = name
        plugin_menu.append((entry, desc))

    accs = PYLOAD.getAccounts(False)

    for data in accs:
        if data.trafficleft == -1:
            data.trafficleft = _("unlimited")
        elif not data.trafficleft:
            data.trafficleft = _("not available")
        else:
            data.trafficleft = formatSize(data.trafficleft)

        if data.validuntil == -1:
            data.validuntil = _("unlimited")
        elif not data.validuntil:
            data.validuntil = _("not available")
        else:
            t = time.localtime(data.validuntil)
            data.validuntil = time.strftime("%d.%m.%Y - %H:%M:%S", t)

        try:
            data.options['time'] = data.options['time'][0]
        except Exception:
            data.options['time'] = "0:00-0:00"

        if "limitDL" in data.options:
            data.options['limitdl'] = data.options['limitDL'][0]
        else:
            data.options['limitdl'] = "0"

    return render_to_response('settings.html',
                              {'conf': {'plugin': plugin_menu, 'general': conf_menu, 'accs': accs},
                               'types': PYLOAD.getAccountTypes()},
                              [pre_processor])
コード例 #8
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def login_post():
    user = bottle.request.forms.get("username")
    password = bottle.request.forms.get("password")

    info = PYLOAD.checkAuth(user, password)

    if not info:
        return render_to_response("login.html", {"errors": True},
                                  [pre_processor])

    set_session(info)
    return bottle.redirect("/")
コード例 #9
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def home():
    try:
        res = [toDict(x) for x in PYLOAD.statusDownloads()]
    except Exception:
        s = bottle.request.environ.get('beaker.session')
        s.delete()
        return bottle.redirect("/login")

    for link in res:
        if link['status'] == 12:
            link['information'] = "%s kB @ %s kB/s" % (link['size'] - link['bleft'], link['speed'])

    return render_to_response("home.html", {"res": res}, [pre_processor])
コード例 #10
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def home():
    try:
        res = [toDict(x) for x in PYLOAD.statusDownloads()]
    except Exception:
        s = bottle.request.environ.get('beaker.session')
        s.delete()
        return bottle.redirect("/login")

    for link in res:
        if link['status'] == 12:
            link['information'] = "%s kB @ %s kB/s" % (
                link['size'] - link['bleft'], link['speed'])

    return render_to_response("home.html", {"res": res}, [pre_processor])
コード例 #11
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def info():
    conf = PYLOAD.getConfigDict()
    extra = os.uname() if hasattr(os, "uname") else tuple()

    data = {"python"   : sys.version,
            "os"       : " ".join((os.name, sys.platform) + extra),
            "version"  : PYLOAD.getServerVersion(),
            "folder"   : os.path.abspath(PYLOAD_DIR), "config": os.path.abspath(""),
            "download" : os.path.abspath(conf['general']['download_folder']['value']),
            "freespace": formatSize(PYLOAD.freeSpace()),
            "remote"   : conf['remote']['port']['value'],
            "webif"    : conf['webui']['port']['value'],
            "language" : conf['general']['language']['value']}

    return render_to_response("info.html", data, [pre_processor])
コード例 #12
0
ファイル: json.py プロジェクト: Bobbaone/pyload
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]})
コード例 #13
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def info():
    conf = PYLOAD.getConfigDict()
    extra = os.uname() if hasattr(os, "uname") else tuple()

    data = {
        "python": sys.version,
        "os": " ".join((os.name, sys.platform) + extra),
        "version": PYLOAD.getServerVersion(),
        "folder": os.path.abspath(PYLOAD_DIR),
        "config": os.path.abspath(""),
        "download":
        os.path.abspath(conf['general']['download_folder']['value']),
        "freespace": formatSize(PYLOAD.freeSpace()),
        "remote": conf['remote']['port']['value'],
        "webif": conf['webui']['port']['value'],
        "language": conf['general']['language']['value']
    }

    return render_to_response("info.html", data, [pre_processor])
コード例 #14
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def admin():
    # convert to dict
    user = dict(
        (name, toDict(y)) for name, y in PYLOAD.getAllUserData().iteritems())
    perms = permlist()

    for data in user.itervalues():
        data['perms'] = {}
        get_permission(data['perms'], data['permission'])
        data['perms']['admin'] = data['role'] is 0

    s = bottle.request.environ.get('beaker.session')
    if bottle.request.environ.get('REQUEST_METHOD', "GET") == "POST":
        for name in user:
            if bottle.request.POST.get("%s|admin" % name, False):
                user[name]['role'] = 0
                user[name]['perms']['admin'] = True
            elif name != s['name']:
                user[name]['role'] = 1
                user[name]['perms']['admin'] = False

            # set all perms to false
            for perm in perms:
                user[name]['perms'][perm] = False

            for perm in bottle.request.POST.getall("%s|perms" % name):
                user[name]['perms'][perm] = True

            user[name]['permission'] = set_permission(user[name]['perms'])

            PYLOAD.setUserPermission(name, user[name]['permission'],
                                     user[name]['role'])

    return render_to_response("admin.html", {
        "users": user,
        "permlist": perms
    }, [pre_processor])
コード例 #15
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def base(messages):
    return render_to_response('base.html', {'messages': messages}, [pre_processor])
コード例 #16
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def login():
    if not PYLOAD and SETUP:
        bottle.redirect("/setup")
    else:
        return render_to_response("login.html", proc=[pre_processor])
コード例 #17
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def logout():
    s = bottle.request.environ.get('beaker.session')
    s.delete()
    return render_to_response("logout.html", proc=[pre_processor])
コード例 #18
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def logs(item=-1):
    s = bottle.request.environ.get('beaker.session')

    perpage = s.get('perpage', 34)
    reversed = s.get('reversed', False)

    warning = ""
    conf = PYLOAD.getConfigValue("log", "file_log")
    if not conf:
        warning = "Warning: File log is disabled, see settings page."

    perpage_p = ((20, 20), (50, 50), (100, 100), (250, 250), (0, 'all'))
    fro = None

    if bottle.request.environ.get('REQUEST_METHOD', "GET") == "POST":
        try:
            fro = datetime.datetime.strptime(bottle.request.forms['from'], '%d.%m.%Y %H:%M:%S')
        except Exception:
            pass
        try:
            perpage = int(bottle.request.forms['perpage'])
            s['perpage'] = perpage

            reversed = bool(bottle.request.forms.get('reversed', False))
            s['reversed'] = reversed
        except Exception:
            pass

        s.save()

    try:
        item = int(item)
    except Exception:
        pass

    log = PYLOAD.getLog()
    if not perpage:
        item = 1

    if item < 1 or type(item) is not int:
        item = 1 if len(log) - perpage + 1 < 1 else len(log) - perpage + 1

    if type(fro) is datetime.datetime:  #: we will search for datetime.datetime
        item = -1

    data = []
    counter = 0
    perpagecheck = 0
    for l in log:
        counter += 1

        if counter >= item:
            try:
                date, time, level, message = l.decode("utf8", "ignore").split(" ", 3)
                dtime = datetime.datetime.strptime(date + ' ' + time, '%Y-%m-%d %H:%M:%S')
            except Exception:
                dtime = None
                date = '?'
                time = ' '
                level = '?'
                message = l

            if item == -1 and dtime is not None and fro <= dtime:
                item = counter  #: found our datetime.datetime

            if item >= 0:
                data.append({'line': counter, 'date': date + " " + time, 'level': level, 'message': message})
                perpagecheck += 1
                if fro is None and dtime is not None:  #: if fro not set set it to first showed line
                    fro = dtime

            if perpagecheck >= perpage > 0:
                break

    if fro is None:  #: still not set, empty log?
        fro = datetime.datetime.now()
    if reversed:
        data.reverse()
    return render_to_response('logs.html', {'warning': warning, 'log': data, 'from': fro.strftime('%d.%m.%Y %H:%M:%S'),
                                            'reversed': reversed, 'perpage': perpage, 'perpage_p': sorted(perpage_p),
                                            'iprev': 1 if item - perpage < 1 else item - perpage,
                                            'inext': (item + perpage) if item + perpage < len(log) else item,
                                            'color_console': PYLOAD.getConfigValue("log", "color_console")},
                              [pre_processor])
コード例 #19
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def path(file="", path=""):
    type = "file" if file else "folder"

    path = os.path.normpath(unquotepath(path))

    if os.path.isfile(path):
        oldfile = path
        path = os.path.dirname(path)
    else:
        oldfile = ''

    abs = False

    if os.path.isdir(path):
        if os.path.isabs(path):
            cwd = os.path.abspath(path)
            abs = True
        else:
            cwd = os.relpath(path)
    else:
        cwd = os.getcwd()

    try:
        cwd = cwd.encode("utf8")
    except Exception:
        pass

    cwd = os.path.normpath(os.path.abspath(cwd))
    parentdir = os.path.dirname(cwd)
    if not abs:
        if os.path.abspath(cwd) == "/":
            cwd = os.relpath(cwd)
        else:
            cwd = os.relpath(cwd) + os.path.sep
        parentdir = os.relpath(parentdir) + os.path.sep

    if os.path.abspath(cwd) == "/":
        parentdir = ""

    try:
        folders = os.listdir(cwd)
    except Exception:
        folders = []

    files = []

    for f in folders:
        try:
            f = f.decode(sys.getfilesystemencoding())
            data = {'name': f, 'fullpath': os.path.join(cwd, f)}
            data['sort'] = data['fullpath'].lower()
            data['modified'] = datetime.datetime.fromtimestamp(int(os.path.getmtime(os.path.join(cwd, f))))
            data['ext'] = os.path.splitext(f)[1]
        except Exception:
            continue

        data['type'] = 'dir' if os.path.isdir(os.path.join(cwd, f)) else 'file'

        if os.path.isfile(os.path.join(cwd, f)):
            data['size'] = os.path.getsize(os.path.join(cwd, f))

            power = 0
            while (data['size'] / 1024) > 0.3:
                power += 1
                data['size'] /= 1024.
            units = ('', 'K', 'M', 'G', 'T')
            data['unit'] = units[power] + 'Byte'
        else:
            data['size'] = ''

        files.append(data)

    files = sorted(files, key=operator.itemgetter('type', 'sort'))

    return render_to_response('pathchooser.html',
                              {'cwd': cwd, 'files': files, 'parentdir': parentdir, 'type': type, 'oldfile': oldfile,
                               'absolute': abs}, [])
コード例 #20
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def config():
    conf = PYLOAD.getConfig()
    plugin = PYLOAD.getPluginConfig()
    conf_menu = []
    plugin_menu = []

    for entry in sorted(conf.keys()):
        conf_menu.append((entry, conf[entry].description))

    last_name = None
    for entry in sorted(plugin.keys()):
        desc = plugin[entry].description
        name, none, type = desc.partition("_")

        if type in PYLOAD.core.pluginManager.TYPES:
            if name == last_name or len([
                    a for a, b in plugin.iteritems()
                    if b.description.startswith(name + "_")
            ]) > 1:
                desc = name + " (" + type.title() + ")"
            else:
                desc = name
            last_name = name
        plugin_menu.append((entry, desc))

    accs = PYLOAD.getAccounts(False)

    for data in accs:
        if data.trafficleft == -1:
            data.trafficleft = _("unlimited")
        elif not data.trafficleft:
            data.trafficleft = _("not available")
        else:
            data.trafficleft = formatSize(data.trafficleft)

        if data.validuntil == -1:
            data.validuntil = _("unlimited")
        elif not data.validuntil:
            data.validuntil = _("not available")
        else:
            t = time.localtime(data.validuntil)
            data.validuntil = time.strftime("%d.%m.%Y - %H:%M:%S", t)

        try:
            data.options['time'] = data.options['time'][0]
        except Exception:
            data.options['time'] = "0:00-0:00"

        if "limitDL" in data.options:
            data.options['limitdl'] = data.options['limitDL'][0]
        else:
            data.options['limitdl'] = "0"

    return render_to_response(
        'settings.html', {
            'conf': {
                'plugin': plugin_menu,
                'general': conf_menu,
                'accs': accs
            },
            'types': PYLOAD.getAccountTypes()
        }, [pre_processor])
コード例 #21
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def path(file="", path=""):
    type = "file" if file else "folder"

    path = os.path.normpath(unquotepath(path))

    if os.path.isfile(path):
        oldfile = path
        path = os.path.dirname(path)
    else:
        oldfile = ''

    abs = False

    if os.path.isdir(path):
        if os.path.isabs(path):
            cwd = os.path.abspath(path)
            abs = True
        else:
            cwd = os.relpath(path)
    else:
        cwd = os.getcwd()

    try:
        cwd = cwd.encode("utf8")
    except Exception:
        pass

    cwd = os.path.normpath(os.path.abspath(cwd))
    parentdir = os.path.dirname(cwd)
    if not abs:
        if os.path.abspath(cwd) == "/":
            cwd = os.relpath(cwd)
        else:
            cwd = os.relpath(cwd) + os.path.sep
        parentdir = os.relpath(parentdir) + os.path.sep

    if os.path.abspath(cwd) == "/":
        parentdir = ""

    try:
        folders = os.listdir(cwd)
    except Exception:
        folders = []

    files = []

    for f in folders:
        try:
            f = f.decode(sys.getfilesystemencoding())
            data = {'name': f, 'fullpath': os.path.join(cwd, f)}
            data['sort'] = data['fullpath'].lower()
            data['modified'] = datetime.datetime.fromtimestamp(
                int(os.path.getmtime(os.path.join(cwd, f))))
            data['ext'] = os.path.splitext(f)[1]
        except Exception:
            continue

        data['type'] = 'dir' if os.path.isdir(os.path.join(cwd, f)) else 'file'

        if os.path.isfile(os.path.join(cwd, f)):
            data['size'] = os.path.getsize(os.path.join(cwd, f))

            power = 0
            while (data['size'] / 1024) > 0.3:
                power += 1
                data['size'] /= 1024.
            units = ('', 'K', 'M', 'G', 'T')
            data['unit'] = units[power] + 'Byte'
        else:
            data['size'] = ''

        files.append(data)

    files = sorted(files, key=operator.itemgetter('type', 'sort'))

    return render_to_response(
        'pathchooser.html', {
            'cwd': cwd,
            'files': files,
            'parentdir': parentdir,
            'type': type,
            'oldfile': oldfile,
            'absolute': abs
        }, [])
コード例 #22
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def collector():
    queue = PYLOAD.getCollector()

    queue.sort(key=operator.attrgetter("order"))

    return render_to_response('queue.html', {'content': queue, 'target': 0}, [pre_processor])
コード例 #23
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def logs(item=-1):
    s = bottle.request.environ.get('beaker.session')

    perpage = s.get('perpage', 34)
    reversed = s.get('reversed', False)

    warning = ""
    conf = PYLOAD.getConfigValue("log", "file_log")
    if not conf:
        warning = "Warning: File log is disabled, see settings page."

    perpage_p = ((20, 20), (50, 50), (100, 100), (250, 250), (0, 'all'))
    fro = None

    if bottle.request.environ.get('REQUEST_METHOD', "GET") == "POST":
        try:
            fro = datetime.datetime.strptime(bottle.request.forms['from'],
                                             '%d.%m.%Y %H:%M:%S')
        except Exception:
            pass
        try:
            perpage = int(bottle.request.forms['perpage'])
            s['perpage'] = perpage

            reversed = bool(bottle.request.forms.get('reversed', False))
            s['reversed'] = reversed
        except Exception:
            pass

        s.save()

    try:
        item = int(item)
    except Exception:
        pass

    log = PYLOAD.getLog()
    if not perpage:
        item = 1

    if item < 1 or type(item) is not int:
        item = 1 if len(log) - perpage + 1 < 1 else len(log) - perpage + 1

    if type(fro) is datetime.datetime:  #: we will search for datetime.datetime
        item = -1

    data = []
    counter = 0
    perpagecheck = 0
    for l in log:
        counter += 1

        if counter >= item:
            try:
                date, time, level, message = l.decode("utf8",
                                                      "ignore").split(" ", 3)
                dtime = datetime.datetime.strptime(date + ' ' + time,
                                                   '%Y-%m-%d %H:%M:%S')
            except Exception:
                dtime = None
                date = '?'
                time = ' '
                level = '?'
                message = l

            if item == -1 and dtime is not None and fro <= dtime:
                item = counter  #: found our datetime.datetime

            if item >= 0:
                data.append({
                    'line': counter,
                    'date': date + " " + time,
                    'level': level,
                    'message': message
                })
                perpagecheck += 1
                if fro is None and dtime is not None:  #: if fro not set set it to first showed line
                    fro = dtime

            if perpagecheck >= perpage > 0:
                break

    if fro is None:  #: still not set, empty log?
        fro = datetime.datetime.now()
    if reversed:
        data.reverse()
    return render_to_response(
        'logs.html', {
            'warning': warning,
            'log': data,
            'from': fro.strftime('%d.%m.%Y %H:%M:%S'),
            'reversed': reversed,
            'perpage': perpage,
            'perpage_p': sorted(perpage_p),
            'iprev': 1 if item - perpage < 1 else item - perpage,
            'inext': (item + perpage) if item + perpage < len(log) else item,
            'color_console': PYLOAD.getConfigValue("log", "color_console")
        }, [pre_processor])
コード例 #24
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def logout():
    s = bottle.request.environ.get('beaker.session')
    s.delete()
    return render_to_response("logout.html", proc=[pre_processor])
コード例 #25
0
ファイル: app.py プロジェクト: Burnout5151/pyload
def login():
    if not PYLOAD and SETUP:
        bottle.redirect("/setup")
    else:
        return render_to_response("login.html", proc=[pre_processor])
コード例 #26
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def base(messages):
    return render_to_response('base.html', {'messages': messages},
                              [pre_processor])