Skip to content

Commit e26e6b9

Browse files
Alexey PortnovAlexey Portnov
authored andcommitted
fix(sysinfo): suppress iptables error in diagnostic report for containers (#1011)
getIptablesInfo() called iptables -S unconditionally, producing modprobe/legacy table errors in Docker on nf_tables hosts (Alpine 6.12+) where the legacy iptables backend cannot initialize without the host's ip_tables kernel module. Skip the iptables call when canManageFirewall() is false and show a context-specific message instead: - Docker: "Firewall managed by host (Docker)" - LXC without CAP_NET_ADMIN: "Firewall unavailable (container without CAP_NET_ADMIN)"
1 parent 13f1f98 commit e26e6b9

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/PBXCoreREST/Lib/Sysinfo/GetInfoAction.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use MikoPBX\Common\Models\PbxSettings;
2525
use MikoPBX\Core\System\PBX;
2626
use MikoPBX\Core\System\Processes;
27+
use MikoPBX\Core\System\System;
2728
use MikoPBX\Core\System\Util;
2829
use MikoPBX\PBXCoreREST\Lib\PBXApiResult;
2930
use MikoPBX\Service\Main;
@@ -284,13 +285,19 @@ private static function getRouteInfo(): string
284285
*/
285286
private static function getIptablesInfo(): string
286287
{
287-
$content = '────────────────────────────────────────── iptables ──────────────────────────────────────';
288-
$content .= PHP_EOL . PHP_EOL;
289-
$iptables = Util::which('iptables');
290-
$out = [];
291-
Processes::mwExec("$iptables -S", $out);
292-
$iptablesOut = implode(PHP_EOL, $out);
293-
$content .= $iptablesOut . PHP_EOL;
288+
$content = '────────────────────────────────────────── iptables ──────────────────────────────────────';
289+
$content .= PHP_EOL . PHP_EOL;
290+
if (!System::canManageFirewall()) {
291+
$reason = System::isDocker()
292+
? 'Firewall managed by host (Docker)'
293+
: 'Firewall unavailable (container without CAP_NET_ADMIN)';
294+
$content .= $reason . PHP_EOL;
295+
} else {
296+
$iptables = Util::which('iptables');
297+
$out = [];
298+
Processes::mwExec("$iptables -S", $out);
299+
$content .= implode(PHP_EOL, $out) . PHP_EOL;
300+
}
294301
$content .= PHP_EOL . PHP_EOL;
295302
return $content;
296303
}

0 commit comments

Comments
 (0)