Telegram - . ? :)

, asteriskcdrdb, , .


.php , , , . , SSH

[root@asterisk]# mysql
mysql>CREATE USER ' user'@'localhost' IDENTIFIED BY 'P@ssw0rd'; 

user P@ssw0rd. :

mysql> GRANT SELECT ON asteriskcdrdb.cdr TO 'user'

.php, . :

$hostname = "localhost";  // .        ,     asteriskcdrdb;
$username = "user"; // 
$password = "P@ssw0rd"; //    
$dbName = "asteriskcdrdb"; // ,      
$today = date('y-m-d'); //     2016-03-25

$counter = 1; // 

mysql_connect($hostname,$username,$password) OR DIE("    ");  //    

mysql_select_db($dbName) or die(mysql_error()); //  .    -   

$headers  = "Content-type: text/html; charset=windows-1251 \r\n"; //  
$headers .= "From:   \r\n"; 

$headers .= "Reply-To: info@merionet.ru\r\n";

, 100. , , , 3 ( ). cdr. .php :

$query = "SELECT  `dst` ,  `src` ,  `duration` ,  `dstchannel` ,  `calldate` ,  `disposition` FROM  `cdr` WHERE `calldate` >='$today 00:00:00' AND `calldate` <='$today 23:59:59' AND LENGTH(  `src` ) >3 AND `dst` = '100';"  ;
$res=mysql_query($query) or die(mysql_error()); //  .    -  . 
$number = mysql_num_rows($res); //     

. . , :

//     
$mes .= ' 
table style="max-width: 575px;border-bottom:none; margin: 0 auto;border-spacing: inherit;">
thead>
tr style="border-bottom: 2px solid #05477c;">
th style="padding:10px; color: #fff; max-width: 150px;background:#05477c;"> 
th style="padding:10px; color: #fff; max-width: 150px;background:#05477c;">
th style="padding:10px; color: #fff; max-width: 100px;background:#05477c;"> 
th style="padding:10px; color: #fff; max-width: 45px;background:#05477c;">
th style="padding:10px; color: #fff; max-width: 45px;background:#05477c;"> 
/tr>
/thead>';
//   .           sql 
  while ($row=mysql_fetch_array($res)) { $mes .= '
tbody>
tr style="width: 100px;">
td style="padding:10px;   border-bottom: 1px solid #eee; text-align:center;">'.$counter.'
td style="padding:10px;   border-bottom: 1px solid #eee; text-align:center;min-width: 100px;">'. $row['calldate'].'
td style="padding:10px;   border-bottom: 1px solid #eee; text-align:center;min-width: 100px;">'. $row['src'].'
td style="padding:10px;  border-bottom: 1px solid #eee; text-align:center;">'.$row['dst'].'
td style="padding:10px;  text-align:center;  border-bottom: 1px solid #eee; min-width: 120px; ">'.$row['disposition'].'
/tr>';	
$counter = $counter + 1;
  }

, $mes html , . :

mail("info@merionet.ru", '   '.$today.'', $mes, $headers);
! , .php (windows-1251)

, . :

Asterisk

. cron. , , , 17:30, :

30 17 * * * php /home/admin/mail_report.php

php, .


?

 .

P.S. , :)

"",