delete_user was leaving the created by comment behind

This commit is contained in:
Andy Teijelo Pérez 2015-11-08 17:04:11 -05:00
parent ebea2b581b
commit 932c6929c4
2 changed files with 43 additions and 34 deletions

75
main.py
View file

@ -52,21 +52,6 @@ def reload_freeradius():
def reload_dnsmasq():
call("./sendhup dnsmasq".split())
def delete_user(deluser):
f = open(users_file)
lines = f.readlines()
f.close()
timestamp = time.time()
tempfile = "{}.{}".format(users_file, timestamp)
f = open(tempfile,"w")
for line in lines:
if line.startswith(deluser):
continue
f.write(line)
f.close()
rename(tempfile, users_file)
reload_freeradius()
def nthash(password):
return hashlib.new('md4',password.encode('utf-16le')).hexdigest().upper()
@ -77,6 +62,49 @@ def create_user(username, password, creator):
f.close()
reload_freeradius()
def delete_user(deluser):
f = open(users_file)
lines = f.readlines()
f.close()
timestamp = time.time()
tempfile = "{}.{}".format(users_file, timestamp)
f = open(tempfile,"w")
createdby = None
for line in lines:
if re.search("#\s+created by", line):
createdby = line
continue
if line.startswith(deluser):
createdby = None
continue
if line.startswith("#"):
f.write(line)
else:
if createdby:
f.write(createdby)
f.write(line)
createdby = None
f.close()
rename(tempfile, users_file)
reload_freeradius()
def load_users():
users = []
creator = None
with open(users_file) as f:
for l in f:
l = l.strip()
if l.startswith("#"):
m = re.match("#\s+created by\s+(\S+)", l)
if m:
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
def login_required(f):
def g(*args, **kwargs):
if not session.get('logged_in', False):
@ -123,23 +151,6 @@ def index():
return render_template("index.html", guestpass=guestpass)
def load_users():
users = []
creator = None
with open(users_file) as f:
for l in f:
l = l.strip()
if l.startswith("#"):
m = re.match("#\s+created by\s+(\S+)", l)
if m:
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
def check_login(username, password):
for u,p,c in load_users():
if u == username and p == nthash(password):

View file

@ -24,5 +24,3 @@ oscarluis NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C"
luilver NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C"
# created by ateijelo
perico NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C"
# created by ateijelo
qwer NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C"