Browse Source

Allow users to set custom basepath

Closes #904
https://forums.sabnzbd.org/viewtopic.php?f=11&t=22511
tags/2.3.0Alpha1
Safihre 8 years ago
parent
commit
12004802b6
  1. 12
      SABnzbd.py
  2. 1
      interfaces/Config/templates/_inc_header_uc.tmpl
  3. 6
      interfaces/Config/templates/staticcfg/js/script.js
  4. 6
      sabnzbd/api.py
  5. 2
      sabnzbd/cfg.py
  6. 14
      sabnzbd/interface.py
  7. 4
      sabnzbd/panic.py
  8. 12
      sabnzbd/wizard.py
  9. 5
      sabnzbd/zconfig.py

12
SABnzbd.py

@ -1027,7 +1027,7 @@ def main():
pass
else:
if not url:
url = 'https://%s:%s/sabnzbd/api?' % (browserhost, port)
url = 'https://%s:%s%s/api?' % (browserhost, port, sabnzbd.cfg.url_base())
if new_instance or not check_for_sabnzbd(url, upload_nzbs, autobrowser):
# Bail out if we have fixed our ports after first start-up
if sabnzbd.cfg.fixed_ports():
@ -1056,7 +1056,7 @@ def main():
pass
else:
if not url:
url = 'http://%s:%s/sabnzbd/api?' % (browserhost, cherryport)
url = 'http://%s:%s%s/api?' % (browserhost, cherryport, sabnzbd.cfg.url_base())
if new_instance or not check_for_sabnzbd(url, upload_nzbs, autobrowser):
# Bail out if we have fixed our ports after first start-up
if sabnzbd.cfg.fixed_ports():
@ -1373,7 +1373,7 @@ def main():
# 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)
cherrypy.tree.mount(main_page, sabnzbd.cfg.url_base(), config=appconfig)
# Set authentication for CherryPy
sabnzbd.interface.set_auth(cherrypy.config)
@ -1398,7 +1398,7 @@ def main():
mode = 's'
else:
mode = ''
api_url = 'http%s://%s:%s/sabnzbd/api?apikey=%s' % (mode, browserhost, cherryport, sabnzbd.cfg.api_key())
api_url = 'http%s://%s:%s%s/api?apikey=%s' % (mode, browserhost, cherryport, sabnzbd.cfg.url_base(), sabnzbd.cfg.api_key())
if sabnzbd.WIN_SERVICE:
mail = MailSlot()
@ -1431,9 +1431,9 @@ def main():
# Set URL for browser
if enable_https:
browser_url = "https://%s:%s/sabnzbd" % (browserhost, cherryport)
browser_url = "https://%s:%s%s" % (browserhost, cherryport, sabnzbd.cfg.url_base())
else:
browser_url = "http://%s:%s/sabnzbd" % (browserhost, cherryport)
browser_url = "http://%s:%s%s" % (browserhost, cherryport, sabnzbd.cfg.url_base())
sabnzbd.BROWSER_URL = browser_url
if not autorestarted:

1
interfaces/Config/templates/_inc_header_uc.tmpl

@ -45,6 +45,7 @@
// Information we need
var sabSession = '$session';
var rootURL = '${root}'
var urlBase = '${url_base}'
var folderBrowseUrl = '${root}tapi?mode=browse&output=json&apikey=$session';
var folderSeperator = '#if $os.sep == '\\' then '\\\\' else '/'#'

6
interfaces/Config/templates/staticcfg/js/script.js

@ -226,15 +226,13 @@ function do_restart() {
$('.main-restarting').show()
// What template
var arrPath = window.location.pathname.split('/');
var urlPath = (arrPath[1] == "m" || arrPath[2] == "m") ? '/sabnzbd/m/' : '/sabnzbd/';
var switchedHTTPS = ($('#enable_https').is(':checked') == ($('#enable_https').data('original') === undefined))
var portsUnchanged = ($('#port').val() == $('#port').data('original')) && ($('#https_port').val() == $('#https_port').data('original'))
// Are we on settings page or did nothing change?
if(!$('body').hasClass('General') || (!switchedHTTPS && portsUnchanged)) {
// Same as before
var urlTotal = window.location.origin + urlPath
var urlTotal = window.location.origin + urlBase
} else {
// Protocol and port depend on http(s) setting
if($('#enable_https').is(':checked') && (window.location.protocol == 'https:' || !$('#https_port').val())) {
@ -248,7 +246,7 @@ function do_restart() {
}
// We cannot make a good guess for the IP, so at least we assume that stays the same
var urlTotal = urlProtocol + '//' + window.location.hostname + ':' + urlPort + urlPath;
var urlTotal = urlProtocol + '//' + window.location.hostname + ':' + urlPort + urlBase;
}
// Show where we are going to connect

6
sabnzbd/api.py

@ -1460,8 +1460,7 @@ def rss_qstatus():
rss = RSS()
rss.channel.title = "SABnzbd Queue"
rss.channel.description = "Overview of current downloads"
rss.channel.link = "http://%s:%s/sabnzbd/queue" % (
cfg.cherryhost(), cfg.cherryport())
rss.channel.link = "http://%s:%s%s/queue" % (cfg.cherryhost(), cfg.cherryport(), cfg.url_base())
rss.channel.language = "en"
item = Item()
@ -1492,7 +1491,7 @@ def rss_qstatus():
item = Item()
item.title = name
item.link = "http://%s:%s/sabnzbd/history" % (cfg.cherryhost(), cfg.cherryport())
item.link = "http://%s:%s%s/history" % (cfg.cherryhost(), cfg.cherryport(), cfg.url_base())
item.guid = nzo_id
status_line = []
status_line.append('<tr>')
@ -1642,6 +1641,7 @@ def build_header(webdir='', output=None):
header['my_lcldata'] = sabnzbd.DIR_LCLDATA
header['my_home'] = sabnzbd.DIR_HOME
header['webdir'] = webdir or sabnzbd.WEB_DIR
header['url_base'] = cfg.url_base()
header['nt'] = sabnzbd.WIN32
header['darwin'] = sabnzbd.DARWIN

2
sabnzbd/cfg.py

@ -275,7 +275,7 @@ history_limit = OptionNumber('misc', 'history_limit', 10, 0)
wait_ext_drive = OptionNumber('misc', 'wait_ext_drive', 5, 1, 60)
marker_file = OptionStr('misc', 'nomedia_marker', '')
ipv6_servers = OptionNumber('misc', 'ipv6_servers', 1, 0, 2)
url_base = OptionStr('misc', 'url_base', '/sabnzbd')
##############################################################################
# Config - Notifications

14
sabnzbd/interface.py

@ -125,8 +125,8 @@ def Raiser(root='', **kwargs):
# Add extras
if args:
root = '%s?%s' % (root, urllib.urlencode(args))
# Optionally add the leading /sabnzbd/
if not root.startswith('/sabnzbd'):
# Optionally add the leading /sabnzbd/ (or what the user set)
if not root.startswith(cfg.url_base()):
root = cherrypy.request.script_name + root
# Send the redirect
return cherrypy.HTTPRedirect(root)
@ -224,9 +224,7 @@ def set_auth(conf):
conf.update({'tools.basic_auth.on': True, 'tools.basic_auth.realm': 'SABnzbd',
'tools.basic_auth.users': get_users, 'tools.basic_auth.encrypt': encrypt_pwd})
conf.update({'/api': {'tools.basic_auth.on': False},
'/m/api': {'tools.basic_auth.on': False},
'/sabnzbd/api': {'tools.basic_auth.on': False},
'/sabnzbd/m/api': {'tools.basic_auth.on': False},
'%s/api' % cfg.url_base(): {'tools.basic_auth.on': False},
})
else:
conf.update({'tools.basic_auth.on': False})
@ -376,7 +374,7 @@ class MainPage(object):
return template.respond()
else:
# Redirect to the setup wizard
raise cherrypy.HTTPRedirect('/sabnzbd/wizard/')
raise cherrypy.HTTPRedirect('%s/wizard/' % cfg.url_base())
@cherrypy.expose
def addFile(self, **kwargs):
@ -1383,7 +1381,7 @@ SPECIAL_BOOL_LIST = \
)
SPECIAL_VALUE_LIST = \
('size_limit', 'folder_max_length', 'fsys_type', 'movie_rename_limit', 'nomedia_marker',
'req_completion_rate', 'wait_ext_drive', 'show_sysload',
'req_completion_rate', 'wait_ext_drive', 'show_sysload', 'url_base',
'direct_unpack_threads', 'ipv6_servers', 'selftest_host', 'rating_host'
)
SPECIAL_LIST_LIST = ('rss_odd_titles', 'quick_check_ext_ignore')
@ -1521,7 +1519,7 @@ class ConfigGeneral(object):
conf['nzb_key'] = cfg.nzb_key()
conf['local_ranges'] = cfg.local_ranges.get_string()
conf['my_lcldata'] = cfg.admin_dir.get_path()
conf['caller_url'] = cherrypy.request.base + '/sabnzbd/'
conf['caller_url'] = cherrypy.request.base + cfg.url_base()
template = Template(file=os.path.join(sabnzbd.WEB_DIR_CONFIG, 'config_general.tmpl'),
filter=FILTER, searchList=[conf], compilerSettings=DIRECTIVES)

4
sabnzbd/panic.py

@ -241,10 +241,10 @@ def error_page_404(status, message, traceback, version):
<head>
<script type="text/javascript">
<!--
location.href = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '') + '/sabnzbd/' ;
location.href = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '') + '%s' ;
//-->
</script>
</head>
<body><br/></body>
</html>
'''
''' % cfg.url_base()

12
sabnzbd/wizard.py

@ -229,19 +229,19 @@ class Wizard(object):
for sock in socks:
if sock:
if cfg.enable_https() and cfg.https_port():
url = 'https://%s:%s/sabnzbd/' % (sock, cfg.https_port())
url = 'https://%s:%s%s' % (sock, cfg.https_port(), cfg.url_base())
elif cfg.enable_https():
url = 'https://%s:%s/sabnzbd/' % (sock, cfg.cherryport())
url = 'https://%s:%s%s' % (sock, cfg.cherryport(), cfg.url_base())
else:
url = 'http://%s:%s/sabnzbd/' % (sock, cfg.cherryport())
url = 'http://%s:%s%s' % (sock, cfg.cherryport(), cfg.url_base())
urls.append(url)
if cfg.enable_https() and cfg.https_port():
access_url = 'https://%s:%s/sabnzbd/' % (sock, cfg.https_port())
access_url = 'https://%s:%s%s' % (sock, cfg.https_port(), cfg.url_base())
elif cfg.enable_https():
access_url = 'https://%s:%s/sabnzbd/' % (access_uri, cfg.cherryport())
access_url = 'https://%s:%s%s' % (access_uri, cfg.cherryport(), cfg.url_base())
else:
access_url = 'http://%s:%s/sabnzbd/' % (access_uri, cfg.cherryport())
access_url = 'http://%s:%s%s' % (access_uri, cfg.cherryport(), cfg.url_base())
return access_url, urls

5
sabnzbd/zconfig.py

@ -84,8 +84,7 @@ def set_bonjour(host=None, port=None):
suffix = ''
else:
suffix = '.local'
if hasattr(cherrypy.wsgiserver, 'redirect_url'):
cherrypy.wsgiserver.redirect_url("https://%s%s:%s/sabnzbd" % (name, suffix, port))
logging.debug('Try to publish in Bonjour as "%s" (%s:%s)', name, host, port)
try:
refObject = pybonjour.DNSServiceRegister(
@ -95,7 +94,7 @@ def set_bonjour(host=None, port=None):
domain=domain,
host=zhost,
port=int(port),
txtRecord=pybonjour.TXTRecord({'path': '/sabnzbd/',
txtRecord=pybonjour.TXTRecord({'path': cfg.url_base(),
'https': cfg.enable_https()}),
callBack=_zeroconf_callback)
except sabnzbd.utils.pybonjour.BonjourError as e:

Loading…
Cancel
Save