add configurable firewall host IP for firewall command generation

This commit is contained in:
CPTN Cosmo 2026-04-18 16:48:41 +02:00
parent 340f8e5bef
commit f57d2fc6be
4 changed files with 28 additions and 1 deletions

View file

@ -6,14 +6,31 @@ document.addEventListener('DOMContentLoaded', () => {
const ufwCmd = document.getElementById('ufw-cmd');
const iptablesCmd = document.getElementById('iptables-cmd');
let config = { firewall_host_ip: null };
const updateFirewallCmds = () => {
const port = portInput.value || '4646';
const hostIp = window.location.hostname;
const hostIp = config.firewall_host_ip || window.location.hostname;
ufwCmd.textContent = `sudo ufw allow from ${hostIp} to any port ${port} proto tcp`;
iptablesCmd.textContent = `sudo iptables -I INPUT -p tcp -s ${hostIp} --dport ${port} -j ACCEPT`;
};
const fetchConfig = async () => {
try {
const res = await fetch('/api/config');
if (res.ok) {
config = await res.json();
updateFirewallCmds();
}
} catch (e) {
console.error('Failed to fetch config:', e);
}
};
portInput.addEventListener('input', updateFirewallCmds);
// Initial fetch of config and instances
fetchConfig();
updateFirewallCmds();
const fetchInstances = async () => {