提交 2f8ec154 authored 作者: Moose's avatar Moose

Added directory support and voicemail parsing

上级 619e5fad
......@@ -2,7 +2,13 @@
<user id="[[[username]]]">
<params>
<param name="password" value="[[[password]]]"/>
<param name="vm-password" value="[[[extension]]]"/>
<param name="vm-password" value="[[[vm_pass]]]"/>
<param name="vm-email-all-messages" value="true"/>
<param name="vm-mailto" value="[[[email]]]"/> <!-- or just notify -->
<param name="vm-notify-mailto" value="[[[email]]]"/> <!-- don't need notify if you have the full voicemail -->
<param name="vm-attach-file" value="true" /> <!-- You need this if you want the voicemail attached -->
<param name="vm-message-ext" value="wav"/> <!-- Can be 'mp3' but needs mod_lame to be loaded. -->
[[[disable_directory]]]
</params>
<variables>
<variable name="toll_allow" value="domestic,international,local"/>
......@@ -12,6 +18,7 @@
<variable name="effective_caller_id_number" value="[[[extension]]]"/>
<variable name="outbound_caller_id_name" value="$${outbound_caller_name}"/>
<variable name="outbound_caller_id_number" value="$${outbound_caller_id}"/>
[[[full_name]]]
</variables>
</user>
</include>
<?php
$file = 'sip-users.example';
$vfile = 'voicemail.example';
$users = parse_ini_file($file, true);
$lines = file($vfile);
$vmboxs = convert_aster_voicemail($lines);
$template = file_get_contents('Templates/User-Template.xml');
echo "Converting Asterisk Users to user files".PHP_EOL;
echo "Using Template: Templates/User-Template.xml".PHP_EOL;
......@@ -9,17 +12,52 @@ echo "".PHP_EOL;
echo "Running..... ".PHP_EOL;
foreach ($users as $extension => $values){
makeUser($template, $extension, $values['secret'], $values['context'], $values['callerid']);
makeUser($template, $extension, $values['secret'], $values['context'], $values['callerid'], $vmboxs[$extension]);
}
echo "Completed Run".PHP_EOL;
function makeUser($template, $extension, $password, $context, $callerid) {
/***
Processes voicemail.conf and makes it so you can set the voicemail password, full name and email from voicemail.conf
to the user xml files based off extension.
**/
function convert_aster_voicemail($lines){
$data = array();
foreach($lines as &$line){
$line = preg_split('/\s*=>\s*/', trim($line));
if (is_numeric($line[0])){
$data[$line[0]] = explode(',',$line[1]);
}
}
return $data;
}
//Processes template and populates it with values from the sip_peers file and information from the voicemail.conf files
function makeUser($template, $extension, $password, $context, $callerid, $vmbox) {
$xml = str_replace('[[[username]]]', $extension, $template);
$xml = str_replace('[[[password]]]', $password, $xml);
$xml = str_replace('[[[extension]]]', $extension, $xml);
$xml = str_replace('[[[callerid]]]', $callerid, $xml);
$xml = str_replace('[[[context]]]', $context, $xml);
if (empty($vmbox[1])){
$xml = str_replace('[[[disable_directory]]]','<param name="directory-exten-visible" value="false"/>',$xml);
$xml = str_replace('[[[full_name]]]','' ,$xml);
} else {
$xml = str_replace('[[[disable_directory]]]','' , $xml);
$full_name = "<variable name=\"directory_full_name\" value=\"$vmbox[1]\"/>";
$xml = str_replace('[[[full_name]]]',$full_name ,$xml);
}
$xml = str_replace('[[[email]]]', $vmbox[2], $xml);
if (empty($vmbox[0])){
$xml = str_replace('[[[vm_pass]]]', $extension, $xml);
} else {
$xml = str_replace('[[[vm_pass]]]', $vmbox[0], $xml);
}
echo "Writing XML file for $extension".PHP_EOL;
file_put_contents('extensions/'.$extension.'.xml', $xml);
}
......
<include>
<user id="1000">
<params>
<param name="password" value="mypassword"/>
<param name="vm-password" value="5555"/>
<param name="vm-email-all-messages" value="true"/>
<param name="vm-mailto" value="john.doe@example.com"/> <!-- or just notify -->
<param name="vm-notify-mailto" value="john.doe@example.com"/> <!-- don't need notify if you have the full voicemail -->
<param name="vm-attach-file" value="true" /> <!-- You need this if you want the voicemail attached -->
<param name="vm-message-ext" value="wav"/> <!-- Can be 'mp3' but needs mod_lame to be loaded. -->
</params>
<variables>
<variable name="toll_allow" value="domestic,international,local"/>
<variable name="accountcode" value="1000"/>
<variable name="user_context" value="default"/>
<variable name="effective_caller_id_name" value="John Doe"/>
<variable name="effective_caller_id_number" value="1000"/>
<variable name="outbound_caller_id_name" value="$${outbound_caller_name}"/>
<variable name="outbound_caller_id_number" value="$${outbound_caller_id}"/>
<variable name="directory_full_name" value="John Doe"/>
</variables>
</user>
</include>
[default]
1000 => 5555,John Doe,john.doe@example.com,,hidefromdir=yes|tz=eastern|delete=yes
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论