sip_multidial.py 1.3 KB
Newer Older
Daniel Stan's avatar
Daniel Stan committed
1
#!/bin/bash /usr/scripts/python.sh
2
# -*- mode: python; coding: utf-8 -*-
3 4 5

import sys,os,hashlib

Vincent Le gallic's avatar
Vincent Le gallic committed
6
import lc_ldap.shortcuts
7
from asterisk_reload_conf import reload_config
8 9


10 11 12 13 14 15 16 17 18 19 20
def gen_multidial(name, entensions):
   dial="""
exten => %(name)s,1,Ringing
exten => %(name)s,n,Wait(4)
exten => %(name)s,n,Answer
exten => %(name)s,n,Dial(%(entensions)s,30)
exten => %(name)s,n,Wait(3)
exten => %(name)s,n,VoiceMail(%(name)s@666)
exten => %(name)s,n,Hangup()
""" % {'name':name, 'entensions': '&'.join('SIP/1%04d' % num for num in entensions)}
   return dial
21

22
if __name__ == '__main__' :
Daniel Stan's avatar
Daniel Stan committed
23
    conn=lc_ldap.shortcuts.lc_ldap_admin()
24 25 26 27 28 29 30 31 32 33 34 35 36
    multidial=""
    for droit in ['nounou', 'bureau', 'cableur', 'imprimeur']:
        multidial+=gen_multidial(droit, (adh['aid'][0].value for adh in conn.search(u'(&(droits=%s)(!(chbre=EXT)))' % droit)))
    multidial_md5=hashlib.md5(multidial).hexdigest()
    try:
        multidial_old_md5=hashlib.md5(open('/usr/scripts/var/sip/sip_multidial','r').read()).hexdigest()
    except IOError:
        multidial_old_md5=""
    if multidial_md5 !=multidial_old_md5:
        file=open('/usr/scripts/var/sip/sip_multidial.new','w')
        file.write(multidial)
        file.close()
        os.rename('/usr/scripts/var/sip/sip_multidial.new','/usr/scripts/var/sip/sip_multidial')
37
        reload_config('dialplan')