diff --git a/gestion/tools/list_droits.py b/gestion/tools/list_droits.py new file mode 100755 index 00000000..d8167be6 --- /dev/null +++ b/gestion/tools/list_droits.py @@ -0,0 +1,25 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-15 -*- + +import sys +sys.path.append('/usr/scripts/gestion') + +from ldap_crans import crans_ldap, decode + +db = crans_ldap() +txts = [] + +for droit in [ u'Nounou', u'Apprenti', u'Modérateur', u'Câbleur', u'Déconnecteur',u'CVSWeb' , u'WebRadio' , u'Imprimeur'] : + adhs = db.search('droits=%s' % droit)['adherent'] + + noms = [] + + txt = '%s\n' % droit + for adh in adhs : + noms.append(u'%s' % adh.Nom().encode('iso-8859-1')) + + txt += u' %s' % '\n '.join(noms) + + txts.append(txt) + +print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(txts) diff --git a/gestion/tools/list_exempt.py b/gestion/tools/list_exempt.py new file mode 100755 index 00000000..f75bc605 --- /dev/null +++ b/gestion/tools/list_exempt.py @@ -0,0 +1,24 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-15 -*- + +import sys +sys.path.append('/usr/scripts/gestion') + +from ldap_crans import crans_ldap, decode, crans + +db = crans_ldap() +machines = db.search('exempt=*')['machine'] + +txts = [] + +for m in machines : + + # texte pour la machine + txt = u'' + txt += u'Propriétaire : %s\n' % m.proprietaire().Nom().encode('iso-8859-1') + txt += u'Machine : %s\n' % m.nom() + txt += u'destination : %s\n' % ', '.join(m.exempt()) + + txts.append(txt.strip()) + +print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(txts) diff --git a/gestion/tools/list_firewall.py b/gestion/tools/list_firewall.py new file mode 100755 index 00000000..617d0732 --- /dev/null +++ b/gestion/tools/list_firewall.py @@ -0,0 +1,38 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-15 -*- + +import sys +sys.path.append('/usr/scripts/gestion') + +from ldap_crans import crans_ldap, decode, crans + +db = crans_ldap() +machines = db.search('portTCPin=*')['machine'] + db.search('portTCPout=*')['machine'] + db.search('portUDPin=*')['machine'] + db.search('portUDPout=*')['machine'] + +done = [] +txts = [] + +for m in machines : + # on vérifie qu'on l'a pas encore traité + if m.ip() in done : + continue + if m.proprietaire().__class__ == crans : + continue + done.append(m.ip()) + + # texte pour la machine + txt = u'' + txt += u'Propriétaire : %s\n' % m.proprietaire().Nom().encode('iso-8859-1') + txt += u'Machine : %s\n' % m.nom() + if m.portTCPin() : + txt += u'ports TCP in : %s\n' % m.portTCPin() + if m.portTCPout() : + txt += u'ports TCP out : %s\n' % m.portTCPout() + if m.portUDPin() : + txt += u'ports UDP in : %s\n' % m.portUDPin() + if m.portUDPout() : + txt += u'ports UDP out : %s\n' % m.portUDPout() + + txts.append(txt.strip()) + +print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(txts) diff --git a/gestion/tools/list_quotas.py b/gestion/tools/list_quotas.py new file mode 100755 index 00000000..1dc353dd --- /dev/null +++ b/gestion/tools/list_quotas.py @@ -0,0 +1,22 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-15 -*- + +import sys +from commands import getoutput +sys.path.append('/usr/scripts/gestion') + +from ldap_crans import crans_ldap, decode + +db = crans_ldap() +comptes = db.search('aid=*')['adherent'] + db.search('cid=*')['club'] + +txts = [] + +for c in comptes : + if not c.compte() : + continue + quota = getoutput('quota %s | grep "/dev/" | awk \'{ print $1" "$3" "$4 }\'' % c.compte() ) + if quota != '/dev/sdb1 300000 500000\n/dev/sdb2 50000 75000' : + txts.append( '%s (%s)\n%s' % (c.Nom(), c.compte(), quota) ) + +print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(txts).encode('iso-8859-1') diff --git a/gestion/tools/list_solde.py b/gestion/tools/list_solde.py new file mode 100755 index 00000000..12f52c85 --- /dev/null +++ b/gestion/tools/list_solde.py @@ -0,0 +1,25 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-15 -*- + +import sys +sys.path.append('/usr/scripts/gestion') + +from ldap_crans import crans_ldap, decode + +db = crans_ldap() +adherents = db.search('solde=*')['adherent'] + +txts = [] + +for a in adherents : + if a.solde() == 0 : + continue + + # texte pour l'adhérent + txt = u'' + txt += u'Nom : %s\n' % a.Nom().encode('iso-8859-1') + txt += u'Solde : %s\n' % a.solde() + + txts.append(txt.strip()) + +print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(txts) diff --git a/gestion/tools/locate-mac.py b/gestion/tools/locate-mac.py new file mode 100755 index 00000000..75e5ca6f --- /dev/null +++ b/gestion/tools/locate-mac.py @@ -0,0 +1,36 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-15 -*- + +import sys +sys.path.append('/usr/scripts/gestion') +from annuaires import reverse, all_switchs +from hptools import hpswitch +from time import sleep +import threading + +mac = ":".join([i.zfill(2) for i in sys.argv[1].split(":")]).lower() + +# on interroge les switchs + +# classe d'interrogation des switchs +class interroge_switch (threading.Thread) : + def __init__ (self, switch, mac = None) : + threading.Thread.__init__(self) + self.switch = switch + self.mac = mac + self.start() + + def run (self) : + sw = hpswitch(self.switch) + prise = sw.where_is_mac(mac) + if prise != None : + # on a trouvé une prise, on affiche si c'est pas un uplink + if 'uplink' not in sw.nom(None, prise) or switch == 'backbone' : + print "%-10s => prise %-2s : %s" % (self.switch, str(prise), sw.nom(None, prise)) + +# on onterroge trois fois car il donne pas toujours les clients +for switch in ['backbone'] + all_switchs(): + interroge_switch(switch, mac) + +while len(threading.enumerate()) > 1 : + sleep(1) diff --git a/gestion/tools/locate-wifi.py b/gestion/tools/locate-wifi.py new file mode 100755 index 00000000..510e6f85 --- /dev/null +++ b/gestion/tools/locate-wifi.py @@ -0,0 +1,84 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-15 -*- + +import sys +sys.path.append('/usr/scripts/gestion') +from whos import borne_clients, borne_etat +from ldap_crans import crans_ldap +from time import sleep +from affich_tools import coul +import threading +from os import getuid + +# il faut être root +if getuid() : + print 'Il faut être root !' + sys.exit(1) + +# connexion à la base de données +db = crans_ldap() + +# décompostion des arguments +try : + mac = ":".join([i.zfill(2) for i in sys.argv[1].split(":")]).upper() +except : + mac = None + +# dit si une mac a déja été traitée +mac_done=[] +def done (mac) : + global mac_done + if mac in mac_done : + return True + else : + mac_done.append(mac) + return False + +# classe d'interrogation des bornes +class interroge_borne (threading.Thread) : + def __init__ (self, db, borne, mac = None) : + threading.Thread.__init__(self) + self.borne = borne + self.mac = mac + self.db = db + self.start() + + def aff_client (self, mac, rssi) : + if done(mac) : + return + + res = db.search("mac=%s" % mac)['machine'] + if not res: + client_nom = '????' + coul_rssi = 'rouge' + rssi = 0 + else: + # On va choisir la bonne couleur pour le RSSI + if rssi > -77: + coul_rssi = 'vert' + elif rssi > -90: + coul_rssi = 'jaune' + else: + coul_rssi = 'rouge' + print '%-10s %-30s (%-15s, RSSI: %s)' % (self.borne.nom().split('.')[0], res[0].proprietaire().Nom(), res[0].nom().split('.')[0],coul("%d" % rssi, coul_rssi)) + + def run (self) : + nom = self.borne.nom() + if not borne_etat(nom) : + return + clients = borne_clients(nom) + for (mac, rssi) in clients : + if not self.mac or self.mac == mac.lower() : + self.aff_client(mac,rssi) + +# on onterroge trois fois car il donne pas toujours les clients +for i in range(0,3) : + # on interroge les bornes + resultat = {} + bornes = db.search('canal=*')['machine'] + for borne in bornes : + interroge_borne(db, borne, mac) + +# on attend la fin de threads +while len(threading.enumerate()) > 1 : + sleep(1) diff --git a/gestion/tools/stats_cableur.sh b/gestion/tools/stats_cableur.sh new file mode 100755 index 00000000..72656b20 --- /dev/null +++ b/gestion/tools/stats_cableur.sh @@ -0,0 +1,6 @@ +#! /bin/sh + +echo -n "Total : " +ldapsearch -x -LLL "(paiement=*)" | grep -E "(inscription|paiement\+2004)" | wc -l + +ldapsearch -x -LLL "(paiement=*)" | grep -E "(inscription|paiement\+2004)" | cut -d ' ' -f 4 | sort | uniq -c | sort -rn