This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
univnautes-old/virtualenv/pffedportal/del_sessions_by_pfsenseid.py

27 lines
753 B
Python
Executable File

#!/usr/bin/env python
'''
delete all pffedportal (django) sessions relative to a (list of) sessionid from
the pfsense captive portal.
syntax : del_sessions_by_pfsenseid.py [sessionid_from_pfsense] [...]
'''
# initialise django environnement for pffedportal
# note : the script must be launch into the pffedportal direcory
import os
os.environ['DJANGO_SETTINGS_MODULE'] = "settings"
import sys
from django.contrib.sessions.models import Session
pfsenseids = sys.argv[1::]
# delete each session containing a sessionid in argv
for s in Session.objects.all():
d = s.get_decoded()
if 'pfsenseid' in d:
if d['pfsenseid'] in pfsenseids:
print "delete session %s (pfsenseid=%s)" % (s.pk, d['pfsenseid'])
s.delete()