resman gut bevor DNS gefixt ist

This commit is contained in:
ecki
2026-03-10 14:46:47 +01:00
parent 9d519701a8
commit 1791070dd6
4 changed files with 444 additions and 4 deletions
+11 -2
View File
@@ -89,6 +89,15 @@ exports.create = async (req,res)=>{
const clean = v => v === "" ? null : v;
function decimal(val){
if(!val) return null
return String(val).replace(",", ".")
}
const data = {
name: req.body.name,
produkt: clean(req.body.produkt),
@@ -103,8 +112,8 @@ os: clean(req.body.os),
ipv6_net: clean(req.body.ipv6_net),
providername: clean(req.body.providername),
kosten_monat: clean(req.body.kosten_monat),
kosten_jahr: clean(req.body.kosten_jahr),
kosten_monat: decimal(req.body.kosten_monat),
kosten_jahr: decimal(req.body.kosten_jahr),
laufzeit_monate: clean(req.body.laufzeit_monate),
bestelldatum: clean(req.body.bestelldatum),
+139
View File
@@ -145,5 +145,144 @@ Domains jährlich: <span id="costDomain">0</span> €<br>
<script src="js/api.js"></script>
<script src="js/ui.js"></script>
<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" type="date">
<label>Kündbar ab</label>
<input id="kuendbar_ab" type="date">
<label>Kündigungsdatum</label>
<input id="kuendigungsdatum" type="date">
<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="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" type="number" step="0.01">
<label>Notizen</label>
<textarea id="domain_notes"></textarea>
<br><br>
<button onclick="saveDomain()">Save</button>
<button onclick="closeDomainModal()">Cancel</button>
</div>
</body>
</html>
+291
View File
@@ -43,6 +43,21 @@ async function loadResources(){
<td>
${ips}
<br>
<button onclick="openIPManager(${r.id})">IPs</button>
</td>
<td>
<button onclick='openEdit(${JSON.stringify(r)})'>
Edit
</button>
<button onclick="deleteResource(${r.id})">
Delete
</button>
</td>
</td>
<td>
@@ -87,6 +102,7 @@ async function loadDomains(){
<td>${d.yearly_cost || ""}</td>
<td>
<button onclick='openDomainEdit(${JSON.stringify(d)})'>Edit</button>
<button onclick="deleteDomain(${d.id})">Delete</button>
</td>
`;
@@ -131,6 +147,281 @@ async function loadMapping(){
}
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 ips = await api(API + "/resources/" + resourceId + "/ips")
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
await api("/resman/api/resources/"+resourceId+"/ips",{
method:"POST",
headers:{'Content-Type':'application/json'},
body:JSON.stringify({ip,type,comment})
})
loadIPs(resourceId)
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"
}
async function saveResource(){
const id = document.getElementById("resource_id").value
let kostenMonat=document.getElementById("kosten_monat").value
let kostenJahr=document.getElementById("kosten_jahr").value
if(kostenMonat) kostenMonat=kostenMonat.replace(",",".")
if(kostenJahr) kostenJahr=kostenJahr.replace(",",".")
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:kostenMonat || null,
kosten_jahr:kostenJahr || null,
providername:document.getElementById("providername").value,
ipv6_net:document.getElementById("ipv6_net").value,
bestelldatum:document.getElementById("bestelldatum").value || null,
kuendbar_ab:document.getElementById("kuendbar_ab").value || null,
kuendigungsdatum:document.getElementById("kuendigungsdatum").value || null,
status:document.getElementById("status").value,
bemerkung:document.getElementById("bemerkung").value
}
if(id){
await api(API+"/resources/"+id,{
method:"PUT",
headers:{'Content-Type':'application/json'},
body:JSON.stringify(data)
})
}else{
await api(API+"/resources",{
method:"POST",
headers:{'Content-Type':'application/json'},
body:JSON.stringify(data)
})
}
closeModal()
loadResources()
loadCancelled()
loadCosts()
loadInfrastructure()
}
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)
})
}
loadResources();
+3 -2
View File
@@ -52,13 +52,15 @@ router.get('/:id', async (req, res) => {
// CREATE DOMAIN
router.post('/', async (req, res) => {
try {
const { domain_name, provider, ip_address, yearly_cost, notes } = req.body;
await pool.query(
const [result] = await pool.query(
`INSERT INTO domains
(domain_name, provider, ip_address, yearly_cost, notes)
VALUES (?, ?, ?, ?, ?)`,
@@ -101,7 +103,6 @@ details: err.sqlMessage
});
// UPDATE DOMAIN
router.put('/:id', async (req, res) => {
try {