Browse Source

Restructure interface.py

We now only have 1 directory that has all the template files, so the directory does not have to be a variable for each page anymore.
There should be caution when doing redirects, to make sure the correct /sabnzbd/ or just / is used.
pull/832/head
Safihre 8 years ago
parent
commit
d1a92aeb36
  1. 36
      SABnzbd.py
  2. 14
      sabnzbd/api.py
  3. 225
      sabnzbd/interface.py
  4. 2
      sabnzbd/skintext.py
  5. 2
      sabnzbd/wizard.py

36
SABnzbd.py

@ -1259,16 +1259,11 @@ def main():
os.chdir(sabnzbd.DIR_PROG)
web_dir = Web_Template(sabnzbd.cfg.web_dir, DEF_STDINTF, fix_webname(web_dir))
web_dir_config = Web_Template(None, DEF_STDCONFIG, '')
sabnzbd.WEB_DIR = Web_Template(sabnzbd.cfg.web_dir, DEF_STDINTF, fix_webname(web_dir))
sabnzbd.WEB_DIR_CONFIG = Web_Template(None, DEF_STDCONFIG, '')
sabnzbd.WIZARD_DIR = os.path.join(sabnzbd.DIR_INTERFACES, 'wizard')
wizard_dir = os.path.join(sabnzbd.DIR_INTERFACES, 'wizard')
sabnzbd.WEB_DIR = web_dir
sabnzbd.WEB_DIR_CONFIG = web_dir_config
sabnzbd.WIZARD_DIR = wizard_dir
sabnzbd.WEB_COLOR = CheckColor(sabnzbd.cfg.web_color(), web_dir)
sabnzbd.WEB_COLOR = CheckColor(sabnzbd.cfg.web_color(), sabnzbd.WEB_DIR)
sabnzbd.cfg.web_color.set(sabnzbd.WEB_COLOR)
if fork and not sabnzbd.WIN32:
@ -1386,32 +1381,29 @@ def main():
'tools.gzip.on': True,
'tools.gzip.mime_types': mime_gzip,
'request.show_tracebacks': True,
'checker.check_localhost': bool(consoleLogging),
'error_page.401': sabnzbd.panic.error_page_401,
'error_page.404': sabnzbd.panic.error_page_404
})
# Force mimetypes (OS might overwrite them)
forced_mime_types = {'css': 'text/css', 'js': 'application/javascript'}
static = {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(web_dir, 'static'), 'tools.staticdir.content_types': forced_mime_types}
staticcfg = {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(web_dir_config, 'staticcfg'), 'tools.staticdir.content_types': forced_mime_types}
wizard_static = {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(wizard_dir, 'static'), 'tools.staticdir.content_types': forced_mime_types}
appconfig = {'/sabnzbd/api': {'tools.basic_auth.on': False},
'/api': {'tools.basic_auth.on': False},
static = {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(sabnzbd.WEB_DIR, 'static'), 'tools.staticdir.content_types': forced_mime_types}
staticcfg = {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(sabnzbd.WEB_DIR_CONFIG, 'staticcfg'), 'tools.staticdir.content_types': forced_mime_types}
wizard_static = {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(sabnzbd.WIZARD_DIR, 'static'), 'tools.staticdir.content_types': forced_mime_types}
appconfig = {'/api': {'tools.basic_auth.on': False},
'/rss': {'tools.basic_auth.on': False},
'/sabnzbd/rss': {'tools.basic_auth.on': False},
'/sabnzbd/shutdown': {'streamResponse': True},
'/sabnzbd/static': static,
'/static': static,
'/sabnzbd/wizard/static': wizard_static,
'/wizard/static': wizard_static,
'/favicon.ico': {'tools.staticfile.on': True, 'tools.staticfile.filename': os.path.join(web_dir_config, 'staticcfg', 'ico', 'favicon.ico')},
'/sabnzbd/staticcfg': staticcfg,
'/favicon.ico': {'tools.staticfile.on': True, 'tools.staticfile.filename': os.path.join(sabnzbd.WEB_DIR_CONFIG, 'staticcfg', 'ico', 'favicon.ico')},
'/staticcfg': staticcfg
}
main_page = sabnzbd.interface.MainPage(web_dir, '/', web_dir_config)
# Make available from both URLs
main_page = sabnzbd.interface.MainPage()
cherrypy.tree.mount(main_page, '/', config=appconfig)
cherrypy.tree.mount(main_page, '/sabnzbd/', config=appconfig)
# Set authentication for CherryPy
sabnzbd.interface.set_auth(cherrypy.config)

14
sabnzbd/api.py

@ -1185,9 +1185,9 @@ def handle_cat_api(output, kwargs):
return name
def build_status(web_dir=None, root=None, skip_dashboard=False, output=None):
def build_status(skip_dashboard=False, output=None):
# build up header full of basic information
info = build_header(web_dir)
info = build_header()
info['logfile'] = sabnzbd.LOGFILE
info['weblogfile'] = sabnzbd.WEBLOGFILE
@ -1292,14 +1292,14 @@ def build_status(web_dir=None, root=None, skip_dashboard=False, output=None):
return info
def build_queue(web_dir=None, root=None, webdir='', start=0, limit=0, trans=False, output=None, search=None):
def build_queue(start=0, limit=0, trans=False, output=None, search=None):
if output:
converter = unicoder
else:
converter = xml_name
# build up header full of basic information
info, pnfo_list, bytespersec, q_size, bytes_left_previous_page = build_queue_header(webdir, search=search, start=start, limit=limit)
info, pnfo_list, bytespersec, q_size, bytes_left_previous_page = build_queue_header(search=search, start=start, limit=limit)
datestart = datetime.datetime.now()
priorities = {TOP_PRIORITY: 'Force', REPAIR_PRIORITY: 'Repair', HIGH_PRIORITY: 'High', NORMAL_PRIORITY: 'Normal', LOW_PRIORITY: 'Low'}
@ -1704,7 +1704,7 @@ def build_header(webdir=''):
header['my_lcldata'] = sabnzbd.DIR_LCLDATA
header['my_home'] = sabnzbd.DIR_HOME
header['webdir'] = webdir
header['webdir'] = webdir or sabnzbd.WEB_DIR
header['pid'] = os.getpid()
header['finishaction'] = sabnzbd.QUEUECOMPLETE
@ -1735,10 +1735,10 @@ def build_header(webdir=''):
def build_queue_header(webdir='', search=None, start=0, limit=0):
def build_queue_header(search=None, start=0, limit=0):
""" Build full queue header """
header = build_header(webdir)
header = build_header()
bytespersec = BPSMeter.do.get_bps()
qnfo = NzbQueue.do.queue_info(search=search, start=start, limit=limit)

225
sabnzbd/interface.py

@ -301,35 +301,18 @@ def check_apikey(kwargs, nokey=False):
return None
class NoPage(object):
def __init__(self):
pass
@cherrypy.expose
def index(self, **kwargs):
return badParameterResponse(T('Error: No secondary interface defined.'))
##############################################################################
class MainPage(object):
def __init__(self, web_dir, root, web_dir_config=None, sub_mount=False):
self.__root = root
self.__web_dir = web_dir
def __init__(self):
# Add all sub-pages
self.login = LoginPage(web_dir_config, root + 'login/')
self.queue = QueuePage(web_dir, root + 'queue/')
self.history = HistoryPage(web_dir, root + 'history/')
self.status = Status(web_dir, root + 'status/')
self.config = ConfigPage(web_dir_config, root + 'config/')
self.nzb = NzoPage(web_dir, root + 'nzb/')
self.wizard = sabnzbd.wizard.Wizard(web_dir, root + 'wizard/')
# Add them again for the /sabnzbd/ links
if not sub_mount:
self.sabnzbd = MainPage(web_dir, '/sabnzbd/', web_dir_config=web_dir_config, sub_mount=True)
self.login = LoginPage()
self.queue = QueuePage('/queue/')
self.history = HistoryPage('/history/')
self.status = Status('/status/')
self.config = ConfigPage('/config/')
self.nzb = NzoPage('/nzb/')
self.wizard = sabnzbd.wizard.Wizard('/wizard/')
@cherrypy.expose
def index(self, **kwargs):
@ -337,7 +320,7 @@ class MainPage(object):
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
if sabnzbd.OLD_QUEUE and not cfg.warned_old_queue():
cfg.warned_old_queue.set(True)
@ -351,7 +334,7 @@ class MainPage(object):
config.save_config()
if kwargs.get('skip_wizard') or config.get_servers():
info = build_header(self.__web_dir)
info = build_header()
info['script_list'] = list_scripts(default=True)
info['script'] = 'Default'
@ -381,7 +364,7 @@ class MainPage(object):
info['warning'] = T('No PAR2 program found, repairs not possible<br />')
# For Glitter we pre-load the JSON output
if 'Glitter' in self.__web_dir:
if 'Glitter' in sabnzbd.WEB_DIR:
# Queue
queue = build_queue(limit=cfg.queue_limit(), output='json')[0]
queue['categories'] = info.pop('cat_list')
@ -403,20 +386,13 @@ class MainPage(object):
info['preload_queue'] = 'false'
info['preload_history'] = 'false'
template = Template(file=os.path.join(self.__web_dir, 'main.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR, 'main.tmpl'),
filter=FILTER, searchList=[info], compilerSettings=DIRECTIVES)
return template.respond()
else:
# Redirect to the setup wizard
raise cherrypy.HTTPRedirect('/sabnzbd/wizard/')
#@cherrypy.expose
# def reset_lang(self, **kwargs):
# msg = check_session(kwargs)
# if msg: return msg
# set_language(cfg.language())
# raise dcRaiser(self.__root, kwargs)
def add_handler(self, kwargs):
if not check_access():
return Protected()
@ -582,14 +558,10 @@ class MainPage(object):
##############################################################################
class LoginPage(object):
def __init__(self, web_dir, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
# Base output var
info = build_header(self.__web_dir)
info = build_header(sabnzbd.WEB_DIR_CONFIG)
info['error'] = ''
# Logout?
@ -598,8 +570,8 @@ class LoginPage(object):
raise dcRaiser('.', kwargs)
# Check if there's even a username/password set
#if check_login():
# raise dcRaiser('../', kwargs)
if check_login():
raise cherrypy.HTTPRedirect(cherrypy.request.script_name + '/')
# Check login info
if kwargs.get('username') == cfg.username() and kwargs.get('password') == cfg.password():
@ -611,7 +583,7 @@ class LoginPage(object):
info['error'] = T('Authentication failed, check username/password.')
# Show login
template = Template(file=os.path.join(self.__web_dir, 'login', 'main.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'login', 'main.tmpl'),
filter=FILTER, searchList=[info], compilerSettings=DIRECTIVES)
return template.respond()
@ -619,9 +591,8 @@ class LoginPage(object):
##############################################################################
class NzoPage(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
self.__cached_selection = {} # None
@cherrypy.expose
@ -635,7 +606,7 @@ class NzoPage(object):
if not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
nzo_id = None
for a in args:
@ -645,7 +616,7 @@ class NzoPage(object):
nzo = NzbQueue.do.get_nzo(nzo_id)
if nzo_id and nzo:
info, pnfo_list, bytespersec, q_size, bytes_left_previous_page = build_queue_header(self.__web_dir)
info, pnfo_list, bytespersec, q_size, bytes_left_previous_page = build_queue_header()
# /SABnzbd_nzo_xxxxx/bulk_operation
if 'bulk_operation' in args:
@ -669,7 +640,7 @@ class NzoPage(object):
info = self.nzo_details(info, pnfo_list, nzo_id)
info = self.nzo_files(info, pnfo_list, nzo_id)
template = Template(file=os.path.join(self.__web_dir, 'nzo.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR, 'nzo.tmpl'),
filter=FILTER, searchList=[info], compilerSettings=DIRECTIVES)
return template.respond()
else:
@ -814,24 +785,22 @@ class NzoPage(object):
##############################################################################
class QueuePage(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
if not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
start = int_conv(kwargs.get('start'))
limit = int_conv(kwargs.get('limit'))
search = kwargs.get('search')
info, _pnfo_list, _bytespersec = build_queue(self.__web_dir, self.__root, self.__web_dir,
start=start, limit=limit, trans=True, search=search)
info, _pnfo_list, _bytespersec = build_queue(start=start, limit=limit, trans=True, search=search)
template = Template(file=os.path.join(self.__web_dir, 'queue.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR, 'queue.tmpl'),
filter=FILTER, searchList=[info], compilerSettings=DIRECTIVES)
return template.respond()
@ -1030,9 +999,8 @@ class QueuePage(object):
##############################################################################
class HistoryPage(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
self.__verbose = False
self.__verbose_list = []
self.__failed_only = False
@ -1042,7 +1010,7 @@ class HistoryPage(object):
if not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
start = int_conv(kwargs.get('start'))
limit = int_conv(kwargs.get('limit'))
@ -1051,7 +1019,7 @@ class HistoryPage(object):
if failed_only is None:
failed_only = self.__failed_only
history = build_header(self.__web_dir)
history = build_header()
history['isverbose'] = self.__verbose
history['failed_only'] = failed_only
@ -1080,7 +1048,7 @@ class HistoryPage(object):
history['finish'] = history['fetched']
history['time_format'] = time_format
template = Template(file=os.path.join(self.__web_dir, 'history.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR, 'history.tmpl'),
filter=FILTER, searchList=[history], compilerSettings=DIRECTIVES)
return template.respond()
@ -1230,28 +1198,27 @@ class HistoryPage(object):
##############################################################################
class ConfigPage(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
self.folders = ConfigFolders(web_dir, root + 'folders/')
self.notify = ConfigNotify(web_dir, root + 'notify/')
self.general = ConfigGeneral(web_dir, root + 'general/')
self.rss = ConfigRss(web_dir, root + 'rss/')
self.scheduling = ConfigScheduling(web_dir, root + 'scheduling/')
self.server = ConfigServer(web_dir, root + 'server/')
self.switches = ConfigSwitches(web_dir, root + 'switches/')
self.categories = ConfigCats(web_dir, root + 'categories/')
self.sorting = ConfigSorting(web_dir, root + 'sorting/')
self.special = ConfigSpecial(web_dir, root + 'special/')
self.folders = ConfigFolders('/folders/')
self.notify = ConfigNotify('/notify/')
self.general = ConfigGeneral('/general/')
self.rss = ConfigRss('/rss/')
self.scheduling = ConfigScheduling('/scheduling/')
self.server = ConfigServer('/server/')
self.switches = ConfigSwitches('/switches/')
self.categories = ConfigCats('/categories/')
self.sorting = ConfigSorting('/sorting/')
self.special = ConfigSpecial('/special/')
@cherrypy.expose
def index(self, **kwargs):
if not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
conf = build_header(self.__web_dir)
raise NeedLogin()
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
conf['configfn'] = config.get_filename()
conf['cmdline'] = sabnzbd.CMDLINE
conf['build'] = sabnzbd.version.__baseline__[:7]
@ -1273,7 +1240,7 @@ class ConfigPage(object):
conf['folders'] = sabnzbd.nzbqueue.scan_jobs(all=False, action=False)
template = Template(file=os.path.join(self.__web_dir, 'config.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()
@ -1352,18 +1319,17 @@ LIST_DIRPAGE = (
class ConfigFolders(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
if cfg.configlock() or not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
conf = build_header(self.__web_dir)
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
for kw in LIST_DIRPAGE:
conf[kw] = config.get_config('misc', kw)()
@ -1371,7 +1337,7 @@ class ConfigFolders(object):
# Temporary fix, problem with build_header
conf['restart_req'] = sabnzbd.RESTART_REQ
template = Template(file=os.path.join(self.__web_dir, 'config_folders.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_folders.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()
@ -1424,18 +1390,17 @@ SWITCH_LIST = \
class ConfigSwitches(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
if cfg.configlock() or not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
conf = build_header(self.__web_dir)
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
conf['have_ssl_context'] = sabnzbd.HAVE_SSL_CONTEXT
conf['have_multicore'] = sabnzbd.WIN32 or sabnzbd.DARWIN_INTEL
@ -1449,7 +1414,7 @@ class ConfigSwitches(object):
conf['script_list'] = list_scripts() or ['None']
template = Template(file=os.path.join(self.__web_dir, 'config_switches.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_switches.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()
@ -1501,18 +1466,17 @@ SPECIAL_LIST_LIST = \
class ConfigSpecial(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
if cfg.configlock() or not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
conf = build_header(self.__web_dir)
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
conf['nt'] = sabnzbd.WIN32
@ -1520,7 +1484,7 @@ class ConfigSpecial(object):
conf['entries'] = [(kw, config.get_config('misc', kw)(), config.get_config('misc', kw).default()) for kw in SPECIAL_VALUE_LIST]
conf['entries'].extend([(kw, config.get_config('misc', kw).get_string(), '') for kw in SPECIAL_LIST_LIST])
template = Template(file=os.path.join(self.__web_dir, 'config_special.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_special.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()
@ -1552,9 +1516,8 @@ GENERAL_LIST = (
class ConfigGeneral(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
@ -1583,9 +1546,9 @@ class ConfigGeneral(object):
if cfg.configlock() or not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
conf = build_header(self.__web_dir)
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
conf['configfn'] = config.get_filename()
@ -1634,7 +1597,7 @@ class ConfigGeneral(object):
conf['my_lcldata'] = cfg.admin_dir.get_path()
conf['caller_url'] = cherrypy.request.base + '/sabnzbd/'
template = Template(file=os.path.join(self.__web_dir, 'config_general.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_general.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()
@ -1733,18 +1696,17 @@ def change_web_dir(web_dir):
##############################################################################
class ConfigServer(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
if cfg.configlock() or not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
conf = build_header(self.__web_dir)
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
new = []
servers = config.get_servers()
@ -1758,7 +1720,7 @@ class ConfigServer(object):
conf['cats'] = list_cats(default=True)
conf['have_ssl_context'] = sabnzbd.HAVE_SSL_CONTEXT
template = Template(file=os.path.join(self.__web_dir, 'config_server.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_server.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()
@ -1892,9 +1854,8 @@ def handle_server_test(kwargs, root):
##############################################################################
class ConfigRss(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
self.__refresh_readout = None # Set to URL when new readout is needed
self.__refresh_download = False # True when feed needs to be read
self.__refresh_force = False # True if forced download of all matches is required
@ -1908,9 +1869,9 @@ class ConfigRss(object):
if cfg.configlock() or not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
conf = build_header(self.__web_dir)
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
conf['script_list'] = list_scripts(default=True)
pick_script = conf['script_list'] != []
@ -1973,7 +1934,7 @@ class ConfigRss(object):
unum += 1
conf['feed'] = txt + str(unum)
template = Template(file=os.path.join(self.__web_dir, 'config_rss.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_rss.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()
@ -2245,9 +2206,8 @@ _SCHED_ACTIONS = ('resume', 'pause', 'pause_all', 'shutdown', 'restart', 'speedl
class ConfigScheduling(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
@ -2266,9 +2226,9 @@ class ConfigScheduling(object):
if cfg.configlock() or not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
conf = build_header(self.__web_dir)
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
actions = []
actions.extend(_SCHED_ACTIONS)
@ -2332,7 +2292,7 @@ class ConfigScheduling(object):
conf['actions'] = actions
conf['actions_lng'] = actions_lng
template = Template(file=os.path.join(self.__web_dir, 'config_scheduling.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_scheduling.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()
@ -2402,18 +2362,17 @@ class ConfigScheduling(object):
##############################################################################
class ConfigCats(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
if cfg.configlock() or not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
conf = build_header(self.__web_dir)
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
conf['script_list'] = list_scripts(default=True)
conf['defdir'] = cfg.complete_dir.get_path()
@ -2431,7 +2390,7 @@ class ConfigCats(object):
slotinfo.insert(1, empty)
conf['slotinfo'] = slotinfo
template = Template(file=os.path.join(self.__web_dir, 'config_cat.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_cat.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()
@ -2478,25 +2437,24 @@ SORT_LIST = (
class ConfigSorting(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
if cfg.configlock() or not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
conf = build_header(self.__web_dir)
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
conf['complete_dir'] = cfg.complete_dir.get_path()
for kw in SORT_LIST:
conf[kw] = config.get_config('misc', kw)()
conf['cat_list'] = list_cats(False)
template = Template(file=os.path.join(self.__web_dir, 'config_sorting.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_sorting.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()
@ -2540,20 +2498,19 @@ LOG_HASH_RE = re.compile(r"([a-fA-F\d]{25})", re.I)
class Status(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
@cherrypy.expose
def index(self, **kwargs):
if not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
header = build_status(web_dir=self.__web_dir, skip_dashboard=kwargs.get('skip_dashboard'))
header = build_status(skip_dashboard=kwargs.get('skip_dashboard'))
template = Template(file=os.path.join(self.__web_dir, 'status.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR, 'status.tmpl'),
filter=FILTER, searchList=[header], compilerSettings=DIRECTIVES)
return template.respond()
@ -2712,8 +2669,13 @@ def Protected():
cherrypy.response.status = 403
return 'Access denied'
def NeedLogin(url, kwargs):
raise dcRaiser(url + 'login/', kwargs)
def NeedLogin():
# Is it / or /sabnzbd/?
if cherrypy.request.script_name:
url = '/sabnzbd/login/'
else:
url = '/login/'
raise cherrypy.HTTPRedirect(url)
def badParameterResponse(msg, ajax=None):
""" Return a html page with error message and a 'back' button """
@ -2867,9 +2829,8 @@ LIST_NSCRIPT = ('nscript_enable', 'nscript_script', 'nscript_parameters',
class ConfigNotify(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
self.__web_dir = web_dir
self.__lastmail = None
@cherrypy.expose
@ -2877,9 +2838,9 @@ class ConfigNotify(object):
if cfg.configlock() or not check_access():
return Protected()
if not check_login():
raise NeedLogin(self.__root, kwargs)
raise NeedLogin()
conf = build_header(self.__web_dir)
conf = build_header(sabnzbd.WEB_DIR_CONFIG)
conf['my_home'] = sabnzbd.DIR_HOME
conf['lastmail'] = self.__lastmail
@ -2912,7 +2873,7 @@ class ConfigNotify(object):
conf['notify_keys'] = sabnzbd.constants.NOTIFY_KEYS
conf['notify_texts'] = sabnzbd.notifier.NOTIFICATION
template = Template(file=os.path.join(self.__web_dir, 'config_notify.tmpl'),
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_notify.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)
return template.respond()

2
sabnzbd/skintext.py

@ -326,7 +326,7 @@ SKIN_TEXT = {
'opt-port' : TT('SABnzbd Port'),
'explain-port' : TT('Port SABnzbd should listen on.'),
'opt-web_dir' : TT('Web Interface'),
'explain-web_dir2' : TT('Activate an alternative skin.'),
'explain-web_dir' : TT('Choose a skin.'),
'opt-web_username' : TT('SABnzbd Username'),
'explain-web_username' : TT('Optional authentication username.'),
'opt-web_password' : TT('SABnzbd Password'),

2
sabnzbd/wizard.py

@ -36,7 +36,7 @@ import sabnzbd.cfg as cfg
class Wizard(object):
def __init__(self, web_dir, root):
def __init__(self, root):
self.__root = root
# Get the path for the folder named wizard
self.__web_dir = sabnzbd.WIZARD_DIR

Loading…
Cancel
Save