Development
This commit is contained in:
parent
f011594b04
commit
b4e773c7b2
5 changed files with 32 additions and 7 deletions
|
|
@ -202,7 +202,7 @@
|
|||
"input_type": "number",
|
||||
"min": 0,
|
||||
"value": "0",
|
||||
"hint": "How long after creation an account is valid before it permanently expires. 0 = never expires."
|
||||
"hint": "How long before account permanently expires. 0 = never expires."
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@
|
|||
"input_type": "number",
|
||||
"min": 0,
|
||||
"value": "0",
|
||||
"hint": "How long after creation an account is valid before it permanently expires. 0 = never expires."
|
||||
"hint": "How long before account permanently expires. 0 = never expires."
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@
|
|||
"input_type": "number",
|
||||
"min": 0,
|
||||
"value": "%RADIUS_DEFAULT_EXPIRATION_VALUE%",
|
||||
"hint": "How long after creation an account is valid before it permanently expires. 0 = never expires."
|
||||
"hint": "How long before account permanently expires. 0 = never expires."
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
|
|
|
|||
|
|
@ -80,7 +80,10 @@ def _verify_credential(username, password, vlan_name):
|
|||
return False
|
||||
if row is None:
|
||||
return False
|
||||
if row['session_seconds'] > 0 and (row['date_set'] + row['session_seconds']) < int(time.time()):
|
||||
now = int(time.time())
|
||||
if row['session_seconds'] > 0 and (row['date_set'] + row['session_seconds']) < now:
|
||||
return False
|
||||
if row['expires_seconds'] > 0 and (row['date_set'] + row['expires_seconds']) < now:
|
||||
return False
|
||||
if row['digest_type'] == DIGEST_HASH_BCRYPT:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -39,11 +39,23 @@ def main():
|
|||
(now,),
|
||||
)
|
||||
]
|
||||
account_expired_ips = [
|
||||
row["ip"]
|
||||
for row in conn.execute(
|
||||
"""SELECT s.ip FROM sessions s
|
||||
JOIN credentials c ON s.credential_id = c.id
|
||||
WHERE c.expires_seconds > 0
|
||||
AND (c.date_set + c.expires_seconds) <= ?""",
|
||||
(now,),
|
||||
)
|
||||
]
|
||||
except sqlite3.OperationalError:
|
||||
conn.close()
|
||||
return
|
||||
|
||||
if not expired_ips:
|
||||
all_ips = list(set(expired_ips + account_expired_ips))
|
||||
|
||||
if not all_ips:
|
||||
conn.close()
|
||||
return
|
||||
|
||||
|
|
@ -51,14 +63,24 @@ def main():
|
|||
"DELETE FROM sessions WHERE expires_at IS NOT NULL AND expires_at <= ?",
|
||||
(now,),
|
||||
)
|
||||
if account_expired_ips:
|
||||
conn.execute(
|
||||
"""DELETE FROM sessions WHERE id IN (
|
||||
SELECT s.id FROM sessions s
|
||||
JOIN credentials c ON s.credential_id = c.id
|
||||
WHERE c.expires_seconds > 0
|
||||
AND (c.date_set + c.expires_seconds) <= ?)""",
|
||||
(now,),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
lines = "".join(f"disallow {ip}\n" for ip in expired_ips)
|
||||
lines = "".join(f"disallow {ip}\n" for ip in all_ips)
|
||||
with open(QUEUE_FILE, "a") as f:
|
||||
f.write(lines)
|
||||
|
||||
print(f"check_captive_users: queued disallow for {len(expired_ips)} expired session(s).")
|
||||
print(f"check_captive_users: queued disallow for {len(all_ips)} expired session(s) "
|
||||
f"({len(expired_ips)} session timeout, {len(account_expired_ips)} account expired).")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue