Skip to content

Commit

Permalink
add new menu trunk SIP erros
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Mar 18, 2021
1 parent 1e92990 commit d807856
Show file tree
Hide file tree
Showing 16 changed files with 486 additions and 9 deletions.
43 changes: 43 additions & 0 deletions app/model/TrunkSipCodes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Classe que define a model "TrunkSIPCodes"
*
* =======================================
* ###################################
* MagnusBilling
*
* @package MagnusBilling
* @author Adilson Leffa Magnus.
* @copyright Copyright (C) 2005 - 2021 MagnusBilling. All rights reserved.
* ###################################
*
* This software is released under the terms of the GNU Lesser General Public License v3
* A copy of which is available from http://www.gnu.org/copyleft/lesser.html
*
* Please submit bug reports, patches, etc to https://github.com/magnusbilling/mbilling/issues
* =======================================
* Magnusbilling.com <[email protected]>
* 25/03/2021
*/
Ext.define('MBilling.model.TrunkSipCodes', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'int'
}, {
name: 'ip',
type: 'string'
}, {
name: 'code',
type: 'int'
}, {
name: 'total',
type: 'int'
}, {
name: 'percentage',
type: 'string'
}],
proxy: {
type: 'uxproxy',
module: 'trunkSipCodes'
}
});
25 changes: 25 additions & 0 deletions app/store/TrunkSipCodes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Classe que define o store "TrunkSIPCodes"
*
* =======================================
* ###################################
* MagnusBilling
*
* @package MagnusBilling
* @author Adilson Leffa Magnus.
* @copyright Copyright (C) 2005 - 2021 MagnusBilling. All rights reserved.
* ###################################
*
* This software is released under the terms of the GNU Lesser General Public License v3
* A copy of which is available from http://www.gnu.org/copyleft/lesser.html
*
* Please submit bug reports, patches, etc to https://github.com/magnusbilling/mbilling/issues
* =======================================
* Magnusbilling.com <[email protected]>
* 25/03/2021
*/
Ext.define('MBilling.store.TrunkSipCodes', {
extend: 'Ext.data.Store',
model: 'MBilling.model.TrunkSipCodes',
groupField: 'ip'
});
Binary file modified build/MagnusBilling-current.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions classic/src/view/trunk/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ Ext.define('MBilling.view.trunk.Controller', {
}
});
}

});
1 change: 1 addition & 0 deletions classic/src/view/trunk/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Ext.define('MBilling.view.trunk.List', {
fieldSearch: 'trunkcode',
initComponent: function() {
var me = this;

me.columns = me.columns || [{
header: t('ID'),
dataIndex: 'id',
Expand Down
24 changes: 24 additions & 0 deletions classic/src/view/trunkSipCodes/Controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Classe que define a lista de "CallShopCdr"
*
* =======================================
* ###################################
* MagnusBilling
*
* @package MagnusBilling
* @author Adilson Leffa Magnus.
* @copyright Copyright (C) 2005 - 2021 MagnusBilling. All rights reserved.
* ###################################
*
* This software is released under the terms of the GNU Lesser General Public License v3
* A copy of which is available from http://www.gnu.org/copyleft/lesser.html
*
* Please submit bug reports, patches, etc to https://github.com/magnussolution/magnusbilling7/issues
* =======================================
* Magnusbilling.org <[email protected]>
* 01/10/2013
*/
Ext.define('MBilling.view.trunkSipCodes.Controller', {
extend: 'Ext.ux.app.ViewController',
alias: 'controller.trunksipcodes'
});
41 changes: 41 additions & 0 deletions classic/src/view/trunkSipCodes/Form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Classe que define o form de "Trunk"
*
* =======================================
* ###################################
* MagnusBilling
*
* @package MagnusBilling
* @author Adilson Leffa Magnus.
* @copyright Copyright (C) 2005 - 2021 MagnusBilling. All rights reserved.
* ###################################
*
* This software is released under the terms of the GNU Lesser General Public License v3
* A copy of which is available from http://www.gnu.org/copyleft/lesser.html
*
* Please submit bug reports, patches, etc to https://github.com/magnussolution/magnusbilling7/issues
* =======================================
* Magnusbilling.org <[email protected]>
* 25/06/2012
*/
Ext.define('MBilling.view.trunkSipCodes.Form', {
extend: 'Ext.ux.form.Panel',
alias: 'widget.trunksipcodesform',
initComponent: function() {
var me = this;
me.items = [{
xtype: 'textfield',
name: 'ip',
fieldLabel: t('IP')
}, {
xtype: 'numberfield',
name: 'code',
fieldLabel: t('Code')
}, {
xtype: 'numberfield',
name: 'total',
fieldLabel: t('Total')
}];
me.callParent(arguments);
}
});
53 changes: 53 additions & 0 deletions classic/src/view/trunkSipCodes/List.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Classe que define a lista de "Trunk"
*
* =======================================
* ###################################
* MagnusBilling
*
* @package MagnusBilling
* @author Adilson Leffa Magnus.
* @copyright Copyright (C) 2005 - 2021 MagnusBilling. All rights reserved.
* ###################################
*
* This software is released under the terms of the GNU Lesser General Public License v3
* A copy of which is available from http://www.gnu.org/copyleft/lesser.html
*
* Please submit bug reports, patches, etc to https://github.com/magnussolution/magnusbilling7/issues
* =======================================
* Magnusbilling.org <[email protected]>
* 25/06/2012
*/
Ext.define('MBilling.view.trunkSipCodes.List', {
extend: 'Ext.ux.grid.Panel',
alias: 'widget.trunksipcodeslist',
store: 'TrunkSipCodes',
fieldSearch: 'ip',
initComponent: function() {
var me = this;
me.buttonCsv = false;
me.allowPrint = false;
me.buttonUpdateLot = false;
me.allowCreate = false;
me.allowUpdate = false;
me.textDelete = t('Reset');
me.columns = me.columns || [{
header: t('Ip'),
dataIndex: 'ip',
flex: 3
}, {
header: t('SIP Code'),
dataIndex: 'code',
flex: 3
}, {
header: t('Total'),
dataIndex: 'total',
flex: 3
}, {
header: t('Percentage'),
dataIndex: 'percentage',
flex: 3
}];
me.callParent(arguments);
}
});
11 changes: 11 additions & 0 deletions classic/src/view/trunkSipCodes/Module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Classe que define o panel de "Trunk"
*
* MagnusSolution.com <[email protected]>
* 18/04/2012
*/
Ext.define('MBilling.view.trunkSipCodes.Module', {
extend: 'Ext.ux.panel.Module',
alias: 'widget.trunksipcodesmodule',
controller: 'trunksipcodes'
});
4 changes: 3 additions & 1 deletion protected/commands/CallChartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ public function user_cdr_show($calls)
}

if (!count($modelSip)) {

if ($status == 'Ring') {
$sip_account = $originate;
}
if (strlen($sip_account) > 3) {
//echo "check per sip_account $originate\n";
if (false !== $key = array_search($originate, $this->sipNames)) {
Expand Down
120 changes: 120 additions & 0 deletions protected/commands/TrunkSIPCodesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php
/**
* =======================================
* ###################################
* MagnusBilling
*
* @package MagnusBilling
* @author Adilson Leffa Magnus.
* @copyright Copyright (C) 2005 - 2021 MagnusSolution. All rights reserved.
* ###################################
*
* This software is released under the terms of the GNU Lesser General Public License v2.1
* A copy of which is available from http://www.gnu.org/copyleft/lesser.html
*
* Please submit bug reports, patches, etc to https://github.com/magnusbilling/mbilling/issues
* =======================================
* Magnusbilling.com <[email protected]>
*
*/
class TrunkSIPCodesCommand extends ConsoleCommand
{
public function run($args)
{

$time = time();

$cache_path = '/tmp/cache_mbilling_codes.sqlite';
exec('rm -rf ' . $cache_path);
$fields = "data,ip,code,msg";
try {
$db = new SQLite3($cache_path);
$db->exec('CREATE TABLE IF NOT EXISTS sipcodes (' . $fields . ');');
} catch (Exception $e) {

}

if (!file_exists('/var/log/asterisk/magnus_processed ')) {
exec('touch /var/log/asterisk/magnus_processed ');
}

exec('cp -rf /var/log/asterisk/magnus /var/log/asterisk/magnus_new');

exec('diff -u /var/log/asterisk/magnus_processed /var/log/asterisk/magnus_new ', $lines);

exec('rm -rf /var/log/asterisk/magnus_processed');
exec('mv /var/log/asterisk/magnus_new /var/log/asterisk/magnus_processed');

$values = '';

$i = 0;
foreach ($lines as $key => $line) {

preg_match_all('/\[(.*)\] DEBUG.*\<sip\:.*@(.*)\>.*\|(.*)\|(.*)/', $line, $output_array);

if (count($output_array) < 4 || !isset($output_array[1][0])) {

continue;
}

$output_array[4][0] = preg_replace("/'/", '', $output_array[4][0]);

$values .= "('" . $output_array[1][0] . "','" . $output_array[2][0] . "','" . $output_array[3][0] . "','" . $output_array[4][0] . "'),";

if ($i == 200) {

$sql = "INSERT INTO sipcodes ($fields) VALUES " . substr($values, 0, -1);
try {
$db->exec($sql);
} catch (Exception $e) {
//
}
$values = '';
$i = 0;
} else {
$i++;
}

}

if ($i < 200 && $i > 0) {

$sql = "INSERT INTO sipcodes ($fields) VALUES " . substr($values, 0, -1);
try {
$db->exec($sql);
} catch (Exception $e) {
//
}
$values = '';
$i = 0;
}

$sql = "SELECT ip FROM sipcodes GROUP BY ip";
$result = $db->query($sql);
while ($ip = $result->fetchArray(SQLITE3_ASSOC)) {

$sql = "SELECT count(code) as total, code FROM sipcodes WHERE ip = '" . $ip['ip'] . "' GROUP BY code";
$resultCodes = $db->query($sql);
while ($code = $resultCodes->fetchArray(SQLITE3_ASSOC)) {

$sql = "SELECT id FROM pkg_trunk WHERE host = '" . $ip['ip'] . "' ";
$modelTrunk = Yii::app()->db->createCommand($sql)->queryAll();
if (isset($modelTrunk[0]['id'])) {
$sql = "INSERT INTO pkg_trunk_error (ip, code,total) VALUES ( '" . $ip['ip'] . "', '" . $code['code'] . "', '" . $code['total'] . "')";
try {
Yii::app()->db->createCommand($sql)->execute();
} catch (Exception $e) {

$sql = "UPDATE pkg_trunk_error SET total = total + " . $code['total'] . " WHERE ip = '" . $ip['ip'] . "' AND code = '" . $code['code'] . "'";
try {
Yii::app()->db->createCommand($sql)->execute();
} catch (Exception $e) {
print_r($e);
}
}
}
}

}
}
}
Loading

0 comments on commit d807856

Please sign in to comment.