def two(self, **kwargs): """ Accept server and show the final page for restart """ if cfg.configlock() or not sabnzbd.interface.check_access(): return sabnzbd.interface.Protected() if not sabnzbd.interface.check_login(): raise sabnzbd.interface.NeedLogin() # Save server details if kwargs: kwargs['enable'] = 1 sabnzbd.interface.handle_server(kwargs) config.save_config() # Show Restart screen info = self.info.copy() info['helpuri'] = 'https://sabnzbd.org/wiki/' info['session'] = cfg.api_key() info['access_url'], info['urls'] = self.get_access_info() info['active_lang'] = cfg.language() info['T'] = Ttemplate info['download_dir'] = cfg.download_dir.get_path() info['complete_dir'] = cfg.complete_dir.get_path() template = Template(file=os.path.join(self.__web_dir, 'two.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def four(self, **kwargs): """ Accept Indexers and show Restart screen """ if kwargs: if 'newzbin_user' in kwargs and 'newzbin_pass' in kwargs: cfg.newzbin_username.set(kwargs.get('newzbin_user','')) cfg.newzbin_password.set(kwargs.get('newzbin_pass','')) cfg.newzbin_bookmarks.set(kwargs.get('newzbin_bookmarks', '0')) if 'matrix_user' in kwargs and 'matrix_apikey' in kwargs: cfg.matrix_username.set(kwargs.get('matrix_user','')) cfg.matrix_apikey.set(kwargs.get('matrix_apikey','')) config.save_config() # Show Restart screen info = self.info.copy() info['num'] = '» %s' % T('Step Four') info['number'] = 4 info['helpuri'] = 'http://wiki.sabnzbd.org/' info['session'] = cfg.api_key() info['access_url'], info['urls'] = self.get_access_info() info['T'] = Ttemplate template = Template(file=os.path.join(self.__web_dir, 'four.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def three(self, **kwargs): """ Accept webserver parms and show Indexers page """ if kwargs: if 'access' in kwargs: cfg.cherryhost.set(kwargs['access']) cfg.enable_https.set(kwargs.get('enable_https', 0)) cfg.autobrowser.set(kwargs.get('autobrowser', 0)) cfg.username.set(kwargs.get('web_user', '')) cfg.password.set(kwargs.get('web_pass', '')) if not cfg.username() or not cfg.password(): sabnzbd.interface.set_auth(cherrypy.config) config.save_config() # Show Restart screen info = self.info.copy() info['num'] = '» %s' % T('Step Three') info['number'] = 3 info['helpuri'] = 'http://wiki.sabnzbd.org/' info['session'] = cfg.api_key() info['access_url'], info['urls'] = self.get_access_info() info['T'] = Ttemplate template = Template(file=os.path.join(self.__web_dir, 'three.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def four(self, **kwargs): """ Accept Indexers and show Restart screen """ if kwargs: if 'newzbin_user' in kwargs and 'newzbin_pass' in kwargs: cfg.newzbin_username.set(kwargs.get('newzbin_user', '')) cfg.newzbin_password.set(kwargs.get('newzbin_pass', '')) cfg.newzbin_bookmarks.set(kwargs.get('newzbin_bookmarks', '0')) if 'matrix_user' in kwargs and 'matrix_apikey' in kwargs: cfg.matrix_username.set(kwargs.get('matrix_user', '')) cfg.matrix_apikey.set(kwargs.get('matrix_apikey', '')) config.save_config() # Show Restart screen info = self.info.copy() info['num'] = '» %s' % T('Step Four') info['number'] = 4 info['helpuri'] = 'http://wiki.sabnzbd.org/' info['session'] = cfg.api_key() info['access_url'], info['urls'] = self.get_access_info() info['T'] = Ttemplate template = Template(file=os.path.join(self.__web_dir, 'four.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def three(self, **kwargs): """ Accept webserver parms and show Indexers page """ if kwargs: if 'access' in kwargs: cfg.cherryhost.set(kwargs['access']) cfg.enable_https.set(kwargs.get('enable_https',0)) cfg.autobrowser.set(kwargs.get('autobrowser',0)) cfg.username.set(kwargs.get('web_user', '')) cfg.password.set(kwargs.get('web_pass', '')) if not cfg.username() or not cfg.password(): sabnzbd.interface.set_auth(cherrypy.config) config.save_config() # Show Restart screen info = self.info.copy() info['num'] = '» %s' % T('Step Three') info['number'] = 3 info['helpuri'] = 'http://wiki.sabnzbd.org/' info['session'] = cfg.api_key() info['access_url'], info['urls'] = self.get_access_info() info['T'] = Ttemplate template = Template(file=os.path.join(self.__web_dir, 'three.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def bad_fetch(nzo, url, msg='', retry=False, content=False): """ Create History entry for failed URL Fetch msg : message to be logged retry : make retry link in histort content : report in history that cause is a bad NZB file """ msg = unicoder(msg) pp = nzo.pp if pp is None: pp = '' else: pp = '&pp=%s' % str(pp) cat = nzo.cat if cat: cat = '&cat=%s' % urllib.quote(cat) else: cat = '' script = nzo.script if script: script = '&script=%s' % urllib.quote(script) else: script = '' nzo.status = 'Failed' if url: nzo.filename = url nzo.final_name = url.strip() if content: # Bad content msg = T('Unusable NZB file') else: # Failed fetch msg = ' (' + msg + ')' if retry: nzbname = nzo.custom_name if nzbname: nzbname = '&nzbname=%s' % urllib.quote(nzbname) else: nzbname = '' text = T('URL Fetching failed; %s' ) + ', <a href="./retry?session=%s&url=%s%s%s%s%s">' + T( 'Try again') + '</a>' parms = (msg, cfg.api_key(), urllib.quote(url), pp, cat, script, nzbname) nzo.fail_msg = text % parms else: nzo.fail_msg = msg from sabnzbd.nzbqueue import NzbQueue assert isinstance(NzbQueue.do, NzbQueue) NzbQueue.do.remove(nzo.nzo_id, add_to_history=True)
def one(self, **kwargs): """ Accept language and show server page """ if cfg.configlock() or not sabnzbd.interface.check_access(): return sabnzbd.interface.Protected() if not sabnzbd.interface.check_login(): raise sabnzbd.interface.NeedLogin() language = kwargs.get('lang') if kwargs.get('lang') else cfg.language() cfg.language.set(language) set_language(language) sabnzbd.api.clear_trans_cache() # Always setup Glitter sabnzbd.interface.change_web_dir('Glitter - Default') info = self.info.copy() info['session'] = cfg.api_key() info['language'] = cfg.language() info['active_lang'] = info['language'] info['T'] = Ttemplate info['have_ssl_context'] = sabnzbd.HAVE_SSL_CONTEXT servers = config.get_servers() if not servers: info['host'] = '' info['port'] = '' info['username'] = '' info['password'] = '' info['connections'] = '' info['ssl'] = 0 info['ssl_verify'] = 2 else: # Sort servers to get the first enabled one server_names = sorted( servers.keys(), key=lambda svr: '%d%02d%s' % (int(not servers[svr].enable()), servers[svr].priority(), servers[svr].displayname().lower())) for server in server_names: # If there are multiple servers, just use the first enabled one s = servers[server] info['host'] = s.host() info['port'] = s.port() info['username'] = s.username() info['password'] = s.password.get_stars() info['connections'] = s.connections() info['ssl'] = s.ssl() info['ssl_verify'] = s.ssl_verify() if s.enable(): break template = Template(file=os.path.join(self.__web_dir, 'one.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def bad_fetch(nzo, url, msg='', retry=False, content=False): """ Create History entry for failed URL Fetch msg : message to be logged retry : make retry link in histort content : report in history that cause is a bad NZB file """ msg = unicoder(msg) pp = nzo.pp if pp is None: pp = '' else: pp = '&pp=%s' % str(pp) cat = nzo.cat if cat: cat = '&cat=%s' % urllib.quote(cat) else: cat = '' script = nzo.script if script: script = '&script=%s' % urllib.quote(script) else: script = '' nzo.status = 'Failed' if url: nzo.filename = url nzo.final_name = url.strip() if content: # Bad content msg = T('Unusable NZB file') else: # Failed fetch msg = ' (' + msg + ')' if retry: nzbname = nzo.custom_name if nzbname: nzbname = '&nzbname=%s' % urllib.quote(nzbname) else: nzbname = '' text = T('URL Fetching failed; %s') + ', <a href="./retry?session=%s&url=%s%s%s%s%s">' + T('Try again') + '</a>' parms = (msg, cfg.api_key(), urllib.quote(url), pp, cat, script, nzbname) nzo.fail_msg = text % parms else: nzo.fail_msg = msg from sabnzbd.nzbqueue import NzbQueue assert isinstance(NzbQueue.do, NzbQueue) NzbQueue.do.remove(nzo.nzo_id, add_to_history=True)
def four(self, **kwargs): if kwargs: cfg.rating_enable.set(kwargs.get('rating_enable', 0)) cfg.rating_api_key.set(kwargs.get('rating_api_key', '')) config.save_config() # Show Restart screen info = self.info.copy() info['num'] = '» %s' % T('Step Four') info['number'] = 4 info['helpuri'] = 'http://wiki.sabnzbd.org/' info['session'] = cfg.api_key() info['access_url'], info['urls'] = self.get_access_info() info['T'] = Ttemplate template = Template(file=os.path.join(self.__web_dir, 'four.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def one(self, **kwargs): """ Accept language and show server page """ language = kwargs.get('lang') if kwargs.get('lang') else cfg.language() cfg.language.set(language) set_language(language) sabnzbd.api.clear_trans_cache() # Always setup Glitter sabnzbd.interface.change_web_dir('Glitter - Default') info = self.info.copy() info['session'] = cfg.api_key() info['language'] = cfg.language() info['active_lang'] = info['language'] info['T'] = Ttemplate info['have_ssl_context'] = sabnzbd.HAVE_SSL_CONTEXT servers = config.get_servers() if not servers: info['host'] = '' info['port'] = '' info['username'] = '' info['password'] = '' info['connections'] = '' info['ssl'] = 0 info['ssl_verify'] = 2 else: for server in servers: # If there are multiple servers, just use the first enabled one s = servers[server] info['host'] = s.host() info['port'] = s.port() info['username'] = s.username() info['password'] = s.password.get_stars() info['connections'] = s.connections() info['ssl'] = s.ssl() info['ssl_verify'] = s.ssl_verify() if s.enable(): break template = Template(file=os.path.join(self.__web_dir, 'one.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def upload_file(url, fp): """ Function for uploading nzbs to a running sabnzbd instance """ try: fp = urllib.quote_plus(fp) url = '%s&mode=addlocalfile&name=%s' % (url, fp) # Add local apikey if it wasn't already in the registered URL apikey = cfg.api_key() if apikey and 'apikey' not in url: url = '%s&apikey=%s' % (url, apikey) if 'apikey' not in url: # Use alternative login method username = cfg.username() password = cfg.password() if username and password: url = '%s&ma_username=%s&ma_password=%s' % (url, username, password) sabnzbd.newsunpack.get_from_url(url) except: logging.error("Failed to upload file: %s", fp) logging.info("Traceback: ", exc_info = True)
def upload_file_to_sabnzbd(url, fp): """ Function for uploading nzbs to a running SABnzbd instance """ try: fp = urllib.parse.quote_plus(fp) url = "%s&mode=addlocalfile&name=%s" % (url, fp) # Add local API-key if it wasn't already in the registered URL apikey = cfg.api_key() if apikey and "apikey" not in url: url = "%s&apikey=%s" % (url, apikey) if "apikey" not in url: # Use alternative login method username = cfg.username() password = cfg.password() if username and password: url = "%s&ma_username=%s&ma_password=%s" % (url, username, password) get_from_url(url) except: logging.error(T("Failed to upload file: %s"), fp) logging.info("Traceback: ", exc_info=True)
def one(self, **kwargs): """ Accept language and show server page """ language = kwargs.get('lang') cfg.language.set(language) set_language(language) sabnzbd.api.clear_trans_cache() # Always setup Plush sabnzbd.interface.change_web_dir('Plush - Gold') info = self.info.copy() info['num'] = '» %s' % T('Step One') info['number'] = 1 info['session'] = cfg.api_key() info['language'] = cfg.language() info['T'] = Ttemplate info['have_ssl'] = bool(sabnzbd.newswrapper.HAVE_SSL) servers = config.get_servers() if not servers: info['host'] = '' info['port'] = '' info['username'] = '' info['password'] = '' info['connections'] = '' info['ssl'] = 0 else: for server in servers: # If there are multiple servers, just use the first enabled one s = servers[server] info['host'] = s.host() info['port'] = s.port() info['username'] = s.username() info['password'] = s.password.get_stars() info['connections'] = s.connections() info['ssl'] = s.ssl() if s.enable(): break template = Template(file=os.path.join(self.__web_dir, 'one.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def two(self, **kwargs): """ Accept server and show the final page for restart """ # Save server details if kwargs: kwargs['enable'] = 1 sabnzbd.interface.handle_server(kwargs) config.save_config() # Show Restart screen info = self.info.copy() info['helpuri'] = 'http://wiki.sabnzbd.org/' info['session'] = cfg.api_key() info['access_url'], info['urls'] = self.get_access_info() info['active_lang'] = cfg.language() info['T'] = Ttemplate template = Template(file=os.path.join(self.__web_dir, 'two.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def two(self, **kwargs): """ Accept server and show the final page for restart """ # Save server details if kwargs: kwargs['enable'] = 1 sabnzbd.interface.handle_server(kwargs) config.save_config() # Show Restart screen info = self.info.copy() info['helpuri'] = 'https://sabnzbd.org/wiki/' info['session'] = cfg.api_key() info['access_url'], info['urls'] = self.get_access_info() info['active_lang'] = cfg.language() info['T'] = Ttemplate template = Template(file=os.path.join(self.__web_dir, 'two.html'), searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES) return template.respond()
def bad_fetch(nzo, url, msg='', retry=False, content=False): """ Create History entry for failed URL Fetch msg : message to be logged retry : make retry link in histort content : report in history that cause is a bad NZB file """ if msg: msg = unicoder(msg) else: msg = '' pp = nzo.pp if pp is None: pp = '' else: pp = '&pp=%s' % str(pp) cat = nzo.cat if cat: cat = '&cat=%s' % urllib.quote(cat) else: cat = '' script = nzo.script if script: script = '&script=%s' % urllib.quote(script) else: script = '' nzo.status = Status.FAILED if url: nzo.filename = url nzo.final_name = url.strip() if content: # Bad content msg = T('Unusable NZB file') else: # Failed fetch msg = ' (' + msg + ')' if retry: nzbname = nzo.custom_name if nzbname: nzbname = '&nzbname=%s' % urllib.quote(nzbname) else: nzbname = '' text = T('URL Fetching failed; %s') + ', <a href="./retry?session=%s&url=%s&job=%s%s%s%s%s">' + T('Try again') + '</a>' parms = (msg, cfg.api_key(), urllib.quote(url), nzo.nzo_id, pp, cat, script, nzbname) nzo.fail_msg = text % parms else: nzo.fail_msg = msg if isinstance(url, int) or url.isdigit(): url = 'Newzbin #%s' % url growler.send_notification(T('URL Fetching failed; %s') % '', '%s\n%s' % (msg, url), 'other') if cfg.email_endjob() > 0: #import sabnzbd.emailer sabnzbd.emailer.badfetch_mail(msg, url) from sabnzbd.nzbqueue import NzbQueue assert isinstance(NzbQueue.do, NzbQueue) NzbQueue.do.remove(nzo.nzo_id, add_to_history=True)