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):