this codebase is kindof a mess now

This commit is contained in:
Enstrayed
2025-05-26 01:26:35 -07:00
parent 1c3427e63f
commit 0ef0b82765
7 changed files with 143 additions and 32 deletions

View File

@@ -43,14 +43,14 @@ app.get("/api/auth/logout", (rreq,rres) => {
if (dbRes.count > 0) { if (dbRes.count > 0) {
rres.send("Success") rres.send("Success")
} else { } else {
rres.status(400).send("Error: Token does not exist.") rres.status(400).send("Token does not exist.")
} }
}).catch(dbErr => { }).catch(dbErr => {
logRequest(rres,rreq,500,dbErr) logRequest(rres,rreq,500,dbErr)
rres.status(500).send("Error: Exception occured while invalidating token, details: "+dbErr) rres.status(500).send("Exception occured while invalidating token, details: "+dbErr)
}) })
} else { } else {
rres.status(400).send("Error: Missing token or authorization header, you may not be logged in.") rres.status(400).send("Missing token or authorization header, you may not be logged in.")
} }
}) })

View File

@@ -8,4 +8,12 @@ app.get("/helpdesk/articles/*", (rreq, rres) => {
rres.sendFile(process.cwd()+"/website/helpdesk/kbas/"+rreq.url.replace("/helpdesk/articles/","")) rres.sendFile(process.cwd()+"/website/helpdesk/kbas/"+rreq.url.replace("/helpdesk/articles/",""))
}) })
app.get("/helpdesk/ticket/new", (rreq,rres) => {
rres.sendFile(process.cwd()+"/website/helpdesk/templates/newticket.html")
})
app.get("/api/helpdesk/forms/*", (rreq, rres) => {
rres.sendFile(process.cwd()+"/website/helpdesk/forms/"+rreq.url.replace("/api/helpdesk/forms/",""))
})
export { app } export { app }

View File

@@ -0,0 +1,10 @@
{
"general_inquiry": "General Inquiry",
"legalrequest": "Legal Request",
"responsibledisclosure": "Responsible Disclosure",
"general_techsupport": "General Technical Support",
"ecls_deleteaccount": "ECLS: Delete Account",
"ecls_passwordreset": "ECLS: Password Reset",
"ecls_personalinfochange": "ECLS: Personal Information Change",
"enstrayedcloud_quotachange": "Enstrayed Cloud: Quota Change"
}

View File

@@ -4,30 +4,8 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enstrayed Helpdesk</title> <title>Enstrayed Helpdesk</title>
<link rel="stylesheet" href="/static/helpdesk.css"> <link rel="stylesheet" href="/static/helpdesk/helpdesk.css">
<script> <script src="/static/helpdesk/login.js"></script>
var globalLoggedIn = false
document.addEventListener("DOMContentLoaded", function() {
fetch(`/api/auth/whoami`).then(fetchRes => {
fetchRes.json().then(jsonRes => {
if (jsonRes.loggedIn) {
globalLoggedIn = true
document.getElementById("loginButton").innerText = `Logout ${jsonRes.username}`
} else {
globalLoggedIn = false
document.getElementById("loginButton").innerText = `Login`
}
})
})
})
function loginFunction() {
if (globalLoggedIn === true) {
}
}
</script>
</head> </head>
<body> <body>
@@ -88,9 +66,9 @@
</div> </div>
</div> </div>
<dialog id="globalDialog"> <dialog id="globalDialog">
<h2>Warning</h2> <h2 id="globalDialogHeader">Warning</h2>
<p>This is a warning</p> <p id="globalDialogText">This is a warning</p>
<button>woag</button> <button onclick="document.getElementById('globalDialog').close()">Dismiss</button>
</dialog> </dialog>
</body> </body>
</html> </html>

View File

@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enstrayed Helpdesk: New Ticket</title>
<link rel="stylesheet" href="/static/helpdesk/helpdesk.css">
<script src="/static/helpdesk/login.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('formSelection').value = 'none'
document.getElementById('formSelection').addEventListener('change', function() {
useGlobalDialog(`Info`, `You selected ${this.value}`)
})
fetch(`/api/helpdesk/forms/manifest.json`).then(fetchRes => {
fetchRes.json().then(jsonRes => {
for (let x in jsonRes) {
let newElement = document.createElement('option')
newElement.value = x
newElement.textContent = jsonRes[x]
document.getElementById('formSelection').appendChild(newElement)
}
})
})
})
</script>
</head>
<body>
<div class="headerbar">
<h1>Enstrayed Helpdesk</h1>
<a href="/helpdesk">Main Page</a>
<a href="/helpdesk/articles">Knowledgebase</a>
<div class="headerbarright">
<button id="loginButton" onclick="loginFunction()">Login</button>
</div>
</div>
<div class="maincontent">
<div class="newticketmaincontent">
<h2>New Ticket</h2>
<label for="formSelection">Please select a form: </label>
<select name="Form Selection" id="formSelection">
<option value="none" disabled selected>-- Choose From List --</option>
</select>
<hr>
</div>
</div>
<dialog id="globalDialog">
<h2 id="globalDialogHeader">Warning</h2>
<p id="globalDialogText">This is a warning</p>
<button onclick="document.getElementById('globalDialog').close()">Dismiss</button>
</dialog>
</body>
</html>

View File

@@ -37,11 +37,16 @@ body {
gap: 2em; gap: 2em;
} }
.cardrow > div { .cardrow > div, .newticketmaincontent {
background-color: #fff; background-color: #fff;
padding: 2em; padding: 2em;
} }
.newticketmaincontent {
min-width: 80ch;
max-width: 80ch;
}
.cardrow > div > h1 { .cardrow > div > h1 {
margin: 0 0 0.5em 0; margin: 0 0 0.5em 0;
} }
@@ -65,7 +70,7 @@ dialog {
border: none; border: none;
} }
dialog > h2 { dialog > h2, .newticketmaincontent > h2 {
margin: 0 0 0.5em 0; margin: 0 0 0.5em 0;
} }

View File

@@ -0,0 +1,54 @@
var globalLoggedIn = false
function useGlobalDialog(title,body) {
document.getElementById("globalDialogHeader").innerText = title
document.getElementById("globalDialogText").innerText = body
document.getElementById("globalDialog").showModal()
}
document.addEventListener("DOMContentLoaded", function () {
fetch(`/api/auth/whoami`).then(fetchRes => {
fetchRes.json().then(jsonRes => {
if (jsonRes.loggedIn) {
globalLoggedIn = true
document.getElementById("loginButton").innerText = `Logout ${jsonRes.username}`
} else {
globalLoggedIn = false
document.getElementById("loginButton").innerText = `Login`
}
})
})
})
function loginFunction() {
if (globalLoggedIn === true) {
fetch(`/api/auth/logout`).then(fetchRes => {
if (fetchRes.status === 200) {
globalLoggedIn = false
document.getElementById("loginButton").innerText = `Login`
} else {
fetchRes.text().then(textRes => {
useGlobalDialog("Error", `An error occurred during logout: ${textRes}`)
})
}
})
} else {
let loginWindow = window.open(`/api/auth/login?state=close`, `_blank`)
let loginWatcher = setInterval(() => {
if (loginWindow.closed) {
fetch(`/api/auth/whoami`).then(fetchRes => {
fetchRes.json().then(jsonRes => {
if (jsonRes.loggedIn) {
globalLoggedIn = true
document.getElementById("loginButton").innerText = `Logout ${jsonRes.username}`
} else {
useGlobalDialog("Error", `You are not logged in. Please try logging in again.`)
}
clearInterval(loginWatcher);
})
})
}
}, 500);
}
}