mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
optimizations, failsafes, formatting
This commit is contained in:
parent
480ac254ab
commit
1ff14b4e05
|
@ -63,7 +63,7 @@ UTC = timezone.utc
|
||||||
|
|
||||||
# !rm.yes>
|
# !rm.yes>
|
||||||
MON3S = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
|
MON3S = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
|
||||||
MON3 = {b:a for a,b in enumerate(MON3S.split(), 1)}
|
MON3 = {b: a for a, b in enumerate(MON3S.split(), 1)}
|
||||||
# !rm.no>
|
# !rm.no>
|
||||||
|
|
||||||
|
|
||||||
|
@ -946,7 +946,7 @@ class CPPF(Operations):
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
# !rm.yes>
|
# !rm.yes>
|
||||||
fn = "cppf-{}-{}-{}".format(time.time(), offset, length)
|
fn = "cppf-{}-{}-{}".format(time.time(), offset, length)
|
||||||
if False:
|
if False:
|
||||||
with open(fn, "wb", len(ret)) as f:
|
with open(fn, "wb", len(ret)) as f:
|
||||||
|
@ -969,7 +969,7 @@ class CPPF(Operations):
|
||||||
raise Exception("cache bork")
|
raise Exception("cache bork")
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
# !rm.no>
|
# !rm.no>
|
||||||
|
|
||||||
def getattr(self, path, fh=None):
|
def getattr(self, path, fh=None):
|
||||||
dbg("getattr %r", path)
|
dbg("getattr %r", path)
|
||||||
|
@ -1057,6 +1057,7 @@ class CPPF(Operations):
|
||||||
def statfs(self, path):
|
def statfs(self, path):
|
||||||
dbg("@@ statfs [{}]".format(path))
|
dbg("@@ statfs [{}]".format(path))
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
# !rm.no>
|
# !rm.no>
|
||||||
|
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
|
|
|
@ -427,6 +427,7 @@ class HttpCli(object):
|
||||||
vpath = undot(vpath)
|
vpath = undot(vpath)
|
||||||
|
|
||||||
ptn = self.conn.hsrv.ptn_cc
|
ptn = self.conn.hsrv.ptn_cc
|
||||||
|
k_safe = self.conn.hsrv.uparam_cc_ok
|
||||||
for k in arglist.split("&"):
|
for k in arglist.split("&"):
|
||||||
if "=" in k:
|
if "=" in k:
|
||||||
k, zs = k.split("=", 1)
|
k, zs = k.split("=", 1)
|
||||||
|
@ -439,7 +440,7 @@ class HttpCli(object):
|
||||||
k = k.lower()
|
k = k.lower()
|
||||||
uparam[k] = sv
|
uparam[k] = sv
|
||||||
|
|
||||||
if k in ("doc", "move", "tree"):
|
if k in k_safe:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
zs = "%s=%s" % (k, sv)
|
zs = "%s=%s" % (k, sv)
|
||||||
|
@ -3829,7 +3830,7 @@ class HttpCli(object):
|
||||||
items: list[str],
|
items: list[str],
|
||||||
) -> bool:
|
) -> bool:
|
||||||
if self.args.no_zip:
|
if self.args.no_zip:
|
||||||
raise Pebkac(400, "not enabled")
|
raise Pebkac(400, "not enabled in server config")
|
||||||
|
|
||||||
logmsg = "{:4} {} ".format("", self.req)
|
logmsg = "{:4} {} ".format("", self.req)
|
||||||
self.keepalive = False
|
self.keepalive = False
|
||||||
|
@ -4145,7 +4146,7 @@ class HttpCli(object):
|
||||||
"dbwt": None,
|
"dbwt": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert vstate and vs # type: ignore # !rm
|
assert vstate.items and vs # type: ignore # !rm
|
||||||
|
|
||||||
fmt = self.uparam.get("ls", "")
|
fmt = self.uparam.get("ls", "")
|
||||||
if not fmt and (self.ua.startswith("curl/") or self.ua.startswith("fetch")):
|
if not fmt and (self.ua.startswith("curl/") or self.ua.startswith("fetch")):
|
||||||
|
@ -5149,6 +5150,9 @@ class HttpCli(object):
|
||||||
for k in ["zip", "tar"]:
|
for k in ["zip", "tar"]:
|
||||||
v = self.uparam.get(k)
|
v = self.uparam.get(k)
|
||||||
if v is not None and (not add_og or not og_fn):
|
if v is not None and (not add_og or not og_fn):
|
||||||
|
if is_dk and "dks" not in vn.flags:
|
||||||
|
t = "server config does not allow download-as-zip/tar; only dk is specified, need dks too"
|
||||||
|
raise Pebkac(403, t)
|
||||||
return self.tx_zip(k, v, self.vpath, vn, rem, [])
|
return self.tx_zip(k, v, self.vpath, vn, rem, [])
|
||||||
|
|
||||||
fsroot, vfs_ls, vfs_virt = vn.ls(
|
fsroot, vfs_ls, vfs_virt = vn.ls(
|
||||||
|
|
|
@ -181,6 +181,7 @@ class HttpSrv(object):
|
||||||
|
|
||||||
self.ptn_cc = re.compile(r"[\x00-\x1f]")
|
self.ptn_cc = re.compile(r"[\x00-\x1f]")
|
||||||
self.ptn_hsafe = re.compile(r"[\x00-\x1f<>\"'&]")
|
self.ptn_hsafe = re.compile(r"[\x00-\x1f<>\"'&]")
|
||||||
|
self.uparam_cc_ok = set("doc move tree".split())
|
||||||
|
|
||||||
self.mallow = "GET HEAD POST PUT DELETE OPTIONS".split()
|
self.mallow = "GET HEAD POST PUT DELETE OPTIONS".split()
|
||||||
if not self.args.no_dav:
|
if not self.args.no_dav:
|
||||||
|
|
|
@ -816,6 +816,8 @@ class _LUnrecv(object):
|
||||||
self.buf = buf + self.buf
|
self.buf = buf + self.buf
|
||||||
t = "\033[0;7mur:push\033[0;1;31m {}\n\033[0;7mur:rem:\033[0;1;35m {}\033[0m"
|
t = "\033[0;7mur:push\033[0;1;31m {}\n\033[0;7mur:rem:\033[0;1;35m {}\033[0m"
|
||||||
print(t.format(buf, self.buf))
|
print(t.format(buf, self.buf))
|
||||||
|
|
||||||
|
|
||||||
# !rm.no>
|
# !rm.no>
|
||||||
|
|
||||||
|
|
||||||
|
@ -3572,6 +3574,8 @@ except ImportError:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
impresources = None
|
impresources = None
|
||||||
try:
|
try:
|
||||||
|
if sys.version_info > (3, 10):
|
||||||
|
raise ImportError()
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pkg_resources = None
|
pkg_resources = None
|
||||||
|
|
|
@ -107,9 +107,9 @@ class TestDots(unittest.TestCase):
|
||||||
os.rename(".b", "v/.b")
|
os.rename(".b", "v/.b")
|
||||||
|
|
||||||
vcfg = [
|
vcfg = [
|
||||||
".::r.,u1:g,u2:c,dk",
|
".::r.,u1:g,u2:c,dks",
|
||||||
"v/a:v/a:r.,u1:g,u2:c,dk",
|
"v/a:v/a:r.,u1:g,u2:c,dks",
|
||||||
"v/.b:v/.b:r.,u1:g,u2:c,dk",
|
"v/.b:v/.b:r.,u1:g,u2:c,dks",
|
||||||
]
|
]
|
||||||
self.args = Cfg(v=vcfg, a=["u1:u1", "u2:u2"])
|
self.args = Cfg(v=vcfg, a=["u1:u1", "u2:u2"])
|
||||||
self.asrv = AuthSrv(self.args, self.log)
|
self.asrv = AuthSrv(self.args, self.log)
|
||||||
|
|
|
@ -26,6 +26,7 @@ def hdr(query):
|
||||||
class TestHttpCli(unittest.TestCase):
|
class TestHttpCli(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.td = tu.get_ramdisk()
|
self.td = tu.get_ramdisk()
|
||||||
|
self.maxDiff = 99999
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
os.chdir(tempfile.gettempdir())
|
os.chdir(tempfile.gettempdir())
|
||||||
|
@ -39,6 +40,7 @@ class TestHttpCli(unittest.TestCase):
|
||||||
os.mkdir(td)
|
os.mkdir(td)
|
||||||
os.chdir(td)
|
os.chdir(td)
|
||||||
|
|
||||||
|
# "perm+user"; r/w/a (a=rw) for user a/o/x (a=all)
|
||||||
self.dtypes = ["ra", "ro", "rx", "wa", "wo", "wx", "aa", "ao", "ax"]
|
self.dtypes = ["ra", "ro", "rx", "wa", "wo", "wx", "aa", "ao", "ax"]
|
||||||
self.can_read = ["ra", "ro", "aa", "ao"]
|
self.can_read = ["ra", "ro", "aa", "ao"]
|
||||||
self.can_write = ["wa", "wo", "aa", "ao"]
|
self.can_write = ["wa", "wo", "aa", "ao"]
|
||||||
|
@ -121,7 +123,8 @@ class TestHttpCli(unittest.TestCase):
|
||||||
|
|
||||||
# expected files in archives
|
# expected files in archives
|
||||||
if rok:
|
if rok:
|
||||||
ref = [x for x in vfiles if self.in_dive(top + "/" + durl, x)]
|
zs = top + "/" + durl
|
||||||
|
ref = [x for x in vfiles if self.in_dive(zs, x)]
|
||||||
ref.sort()
|
ref.sort()
|
||||||
else:
|
else:
|
||||||
ref = []
|
ref = []
|
||||||
|
@ -166,7 +169,7 @@ class TestHttpCli(unittest.TestCase):
|
||||||
self.assertEqual([], zf_ng)
|
self.assertEqual([], zf_ng)
|
||||||
|
|
||||||
# stash
|
# stash
|
||||||
h, ret = self.put(url)
|
h, ret = self.put(durl)
|
||||||
res = h.startswith("HTTP/1.1 201 ")
|
res = h.startswith("HTTP/1.1 201 ")
|
||||||
self.assertEqual(res, wok)
|
self.assertEqual(res, wok)
|
||||||
if wok:
|
if wok:
|
||||||
|
|
|
@ -267,6 +267,7 @@ class VHttpSrv(object):
|
||||||
|
|
||||||
self.u2idx = None
|
self.u2idx = None
|
||||||
self.ptn_cc = re.compile(r"[\x00-\x1f]")
|
self.ptn_cc = re.compile(r"[\x00-\x1f]")
|
||||||
|
self.uparam_cc_ok = set("doc move tree".split())
|
||||||
|
|
||||||
def cachebuster(self):
|
def cachebuster(self):
|
||||||
return "a"
|
return "a"
|
||||||
|
|
Loading…
Reference in a new issue