firewall json

This commit is contained in:
devdatt 2025-12-27 13:23:32 +05:30
parent 4086e5cb22
commit afd1257255
2 changed files with 14 additions and 5 deletions

View File

@ -2,7 +2,8 @@
<?php <?php
$jsonFile = __DIR__ . '/firewall.json'; $jsonFile = __DIR__ . '/firewall.json';
$data = [
$defaults = [
'80' => '', '80' => '',
'443' => '', '443' => '',
'1935' => '', '1935' => '',
@ -10,7 +11,8 @@ $data = [
'8080' => '', '8080' => '',
]; ];
if (file_exists($jsonFile)) { $data = $defaults;
if (is_file($jsonFile)) {
$stored = json_decode(file_get_contents($jsonFile), true); $stored = json_decode(file_get_contents($jsonFile), true);
if (is_array($stored)) { if (is_array($stored)) {
$data = array_merge($data, $stored); $data = array_merge($data, $stored);
@ -18,13 +20,19 @@ if (file_exists($jsonFile)) {
} }
if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
foreach ($data as $port => $val) {
foreach ($defaults as $port => $_) {
$data[$port] = trim($_POST["port_$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);
} }
?>
?> ?>

View File

@ -419,6 +419,7 @@ sudo ufw allow 1935
sudo ufw allow 1937 sudo ufw allow 1937
sudo ufw allow 80 sudo ufw allow 80
sudo ufw allow 443 sudo ufw allow 443
sudo ufw allow 8080
sudo ufw allow proto udp to 224.0.0.0/4 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 route allow proto udp to 224.0.0.0/4
sudo ufw deny out to 239.255.254.254 port 39000 proto udp sudo ufw deny out to 239.255.254.254 port 39000 proto udp