From 5b0ca05fe37b2058314b930ef379c9de853bdab1 Mon Sep 17 00:00:00 2001 From: Andy Teijelo Date: Fri, 6 Nov 2015 17:37:29 -0500 Subject: [PATCH] freeradius users file doesn't like inline comments which broke our parenthood implementation --- main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index f185a4b..a6264dc 100755 --- a/main.py +++ b/main.py @@ -72,7 +72,7 @@ def nthash(password): def create_user(username, password, creator): with exclusive_lock: f = open(users_file,"a") - f.write('{} NT-Password := "{}" # created by {} \n'.format(username, nthash(password), creator)) + f.write('# created by {}\n{} NT-Password := "{}"\n'.format(creator, username, nthash(password))) f.close() reload_freeradius() @@ -125,13 +125,19 @@ def index(): def load_users(): users = [] + creator = None with open(users_file) as f: for l in f: - if l.strip().startswith("#"): + l = l.strip() + if l.startswith("#"): + m = re.match("#\s+created by\s+(\S+)") + if m: + creator = m.group(1) continue - m = re.match("(^\S+).*-Password\s+:=\s+\"(\S+)\"(?:\s+#.*created.by\s+(\S+))?", l) + m = re.match("(^\S+).*-Password\s+:=\s+\"(\S+)\"", l) if m: - users.append(m.groups()) + users.append((m.group(1), m.group(2), creator) + creator = None return users def check_login(username, password):