Skip to content

Commit 8b94b24

Browse files
add sip users ip on ignoreIP
1 parent b5a4d28 commit 8b94b24

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

build/MagnusBilling-current.tar.gz

1.15 KB
Binary file not shown.

protected/commands/FailtwobanipCommand.php

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ public function run($args)
9292
}
9393

9494

95+
$sql = 'SELECT host FROM pkg_sip JOIN pkg_user ON pkg_sip.id_user = pkg_user.id WHERE pkg_user.active = 1 AND host != "dynamic"';
96+
$command = Yii::app()->db->createCommand($sql);
97+
$modelServersIgnoreIPs = $command->queryAll();
98+
99+
foreach ($modelServersIgnoreIPs as $key => $server) {
100+
$this->ignogeips .= $server['host'] . " ";
101+
}
102+
103+
$sql = 'SELECT host FROM pkg_trunk WHERE status = 1 AND host != "dynamic"';
104+
$command = Yii::app()->db->createCommand($sql);
105+
$modelServersIgnoreIPs = $command->queryAll();
106+
107+
foreach ($modelServersIgnoreIPs as $key => $server) {
108+
$this->ignogeips .= $server['host'] . " ";
109+
}
110+
111+
95112
echo "\n\nresultUnBanIps";
96113
print_r($this->resultUnBanIps);
97114

@@ -101,11 +118,16 @@ public function run($args)
101118
$sql = 'TRUNCATE TABLE pkg_firewall';
102119
Yii::app()->db->createCommand($sql)->execute();
103120

121+
104122
foreach ($modelServersIgnoreIPs as $key => $server) {
105-
$sql = "INSERT INTO pkg_firewall (ip,action, date, description, jail, id_server) VALUES ('" . $server['ip'] . "',5, NOW(), '','IgnoreIP','1')";
106-
try {
107-
Yii::app()->db->createCommand($sql)->execute();
108-
} catch (Exception $e) {
123+
124+
if (strlen($server['ip']) > 5) {
125+
$sql = "INSERT INTO pkg_firewall (ip,action, date, description, jail, id_server) VALUES ('" . $server['ip'] . "',5, NOW(), '','IgnoreIP','1')";
126+
echo $sql . "\n";
127+
try {
128+
Yii::app()->db->createCommand($sql)->execute();
129+
} catch (Exception $e) {
130+
}
109131
}
110132
}
111133

@@ -168,12 +190,8 @@ public function getLinesCommand($command, $action = 0, $server)
168190

169191

170192
foreach ($this->resultUnBanIps as $unbanIP) {
171-
172193
echo "unbanip IP " . $unbanIP['ip'] . " on MASTER\n";
173-
174-
@shell_exec("sudo fail2ban-client set asterisk-iptables unbanip " . $unbanIP['ip']);
175-
@shell_exec("sudo fail2ban-client set ip-blacklist unbanip " . $unbanIP['ip']);
176-
@shell_exec("sudo fail2ban-client set sshd unbanip " . $unbanIP['ip']);
194+
@shell_exec("sudo fail2ban-client unban " . $unbanIP['ip']);
177195
}
178196
if ($command == 'ip-blacklist') {
179197

@@ -187,6 +205,7 @@ public function getLinesCommand($command, $action = 0, $server)
187205
}
188206

189207
$sql = "INSERT INTO pkg_firewall (ip,action, date, description, jail, id_server) VALUES ('" . $blokedIP['ip'] . "',1, NOW(), '" . $server['name'] . "','$command','" . $server['id'] . "')";
208+
echo $sql . "\n";
190209
try {
191210
Yii::app()->db->createCommand($sql)->execute();
192211
} catch (Exception $e) {
@@ -203,10 +222,7 @@ public function getLinesCommand($command, $action = 0, $server)
203222

204223
echo "unbanip IP " . $unbanIP['ip'] . " on " . $server['host'] . "\n";
205224

206-
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client set asterisk-iptables unbanip ' . $unbanIP['ip'] . '" ');
207-
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client set ip-blacklist unbanip ' . $unbanIP['ip'] . '" ');
208-
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client set sshd unbanip ' . $unbanIP['ip'] . '" ');
209-
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client set opensips-iptables unbanip ' . $unbanIP['ip'] . '" ');
225+
@shell_exec('ssh -o StrictHostKeyChecking=no root@' . $server['host'] . ' -p ' . $this->ssh_port . ' "fail2ban-client unban ' . $unbanIP['ip'] . '" ');
210226
}
211227

212228
if ($command == 'ip-blacklist') {
@@ -219,6 +235,7 @@ public function getLinesCommand($command, $action = 0, $server)
219235
continue;
220236
}
221237
$sql = "INSERT INTO pkg_firewall (ip,action, date, description, jail, id_server) VALUES ('" . $blokedIP['ip'] . "',1, NOW(), '" . $server['name'] . "','$command','" . $server['id'] . "')";
238+
echo $sql . "\n";
222239
try {
223240
Yii::app()->db->createCommand($sql)->execute();
224241
} catch (Exception $e) {
@@ -241,7 +258,7 @@ public function getLinesCommand($command, $action = 0, $server)
241258
foreach ($ips as $ip) {
242259
$sql = "INSERT INTO pkg_firewall (ip,action, date, description, jail, id_server) VALUES ('$ip',$action, NOW(), '" . $server['name'] . "','$command','" . $server['id'] . "')";
243260

244-
echo $sql;
261+
echo $sql . "\n";
245262
try {
246263
Yii::app()->db->createCommand($sql)->execute();
247264
} catch (Exception $e) {

0 commit comments

Comments
 (0)