add clipboard copy functionality and restrict firewall commands to localhost

This commit is contained in:
CPTN Cosmo 2026-04-18 16:51:10 +02:00
parent f57d2fc6be
commit 2304717de5
3 changed files with 63 additions and 2 deletions

View file

@ -123,6 +123,23 @@ document.addEventListener('DOMContentLoaded', () => {
}
};
window.copyToClipboard = async (elementId) => {
const text = document.getElementById(elementId).textContent;
const btn = event.currentTarget;
try {
await navigator.clipboard.writeText(text);
const originalHtml = btn.innerHTML;
btn.classList.add('copied');
btn.innerHTML = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>';
setTimeout(() => {
btn.classList.remove('copied');
btn.innerHTML = originalHtml;
}, 2000);
} catch (err) {
console.error('Failed to copy: ', err);
}
};
function escapeHtml(unsafe) {
if (!unsafe) return '';
return unsafe.toString()

View file

@ -50,11 +50,21 @@
<p class="helper-text">Run these commands on the machine running XIVLauncher to allow incoming connections on the specified port.</p>
<div class="code-block">
<span class="code-label">UFW</span>
<code id="ufw-cmd">sudo ufw allow 4646/tcp</code>
<div class="code-wrapper">
<code id="ufw-cmd">sudo ufw allow from localhost to any port 4646 proto tcp</code>
<button class="btn-copy" onclick="copyToClipboard('ufw-cmd')" title="Copy to clipboard">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
</button>
</div>
</div>
<div class="code-block">
<span class="code-label">iptables</span>
<code id="iptables-cmd">sudo iptables -I INPUT -p tcp --dport 4646 -j ACCEPT</code>
<div class="code-wrapper">
<code id="iptables-cmd">sudo iptables -I INPUT -p tcp -s localhost --dport 4646 -j ACCEPT</code>
<button class="btn-copy" onclick="copyToClipboard('iptables-cmd')" title="Copy to clipboard">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
</button>
</div>
</div>
</div>

View file

@ -262,4 +262,38 @@ input:focus {
.code-block code {
color: #34d399;
word-break: break-all;
}
.code-wrapper {
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}
.btn-copy {
background: transparent;
border: none;
color: var(--text-muted);
cursor: pointer;
padding: 0.25rem;
border-radius: 4px;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
}
.btn-copy:hover {
background-color: rgba(255, 255, 255, 0.1);
color: var(--text-main);
}
.btn-copy:active {
transform: scale(0.95);
}
.btn-copy.copied {
color: var(--status-online);
}