resman/backend/public/index.html
2026-03-08 17:05:42 +01:00

1115 lines
17 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ResMan</title>
<style>
body{
font-family:Arial;
margin:40px;
background:#f4f6f8;
}
h1{
margin-bottom:30px;
}
section{
background:white;
padding:20px;
margin-bottom:30px;
border-radius:8px;
box-shadow:0 2px 6px rgba(0,0,0,0.1);
}
table{
width:100%;
border-collapse:collapse;
margin-top:10px;
}
th,td{
padding:8px;
border-bottom:1px solid #ddd;
text-align:left;
}
th{
background:#1e3a8a;
color:white;
}
button{
background:#3b82f6;
color:white;
border:none;
border-radius:4px;
padding:6px 10px;
margin:2px;
cursor:pointer;
}
button:hover{
background:#1e40af;
}
input,textarea{
padding:6px;
margin:4px;
width:95%;
}
.ip{
background:#eee;
padding:2px 6px;
border-radius:4px;
margin-right:4px;
display:inline-block;
}
.modal{
display:none;
position:fixed;
top:10%;
left:50%;
transform:translateX(-50%);
background:white;
padding:20px;
width:600px;
max-height:80vh;
overflow:auto;
box-shadow:0 10px 30px rgba(0,0,0,0.3);
border-radius:6px;
}
.system{
font-size:13px;
color:#333;
}
#infraView div{
background:#fafafa;
}
.ip{
font-size:12px;
background:#f4f4f4;
padding:2px 6px;
margin:2px 0;
border-radius:4px;
display:inline-block;
}
.provider{
background:#e9f2ff;
padding:2px 8px;
border-radius:4px;
font-size:12px;
}
.cost{
font-weight:bold;
color:#0a7;
}
section{
border-left:4px solid #3b82f6;
}
td{
vertical-align:top;
}
td:first-child{
font-weight:bold;
}
</style>
</head>
<body>
<h1>Ressourcen Verwaltung</h1>
<section>
<h2>Kosten Dashboard</h2>
<div id="costDashboard">
Server monatlich: <span id="costMonth">0</span><br>
Server jährlich: <span id="costYear">0</span><br>
Domains jährlich: <span id="costDomain">0</span><br>
<hr>
<b>Gesamt jährlich: <span id="costTotal">0</span></b>
</div>
</section>
<section>
<h2>Aktive Ressourcen</h2>
<button onclick="openCreate()">Neue Resource</button>
<table>
<thead>
<tr>
<th>Name</th>
<th>Produkt</th>
<th>Provider</th>
<th>Status</th>
<th>System</th>
<th>Domains</th>
<th>IPs</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody id="resources"></tbody>
</table>
</section>
<section>
<h2>Infrastruktur Übersicht</h2>
<div id="infraView"></div>
</section>
<section>
<h2>Domains</h2>
<button onclick="openDomainCreate()">Neue Domain</button>
<table>
<thead>
<tr>
<th>Domain</th>
<th>Provider</th>
<th>IP</th>
<th>Server</th>
<th>DNS</th>
<th>Kosten/Jahr</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody id="domains"></tbody>
</table>
</section>
<section>
<h2>Domain → Server Zuordnung</h2>
<table>
<thead>
<tr>
<th>Domain</th>
<th>IP</th>
<th>Server</th>
</tr>
</thead>
<tbody id="mapping"></tbody>
</table>
</section>
<section>
<h2>Gekündigte Resources</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Produkt</th>
<th>Provider</th>
<th>CPU</th>
<th>RAM</th>
<th>Disk</th>
<th>Status</th>
</tr>
</thead>
<tbody id="cancelled"></tbody>
</table>
</section>
<div id="resourceModal" class="modal">
<h3 id="modalTitle">Resource</h3>
<input type="hidden" id="resource_id">
<label>Name</label> <input id="name">
<label>Produkt</label> <input id="produkt">
<label>Provider</label> <input id="provider">
<label>Art</label> <input id="art">
<label>CPU</label> <input id="cpu">
<label>RAM</label> <input id="ram">
<label>Disk</label> <input id="disk">
<label>OS</label> <input id="os">
<label>Kosten Monat</label> <input id="kosten_monat">
<label>Kosten Jahr</label> <input id="kosten_jahr">
<label>Providername</label> <input id="providername">
<label>IPv6 Netz</label> <input id="ipv6_net">
<label>Bestelldatum</label> <input id="bestelldatum">
<label>Kündbar ab</label> <input id="kuendbar_ab">
<label>Kündigungsdatum</label> <input id="kuendigungsdatum">
<label>Status</label> <select id="status">
<option value="aktiv">aktiv</option>
<option value="gekündigt">gekündigt</option>
</select>
<label>Bemerkung</label>
<textarea id="bemerkung"></textarea>
<br><br>
<button onclick="saveResource()">Speichern</button>
<button onclick="closeModal()">Abbrechen</button>
</div>
<div id="ipModal" class="modal">
<h3>IP Verwaltung</h3>
<input type="hidden" id="ip_resource_id">
<div id="ipList"></div>
<hr>
<input id="new_ip" placeholder="IP">
<input id="new_type" placeholder="type">
<input id="new_comment" placeholder="comment">
<button onclick="saveIP()">Add</button>
<br><br>
<button onclick="closeIPModal()">Close</button>
</div>
<div id="domainModal" class="modal">
<h3 id="domainModalTitle">Domain</h3>
<input type="hidden" id="domain_id">
<label>Domain</label> <input id="domain_name">
<label>Provider</label> <input id="domain_provider">
<label>IP Adresse</label> <input id="domain_ip">
<label>Jährliche Kosten</label> <input id="domain_cost">
<label>Notizen</label>
<textarea id="domain_notes"></textarea>
<br><br>
<button onclick="saveDomain()">Save</button> <button onclick="closeDomainModal()">Cancel</button>
</div>
<div id="serverDetailModal" class="modal">
<h3>Server Details</h3>
<div id="serverDetailContent"></div>
<br>
<button onclick="closeServerDetail()">Schließen</button>
</div>
<script>
const API="/resman/api"
async function loadResources(){
const res=await fetch(API+"/resources/active")
const data=await res.json()
const mapRes=await fetch(API+"/domainmap")
const mappings=await mapRes.json()
const table=document.getElementById("resources")
table.innerHTML=""
data.forEach(r=>{
let ips=""
if(Array.isArray(r.ips)){
ips=r.ips.map(ip=>`
<span class="ip">${ip.type || ""} ${ip.ip}</span>
`).join("")
}
let domains=mappings
.filter(m=>m.resource_id==r.id)
.map(m=>`<span class="ip">🌐 ${m.domain_name}</span>`)
.join("")
const tr=document.createElement("tr")
tr.innerHTML=`
<td>
<span style="cursor:pointer;color:#1e3a8a;font-weight:bold"
onclick='openServerDetail(${JSON.stringify(r)})'>
${r.name}
</span>
</td>
<td>${r.produkt||""}</td>
<td><span class="provider">${r.provider || ""}</span></td>
<td id="status-${r.id}">...</td>
<td>
<div class="system">
${r.cpu ? r.cpu + " CPU" : ""}
${r.ram ? " • " + r.ram + " RAM" : ""}
${r.disk ? " • " + r.disk : ""}
${r.os ? " • " + r.os : ""}
</div>
</td>
<td>${domains}</td>
<td>
${ips}
<br>
<button onclick="openIPManager(${r.id})">IPs Verwalten</button>
</td>
<td>
<button onclick='openEdit(${JSON.stringify(r)})'>Edit</button>
<button onclick="deleteResource(${r.id})">Delete</button>
</td>
`
table.appendChild(tr)
checkServerStatus(r)
})
}
async function loadCancelled(){
const res=await fetch(API+"/resources/cancelled")
const data=await res.json()
const table=document.getElementById("cancelled")
table.innerHTML=""
data.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 openIPManager(resourceId){
document.getElementById("ip_resource_id").value=resourceId
document.getElementById("ipModal").style.display="block"
loadIPs(resourceId)
}
function closeIPModal(){
document.getElementById("ipModal").style.display="none"
}
async function loadIPs(resourceId){
const res=await fetch(`/resman/api/resources/${resourceId}/ips`)
const ips=await res.json()
const container=document.getElementById("ipList")
container.innerHTML=""
ips.forEach(ip=>{
const div=document.createElement("div")
div.innerHTML=`
${ip.ip} (${ip.type||""}) ${ip.comment||""}
<button onclick="deleteIP(${ip.id},${resourceId})">Delete</button>
`
container.appendChild(div)
})
}
async function saveIP(){
const resourceId=document.getElementById("ip_resource_id").value
const ip=document.getElementById("new_ip").value
const type=document.getElementById("new_type").value
const comment=document.getElementById("new_comment").value
const check = await fetch(API+"/ipcheck/"+ip)
const result = await check.json()
if(result.length){
if(!confirm("IP existiert bereits. Trotzdem speichern?")){
return
}
}
await fetch(`/resman/api/resources/${resourceId}/ips`,{
method:"POST",
headers:{'Content-Type':'application/json'},
body:JSON.stringify({ip,type,comment})
})
loadIPs(resourceId)
loadResources()
}
async function deleteIP(id,res){
await fetch(`/resman/api/ips/${id}`,{method:"DELETE"})
loadIPs(res)
loadResources()
}
async function deleteResource(id){
if(!confirm("delete resource?")) return
await fetch(API+"/resources/"+id,{method:"DELETE"})
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("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 saveResource(){
const id=document.getElementById("resource_id").value
const data={
name:document.getElementById("name").value,
produkt:document.getElementById("produkt").value,
provider:document.getElementById("provider").value,
art:document.getElementById("art").value,
cpu:document.getElementById("cpu").value,
ram:document.getElementById("ram").value,
disk:document.getElementById("disk").value,
os:document.getElementById("os").value,
kosten_monat:document.getElementById("kosten_monat").value,
kosten_jahr:document.getElementById("kosten_jahr").value,
providername:document.getElementById("providername").value,
ipv6_net:document.getElementById("ipv6_net").value,
bestelldatum:document.getElementById("bestelldatum").value,
kuendbar_ab:document.getElementById("kuendbar_ab").value,
kuendigungsdatum:document.getElementById("kuendigungsdatum").value,
status:document.getElementById("status").value,
bemerkung:document.getElementById("bemerkung").value
}
if(id){
await fetch(API+"/resources/"+id,{
method:"PUT",
headers:{'Content-Type':'application/json'},
body:JSON.stringify(data)
})
}else{
await fetch(API+"/resources",{
method:"POST",
headers:{'Content-Type':'application/json'},
body:JSON.stringify(data)
})
}
closeModal()
loadResources()
loadCancelled()
loadCosts()
loadInfrastructure()
}
async function loadDomains(){
const res = await fetch(API+"/domains")
const data = await res.json()
const table = document.getElementById("domains")
table.innerHTML=""
data.forEach(async d=>{
const tr = document.createElement("tr")
tr.innerHTML=`
<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>
`
table.appendChild(tr)
/* DNS Check */
try{
const dnsRes = await fetch(API+"/dns/"+d.domain_name)
const result = await dnsRes.json()
let status="❌"
if(result.ips && result.ips.length){
let 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
/* automatisch Server erkennen */
const mapRes = await fetch(API+"/domainmap")
const mappings = await mapRes.json()
const server = mappings.find(m=>m.ip_address==result.ips[0])
if(server){
document.getElementById("server-"+d.id).innerHTML=server.server_name
}
}
}catch(e){
document.getElementById("dns-"+d.id).innerHTML="❌"
}
})
}
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
const data={
domain_name:domain_name.value,
provider:domain_provider.value,
ip_address:domain_ip.value,
yearly_cost:domain_cost.value,
notes:domain_notes.value
}
if(id){
await fetch(API+"/domains/"+id,{
method:"PUT",
headers:{'Content-Type':'application/json'},
body:JSON.stringify(data)
})
}else{
await fetch(API+"/domains",{
method:"POST",
headers:{'Content-Type':'application/json'},
body:JSON.stringify(data)
})
}
closeDomainModal()
loadDomains()
loadMapping()
}
async function deleteDomain(id){
await fetch(API+"/domains/"+id,{method:"DELETE"})
loadDomains()
loadMapping()
}
async function loadMapping(){
const res=await fetch(API+"/domainmap")
const data=await res.json()
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)
})
}
async function loadCosts(){
const res=await fetch(API+"/resources/active")
const resources=await res.json()
const domRes=await fetch(API+"/domains")
const domains=await domRes.json()
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 res=await fetch(API+"/resources/active")
const resources=await res.json()
const mapRes=await fetch(API+"/domainmap")
const mappings=await mapRes.json()
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
}
async function openServerDetail(resource){
const mapRes = await fetch(API+"/domainmap")
const mappings = await mapRes.json()
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 || ""}
`
document.getElementById("serverDetailContent").innerHTML = html
document.getElementById("serverDetailModal").style.display="block"
}
function closeServerDetail(){
document.getElementById("serverDetailModal").style.display="none"
}
async function checkServerStatus(resource){
if(!Array.isArray(resource.ips)) return
const ip = resource.ips.find(i=>i.type==="public")
if(!ip) return
const res = await fetch(API+"/ping/"+ip.ip)
const data = await res.json()
let icon="🔴"
if(data.status==="online"){
icon="🟢"
}
document.getElementById("status-"+resource.id).innerHTML=icon
}
loadResources()
loadCancelled()
loadDomains()
loadMapping()
loadCosts()
loadInfrastructure()
</script>
</body>
</html>