Provision your Cisco 79xx SIP Phone from Active Directory with these Auto Provisioning Scripts
November 6, 2008
Our friend over at Dave.vc has released a new set of scripts for provisioning your Cisco phones from Active Directory.
Visit Dave's site for more awesome tools like this.
You can download the Cisco Provisioning scripts.
Here's his tutorial, and provisioning scripts.
Here are the scripts I use to automatically provision cisco phones via AD information. The phone number (extension) is taken from AD’s ‘phone number’ field and the mac address comes from AD’s ‘IP Phone’ field.
As with the reboot script below, these scripts require PHP to be installed and compiled with LDAP and CLI on the asterisk server. It is possible (obviously) to perform these tasks remotely (not on the asterisk server) but that’s outside the scope of this post.
The PHP script reads the template files and does simple string replacement as needed. If the user is brand new, it adds their voicemail account, picks a psuedo-random extension password and tells asterisk what their email address is for the voicemail-to-email setup. The email information will only be in AD if you put it there or are running an exchange server in the same forest (as in the example).
It’s useful to note that all of the extensions I use in this example setup are in the format of 3xx. We then have another extension of the format 4xx set up to auto-answer so that we can do paging and intercom. You may need to modify if you have more than 100 extensions.
In order to add the extension, we read the config template in the directory listed and perform string replacement:
function add_extension($name,$extension,$secret,$email){
$template = file_get_contents(â€/etc/asterisk/phones/conf.templateâ€);
$template = str_replace(â€<<<mainextension>>>â€,$extension,$template);
$template = str_replace(â€<<<email>>>â€,$email,$template);
$template = str_replace(â€<<<fullname>>>â€,$name,$template);
$template = str_replace(â€<<<secret>>>â€,$secret,$template);
$template = str_replace(â€<<<pageextension>>>â€,â€4?.substr($extension,1),$template);
file_put_contents(â€/etc/asterisk/phones/â€.$extension.â€.confâ€,$template);
}
The XML config file creation/modification follows the same format:
function provision_phone($name,$extension,$secret,$mac){
$template = file_get_contents(â€/tftpboot/SEPCONF.templateâ€);
$template = str_replace(â€<<<mainextension>>>â€,$extension,$template);
$template = str_replace(â€<<<email>>>â€,$email,$template);
$template = str_replace(â€<<<fullname>>>â€,$name,$template);
$template = str_replace(â€<<<secret>>>â€,$secret,$template);
$template = str_replace(â€<<<pageextension>>>â€,â€4?.substr($extension,1),$template);
file_put_contents(â€/tftpboot/SEPâ€.$mac.â€.cnf.xmlâ€,$template);
}
And finally we add the voicemail account:
function add_voicemail($name,$extension,$email){
$template = file_get_contents(â€/etc/asterisk/voicemail.confâ€);
$template .= “\nâ€.$extension.†=> 1234,â€.$name.â€,â€.$email;
file_put_contents(â€/etc/asterisk/voicemail.confâ€,$template);
}
These functions are really rather trivial but save a world of time when it comes to installing 75 new phones in one fell swoop — or even when you’re attempting to maintain continuity between installations separated lots of time.
I attached the the script to this post as well as some screen shots and config templates (SEPCONF and EXTENCONF) to facilitate setting up your AD objects to allow for automatic phone provisioning.




Comments
Got something to say?