lc_ldap.shortcuts

This commit is contained in:
Vincent Le Gallic 2013-05-16 06:31:57 +02:00
parent dc01a371dc
commit 0922e3c63b
8 changed files with 30 additions and 27 deletions

View file

@ -5,13 +5,15 @@
import os import os
import sys import sys
sys.path.append('/usr/scripts/gestion') sys.path.append('/usr/scripts/gestion')
sys.path.append('/usr/scripts/lc_ldap') sys.path.append('/usr/scripts/')
from config import NETs, blacklist_sanctions, blacklist_sanctions_soft, blacklist_bridage_upload, mac_komaz, mac_titanic, adm_users, accueil_route from config import NETs, blacklist_sanctions, blacklist_sanctions_soft, blacklist_bridage_upload, mac_komaz, mac_titanic, adm_users, accueil_route
import pwd import pwd
import config.firewall import config.firewall
import lc_ldap import lc_ldap.shortcuts
import lc_ldap.objets
import lc_ldap.attributs
import socket import socket
from ipset import IpsetError, Ipset from ipset import IpsetError, Ipset
from iptools import AddrInNet, NetSubnets, IpSubnet, NetInNets from iptools import AddrInNet, NetSubnets, IpSubnet, NetInNets
@ -87,9 +89,9 @@ class firewall_base(object) :
blacklisted = [ machine for machine in conn.search("blacklist=*",sizelimit=4096) if machine.blacklist_actif() ] blacklisted = [ machine for machine in conn.search("blacklist=*",sizelimit=4096) if machine.blacklist_actif() ]
self._blacklisted_machines = set() self._blacklisted_machines = set()
for item in blacklisted: for item in blacklisted:
if isinstance(item, lc_ldap.proprio): if isinstance(item, lc_ldap.objets.proprio):
self._blacklisted_machines = self._blacklisted_machines.union(item.machines()) self._blacklisted_machines = self._blacklisted_machines.union(item.machines())
elif isinstance(item, lc_ldap.machine): elif isinstance(item, lc_ldap.objets.machine):
self._blacklisted_machines.add(item) self._blacklisted_machines.add(item)
else: else:
print >> sys.stderr, 'Objet %s inconnu blacklisté' % a.__class__.__name__ print >> sys.stderr, 'Objet %s inconnu blacklisté' % a.__class__.__name__
@ -206,7 +208,7 @@ class firewall_base(object) :
sys.exit(1) sys.exit(1)
# Connection à la base ldap # Connection à la base ldap
conn = lc_ldap.lc_ldap_admin() conn = lc_ldap.shortcuts.lc_ldap_admin()
self.reloadable = { self.reloadable = {
'blacklist_hard' : self.blacklist_hard, 'blacklist_hard' : self.blacklist_hard,

View file

@ -27,7 +27,7 @@
import sys import sys
sys.path.append('/usr/scripts/') sys.path.append('/usr/scripts/')
sys.path.append('/usr/scripts/gestion') sys.path.append('/usr/scripts/gestion')
sys.path.append('/usr/scripts/lc_ldap') sys.path.append('/usr/scripts/')
import cranslib.deprecated import cranslib.deprecated
cranslib.deprecated.module() cranslib.deprecated.module()
@ -44,13 +44,11 @@ from iptools import AddrInNet, NetSubnets, IpSubnet
from config import NETs, mac_komaz, mac_wifi, mac_titanic, p2p, vlans, debit_max_radin, adm_users, accueil_route, blacklist_sanctions, blacklist_sanctions_soft, periode_transitoire from config import NETs, mac_komaz, mac_wifi, mac_titanic, p2p, vlans, debit_max_radin, adm_users, accueil_route, blacklist_sanctions, blacklist_sanctions_soft, periode_transitoire
import config.firewall import config.firewall
from ipset import IpsetError, Ipset from ipset import IpsetError, Ipset
from lc_ldap import lc_ldap
from ipt import gethostbyname from ipt import gethostbyname
syslog.openlog('firewall') syslog.openlog('firewall')
debug = 1 debug = 1
db = crans_ldap() db = crans_ldap()
QUERY=lc_ldap(uri='ldap://ldap.adm.crans.org/')
class IptablesError(Exception): class IptablesError(Exception):
""" Gestion des erreurs d'iptables """ """ Gestion des erreurs d'iptables """

View file

@ -9,14 +9,14 @@ import hashlib
from socket import gethostname from socket import gethostname
from netifaces import interfaces, ifaddresses, AF_INET from netifaces import interfaces, ifaddresses, AF_INET
sys.path.append('/usr/scripts/lc_ldap') sys.path.append('/usr/scripts/')
sys.path.append('/usr/scripts/gestion') sys.path.append('/usr/scripts/gestion')
sys.path.append('/etc/crans/secrets/') sys.path.append('/etc/crans/secrets/')
import lc_ldap import lc_ldap.shortcuts
import config import config
conn=lc_ldap.lc_ldap_admin() conn = lc_ldap.shortcuts.lc_ldap_admin()
ssh_algo = config.sshfp_algo.keys() ssh_algo = config.sshfp_algo.keys()

View file

@ -3,12 +3,12 @@
import sys import sys
from sh import grep,ErrorReturnCode_1 from sh import grep,ErrorReturnCode_1
sys.path.append('/usr/scripts/gestion') sys.path.append('/usr/scripts/gestion')
sys.path.append('/usr/scripts/lc_ldap') sys.path.append('/usr/scripts/')
sys.path.append('/etc/crans/secrets/') sys.path.append('/etc/crans/secrets/')
import lc_ldap import lc_ldap.shortcuts
conn=lc_ldap.lc_ldap_admin() conn=lc_ldap.shortcuts.lc_ldap_admin()
try: try:
aid=int(sys.argv[1][1:]) aid=int(sys.argv[1][1:])

View file

@ -5,10 +5,10 @@
import sys import sys
import psycopg2 import psycopg2
sys.path.append('/usr/scripts/gestion') sys.path.append('/usr/scripts/gestion')
sys.path.append('/usr/scripts/lc_ldap') sys.path.append('/usr/scripts/')
sys.path.append('/etc/crans/secrets/') sys.path.append('/etc/crans/secrets/')
import lc_ldap import lc_ldap.shortcuts
try: try:
conn = psycopg2.connect("dbname='django' user='crans' host='pgsql.adm.crans.org'") conn = psycopg2.connect("dbname='django' user='crans' host='pgsql.adm.crans.org'")
@ -17,7 +17,7 @@ try:
caller_id = cur.fetchall()[0][0] caller_id = cur.fetchall()[0][0]
if caller_id == 'full_name' or caller_id == 'both': if caller_id == 'full_name' or caller_id == 'both':
conn=lc_ldap.lc_ldap_admin() conn=lc_ldap.shortcuts.lc_ldap_admin()
aid=int(sys.argv[1][1:]) aid=int(sys.argv[1][1:])
adh=conn.search('aid=%s' % aid)[0] adh=conn.search('aid=%s' % aid)[0]
sys.stdout.write('%s %s' % (adh['prenom'][0],adh['nom'][0])) sys.stdout.write('%s %s' % (adh['prenom'][0],adh['nom'][0]))

View file

@ -3,13 +3,14 @@
import sys,os,hashlib import sys,os,hashlib
sys.path.append('/usr/scripts/gestion') sys.path.append('/usr/scripts/gestion')
sys.path.append('/usr/scripts/lc_ldap') sys.path.append('/usr/scripts/')
sys.path.append('/etc/crans/secrets/') sys.path.append('/etc/crans/secrets/')
import secrets,lc_ldap import secrets
import lc_ldap.shortcuts
from sh import asterisk from sh import asterisk
conn=lc_ldap.lc_ldap_admin() conn=lc_ldap.shortcuts.lc_ldap_admin()
def gen_multidial(droit): def gen_multidial(droit):
dial="exten => %(droit)s,1,Ringing\nexten => %(droit)s,n,Wait(4)\nexten => %(droit)s,n,Answer\nexten => %(droit)s,n,Dial(" % {'droit':droit} dial="exten => %(droit)s,1,Ringing\nexten => %(droit)s,n,Wait(4)\nexten => %(droit)s,n,Answer\nexten => %(droit)s,n,Dial(" % {'droit':droit}

View file

@ -2,13 +2,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys import sys
sys.path.append('/usr/scripts/gestion') sys.path.append('/usr/scripts/gestion')
sys.path.append('/usr/scripts/lc_ldap') sys.path.append('/usr/scripts/')
sys.path.append('/etc/crans/secrets/') sys.path.append('/etc/crans/secrets/')
import secrets,lc_ldap import secrets
import lc_ldap.shortcuts
conn=lc_ldap.lc_ldap_admin() conn=lc_ldap.shortcuts.lc_ldap_admin()
try: try:
if len(sys.argv[1])==5: if len(sys.argv[1])==5:
aid=int(sys.argv[1][1:]) aid=int(sys.argv[1][1:])

View file

@ -15,11 +15,12 @@ import time
sys.path.append('/usr/scripts/gestion') sys.path.append('/usr/scripts/gestion')
from config import mac_prise from config import mac_prise
from affich_tools import tableau from affich_tools import tableau
sys.path.append('/usr/scripts/lc_ldap') sys.path.append('/usr/scripts/')
import lc_ldap import lc_ldap.shortcuts
import lc_ldap.objets
import collections import collections
ldap = lc_ldap.lc_ldap_local() ldap = lc_ldap.shortcuts.lc_ldap_local()
conn = psycopg2.connect(user='crans', database='mac_prises') conn = psycopg2.connect(user='crans', database='mac_prises')
conn.set_session(autocommit = True) conn.set_session(autocommit = True)
@ -74,7 +75,7 @@ def genere_comptage(duree):
for entry in fetched: for entry in fetched:
machines = ldap.search('(macAddress=%s)' % entry['mac']) machines = ldap.search('(macAddress=%s)' % entry['mac'])
if len(machines) > 0: if len(machines) > 0:
if isinstance(machines[0], lc_ldap.machineWifi): if isinstance(machines[0], lc_ldap.objets.machineWifi):
continue continue
else: else:
continue continue