alles ok vor aufteilung ui
This commit is contained in:
+131
-26
@@ -71,48 +71,57 @@ async function loadResources(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function loadDomains(){
|
async function loadDomains(){
|
||||||
|
|
||||||
const domains = await api(API + "/domains");
|
const domains = await api(API + "/domains")
|
||||||
|
|
||||||
const table = document.getElementById("domains");
|
const table = document.getElementById("domains")
|
||||||
table.innerHTML = "";
|
table.innerHTML = ""
|
||||||
|
|
||||||
domains.forEach(d => {
|
for(const d of domains){
|
||||||
|
|
||||||
const tr = document.createElement("tr");
|
const tr = document.createElement("tr")
|
||||||
|
|
||||||
tr.innerHTML = `
|
tr.innerHTML = `
|
||||||
<td>${d.domain_name}</td>
|
|
||||||
|
|
||||||
<td>
|
<td>${d.domain_name}</td> <td> <span class="provider">${d.provider || ""}</span> </td> <td>${d.ip_address || ""}</td> <td id="server-${d.id}"> ${d.resource_name ? d.resource_name : "<span style='color:red'>⚠ no server</span>"} </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> </td> `
|
||||||
<span class="provider">${d.provider || ""}</span>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td>${d.ip_address || ""}</td>
|
table.appendChild(tr)
|
||||||
|
|
||||||
<td>
|
try{
|
||||||
${d.resource_name ?
|
|
||||||
d.resource_name :
|
|
||||||
"<span style='color:red'>⚠ no server</span>"}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td id="dns-${d.id}">...</td>
|
const dnsRes = await fetch(API + "/dns/" + d.domain_name)
|
||||||
|
const result = await dnsRes.json()
|
||||||
|
|
||||||
<td>${d.yearly_cost || ""}</td>
|
let status = "❌"
|
||||||
|
|
||||||
<td>
|
if(result.ips && result.ips.length){
|
||||||
<button onclick='openDomainEdit(${JSON.stringify(d)})'>Edit</button>
|
|
||||||
<button onclick="deleteDomain(${d.id})">Delete</button>
|
|
||||||
</td>
|
|
||||||
`;
|
|
||||||
|
|
||||||
table.appendChild(tr);
|
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){
|
async function deleteDomain(id){
|
||||||
|
|
||||||
if(!confirm("Domain löschen?")) return;
|
if(!confirm("Domain löschen?")) return;
|
||||||
@@ -423,8 +432,104 @@ 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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
loadResources();
|
loadResources();
|
||||||
loadDomains();
|
loadDomains();
|
||||||
loadMapping();
|
loadMapping();
|
||||||
|
loadCosts()
|
||||||
|
loadInfrastructure()
|
||||||
|
|||||||
Reference in New Issue
Block a user