From baf79bdda730b6be7966072176adfb7554f8fcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Thu, 26 Nov 2015 19:27:29 +0100 Subject: [PATCH] =?UTF-8?q?Nettoyage=20des=20restes=20de=20paiement=20par?= =?UTF-8?q?=20ann=C3=A9e=20scolaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ça fait plus d'un an qu'on est passés aux factures avec generalizedTimeFormat --- .../gestion}/mail/carte_etudiant.py | 0 .../mail/template/carte_etudiant/From/fr | 0 .../mail/template/carte_etudiant/Subject/fr | 0 .../mail/template/carte_etudiant/To/fr | 0 .../mail/template/carte_etudiant/X-Mailer/fr | 0 .../mail/template/carte_etudiant/body/_fr_old | 0 .../mail/template/carte_etudiant/body/en | 0 .../mail/template/carte_etudiant/body/fr | 0 gestion/config/config.py | 644 +++++++++++++----- gestion/ipt.py | 40 +- gestion/ldap_crans.py | 17 +- surveillance/comptes_inactifs.py | 3 +- utils/stats_cableurs.py | 14 +- 13 files changed, 498 insertions(+), 220 deletions(-) rename {gestion => archive/gestion}/mail/carte_etudiant.py (100%) rename {gestion => archive/gestion}/mail/template/carte_etudiant/From/fr (100%) rename {gestion => archive/gestion}/mail/template/carte_etudiant/Subject/fr (100%) rename {gestion => archive/gestion}/mail/template/carte_etudiant/To/fr (100%) rename {gestion => archive/gestion}/mail/template/carte_etudiant/X-Mailer/fr (100%) rename {gestion => archive/gestion}/mail/template/carte_etudiant/body/_fr_old (100%) rename {gestion => archive/gestion}/mail/template/carte_etudiant/body/en (100%) rename {gestion => archive/gestion}/mail/template/carte_etudiant/body/fr (100%) diff --git a/gestion/mail/carte_etudiant.py b/archive/gestion/mail/carte_etudiant.py similarity index 100% rename from gestion/mail/carte_etudiant.py rename to archive/gestion/mail/carte_etudiant.py diff --git a/gestion/mail/template/carte_etudiant/From/fr b/archive/gestion/mail/template/carte_etudiant/From/fr similarity index 100% rename from gestion/mail/template/carte_etudiant/From/fr rename to archive/gestion/mail/template/carte_etudiant/From/fr diff --git a/gestion/mail/template/carte_etudiant/Subject/fr b/archive/gestion/mail/template/carte_etudiant/Subject/fr similarity index 100% rename from gestion/mail/template/carte_etudiant/Subject/fr rename to archive/gestion/mail/template/carte_etudiant/Subject/fr diff --git a/gestion/mail/template/carte_etudiant/To/fr b/archive/gestion/mail/template/carte_etudiant/To/fr similarity index 100% rename from gestion/mail/template/carte_etudiant/To/fr rename to archive/gestion/mail/template/carte_etudiant/To/fr diff --git a/gestion/mail/template/carte_etudiant/X-Mailer/fr b/archive/gestion/mail/template/carte_etudiant/X-Mailer/fr similarity index 100% rename from gestion/mail/template/carte_etudiant/X-Mailer/fr rename to archive/gestion/mail/template/carte_etudiant/X-Mailer/fr diff --git a/gestion/mail/template/carte_etudiant/body/_fr_old b/archive/gestion/mail/template/carte_etudiant/body/_fr_old similarity index 100% rename from gestion/mail/template/carte_etudiant/body/_fr_old rename to archive/gestion/mail/template/carte_etudiant/body/_fr_old diff --git a/gestion/mail/template/carte_etudiant/body/en b/archive/gestion/mail/template/carte_etudiant/body/en similarity index 100% rename from gestion/mail/template/carte_etudiant/body/en rename to archive/gestion/mail/template/carte_etudiant/body/en diff --git a/gestion/mail/template/carte_etudiant/body/fr b/archive/gestion/mail/template/carte_etudiant/body/fr similarity index 100% rename from gestion/mail/template/carte_etudiant/body/fr rename to archive/gestion/mail/template/carte_etudiant/body/fr diff --git a/gestion/config/config.py b/gestion/config/config.py index 66c63b6d..1a2116eb 100644 --- a/gestion/config/config.py +++ b/gestion/config/config.py @@ -10,39 +10,34 @@ import datetime from config_srv import adm_only, role # Valeur par défaut pour les champs d'études -etudes_defaults = [u"Établissement inconnu", u"Année inconnue", u"Domaine d'études inconnu"] +etudes_defaults = [ + u"Établissement inconnu", + u"Année inconnue", + u"Domaine d'études inconnu" +] gtfepoch = "19700101000000Z" ##### Gestion des câblages # Selon la date, on met : -# -ann_scol : Année scolaire en cours # -periode_transitoire : on accepte ceux qui ont payé l'année dernière -# Ne modifier que les dates ! -dat = time.localtime() -if dat[1] < 8 or dat[1] == 8 and dat[2] < 16: - # Si pas encore début août, on est dans l'année précédente - ann_scol = dat[0]-1 - periode_transitoire = False - # sinon on change d'année -elif dat[1] < 10: - # Si pas encore octobre, les gens ayant payé l'année précédente sont - # acceptés - ann_scol = dat[0] - periode_transitoire = True -else: - # Seulement ceux qui ont payé cette année sont acceptés - ann_scol = dat[0] - periode_transitoire = False +# On récupère l'année scolaire à tout besoin +__annee = time.localtime()[0] -# Prochaine période transitoire de l'année -gtf_debut_periode_transitoire = "%s0816000000+0200" % (dat[0],) -gtf_fin_periode_transitoire = "%s0930235959+0200" % (dat[0],) -debut_periode_transitoire = time.mktime(time.strptime("%s/08/16 00:00:00" % (dat[0],), "%Y/%m/%d %H:%M:%S")) -fin_periode_transitoire = time.mktime(time.strptime("%s/09/30 23:59:59" % (dat[0],), "%Y/%m/%d %H:%M:%S")) +# Prochaine période transitoire de l'année version generalizedTimeFormat +gtf_debut_periode_transitoire = "%s0816000000+0200" % (__annee,) +gtf_fin_periode_transitoire = "%s0930235959+0200" % (__annee,) -#Sursis pour les inscription après le 1/11 pour fournir la carte étudiant -sursis_carte=8*24*3600 +# Version timestampées timezone-naïves +debut_periode_transitoire = time.mktime(time.strptime("%s/08/16 00:00:00" % (__annee,), "%Y/%m/%d %H:%M:%S")) +fin_periode_transitoire = time.mktime(time.strptime("%s/09/30 23:59:59" % (__annee,), "%Y/%m/%d %H:%M:%S")) + +# On est en période transitoire si on est dans le bon intervale +periode_transitoire = (debut_periode_transitoire <= time.time() <= fin_periode_transitoire) + +ann_scol = __annee +if time.time() <= debut_periode_transitoire: + ann_scol -= 1 # Gel des cableurs pas a jour de cotisation # Les droits ne sont pas retires mais il n'y a plus de sudo @@ -60,89 +55,201 @@ quota_hard = 10000000 fquota_soft = 0 fquota_hard = 0 # Shell -login_shell='/bin/zsh' -club_login_shell='/usr/bin/rssh' +login_shell = '/bin/zsh' +club_login_shell = '/usr/bin/rssh' # Longueur maximale d'un login -maxlen_login=25 +maxlen_login = 25 -shells_possibles = [u'/bin/csh', - u'/bin/sh', # tout caca - u'/bin/dash', # un bash light - u'/usr/bin/rc', - u'/usr/bin/ksh', # symlink vers zsh - u'/bin/ksh', # symlink vers zsh - u'/usr/bin/tcsh', # TENEX C Shell (csh++) - u'/bin/tcsh', # TENEX C Shell (csh++) - u'/bin/bash', # the Bourne-Again SHell - u'/bin/zsh', # the Z shell - u'/usr/bin/zsh', # the Z shell - u'/usr/bin/screen', - u'/bin/rbash', # Bash restreint - u'/usr/bin/rssh', # restricted secure shell allowing only scp and/or sftp - u'/usr/local/bin/badPassSh', # demande de changer de mot de passe - u'/usr/bin/passwd', # idem - u'/usr/local/bin/disconnect_shell', # déconnexion crans - u'/usr/scripts/surveillance/disconnect_shell', # idem - u'/usr/sbin/nologin', # This account is currently not available. - u'/bin/false', # vraiement méchant - u'/usr/bin/es', # n'exsite plus - u'/usr/bin/esh', # n'existe plus - u'', # le shell vide pour pouvoir les punis +shells_possibles = [ + u'/bin/csh', + u'/bin/sh', # tout caca + u'/bin/dash', # un bash light + u'/usr/bin/rc', + u'/usr/bin/ksh', # symlink vers zsh + u'/bin/ksh', # symlink vers zsh + u'/usr/bin/tcsh', # TENEX C Shell (csh++) + u'/bin/tcsh', # TENEX C Shell (csh++) + u'/bin/bash', # the Bourne-Again SHell + u'/bin/zsh', # the Z shell + u'/usr/bin/zsh', # the Z shell + u'/usr/bin/screen', + u'/bin/rbash', # Bash restreint + u'/usr/bin/rssh', # restricted secure shell allowing only scp and/or sftp + u'/usr/local/bin/badPassSh', # demande de changer de mot de passe + u'/usr/bin/passwd', # idem + u'/usr/local/bin/disconnect_shell', # déconnexion crans + u'/usr/scripts/surveillance/disconnect_shell', # idem + u'/usr/sbin/nologin', # This account is currently not available. + u'/bin/false', # vraiement méchant + u'/usr/bin/es', # n'exsite plus + u'/usr/bin/esh', # n'existe plus + u'', # le shell vide pour pouvoir les punis +] + +shells_gest_crans_order = [ + "zsh", + "bash", + "tcsh", + "screen", + "rbash", + "rssh", + "badPassSh", + "disconnect_shell" ] -shells_gest_crans_order = ["zsh", "bash", "tcsh", "screen", "rbash", "rssh", - "badPassSh", "disconnect_shell"] shells_gest_crans = { - "zsh": {"path":"/bin/zsh", "desc":"Le Z SHell, shell par defaut sur zamok"}, - "bash": {"path":"/bin/bash", "desc":"Le Boune-Again SHell, shell par defaut de la plupart des linux"}, - "tcsh": {"path":"/bin/tcsh", "desc":"C SHell ++"}, - "screen":{"path":'/usr/bin/screen', "desc":"Un gestionnaire de fenêtre dans un terminal"}, - "rbash": {"path":"/bin/rbash", "desc":"Un bash très restreint, voir man rbash"}, - "rssh": {"path":"/usr/bin/rssh", "desc":"Shell ne permetant que les transferts de fichiers via scp ou sftp"}, - "badPassSh":{"path":"/usr/local/bin/badPassSh", "desc":"Demande de changer de mot de passe à la connexion"}, - "disconnect_shell":{"path":"/usr/local/bin/disconnect_shell", "desc":"Shell pour les suspensions de compte avec message explicatif"}, + "zsh" : { + "path" : "/bin/zsh", + "desc" : "Le Z SHell, shell par defaut sur zamok" + }, + "bash" : { + "path" : "/bin/bash", + "desc" : "Le Boune-Again SHell, shell par defaut de la plupart des linux" + }, + "tcsh" : { + "path" : "/bin/tcsh", + "desc" : "C SHell ++" + }, + "screen" : { + "path" : '/usr/bin/screen', + "desc" : "Un gestionnaire de fenêtre dans un terminal" + }, + "rbash" : { + "path" : "/bin/rbash", + "desc" : "Un bash très restreint, voir man rbash" + }, + "rssh" : { + "path" : "/usr/bin/rssh", + "desc" : "Shell ne permetant que les transferts de fichiers via scp ou sftp" + }, + "badPassSh" : { + "path" : "/usr/local/bin/badPassSh", + "desc" : "Demande de changer de mot de passe à la connexion" + }, + "disconnect_shell" : { + "path" : "/usr/local/bin/disconnect_shell", + "desc" : "Shell pour les suspensions de compte avec message explicatif" + }, } # Quels droits donnent l'appartenance à quel groupe Unix ? -droits_groupes = {'adm' : [u'Nounou'], - 'respbats' : [u'Imprimeur', u'Cableur', u'Nounou'], - 'apprentis' : [u'Apprenti'], - 'moderateurs' : [u'Moderateur'], - 'disconnect' : [u'Bureau'], - 'imprimeurs' : [u'Imprimeur', u'Nounou', u'Tresorier'], - 'bureau' : [u'Bureau'], - 'webadm' : [u'Webmaster'], - 'webradio' : [u'Webradio'], - } +droits_groupes = { + 'adm' : [ + u'Nounou', + ], + 'respbats' : [ + u'Imprimeur', + u'Cableur', + u'Nounou', + ], + 'apprentis' : [ + u'Apprenti', + ], + 'moderateurs' : [ + u'Moderateur', + ], + 'disconnect' : [ + u'Bureau', + ], + 'imprimeurs' : [ + u'Imprimeur', + u'Nounou', + u'Tresorier', + ], + 'bureau' : [ + u'Bureau', + ], + 'webadm' : [ + u'Webmaster', + ], + 'webradio' : [ + u'Webradio', + ], +} ####### Les modes de paiement accepté par le crans -modePaiement = ['liquide', 'paypal', 'solde', 'cheque', 'carte', 'comnpay', 'arbitraire', 'note'] +modePaiement = [ + 'liquide', + 'paypal', + 'solde', + 'cheque', + 'carte', + 'comnpay', + 'arbitraire', + 'note', +] ####### Les ML # Le + devant un nom de ML indique une synchronisation # ML <-> fonction partielle : il n'y a pas d'effacement automatique # des abonnés si le droit est retiré -droits_mailing_listes = {'roots' : [ u'Nounou', u'Apprenti'], - 'mailman' : [ u'Nounou'], - '+nounou' : [ u'Nounou', u'Apprenti'], - 'respbats' : [ u'Cableur', u'Nounou', u'Bureau'], - 'moderateurs' : [ u'Moderateur', u'Bureau'], - 'disconnect' : [ u'Nounou', u'Bureau'], - 'impression' : [ u'Imprimeur'], - 'bureau' : [u'Bureau'], - 'tresorier' : [u'Tresorier'], - 'apprentis' : [u'Apprenti'], - '+ca' : [u'Bureau', u'Apprenti', u'Nounou', u'Cableur'], +droits_mailing_listes = { + 'roots' : [ + u'Nounou', + u'Apprenti', + ], + 'mailman' : [ + u'Nounou', + ], + '+nounou' : [ + u'Nounou', + u'Apprenti', + ], + 'respbats' : [ + u'Cableur', + u'Nounou', + u'Bureau', + ], + 'moderateurs' : [ + u'Moderateur', + u'Bureau', + ], + 'disconnect' : [ + u'Nounou', + u'Bureau', + ], + 'impression' : [ + u'Imprimeur', + ], + 'bureau' : [ + u'Bureau', + ], + 'tresorier' : [ + u'Tresorier', + ], + 'apprentis' : [ + u'Apprenti', + ], + '+ca' : [ + u'Bureau', + u'Apprenti', + u'Nounou', + u'Cableur', + ], + '+federez' : [ + u'Bureau', + u'Apprenti', + u'Nounou', + ], + '+install-party' : [ + u'Bureau', + u'Apprenti', + u'Nounou', + ], - '+federez' : [u'Bureau', u'Apprenti', u'Nounou'], - '+install-party' : [u'Bureau', u'Apprenti', u'Nounou'], - - # Correspondance partielle nécessaire... Des adresses non-crans sont inscrites à ces ML. - '+dsi-crans' : [u'Nounou', u'Bureau'], - '+crous-crans' : [u'Nounou', u'Bureau'], - - '+wrc' : [u'Webradio'], - } + # Correspondance partielle nécessaire... Des adresses non-crans sont inscrites à ces ML. + '+dsi-crans' : [ + u'Nounou', + u'Bureau', + ], + '+crous-crans' : [ + u'Nounou', + u'Bureau', + ], + '+wrc' : [ + u'Webradio', + ], +} #: Répertoire de stockage des objets détruits cimetiere = '/home/cimetiere' @@ -166,21 +273,21 @@ ISCSI_MAP_FILE = "/usr/scripts/var/iscsi_names_%s.py" # IANA_id correspond à l'entier attribué par l'IANA pour l'algorithm dans les champs DNS SSHFP # ssh_algo correspond a la première chaine de caractères donnant le nom de l'algorithme de chiffrement lorsque la clef ssh est dans le format openssh (algo key comment) sshfp_algo = { - "rsa" : (1, "ssh-rsa"), - "dsa" : (2, "ssh-dss"), - "ecdsa-256" : (3, "ecdsa-sha2-nistp256"), - "ecdsa-384" : (3, "ecdsa-sha2-nistp384"), - "ecdsa-521" : (3, "ecdsa-sha2-nistp521"), - "ecdsa" : (3, "ecdsa-sha2-nistp521"), - } + "rsa" : (1, "ssh-rsa"), + "dsa" : (2, "ssh-dss"), + "ecdsa-256" : (3, "ecdsa-sha2-nistp256"), + "ecdsa-384" : (3, "ecdsa-sha2-nistp384"), + "ecdsa-521" : (3, "ecdsa-sha2-nistp521"), + "ecdsa" : (3, "ecdsa-sha2-nistp521"), +} sshfs_ralgo = {} for key, value in sshfp_algo.items(): sshfs_ralgo[value[1]] = (value[0], key) sshfp_hash = { - "sha1" : 1, - "sha256" : 2, + "sha1" : 1, + "sha256" : 2, } sshkey_max_age = int(9.869604401089358 * (365.25 * 24 * 3600)) @@ -218,40 +325,74 @@ plage_ens = '138.231.0.0/16' # clefs qui cassent la bijectivité, mais qui peuvent servir. # NETs est l'union des deux NETs_primaires = { - 'serveurs' : ['138.231.136.0/24'], - 'adherents' : ['138.231.137.0/24', '138.231.138.0/23', '138.231.140.0/22'], - 'wifi-adh' : ['138.231.144.0/22', - '138.231.148.32/27', - '138.231.148.64/26', - '138.231.148.128/25', - '138.231.149.0/24', - '138.231.150.0/23', - ], - 'bornes' : [ - '138.231.148.0/27', - ], - 'adm' : ['10.231.136.0/24'], - 'personnel-ens' : ['10.2.9.0/24'], - 'gratuit' : ['10.42.0.0/16'], - 'accueil' : ['10.51.0.0/16'], - 'federez' : ['10.53.0.0/16'], - 'isolement' : ['10.52.0.0/16'], - 'evenementiel' : ['10.231.137.0/24'], - 'multicast' : ['239.0.0.0/8'], - 'ens' : ['138.231.135.0/24'], - } + 'serveurs' : [ + '138.231.136.0/24', + ], + 'adherents' : [ + '138.231.137.0/24', + '138.231.138.0/23', + '138.231.140.0/22', + ], + 'wifi-adh' : [ + '138.231.144.0/22', + '138.231.148.32/27', + '138.231.148.64/26', + '138.231.148.128/25', + '138.231.149.0/24', + '138.231.150.0/23', + ], + 'bornes' : [ + '138.231.148.0/27', + ], + 'adm' : [ + '10.231.136.0/24' + ], + 'personnel-ens' : [ + '10.2.9.0/24' + ], + 'gratuit' : [ + '10.42.0.0/16' + ], + 'accueil' : [ + '10.51.0.0/16' + ], + 'federez' : [ + '10.53.0.0/16' + ], + 'isolement' : [ + '10.52.0.0/16' + ], + 'evenementiel' : [ + '10.231.137.0/24' + ], + 'multicast' : [ + '239.0.0.0/8' + ], + 'ens' : [ + '138.231.135.0/24' + ], +} NETs_secondaires = { - 'all' : ['138.231.136.0/21', '138.231.144.0/21'], - 'wifi': ['138.231.144.0/21'], - 'fil' : ['138.231.136.0/21'], - } + 'all' : [ + '138.231.136.0/21', + '138.231.144.0/21', + ], + 'wifi': [ + '138.231.144.0/21', + ], + 'fil' : [ + '138.231.136.0/21', + ], +} NETs = {} NETs.update(NETs_primaires) NETs.update(NETs_secondaires) -NETs_regexp = { 'all' : '^138\.231\.1(3[6789]|4[0123456789]|5[01])\.\d+$' } +NETs_regexp = { + 'all' : r'^138\.231\.1(3[6789]|4[0123456789]|5[01])\.\d+$' +} # Classes de rid # Merci d'essayer de les faire correspondre avec les réseaux @@ -288,13 +429,13 @@ rid_primaires = { 'personnel-ens' : [(55296, 55551),], # Un unique rid pour les machines multicast 'multicast' : [(65535, 65535),], - } +} rid_secondaires = { # Rid pour les machines filaire ipv4 'fil' : [(0, 2047),], 'wifi' : [(2048, 4095), (34816, 35071),], - } +} rid = {} rid.update(rid_primaires) @@ -320,24 +461,59 @@ ipv6_machines_speciales = { } # Les préfixes ipv6 publics -prefix = { 'subnet' : [ '2a01:240:fe3d::/48' ], - 'serveurs' : [ '2a01:240:fe3d:4::/64' ], - 'adherents' : [ '2a01:240:fe3d:4::/64' ], - 'fil' : [ '2a01:240:fe3d:4::/64' ], - 'adm' : [ '2a01:240:fe3d:c804::/64' ], - 'adm-v6' : [ '2a01:240:fe3d:c804::/64' ], - 'wifi' : [ '2a01:240:fe3d:c04::/64' ], - 'serveurs-v6' : [ '2a01:240:fe3d:c04::/64' ], - 'adherents-v6' : [ '2a01:240:fe3d:4::/64' ], - 'wifi-adh-v6' : [ '2a01:240:fe3d:c04::/64' ], - 'personnel-ens' : [ '2a01:240:fe3d:4::/64' ], - 'sixxs2' : [ '2a01:240:fe00:68::/64' ], - 'evenementiel' : [ '2a01:240:fe3d:d2::/64' ], - 'bornes' : [ '2a01:240:fe3d:c04::/64' ], - 'bornes-v6' : [ '2a01:240:fe3d:c04::/64' ], - 'wifi-adh' : [ '2a01:240:fe3d:c04::/64' ], - 'v6only' : [ '2001:470:c8b9:a4::/64' ], - } +prefix = { + 'subnet' : [ + '2a01:240:fe3d::/48', + ], + 'serveurs' : [ + '2a01:240:fe3d:4::/64', + ], + 'adherents' : [ + '2a01:240:fe3d:4::/64', + ], + 'fil' : [ + '2a01:240:fe3d:4::/64', + ], + 'adm' : [ + '2a01:240:fe3d:c804::/64', + ], + 'adm-v6' : [ + '2a01:240:fe3d:c804::/64', + ], + 'wifi' : [ + '2a01:240:fe3d:c04::/64', + ], + 'serveurs-v6' : [ + '2a01:240:fe3d:c04::/64', + ], + 'adherents-v6' : [ + '2a01:240:fe3d:4::/64', + ], + 'wifi-adh-v6' : [ + '2a01:240:fe3d:c04::/64', + ], + 'personnel-ens' : [ + '2a01:240:fe3d:4::/64', + ], + 'sixxs2' : [ + '2a01:240:fe00:68::/64', + ], + 'evenementiel' : [ + '2a01:240:fe3d:d2::/64', + ], + 'bornes' : [ + '2a01:240:fe3d:c04::/64', + ], + 'bornes-v6' : [ + '2a01:240:fe3d:c04::/64', + ], + 'wifi-adh' : [ + '2a01:240:fe3d:c04::/64', + ], + 'v6only' : [ + '2001:470:c8b9:a4::/64', + ], +} # Préfixes ipv6 internes (ula) int_prefix = { @@ -346,10 +522,12 @@ int_prefix = { } # Domaines dans lesquels les machines sont placées suivant leur type -domains = { 'machineFixe': 'crans.org', - 'machineCrans': 'crans.org', - 'machineWifi': 'wifi.crans.org', - 'borneWifi': 'wifi.crans.org' } +domains = { + 'machineFixe': 'crans.org', + 'machineCrans': 'crans.org', + 'machineWifi': 'wifi.crans.org', + 'borneWifi': 'wifi.crans.org', +} # VLans vlans = { @@ -383,33 +561,45 @@ vlans = { 'iscsi': 42, # freebox (pour faire descendre la connexion au 0B) 'freebox': 8, - } +} -filter_policy = { 'komaz' : { 'policy_input' : 'ACCEPT', - 'policy_forward' : 'ACCEPT', - 'policy_output' : 'ACCEPT' - }, - 'zamok' : { 'policy_input' : 'ACCEPT', - 'policy_forward' : 'DROP', - 'policy_output' : 'ACCEPT' - }, - 'default' : { 'policy_input' : 'ACCEPT', - 'policy_forward' : 'ACCEPT', - 'policy_output' : 'ACCEPT' - } - } +filter_policy = { + 'komaz' : { + 'policy_input' : 'ACCEPT', + 'policy_forward' : 'ACCEPT', + 'policy_output' : 'ACCEPT', + }, + 'zamok' : { + 'policy_input' : 'ACCEPT', + 'policy_forward' : 'DROP', + 'policy_output' : 'ACCEPT', + }, + 'default' : { + 'policy_input' : 'ACCEPT', + 'policy_forward' : 'ACCEPT', + 'policy_output' : 'ACCEPT', + } +} # Cf RFC 4890 -authorized_icmpv6 = ['echo-request', 'echo-reply', 'destination-unreachable', - 'packet-too-big', 'ttl-zero-during-transit', 'parameter-problem'] +authorized_icmpv6 = [ + 'echo-request', + 'echo-reply', + 'destination-unreachable', + 'packet-too-big', + 'ttl-zero-during-transit', + 'parameter-problem', +] -output_file = { 4 : '/tmp/ipt_rules', - 6 : '/tmp/ip6t_rules' - } +output_file = { + 4 : '/tmp/ipt_rules', + 6 : '/tmp/ip6t_rules', +} -file_pickle = { 4 : '/tmp/ipt_pickle', - 6 : '/tmp/ip6t_pickle' - } +file_pickle = { + 4 : '/tmp/ipt_pickle', + 6 : '/tmp/ip6t_pickle', +} ################################################################################## #: Items de la blackliste @@ -433,7 +623,7 @@ blacklist_sanctions = [ ] #: Blacklistes redirigeant le port 80 en http vers le portail captif (avec des explications) -blacklist_sanctions_soft = [ +blacklist_sanctions_soft = [ 'ipv6_ra', 'mail_invalide', 'virus', @@ -447,10 +637,24 @@ blacklist_bridage_upload = ['autodisc_upload', 'upload'] ################################################################################## -adm_users = [ 'root', 'identd', 'daemon', 'postfix', 'freerad', 'amavis', - 'nut', 'respbats', 'list', 'sqlgrey', 'ntpd', 'lp' ] +adm_users = [ + 'root', + 'identd', + 'daemon', + 'postfix', + 'freerad', + 'amavis', + 'nut', + 'respbats', + 'list', + 'sqlgrey', + 'ntpd', + 'lp', +] -open_ports = { 'tcp' : '22' } +open_ports = { + 'tcp' : '22', +} # Debit max sur le vlan de la connexion gratuite debit_max_radin = 1000000 @@ -460,13 +664,83 @@ debit_max_gratuit = 1000000 ## Vlan accueil et isolement ## ############################### accueil_route = { - '138.231.136.1':{'tcp':['80','443', '22'],'hosts':['ssh.crans.org', 'zamok.crans.org']}, - '138.231.136.67':{'tcp':['80','443'],'hosts':['www.crans.org', 'wiki.crans.org', 'wifi.crans.org']}, - '138.231.136.98':{'tcp':['20','21','80','111','1024:65535'],'udp':['69','1024:65535'], 'hosts':['ftp.crans.org']}, - '138.231.136.130':{'tcp':['80','443'],'hosts':['intranet2.crans.org', 'intranet.crans.org']}, - '138.231.136.18':{'tcp':['80','443'],'hosts':['cas.crans.org', 'login.crans.org', 'auth.crans.org']}, - '213.154.225.236':{'tcp':['80','443'], 'hosts':['crl.cacert.org']}, - '213.154.225.237':{'tcp':['80','443'], 'hosts':['ocsp.cacert.org']}, + '138.231.136.1' : { + 'tcp' : [ + '80', + '443', + '22' + ], + 'hosts' : [ + 'ssh.crans.org', + 'zamok.crans.org', + ], + }, + '138.231.136.67' : { + 'tcp' : [ + '80', + '443', + ], + 'hosts' : [ + 'www.crans.org', + 'wiki.crans.org', + 'wifi.crans.org', + ], + }, + '138.231.136.98' : { + 'tcp' : [ + '20', + '21', + '80', + '111', + '1024:65535', + ], + 'udp' : [ + '69', + '1024:65535', + ], + 'hosts' : [ + 'ftp.crans.org', + ], + }, + '138.231.136.130' : { + 'tcp' : [ + '80', + '443', + ], + 'hosts' : [ + 'intranet2.crans.org', + 'intranet.crans.org', + ], + }, + '138.231.136.18' : { + 'tcp' : [ + '80', + '443', + ], + 'hosts' : [ + 'cas.crans.org', + 'login.crans.org', + 'auth.crans.org', + ], + }, + '213.154.225.236' : { + 'tcp' : [ + '80', + '443', + ], + 'hosts' : [ + 'crl.cacert.org', + ], + }, + '213.154.225.237' : { + 'tcp' : [ + '80', + '443', + ], + 'hosts' : [ + 'ocsp.cacert.org', + ], + }, } dhcp_servers = ['dhcp.adm.crans.org', 'isc.adm.crans.org'] diff --git a/gestion/ipt.py b/gestion/ipt.py index d463bccd..1b28c236 100644 --- a/gestion/ipt.py +++ b/gestion/ipt.py @@ -21,10 +21,10 @@ import sys import os, re, syslog, cPickle, socket -from ldap_crans import crans_ldap, hostname +from ldap_crans import crans_ldap, hostname, generalizedTimeFormat from commands import getstatusoutput from config import NETs, role, prefix, rid, output_file, filter_policy, rid_primaires -from config import blacklist_sanctions, blacklist_sanctions_soft, blacklist_bridage_upload, file_pickle, ann_scol, periode_transitoire +from config import blacklist_sanctions, blacklist_sanctions_soft, blacklist_bridage_upload, file_pickle, periode_transitoire, gtf_debut_periode_transitoire from iptools import AddrInNet from ridtools import Rid, find_rid_plage import subprocess @@ -257,7 +257,7 @@ REJECT --reject-with icmp6-port-unreachable') os.remove(file_pickle[ip_proto]) # On sauve les chaînes - + save_pickle(ipt_p) return 0 @@ -330,16 +330,16 @@ REJECT --reject-with icmp6-port-unreachable') # ipt_p.filter.mac.items.remove[i] # break # print "Erreur, la mac " + mac + " n'est pas dans la chaîne." -# +# # for mac in macs['add']: # ipt_p.macip(mac) -# +# # # On écrit et applique les règles # write_rules(ipt_p) # apply_rules(6) -# +# # os.remove(file_pickle[ip_proto]) -# +# # # On sauve les chaînes # save_pickle(ipt_p) # return 0 @@ -459,18 +459,18 @@ class UnknowUserError(Exception): ############################################################################## # -# Déclaration des fonctions +# Déclaration des fonctions # ############################################################################## def gethostbyname(hostname): hosts4=[] hosts6=[] - try : + try : for host in socket.getaddrinfo(hostname,None,socket.AF_INET,socket.IPPROTO_IP,socket.AI_CANONNAME): hosts4.append(host[4][0]) except(socket.gaierror): pass - try : + try : for host in socket.getaddrinfo(hostname,None,socket.AF_INET6,socket.IPPROTO_IP,socket.AI_CANONNAME): hosts6.append(host[4][0]) except(socket.gaierror): pass @@ -544,14 +544,14 @@ def iface6(net): raise NoIface(net, msg) - + def check_table(table): ''' Vérifie que la table existe bien ''' ctables = open('/etc/iproute2/rt_tables', 'r') rt_tables = ctables.readlines() tables = [item for item in rt_tables if not re.match('#', item)] if any(re.search(table, elt) for elt in tables): - return 0 + return 0 else: raise NoRtTable(table) @@ -682,7 +682,7 @@ def disable_forwarding(ip_proto = 4): def not_private(arg): - ''' Retourne un boolén suivant que la fonction passé en argument + ''' Retourne un boolén suivant que la fonction passé en argument est privée ou non''' if re.match('^_.*', str(arg)): return False @@ -727,7 +727,7 @@ def write_rules(ipt): } # On parcours une première fois l'instance pour initialiser correctement - # nos chaînes + # nos chaînes for itables in ['filter', 'mangle', 'raw']: for ichain in filter(not_private, dir(ipt.__getattribute__(itables))): @@ -768,10 +768,14 @@ def blacklist(ipt): if [x for x in sanctions if x in blacklist_sanctions_ipv6]: blcklst.extend(target.machines()) - s = db.search('mblacklist=*&paiement=%s' % ann_scol) + s = db.search('mblacklist=*&finConnexion>=%(fin)s&finAdhesion>=%(fin)s' % { + 'fin': generalizedTimeFormat(), + }) if periode_transitoire: - s['machine'].extend(db.search('mblacklist=*&paiement=%s' % (ann_scol-1))['machine']) - + s['machine'].extend(db.search('mblacklist=*&finConnexion>=%(fin)s&finAdhsion>=%(fin)s' % { + 'fin': gtf_debut_periode_transitoire, + })['machine']) + for target in s['machine']: sanctions = target.blacklist_actif() if [x for x in sanctions if x in blacklist_sanctions_ipv6]: @@ -837,7 +841,7 @@ def macips(ipt, machines, types_machines): if int(machine.rid()) in range(plage[0], plage[1]): ipt.macip(machine.mac(), type_m) break - + for type_m in types_machines: if not type_m in tab.keys(): type_mm = re.sub('-', '', type_m) diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index 76a74bab..45d7a2f3 100755 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -134,7 +134,6 @@ droits_vieux = [u'Nounou', u'Bureau'] ### Variables internes diverses #isadm = user_tests.isadm() #isdeconnecteur = user_tests.isdeconnecteur() -ann_scol = config.ann_scol #script_utilisateur = user_tests.getuser() script_utilisateur = cur_user @@ -159,12 +158,15 @@ def tz(thetz): else: return "%s%04d" % ("+"*(thetz < 0) + "-"*(thetz > 0), abstz) -def generalizedTimeFormat(stamp): +def generalizedTimeFormat(stamp=None): """Converts a timestamp (local) in a generalized time format for LDAP """ + if stamp is None: + stamp = time.time() + return "%s%s" % (time.strftime("%Y%m%d%H%M%S", time.localtime(stamp)), tz(time.altzone/3600)) def fromGeneralizedTimeFormat(gtf): @@ -833,9 +835,13 @@ class CransLdap: # définifif (cf config.py). if config.periode_transitoire: # Pour la période transitoire année précédente ok - el = "(|(paiement=%d)(paiement=%d)(finAdhesion>=%s))" % (config.ann_scol, config.ann_scol-1, generalizedTimeFormat(time.time())) + el = "(&(finAdhesion>=%(fin)s)(finConnexion>=%(fin)s))" % { + 'fin': config.gtf_debut_periode_transitoire, + } else: - el = "(|(paiement=%s)(finAdhesion>=%s))" % (config.ann_scol, generalizedTimeFormat(time.time())) + el = "(&(finAdhesion>=%(fin)s)(finConnexion>=%(fin)s))" % { + 'fin': generalizedTimeFormat(), + } # Doit-on bloquer en cas de manque de la carte d'etudiant ? # (si période transitoire on ne bloque dans aucun cas) elif champ[1:] == 'blacklist': @@ -1062,9 +1068,6 @@ class BaseClasseCrans(CransLdap): def connexion(self, update=False, f=None): return 0.0 - def sursis_carte(self): - return False - def chbre(self, new=None): return "????" diff --git a/surveillance/comptes_inactifs.py b/surveillance/comptes_inactifs.py index 498590da..9d87577b 100755 --- a/surveillance/comptes_inactifs.py +++ b/surveillance/comptes_inactifs.py @@ -36,7 +36,6 @@ sys.path.append('/usr/scripts/gestion') from affich_tools import tableau, cprint from email_tools import send_email, parse_mail_template from ldap_crans import crans_ldap -from config import ann_scol db = crans_ldap() import syslog @@ -212,7 +211,7 @@ comptes_inactifs.py mail = nb_mails_non_lus(login) mail = mail == None and u'?' or mail > 0 and u'X' or u' ' ligne = (a.id(), login, a.Nom(), date, forward, mail) - if ann_scol in a.paiement() or a.adhesion() > time(): + if a.adhesion() > time(): inscrits.append(ligne) else: anciens.append(ligne) diff --git a/utils/stats_cableurs.py b/utils/stats_cableurs.py index 0bedc304..fcbdc88f 100755 --- a/utils/stats_cableurs.py +++ b/utils/stats_cableurs.py @@ -35,8 +35,6 @@ import gestion.config as config import gestion.affichage as affichage from cranslib.decorators import static_var -from config import ann_scol - ### Appels à LDAP et tri initial sur l'année en cours. DB = shortcuts.lc_ldap_readonly() @@ -91,7 +89,7 @@ def actions_cableurs(): champ = parse_historique(histo_line)[0] champ_action = parse_historique(histo_line)[1] date = parse_historique(histo_line)[2] - if (u' inscription' in champ_action or u'Adhesion+' in champ_action) and date > datetime.date(ann_scol, 8, 1): + if (u' inscription' in champ_action or u'Adhesion+' in champ_action) and date > datetime.date(config.ann_scol, 8, 1): HISTORIQUE.append(champ) for facture in factures(): @@ -100,7 +98,7 @@ def actions_cableurs(): champ = parse_historique(histo_line)[0] champ_action = parse_historique(histo_line)[1] date = parse_historique(histo_line)[2] - if u'controle' in champ_action and date > datetime.date(ann_scol, 8, 1): + if u'controle' in champ_action and date > datetime.date(config.ann_scol, 8, 1): HISTORIQUE.append(champ) return HISTORIQUE @@ -113,7 +111,7 @@ def score_cableurs(): nom = cableur.get(u'nom', None)[0].value prenom = cableur.get(u'prenom', None)[0].value uid = cableur.get(u'uid', None)[0].value - for index in range (0, len(HISTORIQUE)): + for index in range(0, len(HISTORIQUE)): histo_uid = HISTORIQUE[index][2] histo_action = HISTORIQUE[index][3] if histo_uid == uid and histo_action == u' inscription': @@ -129,17 +127,17 @@ def score_cableurs(): ### Tri par score def sort_by_score(): """Tri la liste des câbleurs par ordre de score décroissant de score""" - return score_cableurs().sort(key=lambda x:int(x[1]), reverse=True) + return score_cableurs().sort(key=lambda x: int(x[1]), reverse=True) def sort_by_inverse_score(): """Tri la liste des câbleurs par ordre de score croissant de score""" - return score_cableurs().sort(key=lambda x:int(x[1])) + return score_cableurs().sort(key=lambda x: int(x[1])) def cableurs_utiles(): """Renvoi le nombre de cableurs ayant un score non nul""" useless_cableurs = 0 for k in range(0, len(cableurs())): - if (SCORES[k][1] == 0): + if SCORES[k][1] == 0: useless_cableurs = useless_cableurs + 1 return len(cableurs()) - useless_cableurs