a fait 6 mois qu'on surveille les logs de connexion ; dornavant, on
utilise la date d'inscription par dfaut pour ceux qui ne se sont jamais connects. darcs-hash:20060924211837-68412-80588b1599b08f17d341240274efb6e86e879bf5.gz
This commit is contained in:
parent
1b89af3b52
commit
4916f0ab99
1 changed files with 16 additions and 18 deletions
|
@ -28,9 +28,6 @@ mail_sender = u"Comptes inactifs <disconnect@crans.org>"
|
||||||
template_path = '/usr/scripts/templates/comptes_inactifs.%d.txt'
|
template_path = '/usr/scripts/templates/comptes_inactifs.%d.txt'
|
||||||
actions = ('log', 'dump', 'summary', 'spam')
|
actions = ('log', 'dump', 'summary', 'spam')
|
||||||
|
|
||||||
# Date de début d'analyse des logs : 19/03/2006 05:27 GMT
|
|
||||||
oldest_log = 1142746043
|
|
||||||
|
|
||||||
sys.path.append('/usr/scripts/gestion')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
from affich_tools import tableau, cprint
|
from affich_tools import tableau, cprint
|
||||||
from email_tools import send_email, parse_mail_template
|
from email_tools import send_email, parse_mail_template
|
||||||
|
@ -101,7 +98,7 @@ class ComptesInactifs:
|
||||||
syslog("LDAP(lock): derniereConnexion=<%s>, login=<%s>" %
|
syslog("LDAP(lock): derniereConnexion=<%s>, login=<%s>" %
|
||||||
(strftime("%b %d %H:%M:%S", localtime(timestamp)), login))
|
(strftime("%b %d %H:%M:%S", localtime(timestamp)), login))
|
||||||
return total
|
return total
|
||||||
|
|
||||||
def update(self, login, timestamp):
|
def update(self, login, timestamp):
|
||||||
"""
|
"""
|
||||||
Met à jour l'entrée correspondant au login donné.
|
Met à jour l'entrée correspondant au login donné.
|
||||||
|
@ -110,7 +107,7 @@ class ComptesInactifs:
|
||||||
timestamp = int(timestamp)
|
timestamp = int(timestamp)
|
||||||
if not dic.has_key(login) or timestamp > dic[login]:
|
if not dic.has_key(login) or timestamp > dic[login]:
|
||||||
dic[login] = timestamp
|
dic[login] = timestamp
|
||||||
|
|
||||||
def update_from_syslog(self, loglines):
|
def update_from_syslog(self, loglines):
|
||||||
"""
|
"""
|
||||||
Met à jour le dico avec les lignes de syslog données.
|
Met à jour le dico avec les lignes de syslog données.
|
||||||
|
@ -135,7 +132,7 @@ class ComptesInactifs:
|
||||||
self.update(m.group(2).lower(), t)
|
self.update(m.group(2).lower(), t)
|
||||||
nombre += 1
|
nombre += 1
|
||||||
return nombre
|
return nombre
|
||||||
|
|
||||||
def do_log(self):
|
def do_log(self):
|
||||||
"""
|
"""
|
||||||
Lit des lignes de log sur l'entrée std et met à jour la base LDAP.
|
Lit des lignes de log sur l'entrée std et met à jour la base LDAP.
|
||||||
|
@ -171,7 +168,11 @@ class ComptesInactifs:
|
||||||
pour être sûr).
|
pour être sûr).
|
||||||
"""
|
"""
|
||||||
limit = int(time()) - since
|
limit = int(time()) - since
|
||||||
return self.search('|(!(derniereConnexion=*))(derniereConnexion<=%d)' % limit)
|
liste = self.search("derniereConnexion<=%d" % limit)
|
||||||
|
for x in self.search("!(derniereConnexion=*)"):
|
||||||
|
if x.dateInscription() <= limit:
|
||||||
|
liste.append(x)
|
||||||
|
return liste
|
||||||
|
|
||||||
def do_summary(self):
|
def do_summary(self):
|
||||||
"""
|
"""
|
||||||
|
@ -192,8 +193,6 @@ L
|
||||||
- F : existence d'un .forward
|
- F : existence d'un .forward
|
||||||
- M : existence de mails non lus
|
- M : existence de mails non lus
|
||||||
|
|
||||||
L'analyse des logs remonte au %(oldest)s.
|
|
||||||
|
|
||||||
--
|
--
|
||||||
comptes_inactifs.py
|
comptes_inactifs.py
|
||||||
"""
|
"""
|
||||||
|
@ -203,7 +202,7 @@ comptes_inactifs.py
|
||||||
liste = self.get_idle_accounts()
|
liste = self.get_idle_accounts()
|
||||||
# on trie par login
|
# on trie par login
|
||||||
liste.sort(lambda x, y: cmp(x.compte(), y.compte()))
|
liste.sort(lambda x, y: cmp(x.compte(), y.compte()))
|
||||||
|
|
||||||
for a in liste:
|
for a in liste:
|
||||||
login = a.compte()
|
login = a.compte()
|
||||||
date = a.derniereConnexion()
|
date = a.derniereConnexion()
|
||||||
|
@ -228,8 +227,7 @@ comptes_inactifs.py
|
||||||
inscrits = tableau(inscrits, titres, largeurs, alignements)
|
inscrits = tableau(inscrits, titres, largeurs, alignements)
|
||||||
anciens_total = len(anciens)
|
anciens_total = len(anciens)
|
||||||
anciens = tableau(anciens, titres, largeurs, alignements)
|
anciens = tableau(anciens, titres, largeurs, alignements)
|
||||||
oldest = strftime(u'%d/%m/%Y %H:%M', localtime(oldest_log))
|
|
||||||
|
|
||||||
send_email(mail_sender,
|
send_email(mail_sender,
|
||||||
mail_report,
|
mail_report,
|
||||||
u'Comptes inactifs',
|
u'Comptes inactifs',
|
||||||
|
@ -255,7 +253,7 @@ comptes_inactifs.py
|
||||||
login = a.compte()
|
login = a.compte()
|
||||||
mail = nb_mails_non_lus(login)
|
mail = nb_mails_non_lus(login)
|
||||||
nom = a.Nom()
|
nom = a.Nom()
|
||||||
date = a.derniereConnexion() or oldest_log
|
date = a.derniereConnexion() or a.dateInscription()
|
||||||
date = strftime(u'%d/%m/%Y %H:%M', localtime(date))
|
date = strftime(u'%d/%m/%Y %H:%M', localtime(date))
|
||||||
i = 0
|
i = 0
|
||||||
# est-ce un membre inscrit ?
|
# est-ce un membre inscrit ?
|
||||||
|
@ -275,7 +273,7 @@ comptes_inactifs.py
|
||||||
if debug:
|
if debug:
|
||||||
sujet = u"[Message de test %d] %s" % (i, sujet)
|
sujet = u"[Message de test %d] %s" % (i, sujet)
|
||||||
if stats[i] > 1: continue
|
if stats[i] > 1: continue
|
||||||
|
|
||||||
send_email(mail_sender,
|
send_email(mail_sender,
|
||||||
u"%s <%s@crans.org>" % (nom, login),
|
u"%s <%s@crans.org>" % (nom, login),
|
||||||
sujet,
|
sujet,
|
||||||
|
@ -309,9 +307,9 @@ comptes_inactifs.py
|
||||||
recapitulatif,
|
recapitulatif,
|
||||||
server = smtp,
|
server = smtp,
|
||||||
debug = debug)
|
debug = debug)
|
||||||
|
|
||||||
smtp.quit()
|
smtp.quit()
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
""" Afficher l'aide. """
|
""" Afficher l'aide. """
|
||||||
|
@ -324,7 +322,7 @@ def usage():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
|
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
usage()
|
usage()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -334,7 +332,7 @@ if __name__ == '__main__':
|
||||||
sys.stderr.write("Commande incorrecte : %s\n" % commande)
|
sys.stderr.write("Commande incorrecte : %s\n" % commande)
|
||||||
usage()
|
usage()
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
ci = ComptesInactifs()
|
ci = ComptesInactifs()
|
||||||
for commande in args:
|
for commande in args:
|
||||||
eval('ci.do_%s()' % commande)
|
eval('ci.do_%s()' % commande)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue