#!/usr/bin/php -q The voicemail user * @param string $DPReturnVarName -> The name of the diaplan VARIABLE to return the email to * * EXAMPLE * * exten => 1921,n,AGI(getVMUserData|1234|vmuserEmail) * exten => 1921,n,NoOp(Resulting message for AGI ${noopMessage}) * exten => 1921,n... * * */ /** * Parse voicemail.conf file looking for a user * Then return its email address * * @param int $VMUser * @return string */ function lookForVMEmail($VMUser, $voicemailconf){ $dataFound = array(); $status = "VMUser NOT FOUND"; $nomoreloop = false; $fileArray = file($voicemailconf); foreach ($fileArray as $line){ //leave commented lines out if( strpos(trim($line), ';') !== 0 && !$nomoreloop ){ $findme = '=>'; $pos = strpos($line, $findme); // Note our use of ===. Simply == would not work as expected if ($pos !== false) { /* 1104 => 7906,Jane Doe,,tz=eastern|attach=yes|saycid=no|review=yes|operator=yes|envelope=no|sayduration=no| 1234 => 1234,Some User,email@address.com,pager@address.com,saycid=yes|dialout=fromvm|callback=fromvm|review=yes|operator=yes */ $elements = explode('=>', $line); if(trim($elements[0]) == trim($VMUser)){ $nomoreloop = true; $status = "NO EMAIL"; $elements2 = explode(',',$elements[1]); if(trim($elements2[2]) != ''){ // DATA FOUND $status = trim($elements2[2]); } } } } } return $status; } /* Parameters */ $VMUser = $argv[1]; $DPReturnVarName = $argv[2]; $foundEmail = ''; $voicemailconf = "/etc/asterisk/voicemail.conf"; /* Parse voicemail.conf and find data */ if(trim($DPReturnVarName) != '' && trim($VMUser) != ''){ //both parametes ok //lets look for the user $foundEmail = lookForVMEmail($VMUser, $voicemailconf); switch ($foundEmail){ case 'VMUser NOT FOUND': echo "\SET VARIABLE noopMessage Warning-Voicemail_User_". $VMUser ."_NOT_FOUND_in_voicemail.conf \"*#\"\n"; echo "\SET VARIABLE $DPReturnVarName ERROR \"*#\"\n"; break; case 'NO EMAIL': echo "\SET VARIABLE noopMessage Warning-NO_EMAIL_ADDRESS_FOUND_for_Voicemail_User_". $VMUser ."_in_voicemail.conf \"*#\"\n"; echo "\SET VARIABLE $DPReturnVarName ERROR \"*#\"\n"; break; default: /* Return required data to dialplan */ echo "\SET VARIABLE noopMessage Voicemail_User_". $VMUser ."_FOUND_in_voicemail.conf \"*#\"\n"; echo "\SET VARIABLE $DPReturnVarName " . $foundEmail . " \"*#\"\n"; break; } //end Switch } else { //missing parameter echo "\SET VARIABLE noopMessage Error-Missing_parameters-param1_is_".$VMUser."_param2_is_".$DPReturnVarName." \"*#\"\n"; } ?>