464 lines
5.6 KiB
HTML
464 lines
5.6 KiB
HTML
<!DOCTYPE html>
|
|
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>ResMan</title>
|
|
|
|
<style>
|
|
body{font-family:Arial;margin:40px;background:#f2f2f2}
|
|
h1,h2{margin-top:30px}
|
|
|
|
table{
|
|
border-collapse:collapse;
|
|
width:100%;
|
|
background:white;
|
|
margin-bottom:20px
|
|
}
|
|
|
|
th,td{
|
|
border:1px solid #ddd;
|
|
padding:8px
|
|
}
|
|
|
|
th{
|
|
background:#333;
|
|
color:white
|
|
}
|
|
|
|
button{
|
|
padding:5px 10px;
|
|
margin-right:4px;
|
|
cursor:pointer
|
|
}
|
|
|
|
input{
|
|
padding:4px
|
|
}
|
|
|
|
.form{
|
|
background:white;
|
|
padding:10px;
|
|
margin-bottom:20px
|
|
}
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
|
|
<h1>ResMan</h1>
|
|
|
|
<h2>Create Resource</h2>
|
|
|
|
<div class="form">
|
|
|
|
<input id="r_name" placeholder="Name">
|
|
<input id="r_provider" placeholder="Provider">
|
|
<input id="r_cpu" placeholder="CPU">
|
|
<input id="r_ram" placeholder="RAM">
|
|
<input id="r_disk" placeholder="Disk">
|
|
|
|
<button onclick="createResource()">Create</button>
|
|
|
|
</div>
|
|
|
|
<h2>Active Resources</h2>
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Name</th>
|
|
<th>Provider</th>
|
|
<th>CPU</th>
|
|
<th>RAM</th>
|
|
<th>Disk</th>
|
|
<th>IPs</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody id="resources"></tbody>
|
|
|
|
</table>
|
|
|
|
<h2>Cancelled Resources</h2>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Name</th>
|
|
<th>Provider</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody id="cancelled"></tbody>
|
|
|
|
</table>
|
|
|
|
<h2>Domains</h2>
|
|
|
|
<div class="form">
|
|
|
|
<input id="d_name" placeholder="Domain">
|
|
<input id="d_provider" placeholder="Provider">
|
|
<input id="d_ip" placeholder="IP">
|
|
<input id="d_cost" placeholder="Yearly €">
|
|
|
|
<button onclick="createDomain()">Create</button>
|
|
|
|
</div>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Domain</th>
|
|
<th>Provider</th>
|
|
<th>IP</th>
|
|
<th>Server</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody id="domains"></tbody>
|
|
|
|
</table>
|
|
|
|
<h2>Domain → Server Mapping</h2>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>Domain</th>
|
|
<th>IP</th>
|
|
<th>Server</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody id="mapping"></tbody>
|
|
|
|
</table>
|
|
|
|
<script>
|
|
|
|
const API="/resman/api"
|
|
|
|
|
|
|
|
/* LOAD RESOURCES */
|
|
|
|
async function loadResources(){
|
|
|
|
const res=await fetch(API+"/resources/active")
|
|
const data=await res.json()
|
|
|
|
const table=document.getElementById("resources")
|
|
table.innerHTML=""
|
|
|
|
data.forEach(r=>{
|
|
|
|
const ips=r.ips.map(ip=>ip.ip).join("<br>")
|
|
|
|
const tr=document.createElement("tr")
|
|
|
|
tr.innerHTML=`
|
|
|
|
<td>${r.id}</td>
|
|
<td>${r.name}</td>
|
|
<td>${r.provider||""}</td>
|
|
<td>${r.cpu||""}</td>
|
|
<td>${r.ram||""}</td>
|
|
<td>${r.disk||""}</td>
|
|
|
|
<td>
|
|
|
|
${ips}
|
|
|
|
<br>
|
|
|
|
<input id="ip_${r.id}" placeholder="new ip">
|
|
<button onclick="addIP(${r.id})">Add</button>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<button onclick="editResource(${r.id})">Edit</button>
|
|
|
|
<button onclick="deleteResource(${r.id})">Delete</button>
|
|
|
|
</td>
|
|
|
|
`
|
|
|
|
table.appendChild(tr)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CANCELLED */
|
|
|
|
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.id}</td>
|
|
<td>${r.name}</td>
|
|
<td>${r.provider||""}</td>
|
|
`
|
|
|
|
table.appendChild(tr)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CREATE RESOURCE */
|
|
|
|
async function createResource(){
|
|
|
|
const body={
|
|
name:document.getElementById("r_name").value,
|
|
provider:document.getElementById("r_provider").value,
|
|
cpu:document.getElementById("r_cpu").value,
|
|
ram:document.getElementById("r_ram").value,
|
|
disk:document.getElementById("r_disk").value
|
|
}
|
|
|
|
await fetch(API+"/resources",{
|
|
|
|
method:"POST",
|
|
|
|
headers:{'Content-Type':'application/json'},
|
|
|
|
body:JSON.stringify(body)
|
|
|
|
})
|
|
|
|
loadResources()
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DELETE RESOURCE */
|
|
|
|
async function deleteResource(id){
|
|
|
|
if(!confirm("delete resource?")) return
|
|
|
|
await fetch(API+"/resources/"+id,{method:"DELETE"})
|
|
|
|
loadResources()
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EDIT RESOURCE */
|
|
|
|
async function editResource(id){
|
|
|
|
const name=prompt("Name")
|
|
if(!name) return
|
|
|
|
await fetch(API+"/resources/"+id,{
|
|
|
|
method:"PUT",
|
|
|
|
headers:{'Content-Type':'application/json'},
|
|
|
|
body:JSON.stringify({name})
|
|
|
|
})
|
|
|
|
loadResources()
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IP MANAGER */
|
|
|
|
async function addIP(resource_id){
|
|
|
|
const ip=document.getElementById("ip_"+resource_id).value
|
|
|
|
await fetch(API+"/resources/"+resource_id+"/ips",{
|
|
|
|
method:"POST",
|
|
|
|
headers:{'Content-Type':'application/json'},
|
|
|
|
body:JSON.stringify({ip})
|
|
|
|
})
|
|
|
|
loadResources()
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DOMAINS */
|
|
|
|
async function loadDomains(){
|
|
|
|
const res=await fetch(API+"/domains")
|
|
|
|
const data=await res.json()
|
|
|
|
const table=document.getElementById("domains")
|
|
|
|
table.innerHTML=""
|
|
|
|
data.forEach(d=>{
|
|
|
|
const tr=document.createElement("tr")
|
|
|
|
tr.innerHTML=`
|
|
|
|
<td>${d.id}</td>
|
|
|
|
<td>${d.domain_name}</td>
|
|
|
|
<td>${d.provider||""}</td>
|
|
|
|
<td>${d.ip_address||""}</td>
|
|
|
|
<td>${d.resource_name||""}</td>
|
|
|
|
<td>
|
|
|
|
<button onclick="deleteDomain(${d.id})">Delete</button>
|
|
|
|
</td>
|
|
|
|
`
|
|
|
|
table.appendChild(tr)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CREATE DOMAIN */
|
|
|
|
async function createDomain(){
|
|
|
|
const body={
|
|
|
|
domain_name:document.getElementById("d_name").value,
|
|
|
|
provider:document.getElementById("d_provider").value,
|
|
|
|
ip_address:document.getElementById("d_ip").value,
|
|
|
|
yearly_cost:document.getElementById("d_cost").value
|
|
|
|
}
|
|
|
|
await fetch(API+"/domains",{
|
|
|
|
method:"POST",
|
|
|
|
headers:{'Content-Type':'application/json'},
|
|
|
|
body:JSON.stringify(body)
|
|
|
|
})
|
|
|
|
loadDomains()
|
|
|
|
loadMapping()
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DELETE DOMAIN */
|
|
|
|
async function deleteDomain(id){
|
|
|
|
if(!confirm("delete domain?")) return
|
|
|
|
await fetch(API+"/domains/"+id,{method:"DELETE"})
|
|
|
|
loadDomains()
|
|
|
|
loadMapping()
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DOMAIN MAPPING */
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/* INIT */
|
|
|
|
loadResources()
|
|
|
|
loadCancelled()
|
|
|
|
loadDomains()
|
|
|
|
loadMapping()
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|