rename --webroot to --rp-loc and fix related bugs

This commit is contained in:
ed 2022-12-11 21:09:50 +00:00
parent 0ab2a665de
commit 7fd1d6a4e8
6 changed files with 18 additions and 13 deletions

View file

@ -673,7 +673,7 @@ def run_argparse(
ap2.add_argument("-p", metavar="PORT", type=u, default="3923", help="ports to bind (comma/range)") ap2.add_argument("-p", metavar="PORT", type=u, default="3923", help="ports to bind (comma/range)")
ap2.add_argument("--ll", action="store_true", help="include link-local IPv4/IPv6 even if the NIC has routable IPs (breaks some mdns clients)") ap2.add_argument("--ll", action="store_true", help="include link-local IPv4/IPv6 even if the NIC has routable IPs (breaks some mdns clients)")
ap2.add_argument("--rproxy", metavar="DEPTH", type=int, default=1, help="which ip to keep; [\033[32m0\033[0m]=tcp, [\033[32m1\033[0m]=origin (first x-fwd), [\033[32m2\033[0m]=cloudflare, [\033[32m3\033[0m]=nginx, [\033[32m-1\033[0m]=closest proxy") ap2.add_argument("--rproxy", metavar="DEPTH", type=int, default=1, help="which ip to keep; [\033[32m0\033[0m]=tcp, [\033[32m1\033[0m]=origin (first x-fwd), [\033[32m2\033[0m]=cloudflare, [\033[32m3\033[0m]=nginx, [\033[32m-1\033[0m]=closest proxy")
ap2.add_argument("--webroot", metavar="PATH", type=u, default="", help="if reverse-proxying on a location instead of a dedicated subdomain, provide the location here") ap2.add_argument("--rp-loc", metavar="PATH", type=u, default="", help="if reverse-proxying on a location instead of a dedicated domain/subdomain, provide the base location here (eg. /foo/bar)")
if ANYWIN: if ANYWIN:
ap2.add_argument("--reuseaddr", action="store_true", help="set reuseaddr on listening sockets on windows; allows rapid restart of copyparty at the expense of being able to accidentally start multiple instances") ap2.add_argument("--reuseaddr", action="store_true", help="set reuseaddr on listening sockets on windows; allows rapid restart of copyparty at the expense of being able to accidentally start multiple instances")
ap2.add_argument("--s-wr-sz", metavar="B", type=int, default=256*1024, help="socket write size in bytes") ap2.add_argument("--s-wr-sz", metavar="B", type=int, default=256*1024, help="socket write size in bytes")
@ -1008,8 +1008,11 @@ def main(argv: Optional[list[str]] = None) -> None:
retry = True retry = True
lprint("\n[ {} ]:\n{}\n".format(fmtr, min_ex())) lprint("\n[ {} ]:\n{}\n".format(fmtr, min_ex()))
assert al # type: ignore try:
al.E = E # __init__ is not shared when oxidized assert al # type: ignore
al.E = E # __init__ is not shared when oxidized
except:
sys.exit(1)
if WINDOWS and not al.keep_qem: if WINDOWS and not al.keep_qem:
try: try:

View file

@ -327,7 +327,7 @@ class HttpCli(object):
if vpath.startswith(self.args.R): if vpath.startswith(self.args.R):
vpath = vpath[len(self.args.R) + 1 :] vpath = vpath[len(self.args.R) + 1 :]
else: else:
t = "incorrect --webroot or webserver config; expected vpath starting with [{}] but got [{}]" t = "incorrect --rp-loc or webserver config; expected vpath starting with [{}] but got [{}]"
self.log(t.format(self.args.R, vpath), 1) self.log(t.format(self.args.R, vpath), 1)
self.ouparam = {k: zs for k, zs in uparam.items()} self.ouparam = {k: zs for k, zs in uparam.items()}
@ -2719,13 +2719,14 @@ class HttpCli(object):
def tx_404(self, is_403: bool = False) -> bool: def tx_404(self, is_403: bool = False) -> bool:
rc = 404 rc = 404
if self.args.vague_403: if self.args.vague_403:
t = '<h1 id="n">404 not found &nbsp;┐( ´ -`)┌</h1><p id="o">or maybe you don\'t have access -- try logging in or <a href="/?h">go home</a></p>' t = '<h1 id="n">404 not found &nbsp;┐( ´ -`)┌</h1><p id="o">or maybe you don\'t have access -- try logging in or <a href="{}/?h">go home</a></p>'
elif is_403: elif is_403:
t = '<h1 id="p">403 forbiddena &nbsp;~┻━┻</h1><p id="q">you\'ll have to log in or <a href="/?h">go home</a></p>' t = '<h1 id="p">403 forbiddena &nbsp;~┻━┻</h1><p id="q">you\'ll have to log in or <a href="{}/?h">go home</a></p>'
rc = 403 rc = 403
else: else:
t = '<h1 id="n">404 not found &nbsp;┐( ´ -`)┌</h1><p><a id="r" href="/?h">go home</a></p>' t = '<h1 id="n">404 not found &nbsp;┐( ´ -`)┌</h1><p><a id="r" href="{}/?h">go home</a></p>'
t = t.format(self.args.SR)
html = self.j2s("splash", this=self, qvpath=quotep(self.vpath), msg=t) html = self.j2s("splash", this=self, qvpath=quotep(self.vpath), msg=t)
self.reply(html.encode("utf-8"), status=rc) self.reply(html.encode("utf-8"), status=rc)
return True return True

View file

@ -301,9 +301,9 @@ class SvcHub(object):
vs = [x for x in vs if x] vs = [x for x in vs if x]
setattr(al, n, vs) setattr(al, n, vs)
R = al.webroot R = al.rp_loc
if "//" in R or ":" in R: if "//" in R or ":" in R:
t = "found URL in --webroot; it should be just the location, for example /foo/bar" t = "found URL in --rp-loc; it should be just the location, for example /foo/bar"
raise Exception(t) raise Exception(t)
al.R = R = R.strip("/") al.R = R = R.strip("/")

View file

@ -5750,7 +5750,8 @@ function apply_perms(newperms) {
ebi('acc_info').innerHTML = '<span id="srv_info2"><span>' + srvinf + ebi('acc_info').innerHTML = '<span id="srv_info2"><span>' + srvinf +
'</span></span><span' + aclass + axs + L.access + '</span>' + (acct != '*' ? '</span></span><span' + aclass + axs + L.access + '</span>' + (acct != '*' ?
'<a href="/?pw=x">' + L.logout + acct + '</a>' : '<a href="/?h">Login</a>'); '<a href="' + SR + '/?pw=x">' + L.logout + acct + '</a>' :
'<a href="' + SR + '/?h">Login</a>');
var o = QSA('#ops>a[data-perm]'); var o = QSA('#ops>a[data-perm]');
for (var a = 0; a < o.length; a++) { for (var a = 0; a < o.length; a++) {

View file

@ -17,9 +17,9 @@ var Ls = {
"l1": "logg inn:", "l1": "logg inn:",
"m1": "velkommen tilbake,", "m1": "velkommen tilbake,",
"n1": "404: filen finnes ikke &nbsp;┐( ´ -`)┌", "n1": "404: filen finnes ikke &nbsp;┐( ´ -`)┌",
"o1": 'eller kanskje du ikke har tilgang? prøv å logge inn eller <a href="/?h">gå hjem</a>', "o1": 'eller kanskje du ikke har tilgang? prøv å logge inn eller <a href="' + SR + '/?h">gå hjem</a>',
"p1": "403: tilgang nektet &nbsp;~┻━┻", "p1": "403: tilgang nektet &nbsp;~┻━┻",
"q1": 'du må logge inn eller <a href="/?h">gå hjem</a>', "q1": 'du må logge inn eller <a href="' + SR + '/?h">gå hjem</a>',
"r1": "gå hjem", "r1": "gå hjem",
".s1": "kartlegg", ".s1": "kartlegg",
"t1": "handling", "t1": "handling",

View file

@ -1680,7 +1680,7 @@ function xhrchk(xhr, prefix, e404, lvl, tag) {
qsr('#cf_frame'); qsr('#cf_frame');
var fr = mknod('iframe', 'cf_frame'); var fr = mknod('iframe', 'cf_frame');
fr.src = '/?cf_challenge'; fr.src = SR + '/?cf_challenge';
document.body.appendChild(fr); document.body.appendChild(fr);
} }