copyparty 1.19.4__py3-none-any.whl → 1.19.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- copyparty/__main__.py +85 -32
- copyparty/__version__.py +2 -2
- copyparty/authsrv.py +28 -1
- copyparty/broker_util.py +0 -1
- copyparty/cert.py +1 -0
- copyparty/cfg.py +2 -0
- copyparty/ftpd.py +5 -5
- copyparty/httpcli.py +46 -30
- copyparty/mdns.py +2 -2
- copyparty/multicast.py +3 -3
- copyparty/pwhash.py +1 -0
- copyparty/smbd.py +1 -1
- copyparty/stolen/qrcodegen.py +19 -0
- copyparty/svchub.py +54 -10
- copyparty/tcpsrv.py +37 -4
- copyparty/up2k.py +13 -2
- copyparty/util.py +30 -0
- copyparty/web/a/u2c.py +6 -6
- copyparty/web/browser.css.gz +0 -0
- copyparty/web/browser.js.gz +0 -0
- copyparty/web/md.html +2 -1
- copyparty/web/md.js.gz +0 -0
- copyparty/web/md2.js.gz +0 -0
- copyparty/web/mde.html +2 -1
- copyparty/web/splash.js.gz +0 -0
- copyparty/web/ui.css.gz +0 -0
- copyparty/web/up2k.js.gz +0 -0
- {copyparty-1.19.4.dist-info → copyparty-1.19.6.dist-info}/METADATA +95 -7
- {copyparty-1.19.4.dist-info → copyparty-1.19.6.dist-info}/RECORD +33 -33
- {copyparty-1.19.4.dist-info → copyparty-1.19.6.dist-info}/WHEEL +0 -0
- {copyparty-1.19.4.dist-info → copyparty-1.19.6.dist-info}/entry_points.txt +0 -0
- {copyparty-1.19.4.dist-info → copyparty-1.19.6.dist-info}/licenses/LICENSE +0 -0
- {copyparty-1.19.4.dist-info → copyparty-1.19.6.dist-info}/top_level.txt +0 -0
copyparty/__main__.py
CHANGED
@@ -190,35 +190,41 @@ def init_E(EE ) :
|
|
190
190
|
(unicode, "/tmp"),
|
191
191
|
]
|
192
192
|
errs = []
|
193
|
-
for
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
193
|
+
for npath, (pf, pa) in enumerate(paths):
|
194
|
+
p = ""
|
195
|
+
try:
|
196
|
+
p = pf(pa)
|
197
|
+
if not p or p.startswith("~"):
|
198
|
+
continue
|
199
|
+
|
200
|
+
p = os.path.normpath(p)
|
201
|
+
if os.path.isdir(p) and os.listdir(p):
|
202
|
+
mkdir = False
|
203
|
+
else:
|
204
|
+
mkdir = True
|
205
|
+
os.mkdir(p)
|
206
|
+
|
207
|
+
p = os.path.join(p, "copyparty")
|
208
|
+
if not os.path.isdir(p):
|
209
|
+
os.mkdir(p)
|
210
|
+
|
211
|
+
if npath > 1:
|
212
|
+
t = "Using %s/copyparty [%s] for config; filekeys/dirkeys will change on every restart. Consider setting XDG_CONFIG_HOME or giving the unix-user a ~/.config/"
|
213
|
+
errs.append(t % (pa, p))
|
214
|
+
elif mkdir:
|
215
|
+
t = "Using %s/copyparty [%s] for config%s (Warning: %s did not exist and was created just now)"
|
216
|
+
errs.append(t % (pa, p, " instead" if npath else "", pa))
|
217
|
+
elif errs:
|
218
|
+
errs.append("Using %s/copyparty [%s] instead" % (pa, p))
|
219
|
+
|
220
|
+
if errs:
|
221
|
+
warn(". ".join(errs))
|
222
|
+
|
223
|
+
return p # type: ignore
|
224
|
+
except Exception as ex:
|
225
|
+
if p and npath < 2:
|
226
|
+
t = "Unable to store config in %s [%s] due to %r"
|
227
|
+
errs.append(t % (pa, p, ex))
|
222
228
|
|
223
229
|
raise Exception("could not find a writable path for config")
|
224
230
|
|
@@ -662,6 +668,42 @@ def get_sects():
|
|
662
668
|
"""
|
663
669
|
),
|
664
670
|
],
|
671
|
+
[
|
672
|
+
"auth-ord",
|
673
|
+
"authentication precedence",
|
674
|
+
dedent(
|
675
|
+
"""
|
676
|
+
\033[33m--auth-ord\033[0m is a comma-separated list of auth options
|
677
|
+
(one or more of the [\033[35moptions\033[0m] below); first one wins
|
678
|
+
|
679
|
+
[\033[35mpw\033[0m] is conventional login, for example the "\033[36mPW\033[0m" header,
|
680
|
+
or the \033[36m?pw=\033[0m[...] URL-suffix, or a valid session cookie
|
681
|
+
(see \033[33m--help-auth\033[0m)
|
682
|
+
|
683
|
+
[\033[35midp\033[0m] is a username provided in the http-request-header
|
684
|
+
defined by \033[33m--idp-h-usr\033[0m and/or \033[33m--idp-hm-usr\033[0m, which is
|
685
|
+
provided by an authentication middleware such as
|
686
|
+
authentik, authelia, tailscale, ... (see \033[33m--help-idp\033[0m)
|
687
|
+
|
688
|
+
[\033[35midp-h\033[0m] is specifically an \033[33m--idp-h-usr\033[0m header,
|
689
|
+
[\033[35midp-hm\033[0m] is specifically an \033[33m--idp-hm-usr\033[0m header;
|
690
|
+
[\033[35midp\033[0m] is the same as [\033[35midp-hm,idp-h\033[0m]
|
691
|
+
|
692
|
+
[\033[35mipu\033[0m] is a mapping from an IP-address to a username,
|
693
|
+
auto-authing that client-IP to that account
|
694
|
+
(see the description of \033[36m--ipu\033[0m in \033[33m--help\033[0m)
|
695
|
+
|
696
|
+
NOTE: even if an option (\033[35mpw\033[0m/\033[35mipu\033[0m/...) is not in the list,
|
697
|
+
it may still be enabled and can still take effect if
|
698
|
+
none of the other alternatives identify the user
|
699
|
+
|
700
|
+
NOTE: if [\033[35mipu\033[0m] is in the list, it must be FIRST or LAST
|
701
|
+
|
702
|
+
NOTE: if [\033[35mpw\033[0m] is not in the list, the logout-button
|
703
|
+
will be hidden when any idp feature is enabled
|
704
|
+
"""
|
705
|
+
),
|
706
|
+
],
|
665
707
|
[
|
666
708
|
"flags",
|
667
709
|
"list of volflags",
|
@@ -767,7 +809,7 @@ def get_sects():
|
|
767
809
|
\033[36mc0\033[35m show all process output (default)
|
768
810
|
\033[36mc1\033[35m show only stderr
|
769
811
|
\033[36mc2\033[35m show only stdout
|
770
|
-
\033[36mc3\033[35m mute all process
|
812
|
+
\033[36mc3\033[35m mute all process output
|
771
813
|
\033[0m
|
772
814
|
examples:
|
773
815
|
|
@@ -1106,6 +1148,10 @@ def add_qr(ap, tty):
|
|
1106
1148
|
ap2.add_argument("--qrp", metavar="CELLS", type=int, default=4, help="padding (spec says 4 or more, but 1 is usually fine)")
|
1107
1149
|
ap2.add_argument("--qrz", metavar="N", type=int, default=0, help="[\033[32m1\033[0m]=1x, [\033[32m2\033[0m]=2x, [\033[32m0\033[0m]=auto (try [\033[32m2\033[0m] on broken fonts)")
|
1108
1150
|
ap2.add_argument("--qr-pin", metavar="N", type=int, default=0, help="sticky/pin the qr-code to always stay on-screen; [\033[32m0\033[0m]=disabled, [\033[32m1\033[0m]=with-url, [\033[32m2\033[0m]=just-qr")
|
1151
|
+
ap2.add_argument("--qr-wait", metavar="SEC", type=float, default=0, help="wait \033[33mSEC\033[0m before printing the qr-code to the log")
|
1152
|
+
ap2.add_argument("--qr-every", metavar="SEC", type=float, default=0, help="print the qr-code every \033[33mSEC\033[0m (try this with/without --qr-pin in case of issues)")
|
1153
|
+
ap2.add_argument("--qr-winch", metavar="SEC", type=float, default=0, help="when --qr-pin is enabled, check for terminal size change every \033[33mSEC\033[0m")
|
1154
|
+
ap2.add_argument("--qr-file", metavar="TXT", type=u, action="append", help="\033[34mREPEATABLE:\033[0m write qr-code to file.\n └─To create txt or svg, \033[33mTXT\033[0m is Filepath:Zoom:Pad, for example [\033[32mqr.txt:1:2\033[0m]\n └─To create png or gif, \033[33mTXT\033[0m is Filepath:Zoom:Pad:Foreground:Background, for example [\033[32mqr.png:8:2:333333:ffcc55\033[0m], or [\033[32mqr.png:8:2::ffcc55\033[0m] for transparent")
|
1109
1155
|
|
1110
1156
|
|
1111
1157
|
def add_fs(ap):
|
@@ -1230,7 +1276,7 @@ def add_auth(ap):
|
|
1230
1276
|
ses_db = os.path.join(E.cfg, "sessions.db")
|
1231
1277
|
ap2 = ap.add_argument_group("IdP / identity provider / user authentication options")
|
1232
1278
|
ap2.add_argument("--idp-h-usr", metavar="HN", type=u, action="append", help="\033[34mREPEATABLE:\033[0m bypass the copyparty authentication checks if the request-header \033[33mHN\033[0m contains a username to associate the request with (for use with authentik/oauth/...)\n\033[1;31mWARNING:\033[0m if you enable this, make sure clients are unable to specify this header themselves; must be washed away and replaced by a reverse-proxy")
|
1233
|
-
ap2.add_argument("--idp-hm-usr", metavar="
|
1279
|
+
ap2.add_argument("--idp-hm-usr", metavar="T", type=u, action="append", help="\033[34mREPEATABLE:\033[0m bypass the copyparty authentication checks if the request-header \033[33mT\033[0m is provided, and its value exists in a mapping defined by this option; see --help-idp")
|
1234
1280
|
ap2.add_argument("--idp-h-grp", metavar="HN", type=u, default="", help="assume the request-header \033[33mHN\033[0m contains the groupname of the requesting user; can be referenced in config files for group-based access control")
|
1235
1281
|
ap2.add_argument("--idp-h-key", metavar="HN", type=u, default="", help="optional but recommended safeguard; your reverse-proxy will insert a secret header named \033[33mHN\033[0m into all requests, and the other IdP headers will be ignored if this header is not present")
|
1236
1282
|
ap2.add_argument("--idp-gsep", metavar="RE", type=u, default="|:;+,", help="if there are multiple groups in \033[33m--idp-h-grp\033[0m, they are separated by one of the characters in \033[33mRE\033[0m")
|
@@ -1238,6 +1284,7 @@ def add_auth(ap):
|
|
1238
1284
|
ap2.add_argument("--idp-store", metavar="N", type=int, default=1, help="how to use \033[33m--idp-db\033[0m; [\033[32m0\033[0m] = entirely disable, [\033[32m1\033[0m] = write-only (effectively disabled), [\033[32m2\033[0m] = remember users, [\033[32m3\033[0m] = remember users and groups.\nNOTE: Will remember and restore the IdP-volumes of all users for all eternity if set to 2 or 3, even when user is deleted from your IdP")
|
1239
1285
|
ap2.add_argument("--idp-adm", metavar="U,U", type=u, default="", help="comma-separated list of users allowed to use /?idp (the cache management UI)")
|
1240
1286
|
ap2.add_argument("--idp-cookie", metavar="S", type=int, default=0, help="generate a session-token for IdP users which is written to cookie \033[33mcppws\033[0m (or \033[33mcppwd\033[0m if plaintext), to reduce the load on the IdP server, lifetime \033[33mS\033[0m seconds.\n └─note: The expiration time is a client hint only; the actual lifetime of the session-token is infinite (until next restart with \033[33m--ses-db\033[0m wiped)")
|
1287
|
+
ap2.add_argument("--auth-ord", metavar="TXT", type=u, default="idp,ipu", help="controls auth precedence; examples: [\033[32mpw,idp,ipu\033[0m], [\033[32mipu,pw,idp\033[0m], see --help-auth-ord")
|
1241
1288
|
ap2.add_argument("--no-bauth", action="store_true", help="disable basic-authentication support; do not accept passwords from the 'Authenticate' header at all. NOTE: This breaks support for the android app")
|
1242
1289
|
ap2.add_argument("--bauth-last", action="store_true", help="keeps basic-authentication enabled, but only as a last-resort; if a cookie is also provided then the cookie wins")
|
1243
1290
|
ap2.add_argument("--ses-db", metavar="PATH", type=u, default=ses_db, help="where to store the sessions database (if you run multiple copyparty instances, make sure they use different DBs)")
|
@@ -1248,6 +1295,10 @@ def add_auth(ap):
|
|
1248
1295
|
ap2.add_argument("--ipr", metavar="CIDR=USR", type=u, action="append", help="\033[34mREPEATABLE:\033[0m username \033[33mUSR\033[0m can only connect from an IP matching one or more \033[33mCIDR\033[0m (comma-sep.); example: [\033[32m192.168.123.0/24,172.16.0.0/16=dave]")
|
1249
1296
|
ap2.add_argument("--have-idp-hdrs", type=u, default="", help=argparse.SUPPRESS)
|
1250
1297
|
ap2.add_argument("--have-ipu-or-ipr", type=u, default="", help=argparse.SUPPRESS)
|
1298
|
+
ap2.add_argument("--ao-idp-before-pw", type=u, default="", help=argparse.SUPPRESS)
|
1299
|
+
ap2.add_argument("--ao-h-before-hm", type=u, default="", help=argparse.SUPPRESS)
|
1300
|
+
ap2.add_argument("--ao-ipu-wins", type=u, default="", help=argparse.SUPPRESS)
|
1301
|
+
ap2.add_argument("--ao-has-pw", type=u, default="", help=argparse.SUPPRESS)
|
1251
1302
|
|
1252
1303
|
|
1253
1304
|
def add_chpw(ap):
|
@@ -1487,6 +1538,7 @@ def add_logging(ap):
|
|
1487
1538
|
ap2.add_argument("--log-utc", action="store_true", help="do not use local timezone; assume the TZ env-var is UTC (tiny bit faster)")
|
1488
1539
|
ap2.add_argument("--log-tdec", metavar="N", type=int, default=3, help="timestamp resolution / number of timestamp decimals")
|
1489
1540
|
ap2.add_argument("--log-badpwd", metavar="N", type=int, default=2, help="log failed login attempt passwords: 0=terse, 1=plaintext, 2=hashed")
|
1541
|
+
ap2.add_argument("--log-badxml", action="store_true", help="log any invalid XML received from a client")
|
1490
1542
|
ap2.add_argument("--log-conn", action="store_true", help="debug: print tcp-server msgs")
|
1491
1543
|
ap2.add_argument("--log-htp", action="store_true", help="debug: print http-server threadpool scaling")
|
1492
1544
|
ap2.add_argument("--ihead", metavar="HEADER", type=u, action='append', help="print request \033[33mHEADER\033[0m; [\033[32m*\033[0m]=all")
|
@@ -1624,6 +1676,7 @@ def add_db_metadata(ap):
|
|
1624
1676
|
|
1625
1677
|
def add_txt(ap):
|
1626
1678
|
ap2 = ap.add_argument_group("textfile options")
|
1679
|
+
ap2.add_argument("--md-no-br", action="store_true", help="markdown: disable newline-is-newline; will only render a newline into the html given two trailing spaces or a double-newline (volflag=md_no_br)")
|
1627
1680
|
ap2.add_argument("--md-hist", metavar="TXT", type=u, default="s", help="where to store old version of markdown files; [\033[32ms\033[0m]=subfolder, [\033[32mv\033[0m]=volume-histpath, [\033[32mn\033[0m]=nope/disabled (volflag=md_hist)")
|
1628
1681
|
ap2.add_argument("--txt-eol", metavar="TYPE", type=u, default="", help="enable EOL conversion when writing documents; supported: CRLF, LF (volflag=txt_eol)")
|
1629
1682
|
ap2.add_argument("-mcr", metavar="SEC", type=int, default=60, help="the textfile editor will check for serverside changes every \033[33mSEC\033[0m seconds")
|
@@ -1957,7 +2010,7 @@ def main(argv = None) :
|
|
1957
2010
|
if not HAVE_IPV6 and al.i == "::":
|
1958
2011
|
al.i = "0.0.0.0"
|
1959
2012
|
|
1960
|
-
al.i = al.i.split(",")
|
2013
|
+
al.i = [x.strip() for x in al.i.split(",")]
|
1961
2014
|
try:
|
1962
2015
|
if "-" in al.p:
|
1963
2016
|
lo, hi = [int(x) for x in al.p.split("-")]
|
copyparty/__version__.py
CHANGED
copyparty/authsrv.py
CHANGED
@@ -1320,6 +1320,10 @@ class AuthSrv(object):
|
|
1320
1320
|
zt = split_cfg_ln(ln)
|
1321
1321
|
for zs, za in zt.items():
|
1322
1322
|
zs = zs.lstrip("-")
|
1323
|
+
if "=" in zs:
|
1324
|
+
t = "WARNING: found an option named [%s] in your [global] config; did you mean to say [%s: %s] instead?"
|
1325
|
+
zs1, zs2 = zs.split("=", 1)
|
1326
|
+
self.log(t % (zs, zs1, zs2), 3)
|
1323
1327
|
if za is True:
|
1324
1328
|
self._e("└─argument [{}]".format(zs))
|
1325
1329
|
else:
|
@@ -1329,6 +1333,10 @@ class AuthSrv(object):
|
|
1329
1333
|
if cat == cata:
|
1330
1334
|
try:
|
1331
1335
|
u, p = [zs.strip() for zs in ln.split(":", 1)]
|
1336
|
+
if "=" in u and not p:
|
1337
|
+
t = "WARNING: found username [%s] in your [accounts] config; did you mean to say [%s: %s] instead?"
|
1338
|
+
zs1, zs2 = u.split("=", 1)
|
1339
|
+
self.log(t % (u, zs1, zs2), 3)
|
1332
1340
|
self._l(ln, 5, "account [{}], password [{}]".format(u, p))
|
1333
1341
|
acct[u] = p
|
1334
1342
|
except:
|
@@ -1399,6 +1407,10 @@ class AuthSrv(object):
|
|
1399
1407
|
zd = split_cfg_ln(ln)
|
1400
1408
|
fstr = ""
|
1401
1409
|
for sk, sv in zd.items():
|
1410
|
+
if "=" in sk:
|
1411
|
+
t = "WARNING: found a volflag named [%s] in your config; did you mean to say [%s: %s] instead?"
|
1412
|
+
zs1, zs2 = sk.split("=", 1)
|
1413
|
+
self.log(t % (sk, zs1, zs2), 3)
|
1402
1414
|
bad = re.sub(r"[a-z0-9_-]", "", sk).lstrip("-")
|
1403
1415
|
if bad:
|
1404
1416
|
err = "bad characters [{}] in volflag name [{}]; "
|
@@ -1639,6 +1651,7 @@ class AuthSrv(object):
|
|
1639
1651
|
# accept both , and : as separators between usernames
|
1640
1652
|
zs1, zs2 = x.replace("=", ":").split(":", 1)
|
1641
1653
|
grps[zs1] = zs2.replace(":", ",").split(",")
|
1654
|
+
grps[zs1] = [x.strip() for x in grps[zs1]]
|
1642
1655
|
except:
|
1643
1656
|
t = '\n invalid value "{}" for argument --grp, must be groupname:username1,username2,...'
|
1644
1657
|
raise Exception(t.format(x))
|
@@ -1692,6 +1705,7 @@ class AuthSrv(object):
|
|
1692
1705
|
|
1693
1706
|
self.args.have_idp_hdrs = bool(self.args.idp_h_usr or self.args.idp_hm_usr)
|
1694
1707
|
self.args.have_ipu_or_ipr = bool(self.args.ipu or self.args.ipr)
|
1708
|
+
self.setup_auth_ord()
|
1695
1709
|
|
1696
1710
|
self.setup_pwhash(acct)
|
1697
1711
|
defpw = acct.copy()
|
@@ -2790,7 +2804,8 @@ class AuthSrv(object):
|
|
2790
2804
|
"have_mv": not self.args.no_mv,
|
2791
2805
|
"have_del": not self.args.no_del,
|
2792
2806
|
"have_unpost": int(self.args.unpost),
|
2793
|
-
"have_emp": self.args.emp,
|
2807
|
+
"have_emp": int(self.args.emp),
|
2808
|
+
"md_no_br": int(vf.get("md_no_br") or 0),
|
2794
2809
|
"ext_th": vf.get("ext_th_d") or {},
|
2795
2810
|
"sb_md": "" if "no_sb_md" in vf else (vf.get("md_sbf") or "y"),
|
2796
2811
|
"sba_md": vf.get("md_sba") or "",
|
@@ -2840,6 +2855,18 @@ class AuthSrv(object):
|
|
2840
2855
|
zs = str(vol.flags.get("tcolor") or self.args.tcolor)
|
2841
2856
|
vol.flags["tcolor"] = zs.lstrip("#")
|
2842
2857
|
|
2858
|
+
def setup_auth_ord(self) :
|
2859
|
+
ao = [x.strip() for x in self.args.auth_ord.split(",")]
|
2860
|
+
if "idp" in ao:
|
2861
|
+
zi = ao.index("idp")
|
2862
|
+
ao = ao[:zi] + ["idp-hm", "idp-h"] + ao[zi:]
|
2863
|
+
zsl = "pw idp-h idp-hm ipu".split()
|
2864
|
+
pw, h, hm, ipu = [ao.index(x) if x in ao else 99 for x in zsl]
|
2865
|
+
self.args.ao_idp_before_pw = min(h, hm) < pw
|
2866
|
+
self.args.ao_h_before_hm = h < hm
|
2867
|
+
self.args.ao_ipu_wins = ipu == 0
|
2868
|
+
self.args.ao_have_pw = pw < 99
|
2869
|
+
|
2843
2870
|
def load_idp_db(self, quiet=False) :
|
2844
2871
|
# mutex me
|
2845
2872
|
level = self.args.idp_store
|
copyparty/broker_util.py
CHANGED
copyparty/cert.py
CHANGED
@@ -126,6 +126,7 @@ def _gen_srv(log , args, netdevs ):
|
|
126
126
|
nlog = lambda msg, c=0: log("cert-gen-srv", msg, c)
|
127
127
|
|
128
128
|
names = args.crt_ns.split(",") if args.crt_ns else []
|
129
|
+
names = [x.strip() for x in names]
|
129
130
|
if not args.crt_exact:
|
130
131
|
for n in names[:]:
|
131
132
|
names.append("*.{}".format(n))
|
copyparty/cfg.py
CHANGED
@@ -44,6 +44,7 @@ def vf_bmap() :
|
|
44
44
|
"gsel",
|
45
45
|
"hardlink",
|
46
46
|
"magic",
|
47
|
+
"md_no_br",
|
47
48
|
"no_db_ip",
|
48
49
|
"no_sb_md",
|
49
50
|
"no_sb_lg",
|
@@ -324,6 +325,7 @@ flagcats = {
|
|
324
325
|
"og_ua": "if defined: only send OG html if useragent matches this regex",
|
325
326
|
},
|
326
327
|
"textfiles": {
|
328
|
+
"md_no_br": "newline only on double-newline or two tailing spaces",
|
327
329
|
"md_hist": "where to put markdown backups; s=subfolder, v=volHist, n=nope",
|
328
330
|
"exp": "enable textfile expansion; see --help-exp",
|
329
331
|
"exp_md": "placeholders to expand in markdown files; see --help",
|
copyparty/ftpd.py
CHANGED
@@ -64,13 +64,13 @@ class FtpAuth(DummyAuthorizer):
|
|
64
64
|
if ip.startswith("::ffff:"):
|
65
65
|
ip = ip[7:]
|
66
66
|
|
67
|
-
|
67
|
+
ipn = ipnorm(ip)
|
68
68
|
bans = self.hub.bans
|
69
|
-
if
|
70
|
-
rt = bans[
|
69
|
+
if ipn in bans:
|
70
|
+
rt = bans[ipn] - time.time()
|
71
71
|
if rt < 0:
|
72
72
|
logging.info("client unbanned")
|
73
|
-
del bans[
|
73
|
+
del bans[ipn]
|
74
74
|
else:
|
75
75
|
raise AuthenticationFailed("banned")
|
76
76
|
|
@@ -382,7 +382,7 @@ class FtpFs(AbstractedFS):
|
|
382
382
|
svp = join(self.cwd, src).lstrip("/")
|
383
383
|
dvp = join(self.cwd, dst).lstrip("/")
|
384
384
|
try:
|
385
|
-
self.hub.up2k.handle_mv(self.uname, self.h.cli_ip, svp, dvp)
|
385
|
+
self.hub.up2k.handle_mv("", self.uname, self.h.cli_ip, svp, dvp)
|
386
386
|
except Exception as ex:
|
387
387
|
raise FSE(str(ex))
|
388
388
|
|
copyparty/httpcli.py
CHANGED
@@ -12,7 +12,6 @@ import random
|
|
12
12
|
import re
|
13
13
|
import socket
|
14
14
|
import stat
|
15
|
-
import string
|
16
15
|
import sys
|
17
16
|
import threading # typechk
|
18
17
|
import time
|
@@ -31,7 +30,7 @@ try:
|
|
31
30
|
except:
|
32
31
|
pass
|
33
32
|
|
34
|
-
from .__init__ import ANYWIN,
|
33
|
+
from .__init__ import ANYWIN, RES, TYPE_CHECKING, EnvParams, unicode
|
35
34
|
from .__version__ import S_VERSION
|
36
35
|
from .authsrv import LEELOO_DALLAS, VFS # typechk
|
37
36
|
from .bos import bos
|
@@ -66,6 +65,7 @@ from .util import (
|
|
66
65
|
exclude_dotfiles,
|
67
66
|
formatdate,
|
68
67
|
fsenc,
|
68
|
+
gen_content_disposition,
|
69
69
|
gen_filekey,
|
70
70
|
gen_filekey_dbg,
|
71
71
|
gencookie,
|
@@ -389,10 +389,10 @@ class HttpCli(object):
|
|
389
389
|
zsl = [
|
390
390
|
" rproxy: %d if this client's IP-address is [%s]"
|
391
391
|
% (-1 - zd, zs.strip())
|
392
|
-
for zd, zs in enumerate(zsl)
|
392
|
+
for zd, zs in enumerate(zsl[::-1])
|
393
393
|
]
|
394
|
-
t = 'could not determine the client\'s IP-address because the global-option --rproxy has not been configured, so the request-header [%s] specified by global-option --xff-hdr cannot be used safely! Please see the "reverse-proxy" section in the readme. The best approach is to configure your reverse-proxy to give copyparty the exact IP-address to assume (perhaps in another header), but you may also try the following:'
|
395
|
-
t = t % (self.args.xff_hdr,)
|
394
|
+
t = 'could not determine the client\'s IP-address because the global-option --rproxy has not been configured, so the request-header [%s] specified by global-option --xff-hdr cannot be used safely! The raw header value was [%s]. Please see the "reverse-proxy" section in the readme. The best approach is to configure your reverse-proxy to give copyparty the exact IP-address to assume (perhaps in another header), but you may also try the following:'
|
395
|
+
t = t % (self.args.xff_hdr, zso)
|
396
396
|
self.log("%s\n\n%s\n" % (t, "\n".join(zsl)), 3)
|
397
397
|
|
398
398
|
pip = self.conn.addr[0]
|
@@ -619,7 +619,9 @@ class HttpCli(object):
|
|
619
619
|
or "*"
|
620
620
|
)
|
621
621
|
|
622
|
-
if self.args.have_idp_hdrs
|
622
|
+
if self.args.have_idp_hdrs and (
|
623
|
+
self.uname == "*" or self.args.ao_idp_before_pw
|
624
|
+
):
|
623
625
|
idp_usr = ""
|
624
626
|
if self.args.idp_hm_usr:
|
625
627
|
for hn, hmv in self.args.idp_hm_usr_p.items():
|
@@ -632,9 +634,9 @@ class HttpCli(object):
|
|
632
634
|
if idp_usr:
|
633
635
|
break
|
634
636
|
for hn in self.args.idp_h_usr:
|
635
|
-
if idp_usr:
|
637
|
+
if idp_usr and not self.args.ao_h_before_hm:
|
636
638
|
break
|
637
|
-
idp_usr = self.headers.get(hn)
|
639
|
+
idp_usr = self.headers.get(hn) or idp_usr
|
638
640
|
if idp_usr:
|
639
641
|
idp_grp = (
|
640
642
|
self.headers.get(self.args.idp_h_grp) or ""
|
@@ -683,7 +685,10 @@ class HttpCli(object):
|
|
683
685
|
if idp_usr in self.asrv.vfs.aread:
|
684
686
|
self.pw = ""
|
685
687
|
self.uname = idp_usr
|
686
|
-
self.
|
688
|
+
if self.args.ao_have_pw:
|
689
|
+
self.html_head += "<script>var is_idp=1</script>\n"
|
690
|
+
else:
|
691
|
+
self.html_head += "<script>var is_idp=2</script>\n"
|
687
692
|
zs = self.asrv.ases.get(idp_usr)
|
688
693
|
if zs:
|
689
694
|
self.set_idp_cookie(zs)
|
@@ -691,7 +696,7 @@ class HttpCli(object):
|
|
691
696
|
self.log("unknown username: %r" % (idp_usr,), 1)
|
692
697
|
|
693
698
|
if self.args.have_ipu_or_ipr:
|
694
|
-
if self.args.ipu and self.uname == "*":
|
699
|
+
if self.args.ipu and (self.uname == "*" or self.args.ao_ipu_wins):
|
695
700
|
self.uname = self.conn.ipu_iu[self.conn.ipu_nm.map(self.ip)]
|
696
701
|
ipr = self.conn.hsrv.ipr
|
697
702
|
if ipr and self.uname in ipr:
|
@@ -809,6 +814,15 @@ class HttpCli(object):
|
|
809
814
|
6 if em.startswith("client d/c ") else 3,
|
810
815
|
)
|
811
816
|
|
817
|
+
if self.hint and self.hint.startswith("<xml> "):
|
818
|
+
if self.args.log_badxml:
|
819
|
+
t = "invalid XML received from client: %r"
|
820
|
+
self.log(t % (self.hint[6:],), 6)
|
821
|
+
else:
|
822
|
+
t = "received invalid XML from client; enable --log-badxml to see the whole XML in the log"
|
823
|
+
self.log(t, 6)
|
824
|
+
self.hint = ""
|
825
|
+
|
812
826
|
msg = "%s\r\nURL: %s\r\n" % (em, self.vpath)
|
813
827
|
if self.hint:
|
814
828
|
msg += "hint: %s\r\n" % (self.hint,)
|
@@ -1525,7 +1539,9 @@ class HttpCli(object):
|
|
1525
1539
|
if not rbuf or len(buf) >= 32768:
|
1526
1540
|
break
|
1527
1541
|
|
1528
|
-
|
1542
|
+
sbuf = buf.decode(enc, "replace")
|
1543
|
+
self.hint = "<xml> " + sbuf
|
1544
|
+
xroot = parse_xml(sbuf)
|
1529
1545
|
xtag = next((x for x in xroot if x.tag.split("}")[-1] == "prop"), None)
|
1530
1546
|
if xtag is not None:
|
1531
1547
|
props = set([y.tag.split("}")[-1] for y in xtag])
|
@@ -1731,6 +1747,7 @@ class HttpCli(object):
|
|
1731
1747
|
uenc = enc.upper()
|
1732
1748
|
|
1733
1749
|
txt = buf.decode(enc, "replace")
|
1750
|
+
self.hint = "<xml> " + txt
|
1734
1751
|
ET.register_namespace("D", "DAV:")
|
1735
1752
|
xroot = mkenod("D:orz")
|
1736
1753
|
xroot.insert(0, parse_xml(txt))
|
@@ -1788,6 +1805,7 @@ class HttpCli(object):
|
|
1788
1805
|
uenc = enc.upper()
|
1789
1806
|
|
1790
1807
|
txt = buf.decode(enc, "replace")
|
1808
|
+
self.hint = "<xml> " + txt
|
1791
1809
|
ET.register_namespace("D", "DAV:")
|
1792
1810
|
lk = parse_xml(txt)
|
1793
1811
|
assert lk.tag == "{DAV:}lockinfo"
|
@@ -3995,6 +4013,13 @@ class HttpCli(object):
|
|
3995
4013
|
if not editions:
|
3996
4014
|
return self.tx_404()
|
3997
4015
|
|
4016
|
+
#
|
4017
|
+
# force download
|
4018
|
+
|
4019
|
+
if "dl" in self.ouparam:
|
4020
|
+
cdis = gen_content_disposition(os.path.basename(req_path))
|
4021
|
+
self.out_headers["Content-Disposition"] = cdis
|
4022
|
+
|
3998
4023
|
#
|
3999
4024
|
# if-modified
|
4000
4025
|
|
@@ -4162,6 +4187,13 @@ class HttpCli(object):
|
|
4162
4187
|
if not editions:
|
4163
4188
|
return self.tx_404()
|
4164
4189
|
|
4190
|
+
#
|
4191
|
+
# force download
|
4192
|
+
|
4193
|
+
if "dl" in self.ouparam:
|
4194
|
+
cdis = gen_content_disposition(os.path.basename(req_path))
|
4195
|
+
self.out_headers["Content-Disposition"] = cdis
|
4196
|
+
|
4165
4197
|
#
|
4166
4198
|
# if-modified
|
4167
4199
|
|
@@ -4707,24 +4739,7 @@ class HttpCli(object):
|
|
4707
4739
|
if maxn < nf:
|
4708
4740
|
raise Pebkac(400, t)
|
4709
4741
|
|
4710
|
-
|
4711
|
-
afn = "".join([x if x in safe.replace('"', "") else "_" for x in fn])
|
4712
|
-
bascii = unicode(safe).encode("utf-8")
|
4713
|
-
zb = fn.encode("utf-8", "xmlcharrefreplace")
|
4714
|
-
if not PY2:
|
4715
|
-
zbl = [
|
4716
|
-
chr(x).encode("utf-8")
|
4717
|
-
if x in bascii
|
4718
|
-
else "%{:02x}".format(x).encode("ascii")
|
4719
|
-
for x in zb
|
4720
|
-
]
|
4721
|
-
else:
|
4722
|
-
zbl = [unicode(x) if x in bascii else "%{:02x}".format(ord(x)) for x in zb]
|
4723
|
-
|
4724
|
-
ufn = b"".join(zbl).decode("ascii")
|
4725
|
-
|
4726
|
-
cdis = "attachment; filename=\"{}.{}\"; filename*=UTF-8''{}.{}"
|
4727
|
-
cdis = cdis.format(afn, ext, ufn, ext)
|
4742
|
+
cdis = gen_content_disposition("%s.%s" % (fn, ext))
|
4728
4743
|
self.log(repr(cdis))
|
4729
4744
|
self.send_headers(None, mime=mime, headers={"Content-Disposition": cdis})
|
4730
4745
|
|
@@ -4911,7 +4926,8 @@ class HttpCli(object):
|
|
4911
4926
|
"lastmod": int(ts_md * 1000),
|
4912
4927
|
"lang": self.args.lang,
|
4913
4928
|
"favico": self.args.favico,
|
4914
|
-
"have_emp": self.args.emp,
|
4929
|
+
"have_emp": int(self.args.emp),
|
4930
|
+
"md_no_br": int(vn.flags.get("md_no_br") or 0),
|
4915
4931
|
"md_chk_rate": self.args.mcr,
|
4916
4932
|
"md": boundary,
|
4917
4933
|
"arg_base": arg_base,
|
copyparty/mdns.py
CHANGED
@@ -27,7 +27,7 @@ from .stolen.dnslib import (
|
|
27
27
|
DNSRecord,
|
28
28
|
set_avahi_379,
|
29
29
|
)
|
30
|
-
from .util import CachedSet, Daemon, Netdev, list_ips, min_ex
|
30
|
+
from .util import IP6_LL, CachedSet, Daemon, Netdev, list_ips, min_ex
|
31
31
|
|
32
32
|
if TYPE_CHECKING:
|
33
33
|
from .svchub import SvcHub
|
@@ -371,7 +371,7 @@ class MDNS(MCast):
|
|
371
371
|
cip = addr[0]
|
372
372
|
v6 = ":" in cip
|
373
373
|
if (cip.startswith("169.254") and not self.ll_ok) or (
|
374
|
-
v6 and not cip.startswith(
|
374
|
+
v6 and not cip.startswith(IP6_LL)
|
375
375
|
):
|
376
376
|
return
|
377
377
|
|
copyparty/multicast.py
CHANGED
@@ -15,7 +15,7 @@ from ipaddress import (
|
|
15
15
|
)
|
16
16
|
|
17
17
|
from .__init__ import MACOS, TYPE_CHECKING
|
18
|
-
from .util import Daemon, Netdev, find_prefix, min_ex, spack
|
18
|
+
from .util import IP6_LL, IP64_LL, Daemon, Netdev, find_prefix, min_ex, spack
|
19
19
|
|
20
20
|
if TYPE_CHECKING:
|
21
21
|
from .svchub import SvcHub
|
@@ -142,7 +142,7 @@ class MCast(object):
|
|
142
142
|
all_selected = ips[:]
|
143
143
|
|
144
144
|
# discard non-linklocal ipv6
|
145
|
-
ips = [x for x in ips if ":" not in x or x.startswith(
|
145
|
+
ips = [x for x in ips if ":" not in x or x.startswith(IP6_LL)]
|
146
146
|
|
147
147
|
if not ips:
|
148
148
|
raise NoIPs()
|
@@ -180,7 +180,7 @@ class MCast(object):
|
|
180
180
|
srv.ips[oth_ip.split("/")[0]] = ipaddress.ip_network(oth_ip, False)
|
181
181
|
|
182
182
|
# gvfs breaks if a linklocal ip appears in a dns reply
|
183
|
-
ll = {k: v for k, v in srv.ips.items() if k.startswith(
|
183
|
+
ll = {k: v for k, v in srv.ips.items() if k.startswith(IP64_LL)}
|
184
184
|
rt = {k: v for k, v in srv.ips.items() if k not in ll}
|
185
185
|
|
186
186
|
if self.args.ll or not rt:
|
copyparty/pwhash.py
CHANGED
copyparty/smbd.py
CHANGED
@@ -315,7 +315,7 @@ class SMB(object):
|
|
315
315
|
t = "blocked rename (no-move-acc %s): /%s @%s"
|
316
316
|
yeet(t % (vfs1.axs.umove, vp1, uname))
|
317
317
|
|
318
|
-
self.hub.up2k.handle_mv(uname, "1.7.6.2", vp1, vp2)
|
318
|
+
self.hub.up2k.handle_mv("", uname, "1.7.6.2", vp1, vp2)
|
319
319
|
try:
|
320
320
|
bos.makedirs(ap2, vf=vfs2.flags)
|
321
321
|
except:
|
copyparty/stolen/qrcodegen.py
CHANGED
@@ -195,6 +195,25 @@ class QrCode(object):
|
|
195
195
|
|
196
196
|
return "\n".join(rows)
|
197
197
|
|
198
|
+
def to_png(self, zoom, pad, bg, fg, ap) :
|
199
|
+
from PIL import Image
|
200
|
+
|
201
|
+
tab = self.modules
|
202
|
+
sz = self.size
|
203
|
+
psz = sz + pad * 2
|
204
|
+
if bg:
|
205
|
+
img = Image.new("RGB", (psz, psz), bg)
|
206
|
+
else:
|
207
|
+
img = Image.new("RGBA", (psz, psz), (0, 0, 0, 0))
|
208
|
+
fg = (fg[0], fg[1], fg[2], 255)
|
209
|
+
for y in range(sz):
|
210
|
+
for x in range(sz):
|
211
|
+
if tab[y][x]:
|
212
|
+
img.putpixel((x + pad, y + pad), fg)
|
213
|
+
if zoom != 1:
|
214
|
+
img = img.resize((sz * zoom, sz * zoom), Image.Resampling.NEAREST)
|
215
|
+
img.save(ap)
|
216
|
+
|
198
217
|
def _draw_function_patterns(self) :
|
199
218
|
# Draw horizontal and vertical timing patterns
|
200
219
|
for i in range(self.size):
|