From abc0424c26e69dced080781b5e997b3edec8e4de Mon Sep 17 00:00:00 2001
From: ed
Date: Wed, 15 Sep 2021 21:53:30 +0200
Subject: [PATCH] show login prompt on 404
---
copyparty/httpcli.py | 21 ++++++++++++++++-----
copyparty/web/browser.css | 2 +-
copyparty/web/splash.css | 10 ++++++++++
copyparty/web/splash.html | 14 ++++++++++++--
docs/notes.sh | 4 ++--
5 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py
index b9db9a1f..f5644bda 100644
--- a/copyparty/httpcli.py
+++ b/copyparty/httpcli.py
@@ -385,7 +385,7 @@ class HttpCli(object):
if not self.can_read and not self.can_write and not self.can_get:
if self.vpath:
self.log("inaccessible: [{}]".format(self.vpath))
- raise Pebkac(404)
+ return self.tx_404()
self.uparam["h"] = False
@@ -889,8 +889,12 @@ class HttpCli(object):
pwd = self.parser.require("cppwd", 64)
self.parser.drop()
+ dst = "/?h"
+ if self.vpath:
+ dst = "/" + quotep(self.vpath)
+
ck, msg = self.get_pwd_cookie(pwd)
- html = self.j2("msg", h1=msg, h2='ack', redir="/?h")
+ html = self.j2("msg", h1=msg, h2='ack', redir=dst)
self.reply(html.encode("utf-8"), headers={"Set-Cookie": ck})
return True
@@ -1279,7 +1283,7 @@ class HttpCli(object):
break
if not editions:
- raise Pebkac(404)
+ return self.tx_404()
#
# if-modified
@@ -1598,6 +1602,7 @@ class HttpCli(object):
html = self.j2(
"splash",
this=self,
+ qvpath=quotep(self.vpath),
rvol=rvol,
wvol=wvol,
avol=avol,
@@ -1611,6 +1616,12 @@ class HttpCli(object):
self.reply(html.encode("utf-8"))
return True
+ def tx_404(self):
+ m = '404 not found
or maybe you don\'t have access -- try logging in or go home
' + html = self.j2("splash", this=self, qvpath=quotep(self.vpath), msg=m) + self.reply(html.encode("utf-8"), status=404) + return True + def scanvol(self): if not self.can_read or not self.can_write: raise Pebkac(403, "not allowed for user " + self.uname) @@ -1784,7 +1795,7 @@ class HttpCli(object): try: st = bos.stat(abspath) except: - raise Pebkac(404) + return self.tx_404() if rem.startswith(".hist/up2k.") or ( rem.endswith("/dir.txt") and rem.startswith(".hist/th/") @@ -1926,7 +1937,7 @@ class HttpCli(object): return True if not stat.S_ISDIR(st.st_mode): - raise Pebkac(404) + return self.tx_404() if "zip" in self.uparam or "tar" in self.uparam: raise Pebkac(403) diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index 4ae0494a..649bbe45 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -571,7 +571,7 @@ html.light #wfm a:not(.en) { padding: .5em; border-radius: 0 1em 1em 0; border-width: .15em .3em .3em 0; - max-width: 40em; + max-width: 41em; } .opbox input { margin: .5em; diff --git a/copyparty/web/splash.css b/copyparty/web/splash.css index 0da733b3..fda68f2c 100644 --- a/copyparty/web/splash.css +++ b/copyparty/web/splash.css @@ -55,6 +55,16 @@ table { .btns { margin: 1em 0; } +#msg { + margin: 3em 0; +} +#msg h1 { + margin-bottom: 0; +} +#msg h1 + p { + margin-top: .3em; + text-align: right; +} html.dark, diff --git a/copyparty/web/splash.html b/copyparty/web/splash.html index d28f702e..c8c7d576 100644 --- a/copyparty/web/splash.html +++ b/copyparty/web/splash.html @@ -12,7 +12,17 @@hello {{ this.uname }}
+ {%- if this.uname == '*' %} +howdy stranger (you're not logged in)
+ {%- else %} +welcome back, {{ this.uname }}
+ {%- endif %} + + {%- if msg %} +