Commit bf89b408 authored by Gabriel Detraz's avatar Gabriel Detraz

Merge branch 'master' of https://gitlab.crans.org/nounous/scripts

Maj
parents d80f4f2f e437fccd
......@@ -88,17 +88,23 @@ def generate_ps(proprio, mail):
raise
def set_mail_invalide(adherent, mail, a_verifier, a_imprimer):
if adherent.chbre() not in ['????', 'EXT']:
print "Génération de la fiche pour %s :" % adherent.Nom().encode('utf-8')
fiche = generate_ps(adherent, mail)
print fiche
a_imprimer.append(fiche)
adherent.blacklist([time.time() + 14 * 24 * 3600,
'-', 'mail_invalide', "Mail invalide"])
adherent.save()
else:
print u"Chambre de %s : %s, impossible de générer la fiche." % (adherent.Nom().encode('utf-8'), adherent.chbre())
a_verifier.append(mail)
if adherent.chbre() in ['????', 'EXT']:
print u"Chambre de %s : %s, générer la fiche ? [Yn]" % (adherent.Nom().encode('utf-8'), adherent.chbre())
read = ''
while read not in ['y', 'n']:
read = raw_input().lower()
if read == 'n':
print u"Chambre de %s : %s, impossible de générer la fiche." % (adherent.Nom().encode('utf-8'), adherent.chbre())
a_verifier.append(mail)
return
print "Génération de la fiche pour %s :" % adherent.Nom().encode('utf-8')
fiche = generate_ps(adherent, mail)
print fiche
a_imprimer.append(fiche)
adherent.blacklist([time.time() + 14 * 24 * 3600,
'-', 'mail_invalide', "Mail invalide"])
adherent.save()
if __name__ == "__main__":
if '--help' in sys.argv or '-h' in sys.argv or len(sys.argv) < 2:
......
......@@ -32,7 +32,6 @@ from lc_ldap.shortcuts import lc_ldap_admin as make_ldap_conn
import gestion.annuaires_pg as annuaire
import gestion.config as config
import lc_ldap.objets as ldap_classes
from gestion.hptools import snmp
import gestion.config.encoding as enc
GIGABIT_MODELS = ['J9021A', 'J9145A']
......@@ -293,6 +292,7 @@ def get_port_dict(switch):
def fill_port_infos(hostname, port_dict):
"""Rajoute des infos sur les ports d'un switch"""
from gestion.hptools import snmp
conn = snmp(hostname, version='1', community='public')
prise_vlan = conn.walk(MIB_PRISE_VLAN, bin_comp=True)
......
......@@ -1600,6 +1600,7 @@ def modif_club(club):
arg += u'"Blackliste" "Modifier la blackliste du club" '
if isimprimeur:
arg += u'"Solde" "Effectuer un débit/crédit pour ce club" '
arg += u'"Vente" "Vendre un cable ou adaptateur ethernet ou autre" '
arg += u'"Remarque" "Ajouter ou modifer un commentaire" '
annul, res = dialog(arg)
......@@ -1626,6 +1627,8 @@ def modif_club(club):
__prompt_input_menu(club.alias, 'Alias mail', "Entrez ou modifier un alias mail.\nPour ajouter un alias modifier le dernier de la liste.")
elif res[0] == 'Solde':
set_solde(club)
elif res[0] == 'Vente':
set_vente(club)
if club.modifs:
return confirm(club)
......@@ -2314,7 +2317,7 @@ def select(clas, quoi, mde=''):
si m = ro ouvre l'objet en mode read-only
"""
s= ['', '', '', '', '', '', '', '', '', '']
s= ['', '', '', '', '', '', '', '', '', '', '']
def unicodize(a):
try:
return unicode(a, 'utf-8')
......@@ -2325,18 +2328,21 @@ def select(clas, quoi, mde=''):
arg = u'--title "Recherche %s" ' % ' '.join(quoi.split()[:-1])
arg += u'--help-button '
arg += u'--form "Entrez vos paramètres de recherche" 0 0 0 '
arg += u'"Nom :" 1 1 "%s" 1 13 20 20 ' % s[0]
arg += u'"Prenom :" 2 1 "%s" 2 13 20 20 ' % s[1]
arg += u'"Téléphone :" 3 1 "%s" 3 13 10 00 ' % s[2]
arg += u'"Chambre :" 4 1 "%s" 4 13 05 00 ' % s[3]
arg += u'"aid :" 5 1 "%s" 5 13 5 5 ' % s[4]
arg += u'"Login / mail :" 6 1 "%s" 6 16 30 00 ' % s[5]
arg += u'"Machine :" 1 35 "" 0 0 0 0 '
arg += u'"Nom :" 2 37 "%s" 2 43 17 17 ' % s[6]
arg += u'"Filtres adhérent" 1 8 "" 0 0 0 0 '
arg += u'"Nom :" 2 1 "%s" 2 13 20 30 ' % s[0]
arg += u'"Prenom :" 3 1 "%s" 3 13 20 30 ' % s[1]
arg += u'"Téléphone :" 4 1 "%s" 4 13 20 00 ' % s[2]
arg += u'"Chambre :" 5 1 "%s" 5 13 20 00 ' % s[3]
arg += u'"aid :" 6 1 "%s" 6 13 20 5 ' % s[4]
arg += u'"Mail :" 7 1 "%s" 7 13 20 00 ' % s[5]
arg += u'"Filtres machine" 1 40 "" 0 0 0 0 '
arg += u'"Nom :" 2 37 "%s" 2 43 17 50 ' % s[6]
arg += u'"Mac :" 3 37 "%s" 3 43 17 17 ' % s[7]
arg += u'"IP :" 4 37 "%s" 4 43 15 15 ' % s[8]
arg += u'"mid :" 5 37 "%s" 5 43 5 5 ' % s[9]
arg += u'"Les champs vides sont ignorés." 7 1 "" 0 0 0 0'
arg += u'"IP :" 4 37 "%s" 4 43 17 40 ' % s[8]
arg += u'"mid :" 5 37 "%s" 5 43 17 5 ' % s[9]
arg += u'"Filtres facture" 6 40 "" 0 0 0 0 '
arg += u'"fid :" 7 37 "%s" 7 43 17 5 ' % s[10]
arg += u'"Remarque : les champs vides sont ignorés." 8 1 "" 0 0 0 0'
annul, result = dialog(arg)
if annul: return
......@@ -2359,8 +2365,10 @@ def select(clas, quoi, mde=''):
s[5] += '@crans.org'
### Contruction de la chaîne de recherche
print s
filtre_adher = u'nom=%s&prenom=%s&tel=%s&chbre=%s&aid=%s&mail=%s&' % tuple(s[:6])
filtre_machine = u'host=%s&macAddress=%s&ipHostNumber=%s&mid=%s&' % tuple(s[6:])
filtre_machine = u'host=%s&macAddress=%s&ipHostNumber=%s&mid=%s&' % tuple(s[6:10])
filtre_facture = u'fid=%s&' % s[10]
filtre = u''
if filtre_adher.count('=*&') != 6:
......@@ -2370,6 +2378,9 @@ def select(clas, quoi, mde=''):
# Au moins une condition machine
if filtre: filtre += '&'
filtre += filtre_machine[:-1]
if filtre_facture.count('=*&') != 1:
if filtre: filtre += '&'
filtre += filtre_facture[:-1]
if filtre == '':
# Aucune condion => erreur
arg = u'--title "Recherche" '
......
......@@ -51,8 +51,8 @@ def get_mapping(baie_name):
map = {
""" % (sys.argv[0], baie)).encode(coding))
for lun, name in map:
f.write(' %d : "%s",\n' % (lun, name))
for lun, data in map:
f.write(' %d : %r,\n' % (lun, data))
f.write("}\n")
......
......@@ -121,12 +121,13 @@ class Nols(object):
name = None
lun = None
name = Object.findall("PROPERTY[@name='volume-name']")[0].text
serial = Object.findall("PROPERTY[@name='volume-serial']")[0].text
lun = Object.findall("OBJECT/PROPERTY[@name='lun']")[0].text
if lun is None:
pass
else:
map[int(lun)] = name
map[int(lun)] = (name, serial)
return map
def create_volume(self, name, size, unit="GiB", vdisk="slon1"):
......
......@@ -8,7 +8,9 @@
'''Bibliothèque pour accéder à la baie de stockage'''
import telnetlib, re
import telnetlib
import re
from xml.etree.ElementTree import ElementTree, fromstring
# Message envoyé par le serveur pour attendre l'appuie sur touche
junk_regexp = re.compile("Press any key to continue \(Q to quit\)\r *\r")
......@@ -58,7 +60,7 @@ class Slon(object):
# On met un nombre de lignes le plus élévé possible pour
# éviter que le serveur ne se mette en attente de l'appuie sur
# une touche
self.cmd("stty rows 32767")
self.cmd("set cli-parameters pager off")
# Au delà de cette valeur il y a un overflow
def logout(self):
......@@ -69,28 +71,38 @@ class Slon(object):
print ("Si vous avez effectué des modifications pensez à exécuter:\n" +
"/usr/scripts/gestion/iscsi/update.sh sur chacun des dom0\n")
def cmd(self, cmd):
'''Exécute une commande et renvoie le résultat. Lance
def cmd(self, cmd, mode='text'):
'''Exécute une commande et renvoie le résultat. Lève
l'exception Error si la commande échoue'''
# Si c'est le script qui bosse, on utilise le mode XML, sinon
# on peut aussi lancer des commandes en mode texte
if mode == 'XML':
self.tn.write("set cli-parameters xml\r\n")
self.tn.read_until("# ")
else:
self.tn.write("set cli-parameters console\r\n")
self.tn.read_until("# ")
self.tn.write(cmd + "\r\n")
resp = ""
# Lecture de la réponse, c'est terminé quand on atteint un
# nouveau prompt:
while not resp.endswith("# "):
resp = resp + self.tn.read_some()
# Parfois le serveur attend que l'on appuie sur une touche
# pour continuer à envoyer les données:
if resp.endswith("Press any key to continue (Q to quit)"):
self.tn.write(" ")
# On retire les messages parasites
resp = self.tn.read_until("# ")
# On retire les messages parasites s'il en reste par hasard
resp = junk_regexp.sub("", resp)
# On vire la commande qui est là et dont on veut pas
[_, resp] = resp.split(cmd+"\r\n", 1)
# On retire le prompt
[resp, _] = resp.rsplit("\r\n", 1)
# Remplace les fins de ligne dos pas des fin de lignes unix
# Remplace les fins de ligne dos par des fin de lignes unix
resp = crlf_regexp.sub("\n", resp)
if resp.lower().startswith("error"):
raise NolsError(resp.replace("Error: ", ""))
return resp
......@@ -105,11 +117,28 @@ class Slon(object):
def volume_map(self):
'''Retourne le mapping lun<->nom de volume'''
map = {}
for m in volume_map_regexp.finditer(self.cmd("show volume-maps")):
map[int(m.group(2))] = m.group(1)
XML_map = self.cmd("show volume-maps", mode="XML")
root = fromstring(XML_map)
tree = ElementTree(root)
# XML c'est trobyien
tree = tree.findall("volume-view")[0]
Objects = tree.findall("volume_view")
for Object in Objects:
name = None
lun = None
name = Object.findall("volume_name")[0].text
serial = Object.findall("volume_serial")[0].text
lun = Object.findall("lun")[0].text
if lun is None:
pass
else:
map[int(lun)] = (name, serial)
return map
def create_volume(self, name, size, unit="GB", vdisk="slon1"):
def create_volume(self, name, size, unit="GB", vdisk="slon2"):
'''Créé un nouveau volume. Retourne le lun sur lequel il est
mappé. La taille est en Giga-octet. L'unité doit être "KB",
"MB" ou "GB". Par défault c'est "GB".'''
......
......@@ -41,7 +41,7 @@ def getname(device, baie):
globals()['map'] = {}
execfile(map_file, globals())
return map.get(lun, "lun%d" % lun) + part
return map.get(lun, "lun%d" % lun)[0] + part
if __name__ == '__main__':
if len(sys.argv) != 2:
......
......@@ -1577,6 +1577,8 @@ class BaseProprietaire(BaseClasseCrans):
if '@' not in new:
new += '@crans.org'
else:
new = new.split('@')[0].lower() + '@crans.org'
if index != -1:
liste[index] = new
......
#!/bin/bash
#
# /usr/lib/cups/backend/2dir
#
# (c) September 2007 Kurt Pfeifle <pfeifle@kde.org>
# <kurt.pfeifle@infotec.com>
# Network printing consultant Linux/Unix/Windows/Samba/CUPS
#
# License: GNU GPLv2 or GPLv3 (your choice)
# Warranty: None at all; you may need to fix included defects on your own.
#
backend=${0}
jobid=${1}
cupsuser=${2}
jobtitle=${3}
jobcopies=${4}
joboptions=${5}
jobfile=${6}
printtime=$(date +%Y-%b-%d-%H-%M-%S)
# the following messages should appear in /var/log/cups/error_log,
# depending on what "LogLevel" setting your cupsd.conf carries:
echo "INFO: backend=${backend}" 1>&2
echo "INFO: jobid=${jobid}" 1>&2
echo "INFO: cupsuser=${cupsuser}" 1>&2
echo "INFO: jobtitle=${jobtitle}" 1>&2
echo "INFO: jobcopies=${jobcopies}" 1>&2
echo "INFO: joboptions=${joboptions}" 1>&2
echo "INFO: jobfile=${jobfile}" 1>&2
echo "INFO: printtime=${printtime}" 1>&2
echo "EMERG: This is a \"emergency\" level log message" 1>&2
echo "ALERT: This is a \"alert\" level log message" 1>&2
echo "CRIT: This is a \"critical\" level log message" 1>&2
echo "ERROR: This is a \"error\" level log message" 1>&2
echo "WARN: This is a \"warn\" level log message" 1>&2
echo "NOTICE: This is a \"notice\" level log message" 1>&2
echo "INFO: This is a \"info\" level log message" 1>&2
echo "INFO: This is a 2nd \"info\" level log message" 1>&2
echo "INFO: This is a 3rd \"info\" level log message" 1>&2
echo "DEBUG: This is a \"debug\" level log message" 1>&2
# we are free to compose the output filename written by the 2dir backend
# in whatever way we like... However, we must be careful when using the
# $jobtitle part -- the job may originate from a web browser and contain
# slashes and all kinds of illegal or problematic characters. Therefore
# we prefer to radically convert every "weird" character to an underscore
# for our current purpose...
sanitized_jobtitle="$(echo ${jobtitle} | tr [[:blank:]:/%\&=+?\\\\#\'\`\´\*] _)"
# the following lines would do (nearly) the same as the above, but slower
# -- yet better readable (and the above may be in need of some fixing still):
#sanitized_jobtitle="$(echo ${jobtitle} \
# |tr [:blank:] _ \
# |tr : _ \
# |tr \"\ \" _ \
# |tr / _ \
# |tr % _ \
# |tr \' _ \
# |tr \` _ \
# |tr \´ _ \
# |tr \' _ \
# |tr \& _ \
# |tr \* _ \
# |tr \# _ \
# |tr = _ \
# |tr + _ \
# |tr ? _ \
# |tr \\\\ _ )"
## # last line to get rid of "backslashes"...
# now for our final job output name:
outname=${jobid}_${printtime}_${sanitized_jobtitle}
# we include the $printtime part to have a uniq name in case the same job
# is tested with different settings to be kept for comparing. It is also
# useful for aligning debug efforts to CUPS' error_log entries.
# we will read the output directory from the printers $DEVICE_URI environment
# variable that should look s.th. like "2dir:/path/to/a/directory" and write
# our printfile as $outname there....
# Now do the real work:
case ${#} in
0)
# this case is for "backend discovery mode"
echo "file 2dir \"KDEPrint Devel Dept.\" \"2dir backend to test CUPS and help KDEPrint development\""
exit 0
;;
5)
if [ ! -e ${DEVICE_URI#2dir:} ]; then
mkdir -p ${DEVICE_URI#2dir:}
# You may want to change this to 777 to allow you
# to periodically delete the generated files:
chmod 755 ${DEVICE_URI#2dir:}
# WARNING! WARNING! WARNING! Don't use these file permissions
# on a production print server! This is for development convenience
# only! WARNING, security risk!
fi
# backend needs to read from stdin if number of arguments is 5
cat - > ${DEVICE_URI#2dir:}/${outname}
# Make sure everyone can read it
chmod 644 ${DEVICE_URI#2dir:}/${outname}
# WARNING! WARNING! WARNING! Don't use these file permissions
# on a production print server! This is for development convenience
# only! WARNING, security risk!
;;
6)
if [ ! -e ${DEVICE_URI#2dir:} ]; then
mkdir -p ${DEVICE_URI#2dir:}
# You may want to change this to 777 to allow you
# to periodically delete the generated files:
chmod 755 ${DEVICE_URI#2dir:}
# WARNING! WARNING! WARNING! Don't use these file permissions
# on a production print server! This is for development convenience
# only! WARNING, security risk!
fi
# backend needs to read from file if number of arguments is 6
cat ${6} > ${DEVICE_URI#2dir:}/${outname}
# Make sure everyone can read it
chmod 644 ${DEVICE_URI#2dir:}/${outname}
;;
1|2|3|4|*)
# these cases are unsupported
echo " "
echo " Usage: 2dir job-id user title copies options [file]"
echo " "
echo " (Install as CUPS backend in /usr/lib/cups/backend/2dir)"
echo " (Use as 'device URI' like \"2dir:/path/to/writeable/directory\" for printer installation.)"
exit 0
esac
echo 1>&2
# we reach this line only if we actually "printed something"
echo "NOTICE: processed Job ${jobid} to file ${DEVICE_URI#2dir:}/${outname}" 1>&2
echo "NOTICE: End of \"${0}\" run...." 1>&2
echo "NOTICE: ---------------------------------------------------------" 1>&2
echo 1>&2
exit 0
################# end "2dir" ##############################################
......@@ -17,7 +17,7 @@ def getUserQuota( userLogin ):
pipe.close()
string_result = string_result.split("\n")
quotas = []
for a_line in string_result[2:3]:
for a_line in string_result[2:-1]:
usage, quota, limite, percentage, fs = a_line.split("\t")
line_dict = {
"label": "Quota personnel",
......@@ -25,7 +25,7 @@ def getUserQuota( userLogin ):
"quota":getFloat(quota),
"limite":getFloat(limite),
"%":getFloat(percentage),
"filesystem":"rda", # pourquoi pas ?
"filesystem":fs, # pourquoi pas ?
}
quotas.append(line_dict)
return quotas
......@@ -34,17 +34,17 @@ def getUserQuota( userLogin ):
def fake_getUserQuota( userLogin ):
return [
{'%': 33.9,
'quota': 390.62,
{'%': 33.9,
'quota': 390.62,
'label': u'Dossier personnel (fake)',
'limite': 585.94,
'filesystem': '/home',
'usage': 420.32},
{'%': 0.1,
'quota': 100.00,
'filesystem': '/home',
'usage': 420.32},
{'%': 0.1,
'quota': 100.00,
'label': u'Boite de r\xe9ception (fake)',
'limite': 150.00,
'filesystem': '/var/mail',
'limite': 150.00,
'filesystem': '/var/mail',
'usage': 0.06}
]
]
# -*- encoding: utf-8 -*-
def execute(macro, args):
name = macro.request.page.page_name
name = name.split('/')[-1]
url = "http://pad.crans.org/p/" + name
return macro.formatter.rawHTML("""Lien vers l'<a href="%s">
etherpad associ&eacute;</a>""" % url)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment