password-changer fixes:

* fix `--chpw-no` which did nothing
* print list of users with unchanged passwords by default
* more granular verbosity levels
This commit is contained in:
ed 2024-08-15 17:30:01 +00:00
parent 83fb569d61
commit 00da74400c
3 changed files with 35 additions and 16 deletions

View file

@ -1072,8 +1072,7 @@ def add_chpw(ap):
ap2.add_argument("--chpw-no", metavar="U,U,U", type=u, action="append", help="do not allow password-changes for this comma-separated list of usernames") ap2.add_argument("--chpw-no", metavar="U,U,U", type=u, action="append", help="do not allow password-changes for this comma-separated list of usernames")
ap2.add_argument("--chpw-db", metavar="PATH", type=u, default=db_path, help="where to store the passwords database (if you run multiple copyparty instances, make sure they use different DBs)") ap2.add_argument("--chpw-db", metavar="PATH", type=u, default=db_path, help="where to store the passwords database (if you run multiple copyparty instances, make sure they use different DBs)")
ap2.add_argument("--chpw-len", metavar="N", type=int, default=8, help="minimum password length") ap2.add_argument("--chpw-len", metavar="N", type=int, default=8, help="minimum password length")
ap2.add_argument("--chpw-v", action="store_true", help="verbose (when loading: list status of each user)") ap2.add_argument("--chpw-v", metavar="LVL", type=int, default=2, help="verbosity of summary on config load [\033[32m0\033[0m] = nothing at all, [\033[32m1\033[0m] = number of users, [\033[32m2\033[0m] = list users with default-pw, [\033[32m3\033[0m] = list all users")
ap2.add_argument("--chpw-q", action="store_true", help="quiet (when loading: don't print summary)")
def add_zeroconf(ap): def add_zeroconf(ap):

View file

@ -2101,11 +2101,18 @@ class AuthSrv(object):
if uname == "*" or uname not in self.defpw: if uname == "*" or uname not in self.defpw:
return False, "not logged in" return False, "not logged in"
if uname in self.args.chpw_no:
return False, "not allowed for this account"
if len(pw) < self.args.chpw_len: if len(pw) < self.args.chpw_len:
t = "minimum password length: %d characters" t = "minimum password length: %d characters"
return False, t % (self.args.chpw_len,) return False, t % (self.args.chpw_len,)
hpw = self.ah.hash(pw) if self.ah.on else pw hpw = self.ah.hash(pw) if self.ah.on else pw
if hpw == self.acct[uname]:
return False, "that's already your password my dude"
if hpw in self.iacct: if hpw in self.iacct:
return False, "password is taken" return False, "password is taken"
@ -2141,12 +2148,13 @@ class AuthSrv(object):
with open(ap, "r", encoding="utf-8") as f: with open(ap, "r", encoding="utf-8") as f:
pwdb = json.load(f) pwdb = json.load(f)
u404 = set() useen = set()
urst = set() urst = set()
uok = set() uok = set()
for usr, orig, mod in pwdb: for usr, orig, mod in pwdb:
useen.add(usr)
if usr not in acct: if usr not in acct:
u404.add(usr) # previous user, no longer known
continue continue
if acct[usr] != orig: if acct[usr] != orig:
urst.add(usr) urst.add(usr)
@ -2154,33 +2162,39 @@ class AuthSrv(object):
uok.add(usr) uok.add(usr)
acct[usr] = mod acct[usr] = mod
if self.args.chpw_q: if not self.args.chpw_v:
return return
for usr in acct:
if usr not in useen:
urst.add(usr)
for zs in uok: for zs in uok:
urst.discard(zs) urst.discard(zs)
if not self.args.chpw_v: if self.args.chpw_v == 1 or (self.args.chpw_v == 2 and not urst):
t = "chpw: %d loaded, %d default, %d ignored" t = "chpw: %d changed, %d unchanged"
self.log(t % (len(uok), len(urst), len(u404))) self.log(t % (len(uok), len(urst)))
return
elif self.args.chpw_v == 2:
t = "chpw: %d changed" % (len(uok))
if urst:
t += ", \033[0munchanged:\033[35m %s" % (", ".join(list(urst)))
self.log(t, 6)
return return
msg = "" msg = ""
if uok: if uok:
t = "\033[0mloaded: \033[32m%s" t = "\033[0mchanged: \033[32m%s"
msg += t % (", ".join(list(uok)),) msg += t % (", ".join(list(uok)),)
if urst: if urst:
t = "%s\033[0mdefault: \033[35m%s" t = "%s\033[0munchanged: \033[35m%s"
msg += t % ( msg += t % (
", " if msg else "", ", " if msg else "",
", ".join(list(urst)), ", ".join(list(urst)),
) )
if u404:
t = "%s\033[0mignored: \033[35m%s"
msg += t % (
", " if msg else "",
", ".join(list(u404)),
)
self.log("chpw: " + msg, 6) self.log("chpw: " + msg, 6)

View file

@ -213,6 +213,12 @@ class SvcHub(object):
self.log("root", t, 1) self.log("root", t, 1)
raise Exception(t) raise Exception(t)
noch = set()
for zs in args.chpw_no or []:
zsl = [x.strip() for x in zs.split(",")]
noch.update([x for x in zsl if x])
args.chpw_no = noch
bri = "zy"[args.theme % 2 :][:1] bri = "zy"[args.theme % 2 :][:1]
ch = "abcdefghijklmnopqrstuvwx"[int(args.theme / 2)] ch = "abcdefghijklmnopqrstuvwx"[int(args.theme / 2)]
args.theme = "{0}{1} {0} {1}".format(ch, bri) args.theme = "{0}{1} {0} {1}".format(ch, bri)