コード例 #1
0
    def conf_basic(self):
        print ""
        print _("## Basic Setup ##")

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

        from pyload.database import DatabaseBackend

        db = DatabaseBackend(None)
        db.setup()
        username = self.ask(_("Username"), "User")
        password = self.ask("", "", password=True)
        db.addUser(username, password)
        db.shutdown()

        print ""
        langs = self.config.getMetaData("general", "language")
        self.config["general"]["language"] = self.ask(_("Language"), "en",
                                                      langs.type.split(";"))

        self.config["general"]["download_folder"] = self.ask(
            _("Download folder"), "Downloads")
        self.config["download"]["max_downloads"] = self.ask(
            _("Max parallel downloads"), "3")

        reconnect = self.ask(_("Use Reconnect?"), self.no, bool=True)
        self.config["reconnect"]["activated"] = reconnect
        if reconnect:
            self.config["reconnect"]["method"] = self.ask(
                _("Reconnect script location"), "./reconnect.sh")
コード例 #2
0
ファイル: Setup.py プロジェクト: PaddyPat/pyload
    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()
コード例 #3
0
    def setUpClass(cls):
        c = Core()
        # db needs seperate initialisation
        cls.db = c.db = DatabaseBackend(c)
        cls.db.setup()
        cls.db.purgeAll()

        cls.m = cls.db.manager = FileManager(c)
コード例 #4
0
ファイル: Setup.py プロジェクト: chkorn/pyload
    def conf_basic(self):
        print ""
        print _("## Basic Setup ##")

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

        from pyload.database import DatabaseBackend

        db = DatabaseBackend(None)
        db.setup()
        username = self.ask(_("Username"), "User")
        password = self.ask("", "", password=True)
        db.addUser(username, password)
        db.shutdown()

        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["remote"]["activated"] = self.ask(_("Enable remote access"), self.yes, bool=True)

        print ""
        langs = self.config.getMetaData("general", "language")
        self.config["general"]["language"] = self.ask(_("Language"), "en", langs.type.split(";"))

        self.config["general"]["download_folder"] = self.ask(_("Download folder"), "Downloads")
        self.config["download"]["max_downloads"] = self.ask(_("Max parallel downloads"), "3")
        #print _("You should disable checksum proofing, if you have low hardware requirements.")
        #self.config["general"]["checksum"] = self.ask(_("Proof checksum?"), "y", bool=True)

        reconnect = self.ask(_("Use Reconnect?"), self.no, bool=True)
        self.config["reconnect"]["activated"] = reconnect
        if reconnect:
            self.config["reconnect"]["method"] = self.ask(_("Reconnect script location"), "./reconnect.sh")
コード例 #5
0
ファイル: Setup.py プロジェクト: ASCIIteapot/pyload
    def conf_basic(self):
        print ""
        print _("## Basic Setup ##")

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

        from pyload.database import DatabaseBackend

        db = DatabaseBackend(None)
        db.setup()
        username = self.ask(_("Username"), "User")
        password = self.ask("", "", password=True)
        db.addUser(username, password)
        db.shutdown()

        print ""
        langs = self.config.getMetaData("general", "language")
        self.config["general"]["language"] = self.ask(_("Language"), "en", langs.type.split(";"))

        self.config["general"]["download_folder"] = self.ask(_("Download folder"), "Downloads")
        self.config["download"]["max_downloads"] = self.ask(_("Max parallel downloads"), "3")

        reconnect = self.ask(_("Use Reconnect?"), self.no, bool=True)
        self.config["reconnect"]["activated"] = reconnect
        if reconnect:
            self.config["reconnect"]["method"] = self.ask(_("Reconnect script location"), "./reconnect.sh")
コード例 #6
0
    def setUpClass(cls):
        cls.pids = [-1]
        cls.fids = []

        cls.db = DatabaseBackend(Core())
        cls.db.manager = cls.db.core

        cls.db.setup()
        cls.db.purgeAll()
コード例 #7
0
 def setUpClass(cls):
     cls.core = Core()
     cls.db = DatabaseBackend(cls.core)
     cls.core.db = cls.db
     cls.db.manager = cls.core
     cls.db.manager.statusMsg = defaultdict(lambda: "statusmsg")
     cls.parser = ConfigParser()
     cls.config = ConfigManager(cls.core, cls.parser)
     cls.db.setup()
コード例 #8
0
ファイル: Setup.py プロジェクト: PaddyPat/pyload
    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"))
コード例 #9
0
    def conf_basic(self):
        print ""
        print _("## Basic Setup ##")

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

        from pyload.database import DatabaseBackend

        db = DatabaseBackend(None)
        db.setup()
        username = self.ask(_("Username"), "User")
        password = self.ask("", "", password=True)
        db.addUser(username, password)
        db.shutdown()

        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["remote"]["activated"] = self.ask(
            _("Enable remote access"), self.yes, bool=True)

        print ""
        langs = self.config.getMetaData("general", "language")
        self.config["general"]["language"] = self.ask(_("Language"), "en",
                                                      langs.type.split(";"))

        self.config["general"]["download_folder"] = self.ask(
            _("Downloadfolder"), "Downloads")
        self.config["download"]["max_downloads"] = self.ask(
            _("Max parallel downloads"), "3")
        #print _("You should disable checksum proofing, if you have low hardware requirements.")
        #self.config["general"]["checksum"] = self.ask(_("Proof checksum?"), "y", bool=True)

        reconnect = self.ask(_("Use Reconnect?"), self.no, bool=True)
        self.config["reconnect"]["activated"] = reconnect
        if reconnect:
            self.config["reconnect"]["method"] = self.ask(
                _("Reconnect script location"), "./reconnect.sh")
コード例 #10
0
ファイル: Setup.py プロジェクト: PaddyPat/pyload
    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"))
コード例 #11
0
    def openDB(self):
        from pyload.database import DatabaseBackend

        if self.db is None:
            self.db = DatabaseBackend(None)
            self.db.setup()
コード例 #12
0
ファイル: Setup.py プロジェクト: ASCIIteapot/pyload
class Setup():
    """
    pyLoads initial setup configuration assistant
    """

    @staticmethod
    def check_system():
        return get_system_info()


    @staticmethod
    def check_deps():
        result = {
            "core": [],
            "opt": []
        }

        for d in deps:
            avail, v = d.check()
            check = {
                "name": d.name,
                "avail": avail,
                "v": v
            }
            if d.optional:
                result["opt"].append(check)
            else:
                result["core"].append(check)

        return result


    def __init__(self, path, config):
        self.path = path
        self.config = config
        self.stdin_encoding = get_console_encoding(sys.stdin.encoding)
        self.lang = None
        self.db = None

        # We will create a timestamp so that the setup will be completed in a specific interval
        self.timestamp = time()

        # TODO: probably unneeded
        self.yes = "yes"
        self.no = "no"

    def start(self):
        import __builtin__
        # set the gettext translation
        __builtin__._ = lambda x: x

        web = WebServer(pysetup=self)
        web.start()

        error = web.check_error()

        # TODO: start cli in this case
        if error: #todo errno 44 port already in use
            print error

        url = "http://%s:%d/" % (socket.gethostbyname(socket.gethostname()), web.port)

        print "Setup is running at %s" % url

        opened = webbrowser.open_new_tab(url)
        if not opened:
            print "Please point your browser to the url above."

        cli = self.ask("Use commandline for configuration instead?", self.no, bool=True)
        if cli:
            print "Not implemented yet!"
            print "Use web configuration or config files"

        raw_input()

        return True


    def start_cli(self):

        self.ask_lang()

        print _("Welcome to the pyLoad Configuration Assistent.")
        print _("It will check your system and make a basic setup in order to run pyLoad.")
        print ""
        print _("The value in brackets [] always is the default value,")
        print _("in case you don't want to change it or you are unsure what to choose, just hit enter.")
        print _(
            "Don't forget: You can always rerun this assistent with --setup or -s parameter, when you start pyLoadCore.")
        print _("If you have any problems with this assistent hit CTRL+C,")
        print _("to abort and don't let him start with pyLoadCore automatically anymore.")
        print ""
        print _("When you are ready for system check, hit enter.")
        raw_input()


        # TODO: new system check + deps

        con = self.ask(_("Continue with setup?"), self.yes, bool=True)

        if not con:
            return False

        print ""
        print _("Do you want to change the config path? Current is %s") % abspath("")
        print _(
            "If you use pyLoad on a server or the home partition lives on an internal flash it may be a good idea to change it.")
        path = self.ask(_("Change config path?"), self.no, bool=True)
        if path:
            self.conf_path()
            #calls exit when changed

        print ""
        print _("Do you want to configure login data and basic settings?")
        print _("This is recommend for first run.")
        con = self.ask(_("Make basic setup?"), self.yes, bool=True)

        if con:
            self.conf_basic()

        if ssl:
            print ""
            print _("Do you want to configure ssl?")
            ssl = self.ask(_("Configure ssl?"), self.no, bool=True)
            if ssl:
                self.conf_ssl()

        print ""
        print _("Do you want to configure webinterface?")
        web = self.ask(_("Configure webinterface?"), self.yes, bool=True)
        if web:
            self.conf_web()

        print ""
        print _("Setup finished successfully.")
        print _("Hit enter to exit and restart pyLoad")
        raw_input()
        return True


    def conf_basic(self):
        print ""
        print _("## Basic Setup ##")

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

        from pyload.database import DatabaseBackend

        db = DatabaseBackend(None)
        db.setup()
        username = self.ask(_("Username"), "User")
        password = self.ask("", "", password=True)
        db.addUser(username, password)
        db.shutdown()

        print ""
        langs = self.config.getMetaData("general", "language")
        self.config["general"]["language"] = self.ask(_("Language"), "en", langs.type.split(";"))

        self.config["general"]["download_folder"] = self.ask(_("Download folder"), "Downloads")
        self.config["download"]["max_downloads"] = self.ask(_("Max parallel downloads"), "3")

        reconnect = self.ask(_("Use Reconnect?"), self.no, bool=True)
        self.config["reconnect"]["activated"] = reconnect
        if reconnect:
            self.config["reconnect"]["method"] = self.ask(_("Reconnect script location"), "./reconnect.sh")


    def conf_web(self):
        print ""
        print _("## Webinterface Setup ##")

        print ""
        self.config["webinterface"]["activated"] = self.ask(_("Activate webinterface?"), self.yes, bool=True)
        print ""
        print _("Listen address, if you use 127.0.0.1 or localhost, the webinterface will only accessible locally.")
        self.config["webinterface"]["host"] = self.ask(_("Address"), "0.0.0.0")
        self.config["webinterface"]["port"] = self.ask(_("Port"), "8000")
        print ""
        print _("pyLoad offers several server backends, now following a short explanation.")
        print "threaded:", _("Default server, this server offers SSL and is a good alternative to builtin.")
        print "fastcgi:", _(
            "Can be used by apache, lighttpd, requires you to configure them, which is not too easy job.")
        print "lightweight:", _("Very fast alternative written in C, requires libev and linux knowledge.")
        print "\t", _("Get it from here: https://github.com/jonashaag/bjoern, compile it")
        print "\t", _("and copy bjoern.so to pyload/lib")

        print
        print _(
            "Attention: In some rare cases the builtin server is not working, if you notice problems with the webinterface")
        print _("come back here and change the builtin server to the threaded one here.")

        self.config["webinterface"]["server"] = self.ask(_("Server"), "threaded",
            ["builtin", "threaded", "fastcgi", "lightweight"])

    def conf_ssl(self):
        print ""
        print _("## SSL Setup ##")
        print ""
        print _("Execute these commands from pyLoad config folder to make ssl certificates:")
        print ""
        print "openssl genrsa -out ssl.key 1024"
        print "openssl req -new -key ssl.key -out ssl.csr"
        print "openssl req -days 36500 -x509 -key ssl.key -in ssl.csr > ssl.crt "
        print ""
        print _("If you're done and everything went fine, you can activate ssl now.")
        self.config["ssl"]["activated"] = self.ask(_("Activate SSL?"), self.yes, bool=True)

    def set_user(self):
        translation = gettext.translation("setup", join(self.path, "locale"),
            languages=[self.config["general"]["language"], "en"], fallback=True)
        translation.install(True)

        self.openDB()

        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)
                    admin = self.ask("Admin?", self.yes, bool=True)

                    self.db.addUser(username, password, Role.Admin if admin else Role.User, int('1111111', 2))
                elif action == "2":
                    print ""
                    print _("Users")
                    print "-----"
                    users = self.db.getAllUserData()
                    for user in users.itervalues():
                        print user.name
                    print "-----"
                    print ""
                elif action == "3":
                    print ""
                    username = self.ask(_("Username"), "")
                    if username:
                        self.db.removeUserByName(username)
                elif action == "4":
                    self.db.syncSave()
                    break
        finally:
            self.closeDB()

    def addUser(self, username, password, role=Role.Admin):
        self.openDB()
        try:
            self.db.addUser(username, password, role, int('1111111', 2))
        finally:
            self.closeDB()

    def openDB(self):
        from pyload.database import DatabaseBackend

        if self.db is None:
            self.db = DatabaseBackend(None)
            self.db.setup()

    def closeDB(self):
        if self.db is not None:
            self.db.syncSave()
            self.db.shutdown()

    def save(self):
        self.config.save()
        self.closeDB()

    def conf_path(self, trans=False):
        if trans:
            translation = gettext.translation("setup", join(self.path, "locale"),
                languages=[self.config["general"]["language"], "en"], fallback=True)
            translation.install(True)

        print _("Setting new configpath, current configuration will not be transferred!")
        path = self.ask(_("Config path"), abspath(""))
        try:
            path = join(pypath, path)
            if not exists(path):
                makedirs(path)
            f = open(join(pypath, "pyload", "config", "configdir"), "wb")
            f.write(path)
            f.close()
            print _("Config path changed, setup will now close, please restart to go on.")
            print _("Press Enter to exit.")
            raw_input()
            exit()
        except Exception, e:
            print _("Setting config path failed: %s") % str(e)
コード例 #13
0
ファイル: Setup.py プロジェクト: ASCIIteapot/pyload
    def openDB(self):
        from pyload.database import DatabaseBackend

        if self.db is None:
            self.db = DatabaseBackend(None)
            self.db.setup()
コード例 #14
0
ファイル: AccountDatabase.py プロジェクト: neubi4/pyload
# -*- coding: utf-8 -*-

from pyload.database import queue, async
from pyload.database import DatabaseBackend


class AccountMethods:
    @queue
    def loadAccounts(db):
        db.c.execute("SELECT plugin, loginname, activated, password, options FROM accounts;")
        return db.c.fetchall()

    @async
    def saveAccounts(db, data):
        # TODO: owner, shared

        db.c.executemany(
            "INSERT INTO accounts(plugin, loginname, activated, password, options) VALUES(?,?,?,?,?)", data
        )

    @async
    def removeAccount(db, plugin, loginname):
        db.c.execute("DELETE FROM accounts WHERE plugin=? AND loginname=?", (plugin, loginname))


DatabaseBackend.registerSub(AccountMethods)
コード例 #15
0
ファイル: File.py プロジェクト: torrero007/pyload
        """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)
コード例 #16
0
ファイル: StorageDatabase.py プロジェクト: ASCIIteapot/pyload
from pyload.database import DatabaseBackend, queue

class StorageMethods():
    @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))
    
    @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, ))
            d = {}
            for row in db.c:
                d[row[0]] = row[1]
            return d
    
    @queue
    def delStorage(db, identifier, key):
        db.c.execute("DELETE FROM storage WHERE identifier=? AND key=?", (identifier, key))

DatabaseBackend.registerSub(StorageMethods)
コード例 #17
0
class Setup():
    """
    pyLoads initial setup configuration assistant
    """
    @staticmethod
    def check_system():
        return get_system_info()

    @staticmethod
    def check_deps():
        result = {"core": [], "opt": []}

        for d in deps:
            avail, v = d.check()
            check = {"name": d.name, "avail": avail, "v": v}
            if d.optional:
                result["opt"].append(check)
            else:
                result["core"].append(check)

        return result

    def __init__(self, path, config):
        self.path = path
        self.config = config
        self.stdin_encoding = get_console_encoding(sys.stdin.encoding)
        self.lang = None
        self.db = None

        # We will create a timestamp so that the setup will be completed in a specific interval
        self.timestamp = time()

        # TODO: probably unneeded
        self.yes = "yes"
        self.no = "no"

    def start(self):
        import __builtin__
        # set the gettext translation
        __builtin__._ = lambda x: x

        web = WebServer(pysetup=self)
        web.start()

        error = web.check_error()

        # TODO: start cli in this case
        if error:  #todo errno 44 port already in use
            print error

        url = "http://%s:%d/" % (socket.gethostbyname(
            socket.gethostname()), web.port)

        print "Setup is running at %s" % url

        opened = webbrowser.open_new_tab(url)
        if not opened:
            print "Please point your browser to the url above."

        cli = self.ask("Use commandline for configuration instead?",
                       self.no,
                       bool=True)
        if cli:
            print "Not implemented yet!"
            print "Use web configuration or config files"

        raw_input()

        return True

    def start_cli(self):

        self.ask_lang()

        print _("Welcome to the pyLoad Configuration Assistent.")
        print _(
            "It will check your system and make a basic setup in order to run pyLoad."
        )
        print ""
        print _("The value in brackets [] always is the default value,")
        print _(
            "in case you don't want to change it or you are unsure what to choose, just hit enter."
        )
        print _(
            "Don't forget: You can always rerun this assistent with --setup or -s parameter, when you start pyLoadCore."
        )
        print _("If you have any problems with this assistent hit CTRL+C,")
        print _(
            "to abort and don't let him start with pyLoadCore automatically anymore."
        )
        print ""
        print _("When you are ready for system check, hit enter.")
        raw_input()

        # TODO: new system check + deps

        con = self.ask(_("Continue with setup?"), self.yes, bool=True)

        if not con:
            return False

        print ""
        print _("Do you want to change the config path? Current is %s"
                ) % abspath("")
        print _(
            "If you use pyLoad on a server or the home partition lives on an internal flash it may be a good idea to change it."
        )
        path = self.ask(_("Change config path?"), self.no, bool=True)
        if path:
            self.conf_path()
            #calls exit when changed

        print ""
        print _("Do you want to configure login data and basic settings?")
        print _("This is recommend for first run.")
        con = self.ask(_("Make basic setup?"), self.yes, bool=True)

        if con:
            self.conf_basic()

        if ssl:
            print ""
            print _("Do you want to configure ssl?")
            ssl = self.ask(_("Configure ssl?"), self.no, bool=True)
            if ssl:
                self.conf_ssl()

        print ""
        print _("Do you want to configure webinterface?")
        web = self.ask(_("Configure webinterface?"), self.yes, bool=True)
        if web:
            self.conf_web()

        print ""
        print _("Setup finished successfully.")
        print _("Hit enter to exit and restart pyLoad")
        raw_input()
        return True

    def conf_basic(self):
        print ""
        print _("## Basic Setup ##")

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

        from pyload.database import DatabaseBackend

        db = DatabaseBackend(None)
        db.setup()
        username = self.ask(_("Username"), "User")
        password = self.ask("", "", password=True)
        db.addUser(username, password)
        db.shutdown()

        print ""
        langs = self.config.getMetaData("general", "language")
        self.config["general"]["language"] = self.ask(_("Language"), "en",
                                                      langs.type.split(";"))

        self.config["general"]["download_folder"] = self.ask(
            _("Download folder"), "Downloads")
        self.config["download"]["max_downloads"] = self.ask(
            _("Max parallel downloads"), "3")

        reconnect = self.ask(_("Use Reconnect?"), self.no, bool=True)
        self.config["reconnect"]["activated"] = reconnect
        if reconnect:
            self.config["reconnect"]["method"] = self.ask(
                _("Reconnect script location"), "./reconnect.sh")

    def conf_web(self):
        print ""
        print _("## Webinterface Setup ##")

        print ""
        self.config["webinterface"]["activated"] = self.ask(
            _("Activate webinterface?"), self.yes, bool=True)
        print ""
        print _(
            "Listen address, if you use 127.0.0.1 or localhost, the webinterface will only accessible locally."
        )
        self.config["webinterface"]["host"] = self.ask(_("Address"), "0.0.0.0")
        self.config["webinterface"]["port"] = self.ask(_("Port"), "8000")
        print ""
        print _(
            "pyLoad offers several server backends, now following a short explanation."
        )
        print "threaded:", _(
            "Default server, this server offers SSL and is a good alternative to builtin."
        )
        print "fastcgi:", _(
            "Can be used by apache, lighttpd, requires you to configure them, which is not too easy job."
        )
        print "lightweight:", _(
            "Very fast alternative written in C, requires libev and linux knowledge."
        )
        print "\t", _(
            "Get it from here: https://github.com/jonashaag/bjoern, compile it"
        )
        print "\t", _("and copy bjoern.so to pyload/lib")

        print
        print _(
            "Attention: In some rare cases the builtin server is not working, if you notice problems with the webinterface"
        )
        print _(
            "come back here and change the builtin server to the threaded one here."
        )

        self.config["webinterface"]["server"] = self.ask(
            _("Server"), "threaded",
            ["builtin", "threaded", "fastcgi", "lightweight"])

    def conf_ssl(self):
        print ""
        print _("## SSL Setup ##")
        print ""
        print _(
            "Execute these commands from pyLoad config folder to make ssl certificates:"
        )
        print ""
        print "openssl genrsa -out ssl.key 1024"
        print "openssl req -new -key ssl.key -out ssl.csr"
        print "openssl req -days 36500 -x509 -key ssl.key -in ssl.csr > ssl.crt "
        print ""
        print _(
            "If you're done and everything went fine, you can activate ssl now."
        )
        self.config["ssl"]["activated"] = self.ask(_("Activate SSL?"),
                                                   self.yes,
                                                   bool=True)

    def set_user(self):
        gettext.setpaths(
            [join(os.sep, "usr", "share", "pyload", "locale"), None])
        translation = gettext.translation(
            "setup",
            join(self.path, "locale"),
            languages=[self.config["general"]["language"], "en"],
            fallback=True)
        translation.install(True)

        self.openDB()

        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)
                    self.db.addUser(username, password)
                elif action == "2":
                    print ""
                    print _("Users")
                    print "-----"
                    users = self.db.getAllUserData()
                    for user in users.itervalues():
                        print user.name
                    print "-----"
                    print ""
                elif action == "3":
                    print ""
                    username = self.ask(_("Username"), "")
                    if username:
                        self.db.removeUserByName(username)
                elif action == "4":
                    self.db.syncSave()
                    break
        finally:
            self.closeDB()

    def addUser(self, username, password):
        self.openDB()
        try:
            self.db.addUser(username, password)
        finally:
            self.closeDB()

    def openDB(self):
        from pyload.database import DatabaseBackend

        if self.db is None:
            self.db = DatabaseBackend(None)
            self.db.setup()

    def closeDB(self):
        if self.db is not None:
            self.db.syncSave()
            self.db.shutdown()

    def save(self):
        self.config.save()
        self.closeDB()

    def conf_path(self, trans=False):
        if trans:
            gettext.setpaths(
                [join(os.sep, "usr", "share", "pyload", "locale"), None])
            translation = gettext.translation(
                "setup",
                join(self.path, "locale"),
                languages=[self.config["general"]["language"], "en"],
                fallback=True)
            translation.install(True)

        print _(
            "Setting new configpath, current configuration will not be transferred!"
        )
        path = self.ask(_("Config path"), abspath(""))
        try:
            path = join(pypath, path)
            if not exists(path):
                makedirs(path)
            f = open(join(pypath, "pyload", "config", "configdir"), "wb")
            f.write(path)
            f.close()
            print _(
                "Config path changed, setup will now close, please restart to go on."
            )
            print _("Press Enter to exit.")
            raw_input()
            exit()
        except Exception, e:
            print _("Setting config path failed: %s") % str(e)
コード例 #18
0
ファイル: AccountDatabase.py プロジェクト: Kagenoshin/pyload
# -*- coding: utf-8 -*-

from pyload.database import queue, async
from pyload.database import DatabaseBackend


class AccountMethods:
    @queue
    def loadAccounts(db):
        db.c.execute(
            'SELECT plugin, loginname, activated, password, options FROM accounts;'
        )
        return db.c.fetchall()

    @async
    def saveAccounts(db, data):
        # TODO: owner, shared

        db.c.executemany(
            'INSERT INTO accounts(plugin, loginname, activated, password, options) VALUES(?,?,?,?,?)',
            data)

    @async
    def removeAccount(db, plugin, loginname):
        db.c.execute('DELETE FROM accounts WHERE plugin=? AND loginname=?',
                     (plugin, loginname))


DatabaseBackend.registerSub(AccountMethods)
コード例 #19
0
 def setUpClass(cls):
     cls.core = Core()
     cls.db = DatabaseBackend(cls.core)
     cls.core.db = cls.db
     cls.db.setup()
コード例 #20
0
    @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 {
            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)
コード例 #21
0
ファイル: Setup.py プロジェクト: chkorn/pyload
    def set_user(self):
        gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None])
        translation = gettext.translation("setup", join(self.path, "locale"),
            languages=[self.config["general"]["language"], "en"], fallback=True)
        translation.install(True)

        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.getAllUserData()
                    noaction = False
                    for user in users.itervalues():
                        print user.name
                    print "-----"
                    print ""
                elif action == "3":
                    print ""
                    username = self.ask(_("Username"), "")
                    if username:
                        db.removeUserByName(username)
                        noaction = False
                elif action == "4":
                    db.syncSave()
                    break
        finally:
            if not noaction:
                db.shutdown()
コード例 #22
0
ファイル: StorageDatabase.py プロジェクト: zaratozom/pyload
                (value, identifier, key))
        else:
            db.c.execute(
                "INSERT INTO storage (identifier, key, value) VALUES (?, ?, ?)",
                (identifier, key, value))

    @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, ))
            d = {}
            for row in db.c:
                d[row[0]] = row[1]
            return d

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


DatabaseBackend.registerSub(StorageMethods)
コード例 #23
0
ファイル: User.py プロジェクト: achimschneider/pyload
    @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')
        users = []
        for row in db.c:
            users.append(row[0])
        return users


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

        return user


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

DatabaseBackend.registerSub(UserMethods)
コード例 #24
0
    def set_user(self):
        gettext.setpaths(
            [join(os.sep, "usr", "share", "pyload", "locale"), None])
        translation = gettext.translation(
            "setup",
            join(self.path, "locale"),
            languages=[self.config["general"]["language"], "en"],
            fallback=True)
        translation.install(True)

        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.getAllUserData()
                    noaction = False
                    for user in users.itervalues():
                        print user.name
                    print "-----"
                    print ""
                elif action == "3":
                    print ""
                    username = self.ask(_("Username"), "")
                    if username:
                        db.removeUser(username)
                        noaction = False
                elif action == "4":
                    db.syncSave()
                    break
        finally:
            if not noaction:
                db.shutdown()
コード例 #25
0
ファイル: Setup.py プロジェクト: PaddyPat/pyload
    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()