Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git://github.com/2600hz/bluebox.git
- Loading branch information
Showing
78 changed files
with
3,317 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
/** | ||
* Config options for the Calls module | ||
*/ | ||
|
||
$config['scandir'] = '/usr/local/freeswitch/log/cdr-csv'; | ||
$config['defaulttemplate'] = '"uuid","${uuid}","accountcode","${accountcode}","caller_id_number","${caller_id_number}","destination_number","${destination_number}","context","${context}","duration","${duration}","start_stamp","${start_stamp}","answer_stamp","${answer_stamp}","end_stamp","${end_stamp}","billsec","${billsec}","hangup_cause","${hangup_cause}","channel_name","${channel_name}","bridge_channel","${bridge_channel}","caller_id_name","${caller_id_name}","bleg_uuid","${bleg_uuid}","read_codec","${read_codec}","write_codec","${write_codec}"'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
class Call_Configure extends Bluebox_Configure | ||
{ | ||
public static $version = 1.0; | ||
public static $packageName = 'calls'; | ||
public static $author = 'Dale Hege'; | ||
public static $vendor = ''; | ||
public static $license = 'MPL'; | ||
public static $summary = 'Call Records and Reporting'; | ||
public static $default = TRUE; | ||
public static $type = Package_Manager::TYPE_MODULE; | ||
public static $required = array( | ||
'core' => 0.1 | ||
); | ||
public static $navLabel = 'Calls'; | ||
public static $navBranch = '/Reports/'; | ||
public static $navURL = 'calls/index'; | ||
public static $navSubmenu = array( | ||
'Download Records' => '/calls/download', | ||
'Import Call Records' => '/calls/import' | ||
); | ||
|
||
public function postInstall() | ||
{ | ||
|
||
$settings = new CallsSetting; | ||
$settings->save(); | ||
|
||
} | ||
|
||
public function repair() | ||
{ | ||
|
||
$settings = new CallsSetting; | ||
$settings->save(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
class Calls_Controller extends Bluebox_Controller | ||
{ | ||
protected $baseModel = 'Calls'; | ||
|
||
public $coreFields = array( | ||
'uuid' => 'Unique ID', | ||
'accountcode' => 'Account Code', | ||
'caller_id_number' => 'Caller ID Number', | ||
'destination_number' => 'Desitnation', | ||
'context' => 'Context', | ||
'duration' => 'Duration Seconds', | ||
'start_stamp' => 'Start', | ||
'answer_stamp' => 'Answered', | ||
'end_stamp' => 'End', | ||
'billsec' => 'Billable Seconds', | ||
'hangup_cause' => 'Call End Cause', | ||
'channel_name' => 'Src Channel', | ||
'bridge_channel' => 'Dest Chanel' | ||
); | ||
|
||
|
||
public function index() | ||
{ | ||
$this->template->content = new View('generic/grid'); | ||
|
||
// Setup the base grid object | ||
$grid = jgrid::grid($this->baseModel, array( | ||
'caption' => 'Calls' | ||
) | ||
) | ||
// Add the base model columns to the grid | ||
->add('calls_id', 'ID', array( | ||
'hidden' => true, | ||
'key' => true | ||
)) | ||
->add('start_stamp', 'Start', array( | ||
'callback' => array( | ||
'arguments' => 'calls_id', | ||
'function' => array($this, '_showCall') | ||
) | ||
)) | ||
->add('caller_id_number', 'Calling Party') | ||
->add('destination_number', 'Called Party') | ||
->add('duration', 'Length') | ||
->add('hangup_cause', 'Call End Cause') | ||
// Add the actions to the grid | ||
->addAction('calls/view', 'View', array( | ||
'arguments' => 'calls_id', | ||
'width' => '120' | ||
) | ||
); | ||
|
||
// Let plugins populate the grid as well | ||
$this->grid = $grid; | ||
plugins::views($this); | ||
|
||
// Produce a grid in the view | ||
$this->view->grid = $this->grid->produce(); | ||
} | ||
|
||
public function download($start = NULL, $end = NULL) { | ||
// Download a CDR | ||
|
||
// Setup the base grid object | ||
$grid = jgrid::grid($this->baseModel, array( | ||
'gridName' => 'calldownload', | ||
'caption' => 'Export Preview' | ||
) | ||
) | ||
// Add the base model columns to the grid | ||
->add('calls_id', 'ID', array( | ||
'hidden' => true, | ||
'key' => true | ||
)) | ||
->add('start_stamp', 'Start') | ||
->add('end_stamp', 'End') | ||
->add('caller_id_number', 'Calling Party') | ||
->add('destination_number', 'Called Party') | ||
->add('duration', 'Length') | ||
->add('hangup_cause', 'Call End Cause'); | ||
|
||
if( ! is_null($start)) { | ||
$grid->andWhere('start_stamp >', "'" . $start . "'"); | ||
} | ||
|
||
if( ! is_null($end)) { | ||
$grid->andWhere('end_stamp <', "'" . $end . "'"); | ||
} | ||
|
||
// Let plugins populate the grid as well | ||
$this->grid = $grid; | ||
|
||
Kohana::log('debug', print_r($_POST, TRUE)); | ||
|
||
plugins::views($this); | ||
|
||
// Produce a grid in the view | ||
$this->view->grid = $this->grid->produce(); | ||
} | ||
|
||
public function view($id) { | ||
|
||
|
||
if ($this->submitted()) { | ||
url::redirect(Router_Core::$controller); | ||
} | ||
|
||
$base = strtolower($this->baseModel); | ||
|
||
$this->createView(); | ||
|
||
$this->loadBaseModel($id); | ||
|
||
$this->prepareUpdateView(); | ||
|
||
$this->view->title = 'Call Detail'; | ||
|
||
$this->view->coreFields = $this->coreFields; | ||
|
||
} | ||
|
||
public function downloadAsCsv($startDate, $endDate, $otherStuff) { | ||
// Actual download processing (after Csv is selected) | ||
} | ||
|
||
public function downloadAsXml($startDate, $endDate, $otherStuff) { | ||
// Actual download processing (after Xml is selected) | ||
} | ||
|
||
public function import() { | ||
// Manually import a CDR | ||
ProcessLog::importLogs(); | ||
url::redirect(Router_Core::$controller); | ||
} | ||
|
||
public function _showCall($NULL, $calls_id) | ||
{ | ||
|
||
$coreFields = $this->coreFields; | ||
|
||
$call = Doctrine::getTable('Calls')->find($calls_id)->toArray(); | ||
|
||
$callDetail = '<table>'; | ||
|
||
foreach ($call as $field => $value) | ||
{ | ||
if(isset($coreFields[$field])) { | ||
$callDetail .= '<tr><th>' . $coreFields[$field] . '</th><td>' . $value .'</td></tr>'; | ||
} | ||
} | ||
|
||
// foreach ($call['custom_fields'] as $field => $value) | ||
// { | ||
// $callDetail .= '<tr><th>' . $field . '</th><td>' . $value .'</td></tr>'; | ||
// } | ||
|
||
$callDetail .= '</table>'; | ||
|
||
return "<a title='Call Info' tooltip='" . $callDetail ."' class='addInfo' href='#'>" . $call['start_stamp'] .'</a>'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
Event::add('bluebox.maintenance', array('ProcessLog', 'importLogs')); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* Library for CDR log processing. Imports logs from FS into database. | ||
* Run this externally via cron or as a background event. | ||
* | ||
* @author dman | ||
*/ | ||
class ProcessLog { | ||
|
||
|
||
public function importLogs() { | ||
// Scan for new logs that haven't been processed before and import them into the log table | ||
// Make sure not to get dupes, even if there's a crash (how?) | ||
|
||
$coreFields = array( | ||
'uuid' => 1, | ||
'accountcode' => 1, | ||
'caller_id_number' => 1, | ||
'destination_number' => 1, | ||
'context' => 1, | ||
'duration' => 1, | ||
'start_stamp' => 1, | ||
'answer_stamp' => 1, | ||
'end_stamp' => 1, | ||
'billsec' => 1, | ||
'hangup_cause' => 1, | ||
'channel_name' => 1, | ||
'bridge_channel' => 1 | ||
); | ||
|
||
Kohana::log('debug', 'scandir: ' . Kohana::config('calls.scandir')); | ||
|
||
$callFiles = glob(rtrim(Kohana::config('calls.scandir'), '/') . '/' . 'Master.csv.*', GLOB_MARK); | ||
|
||
foreach( $callFiles as $callFile ) { | ||
|
||
$recordCount = 0; | ||
$recordsInserted = 0; | ||
$recordsErrored = 0; | ||
$recordsDup = 0; | ||
|
||
$callFileHistory = new CallsFiles; | ||
$callFileHistory->filename = $callFile; | ||
|
||
// Save before we start so we can see if we crash. Also lets us calc how long it took. | ||
$callFileHistory->save(); | ||
|
||
if (($callFileHandle = fopen($callFile, "r")) !== FALSE) { | ||
|
||
while (($callRecord = fgetcsv($callFileHandle, 2000, ",")) !== FALSE) { | ||
|
||
$corecdr = array(); | ||
$extracdr = array(); | ||
|
||
$numFields = count($callRecord); | ||
$recordCount++; | ||
|
||
$insertCall = new Calls; | ||
|
||
Kohana::log('debug', "$numFields fields in record $recordCount"); | ||
|
||
for ($field = 0; $field < $numFields; $field = $field+2) { | ||
if(isset($coreFields[$callRecord[$field]])) { | ||
$corecdr[$callRecord[$field]] = $callRecord[$field+1]; | ||
} else { | ||
$extracdr[$callRecord[$field]] = $callRecord[$field+1]; | ||
} | ||
} | ||
$corecdr['custom_fields'] = $extracdr; | ||
$insertCall->synchronizeWithArray($corecdr); | ||
|
||
try { | ||
$insertCall->save(); | ||
$recordsInserted++; | ||
} catch (Exception $e) { | ||
if(preg_match('/Duplicate entry/',$e->getMessage())) { | ||
$recordsDup++; | ||
} else { | ||
$recordsErrored++; | ||
} | ||
Kohana::log('debug', 'Insert of Call Log Failed. UUID: ' . $corecdr['uuid'] . 'Message: ' . $e->getMessage()); | ||
} | ||
|
||
|
||
Kohana::log('debug', 'Call Log: ' . print_r($corecdr,true)); | ||
Kohana::log('debug', 'Call Log: ' . print_r($extracdr,true)); | ||
|
||
} | ||
|
||
fclose($callFileHandle); | ||
} | ||
|
||
// Update the history adter we have processed the file. | ||
$callFileHistory->records_processed = $recordCount; | ||
$callFileHistory->records_inserted = $recordsInserted; | ||
$callFileHistory->records_errored = $recordsErrored; | ||
$callFileHistory->records_dup = $recordsDup; | ||
|
||
$callFileHistory->save(); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
modules/calls-1.0/libraries/drivers/freeswitch/callssetting.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
class FreeSwitch_CallsSetting_Driver extends FreeSwitch_Base_Driver { | ||
|
||
public static function set($base) | ||
{ | ||
$xml = Telephony::getDriver()->xml; | ||
|
||
FreeSwitch::setSection('cdr_csv'); | ||
|
||
$xml->update('/settings/param[@name="default-template"]{@value="bluebox"}'); | ||
$xml->update('/settings/param[@name="legs"]{@value="a"}'); | ||
$xml->update('/settings/param[@name="rotate-on-hup"]{@value="true"}'); | ||
$xml->replaceWithXml(Kohana::config('calls.defaulttemplate'),'/templates/template[@name="bluebox"]'); | ||
|
||
} | ||
|
||
public static function delete($base) | ||
{ | ||
$xml = Telephony::getDriver()->xml; | ||
|
||
FreeSwitch::setSection('cdr_csv'); | ||
|
||
//not sure what to do here | ||
|
||
// $xml->deleteNode(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
modules/calls-1.0/libraries/drivers/freeswitch/callstemplate.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
class FreeSwitch_CallsTemplate_Driver extends FreeSwitch_Base_Driver { | ||
|
||
public static function set($base) | ||
{ | ||
$xml = Telephony::getDriver()->xml; | ||
|
||
FreeSwitch::setSection('cdr_csv'); | ||
|
||
$xml->update('/settings/template[@name="account_' . $base->account_id . '"]{@value="' . $template_config . '"}'); | ||
} | ||
|
||
public static function delete($base) | ||
{ | ||
$xml = Telephony::getDriver()->xml; | ||
|
||
FreeSwitch::setSection('cdr_csv'); | ||
|
||
$xml->deleteNode('/settings/template[@name="account_' . $base->account_id . '"]'); | ||
} | ||
} |
Oops, something went wrong.