Resourcen ujnd Domians aus ux.js entfernt.

This commit is contained in:
ecki 2026-03-21 17:59:55 +01:00
parent 312aa366e5
commit 67106ac1a1
5 changed files with 552 additions and 537 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ node_modules/
.env
.DS_Store
*.log
docker-compose.yaml

View File

@ -322,6 +322,7 @@ Domains jährlich: <span id="costDomain">0</span> €<br>
<script src="js/api.js"></script>
<script src="js/resources.js"></script>
<script src="js/domains.js"</script>
<script src="js/ui.js"></script>
<script src="js/main.js"></script>

View File

@ -0,0 +1,259 @@
async function loadDomains(){
const domains = await api(API + "/domains")
const subs = await api(API + "/subdomains")
const table = document.getElementById("domains")
table.innerHTML = ""
for(const d of domains){
const tr = document.createElement("tr")
const sublist = subs
.filter(s => s.domain_id === d.id)
.map(s => `
<div class="subdomain">
${s.subdomain}.${s.domain_name}
<span id="subdns-${s.id}">...</span>
<span id="subserver-${s.id}" class="serverlink"></span>
<button onclick="deleteSub(${s.id})">Delete</button>
</div>
`)
.join("");
tr.innerHTML = `
<td>
${d.domain_name}
${sublist}
</td>
<td><span class="provider">${d.provider || ""}</span></td>
<td>${d.ip_address || ""}</td>
<td>${d.resource_name || ""}</td>
<td id="dns-${d.id}">...</td>
<td>${d.yearly_cost || ""}</td>
<td>
<button onclick='openDomainEdit(${JSON.stringify(d)})'>Edit</button>
<button onclick="deleteDomain(${d.id})">Delete</button>
<button onclick="openSubCreate(${d.id},'${d.domain_name}')">
+ Subdomain
</button>
</td>
`;
table.appendChild(tr)
const resources = window.resources || []
subs.forEach(s => {
const server = resources.find(r =>
Array.isArray(r.ips) &&
r.ips.some(ip => ip.ip === s.ip_address)
)
if(server){
const el = document.getElementById("subserver-"+s.id)
if(el){
el.innerText = " → " + server.name
}
}
})
subs
.filter(s => s.domain_id === d.id)
.forEach(async s => {
const full = s.subdomain + "." + s.domain_name
try{
const dns = await api(API + "/dns/" + full)
let status="❌"
if(dns.ips && dns.ips.includes(s.ip_address)){
status="✅" + dns.ips.join(", ")
}else if(dns.ips.length){
status="⚠" + dns.ips.join(", ")
}
document.getElementById("subdns-"+s.id).innerHTML=status
}catch(e){
document.getElementById("subdns-"+s.id).innerHTML="❌"
}
})
try{
const dnsRes = await fetch(API + "/dns/" + d.domain_name)
const result = await dnsRes.json()
let status = "❌"
if(result.ips && result.ips.length){
const ipList = result.ips.join("<br>")
if(d.ip_address && result.ips.includes(d.ip_address)){
status = "✅ " + ipList
}else{
status = "⚠ " + ipList
}
}
document.getElementById("dns-"+d.id).innerHTML = status
}catch(e){
document.getElementById("dns-"+d.id).innerHTML = "❌"
}
}
}
async function deleteDomain(id){
if(!confirm("Domain löschen?")) return;
await api(API + "/domains/" + id, {
method: "DELETE"
});
loadDomains();
}
async function saveDomain(){
const id=document.getElementById("domain_id").value
let cost=document.getElementById("domain_cost").value
if(cost){
cost=cost.replace(",",".")
}
const data={
domain_name:domain_name.value,
provider:domain_provider.value,
ip_address:domain_ip.value,
yearly_cost:cost || null,
notes:domain_notes.value
}
if(id){
await api(API+"/domains/"+id,{
method:"PUT",
headers:{'Content-Type':'application/json'},
body:JSON.stringify(data)
})
}else{
await api(API+"/domains",{
method:"POST",
headers:{'Content-Type':'application/json'},
body:JSON.stringify(data)
})
}
closeDomainModal()
loadDomains()
loadMapping()
loadCosts()
}
async function loadMapping(){
const data = await api(API + "/domainmap");
const table = document.getElementById("mapping");
table.innerHTML = "";
data.forEach(m => {
const tr = document.createElement("tr");
tr.innerHTML = `
<td>${m.domain_name}</td>
<td>${m.ip_address}</td>
<td>${m.server_name || ""}</td>
`;
table.appendChild(tr);
});
}
function openDomainCreate(){
document.getElementById("domainModalTitle").innerText="Create Domain"
document.getElementById("domain_id").value=""
document.getElementById("domain_name").value=""
document.getElementById("domain_provider").value=""
document.getElementById("domain_ip").value=""
document.getElementById("domain_cost").value=""
document.getElementById("domain_notes").value=""
document.getElementById("domainModal").style.display="block"
}
function openDomainEdit(d){
document.getElementById("domainModalTitle").innerText="Edit Domain"
document.getElementById("domain_id").value=d.id
document.getElementById("domain_name").value=d.domain_name||""
document.getElementById("domain_provider").value=d.provider||""
document.getElementById("domain_ip").value=d.ip_address||""
document.getElementById("domain_cost").value=d.yearly_cost||""
document.getElementById("domain_notes").value=d.notes||""
document.getElementById("domainModal").style.display="block"
}
function closeDomainModal(){
document.getElementById("domainModal").style.display="none"
}

View File

@ -194,3 +194,294 @@ async function checkServerStatus(resource){
}
function openCreate(){
document.getElementById("modalTitle").innerText = "Create Resource"
document.getElementById("resource_id").value = ""
document.querySelectorAll("#resourceModal input, #resourceModal textarea")
.forEach(e=>e.value="")
document.getElementById("status").value = "aktiv"
document.getElementById("resourceModal").style.display = "block"
}
function openEdit(resource){
document.getElementById("modalTitle").innerText = "Edit Resource"
document.getElementById("resource_id").value = resource.id
Object.keys(resource).forEach(k=>{
const el = document.getElementById(k)
if(el) el.value = resource[k] || ""
})
document.getElementById("resourceModal").style.display = "block"
}
function closeModal(){
document.getElementById("resourceModal").style.display="none"
}
async function openServerDetail(resource){
const mappings = await api(API+"/domainmap")
let html = `
<b>Name:</b> ${resource.name}<br>
<b>Produkt:</b> ${resource.produkt || ""}<br>
<b>Provider:</b> ${resource.provider || ""}<br>
<b>Provider Name:</b> ${resource.providername || ""}
<br><br>
<b>System</b><br>
CPU: ${resource.cpu || ""}<br>
RAM: ${resource.ram || ""}<br>
Disk: ${resource.disk || ""}<br>
OS: ${resource.os || ""}
<br><br>
<b>IPs</b><br>
`
if(Array.isArray(resource.ips)){
resource.ips.forEach(ip=>{
html += `<div class="ip">${ip.type || ""} ${ip.ip}</div>`
})
}
html += `<br><b>Domains</b><br>`
const domains = mappings.filter(m => m.resource_id == resource.id)
domains.forEach(d=>{
html += `<div class="ip">🌐 ${d.domain_name}</div>`
})
html += `
<br>
<b>Bestelldatum:</b> ${resource.bestelldatum || ""}<br>
<b>Kündbar ab:</b> ${resource.kuendbar_ab || ""}
<br><br>
<b>Bemerkung</b><br>
${resource.bemerkung || ""}
`
const subs = await api(API + "/subdomains")
html += "<br><b>Subdomains</b><br>"
if(Array.isArray(resource.ips)){
subs.forEach(s => {
const match = resource.ips.find(ip => ip.ip === s.ip_address)
if(match){
html += `<div class="ip">🌐 ${s.subdomain}.${s.domain_name}</div>`
}
})
}
/* jetzt erst rendern */
document.getElementById("serverDetailContent").innerHTML = html
document.getElementById("serverDetailModal").style.display="block"
}
function closeServerDetail(){
document.getElementById("serverDetailModal").style.display="none"
}
document.addEventListener("click", function(event){
const modal = document.getElementById("serverDetailModal");
if(!modal) return;
if(event.target === modal){
modal.style.display = "none";
}
});
document.addEventListener("keydown", function(e){
if(e.key === "Escape"){
const modal = document.getElementById("serverDetailModal");
if(modal) modal.style.display="none";
}
});
router.delete("/:id", async (req,res)=>{
await db.query("DELETE FROM subdomains WHERE id=?",[req.params.id])
res.json({success:true})
})
async function loadCancelled(){
const res = await api(API+"/resources/cancelled")
const table = document.getElementById("cancelled")
table.innerHTML=""
res.forEach(r=>{
const tr=document.createElement("tr")
tr.innerHTML=`
<td>${r.name}</td>
<td>${r.produkt||""}</td>
<td><span class="provider">${r.provider || ""}</span></td>
<td>${r.cpu||""}</td>
<td>${r.ram||""}</td>
<td>${r.disk||""}</td>
<td>gekündigt</td>
`
table.appendChild(tr)
})
}
async function loadCosts(){
const resources = await api(API+"/resources/active")
const domains = await api(API+"/domains")
let month = 0
let year = 0
let domainYear = 0
resources.forEach(r=>{
let m = Number(r.kosten_monat || 0)
let y = Number(r.kosten_jahr || 0)
if(m){
month += m
}else if(y){
month += y / 12
}
if(y){
year += y
}else if(m){
year += m * 12
}
})
domains.forEach(d=>{
domainYear += Number(d.yearly_cost || 0)
})
document.getElementById("costMonth").innerText = month.toFixed(2)
document.getElementById("costYear").innerText = year.toFixed(2)
document.getElementById("costDomain").innerText = domainYear.toFixed(2)
document.getElementById("costTotal").innerText = (year + domainYear).toFixed(2)
}
async function loadInfrastructure(){
const resources = await api(API + "/resources/active")
const mappings = await api(API + "/domainmap")
let html = ""
resources.forEach(r => {
html += `
<div style="margin-bottom:20px;border:1px solid #ddd;padding:10px;border-radius:6px">
<b>${r.name}</b><br>
Produkt: ${r.produkt || ""}<br>
CPU: ${r.cpu || ""} | RAM: ${r.ram || ""} | Disk: ${r.disk || ""}<br>
OS: ${r.os || ""}
<br><br>
`
if(Array.isArray(r.ips)){
r.ips.forEach(ip => {
html += `
<div style="margin-left:20px">
<b>IP:</b> ${ip.ip} (${ip.type || ""})
`
const domains = mappings.filter(m => m.ip_address == ip.ip)
domains.forEach(d => {
html += `
<div style="margin-left:20px;color:#444">
🌐 ${d.domain_name}
</div>
`
})
html += "</div>"
})
}
html += "</div>"
})
document.getElementById("infraView").innerHTML = html
}

View File

@ -1,174 +1,4 @@
window.resources = []
async function loadDomains(){
const domains = await api(API + "/domains")
const subs = await api(API + "/subdomains")
const table = document.getElementById("domains")
table.innerHTML = ""
for(const d of domains){
const tr = document.createElement("tr")
const sublist = subs
.filter(s => s.domain_id === d.id)
.map(s => `
<div class="subdomain">
${s.subdomain}.${s.domain_name}
<span id="subdns-${s.id}">...</span>
<span id="subserver-${s.id}" class="serverlink"></span>
<button onclick="deleteSub(${s.id})">Delete</button>
</div>
`)
.join("");
tr.innerHTML = `
<td>
${d.domain_name}
${sublist}
</td>
<td><span class="provider">${d.provider || ""}</span></td>
<td>${d.ip_address || ""}</td>
<td>${d.resource_name || ""}</td>
<td id="dns-${d.id}">...</td>
<td>${d.yearly_cost || ""}</td>
<td>
<button onclick='openDomainEdit(${JSON.stringify(d)})'>Edit</button>
<button onclick="deleteDomain(${d.id})">Delete</button>
<button onclick="openSubCreate(${d.id},'${d.domain_name}')">
+ Subdomain
</button>
</td>
`;
table.appendChild(tr)
const resources = window.resources || []
subs.forEach(s => {
const server = resources.find(r =>
Array.isArray(r.ips) &&
r.ips.some(ip => ip.ip === s.ip_address)
)
if(server){
const el = document.getElementById("subserver-"+s.id)
if(el){
el.innerText = " → " + server.name
}
}
})
subs
.filter(s => s.domain_id === d.id)
.forEach(async s => {
const full = s.subdomain + "." + s.domain_name
try{
const dns = await api(API + "/dns/" + full)
let status="❌"
if(dns.ips && dns.ips.includes(s.ip_address)){
status="✅" + dns.ips.join(", ")
}else if(dns.ips.length){
status="⚠" + dns.ips.join(", ")
}
document.getElementById("subdns-"+s.id).innerHTML=status
}catch(e){
document.getElementById("subdns-"+s.id).innerHTML="❌"
}
})
try{
const dnsRes = await fetch(API + "/dns/" + d.domain_name)
const result = await dnsRes.json()
let status = "❌"
if(result.ips && result.ips.length){
const ipList = result.ips.join("<br>")
if(d.ip_address && result.ips.includes(d.ip_address)){
status = "✅ " + ipList
}else{
status = "⚠ " + ipList
}
}
document.getElementById("dns-"+d.id).innerHTML = status
}catch(e){
document.getElementById("dns-"+d.id).innerHTML = "❌"
}
}
}
async function deleteDomain(id){
if(!confirm("Domain löschen?")) return;
await api(API + "/domains/" + id, {
method: "DELETE"
});
loadDomains();
}
async function loadMapping(){
const data = await api(API + "/domainmap");
const table = document.getElementById("mapping");
table.innerHTML = "";
data.forEach(m => {
const tr = document.createElement("tr");
tr.innerHTML = `
<td>${m.domain_name}</td>
<td>${m.ip_address}</td>
<td>${m.server_name || ""}</td>
`;
table.appendChild(tr);
});
}
function openIPManager(resourceId){
@ -226,257 +56,6 @@ loadResources()
}
function openCreate(){
document.getElementById("modalTitle").innerText = "Create Resource"
document.getElementById("resource_id").value = ""
document.querySelectorAll("#resourceModal input, #resourceModal textarea")
.forEach(e=>e.value="")
document.getElementById("status").value = "aktiv"
document.getElementById("resourceModal").style.display = "block"
}
function openEdit(resource){
document.getElementById("modalTitle").innerText = "Edit Resource"
document.getElementById("resource_id").value = resource.id
Object.keys(resource).forEach(k=>{
const el = document.getElementById(k)
if(el) el.value = resource[k] || ""
})
document.getElementById("resourceModal").style.display = "block"
}
function closeModal(){
document.getElementById("resourceModal").style.display="none"
}
function openDomainCreate(){
document.getElementById("domainModalTitle").innerText="Create Domain"
document.getElementById("domain_id").value=""
document.getElementById("domain_name").value=""
document.getElementById("domain_provider").value=""
document.getElementById("domain_ip").value=""
document.getElementById("domain_cost").value=""
document.getElementById("domain_notes").value=""
document.getElementById("domainModal").style.display="block"
}
function openDomainEdit(d){
document.getElementById("domainModalTitle").innerText="Edit Domain"
document.getElementById("domain_id").value=d.id
document.getElementById("domain_name").value=d.domain_name||""
document.getElementById("domain_provider").value=d.provider||""
document.getElementById("domain_ip").value=d.ip_address||""
document.getElementById("domain_cost").value=d.yearly_cost||""
document.getElementById("domain_notes").value=d.notes||""
document.getElementById("domainModal").style.display="block"
}
function closeDomainModal(){
document.getElementById("domainModal").style.display="none"
}
async function saveDomain(){
const id=document.getElementById("domain_id").value
let cost=document.getElementById("domain_cost").value
if(cost){
cost=cost.replace(",",".")
}
const data={
domain_name:domain_name.value,
provider:domain_provider.value,
ip_address:domain_ip.value,
yearly_cost:cost || null,
notes:domain_notes.value
}
if(id){
await api(API+"/domains/"+id,{
method:"PUT",
headers:{'Content-Type':'application/json'},
body:JSON.stringify(data)
})
}else{
await api(API+"/domains",{
method:"POST",
headers:{'Content-Type':'application/json'},
body:JSON.stringify(data)
})
}
closeDomainModal()
loadDomains()
loadMapping()
loadCosts()
}
async function loadCancelled(){
const res = await api(API+"/resources/cancelled")
const table = document.getElementById("cancelled")
table.innerHTML=""
res.forEach(r=>{
const tr=document.createElement("tr")
tr.innerHTML=`
<td>${r.name}</td>
<td>${r.produkt||""}</td>
<td><span class="provider">${r.provider || ""}</span></td>
<td>${r.cpu||""}</td>
<td>${r.ram||""}</td>
<td>${r.disk||""}</td>
<td>gekündigt</td>
`
table.appendChild(tr)
})
}
async function loadCosts(){
const resources = await api(API+"/resources/active")
const domains = await api(API+"/domains")
let month = 0
let year = 0
let domainYear = 0
resources.forEach(r=>{
let m = Number(r.kosten_monat || 0)
let y = Number(r.kosten_jahr || 0)
if(m){
month += m
}else if(y){
month += y / 12
}
if(y){
year += y
}else if(m){
year += m * 12
}
})
domains.forEach(d=>{
domainYear += Number(d.yearly_cost || 0)
})
document.getElementById("costMonth").innerText = month.toFixed(2)
document.getElementById("costYear").innerText = year.toFixed(2)
document.getElementById("costDomain").innerText = domainYear.toFixed(2)
document.getElementById("costTotal").innerText = (year + domainYear).toFixed(2)
}
async function loadInfrastructure(){
const resources = await api(API + "/resources/active")
const mappings = await api(API + "/domainmap")
let html = ""
resources.forEach(r => {
html += `
<div style="margin-bottom:20px;border:1px solid #ddd;padding:10px;border-radius:6px">
<b>${r.name}</b><br>
Produkt: ${r.produkt || ""}<br>
CPU: ${r.cpu || ""} | RAM: ${r.ram || ""} | Disk: ${r.disk || ""}<br>
OS: ${r.os || ""}
<br><br>
`
if(Array.isArray(r.ips)){
r.ips.forEach(ip => {
html += `
<div style="margin-left:20px">
<b>IP:</b> ${ip.ip} (${ip.type || ""})
`
const domains = mappings.filter(m => m.ip_address == ip.ip)
domains.forEach(d => {
html += `
<div style="margin-left:20px;color:#444">
🌐 ${d.domain_name}
</div>
`
})
html += "</div>"
})
}
html += "</div>"
})
document.getElementById("infraView").innerHTML = html
}
@ -493,122 +72,6 @@ async function deleteIP(id, resourceId){
}
async function openServerDetail(resource){
const mappings = await api(API+"/domainmap")
let html = `
<b>Name:</b> ${resource.name}<br>
<b>Produkt:</b> ${resource.produkt || ""}<br>
<b>Provider:</b> ${resource.provider || ""}<br>
<b>Provider Name:</b> ${resource.providername || ""}
<br><br>
<b>System</b><br>
CPU: ${resource.cpu || ""}<br>
RAM: ${resource.ram || ""}<br>
Disk: ${resource.disk || ""}<br>
OS: ${resource.os || ""}
<br><br>
<b>IPs</b><br>
`
if(Array.isArray(resource.ips)){
resource.ips.forEach(ip=>{
html += `<div class="ip">${ip.type || ""} ${ip.ip}</div>`
})
}
html += `<br><b>Domains</b><br>`
const domains = mappings.filter(m => m.resource_id == resource.id)
domains.forEach(d=>{
html += `<div class="ip">🌐 ${d.domain_name}</div>`
})
html += `
<br>
<b>Bestelldatum:</b> ${resource.bestelldatum || ""}<br>
<b>Kündbar ab:</b> ${resource.kuendbar_ab || ""}
<br><br>
<b>Bemerkung</b><br>
${resource.bemerkung || ""}
`
const subs = await api(API + "/subdomains")
html += "<br><b>Subdomains</b><br>"
if(Array.isArray(resource.ips)){
subs.forEach(s => {
const match = resource.ips.find(ip => ip.ip === s.ip_address)
if(match){
html += `<div class="ip">🌐 ${s.subdomain}.${s.domain_name}</div>`
}
})
}
/* jetzt erst rendern */
document.getElementById("serverDetailContent").innerHTML = html
document.getElementById("serverDetailModal").style.display="block"
}
function closeServerDetail(){
document.getElementById("serverDetailModal").style.display="none"
}
document.addEventListener("click", function(event){
const modal = document.getElementById("serverDetailModal");
if(!modal) return;
if(event.target === modal){
modal.style.display = "none";
}
});
document.addEventListener("keydown", function(e){
if(e.key === "Escape"){
const modal = document.getElementById("serverDetailModal");
if(modal) modal.style.display="none";
}
});
router.delete("/:id", async (req,res)=>{
await db.query("DELETE FROM subdomains WHERE id=?",[req.params.id])
res.json({success:true})
})
function openSubCreate(domainId){