Example #1
0
    def set_user(self):
        load_translation("setup", self.config.get("general", "language"))

        from pyload.Database import DatabaseBackend

        db = DatabaseBackend(None)
        db.setup()

        noaction = True
        try:
            while True:
                print _("Select action")
                print _("1 - Create/Edit user")
                print _("2 - List users")
                print _("3 - Remove user")
                print _("4 - Quit")
                action = raw_input("1/2/3/4: ")
                if not action in ("1", "2", "3", "4"):
                    continue
                elif action == "1":
                    print
                    username = self.ask(_("Username"), "User")
                    password = self.ask("", "", password=True)
                    db.addUser(username, password)
                    noaction = False
                elif action == "2":
                    print
                    print _("Users")
                    print "-----"
                    users = db.listUsers()
                    noaction = False
                    for user in users:
                        print user
                    print "-----"
                    print
                elif action == "3":
                    print
                    username = self.ask(_("Username"), "")
                    if username:
                        db.removeUser(username)
                        noaction = False
                elif action == "4":
                    break
        finally:
            if not noaction:
                db.shutdown()
Example #2
0
    def conf_basic(self):
        print _("## Basic Setup ##")

        print
        print _("The following logindata is valid for CLI and webinterface.")

        from pyload.Database import DatabaseBackend

        db = DatabaseBackend(None)
        db.setup()
        print _(
            "NOTE: Consider a password of 10 or more symbols if you expect to access to your local network from outside (ex. internet)."
        )
        print
        username = self.ask(_("Username"), "User")
        password = self.ask("", "", password=True)
        db.addUser(username, password)
        db.shutdown()

        print
        print
        print _(
            "External clients (GUI, CLI or other) need remote access to work over the network."
        )
        print _(
            "However, if you only want to use the webinterface you may disable it to save ram."
        )
        self.config.set(
            "remote", "activated",
            self.ask(_("Enable remote access"), self.no, bool=True))

        print
        langs = sorted(
            self.config.getMetaData("general", "language")['type'].split(";"))
        self.config.set(
            "general", "language",
            self.ask(_("Choose system language"), self.lang, langs))

        print
        self.config.set("general", "download_folder",
                        self.ask(_("Download folder"), "Downloads"))
        print
        self.config.set("download", "max_downloads",
                        self.ask(_("Max parallel downloads"), "3"))
        print
        reconnect = self.ask(_("Use Reconnect?"), self.no, bool=True)
        self.config.set("reconnect", "activated", reconnect)
        if reconnect:
            self.config.set(
                "reconnect", "method",
                self.ask(_("Reconnect script location"), "./reconnect.sh"))
Example #3
0
    def conf_basic(self):
        print _("## Basic Setup ##")

        print
        print _("The following logindata is valid for CLI and webinterface.")

        from pyload.Database import DatabaseBackend

        db = DatabaseBackend(None)
        db.setup()
        print _("NOTE: Consider a password of 10 or more symbols if you expect to access to your local network from outside (ex. internet).")
        print
        username = self.ask(_("Username"), "User")
        password = self.ask("", "", password=True)
        db.addUser(username, password)
        db.shutdown()

        print
        print
        print _("External clients (GUI, CLI or other) need remote access to work over the network.")
        print _("However, if you only want to use the webinterface you may disable it to save ram.")
        self.config.set("remote", "activated", self.ask(_("Enable remote access"), self.no, bool=True))

        print
        langs = sorted(self.config.getMetaData("general", "language")['type'].split(";"))
        self.config.set("general", "language", self.ask(_("Choose system language"), self.lang, langs))

        print
        self.config.set("general", "download_folder", self.ask(_("Download folder"), "Downloads"))
        print
        self.config.set("download", "max_downloads", self.ask(_("Max parallel downloads"), "3"))
        print
        reconnect = self.ask(_("Use Reconnect?"), self.no, bool=True)
        self.config.set("reconnect", "activated", reconnect)
        if reconnect:
            self.config.set("reconnect", "method", self.ask(_("Reconnect script location"), "./reconnect.sh"))
Example #4
0
        """return list of max length 3 ids with pyfiles in package not finished or processed"""

        self.c.execute("SELECT id FROM links WHERE package=? AND status NOT IN (0, 4, 13) LIMIT 3", (str(pid),))
        return [r[0] for r in self.c]

    @style.queue
    def deleteFinished(self):
        self.c.execute("DELETE FROM links WHERE status IN (0, 4)")
        self.c.execute("DELETE FROM packages WHERE NOT EXISTS(SELECT 1 FROM links WHERE packages.id=links.package)")

    @style.queue
    def restartFailed(self):
        self.c.execute("UPDATE links SET status=3, error='' WHERE status IN (6, 8, 9)")

    @style.queue
    def findDuplicates(self, id, folder, filename):
        """ checks if filename exists with different id and same package """
        self.c.execute(
            "SELECT l.plugin FROM links as l INNER JOIN packages as p ON l.package=p.id AND p.folder=? WHERE l.id!=? AND l.status=0 AND l.name=?",
            (folder, id, filename),
        )
        return self.c.fetchone()

    @style.queue
    def purgeLinks(self):
        self.c.execute("DELETE FROM links;")
        self.c.execute("DELETE FROM packages;")


DatabaseBackend.registerSub(FileMethods)
Example #5
0

    @style.async
    def setPermission(db, user, perms):
        db.c.execute("UPDATE users SET permission=? WHERE name=?", (perms, user))


    @style.async
    def setRole(db, user, role):
        db.c.execute("UPDATE users SET role=? WHERE name=?", (role, user))


    @style.queue
    def listUsers(db):
        db.c.execute('SELECT name FROM users')
        return [row[0] for row in db.c]


    @style.queue
    def getAllUserData(db):
        db.c.execute("SELECT name, permission, role, template, email FROM users")
        return dict((r[0], {"permission": r[1], "role": r[2], "template": r[3], "email": r[4]}) for r in db.c)


    @style.queue
    def removeUser(db, user):
        db.c.execute('DELETE FROM users WHERE name=?', (user,))


DatabaseBackend.registerSub(UserMethods)
Example #6
0
    def setPermission(db, user, perms):
        db.c.execute("UPDATE users SET permission=? WHERE name=?",
                     (perms, user))

    @style. async
    def setRole(db, user, role):
        db.c.execute("UPDATE users SET role=? WHERE name=?", (role, user))

    @style.queue
    def listUsers(db):
        db.c.execute('SELECT name FROM users')
        return [row[0] for row in db.c]

    @style.queue
    def getAllUserData(db):
        db.c.execute(
            "SELECT name, permission, role, template, email FROM users")
        return dict((r[0], {
            "permission": r[1],
            "role": r[2],
            "template": r[3],
            "email": r[4]
        }) for r in db.c)

    @style.queue
    def removeUser(db, user):
        db.c.execute('DELETE FROM users WHERE name=?', (user, ))


DatabaseBackend.registerSub(UserMethods)
Example #7
0
class StorageMethods(object):

    @style.queue
    def setStorage(db, identifier, key, value):
        db.c.execute("SELECT id FROM storage WHERE identifier=? AND key=?", (identifier, key))
        if db.c.fetchone() is not None:
            db.c.execute("UPDATE storage SET value=? WHERE identifier=? AND key=?", (value, identifier, key))
        else:
            db.c.execute("INSERT INTO storage (identifier, key, value) VALUES (?, ?, ?)", (identifier, key, value))


    @style.queue
    def getStorage(db, identifier, key=None):
        if key is not None:
            db.c.execute("SELECT value FROM storage WHERE identifier=? AND key=?", (identifier, key))
            row = db.c.fetchone()
            if row is not None:
                return row[0]
        else:
            db.c.execute("SELECT key, value FROM storage WHERE identifier=?", (identifier,))
            return dict((row[0], row[1]) for row in db.c)


    @style.queue
    def delStorage(db, identifier, key):
        db.c.execute("DELETE FROM storage WHERE identifier=? AND key=?", (identifier, key))


DatabaseBackend.registerSub(StorageMethods)
Example #8
0
        if db.c.fetchone() is not None:
            db.c.execute(
                "UPDATE storage SET value=? WHERE identifier=? AND key=?",
                (value, identifier, key))
        else:
            db.c.execute(
                "INSERT INTO storage (identifier, key, value) VALUES (?, ?, ?)",
                (identifier, key, value))

    @style.queue
    def getStorage(db, identifier, key=None):
        if key is not None:
            db.c.execute(
                "SELECT value FROM storage WHERE identifier=? AND key=?",
                (identifier, key))
            row = db.c.fetchone()
            if row is not None:
                return row[0]
        else:
            db.c.execute("SELECT key, value FROM storage WHERE identifier=?",
                         (identifier, ))
            return dict((row[0], row[1]) for row in db.c)

    @style.queue
    def delStorage(db, identifier, key):
        db.c.execute("DELETE FROM storage WHERE identifier=? AND key=?",
                     (identifier, key))


DatabaseBackend.registerSub(StorageMethods)
Example #9
0
    def set_user(self):
        load_translation("setup", self.config.get("general", "language"))

        from pyload.Database import DatabaseBackend

        db = DatabaseBackend(None)
        db.setup()

        noaction = True
        try:
            while True:
                print _("Select action")
                print _("1 - Create/Edit user")
                print _("2 - List users")
                print _("3 - Remove user")
                print _("4 - Quit")
                action = raw_input("1/2/3/4: ")
                if not action in ("1", "2", "3", "4"):
                    continue
                elif action == "1":
                    print
                    username = self.ask(_("Username"), "User")
                    password = self.ask("", "", password=True)
                    db.addUser(username, password)
                    noaction = False
                elif action == "2":
                    print
                    print _("Users")
                    print "-----"
                    users = db.listUsers()
                    noaction = False
                    for user in users:
                        print user
                    print "-----"
                    print
                elif action == "3":
                    print
                    username = self.ask(_("Username"), "")
                    if username:
                        db.removeUser(username)
                        noaction = False
                elif action == "4":
                    break
        finally:
            if not noaction:
                db.shutdown()