From ab40ff505104a8e353c8a6d1db6f2830daf01660 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 31 Dec 2023 18:20:24 +0000 Subject: [PATCH] add permission "A" (alias of "rwmda."); closes #70 --- README.md | 1 + copyparty/__main__.py | 1 + copyparty/authsrv.py | 29 ++++++++++++++++++++--------- copyparty/cfg.py | 1 + 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index aa4e6d95..c5f397f3 100644 --- a/README.md +++ b/README.md @@ -374,6 +374,7 @@ permissions: * `G` (upget): same as `g` except uploaders get to see their own [filekeys](#filekeys) (see `fk` in examples below) * `h` (html): same as `g` except folders return their index.html, and filekeys are not necessary for index.html * `a` (admin): can see upload time, uploader IPs, config-reload +* 'A' ("all"): same as `rwmda.` (read/write/move/delete/dotfiles) examples: * add accounts named u1, u2, u3 with passwords p1, p2, p3: `-a u1:p1 -a u2:p2 -a u3:p3` diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 119cd7bf..2b10ebfb 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -500,6 +500,7 @@ def get_sects(): "h" (html): "get", but folders return their index.html "." (dots): user can ask to show dotfiles in listings "a" (admin): can see uploader IPs, config-reload + "A" ("all"): same as "rwmda." (read/write/move/delete/admin/dotfiles) too many volflags to list here, see --help-flags diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index fb90e842..6bfa08df 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -956,7 +956,7 @@ class AuthSrv(object): try: self._l(ln, 5, "volume access config:") sk, sv = ln.split(":") - if re.sub("[rwmdgGha.]", "", sk) or not sk: + if re.sub("[rwmdgGhaA.]", "", sk) or not sk: err = "invalid accs permissions list; " raise Exception(err) if " " in re.sub(", *", "", sv).strip(): @@ -966,7 +966,7 @@ class AuthSrv(object): self._read_vol_str(sk, sv.replace(" ", ""), daxs[vp], mflags[vp]) continue except: - err += "accs entries must be 'rwmdgGha.: user1, user2, ...'" + err += "accs entries must be 'rwmdgGhaA.: user1, user2, ...'" raise Exception(err + SBADCFG) if cat == catf: @@ -1004,7 +1004,7 @@ class AuthSrv(object): def _read_vol_str( self, lvl: str, uname: str, axs: AXS, flags: dict[str, Any] ) -> None: - if lvl.strip("crwmdgGha."): + if lvl.strip("crwmdgGhaA."): t = "%s,%s" % (lvl, uname) if uname else lvl raise Exception("invalid config value (volume or volflag): %s" % (t,)) @@ -1028,7 +1028,19 @@ class AuthSrv(object): if uname == "": uname = "*" + junkset = set() for un in uname.replace(",", " ").strip().split(): + for alias, mapping in [ + ("h", "gh"), + ("G", "gG"), + ("A", "rwmda.A"), + ]: + expanded = "" + for ch in mapping: + if ch not in lvl: + expanded += ch + lvl = lvl.replace(alias, expanded + alias) + for ch, al in [ ("r", axs.uread), ("w", axs.uwrite), @@ -1036,12 +1048,11 @@ class AuthSrv(object): ("d", axs.udel), (".", axs.udot), ("a", axs.uadmin), - ("h", axs.uhtml), - ("h", axs.uget), + ("A", junkset), ("g", axs.uget), - ("G", axs.uget), ("G", axs.upget), - ]: # b bb bbb + ("h", axs.uhtml), + ]: if ch in lvl: if un == "*": t = "└─add permission [{0}] for [everyone] -- {2}" @@ -1113,7 +1124,7 @@ class AuthSrv(object): if self.args.v: # list of src:dst:permset:permset:... - # permset is [,username][,username] or ,[=args] + # permset is [,username][,username] or ,[=args] for v_str in self.args.v: m = re_vol.match(v_str) if not m: @@ -2189,7 +2200,7 @@ def upgrade_cfg_fmt( else: sn = sn.replace(",", ", ") ret.append(" " + sn) - elif sn[:1] in "rwmdgGha.": + elif sn[:1] in "rwmdgGhaA.": if cat != catx: cat = catx ret.append(cat) diff --git a/copyparty/cfg.py b/copyparty/cfg.py index f7e0261a..824e36ba 100644 --- a/copyparty/cfg.py +++ b/copyparty/cfg.py @@ -104,6 +104,7 @@ permdescs = { "G": 'upget; same as "g" but can see filekeys of their own uploads', "h": 'html; same as "g" but folders return their index.html', "a": "admin; can see uploader IPs, config-reload", + "A": "all; same as 'rwmda.' (read/write/move/delete/dotfiles)", }