Example #1
0
 def __init__(self, conf=config.Config(), RT=None, aliases=None):
     self.Config = conf
     if not RT:
         self.RT = rtorrent.rtorrent(self.Config.get("rtorrent_socket"))
     else:
         self.RT = RT
     self.handler = torrentHandler.Handler()
     self.aliases = aliases
Example #2
0
    def __init__(self, conf=config.Config(), RT=None, aliases=None):
        self.C = conf
        if not RT:
            self.RT = rtorrent.rtorrent(self.C.get("rtorrent_socket"))
        else:
            self.RT = RT

        self.ALIASES = aliases
Example #3
0
 def __init__(self, conf=config.Config(), RT=None, aliases=None):
     self.Config = conf
     if not RT:
         self.RT = rtorrent.rtorrent(self.Config.get("rtorrent_socket"))
     else:
         self.RT = RT
     self.handler = torrentHandler.Handler()
     self.aliases = aliases
Example #4
0
    def __init__(self, conf=config.Config(), RT=None, aliases=None):
        self.C = conf
        if not RT:
            self.RT = rtorrent.rtorrent(self.C.get("rtorrent_socket"))
        else:
            self.RT = RT

        self.ALIASES = aliases
Example #5
0
 def __init__(self, conf=config.Config(), RT=None, Log=None, Sockets=None, Aliases=None, DLHandler=None):
     self.config = conf
     if not RT:
         self.RT = rtorrent.rtorrent(self.config.get("rtorrent_socket"))
     else:
         self.RT = RT
     self.handler = torrentHandler.Handler()
     self.login = login.Login(conf=self.config)
     self.log = Log
     self.sockets = Sockets
     self.aliases = Aliases
     self.downloadHandler = DLHandler
     self.public_commands = {
         "get_torrent_info" : Handle(self.get_torrent_info, ["torrent_id"], ["html"]),
         "get_info_multi" : Handle(self.get_info_multi, ["view"], ["sortby", "reverse", "drop_down_ids"]),
         "get_torrent_row" : Handle(self.get_torrent_row, ["torrent_id"]),
         "pause_torrent" : Handle(self.pause_torrent, ["torrent_id"]),
         "stop_torrent" : Handle(self.stop_torrent, ["torrent_id"]),
         "start_torrent" : Handle(self.start_torrent, ["torrent_id"]),
         "remove_torrent" : Handle(self.remove_torrent, ["torrent_id"]),
         "delete_torrent" : Handle(self.delete_torrent, ["torrent_id"]),
         "hash_torrent" : Handle(self.hash_torrent, ["torrent_id"]),
         "get_file" : Handle(self.get_file, ["torrent_id", "filepath"]),
         "upload_torrent_socket" : Handle(self.upload_torrent_socket, ["torrent"], ["start"]),
         "upload_torrent" : Handle(self.upload_torrent, [], ["torrent", "start"]),
         "get_feeds" : Handle(self.get_feeds),
         "start_batch" : Handle(self.start_batch, ["torrentIDs"]),
         "pause_batch" : Handle(self.pause_batch, ["torrentIDs"]),
         "stop_batch" : Handle(self.stop_batch, ["torrentIDs"]),
         "remove_batch" : Handle(self.remove_batch, ["torrentIDs"]),
         "delete_batch" : Handle(self.delete_batch, ["torrentIDs"]),
         "get_tracker_favicon" : Handle(self.get_tracker_favicon, ["torrent_id"]),
         "verify_conf_value" : Handle(self.verify_conf_value, ["key", "value"]),
         "set_config_multiple" : Handle(self.set_config_multiple, ["keys","values"]),
         "get_refresh_rate" : Handle(self.getRefreshRate),
         "move_tracker" : Handle(self.moveTracker, ["url", "target_alias"]),
         "download_file" : Handle(self.downloadGen, ["torrentID", "path"]),
     }
Example #6
0
 def __init__(self, conf=config.Config(), RT=None, Log=None, Sockets=None, Aliases=None, DLHandler=None):
     self.config = conf
     if not RT:
         self.RT = rtorrent.rtorrent(self.config.get("rtorrent_socket"))
     else:
         self.RT = RT
     self.handler = torrentHandler.Handler()
     self.login = login.Login(conf=self.config)
     self.log = Log
     self.sockets = Sockets
     self.aliases = Aliases
     self.downloadHandler = DLHandler
     self.public_commands = {
         "get_torrent_info" : Handle(self.get_torrent_info, ["torrent_id"], ["html"]),
         "get_info_multi" : Handle(self.get_info_multi, ["view"], ["sortby", "reverse", "drop_down_ids"]),
         "get_torrent_row" : Handle(self.get_torrent_row, ["torrent_id"]),
         "pause_torrent" : Handle(self.pause_torrent, ["torrent_id"]),
         "stop_torrent" : Handle(self.stop_torrent, ["torrent_id"]),
         "start_torrent" : Handle(self.start_torrent, ["torrent_id"]),
         "remove_torrent" : Handle(self.remove_torrent, ["torrent_id"]),
         "delete_torrent" : Handle(self.delete_torrent, ["torrent_id"]),
         "hash_torrent" : Handle(self.hash_torrent, ["torrent_id"]),
         "get_file" : Handle(self.get_file, ["torrent_id", "filepath"]),
         "upload_torrent_socket" : Handle(self.upload_torrent_socket, ["torrent"], ["start"]),
         "upload_torrent" : Handle(self.upload_torrent, [], ["torrent", "start"]),
         "get_feeds" : Handle(self.get_feeds),
         "start_batch" : Handle(self.start_batch, ["torrentIDs"]),
         "pause_batch" : Handle(self.pause_batch, ["torrentIDs"]),
         "stop_batch" : Handle(self.stop_batch, ["torrentIDs"]),
         "remove_batch" : Handle(self.remove_batch, ["torrentIDs"]),
         "delete_batch" : Handle(self.delete_batch, ["torrentIDs"]),
         "get_tracker_favicon" : Handle(self.get_tracker_favicon, ["torrent_id"]),
         "verify_conf_value" : Handle(self.verify_conf_value, ["key", "value"]),
         "set_config_multiple" : Handle(self.set_config_multiple, ["keys","values"]),
         "get_refresh_rate" : Handle(self.getRefreshRate),
         "move_tracker" : Handle(self.moveTracker, ["url", "target_alias"]),
         "download_file" : Handle(self.downloadGen, ["torrentID", "path"]),
     }
Example #7
0
    def main(self, c):
        signal.signal(signal.SIGTERM, self.shutdown)
        
        global_config = {
            "server.socket_host" : str(c.get("host")),
            "server.socket_port" : c.get("port"),
        }
        
        ssl_certificate = c.get("ssl_certificate")
        ssl_keyfile = c.get("ssl_private_key")
        ssl_ca_certs = c.get("ssl_ca_certs")
        if ssl_certificate and ssl_keyfile:
            ssl_options = {
                "certfile" : ssl_certificate,
                "keyfile" : ssl_keyfile,
                "ca_certs" : ssl_ca_certs,
            }
        else:
            ssl_options = None
        
        tornado.options.parse_command_line(["--logging=debug"])
    
        if os.path.exists(".user.pickle"):
            os.remove(".user.pickle")
        settings = {
            "static_path" : os.path.join(os.getcwd(), "static"),
            "gzip" : True,
        }
        application = tornado.web.Application([
            (r"/css/(.*)", tornado.web.StaticFileHandler, {"path" : os.path.join(os.getcwd(), "static/css/")}),
            (r"/javascript/(.*)", tornado.web.StaticFileHandler, {"path" : os.path.join(os.getcwd(), "static/javascript/")}),
            (r"/images/(.*)", tornado.web.StaticFileHandler, {"path" : os.path.join(os.getcwd(), "static/images/") }),
            (r"/favicons/(.*)", tornado.web.StaticFileHandler, {"path" : os.path.join(os.getcwd(), "static/favicons/") }),
            (r"/cache\.manifest", manifest),
            (r"/manifest-hack", manifesthack),
            (r"/", index),
            (r"/index", index),
            (r"/ajax", ajax),
            (r"/options", options),
            (r"/stats", stats),
            (r"/log", logHandler),
            (r"/ajaxsocket", ajaxSocket),
            (r"/filesocket", fileSocket),
            (r"/statsocket", statSocket),
            (r"/logsocket", logSocket),
            (r"/auto", autoHandler),
            (r"/autosocket", autoSocket),
            (r"/RPCSocket", RPCSocket),
            (r"/create", createHandler),
            (r"/createsocket", createSocket),
            (r"/downloadcreation", downloadCreation),
            #(r"/test", test),
        ], **settings)
    
        application._pyrtSockets = SocketStorage()
        application._pyrtLog = weblog.Logger(sockets=application._pyrtSockets)
        application._pyrtRT = rtorrent.rtorrent(c.get("rtorrent_socket"))    
        application._pyrtL = login.Login(conf=c, log=application._pyrtLog)
        application._pyrtAliasStorage = aliases.AliasStore(application._pyrtLog, application._pyrtRT)
        application._pyrtAJAX = ajaxPage.Ajax(conf=c, RT=application._pyrtRT, Log=application._pyrtLog, Sockets=application._pyrtSockets, Aliases=application._pyrtAliasStorage)
        application._pyrtOPTIONS = optionsPage.Options(conf=c, RT=application._pyrtRT, aliases=application._pyrtAliasStorage)
        application._pyrtSTATS = statsPage.Index(conf=c, RT=application._pyrtRT, aliases=application._pyrtAliasStorage)
        application._pyrtRemoteStorage = remotes.RemoteStorage(log=application._pyrtLog)
        application._pyrtGLOBALS = {
            "login" : application._pyrtL,
            "ajaxPage" : application._pyrtAJAX,
            "optionsPage" : application._pyrtOPTIONS,
            "statsPage" : application._pyrtSTATS,
            "log" : application._pyrtLog,
            "RT" : application._pyrtRT,
            "config" : c,
            "sockets" : application._pyrtSockets,
            "remoteStorage" : application._pyrtRemoteStorage,
            "aliasStorage" : application._pyrtAliasStorage,
        }
        
       
        http_server = tornado.httpserver.HTTPServer(application, ssl_options=ssl_options)
        logging.info("Starting webserver on http%s://%s:%i with PID %d", (ssl_options and "s" or ""), global_config["server.socket_host"], global_config["server.socket_port"], os.getpid())
        self._pyrtPID = os.getpid()
        
        #start listening on 10 UNIX sockets + the dedicated RSS socket
        sockets = []
        s_rss = tornado.netutil.bind_unix_socket(".sockets/rss.interface")
        logging.info("Starting UNIX websocket on .sockets/rss.interface")
        http_server.add_socket(s_rss)
        logging.info("Starting UNIX websockets")
        for i in range(10):
            s = tornado.netutil.bind_unix_socket(".sockets/rpc%i.interface" % i)
            http_server.add_socket(s)
        try:
            http_server.listen(global_config["server.socket_port"], global_config["server.socket_host"])
        except socket.error:
            logging.error("Address already in use, aborting")
            if os.path.exists("proc/pyrt.pid"):
                os.remove("proc/pyrt.pid")

            if os.path.exists(".sockets/rss.interface"):
                os.remove(".sockets/rss.interface")
            for i in range(10):
                try:
                    os.remove(".sockets/rpc%i.interface" % i)
                except:
                    pass
                
            sys.exit(0)

        logging.info("Starting RSS listener")
        application._pyrtRSS = rss.RSS(application._pyrtL, application._pyrtLog, application._pyrtRemoteStorage)
        self._pyrtRSSPID = application._pyrtRSS.start()
        
        self.instance = tornado.ioloop.IOLoop.instance()
        self.instance.start()
Example #8
0
    def main(self, c):
        signal.signal(signal.SIGTERM, self.shutdown)

        global_config = {
            "server.socket_host": str(c.get("host")),
            "server.socket_port": c.get("port"),
        }

        ssl_certificate = c.get("ssl_certificate")
        ssl_keyfile = c.get("ssl_private_key")
        ssl_ca_certs = c.get("ssl_ca_certs")
        if ssl_certificate and ssl_keyfile:
            ssl_options = {
                "certfile": ssl_certificate,
                "keyfile": ssl_keyfile,
                "ca_certs": ssl_ca_certs,
            }
        else:
            ssl_options = None

        tornado.options.parse_command_line(["--logging=debug"])

        if os.path.exists(".user.pickle"):
            os.remove(".user.pickle")
        settings = {
            "static_path": os.path.join(os.getcwd(), "static"),
            "gzip": True,
        }
        application = tornado.web.Application(
            [
                (r"/css/(.*)", tornado.web.StaticFileHandler, {
                    "path": os.path.join(os.getcwd(), "static/css/")
                }),
                (r"/javascript/(.*)", tornado.web.StaticFileHandler, {
                    "path": os.path.join(os.getcwd(), "static/javascript/")
                }),
                (r"/images/(.*)", tornado.web.StaticFileHandler, {
                    "path": os.path.join(os.getcwd(), "static/images/")
                }),
                (r"/favicons/(.*)", tornado.web.StaticFileHandler, {
                    "path": os.path.join(os.getcwd(), "static/favicons/")
                }),
                (r"/cache\.manifest", manifest),
                (r"/manifest-hack", manifesthack),
                (r"/", index),
                (r"/index", index),
                (r"/ajax", ajax),
                (r"/options", options),
                (r"/stats", stats),
                (r"/log", logHandler),
                (r"/ajaxsocket", ajaxSocket),
                (r"/filesocket", fileSocket),
                (r"/statsocket", statSocket),
                (r"/logsocket", logSocket),
                (r"/auto", autoHandler),
                (r"/autosocket", autoSocket),
                (r"/RPCSocket", RPCSocket),
                (r"/create", createHandler),
                (r"/createsocket", createSocket),
                (r"/downloadcreation", downloadCreation),
                (r"/download", download),
                #(r"/workersocket", workerSocket),
                #(r"/test", test),
            ],
            **settings)

        application._pyrtSockets = SocketStorage()
        application._pyrtLog = weblog.Logger(sockets=application._pyrtSockets)
        application._pyrtRT = rtorrent.rtorrent(c.get("rtorrent_socket"))
        application._pyrtL = login.Login(conf=c, log=application._pyrtLog)
        application._pyrtAliasStorage = aliases.AliasStore(
            application._pyrtLog, application._pyrtRT)
        application._pyrtDownloadHandler = downloadHandler.downloadHandler(
            application._pyrtLog)
        application._pyrtAJAX = ajaxPage.Ajax(
            conf=c,
            RT=application._pyrtRT,
            Log=application._pyrtLog,
            Sockets=application._pyrtSockets,
            Aliases=application._pyrtAliasStorage,
            DLHandler=application._pyrtDownloadHandler)
        application._pyrtOPTIONS = optionsPage.Options(
            conf=c,
            RT=application._pyrtRT,
            aliases=application._pyrtAliasStorage)
        application._pyrtSTATS = statsPage.Index(
            conf=c,
            RT=application._pyrtRT,
            aliases=application._pyrtAliasStorage)
        application._pyrtRemoteStorage = remotes.RemoteStorage(
            log=application._pyrtLog)
        application._pyrtGLOBALS = {
            "login": application._pyrtL,
            "ajaxPage": application._pyrtAJAX,
            "optionsPage": application._pyrtOPTIONS,
            "statsPage": application._pyrtSTATS,
            "log": application._pyrtLog,
            "RT": application._pyrtRT,
            "config": c,
            "sockets": application._pyrtSockets,
            "remoteStorage": application._pyrtRemoteStorage,
            "aliasStorage": application._pyrtAliasStorage,
        }

        http_server = tornado.httpserver.HTTPServer(application,
                                                    ssl_options=ssl_options)
        logging.info("Starting webserver on http%s://%s:%i with PID %d",
                     (ssl_options and "s" or ""),
                     global_config["server.socket_host"],
                     global_config["server.socket_port"], os.getpid())
        self._pyrtPID = os.getpid()

        #start listening on 10 UNIX sockets + the dedicated RSS socket
        sockets = []
        s_rss = tornado.netutil.bind_unix_socket(".sockets/rss.interface")
        logging.info("Starting UNIX websocket on .sockets/rss.interface")
        http_server.add_socket(s_rss)
        logging.info("Starting UNIX websockets")
        for i in range(10):
            s = tornado.netutil.bind_unix_socket(".sockets/rpc%i.interface" %
                                                 i)
            http_server.add_socket(s)
        try:
            http_server.listen(global_config["server.socket_port"],
                               global_config["server.socket_host"])
        except socket.error:
            logging.error("Address already in use, aborting")
            if os.path.exists("proc/pyrt.pid"):
                os.remove("proc/pyrt.pid")

            if os.path.exists(".sockets/rss.interface"):
                os.remove(".sockets/rss.interface")
            for i in range(10):
                try:
                    os.remove(".sockets/rpc%i.interface" % i)
                except:
                    pass

            sys.exit(0)

        logging.info("Starting RSS listener")
        application._pyrtRSS = rss.RSS(application._pyrtL,
                                       application._pyrtLog,
                                       application._pyrtRemoteStorage)
        self._pyrtRSSPID = application._pyrtRSS.start()

        self.instance = tornado.ioloop.IOLoop.instance()
        self.instance.start()