Skip to content

Commit

Permalink
add option to select specific servers on proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
magnussolution committed Apr 24, 2023
1 parent e79a7a3 commit 91997f9
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 23 deletions.
Binary file modified build/MagnusBilling-current.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion classic/src/Application.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions classic/src/view/servers/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ Ext.define('MBilling.view.servers.Controller', {
}
});
},
onNew: function() {
var me = this;
fieldPid_server = me.lookupReference('id_server')['hide']();
me.callParent(arguments);
},
onEdit: function() {
var me = this,
fieldWeight = me.formPanel.getForm().findField('weight'),
Expand All @@ -58,6 +63,11 @@ Ext.define('MBilling.view.servers.Controller', {
} else {
fieldWeight['hide']();
}
if (fieldType.value == 'sipproxy') {
fieldPid_server = me.lookupReference('id_server')['show']();
} else {
fieldPid_server = me.lookupReference('id_server')['hide']();
}
},
onDelete: function(btn) {
var me = this,
Expand Down
16 changes: 16 additions & 0 deletions classic/src/view/servers/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ Ext.define('MBilling.view.servers.Form', {
[0, t('Inactive')],
[2, t('OffLine')]
]
}, {
xtype: 'fieldset',
style: 'margin-top:10px; overflow: visible;',
title: t('Select one or more slave.'),
collapsible: true,
reference: 'id_server',
height: 100,
collapsed: false,
items: [{
xtype: 'serverstag',
name: 'id_server',
fieldLabel: t(''),
labelWidth: 10,
anchor: '100%',
allowBlank: true
}]
}, {
xtype: 'textareafield',
name: 'description',
Expand Down
25 changes: 25 additions & 0 deletions classic/src/view/servers/Tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Class to define tag of "phoneBook"
*
* Adilson L. Magnus <[email protected]>
* 15/04/2013
*/
Ext.define('MBilling.view.servers.Tag', {
extend: 'Ext.form.field.Tag',
alias: 'widget.serverstag',
name: 'id_server',
fieldLabel: t('Servers'),
displayField: 'name',
valueField: 'id',
initComponent: function() {
var me = this;
me.store = Ext.create('MBilling.store.Servers', {
proxy: {
type: 'uxproxy',
module: 'servers',
limitParam: undefined
}
});
me.callParent(arguments);
}
});
17 changes: 17 additions & 0 deletions protected/commands/UpdateMysqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,23 @@ public function run($args)
$version = '7.8.3.5';
$this->update($version);
}

//2023-04-21
if ($version == '7.8.3.5') {
$sql = "
CREATE TABLE `pkg_servers_servers` (
`id_proxy` int(11) NOT NULL,
`id_server` int(11) NOT NULL,
PRIMARY KEY (`id_server`,`id_proxy`),
KEY `fk_pkg_servers` (`id_server`),
KEY `fk_pkg_proxy` (`id_proxy`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
$this->executeDB($sql);

$version = '7.8.3.6';
$this->update($version);
}
}

public function executeDB($sql)
Expand Down
4 changes: 3 additions & 1 deletion protected/components/AsteriskAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AsteriskAccess

private $asmanager;
private static $instance;
private static $config;

public static function instance($host = 'localhost', $user = 'magnus', $pass = 'magnussolution')
{
Expand All @@ -24,6 +25,7 @@ public static function instance($host = 'localhost', $user = 'magnus', $pass = '
private function __construct()
{
$this->asmanager = new AGI_AsteriskManager;
$this->config = LoadConfig::getConfig();
}

private function connectAsterisk($host, $user, $pass)
Expand Down Expand Up @@ -288,7 +290,7 @@ public function writeAsteriskFile($model, $file, $head_field = 'name')
$line .= 'deny=0.0.0.0/0.0.0.0' . "\n";
$line .= 'permit=' . $data['host'] . "/255.255.255.0\n";
$line .= 'disallow=all' . "\n";
$line .= 'allow=g729,alaw,ulaw' . "\n";
$line .= 'allow=' . $this->config['global']['default_codeds'] . "\n";
$line .= 'dtmfmode=RFC2833' . "\n";
$line .= 'insecure=invite' . "\n";

Expand Down
71 changes: 51 additions & 20 deletions protected/controllers/ServersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,31 @@ class ServersController extends Controller
{
public $attributeOrder = 't.id';

public $nameModelRelated = 'ServersServers';
public $nameFkRelated = 'id_proxy';
public $nameOtherFkRelated = 'id_server';

public function init()
{
$this->instanceModel = new Servers;
$this->abstractModel = Servers::model();
$this->titleReport = Yii::t('zii', 'CallerID');
$this->instanceModel = new Servers;
$this->abstractModel = Servers::model();
$this->titleReport = Yii::t('zii', 'CallerID');
$this->abstractModelRelated = ServersServers::model();
parent::init();
}

public function afterSave($model, $values)
{

$modelServer = Servers::model()->findAll("type = 'sipproxy' AND status = 1");
foreach ($modelServer as $key => $server) {
foreach ($modelServer as $key => $proxy) {

$hostname = $server->host;
$hostname = $proxy->host;
$dbname = 'opensips';
$table = 'dispatcher';
$user = $server->username;
$password = $server->password;
$port = $server->port;
$user = $proxy->username;
$password = $proxy->password;
$port = $proxy->port;

$dsn = 'mysql:host=' . $hostname . ';dbname=' . $dbname;

Expand All @@ -58,23 +63,49 @@ public function afterSave($model, $values)
$sql = "TRUNCATE $dbname.$table";
$con->createCommand($sql)->execute();

$modelServerAS = Servers::model()->findAll("(type = 'asterisk' OR type = 'mbilling')
AND status = 1 AND weight > 0");
$modelServerAS = ServersServers::model()->findAll("id_proxy = :key", [':key' => $proxy->id]);

foreach ($modelServerAS as $key => $server) {
if (isset($modelServerAS[0]->id_server)) {
foreach ($modelServerAS as $key => $server) {

if ($this->ip_is_private($hostname)) {
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $server->host . ":" . $server->sip_port . "','" . $server->weight . "','" . $server->description . "')";
} else {
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $server->public_ip . ":" . $server->sip_port . "','" . $server->weight . "','" . $server->description . "')";
}
$modelServer = Servers::model()->find("id = :key AND (type = 'asterisk' OR type = 'mbilling')
AND status = 1 AND weight > 0", [':key' => $server->id_server]);

if (isset($modelServer->id)) {
if ($this->ip_is_private($hostname)) {
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $modelServer->host . ":" . $modelServer->sip_port . "','" . $modelServer->weight . "','" . $modelServer->description . "')";
} else {
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $modelServer->public_ip . ":" . $modelServer->sip_port . "','" . $modelServer->weight . "','" . $modelServer->description . "')";
}

try {
$con->createCommand($sql)->execute();
} catch (Exception $e) {
return;
}
}

try {
$con->createCommand($sql)->execute();
} catch (Exception $e) {
return;
}

} else {

$modelServerAS = Servers::model()->find("(type = 'asterisk' OR type = 'mbilling')
AND status = 1 AND weight > 0");
foreach ($modelServerAS as $key => $server) {

if ($this->ip_is_private($hostname)) {
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $server->host . ":" . $server->sip_port . "','" . $server->weight . "','" . $server->description . "')";
} else {
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $server->public_ip . ":" . $server->sip_port . "','" . $server->weight . "','" . $server->description . "')";
}

try {
$con->createCommand($sql)->execute();
} catch (Exception $e) {
return;
}

}
}

}
Expand Down
71 changes: 71 additions & 0 deletions protected/models/ServersServers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Modelo para a tabela "CampaignPhonebook".
* =======================================
* ###################################
* 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 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]>
* 29/10/2012
*/

class ServersServers extends Model
{
protected $_module = 'serversservers';
/**
* Retorna a classe estatica da model.
* @return SubModule classe estatica da model.
*/
public static function model($className = __CLASS__)
{
return parent::model($className);
}

/**
* @return nome da tabela.
*/
public function tableName()
{
return 'pkg_servers_servers';
}

/**
* @return nome da(s) chave(s) primaria(s).
*/
public function primaryKey()
{
return array('id_proxy', 'id_server');
}

/**
* @return array validacao dos campos da model.
*/
public function rules()
{
$rules = array(
array('id_proxy, id_server', 'required'),
array('id_proxy, id_server', 'numerical', 'integerOnly' => true),
);
return $this->getExtraField($rules);
}

public function beforeSave()
{
return parent::beforeSave();
}

public function afterSave()
{
return parent::afterSave();
}
}
3 changes: 2 additions & 1 deletion script/installOpenSips-3.1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ ulimit -a # All current limits are reported.

sed -i -e 's/$S_MEMORY/2048/g' /lib/systemd/system/opensips.service
sed -i -e 's/$P_MEMORY/2048/g' /lib/systemd/system/opensips.service

sed -i -e 's/User=opensips/User=root/g' /lib/systemd/system/opensips.service
sed -i -e 's/Group=opensips/Group=root/g' /lib/systemd/system/opensips.service
echo 'SystemMaxUse=10M' >> /etc/systemd/journald.conf
systemctl daemon-reload
systemctl restart systemd-journald
Expand Down

0 comments on commit 91997f9

Please sign in to comment.