From 7fd1d6a4e848fa1f0da4709e16585c956098b84f Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 11 Dec 2022 21:09:50 +0000 Subject: [PATCH] rename --webroot to --rp-loc and fix related bugs --- copyparty/__main__.py | 9 ++++++--- copyparty/httpcli.py | 9 +++++---- copyparty/svchub.py | 4 ++-- copyparty/web/browser.js | 3 ++- copyparty/web/splash.js | 4 ++-- copyparty/web/util.js | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 479d569d..5c60d610 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -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("--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("--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: 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") @@ -1008,8 +1008,11 @@ def main(argv: Optional[list[str]] = None) -> None: retry = True lprint("\n[ {} ]:\n{}\n".format(fmtr, min_ex())) - assert al # type: ignore - al.E = E # __init__ is not shared when oxidized + try: + assert al # type: ignore + al.E = E # __init__ is not shared when oxidized + except: + sys.exit(1) if WINDOWS and not al.keep_qem: try: diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 0190aec3..e64466a8 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -327,7 +327,7 @@ class HttpCli(object): if vpath.startswith(self.args.R): vpath = vpath[len(self.args.R) + 1 :] 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.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: rc = 404 if self.args.vague_403: - t = '

404 not found  ┐( ´ -`)┌

or maybe you don\'t have access -- try logging in or go home

' + t = '

404 not found  ┐( ´ -`)┌

or maybe you don\'t have access -- try logging in or go home

' elif is_403: - t = '

403 forbiddena  ~┻━┻

you\'ll have to log in or go home

' + t = '

403 forbiddena  ~┻━┻

you\'ll have to log in or go home

' rc = 403 else: - t = '

404 not found  ┐( ´ -`)┌

go home

' + t = '

404 not found  ┐( ´ -`)┌

go home

' + t = t.format(self.args.SR) html = self.j2s("splash", this=self, qvpath=quotep(self.vpath), msg=t) self.reply(html.encode("utf-8"), status=rc) return True diff --git a/copyparty/svchub.py b/copyparty/svchub.py index d12cdb4f..b235325a 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -301,9 +301,9 @@ class SvcHub(object): vs = [x for x in vs if x] setattr(al, n, vs) - R = al.webroot + R = al.rp_loc 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) al.R = R = R.strip("/") diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index a7ca5351..682fbcc9 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -5750,7 +5750,8 @@ function apply_perms(newperms) { ebi('acc_info').innerHTML = '' + srvinf + '' + (acct != '*' ? - '' + L.logout + acct + '' : 'Login'); + '' + L.logout + acct + '' : + 'Login'); var o = QSA('#ops>a[data-perm]'); for (var a = 0; a < o.length; a++) { diff --git a/copyparty/web/splash.js b/copyparty/web/splash.js index 7bb9037c..a35bee09 100644 --- a/copyparty/web/splash.js +++ b/copyparty/web/splash.js @@ -17,9 +17,9 @@ var Ls = { "l1": "logg inn:", "m1": "velkommen tilbake,", "n1": "404: filen finnes ikke  ┐( ´ -`)┌", - "o1": 'eller kanskje du ikke har tilgang? prøv å logge inn eller gå hjem', + "o1": 'eller kanskje du ikke har tilgang? prøv å logge inn eller gå hjem', "p1": "403: tilgang nektet  ~┻━┻", - "q1": 'du må logge inn eller gå hjem', + "q1": 'du må logge inn eller gå hjem', "r1": "gå hjem", ".s1": "kartlegg", "t1": "handling", diff --git a/copyparty/web/util.js b/copyparty/web/util.js index ea22f802..313683be 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1680,7 +1680,7 @@ function xhrchk(xhr, prefix, e404, lvl, tag) { qsr('#cf_frame'); var fr = mknod('iframe', 'cf_frame'); - fr.src = '/?cf_challenge'; + fr.src = SR + '/?cf_challenge'; document.body.appendChild(fr); }