Pessoal achei esse script que pega os arquivos do diretório INBOX e sobe automático no banco, funfou belezinha segue o mesmo pra alguém que tiver interesse:<br><br><ol><li>!/usr/bin/php -q
</li></ol><?
<br>$my_user = "convert"; <br>$my_passwd = "convert"; <br>$my_host = "localhost"; <br>$my_database = "asterisk"; <br>$my_table = "voicemessages"; <br>
$msg_format = "WAV"; <br>$dir_prefix = "/var/spool/asterisk/voicemail/"; <br>$ignore_default = TRUE; # TRUE ignorar contexto 'default' ,
FALSE nao ignora contexto default
<br>
<br>echo "Starting....\n";
<br>$DB = mysql_connect($my_host, $my_user, $my_passwd) or die("Could
not connect: " . mysql_error());
<br>mysql_select_db($my_database) or die("Could not select database: " .
mysql_error());
<br>
<br>if(!is_dir($dir_prefix)) die("$dir_prefix is not a directory.\n");
<br>$DirH = opendir($dir_prefix) or die ("opendir failed on
$dir_prefix.\n");
<br>while(FALSE !== ($DirEnt = readdir($DirH)) ) { # each of these
directories is a voicemailbox context
<br><span style="font-family: monospace;"> if($DirEnt == "." || $DirEnt == "..") continue;
</span><br><span style="font-family: monospace;"> if($DirEnt == "default" && $ignore_default) continue;
</span><br><span style="font-family: monospace;"> echo "Processing context directory $dir_prefix$DirEnt\n";
</span><br><span style="font-family: monospace;"> $mailboxcontext=$DirEnt;
</span><br><span style="font-family: monospace;"> $CtxH = opendir($dir_prefix.$DirEnt) or die ("opendir failed on $dir_prefix$DirEnt\n");
</span><br><span style="font-family: monospace;"> while(FALSE !== ($CtxEnt = readdir($CtxH)) ) { # each of these directories is a voicemailbox
</span><br><span style="font-family: monospace;"> if($CtxEnt == "." || $CtxEnt == "..") continue;
</span><br><span style="font-family: monospace;"> $mailbox=$CtxEnt;
</span><br><span style="font-family: monospace;"> echo "\tVoicemailbox $mailbox\n";
</span><br><span style="font-family: monospace;"> $MbxH = opendir($dir_prefix.$DirEnt."/".$mailbox) or die ("opendir failed on $dir_prefix$DirEnt/$mailbox\n");
</span><br><span style="font-family: monospace;"> while(FALSE !== ($MbxEnt = readdir($MbxH)) ) { # each of these directories is a folder or announcemen/greeting
</span><br><span style="font-family: monospace;"> if($MbxEnt == "." || $MbxEnt == "..") continue;
</span><br><span style="font-family: monospace;"> $path = $dir_prefix.$DirEnt."/".$mailbox."/".$MbxEnt;
</span><br><span style="font-family: monospace;"> if(is_dir($path)) {
</span><br><span style="font-family: monospace;"> echo "\t\tVmailbox folder $MbxEnt: ";
</span><br><span style="font-family: monospace;"> $FldH = opendir($path) or die ("opendir failed on $path\n");
</span><br><span style="font-family: monospace;"> while(FALSE !== ($FldEnt = readdir($FldH))) { # entries in mailbox folders: the messages
</span><br><span style="font-family: monospace;"> if($FldEnt == "." || $FldEnt == "..") continue;
</span><br><span style="font-family: monospace;"> if(strpos($FldEnt,"txt") !== FALSE) {
</span><br><span style="font-family: monospace;"> doMsgInsert($mailboxcontext,$mailbox,$FldEnt,$path);
</span><br><span style="font-family: monospace;"> echo ".";
</span><br><span style="font-family: monospace;"> }
</span><br><span style="font-family: monospace;"> } # end mailbox-folder directory loop
</span><br><span style="font-family: monospace;"> closedir($FldH);
</span><br><span style="font-family: monospace;"> echo "\n";
</span><br><span style="font-family: monospace;"> } else {
</span><br><span style="font-family: monospace;"> switch($MbxEnt) {
</span><br><span style="font-family: monospace;"> case "busy.".$msg_format:
</span><br><span style="font-family: monospace;"> case "temp.".$msg_format:
</span><br><span style="font-family: monospace;"> case "greet.".$msg_format:
</span><br><span style="font-family: monospace;"> case "unavail.".$msg_format:
</span><br><span style="font-family: monospace;"> $announce = substr($MbxEnt,0,-4);
</span><br><span style="font-family: monospace;"> break;
</span><br><span style="font-family: monospace;"> default:
</span><br><span style="font-family: monospace;"> $announce = "WRONG_FORMAT";
</span><br><span style="font-family: monospace;"> break;
</span><br><span style="font-family: monospace;"> }
</span><br><span style="font-family: monospace;"> if($announce == "WRONG_FORMAT") continue;
</span><br><span style="font-family: monospace;"> doGreetInsert($mailboxcontext,$mailbox,$path);
</span><br><span style="font-family: monospace;"> echo "\t — Mailbox recording $announce done.\t \n";
</span><br><span style="font-family: monospace;"> }
</span><br><span style="font-family: monospace;"> } # end voicemailbox directory loop
</span><br><span style="font-family: monospace;"> closedir($MbxH);
</span><br><span style="font-family: monospace;"> } # end voicemailbox directory loop
</span><br><span style="font-family: monospace;"> closedir($CtxH);
</span><br>} # end voicemailbox context directory loop
<br>closedir($DirH);
<br>
<br>echo "\n";
<br>echo "All done.\n";
<br>exit(0);
<br>
<br>function doMsgInsert($mailboxcontext,$mailbox,$msgFile,$path) {
<br><span style="font-family: monospace;"> global $msg_format;
</span><br><span style="font-family: monospace;"> $Ipref = "INSERT INTO voicemessages (msgnum,context,callerid,duration,origtime,dir,mailboxuser,mailboxcontext,recording) VALUES (";
</span><br><span style="font-family: monospace;"> $msgnum = 0+substr($msgFile,3,4);
</span><br><span style="font-family: monospace;"> $DETAILS = parse_ini_file($path."/".$msgFile,FALSE);
</span><br><span style="font-family: monospace;"> $DFile = fopen($path."/".$msgFile,"r") or die ("Could not open $dir_prefix $MSG_FILE \n");
</span><br><span style="font-family: monospace;"> while(!feof($DFile)) { # need to get callerid seperately
</span><br><span style="font-family: monospace;"> $LINE = rtrim(fgets($DFile,4096));
</span><br><span style="font-family: monospace;"> if(strpos($LINE,"callerid") !== FALSE) list($y,$callerid) = explode("=",$LINE);
</span><br><span style="font-family: monospace;"> }
</span><br><span style="font-family: monospace;"> fclose($DFile);
</span><br><span style="font-family: monospace;"> $recording = mysql_real_escape_string(file_get_contents($path."/".substr($msgFile,0,-3).$msg_format));
</span><br><span style="font-family: monospace;"> if($recording) $BLOB = "read ok"; else $BLOB = "false";
</span><br><span style="font-family: monospace;"> $INSERT = $Ipref . "'".$msgnum."','".$DETAILS<em>context</em>>'context'."','" . mysql_real_escape_string($callerid)."','";
</span><br><span style="font-family: monospace;"> if (!isset($DETAILS<em>duration</em>>'duration')) $DETAILS<em>duration</em>>'duration' = 0;
</span><br><span style="font-family: monospace;"> $INSERT .= $DETAILS<em>duration</em>>'duration'."','";
</span><br><span style="font-family: monospace;"> if (!isset($DETAILS<em>origtime</em>>'origtime')) $DETAILS<em>origtime</em>>'origtime' = 0;
</span><br><span style="font-family: monospace;"> $INSERT .= $DETAILS<em>origtime</em>>'origtime'."','" . $path . "','$mailbox','$mailboxcontext','";
</span><br><span style="font-family: monospace;"> $INSERT_REAL = $INSERT . $recording ."')";
</span><br><span style="font-family: monospace;"> $INSERT .= $BLOB. "')";
</span><br><span style="font-family: monospace;"> $R = mysql_query($INSERT_REAL) or die("Problem with INSERT: \n$INSERT\n\n". mysql_error()."\n");
</span><br>} # end function doMsgInsert()
<br>
<br>function doGreetInsert($mailboxcontext,$mailbox,$path) {
<br><span style="font-family: monospace;"> $Gpref = "INSERT INTO voicemessages (msgnum,dir,mailboxuser,mailboxcontext,recording) VALUES (-1,'";
</span><br><span style="font-family: monospace;"> $dir = substr($path,0,-4);
</span><br><span style="font-family: monospace;"> $recording = mysql_real_escape_string(file_get_contents($path));
</span><br><span style="font-family: monospace;"> if($recording) $BLOB = "ok"; else $BLOB = "failed";
</span><br><span style="font-family: monospace;"> $INSERT = $Gpref . $dir . "','$mailbox','$mailboxcontext','";
</span><br><span style="font-family: monospace;"> $INSERT_REAL = $INSERT . $recording . "')";
</span><br><span style="font-family: monospace;"> $INSERT .= $BLOB."')";
</span><br><span style="font-family: monospace;"> $R = mysql_query($INSERT_REAL) or die("Problem with INSERT: \n$INSERT\n\n". mysql_error()."\n");
</span><br>} # end function doGreetInsert()
<br>
<br>?>
<br clear="all"><br>-- <br>Wendell Silva Bandeira<br>Analista de TI <br><br>