Initial commit: DDNS service with NIC V2 protocol support
Features: - Token-based subdomain claiming - NIC V2 (DynDNS2) protocol implementation - Technitium DNS integration - Rate limiting (10 req/min IP, 1 req/min token) - Web UI for space claiming - Docker/Docker Compose support - Compatible with UniFi, pfSense, EdgeRouter Module: git.dws.rip/DWS/dyn
This commit is contained in:
258
web/static/css/style.css
Normal file
258
web/static/css/style.css
Normal file
@@ -0,0 +1,258 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: center;
|
||||
padding: 40px 0;
|
||||
color: white;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
header p {
|
||||
font-size: 1.2rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 30px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin-bottom: 20px;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #f5f5f5;
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.input-group input {
|
||||
flex: 1;
|
||||
border: none;
|
||||
background: transparent;
|
||||
font-size: 1.1rem;
|
||||
outline: none;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.domain-suffix {
|
||||
color: #666;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.status {
|
||||
margin: 10px 0;
|
||||
font-size: 0.9rem;
|
||||
min-height: 20px;
|
||||
}
|
||||
|
||||
.status.available {
|
||||
color: #22c55e;
|
||||
}
|
||||
|
||||
.status.taken {
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
button:hover:not(:disabled) {
|
||||
background: #5a67d8;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #f5f5f5;
|
||||
color: #333;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #e5e5e5;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.token-display {
|
||||
background: #f0f9ff;
|
||||
border: 2px solid #667eea;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.token {
|
||||
display: block;
|
||||
word-break: break-all;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 0.9rem;
|
||||
background: white;
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.fqdn-display {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.fqdn-display code {
|
||||
display: block;
|
||||
font-size: 1.1rem;
|
||||
color: #667eea;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.config-grid {
|
||||
display: grid;
|
||||
gap: 15px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.config-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: #f5f5f5;
|
||||
padding: 12px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.config-item label {
|
||||
font-weight: 600;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.config-item code {
|
||||
font-family: 'Courier New', monospace;
|
||||
background: white;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
max-width: 60%;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.examples {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.examples h3 {
|
||||
margin-bottom: 15px;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.example {
|
||||
background: #f5f5f5;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.example h4 {
|
||||
margin-bottom: 10px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.example ul {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.example li {
|
||||
padding: 5px 0;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.example li:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.example pre {
|
||||
background: #1a1a1a;
|
||||
color: #fff;
|
||||
padding: 15px;
|
||||
border-radius: 6px;
|
||||
overflow-x: auto;
|
||||
font-size: 0.85rem;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.card.error {
|
||||
border-left: 4px solid #ef4444;
|
||||
}
|
||||
|
||||
.card.error h2 {
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
header h1 {
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.config-item {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.config-item code {
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
135
web/static/js/app.js
Normal file
135
web/static/js/app.js
Normal file
@@ -0,0 +1,135 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const claimForm = document.getElementById('claim-form');
|
||||
const subdomainInput = document.getElementById('subdomain');
|
||||
const availabilityStatus = document.getElementById('availability-status');
|
||||
const claimBtn = document.getElementById('claim-btn');
|
||||
const claimSection = document.getElementById('claim-section');
|
||||
const successSection = document.getElementById('success-section');
|
||||
const errorSection = document.getElementById('error-section');
|
||||
const routerConfig = document.getElementById('router-config');
|
||||
|
||||
let checkTimeout = null;
|
||||
|
||||
subdomainInput.addEventListener('input', function() {
|
||||
const value = this.value.toLowerCase().replace(/[^a-z0-9-]/g, '');
|
||||
this.value = value;
|
||||
|
||||
clearTimeout(checkTimeout);
|
||||
availabilityStatus.textContent = '';
|
||||
availabilityStatus.className = 'status';
|
||||
claimBtn.disabled = true;
|
||||
|
||||
if (value.length >= 3) {
|
||||
checkTimeout = setTimeout(() => checkAvailability(value), 300);
|
||||
}
|
||||
});
|
||||
|
||||
async function checkAvailability(subdomain) {
|
||||
try {
|
||||
const response = await fetch(`/api/check?subdomain=${encodeURIComponent(subdomain)}`);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.available) {
|
||||
availabilityStatus.textContent = '✓ Available';
|
||||
availabilityStatus.className = 'status available';
|
||||
claimBtn.disabled = false;
|
||||
} else {
|
||||
availabilityStatus.textContent = '✗ Already taken';
|
||||
availabilityStatus.className = 'status taken';
|
||||
claimBtn.disabled = true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking availability:', error);
|
||||
}
|
||||
}
|
||||
|
||||
claimForm.addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
const subdomain = subdomainInput.value;
|
||||
|
||||
claimBtn.disabled = true;
|
||||
claimBtn.textContent = 'Claiming...';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/claim', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ subdomain: subdomain }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
showSuccess(data);
|
||||
} else {
|
||||
showError(data.error || 'Failed to claim space');
|
||||
}
|
||||
} catch (error) {
|
||||
showError('Network error. Please try again.');
|
||||
}
|
||||
|
||||
claimBtn.disabled = false;
|
||||
claimBtn.textContent = 'Claim Space';
|
||||
});
|
||||
|
||||
function showSuccess(data) {
|
||||
claimSection.classList.add('hidden');
|
||||
successSection.classList.remove('hidden');
|
||||
routerConfig.classList.remove('hidden');
|
||||
|
||||
document.getElementById('token-value').textContent = data.token;
|
||||
document.getElementById('fqdn-value').textContent = data.fqdn;
|
||||
|
||||
const updateUrl = `https://dyn.${data.fqdn.split('.').slice(-2).join('.')}/api/nic/update?hostname=%h&myip=%i`;
|
||||
document.getElementById('update-url').textContent = updateUrl;
|
||||
|
||||
document.querySelectorAll('.hostname-placeholder').forEach(el => {
|
||||
el.textContent = data.fqdn;
|
||||
});
|
||||
|
||||
document.querySelectorAll('.update-url-placeholder').forEach(el => {
|
||||
el.textContent = updateUrl;
|
||||
});
|
||||
|
||||
const curlCmd = `curl -u "none:${data.token}" "https://dyn.${data.fqdn.split('.').slice(-2).join('.')}/api/nic/update?hostname=${data.fqdn}"`;
|
||||
document.getElementById('curl-example').textContent = curlCmd;
|
||||
|
||||
document.getElementById('copy-token').addEventListener('click', function() {
|
||||
copyToClipboard(data.token);
|
||||
this.textContent = 'Copied!';
|
||||
setTimeout(() => this.textContent = 'Copy Token', 2000);
|
||||
});
|
||||
|
||||
document.getElementById('copy-curl').addEventListener('click', function() {
|
||||
copyToClipboard(curlCmd);
|
||||
this.textContent = 'Copied!';
|
||||
setTimeout(() => this.textContent = 'Copy', 2000);
|
||||
});
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
claimSection.classList.add('hidden');
|
||||
errorSection.classList.remove('hidden');
|
||||
document.getElementById('error-message').textContent = message;
|
||||
}
|
||||
|
||||
document.getElementById('try-again').addEventListener('click', function() {
|
||||
errorSection.classList.add('hidden');
|
||||
claimSection.classList.remove('hidden');
|
||||
subdomainInput.value = '';
|
||||
subdomainInput.focus();
|
||||
});
|
||||
|
||||
function copyToClipboard(text) {
|
||||
navigator.clipboard.writeText(text).catch(function() {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(textarea);
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user