Advertisement
Guest User

Rodrigo Lang

a guest
Dec 3rd, 2010
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. #!/usr/bin/php5
  2. <?php
  3.  
  4. $connect = mysql_connect("localhost", "user", "password") or die(mysql_error());
  5. $connect = mysql_select_db("asterisk") or die(mysql_error());
  6.  
  7. $arq = fopen("/var/log/asterisk/queue_log", "r") or exit("Error when try to read file.");
  8.  
  9. while(!feof($arq)) {
  10.     $get_line = fgets($arq);
  11.     if(!isset($get_line)) { break; }
  12.     $get_line = explode("\n", $get_line);
  13.     $line = explode("|", $get_line[0]);
  14.     if(isset($line[5]) || isset($line[6]) || isset($line[7])) {
  15.         if(isset($line[6])) {
  16.             $data = $line[5]."|".$line[6];
  17.             if(isset($line[7])) {
  18.                 $data = $data."|".$line[7];
  19.             }
  20.         } else {
  21.             if(isset($line[7])) {
  22.                 $data = $line[5]."|".$line[7];
  23.             }
  24.         }
  25.                 if(!isset($data)) {
  26.                         $data = "|";
  27.                 }
  28.     }
  29.     //echo "$line[0] $line[1] $line[2] $line[3] $line[4] $data \n";
  30.     $insert = "INSERT INTO queue_log(time,callid,queuename,agent,event,data) VALUES('".$line[0]."','".$line[1]."','".$line[2]."','".$line[3]."','".$line[4]."','".$data."')";
  31.     $insert = mysql_query($insert);
  32.     $line = NULL;
  33.     $data = NULL;
  34. }
  35.  
  36. $update = "UPDATE queue_log SET data = 0 WHERE event = 'RINGNOANSWER' AND data = '|'";
  37. $update = mysql_query($update);
  38.  
  39. fclose($arq);
  40.  
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement