mirror of
https://github.com/9001/copyparty.git
synced 2026-04-05 23:38:24 +10:00
Merge branch 'dirkeys' into hovudstraum
This commit is contained in:
@@ -1966,7 +1966,12 @@ class HttpCli(object):
|
||||
|
||||
v = self.uparam[k]
|
||||
|
||||
vn, rem = self.asrv.vfs.get(self.vpath, self.uname, True, False)
|
||||
if self._use_dirkey():
|
||||
vn = self.vn
|
||||
rem = self.rem
|
||||
else:
|
||||
vn, rem = self.asrv.vfs.get(self.vpath, self.uname, True, False)
|
||||
|
||||
zs = self.parser.require("files", 1024 * 1024)
|
||||
if not zs:
|
||||
raise Pebkac(422, "need files list")
|
||||
@@ -2870,6 +2875,27 @@ class HttpCli(object):
|
||||
|
||||
return file_lastmod, True
|
||||
|
||||
def _use_dirkey(self, ap: str = "") -> bool:
|
||||
if self.can_read or not self.can_get:
|
||||
return False
|
||||
|
||||
req = self.uparam.get("k") or ""
|
||||
if not req:
|
||||
return False
|
||||
|
||||
dk_len = self.vn.flags.get("dk")
|
||||
if not dk_len:
|
||||
return False
|
||||
|
||||
ap = ap or self.vn.canonical(self.rem)
|
||||
zs = self.gen_fk(2, self.args.dk_salt, ap, 0, 0)[:dk_len]
|
||||
if req == zs:
|
||||
return True
|
||||
|
||||
t = "wrong dirkey, want %s, got %s\n vp: %s\n ap: %s"
|
||||
self.log(t % (zs, req, self.req, ap), 6)
|
||||
return False
|
||||
|
||||
def _expand(self, txt: str, phs: list[str]) -> str:
|
||||
for ph in phs:
|
||||
if ph.startswith("hdr."):
|
||||
@@ -3557,7 +3583,7 @@ class HttpCli(object):
|
||||
|
||||
dst = dst[len(top) + 1 :]
|
||||
|
||||
ret = self.gen_tree(top, dst)
|
||||
ret = self.gen_tree(top, dst, self.uparam.get("k", ""))
|
||||
if self.is_vproxied:
|
||||
parents = self.args.R.split("/")
|
||||
for parent in reversed(parents):
|
||||
@@ -3567,18 +3593,25 @@ class HttpCli(object):
|
||||
self.reply(zs.encode("utf-8"), mime="application/json")
|
||||
return True
|
||||
|
||||
def gen_tree(self, top: str, target: str) -> dict[str, Any]:
|
||||
def gen_tree(self, top: str, target: str, dk: str) -> dict[str, Any]:
|
||||
ret: dict[str, Any] = {}
|
||||
excl = None
|
||||
if target:
|
||||
excl, target = (target.split("/", 1) + [""])[:2]
|
||||
sub = self.gen_tree("/".join([top, excl]).strip("/"), target)
|
||||
sub = self.gen_tree("/".join([top, excl]).strip("/"), target, dk)
|
||||
ret["k" + quotep(excl)] = sub
|
||||
|
||||
vfs = self.asrv.vfs
|
||||
dk_sz = False
|
||||
if dk:
|
||||
vn, rem = vfs.get(top, self.uname, False, False)
|
||||
if vn.flags.get("dks") and self._use_dirkey(vn.canonical(rem)):
|
||||
dk_sz = vn.flags.get("dk")
|
||||
|
||||
dots = False
|
||||
fsroot = ""
|
||||
try:
|
||||
vn, rem = vfs.get(top, self.uname, True, False)
|
||||
vn, rem = vfs.get(top, self.uname, not dk_sz, False)
|
||||
fsroot, vfs_ls, vfs_virt = vn.ls(
|
||||
rem,
|
||||
self.uname,
|
||||
@@ -3601,6 +3634,14 @@ class HttpCli(object):
|
||||
|
||||
dirs = [quotep(x) for x in dirs if x != excl]
|
||||
|
||||
if dk_sz and fsroot:
|
||||
kdirs = []
|
||||
for dn in dirs:
|
||||
ap = os.path.join(fsroot, dn)
|
||||
zs = self.gen_fk(2, self.args.dk_salt, ap, 0, 0)[:dk_sz]
|
||||
kdirs.append(dn + "?k=" + zs)
|
||||
dirs = kdirs
|
||||
|
||||
for x in vfs_virt:
|
||||
if x != excl:
|
||||
try:
|
||||
@@ -3865,6 +3906,7 @@ class HttpCli(object):
|
||||
self.out_headers["X-Robots-Tag"] = "noindex, nofollow"
|
||||
|
||||
is_dir = stat.S_ISDIR(st.st_mode)
|
||||
is_dk = False
|
||||
fk_pass = False
|
||||
icur = None
|
||||
if is_dir and (e2t or e2d):
|
||||
@@ -3873,7 +3915,7 @@ class HttpCli(object):
|
||||
icur = idx.get_cur(dbv.realpath)
|
||||
|
||||
th_fmt = self.uparam.get("th")
|
||||
if self.can_read:
|
||||
if self.can_read or (self.can_get and vn.flags.get("dk")):
|
||||
if th_fmt is not None:
|
||||
nothumb = "dthumb" in dbv.flags
|
||||
if is_dir:
|
||||
@@ -3979,8 +4021,11 @@ class HttpCli(object):
|
||||
|
||||
return self.tx_file(abspath)
|
||||
|
||||
elif is_dir and not self.can_read and not self.can_write:
|
||||
return self.tx_404(True)
|
||||
elif is_dir and not self.can_read:
|
||||
if self._use_dirkey(abspath):
|
||||
is_dk = True
|
||||
elif not self.can_write:
|
||||
return self.tx_404(True)
|
||||
|
||||
srv_info = []
|
||||
|
||||
@@ -4002,7 +4047,7 @@ class HttpCli(object):
|
||||
srv_infot = "</span> // <span>".join(srv_info)
|
||||
|
||||
perms = []
|
||||
if self.can_read:
|
||||
if self.can_read or is_dk:
|
||||
perms.append("read")
|
||||
if self.can_write:
|
||||
perms.append("write")
|
||||
@@ -4130,7 +4175,7 @@ class HttpCli(object):
|
||||
if not self.conn.hsrv.prism:
|
||||
j2a["no_prism"] = True
|
||||
|
||||
if not self.can_read:
|
||||
if not self.can_read and not is_dk:
|
||||
if is_ls:
|
||||
return self.tx_ls(ls_ret)
|
||||
|
||||
@@ -4183,8 +4228,12 @@ class HttpCli(object):
|
||||
):
|
||||
ls_names = exclude_dotfiles(ls_names)
|
||||
|
||||
add_dk = vf.get("dk")
|
||||
add_fk = vf.get("fk")
|
||||
fk_alg = 2 if "fka" in vf else 1
|
||||
if add_dk:
|
||||
zs = self.gen_fk(2, self.args.dk_salt, abspath, 0, 0)[:add_dk]
|
||||
ls_ret["dk"] = cgv["dk"] = zs
|
||||
|
||||
dirs = []
|
||||
files = []
|
||||
@@ -4212,6 +4261,12 @@ class HttpCli(object):
|
||||
href += "/"
|
||||
if self.args.no_zip:
|
||||
margin = "DIR"
|
||||
elif add_dk:
|
||||
zs = absreal(fspath)
|
||||
margin = '<a href="%s?k=%s&zip" rel="nofollow">zip</a>' % (
|
||||
quotep(href),
|
||||
self.gen_fk(2, self.args.dk_salt, zs, 0, 0)[:add_dk],
|
||||
)
|
||||
else:
|
||||
margin = '<a href="%s?zip" rel="nofollow">zip</a>' % (quotep(href),)
|
||||
elif fn in hist:
|
||||
@@ -4252,6 +4307,11 @@ class HttpCli(object):
|
||||
0 if ANYWIN else inf.st_ino,
|
||||
)[:add_fk],
|
||||
)
|
||||
elif add_dk and is_dir:
|
||||
href = "%s?k=%s" % (
|
||||
quotep(href),
|
||||
self.gen_fk(2, self.args.dk_salt, fspath, 0, 0)[:add_dk],
|
||||
)
|
||||
else:
|
||||
href = quotep(href)
|
||||
|
||||
@@ -4270,6 +4330,9 @@ class HttpCli(object):
|
||||
files.append(item)
|
||||
item["rd"] = rem
|
||||
|
||||
if is_dk and not vf.get("dks"):
|
||||
dirs = []
|
||||
|
||||
if (
|
||||
self.cookies.get("idxh") == "y"
|
||||
and "ls" not in self.uparam
|
||||
|
||||
Reference in New Issue
Block a user