u2c: add --ba argument to use basicauth instead of PW header

This allows using u2c.py with a copyparty server behind a reverseproxy
which enforces authentication through basicauth

Also expands the BadAuth check to status 401.

Closes #1150
This commit is contained in:
Leo Developer 2025-12-29 20:57:15 +01:00
parent 4642d32366
commit 76eef78374
No known key found for this signature in database
GPG key ID: 783F30D13A9C220B

View file

@ -195,7 +195,10 @@ class HCli(object):
hdrs.update(self.base_hdrs)
if self.ar.a:
hdrs["PW"] = self.ar.a
if self.ar.ba:
hdrs["Authorization"] = "Basic " + base64.b64encode(self.ar.a.encode("utf-8")).decode("utf-8")
else:
hdrs["PW"] = self.ar.a
if ctype:
hdrs["Content-Type"] = ctype
if meth == "POST" and CLEN not in hdrs:
@ -857,7 +860,7 @@ def handshake(ar, file, search):
return [], False
elif sc == 409 or "<pre>upload rejected, file already exists" in txt:
return [], False
elif sc == 403:
elif sc == 403 or sc == 401:
print("\nERROR: login required, or wrong password:\n%s" % (txt,))
raise BadAuth()
@ -1551,6 +1554,7 @@ NOTE: if server has --usernames enabled, then password is "username:password"
ap.add_argument("files", type=files_decoder, nargs="+", help="files and/or folders to process")
ap.add_argument("-v", action="store_true", help="verbose")
ap.add_argument("-a", metavar="PASSWD", help="password or $filepath")
ap.add_argument("--ba", action="store_true", help="use basic auth instead of PW header")
ap.add_argument("-s", action="store_true", help="file-search (disables upload)")
ap.add_argument("-x", type=unicode, metavar="REGEX", action="append", help="skip file if filesystem-abspath matches REGEX (option can be repeated), example: '.*/\\.hist/.*'")
ap.add_argument("--ok", action="store_true", help="continue even if some local files are inaccessible")