MikeD
New Member
- Joined
- Mar 2, 2016
- Messages
- 14
- Reaction score
- 9
Hi,
Been enjoying PIAF and I have been tuning my install to work better for me. One of the things I did was to make a new function to replace the old CDR report export csv function to export a file ready for upload to the Blacklist Module. Every day (or when I remember) I run a query for a destination of "*98" for the previous day.
I would love to see this make it into a future release as the number of hack attempts is getting smaller and smaller as the Blacklist grows.
Mike
//**********change to cdr/functions.inc.php sdded new function
function cdr_export_blacklist_csv($csvdata) {
// Searching for more than 10,000 records take more than 30 seconds.
// php default timeout is 30 seconds, hard code it to 3000 seconds for now (which is WAY overkill).
// TODO: make this value a setting in Advanced Settings
set_time_limit(3000);
$fname = "cdr__" . (string) time() . $_SERVER["SERVER_NAME"] . ".csv";
$csv_header ="src,clid"; //<=====what fields to output
$mimetype = "application/octet-stream";
// Start sending headers
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Transfer-Encoding: binary");
header("Content-Type: " . $mimetype);
header("Content-Disposition: attachment; filename=\"" . $fname . "\";" );
// Send data
$out = fopen('php://output', 'w');
fputcsv($out, explode(",",$csv_header));
foreach ($csvdata as $csv) {
$csv_line = array();
foreach(explode(",",$csv_header) as $k => $item) {
if ($item=='clid') //<==need to cleanup the callerID field
{
$csv[$item]=preg_replace('/\<.*\>/','',$csv[$item]); //<=====get rid of <number>
$csv[$item]=preg_replace('/"/','',$csv[$item]);//<=====delete quotes
}
$csv_line[$k] = $csv[$item];
}
fputcsv($out, $csv_line);
}
fclose($out);
die();
}
//***********change to cdr/page.cdr.php
[snip]
if ( isset($_POST['need_csv']) && $_POST['need_csv'] == 'true' ) {
$query = "(SELECT calldate, clid, did, src, dst, dcontext, channel, dstchannel, lastapp, lastdata, duration, billsec, disposition, amaflags, accountcode, uniqueid, userfield, cnum, cnam, outbound_cnum, outbound_cnam, dst_cnam FROM $db_name.$db_table_name $where $order $sort LIMIT $result_limit)";
$resultcsv = $dbcdr->getAll($query, DB_FETCHMODE_ASSOC);
cdr_export_blacklist_csv($resultcsv); //<===changed to my blacklist function
}
[snip]
Been enjoying PIAF and I have been tuning my install to work better for me. One of the things I did was to make a new function to replace the old CDR report export csv function to export a file ready for upload to the Blacklist Module. Every day (or when I remember) I run a query for a destination of "*98" for the previous day.
I would love to see this make it into a future release as the number of hack attempts is getting smaller and smaller as the Blacklist grows.
Mike
//**********change to cdr/functions.inc.php sdded new function
function cdr_export_blacklist_csv($csvdata) {
// Searching for more than 10,000 records take more than 30 seconds.
// php default timeout is 30 seconds, hard code it to 3000 seconds for now (which is WAY overkill).
// TODO: make this value a setting in Advanced Settings
set_time_limit(3000);
$fname = "cdr__" . (string) time() . $_SERVER["SERVER_NAME"] . ".csv";
$csv_header ="src,clid"; //<=====what fields to output
$mimetype = "application/octet-stream";
// Start sending headers
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Transfer-Encoding: binary");
header("Content-Type: " . $mimetype);
header("Content-Disposition: attachment; filename=\"" . $fname . "\";" );
// Send data
$out = fopen('php://output', 'w');
fputcsv($out, explode(",",$csv_header));
foreach ($csvdata as $csv) {
$csv_line = array();
foreach(explode(",",$csv_header) as $k => $item) {
if ($item=='clid') //<==need to cleanup the callerID field
{
$csv[$item]=preg_replace('/\<.*\>/','',$csv[$item]); //<=====get rid of <number>
$csv[$item]=preg_replace('/"/','',$csv[$item]);//<=====delete quotes
}
$csv_line[$k] = $csv[$item];
}
fputcsv($out, $csv_line);
}
fclose($out);
die();
}
//***********change to cdr/page.cdr.php
[snip]
if ( isset($_POST['need_csv']) && $_POST['need_csv'] == 'true' ) {
$query = "(SELECT calldate, clid, did, src, dst, dcontext, channel, dstchannel, lastapp, lastdata, duration, billsec, disposition, amaflags, accountcode, uniqueid, userfield, cnum, cnam, outbound_cnum, outbound_cnam, dst_cnam FROM $db_name.$db_table_name $where $order $sort LIMIT $result_limit)";
$resultcsv = $dbcdr->getAll($query, DB_FETCHMODE_ASSOC);
cdr_export_blacklist_csv($resultcsv); //<===changed to my blacklist function
}
[snip]