imports de petits utilisatires pour faire des stats et voir les tats de
certains trucs darcs-hash:20050411210725-4ec08-0edcb7b1d4e46ce310dbffcffd8b07e50690c8a1.gz
This commit is contained in:
parent
21f285fabb
commit
477219f2ed
8 changed files with 260 additions and 0 deletions
25
gestion/tools/list_droits.py
Executable file
25
gestion/tools/list_droits.py
Executable file
|
@ -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)
|
24
gestion/tools/list_exempt.py
Executable file
24
gestion/tools/list_exempt.py
Executable file
|
@ -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)
|
38
gestion/tools/list_firewall.py
Executable file
38
gestion/tools/list_firewall.py
Executable file
|
@ -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)
|
22
gestion/tools/list_quotas.py
Executable file
22
gestion/tools/list_quotas.py
Executable file
|
@ -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')
|
25
gestion/tools/list_solde.py
Executable file
25
gestion/tools/list_solde.py
Executable file
|
@ -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)
|
36
gestion/tools/locate-mac.py
Executable file
36
gestion/tools/locate-mac.py
Executable file
|
@ -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)
|
84
gestion/tools/locate-wifi.py
Executable file
84
gestion/tools/locate-wifi.py
Executable file
|
@ -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)
|
6
gestion/tools/stats_cableur.sh
Executable file
6
gestion/tools/stats_cableur.sh
Executable file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue