commit 20/08/2025

This commit is contained in:
2025-08-20 16:42:06 +07:00
parent 4f0a7a1560
commit 0c84449b77
28 changed files with 966 additions and 42 deletions

View File

@@ -1,7 +1,10 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ClassName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="ConstPropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="EnumEntryName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="FunctionName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="MethodNameSameAsClassName" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />

View File

@@ -0,0 +1,12 @@
<component name="libraryTable">
<library name="fasterxml.jackson.core.databind" type="repository">
<properties maven-id="com.fasterxml.jackson.core:jackson-databind:2.17.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.17.2/jackson-databind-2.17.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.17.2/jackson-annotations-2.17.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.17.2/jackson-core-2.17.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@@ -0,0 +1,17 @@
<component name="libraryTable">
<library name="fasterxml.jackson.module.kotlin" type="repository">
<properties maven-id="com.fasterxml.jackson.module:jackson-module-kotlin:2.17.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/module/jackson-module-kotlin/2.17.2/jackson-module-kotlin-2.17.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.17.2/jackson-databind-2.17.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.17.2/jackson-core-2.17.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.17.2/jackson-annotations-2.17.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-reflect/1.7.22/kotlin-reflect-1.7.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.7.22/kotlin-stdlib-1.7.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.7.22/kotlin-stdlib-common-1.7.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

13
.idea/libraries/github_oshi_core.xml generated Normal file
View File

@@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="github.oshi.core" type="repository">
<properties maven-id="com.github.oshi:oshi-core:6.6.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/github/oshi/oshi-core/6.6.2/oshi-core-6.6.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/net/java/dev/jna/jna/5.14.0/jna-5.14.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/net/java/dev/jna/jna-platform/5.14.0/jna-platform-5.14.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/2.0.13/slf4j-api-2.0.13.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

11
.idea/libraries/google_code_gson.xml generated Normal file
View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="google.code.gson" type="repository">
<properties maven-id="com.google.code.gson:gson:2.13.1" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.13.1/gson-2.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.38.0/error_prone_annotations-2.38.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@@ -1,37 +1,28 @@
<component name="libraryTable">
<library name="io.javalin" type="repository">
<properties maven-id="io.javalin:javalin:5.4.2" />
<properties maven-id="io.javalin:javalin:LATEST" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/io/javalin/javalin/5.4.2/javalin-5.4.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/2.0.6/slf4j-api-2.0.6.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-server/11.0.14/jetty-server-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/javalin/javalin/6.7.0/javalin-6.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/2.0.17/slf4j-api-2.0.17.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-server/11.0.25/jetty-server-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-http/11.0.25/jetty-http-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-util/11.0.25/jetty-util-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-io/11.0.25/jetty-io-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/toolchain/jetty-jakarta-servlet-api/5.0.2/jetty-jakarta-servlet-api-5.0.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-http/11.0.14/jetty-http-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-util/11.0.14/jetty-util-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-io/11.0.14/jetty-io-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-webapp/11.0.14/jetty-webapp-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-servlet/11.0.14/jetty-servlet-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-security/11.0.14/jetty-security-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-xml/11.0.14/jetty-xml-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-jetty-server/11.0.14/websocket-jetty-server-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-jetty-common/11.0.14/websocket-jetty-common-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-core-common/11.0.14/websocket-core-common-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-servlet/11.0.14/websocket-servlet-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-core-server/11.0.14/websocket-core-server-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-annotations/11.0.14/jetty-annotations-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-plus/11.0.14/jetty-plus-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/jakarta/transaction/jakarta.transaction-api/2.0.0/jakarta.transaction-api-2.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-jndi/11.0.14/jetty-jndi-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/jakarta/annotation/jakarta.annotation-api/2.1.1/jakarta.annotation-api-2.1.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/9.4/asm-9.4.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm-commons/9.4/asm-commons-9.4.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm-tree/9.4/asm-tree-9.4.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-jetty-api/11.0.14/websocket-jetty-api-11.0.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.7.10/kotlin-stdlib-jdk8-1.7.10.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.7.10/kotlin-stdlib-1.7.10.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.7.10/kotlin-stdlib-common-1.7.10.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-jetty-server/11.0.25/websocket-jetty-server-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-servlet/11.0.25/jetty-servlet-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-security/11.0.25/jetty-security-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-webapp/11.0.25/jetty-webapp-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/jetty-xml/11.0.25/jetty-xml-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-jetty-api/11.0.25/websocket-jetty-api-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-jetty-common/11.0.25/websocket-jetty-common-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-core-common/11.0.25/websocket-core-common-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-servlet/11.0.25/websocket-servlet-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/jetty/websocket/websocket-core-server/11.0.25/websocket-core-server-11.0.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.9.25/kotlin-stdlib-jdk8-1.9.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.25/kotlin-stdlib-1.9.25.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.7.10/kotlin-stdlib-jdk7-1.7.10.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.9.25/kotlin-stdlib-jdk7-1.9.25.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

11
.idea/libraries/slf4j_simple.xml generated Normal file
View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="slf4j.simple" type="repository">
<properties maven-id="org.slf4j:slf4j-simple:2.0.17" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-simple/2.0.17/slf4j-simple-2.0.17.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/2.0.17/slf4j-api-2.0.17.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

1
.idea/misc.xml generated
View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">

View File

@@ -8,6 +8,7 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/html" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
@@ -17,5 +18,9 @@
<orderEntry type="library" name="io.javalin" level="project" />
<orderEntry type="library" name="mariadb.jdbc.java.client" level="project" />
<orderEntry type="library" name="kotlinx-coroutines-core" level="project" />
<orderEntry type="library" name="slf4j.simple" level="project" />
<orderEntry type="library" name="fasterxml.jackson.module.kotlin" level="project" />
<orderEntry type="library" name="fasterxml.jackson.core.databind" level="project" />
<orderEntry type="library" name="github.oshi.core" level="project" />
</component>
</module>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,57 @@
.bs-icon {
--bs-icon-size: .75rem;
display: flex;
flex-shrink: 0;
justify-content: center;
align-items: center;
font-size: var(--bs-icon-size);
width: calc(var(--bs-icon-size) * 2);
height: calc(var(--bs-icon-size) * 2);
color: var(--bs-primary);
}
.bs-icon-xs {
--bs-icon-size: 1rem;
width: calc(var(--bs-icon-size) * 1.5);
height: calc(var(--bs-icon-size) * 1.5);
}
.bs-icon-sm {
--bs-icon-size: 1rem;
}
.bs-icon-md {
--bs-icon-size: 1.5rem;
}
.bs-icon-lg {
--bs-icon-size: 2rem;
}
.bs-icon-xl {
--bs-icon-size: 2.5rem;
}
.bs-icon.bs-icon-primary {
color: var(--bs-white);
background: var(--bs-primary);
}
.bs-icon.bs-icon-primary-light {
color: var(--bs-primary);
background: rgba(var(--bs-primary-rgb), .2);
}
.bs-icon.bs-icon-semi-white {
color: var(--bs-primary);
background: rgba(255, 255, 255, .5);
}
.bs-icon.bs-icon-rounded {
border-radius: .5rem;
}
.bs-icon.bs-icon-circle {
border-radius: 50%;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,93 @@
$(document).ready(function() {
document.title = "Automatic Announcement System"
const ws = new WebSocket(window.location.pathname + '/ws');
ws.onopen = () => {
console.log('WebSocket connection established');
};
ws.onmessage = (event) => {
let rep = JSON.parse(event.data);
let cmd = rep.reply
let data = rep.data;
if (cmd && cmd.length > 0){
// console.log('Command:', cmd);
// console.log('Data:', data);
switch(cmd){
case "getCPUStatus" :
$('#cpustatus').text("CPU Usage: " + data)
break;
case "getMemoryStatus" :
$('#ramstatus').text("Memory Usage: " + data)
break;
case "getDiskStatus" :
$('#diskstatus').text("Disk Usage: " + data)
break;
case "getNetworkStatus" :
$('#networkstatus').text("Network Usage: " + data)
break;
}
}
};
ws.onclose = () => {
console.log('WebSocket connection closed');
};
// ws.onerror = (error) => {
// console.error('WebSocket error:', error);
// };
/**
* Send a command to the WebSocket server.
* @param {String} command command to send
* @param {String} data data to send
*/
function sendCommand(command, data){
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ command, data }));
} else {
console.error('WebSocket is not open');
}
}
setInterval(()=>{
$('#datetimetext').text(new Date().toLocaleString());
sendCommand("getCPUStatus", "")
sendCommand("getMemoryStatus", "")
sendCommand("getDiskStatus", "")
sendCommand("getNetworkStatus", "")
}, 1000)
let sidemenu = new bootstrap.Offcanvas('#offcanvas-menu');
$('#showmenu').click(()=>{
sidemenu.show();
})
$('#soundbanklink').click(()=>{
sidemenu.hide();
$('#content').load('soundbank.html');
})
$('#messagebanklink').click(()=>{
sidemenu.hide();
$('#content').load('messagebank.html');
})
$('#languagelink').click(()=>{
sidemenu.hide();
$('#content').load('language.html');
})
$('#timerlink').click(()=>{
sidemenu.hide();
$('#content').load('timer.html');
})
$('#loglink').click(()=>{
sidemenu.hide();
$('#content').load('log.html');
})
$('#settinglink').click(()=>{
sidemenu.hide();
$('#content').load('setting.html');
})
$('#logoutlink').click(()=>{
window.location.href = "login.html"
})
});

90
html/webpage/home.html Normal file
View File

@@ -0,0 +1,90 @@
<!DOCTYPE html>
<html data-bs-theme="light" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>AAS_NewGen</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/Login-Form-Basic-icons.css">
</head>
<body>
<h1 style="text-align: center;">Automatic Announcement System</h1>
<div class="offcanvas offcanvas-start bg-body" tabindex="-1" data-bs-backdrop="false" id="offcanvas-menu">
<div class="offcanvas-header"><a class="link-body-emphasis d-flex align-items-center me-md-auto mb-3 mb-md-0 text-decoration-none" href="/"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bootstrap-fill me-3" style="font-size: 25px;">
<path d="M6.375 7.125V4.658h1.78c.973 0 1.542.457 1.542 1.237 0 .802-.604 1.23-1.764 1.23zm0 3.762h1.898c1.184 0 1.81-.48 1.81-1.377 0-.885-.65-1.348-1.886-1.348H6.375v2.725z"></path>
<path d="M4.002 0a4 4 0 0 0-4 4v8a4 4 0 0 0 4 4h8a4 4 0 0 0 4-4V4a4 4 0 0 0-4-4h-8zm1.06 12V3.545h3.399c1.587 0 2.543.809 2.543 2.11 0 .884-.65 1.675-1.483 1.816v.1c1.143.117 1.904.931 1.904 2.033 0 1.488-1.084 2.396-2.888 2.396z"></path>
</svg><span class="fs-4">Galva Technologies</span></a><button class="btn-close" type="button" aria-label="Close" data-bs-dismiss="offcanvas"></button></div>
<div class="offcanvas-body d-flex flex-column justify-content-between pt-0">
<div>
<hr class="mt-0">
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item"><a class="nav-link active link-light" id="homelink" href="#" aria-current="page"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-house-door me-2">
<path d="M8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4.5a.5.5 0 0 0 .5-.5v-4h2v4a.5.5 0 0 0 .5.5H14a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293zM2.5 14V7.707l5.5-5.5 5.5 5.5V14H10v-4a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5v4z"></path>
</svg> Home </a></li>
<li class="nav-item"><a class="nav-link link-body-emphasis" id="soundbanklink" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-soundwave me-2">
<path fill-rule="evenodd" d="M8.5 2a.5.5 0 0 1 .5.5v11a.5.5 0 0 1-1 0v-11a.5.5 0 0 1 .5-.5m-2 2a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5m4 0a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5m-6 1.5A.5.5 0 0 1 5 6v4a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m8 0a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m-10 1A.5.5 0 0 1 3 7v2a.5.5 0 0 1-1 0V7a.5.5 0 0 1 .5-.5m12 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0V7a.5.5 0 0 1 .5-.5"></path>
</svg>&nbsp;Soundbank</a></li>
<li class="nav-item"><a class="nav-link link-body-emphasis" id="messagebanklink" href="#"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 24 24" width="1em" fill="currentColor" class="me-2">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z"></path>
</svg>&nbsp;Messagebank</a></li>
<li class="nav-item"><a class="nav-link link-body-emphasis" id="languagelink" href="#"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 24 24" width="1em" fill="currentColor" class="me-2">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path>
</svg>&nbsp;Language Link</a></li>
<li class="nav-item"><a class="nav-link link-body-emphasis" id="timerlink" href="#"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 24 24" width="1em" fill="currentColor" class="me-2">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"></path>
<path d="M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z"></path>
</svg>&nbsp;Timer</a></li>
<li class="nav-item"><a class="nav-link link-body-emphasis" id="loglink" href="#"><svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="1em" viewBox="0 0 24 24" width="1em" fill="currentColor" class="me-2">
<g>
<rect fill="none" height="24" width="24"></rect>
<path d="M19,7H9C7.9,7,7,7.9,7,9v10c0,1.1,0.9,2,2,2h10c1.1,0,2-0.9,2-2V9C21,7.9,20.1,7,19,7z M19,9v2H9V9H19z M13,15v-2h2v2H13z M15,17v2h-2v-2H15z M11,15H9v-2h2V15z M17,13h2v2h-2V13z M9,17h2v2H9V17z M17,19v-2h2v2H17z M6,17H5c-1.1,0-2-0.9-2-2V5 c0-1.1,0.9-2,2-2h10c1.1,0,2,0.9,2,2v1h-2V5H5v10h1V17z"></path>
</g>
</svg>&nbsp;Log</a></li>
<li class="nav-item"><a class="nav-link link-body-emphasis" id="settinglink" href="#"><svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="1em" viewBox="0 0 24 24" width="1em" fill="currentColor" class="me-2">
<g>
<path d="M0,0h24v24H0V0z" fill="none"></path>
<path d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z"></path>
</g>
</svg>&nbsp;Setting</a></li>
<li class="nav-item"><a class="nav-link link-body-emphasis" id="logoutlink" href="#"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 24 24" width="1em" fill="currentColor" class="me-2">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z"></path>
</svg>&nbsp;Logout</a></li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-1 border border-dark"><button class="btn btn-primary w-100 h-100" id="showmenu" type="button">Open Menu</button></div>
<div class="col border border-dark">
<p class="w-100 h-100" id="cpustatus">CPU Status</p>
</div>
<div class="col border border-dark">
<p class="w-100 h-100" id="ramstatus">RAM Status</p>
</div>
<div class="col border border-dark">
<p class="w-100 h-100" id="diskstatus">Disk Status</p>
</div>
<div class="col border border-dark">
<p class="w-100 h-100" id="networkstatus">Network Status</p>
</div>
<div class="col border border-dark">
<p class="w-100 h-100" id="datetimetext">Date and Time</p>
</div>
</div>
<div class="row w-100">
<div class="col w-100">
<div class="container w-100" id="content"></div>
</div>
</div>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery-3.7.1.min.js"></script>
<script src="assets/js/script.js"></script>
</body>
</html>

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html data-bs-theme="light" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>AAS_NewGen</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/Login-Form-Basic-icons.css">
</head>
<body>
<div class="row">
<div class="col w-100 h-100">
<h1 style="text-align: center;">Language Link</h1>
</div>
</div>
<div class="row">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th class="col-sm-1">No</th>
<th>Description</th>
<th class="col-sm-1">TAG</th>
<th class="col-sm-1">Category</th>
<th class="col-sm-1">Language</th>
<th class="col-sm-1">Type</th>
<th class="col-sm-3">Filename</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 3</td>
<td>Cell 5</td>
<td>Cell 6</td>
<td>Cell 7</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
<td>Cell 3</td>
<td>Cell 3</td>
<td>Cell 5</td>
<td>Cell 6</td>
<td>Cell 7</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col"><button class="btn btn-primary w-100" id="btnClear" type="button">Clear</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnAdd" type="button">Add</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnRemove" type="button">Remove</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnEdit" type="button">Edit</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnExport" type="button">Export</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnImport" type="button">Import</button></div>
</div>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery-3.7.1.min.js"></script>
</body>
</html>

68
html/webpage/log.html Normal file
View File

@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html data-bs-theme="light" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>AAS_NewGen</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/Login-Form-Basic-icons.css">
</head>
<body>
<div class="row">
<div class="col w-100 h-100">
<h1 style="text-align: center;">Operational Log</h1>
</div>
</div>
<div class="row">
<div class="col-6 col-sm-6 col-md-5 col-xxl-5">
<div class="row">
<div class="col-4 col-sm-6 col-md-5 col-lg-4 col-xl-4 col-xxl-3">
<p>Select Log Date</p>
</div>
<div class="col-sm-7 col-md-6 col-lg-5 col-xl-4 col-xxl-4"><input id="logdate" type="date"></div>
</div>
</div>
<div class="col">
<div class="row">
<div class="col col-md-3 col-lg-2">
<p>Search</p>
</div>
<div class="col"><input type="text" id="searchfilter" placeholder="Search Filter"></div>
</div>
</div>
</div>
<div class="row">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th class="col-1 col-md-1">No</th>
<th class="col-2 col-md-2 col-lg-2">Date</th>
<th class="col-2 col-md-2 col-lg-2">Time</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</tbody>
</table>
</div>
</div>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery-3.7.1.min.js"></script>
</body>
</html>

42
html/webpage/login.html Normal file
View File

@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html data-bs-theme="light" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>AAS_NewGen</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/Login-Form-Basic-icons.css">
</head>
<body>
<section class="position-relative py-4 py-xl-5">
<div class="container">
<div class="row mb-5">
<div class="col-md-8 col-xl-6 text-center mx-auto">
<h2>Log in</h2>
</div>
</div>
<div class="row d-flex justify-content-center">
<div class="col-md-6 col-xl-4">
<div class="card mb-5">
<div class="card-body d-flex flex-column align-items-center">
<div class="bs-icon-xl bs-icon-circle bs-icon-primary my-4 bs-icon"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-person">
<path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6m2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0m4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4m-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10c-2.29 0-3.516.68-4.168 1.332-.678.678-.83 1.418-.832 1.664z"></path>
</svg></div>
<form class="text-center" method="post">
<div class="mb-3"><input class="form-control" type="text" name="username" placeholder="Username"></div>
<div class="mb-3"><input class="form-control" type="password" name="password" placeholder="Password"></div>
<div class="mb-3"><button class="btn btn-primary w-100 d-block" type="submit">Login</button></div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery-3.7.1.min.js"></script>
</body>
</html>

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html data-bs-theme="light" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>AAS_NewGen</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/Login-Form-Basic-icons.css">
</head>
<body>
<div class="row">
<div class="col w-100 h-100">
<h1 style="text-align: center;">Message Bank</h1>
</div>
</div>
<div class="row">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th class="col-sm-1">No</th>
<th class="col-sm-2">Description</th>
<th class="col-sm-1">Language</th>
<th class="col-sm-1">ANN ID</th>
<th class="col-sm-1">Type</th>
<th class="col-sm-3">Message Details</th>
<th class="col-sm-3">Message Tags</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 3</td>
<td>Cell 5</td>
<td>Cell 6</td>
<td>Cell 7</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
<td>Cell 3</td>
<td>Cell 3</td>
<td>Cell 5</td>
<td>Cell 6</td>
<td>Cell 7</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col"><button class="btn btn-primary w-100" id="btnClear" type="button">Clear</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnAdd" type="button">Add</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnRemove" type="button">Remove</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnEdit" type="button">Edit</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnExport" type="button">Export</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnImport" type="button">Import</button></div>
</div>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery-3.7.1.min.js"></script>
</body>
</html>

22
html/webpage/setting.html Normal file
View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html data-bs-theme="light" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>AAS_NewGen</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/Login-Form-Basic-icons.css">
</head>
<body>
<div class="row">
<div class="col w-100 h-100">
<h1 style="text-align: center;">Setting</h1>
</div>
</div>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery-3.7.1.min.js"></script>
</body>
</html>

View File

@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html data-bs-theme="light" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>AAS_NewGen</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/Login-Form-Basic-icons.css">
</head>
<body>
<div class="row">
<div class="col w-100 h-100">
<h1 style="text-align: center;">Sound Bank</h1>
</div>
</div>
<div class="row">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th class="col-sm-1">No</th>
<th>Description</th>
<th class="col-sm-1">TAG</th>
<th class="col-sm-1">Category</th>
<th class="col-sm-1">Language</th>
<th class="col-sm-1">Type</th>
<th class="col-sm-3">Filename</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 3</td>
<td>Cell 5</td>
<td>Cell 6</td>
<td>Cell 7</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
<td>Cell 3</td>
<td>Cell 3</td>
<td>Cell 5</td>
<td>Cell 6</td>
<td>Cell 7</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-2">
<p>Search</p>
</div>
<div class="col"><input class="w-100" type="text" id="findsoundbank" placeholder="Search keyword" name="findsoundbank"></div>
</div>
<div class="row">
<div class="col"><button class="btn btn-primary w-100" id="btnClear" type="button">Clear</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnAdd" type="button">Add</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnRemove" type="button">Remove</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnEdit" type="button">Edit</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnExport" type="button">Export</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnImport" type="button">Import</button></div>
</div>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery-3.7.1.min.js"></script>
</body>
</html>

67
html/webpage/timer.html Normal file
View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html data-bs-theme="light" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>AAS_NewGen</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/Login-Form-Basic-icons.css">
</head>
<body>
<div class="row">
<div class="col w-100 h-100">
<h1 style="text-align: center;">Timer</h1>
</div>
</div>
<div class="row">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th class="col-sm-1">No</th>
<th>Description</th>
<th class="col-sm-1">TAG</th>
<th class="col-sm-1">Category</th>
<th class="col-sm-1">Language</th>
<th class="col-sm-1">Type</th>
<th class="col-sm-3">Filename</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 3</td>
<td>Cell 5</td>
<td>Cell 6</td>
<td>Cell 7</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
<td>Cell 3</td>
<td>Cell 3</td>
<td>Cell 5</td>
<td>Cell 6</td>
<td>Cell 7</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col"><button class="btn btn-primary w-100" id="btnClear" type="button">Clear</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnAdd" type="button">Add</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnRemove" type="button">Remove</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnEdit" type="button">Edit</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnExport" type="button">Export</button></div>
<div class="col"><button class="btn btn-primary w-100" id="btnImport" type="button">Import</button></div>
</div>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery-3.7.1.min.js"></script>
</body>
</html>

View File

@@ -1,7 +1,7 @@
import audio.AudioPlayer
import content.ContentCache
import org.tinylog.Logger
import web.WebApp
fun main() {
@@ -9,5 +9,12 @@ fun main() {
val audioPlayer = AudioPlayer(44100) // 44100 Hz sampling rate
audioPlayer.InitAudio(1)
val content = ContentCache()
val web = WebApp(3030,
listOf(
Pair("admin", "password"),
Pair("user", "password")
)
)
web.Start()
}

View File

@@ -1,5 +1,8 @@
package codes
import oshi.SystemInfo
import oshi.hardware.CentralProcessor
import oshi.hardware.GlobalMemory
import java.nio.file.Files
import java.nio.file.Path
@@ -7,6 +10,45 @@ import java.nio.file.Path
@Suppress("unused")
class Somecodes {
companion object {
val si = SystemInfo()
val processor: CentralProcessor = si.hardware.processor
val memory : GlobalMemory = si.hardware.memory
const val KB_threshold = 1024.0
const val MB_threshold = KB_threshold * 1024.0
const val GB_threshold = MB_threshold * 1024.0
const val TB_threshold = GB_threshold * 1024.0
/**
* Converts a size in bytes to a human-readable format.
* @param size Size in bytes.
* @return A string representing the size in a human-readable format.
*/
fun SizetoHuman(size: Long): String {
return when {
size < KB_threshold -> "${size}B"
size < MB_threshold -> String.format("%.2f KB", size / KB_threshold)
size < GB_threshold -> String.format("%.2f MB", size / MB_threshold)
size < TB_threshold -> String.format("%.2f GB", size / GB_threshold)
else -> String.format("%.2f TB", size / TB_threshold)
}
}
fun getMemoryUsage() : String{
val totalMemory = memory.total
val availableMemory = memory.available
val usedMemory = totalMemory - availableMemory
return String.format("Total: %s, Used: %s, Available: %s, Usage: %.2f%%",
SizetoHuman(totalMemory),
SizetoHuman(usedMemory),
SizetoHuman(availableMemory)
, (usedMemory.toDouble() / totalMemory * 100))
}
fun ValidString(value: Any) : Boolean {
return value is String && value.isNotBlank()
}

View File

@@ -1,5 +1,8 @@
package database
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.mariadb.jdbc.Connection
import org.tinylog.Logger
import java.sql.DriverManager
@@ -46,19 +49,17 @@ class MariaDB (
Logger.info("Connected to MariaDB" as Any)
connected = true
val loadthread = Thread {
// Load soundbank and messagebank lists
Reload_Messagebank()
Logger.info { "Messagebank loaded" }
Reload_Soundbank()
Logger.info { "Soundbank loaded" }
runBlocking {
withContext(Dispatchers.IO){
Reload_Messagebank()
Logger.info { "Messagebank loaded" }
Reload_Soundbank()
Logger.info { "Soundbank loaded" }
}
}
loadthread.name = "LoadMariaDBThread"
loadthread.isDaemon = true
loadthread.start()
loadthread.join()
Logger.info { "Loading MariaDB completed" }
Logger.info { "Soundbank count: ${SoundbankList.size}" }
Logger.info { "Messagebank count: ${MessagebankList.size}" }

145
src/web/WebApp.kt Normal file
View File

@@ -0,0 +1,145 @@
package web
import codes.Somecodes
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.javalin.Javalin
import io.javalin.apibuilder.ApiBuilder.before
import io.javalin.apibuilder.ApiBuilder.get
import io.javalin.apibuilder.ApiBuilder.path
import io.javalin.apibuilder.ApiBuilder.post
import io.javalin.apibuilder.ApiBuilder.ws
import io.javalin.http.Context
@Suppress("unused")
class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
var app : Javalin? = null
private val objectmapper = jacksonObjectMapper()
fun Start() {
app = Javalin.create {
config ->
config.useVirtualThreads = true
config.staticFiles.add("/webpage")
config.router.apiBuilder {
path("/"){
get { ctx ->
// Serve the main page
ctx.sessionAttribute("user", null) // Clear user session
ctx.redirect("login.html")
}
}
path("login.html"){
post{ it ->
// get username and password from form
val username = it.formParam("username")
val password = it.formParam("password")
if (username == null || password == null) {
it.status(400).result("Username and password are required")
return@post
}
// Check if user exists in userlist
val user = userlist.find { it.first == username && it.second == password }
if (user == null) {
it.status(401).result("Invalid username or password")
return@post
}
// Set user session
it.sessionAttribute("user", user.first)
println("User ${user.first} logged in")
// Redirect to home page
it.redirect("home.html")
}
}
path("home.html") {
before { CheckUsers(it) }
ws("/ws") { it ->
// WebSocket endpoint for home
it.onClose {
// TODO Handle WebSocket close event
println("WebSocket closed: ${it.session.remoteAddress}")
}
it.onMessage {
try{
val cmd = objectmapper.readValue(it.message(), WebsocketCommand::class.java)
when (cmd.command) {
"getCPUStatus" ->{
//TODO Get CPU status
it.send(objectmapper.writeValueAsString(WebsocketReply(cmd.command,"OK")))
}
"getMemoryStatus" ->{
// TODO Get Memory status
it.send(objectmapper.writeValueAsString(WebsocketReply(cmd.command, Somecodes.getMemoryUsage())))
}
"getDiskStatus" ->{
// TODO Get Disk status
it.send(objectmapper.writeValueAsString(WebsocketReply(cmd.command,"OK")))
}
"getNetworkStatus" ->{
// TODO Get Network status
it.send(objectmapper.writeValueAsString(WebsocketReply(cmd.command,"OK")))
}
else -> {
it.send(objectmapper.writeValueAsString(WebsocketReply("error", "Unknown command: ${cmd.command}")))
}
}
} catch (e: Exception){
println("Error processing WebSocket message: ${e.message}")
}
}
it.onConnect {
// TODO Handle WebSocket connect event
println("WebSocket connected: ${it.session.remoteAddress}")
}
}
}
path("soundbank.html") {
before {CheckUsers(it)}
}
path("messagebank.html") {
before { CheckUsers(it) }
}
path("language.html") {
before { CheckUsers(it) }
}
path("log.html") {
before { CheckUsers(it) }
}
path("setting.html") {
before { CheckUsers(it) }
}
path("timer.html") {
before { CheckUsers(it) }
}
}
}.start(listenPort)
}
fun CheckUsers(ctx: Context){
println("Checking user session at ${ctx.req().requestURI}")
val user = ctx.sessionAttribute<String?>("user")
if (user == null) {
println("User not logged in, redirecting to login page")
ctx.redirect("login.html")
}
println("User is logged in: $user")
val foundUser = userlist.find { it.first == user }
if (foundUser==null) {
println("User not found in user list, redirecting to login page")
ctx.redirect("login.html")
} else {
println("User found: $user")
}
}
fun Stop(){
app?.stop()
}
}

View File

@@ -0,0 +1,4 @@
package web
@Suppress("unused")
data class WebsocketCommand (val command: String, val data: String)

View File

@@ -0,0 +1,4 @@
package web
@Suppress("unused")
data class WebsocketReply (val reply: String, val data: String)