From afd125725553bc441ba787451d22cdc8684ffae4 Mon Sep 17 00:00:00 2001 From: devdatt Date: Sat, 27 Dec 2025 13:23:32 +0530 Subject: [PATCH] firewall json --- encoder/firewall.php | 18 +++++++++++++----- install.sh | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/encoder/firewall.php b/encoder/firewall.php index a8a3365..21da598 100644 --- a/encoder/firewall.php +++ b/encoder/firewall.php @@ -2,7 +2,8 @@ '', '443' => '', '1935' => '', @@ -10,7 +11,8 @@ $data = [ '8080' => '', ]; -if (file_exists($jsonFile)) { +$data = $defaults; +if (is_file($jsonFile)) { $stored = json_decode(file_get_contents($jsonFile), true); if (is_array($stored)) { $data = array_merge($data, $stored); @@ -18,13 +20,19 @@ if (file_exists($jsonFile)) { } if ($_SERVER['REQUEST_METHOD'] === 'POST') { - foreach ($data as $port => $val) { + + foreach ($defaults as $port => $_) { $data[$port] = trim($_POST["port_$port"] ?? ''); } - file_put_contents($jsonFile, json_encode($data, JSON_PRETTY_PRINT)); + $tmp = $jsonFile . '.tmp'; + file_put_contents( + $tmp, + json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) + ); + rename($tmp, $jsonFile); } - +?> ?> diff --git a/install.sh b/install.sh index 857518e..e754be4 100755 --- a/install.sh +++ b/install.sh @@ -419,6 +419,7 @@ sudo ufw allow 1935 sudo ufw allow 1937 sudo ufw allow 80 sudo ufw allow 443 +sudo ufw allow 8080 sudo ufw allow proto udp to 224.0.0.0/4 sudo ufw route allow proto udp to 224.0.0.0/4 sudo ufw deny out to 239.255.254.254 port 39000 proto udp