add configurable firewall host IP for firewall command generation
This commit is contained in:
parent
340f8e5bef
commit
f57d2fc6be
4 changed files with 28 additions and 1 deletions
|
|
@ -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 () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue