Skip to content

Commit

Permalink
remember url-hash during login from 403
Browse files Browse the repository at this point in the history
  • Loading branch information
9001 committed May 5, 2024
1 parent da091ae commit f849197
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions copyparty/httpcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,10 @@ def handle_post_binary(self) -> bool:
def handle_login(self) -> bool:
assert self.parser
pwd = self.parser.require("cppwd", 64)
try:
uhash = self.parser.require("uhash", 256)
except:
uhash = ""
self.parser.drop()

self.out_headerlist = [
Expand All @@ -2314,6 +2318,11 @@ def handle_login(self) -> bool:

dst += self.ourlq()

uhash = uhash.lstrip("#")
if uhash not in ("", "-"):
dst += "&" if "?" in dst else "?"
dst += "_=1#" + html_escape(uhash, True, True)

msg = self.get_pwd_cookie(pwd)
html = self.j2s("msg", h1=msg, h2='<a href="' + dst + '">ack</a>', redir=dst)
self.reply(html.encode("utf-8"))
Expand Down Expand Up @@ -4876,8 +4885,11 @@ def tx_browser(self) -> bool:

ogh["og:title"] = title

zs = '\t<meta property="%s" content="%s">'
oghs = [zs % (k, html_escape(str(v))) for k, v in ogh.items()]
oghs = [
'\t<meta property="%s" content="%s">'
% (k, html_escape(str(v), True, True))
for k, v in ogh.items()
]
zs = self.html_head + "\n%s\n" % ("\n".join(oghs),)
self.html_head = zs.replace("\n\n", "\n")

Expand Down
1 change: 1 addition & 0 deletions copyparty/web/splash.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h1 id="l">login for more:</h1>
<form method="post" enctype="multipart/form-data" action="{{ r }}/{{ qvpath }}">
<input type="hidden" name="act" value="login" />
<input type="password" name="cppwd" placeholder=" password" />
<input type="hidden" name="uhash" id="uhash" value="x" />
<input type="submit" value="Login" />
{% if ahttps %}
<a id="w" href="{{ ahttps }}">switch to https</a>
Expand Down
2 changes: 2 additions & 0 deletions copyparty/web/splash.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ if (!ebi('c') && o.offsetTop + o.offsetHeight < window.innerHeight)
o = ebi('u');
if (o && /[0-9]+$/.exec(o.innerHTML))
o.innerHTML = shumantime(o.innerHTML);

ebi('uhash').value = '' + location.hash;

0 comments on commit f849197

Please sign in to comment.