[Asterisk-Users] Some * scripts: Pull asterisk config from LDAP and authenticate() against voicemail passwords

Simon Morris simon.morris at cmtww.com
Fri Apr 29 00:57:24 MST 2005


Hello,

Wrote some Python scripts last night to "scratch an itch" I was having
with Asterisk.

http://www.beerandspeech.org/cgi-bin/blosxom.cgi/tech/linux/050429a.html
http://www.beerandspeech.org/images/050429/asterisk-config.py.txt
http://www.beerandspeech.org/images/050429/asterisk-passwd.py.txt

asterisk-config.py lets me store asterisk config data in LDAP and generate config files from it

head -n 32 asterisk-config.py
#!/usr/bin/python

# This script connects to an LDAP server looking for attributes that it can use
# to build some asterisk config files
#
# You need to setup your LDAP server (this was written in mind to connect to AD)
# and populate the correct attributes - it will then go away and build sip.conf,
# extensions.conf, SIP$MAC.cnf, SEP$MAC.cnf and CTLSEP$MAC.cnf
#
# This script builds sip.conf and extensions.conf in 3 parts... it reads a file
# (by default /etc/asterisk/sip.conf.head ) then dynamically builds the
# extensions and then appends the contents of sip.conf.tail
#
# This means you can maintain the static content of sip.conf ( the [general]
# parameters and dynamically build the rest
#
# On my extensions.conf.head the last line is [default] so all the
# dynamically created extensions go into this context
#
# You can also elect to not include certain SIP lines, phones and extensions in
# the autoconfiguration process
#
# It also writes out a Cisco XML phone directory file and a HTML phone list
# style file. On these files you can expand your LDAP search to include
# external non-asterisk users - maybe business contacts or such-like
#
# BUGS: Currently doesn't do a lot of error checking so missing attributes may
# make the script barf.. also doesn't do anything to voicemail.conf - thats coming
# next
#
# If you have any questions, comments or patches please email me at simon.morris at cmtww.com

and secondly asterisk-passwd.py allows me to run the Authenticate() command using the same password
people have for their voicemail. Basically greps voicemail.conf and dumps their password into separate file

head -n 18 asterisk-passwd.py

#!/usr/bin/python

# I needed to add a Asterisk Authenticate() command to a dialplan but
# I wanted to use the same passwords as those in voicemail.conf to avoid giving
# users multiple passwords - grepping voicemail.conf seemed a little complicated
# so this script runs every 5 minutes under cron and it refreshs the password files
# in case a user changes their voicemail password (which happens like..... never!)
#
# To include in the dial plan I used this....
# [callforwarding]
# exten => s,1,Authenticate(/etc/asterisk/passwords/${CALLERIDNAME})
#
# So the Authenticate command would read /etc/asterisk/passwords/683 for my extension
#
# BUGS: Hmm, I guess it depends if your ${CALLEDIDNAME} equals your numeric extension number - mine did :)
# If not play with the splitting of the line to get the correct index for the
# filename - look at the output of asterisk -rvvvvvv to see which filename it's trying to read
# Any questions or comments welcome to simon.morris at cmtww.com


Hope someone finds these useful - please let me know if you use them and it works.

Rgds

~sm



More information about the asterisk-users mailing list