async function fetchConfig(element) { let xhr = new XMLHttpRequest(); xhr.open("GET", '/-/config', true); xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { element.innerHTML = JSON.stringify(JSON.parse(xhr.response),null,2); } }; xhr.send(); } async function fetchOriginsWithLeases(element) { let xhr = new XMLHttpRequest(); xhr.open("GET", '/-/origins?leases=true', true); xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { const x = JSON.parse(xhr.response) console.debug(x) element.innerHTML = '' let table = document.createElement('table') table.classList.add('table', 'mt-4'); let thead = document.createElement('thead'); thead.innerHTML = ` origin hostname OS driver version leases ` table.appendChild(thead) let tbody = document.createElement('thead'); x.sort((a, b) => a.hostname.localeCompare(b.hostname)).forEach((o) => { let row = document.createElement('tr'); row.innerHTML = ` ${o.origin_ref} ${o.hostname} ${o.os_platform} (${o.os_version}) ${o.guest_driver_version} ${o.leases.map(x => `${x.lease_ref}`).join(', ')}` tbody.appendChild(row); }) table.appendChild(tbody) element.appendChild(table) } }; xhr.send(); } async function fetchLeases(element) { // datetime config const dtc = { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", timeZoneName: "short" } let xhr = new XMLHttpRequest(); xhr.open("GET", '/-/leases?origin=true', true); xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { const x = JSON.parse(xhr.response) console.debug(x) element.innerHTML = '' let table = document.createElement('table') table.classList.add('table', 'mt-4'); let thead = document.createElement('thead'); thead.innerHTML = ` lease created updated next renew expires origin ` table.appendChild(thead) let tbody = document.createElement('thead'); x.sort((a, b) => new Date(a.lease_expires) - new Date(b.lease_expires)).forEach((o) => { let row = document.createElement('tr'); row.innerHTML = ` ${o.lease_ref} ${new Date(o.lease_created).toLocaleDateString('system', dtc)} ${new Date(o.lease_updated).toLocaleDateString('system', dtc)} ${new Date(o.lease_renewal).toLocaleDateString('system', dtc)} ${new Date(o.lease_expires).toLocaleDateString('system', dtc)} ${o.origin_ref}` tbody.appendChild(row); }) table.appendChild(tbody) element.appendChild(table) } }; xhr.send(); } async function deleteOrigins() { let xhr = new XMLHttpRequest(); xhr.open("DELETE", '/-/origins', true); xhr.send(); } async function deleteOrigin(origin_ref) { if (origin_ref === undefined) origin_ref = window.prompt("Please enter 'origin_ref' which should be deleted"); if (origin_ref === null || origin_ref === "") return let xhr = new XMLHttpRequest(); xhr.open("DELETE", `/-/origins/${origin_ref}`, true); xhr.send(); } async function deleteLease(lease_ref) { if (lease_ref === undefined) lease_ref = window.prompt("Please enter 'lease_ref' which should be deleted"); if (lease_ref === null || lease_ref === "") return let xhr = new XMLHttpRequest(); xhr.open("DELETE", `/-/lease/${{lease_ref}}`, true); xhr.send(); }