mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
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:
parent
83fb569d61
commit
00da74400c
|
@ -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-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-v", action="store_true", help="verbose (when loading: list status of each user)")
|
||||
ap2.add_argument("--chpw-q", action="store_true", help="quiet (when loading: don't print summary)")
|
||||
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")
|
||||
|
||||
|
||||
def add_zeroconf(ap):
|
||||
|
|
|
@ -2101,11 +2101,18 @@ class AuthSrv(object):
|
|||
if uname == "*" or uname not in self.defpw:
|
||||
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:
|
||||
t = "minimum password length: %d characters"
|
||||
return False, t % (self.args.chpw_len,)
|
||||
|
||||
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:
|
||||
return False, "password is taken"
|
||||
|
||||
|
@ -2141,12 +2148,13 @@ class AuthSrv(object):
|
|||
with open(ap, "r", encoding="utf-8") as f:
|
||||
pwdb = json.load(f)
|
||||
|
||||
u404 = set()
|
||||
useen = set()
|
||||
urst = set()
|
||||
uok = set()
|
||||
for usr, orig, mod in pwdb:
|
||||
useen.add(usr)
|
||||
if usr not in acct:
|
||||
u404.add(usr)
|
||||
# previous user, no longer known
|
||||
continue
|
||||
if acct[usr] != orig:
|
||||
urst.add(usr)
|
||||
|
@ -2154,33 +2162,39 @@ class AuthSrv(object):
|
|||
uok.add(usr)
|
||||
acct[usr] = mod
|
||||
|
||||
if self.args.chpw_q:
|
||||
if not self.args.chpw_v:
|
||||
return
|
||||
|
||||
for usr in acct:
|
||||
if usr not in useen:
|
||||
urst.add(usr)
|
||||
|
||||
for zs in uok:
|
||||
urst.discard(zs)
|
||||
|
||||
if not self.args.chpw_v:
|
||||
t = "chpw: %d loaded, %d default, %d ignored"
|
||||
self.log(t % (len(uok), len(urst), len(u404)))
|
||||
if self.args.chpw_v == 1 or (self.args.chpw_v == 2 and not urst):
|
||||
t = "chpw: %d changed, %d unchanged"
|
||||
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
|
||||
|
||||
msg = ""
|
||||
if uok:
|
||||
t = "\033[0mloaded: \033[32m%s"
|
||||
t = "\033[0mchanged: \033[32m%s"
|
||||
msg += t % (", ".join(list(uok)),)
|
||||
if urst:
|
||||
t = "%s\033[0mdefault: \033[35m%s"
|
||||
t = "%s\033[0munchanged: \033[35m%s"
|
||||
msg += t % (
|
||||
", " if msg else "",
|
||||
", ".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)
|
||||
|
||||
|
|
|
@ -213,6 +213,12 @@ class SvcHub(object):
|
|||
self.log("root", t, 1)
|
||||
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]
|
||||
ch = "abcdefghijklmnopqrstuvwx"[int(args.theme / 2)]
|
||||
args.theme = "{0}{1} {0} {1}".format(ch, bri)
|
||||
|
|
Loading…
Reference in a new issue