freeradius users file doesn't like inline comments

which broke our parenthood implementation
This commit is contained in:
Andy Teijelo 2015-11-06 17:37:29 -05:00
parent a213295b7c
commit 5b0ca05fe3

16
main.py
View file

@ -72,7 +72,7 @@ def nthash(password):
def create_user(username, password, creator): def create_user(username, password, creator):
with exclusive_lock: with exclusive_lock:
f = open(users_file,"a") 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() f.close()
reload_freeradius() reload_freeradius()
@ -125,13 +125,19 @@ def index():
def load_users(): def load_users():
users = [] users = []
creator = None
with open(users_file) as f: with open(users_file) as f:
for l in f: for l in f:
if l.strip().startswith("#"): l = l.strip()
continue if l.startswith("#"):
m = re.match("(^\S+).*-Password\s+:=\s+\"(\S+)\"(?:\s+#.*created.by\s+(\S+))?", l) m = re.match("#\s+created by\s+(\S+)")
if m: if m:
users.append(m.groups()) creator = m.group(1)
continue
m = re.match("(^\S+).*-Password\s+:=\s+\"(\S+)\"", l)
if m:
users.append((m.group(1), m.group(2), creator)
creator = None
return users return users
def check_login(username, password): def check_login(username, password):