commit 17/10/2025 Add few logs

This commit is contained in:
2025-10-17 17:15:00 +07:00
parent 4d02ab6d07
commit 17b4485e69
17 changed files with 392 additions and 205 deletions

View File

@@ -16,6 +16,8 @@ import oshi.SystemInfo
import oshi.hardware.CentralProcessor
import oshi.hardware.GlobalMemory
import oshi.hardware.NetworkIF
import oshi.hardware.Sensors
import oshi.software.os.OperatingSystem
import java.nio.file.Files
import java.nio.file.Path
import java.time.LocalDateTime
@@ -37,6 +39,8 @@ class Somecodes {
val processor: CentralProcessor = si.hardware.processor
val memory : GlobalMemory = si.hardware.memory
val NetworkInfoMap = mutableMapOf<String, NetworkInformation>()
val sensor : Sensors = si.hardware.sensors
val os : OperatingSystem = si.operatingSystem
val datetimeformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss")
val dateformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy")
@@ -492,6 +496,35 @@ class Somecodes {
sb.append(".wav")
return sb.toString()
}
/**
* Get sensors information using OSHI library.
* @return A string representing the CPU temperature, fan speeds, and CPU voltage, or an empty string if not available.
*/
fun GetSensorsInfo() : String {
val cputemp = sensor.cpuTemperature
val cpuvolt = sensor.cpuVoltage
val fanspeed = sensor.fanSpeeds
return if (cpuvolt>0 && cputemp > 0 && fanspeed.isNotEmpty()){
String.format("CPU Temp: %.1f °C\nFan Speeds: %s RPM\nCPU Voltage: %.2f V",
sensor.cpuTemperature,
sensor.fanSpeeds.joinToString("/"),
sensor.cpuVoltage
)
} else ""
}
fun GetUptime() : String {
val value = os.systemUptime
return if (value>0){
// number of seconds since system boot
val hours = value / 3600
val minutes = (value % 3600) / 60
val seconds = value % 60
String.format("%02d:%02d:%02d", hours, minutes, seconds)
} else ""
}
}

View File

@@ -670,7 +670,7 @@ class MariaDB(
val statement = connection.createStatement()
val resultSet = statement?.executeQuery("SELECT * FROM ${super.dbName}")
val workbook = XSSFWorkbook()
val sheet = workbook.createSheet("LanguageLink")
val sheet = workbook.createSheet("languagelinking")
val headerRow = sheet.createRow(0)
val headers = arrayOf("Index", "TAG", "Language")
for ((colIndex, header) in headers.withIndex()) {

View File

@@ -2,6 +2,8 @@ package web
import StreamerOutputs
import codes.Somecodes
import codes.Somecodes.Companion.GetSensorsInfo
import codes.Somecodes.Companion.GetUptime
import codes.Somecodes.Companion.ListAudioFiles
import codes.Somecodes.Companion.ValiDateForLogHtml
import codes.Somecodes.Companion.ValidFile
@@ -24,7 +26,6 @@ import database.ScheduleBank
import database.SoundChannel
import database.Soundbank
import database.UserDB
//>>>>>>>>> Temporary merge branch 2
import db
import io.javalin.Javalin
import io.javalin.apibuilder.ApiBuilder.before
@@ -41,7 +42,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook
import java.nio.file.Files
import java.time.LocalDateTime
@Suppress("unused")
class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
@@ -91,7 +91,6 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
it.sessionAttribute("user", user.first)
//println("User ${user.first} logged in")
// Redirect to home page
//db.Add_Log("WEB", "User ${user.first} logged in")
it.redirect("home.html")
}
}
@@ -107,16 +106,23 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
objectmapper.readValue(wsMessageContext.message(), WebsocketCommand::class.java)
when (cmd.command) {
"getSystemTime" -> {
val systemtime = LocalDateTime.now().format(Somecodes.datetimeformat1)
val uptime = GetUptime()
SendReply(
wsMessageContext,
cmd.command,
LocalDateTime.now().format(Somecodes.datetimeformat1)
if (uptime.isNotEmpty()) "Date & Time : $systemtime\nSystem Uptime : $uptime" else "Date & Time : $systemtime"
)
}
"getCPUStatus" -> {
Somecodes.getCPUUsage { vv ->
SendReply(wsMessageContext, cmd.command, vv)
val sv = GetSensorsInfo()
if (sv.isNotEmpty()){
SendReply(wsMessageContext, cmd.command, vv+"\n"+sv)
} else {
SendReply(wsMessageContext, cmd.command, vv)
}
}
}
@@ -437,8 +443,15 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
// get messagebank list
it.result(MariaDB.ArrayListtoString(db.messageDB.List))
}
post("Add"){
val json : JsonNode = objectmapper.readTree(it.body())
get("MessageIDs") { ctx ->
val value = db.messageDB.List
.distinctBy { it.ANN_ID }
.sortedBy { it.ANN_ID }
.map { KeyValueMessage(it.ANN_ID.toString(), it.Description) }
ctx.result(objectmapper.writeValueAsString(value))
}
post("Add") {
val json: JsonNode = objectmapper.readTree(it.body())
val description = json.get("Description")?.asText("") ?: ""
val language = json.get("Language")?.asText("") ?: ""
val ann_id = json.get("ANN_ID")?.asInt()?.toUInt() ?: 0u
@@ -750,8 +763,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
if (ValidString(description)){
if (ValidString(day) && ValidScheduleDay(day)){
if (ValidString(time) && ValidScheduleTime(time)){
//soundpath is a messagebank desc and aan_id
if (ValidString(soundpath)) {
if (ValidString(soundpath) && ValidFile(soundpath)){
if (repeat in 0u..127u){
if (ValidString(broadcast_zones)){
val zones = broadcast_zones.split(";")