Skip to content

Commit 223c88c

Browse files
author
magnussolution
committed
add option to select specific servers on proxy
1 parent e79a7a3 commit 223c88c

File tree

9 files changed

+194
-22
lines changed

9 files changed

+194
-22
lines changed

build/MagnusBilling-current.tar.gz

2.41 KB
Binary file not shown.

classic/src/Application.js

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

classic/src/view/servers/Controller.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ Ext.define('MBilling.view.servers.Controller', {
4848
}
4949
});
5050
},
51+
onNew: function() {
52+
var me = this;
53+
fieldPid_server = me.lookupReference('id_server')['hide']();
54+
me.callParent(arguments);
55+
},
5156
onEdit: function() {
5257
var me = this,
5358
fieldWeight = me.formPanel.getForm().findField('weight'),
@@ -58,6 +63,11 @@ Ext.define('MBilling.view.servers.Controller', {
5863
} else {
5964
fieldWeight['hide']();
6065
}
66+
if (fieldType.value == 'sipproxy') {
67+
fieldPid_server = me.lookupReference('id_server')['show']();
68+
} else {
69+
fieldPid_server = me.lookupReference('id_server')['hide']();
70+
}
6171
},
6272
onDelete: function(btn) {
6373
var me = this,

classic/src/view/servers/Form.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ Ext.define('MBilling.view.servers.Form', {
8181
[0, t('Inactive')],
8282
[2, t('OffLine')]
8383
]
84+
}, {
85+
xtype: 'fieldset',
86+
style: 'margin-top:10px; overflow: visible;',
87+
title: t('Select one or more slave.'),
88+
collapsible: true,
89+
reference: 'id_server',
90+
height: 100,
91+
collapsed: false,
92+
items: [{
93+
xtype: 'serverstag',
94+
name: 'id_server',
95+
fieldLabel: t(''),
96+
labelWidth: 10,
97+
anchor: '100%',
98+
allowBlank: true
99+
}]
84100
}, {
85101
xtype: 'textareafield',
86102
name: 'description',

classic/src/view/servers/Tag.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Class to define tag of "phoneBook"
3+
*
4+
* Adilson L. Magnus <[email protected]>
5+
* 15/04/2013
6+
*/
7+
Ext.define('MBilling.view.servers.Tag', {
8+
extend: 'Ext.form.field.Tag',
9+
alias: 'widget.serverstag',
10+
name: 'id_server',
11+
fieldLabel: t('Servers'),
12+
displayField: 'name',
13+
valueField: 'id',
14+
initComponent: function() {
15+
var me = this;
16+
me.store = Ext.create('MBilling.store.Servers', {
17+
proxy: {
18+
type: 'uxproxy',
19+
module: 'servers',
20+
limitParam: undefined
21+
}
22+
});
23+
me.callParent(arguments);
24+
}
25+
});

protected/commands/UpdateMysqlCommand.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,23 @@ public function run($args)
18911891
$version = '7.8.3.5';
18921892
$this->update($version);
18931893
}
1894+
1895+
//2023-04-21
1896+
if ($version == '7.8.3.5') {
1897+
$sql = "
1898+
CREATE TABLE `pkg_servers_servers` (
1899+
`id_proxy` int(11) NOT NULL,
1900+
`id_server` int(11) NOT NULL,
1901+
PRIMARY KEY (`id_server`,`id_proxy`),
1902+
KEY `fk_pkg_servers` (`id_server`),
1903+
KEY `fk_pkg_proxy` (`id_proxy`)
1904+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1905+
";
1906+
$this->executeDB($sql);
1907+
1908+
$version = '7.8.3.6';
1909+
$this->update($version);
1910+
}
18941911
}
18951912

18961913
public function executeDB($sql)

protected/components/AsteriskAccess.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class AsteriskAccess
1111

1212
private $asmanager;
1313
private static $instance;
14+
private static $config;
1415

1516
public static function instance($host = 'localhost', $user = 'magnus', $pass = 'magnussolution')
1617
{
@@ -24,6 +25,7 @@ public static function instance($host = 'localhost', $user = 'magnus', $pass = '
2425
private function __construct()
2526
{
2627
$this->asmanager = new AGI_AsteriskManager;
28+
$this->config = LoadConfig::getConfig();
2729
}
2830

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

protected/controllers/ServersController.php

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,31 @@ class ServersController extends Controller
2424
{
2525
public $attributeOrder = 't.id';
2626

27+
public $nameModelRelated = 'ServersServers';
28+
public $nameFkRelated = 'id_proxy';
29+
public $nameOtherFkRelated = 'id_server';
30+
2731
public function init()
2832
{
29-
$this->instanceModel = new Servers;
30-
$this->abstractModel = Servers::model();
31-
$this->titleReport = Yii::t('zii', 'CallerID');
33+
$this->instanceModel = new Servers;
34+
$this->abstractModel = Servers::model();
35+
$this->titleReport = Yii::t('zii', 'CallerID');
36+
$this->abstractModelRelated = ServersServers::model();
3237
parent::init();
3338
}
3439

3540
public function afterSave($model, $values)
3641
{
3742

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

41-
$hostname = $server->host;
46+
$hostname = $proxy->host;
4247
$dbname = 'opensips';
4348
$table = 'dispatcher';
44-
$user = $server->username;
45-
$password = $server->password;
46-
$port = $server->port;
49+
$user = $proxy->username;
50+
$password = $proxy->password;
51+
$port = $proxy->port;
4752

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

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

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

64-
foreach ($modelServerAS as $key => $server) {
68+
if (isset($modelServerAS[0]->id_server)) {
69+
foreach ($modelServerAS as $key => $server) {
6570

66-
if ($this->ip_is_private($hostname)) {
67-
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $server->host . ":" . $server->sip_port . "','" . $server->weight . "','" . $server->description . "')";
68-
} else {
69-
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $server->public_ip . ":" . $server->sip_port . "','" . $server->weight . "','" . $server->description . "')";
70-
}
71+
$modelServer = Servers::model()->find("id = :key AND (type = 'asterisk' OR type = 'mbilling')
72+
AND status = 1 AND weight > 0", [':key' => $server->id_server]);
73+
74+
if (isset($modelServer->id)) {
75+
if ($this->ip_is_private($hostname)) {
76+
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $modelServer->host . ":" . $modelServer->sip_port . "','" . $modelServer->weight . "','" . $modelServer->description . "')";
77+
} else {
78+
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $modelServer->public_ip . ":" . $modelServer->sip_port . "','" . $modelServer->weight . "','" . $modelServer->description . "')";
79+
}
80+
81+
try {
82+
$con->createCommand($sql)->execute();
83+
} catch (Exception $e) {
84+
return;
85+
}
86+
}
7187

72-
try {
73-
$con->createCommand($sql)->execute();
74-
} catch (Exception $e) {
75-
return;
7688
}
7789

90+
} else {
91+
92+
$modelServerAS = Servers::model()->find("(type = 'asterisk' OR type = 'mbilling')
93+
AND status = 1 AND weight > 0");
94+
foreach ($modelServerAS as $key => $server) {
95+
96+
if ($this->ip_is_private($hostname)) {
97+
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $server->host . ":" . $server->sip_port . "','" . $server->weight . "','" . $server->description . "')";
98+
} else {
99+
$sql = "INSERT INTO $dbname.$table (setid,destination,weight,description) VALUES ('1','sip:" . $server->public_ip . ":" . $server->sip_port . "','" . $server->weight . "','" . $server->description . "')";
100+
}
101+
102+
try {
103+
$con->createCommand($sql)->execute();
104+
} catch (Exception $e) {
105+
return;
106+
}
107+
108+
}
78109
}
79110

80111
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Modelo para a tabela "CampaignPhonebook".
4+
* =======================================
5+
* ###################################
6+
* MagnusBilling
7+
*
8+
* @package MagnusBilling
9+
* @author Adilson Leffa Magnus.
10+
* @copyright Copyright (C) 2005 - 2021 MagnusSolution. All rights reserved.
11+
* ###################################
12+
*
13+
* This software is released under the terms of the GNU Lesser General Public License v3
14+
* A copy of which is available from http://www.gnu.org/copyleft/lesser.html
15+
*
16+
* Please submit bug reports, patches, etc to https://github.com/magnusbilling/mbilling/issues
17+
* =======================================
18+
* Magnusbilling.com <[email protected]>
19+
* 29/10/2012
20+
*/
21+
22+
class ServersServers extends Model
23+
{
24+
protected $_module = 'serversservers';
25+
/**
26+
* Retorna a classe estatica da model.
27+
* @return SubModule classe estatica da model.
28+
*/
29+
public static function model($className = __CLASS__)
30+
{
31+
return parent::model($className);
32+
}
33+
34+
/**
35+
* @return nome da tabela.
36+
*/
37+
public function tableName()
38+
{
39+
return 'pkg_servers_servers';
40+
}
41+
42+
/**
43+
* @return nome da(s) chave(s) primaria(s).
44+
*/
45+
public function primaryKey()
46+
{
47+
return array('id_proxy', 'id_server');
48+
}
49+
50+
/**
51+
* @return array validacao dos campos da model.
52+
*/
53+
public function rules()
54+
{
55+
$rules = array(
56+
array('id_proxy, id_server', 'required'),
57+
array('id_proxy, id_server', 'numerical', 'integerOnly' => true),
58+
);
59+
return $this->getExtraField($rules);
60+
}
61+
62+
public function beforeSave()
63+
{
64+
return parent::beforeSave();
65+
}
66+
67+
public function afterSave()
68+
{
69+
return parent::afterSave();
70+
}
71+
}

0 commit comments

Comments
 (0)