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'
|
||||
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')
|
||||
from affich_tools import tableau, cprint
|
||||
from email_tools import send_email, parse_mail_template
|
||||
|
@ -101,7 +98,7 @@ class ComptesInactifs:
|
|||
syslog("LDAP(lock): derniereConnexion=<%s>, login=<%s>" %
|
||||
(strftime("%b %d %H:%M:%S", localtime(timestamp)), login))
|
||||
return total
|
||||
|
||||
|
||||
def update(self, login, timestamp):
|
||||
"""
|
||||
Met à jour l'entrée correspondant au login donné.
|
||||
|
@ -110,7 +107,7 @@ class ComptesInactifs:
|
|||
timestamp = int(timestamp)
|
||||
if not dic.has_key(login) or timestamp > dic[login]:
|
||||
dic[login] = timestamp
|
||||
|
||||
|
||||
def update_from_syslog(self, loglines):
|
||||
"""
|
||||
Met à jour le dico avec les lignes de syslog données.
|
||||
|
@ -135,7 +132,7 @@ class ComptesInactifs:
|
|||
self.update(m.group(2).lower(), t)
|
||||
nombre += 1
|
||||
return nombre
|
||||
|
||||
|
||||
def do_log(self):
|
||||
"""
|
||||
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).
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
|
@ -192,8 +193,6 @@ L
|
|||
- F : existence d'un .forward
|
||||
- M : existence de mails non lus
|
||||
|
||||
L'analyse des logs remonte au %(oldest)s.
|
||||
|
||||
--
|
||||
comptes_inactifs.py
|
||||
"""
|
||||
|
@ -203,7 +202,7 @@ comptes_inactifs.py
|
|||
liste = self.get_idle_accounts()
|
||||
# on trie par login
|
||||
liste.sort(lambda x, y: cmp(x.compte(), y.compte()))
|
||||
|
||||
|
||||
for a in liste:
|
||||
login = a.compte()
|
||||
date = a.derniereConnexion()
|
||||
|
@ -228,8 +227,7 @@ comptes_inactifs.py
|
|||
inscrits = tableau(inscrits, titres, largeurs, alignements)
|
||||
anciens_total = len(anciens)
|
||||
anciens = tableau(anciens, titres, largeurs, alignements)
|
||||
oldest = strftime(u'%d/%m/%Y %H:%M', localtime(oldest_log))
|
||||
|
||||
|
||||
send_email(mail_sender,
|
||||
mail_report,
|
||||
u'Comptes inactifs',
|
||||
|
@ -255,7 +253,7 @@ comptes_inactifs.py
|
|||
login = a.compte()
|
||||
mail = nb_mails_non_lus(login)
|
||||
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))
|
||||
i = 0
|
||||
# est-ce un membre inscrit ?
|
||||
|
@ -275,7 +273,7 @@ comptes_inactifs.py
|
|||
if debug:
|
||||
sujet = u"[Message de test %d] %s" % (i, sujet)
|
||||
if stats[i] > 1: continue
|
||||
|
||||
|
||||
send_email(mail_sender,
|
||||
u"%s <%s@crans.org>" % (nom, login),
|
||||
sujet,
|
||||
|
@ -309,9 +307,9 @@ comptes_inactifs.py
|
|||
recapitulatif,
|
||||
server = smtp,
|
||||
debug = debug)
|
||||
|
||||
|
||||
smtp.quit()
|
||||
|
||||
|
||||
|
||||
def usage():
|
||||
""" Afficher l'aide. """
|
||||
|
@ -324,7 +322,7 @@ def usage():
|
|||
|
||||
if __name__ == '__main__':
|
||||
args = sys.argv[1:]
|
||||
|
||||
|
||||
if len(args) == 0:
|
||||
usage()
|
||||
sys.exit(0)
|
||||
|
@ -334,7 +332,7 @@ if __name__ == '__main__':
|
|||
sys.stderr.write("Commande incorrecte : %s\n" % commande)
|
||||
usage()
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
ci = ComptesInactifs()
|
||||
for commande in args:
|
||||
eval('ci.do_%s()' % commande)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue