Skip to content

Commit ed719bf

Browse files
import sip users from CSV
1 parent ca48140 commit ed719bf

File tree

6 files changed

+100
-34
lines changed

6 files changed

+100
-34
lines changed

build/MagnusBilling-current.tar.gz

640 Bytes
Binary file not shown.

classic/src/Application.js

Lines changed: 18 additions & 18 deletions
Large diffs are not rendered by default.

classic/src/view/sip/ImportCsv.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Classe que define a window import csv de "Did"
3+
*
4+
* =======================================
5+
* ###################################
6+
* MagnusBilling
7+
*
8+
* @package MagnusBilling
9+
* @author Adilson Leffa Magnus.
10+
* @copyright Copyright (C) 2005 - 2021 MagnusBilling. 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/magnussolution/magnusbilling7/issues
17+
* =======================================
18+
* Magnusbilling.org <[email protected]>
19+
* 11/08/2014
20+
*/
21+
Ext.define('MBilling.view.sip.ImportCsv', {
22+
extend: 'Ext.ux.window.ImportCsv',
23+
alias: 'widget.sipimportcsv',
24+
fieldsImport: [{
25+
fieldLabel: t('Table'),
26+
hidden: true,
27+
allowBlank: true
28+
}]
29+
});

classic/src/view/sip/List.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Ext.define('MBilling.view.sip.List', {
2323
alias: 'widget.siplist',
2424
store: 'Sip',
2525
fieldSearch: 'name',
26-
initComponent: function() {
26+
initComponent: function () {
2727
var me = this;
2828
me.extraButtons = [{
2929
text: t('Bulk SIP'),
@@ -32,6 +32,11 @@ Ext.define('MBilling.view.sip.List', {
3232
disabled: false,
3333
hidden: App.user.isClient || !me.allowCreate || window.isTablet
3434
}];
35+
36+
if (App.user.isAdmin) {
37+
me.buttonImportCsv = true;
38+
}
39+
3540
me.columns = me.columns || [{
3641
header: t('ID'),
3742
dataIndex: 'id',
@@ -179,7 +184,7 @@ Ext.define('MBilling.view.sip.List', {
179184
hidden: true,
180185
hideable: window.dma && window.dialC,
181186
flex: 2,
182-
renderer: function(value) {
187+
renderer: function (value) {
183188
return value == 1 ? t('Enable') : t('Disable');
184189
},
185190
filter: {

protected/commands/FailtwobanipCommand.php

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class FailtwobanipCommand extends ConsoleCommand
2222
{
2323
protected $resultBanIps = [];
2424
protected $resultUnBanIps = [];
25+
protected $ignogeips;
26+
protected $ssh_port = 22;
2527
public function run($args)
2628
{
2729

@@ -53,19 +55,32 @@ public function run($args)
5355

5456

5557

58+
if (isset($args[0])) {
59+
$this->ssh_port = $args[0];
60+
}
61+
62+
63+
5664
$sql = 'SELECT ip FROM pkg_firewall WHERE action = 3';
5765
$command = Yii::app()->db->createCommand($sql);
5866
$this->resultUnBanIps = $command->queryAll();
5967

60-
$sql = 'DELETE FROM pkg_firewall WHERE action = 3';
61-
$command = Yii::app()->db->createCommand($sql);
62-
68+
foreach ($this->resultUnBanIps as $unbanIP) {
69+
$sql = 'DELETE FROM pkg_firewall WHERE ip = "' . $unbanIP['ip'] . '"';
70+
Yii::app()->db->createCommand($sql)->execute();
71+
}
6372

6473
$sql = 'SELECT ip FROM pkg_firewall WHERE action = 1';
6574
$command = Yii::app()->db->createCommand($sql);
6675
$this->resultBanIps = $command->queryAll();
6776

6877

78+
echo "\n\nresultUnBanIps";
79+
print_r($this->resultUnBanIps);
80+
81+
echo "\nresultBanIps";
82+
print_r($this->resultBanIps);
83+
6984
$sql = 'TRUNCATE TABLE pkg_firewall';
7085
Yii::app()->db->createCommand($sql)->execute();
7186

@@ -88,9 +103,17 @@ public function run($args)
88103
$modelServers = Servers::model()->findAll('status IN (1,3,4)');
89104
}
90105

106+
$this->ignogeips = 'ignoreip = 127.0.0.1 ';
91107
foreach ($modelServers as $key => $server) {
108+
$this->ignogeips .= $server['host'] . " ";
109+
}
92110

93-
echo $server['host'] . "\n";
111+
112+
$modelServers = Servers::model()->findAll('status IN (1,3,4)');
113+
114+
foreach ($modelServers as $key => $server) {
115+
116+
echo "\n" . $server['host'] . "\n\n";
94117

95118
if ($server['type'] == 'sipproxy') {
96119

@@ -107,11 +130,18 @@ public function run($args)
107130

108131
public function getLinesCommand($command, $action = 0, $server)
109132
{
133+
134+
echo "sed -i 's/^ignoreip = .*/" . $this->ignogeips . "/' /etc/fail2ban/jail.local\n";
135+
110136
if ($server['type'] == 'mbilling') {
111137

138+
shell_exec("sed -i 's/^ignoreip = .*/" . $this->ignogeips . "/' /etc/fail2ban/jail.local");
139+
shell_exec("systemctl reload fail2ban");
140+
141+
112142
foreach ($this->resultUnBanIps as $unbanIP) {
113143

114-
echo "unbanip IP " . $unbanIP['ip'] . "\n";
144+
echo "unbanip IP " . $unbanIP['ip'] . " on MASTER\n";
115145

116146
@shell_exec("sudo fail2ban-client set asterisk-iptables unbanip " . $unbanIP['ip']);
117147
@shell_exec("sudo fail2ban-client set ip-blacklist unbanip " . $unbanIP['ip']);
@@ -138,19 +168,22 @@ public function getLinesCommand($command, $action = 0, $server)
138168
$status = shell_exec("fail2ban-client status " . $command);
139169
} else {
140170

171+
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "sed -i \'s/^ignoreip = .*/' . $this->ignogeips . '/\' /etc/fail2ban/jail.local" ');
172+
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "systemctl reload fail2ban"');
173+
141174
foreach ($this->resultUnBanIps as $unbanIP) {
142175

143-
echo "unbanip IP " . $unbanIP['ip'] . "\n";
176+
echo "unbanip IP " . $unbanIP['ip'] . " on " . $server['host'] . "\n";
144177

145-
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p 22 "fail2ban-client set asterisk-iptables unbanip ' . $unbanIP['ip'] . '" ');
146-
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p 22 "fail2ban-client set ip-blacklist unbanip ' . $unbanIP['ip'] . '" ');
147-
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p 22 "fail2ban-client set sshd unbanip ' . $unbanIP['ip'] . '" ');
148-
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p 22 "fail2ban-client set opensips-iptables unbanip ' . $unbanIP['ip'] . '" ');
178+
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client set asterisk-iptables unbanip ' . $unbanIP['ip'] . '" ');
179+
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client set ip-blacklist unbanip ' . $unbanIP['ip'] . '" ');
180+
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client set sshd unbanip ' . $unbanIP['ip'] . '" ');
181+
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client set opensips-iptables unbanip ' . $unbanIP['ip'] . '" ');
149182
}
150183

151184
if ($command == 'ip-blacklist') {
152185
foreach ($this->resultBanIps as $blokedIP) {
153-
$status = shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p 22 "fail2ban-client set ip-blacklist banip ' . $blokedIP['ip'] . '" ');
186+
$status = shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client set ip-blacklist banip ' . $blokedIP['ip'] . '" ');
154187

155188
$sqlCheck = "SELECT COUNT(*) FROM pkg_firewall WHERE ip = '" . $blokedIP['ip'] . "' AND id_server = '" . $server['id'] . "'";
156189
$exists = Yii::app()->db->createCommand($sqlCheck)->queryScalar();
@@ -165,8 +198,7 @@ public function getLinesCommand($command, $action = 0, $server)
165198
}
166199
}
167200

168-
169-
$status = shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p 22 "fail2ban-client status ' . $command . '" ');
201+
$status = shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client status ' . $command . '" ');
170202
}
171203

172204
preg_match('/Banned IP list:\s*(.*)/', $status, $ipMatches);

protected/commands/UpdateMysqlCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ public function run($args)
20952095
$sql = "ALTER TABLE pkg_firewall ADD UNIQUE KEY ipperserver (ip, id_server);";
20962096
$this->executeDB($sql);
20972097

2098-
exec("echo '\n* * * * * root php /var/www/html/mbilling/cron.php failtwobanip' >> /etc/crontab");
2098+
exec("echo '\n*/2 * * * * root php /var/www/html/mbilling/cron.php failtwobanip' >> /etc/crontab");
20992099
exec("sed -i 's/ssh-iptables/sshd/g' /etc/fail2ban/jail.local");
21002100
exec("systemctl restart fail2ban");
21012101

0 commit comments

Comments
 (0)