diff --git a/.gitignore b/.gitignore index d9b9fde..60e45c6 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,14 @@ bin/ PagingResult/ SoundBank/ SoundbankResult/ -logs/ \ No newline at end of file +logs/ +ARABIC/ +CHINESE/ +ENGLISH/ +INDONESIA/ +JAPANESE/ +LOCAL/ +chimedown.wav +chimeup.wav +silence1s.wav +silencehalf.wav \ No newline at end of file diff --git a/config.properties b/config.properties new file mode 100644 index 0000000..61631d0 --- /dev/null +++ b/config.properties @@ -0,0 +1,12 @@ +#Configuration file +#Tue Oct 21 17:17:50 WIB 2025 +database.host=localhost +database.name=aas +database.password=admin +database.port=3306 +database.user=admin +remark.FLD= +remark.GBD= +remark.GFC= +remark.GOP= +soundbank.directory=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\AAS_NewGen\\soundbank diff --git a/html/webpage/assets/js/schedulebank.js b/html/webpage/assets/js/schedulebank.js index 8cf9863..c368a8c 100644 --- a/html/webpage/assets/js/schedulebank.js +++ b/html/webpage/assets/js/schedulebank.js @@ -61,6 +61,42 @@ function fill_schedulebanktablebody(vv) { $('#tablesize').text("Table Size: " + vv.length); } +/** + * Convert input date string yyyy-mm-dd to dd/mm/yyyy + * @param {String} value from input date, which is in format yyyy-mm-dd + * @returns {String} converted date in format dd/mm/yyyy + */ +function Convert_input_date_to_string(value){ + if (value && value.length>0 && value.includes('-')){ + let parts = value.split('-'); + if (parts.length === 3) { + let year = parts[0]; + let month = parts[1]; + let day = parts[2]; + return `${day}/${month}/${year}`; + } + } + return ""; +} + +/** + * Convert string date dd/mm/yyyy to input date yyyy-mm-dd + * @param {String} value string date in format dd/mm/yyyy + * @returns {String} converted date in format yyyy-mm-dd + */ +function Convert_string_to_input_date(value){ + if (value && value.length>0 && value.includes('/')){ + let parts = value.split('/'); + if (parts.length === 3) { + let day = parts[0]; + let month = parts[1]; + let year = parts[2]; + return `${year}-${month}-${day}`; + } + } + return ""; +} + /** * Reload timer bank from server * @param {string} APIURL API URL endpoint, default "ScheduleBank/" @@ -249,7 +285,7 @@ $(document).ready(function () { if ($scheduleeveryday.is(':checked')) { _Day = "Everyday"; } else if ($schedulespecialdate.is(':checked')) { - _Day = $scheduledate.val(); + _Day = Convert_input_date_to_string($scheduledate.val()); } else if ($scheduleweekly.is(':checked')) { _Day = $weeklyselect.val(); } @@ -322,59 +358,46 @@ $(document).ready(function () { /** @type {ScheduleBank} */ let sr = { index: Number(cells.eq(0).text()), - description: cells.eq(1).text(), - day: cells.eq(2).text(), - time: cells.eq(3).text(), - soundpath: cells.eq(4).text(), - repeat: cells.eq(5).text(), - enable: cells.eq(6).text(), - broadcastZones: cells.eq(7).text(), - language: cells.eq(8).text() + Description: cells.eq(1).text(), + Day: cells.eq(2).text(), + Time: cells.eq(3).text(), + Soundpath: cells.eq(4).text(), + Repeat: cells.eq(5).text(), + Enable: cells.eq(6).text(), + BroadcastZones: cells.eq(7).text(), + Language: cells.eq(8).text() } - if (confirm(`Are you sure to edit schedule [${sr.index}] Description=${sr.description}?`)) { + console.log('Editing schedule:', sr); + if (confirm(`Are you sure to edit schedule [${sr.index}] Description=${sr.Description}?`)) { $schedulemodal.modal('show'); clearScheduleModal(); // fill the form with existing data $scheduleid.val(sr.index); - $scheduledescription.val(sr.description); - let [hour, minute] = sr.time.split(':').map(num => parseInt(num, 10)); + $scheduledescription.val(sr.Description); + let [hour, minute] = sr.Time.split(':').map(num => parseInt(num, 10)); $schedulehour.val(hour.toString()); $scheduleminute.val(minute.toString()); - $schedulemessage.val(sr.soundpath); - $schedulerepeat.val(sr.repeat.toString()); - $scheduleenable.prop('checked', sr.enable.toLowerCase() === 'true'); - switch (sr.day) { + $schedulemessage.val(sr.Soundpath).trigger('change'); + $schedulerepeat.val(sr.Repeat); + $scheduleenable.prop('checked', sr.Enable.toLowerCase() === 'true'); + $languageselect.val(sr.Language.split(';')).trigger('change'); + $schedulezones.val(sr.BroadcastZones.split(';')).trigger('change'); + switch (sr.Day) { case 'Everyday': $scheduleeveryday.click(); break; - case 'Sunday': - $schedulesunday.click(); - break; - case 'Monday': - $schedulemonday.click(); - break; - case 'Tuesday': - $scheduletuesday.click(); - break; - case 'Wednesday': - $schedulewednesday.click(); - break; - case 'Thursday': - $schedulethursday.click(); - break; - case 'Friday': - $schedulefriday.click(); - break; - case 'Saturday': - $schedulesaturday.click(); + case 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday': + console.log(`Setting weekly schedule for day: ${sr.Day}`); + $scheduleweekly.click(); + $weeklyselect.val(sr.Day).trigger('change'); break; default: // check if the day is in format dd/mm/yyyy // and set the special date radio button and date input - if (/^\d{2}\/\d{2}\/\d{4}$/.test(sr.day)) { + if (/^\d{2}\/\d{2}\/\d{4}$/.test(sr.Day)) { $schedulespecialdate.click(); - $scheduledate.val(sr.day); + $scheduledate.val(Convert_string_to_input_date(sr.Day)); } } diff --git a/html/webpage/assets/js/script.js b/html/webpage/assets/js/script.js index 5ef1826..2122c4c 100644 --- a/html/webpage/assets/js/script.js +++ b/html/webpage/assets/js/script.js @@ -578,7 +578,18 @@ $(document).ready(function () { }); }) $('#logoutlink').click(() => { - window.location.href = "login.html" - }) + //window.location.href = "login.html" + fetch("/logout", {method: 'GET'}) + .then(response => { + if (response.ok) { + window.location.href = "login.html"; + } else { + alert("Logout failed: " + response.statusText); + } + }) + .catch(error => { + alert("Logout error: " + error.message); + }); + }); }); \ No newline at end of file diff --git a/src/Main.kt b/src/Main.kt index 8a65050..38a068a 100644 --- a/src/Main.kt +++ b/src/Main.kt @@ -5,6 +5,8 @@ import audio.UDPReceiver import barix.BarixConnection import barix.TCP_Barix_Command_Server import codes.Somecodes +import codes.configFile +import codes.configKeys import com.sun.jna.Platform import commandServer.TCP_Android_Command_Server import content.Category @@ -31,7 +33,7 @@ lateinit var audioPlayer: AudioPlayer val StreamerOutputs: MutableMap = HashMap() lateinit var udpreceiver: UDPReceiver lateinit var tcpreceiver: TCPReceiver -const val version = "0.0.9 (20/10/2025)" +const val version = "0.0.10 (20/10/2025)" // AAS 64 channels const val max_channel = 64 @@ -55,7 +57,8 @@ val contentCache = ContentCache() */ fun folder_preparation(){ // sementara diset begini, nanti pake config file - Somecodes.Soundbank_directory = Paths.get("c:\\soundbank") + //Somecodes.Soundbank_directory = Paths.get("c:\\soundbank") + Somecodes.Soundbank_directory = Paths.get(config.Get(configKeys.SOUNDBANK_DIRECTORY.key)) Files.createDirectories(Somecodes.SoundbankResult_directory) Files.createDirectories(Somecodes.PagingResult_directory) Files.createDirectories(Somecodes.Soundbank_directory) @@ -94,6 +97,8 @@ fun files_preparation(){ } +lateinit var config : configFile; + // Application start here fun main() { if (Platform.isWindows()) { @@ -102,6 +107,7 @@ fun main() { } Logger.info { "Starting AAS New Generation version $version" } + config = configFile() folder_preparation() audioPlayer = AudioPlayer(44100) // 44100 Hz sampling rate @@ -109,8 +115,10 @@ fun main() { files_preparation() + db = MariaDB() + val subcode01 = MainExtension01() // Coroutine untuk cek Paging Queue dan AAS Queue setiap detik @@ -171,6 +179,7 @@ fun main() { val _streamer = StreamerOutputs[cmd.ipaddress] val _sc = db.soundchannelDB.List.find { it.ip == cmd.ipaddress } if (_streamer == null) { + // belum create BarixConnection untuk ipaddress ini //Logger.info { "New Streamer Output connection from ${cmd.ipaddress}" } if (_sc != null) { diff --git a/src/audio/UDPReceiverToFile.kt b/src/audio/UDPReceiverToFile.kt index f07e310..09c42e2 100644 --- a/src/audio/UDPReceiverToFile.kt +++ b/src/audio/UDPReceiverToFile.kt @@ -29,7 +29,7 @@ import java.util.function.Consumer * @param outputFilePath The path to the file where the received data will be written. * @param senderIP The IP address of the sender from which to accept packets. */ -class UDPReceiverToFile(listeningAddress: String, listeningPort: Int, val samplingrate: Int=44100, val channel: Int=1, val outputFilePath: String, val senderIP: String) { +class UDPReceiverToFile(listeningAddress: String, listeningPort: Int, val samplingrate: Int=44100, val channel: Int=1, val outputFilePath: String, val senderIP: String) { private var socket: DatagramSocket? = null private val bass : Bass = Bass.Instance diff --git a/src/audio/UDPSenderFromFile.kt b/src/audio/UDPSenderFromFile.kt index 75981b7..df81a21 100644 --- a/src/audio/UDPSenderFromFile.kt +++ b/src/audio/UDPSenderFromFile.kt @@ -31,7 +31,8 @@ class UDPSenderFromFile(val fileName: String, val bytesPerPackage: Int=1024, tar if (handle!=0){ // test buka file berhasil, tutup lagi bass.BASS_StreamFree(handle) - if (targetPort>0 && targetPort<65535){ + //if (targetPort>0 && targetPort<65535){ + if (targetPort in 0..65535){ if (targetIP.isNotEmpty()){ var validIPs = true for(ip in targetIP){ diff --git a/src/barix/TCP_Barix_Command_Server.kt b/src/barix/TCP_Barix_Command_Server.kt index c60c05d..6c01518 100644 --- a/src/barix/TCP_Barix_Command_Server.kt +++ b/src/barix/TCP_Barix_Command_Server.kt @@ -71,7 +71,8 @@ class TCP_Barix_Command_Server { } } catch (ex:Exception){ - Logger.error { "Error in communication with Streamer Output with IP $key, Message : ${ex.message}" } + if (ex.message!=null) Logger.error { "Error in communication with Streamer Output with IP $key, Message : ${ex.message}" } + } Logger.info { "Finished communicating with Streamer Output with IP $key" } diff --git a/src/codes/Somecodes.kt b/src/codes/Somecodes.kt index 53a55d6..ae24b32 100644 --- a/src/codes/Somecodes.kt +++ b/src/codes/Somecodes.kt @@ -45,8 +45,8 @@ class Somecodes { val datetimeformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss") val dateformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy") val dateformat2: DateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy") - val timeformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("hh:mm:ss") - val timeformat2: DateTimeFormatter = DateTimeFormatter.ofPattern("hh:mm") + val timeformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss") + val timeformat2: DateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm") val filenameformat: DateTimeFormatter = DateTimeFormatter.ofPattern("ddMMyyyy_HHmmss") const val KB_threshold = 1024.0 const val MB_threshold = KB_threshold * 1024.0 diff --git a/src/codes/configFile.kt b/src/codes/configFile.kt new file mode 100644 index 0000000..f1c0e71 --- /dev/null +++ b/src/codes/configFile.kt @@ -0,0 +1,66 @@ +package codes + +import org.tinylog.Logger +import java.nio.file.Files +import java.nio.file.Paths +import java.util.Properties + +class configFile { + private val config : Properties = Properties() + private val configFilePath = Paths.get(Somecodes.current_directory, "config.properties") + init{ + + if (Files.exists(configFilePath)) { + try{ + config.load(Files.newInputStream(configFilePath)) + if (HaveAllKeys()){ + Logger.info { "Configuration file loaded successfully." } + } else { + Logger.warn { "Configuration file is missing required keys. Creating default configuration." } + CreateDefaultConfig() + } + } catch (e: Exception){ + Logger.error { "Failed to load config file: ${e.message}" } + CreateDefaultConfig() + } + } else CreateDefaultConfig() + } + + fun Get(key: String) : String{ + return config[key]?.toString() ?: "" + } + + fun Set(key: String, value: String){ + config[key] = value + } + + fun Save(){ + try{ + config.store(Files.newOutputStream(configFilePath), "Configuration file") + Logger.info { "Configuration file saved successfully." } + } catch (e: Exception){ + Logger.error { "Failed to save config file: ${e.message}" } + } + } + + private fun HaveAllKeys() : Boolean{ + return configKeys.values().all { config.containsKey(it.key) } + + } + + private fun CreateDefaultConfig(){ + config.clear() + // create default config file + config[configKeys.DATABASE_HOST.key] = "localhost" + config[configKeys.DATABASE_PORT.key] = "3306" + config[configKeys.DATABASE_USER.key] = "admin" + config[configKeys.DATABASE_PASSWORD.key] = "admin" + config[configKeys.DATABASE_NAME.key] = "aas" + config[configKeys.SOUNDBANK_DIRECTORY.key] = Paths.get(Somecodes.current_directory, "soundbank").toString() + config[configKeys.REMARK_GOP.key] = "" + config[configKeys.REMARK_GBD.key] = "" + config[configKeys.REMARK_GFC.key] = "" + config[configKeys.REMARK_FLD.key] = "" + Save() + } +} \ No newline at end of file diff --git a/src/codes/configKeys.kt b/src/codes/configKeys.kt new file mode 100644 index 0000000..26bab7a --- /dev/null +++ b/src/codes/configKeys.kt @@ -0,0 +1,14 @@ +package codes + +enum class configKeys(val key: String) { + DATABASE_HOST("database.host"), + DATABASE_PORT("database.port"), + DATABASE_USER("database.user"), + DATABASE_PASSWORD("database.password"), + DATABASE_NAME("database.name"), + SOUNDBANK_DIRECTORY("soundbank.directory"), + REMARK_GOP("remark.GOP"), + REMARK_GBD("remark.GBD"), + REMARK_GFC("remark.GFC"), + REMARK_FLD("remark.FLD") +} \ No newline at end of file diff --git a/src/database/MariaDB.kt b/src/database/MariaDB.kt index 9e79ca6..7adadbb 100644 --- a/src/database/MariaDB.kt +++ b/src/database/MariaDB.kt @@ -3,6 +3,7 @@ package database import codes.Somecodes.Companion.ValiDateForLogHtml import codes.Somecodes.Companion.ValidScheduleDay import codes.Somecodes.Companion.toJsonString +import config import content.Category import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking @@ -13,6 +14,7 @@ import org.tinylog.Logger import java.sql.Connection import java.sql.DriverManager import java.util.function.Consumer +import codes.configKeys /** * A class to manage a connection to a MariaDB database. @@ -25,11 +27,11 @@ import java.util.function.Consumer */ @Suppress("unused", "SqlSourceToSinkFlow") class MariaDB( - address: String = "localhost", - port: Int = 3306, - dbName: String = "aas", - username: String = "admin", - password: String = "admin" + address: String = config.Get(configKeys.DATABASE_HOST.key), + port: Int = config.Get(configKeys.DATABASE_PORT.key).toInt(), + dbName: String = config.Get(configKeys.DATABASE_NAME.key), + username: String = config.Get(configKeys.DATABASE_USER.key), + password: String = config.Get(configKeys.DATABASE_PASSWORD.key) ) { var connected: Boolean = false @@ -54,8 +56,8 @@ class MariaDB( } fun ValidTime(time: String): Boolean { - // Check if the time is in the format HH:MM:SS - val regex = Regex("""^\d{2}:\d{2}:\d{2}$""") + // Check if the time is in the format HH:MM + val regex = Regex("""^\d{2}:\d{2}$""") return regex.matches(time) } @@ -160,9 +162,11 @@ class MariaDB( Logger.info("Soundbank added: ${data.Description}" as Any) return true } else { + Add_Log("AAS", "No soundbank entry added for: ${data.Description}") Logger.warn("No soundbank entry added for: ${data.Description}" as Any) } } catch (e: Exception) { + Add_Log("AAS", "Failed to add Soundbank: ${data.Description}. Error: ${e.message}") Logger.error("Error adding soundbank entry: ${e.message}" as Any) } return false @@ -187,9 +191,11 @@ class MariaDB( statement.executeBatch() connection.commit() Logger.info("Bulk soundbank insert successful: ${data.size} entries" as Any) + Add_Log("AAS","Successfully Import Sound Bank Table: ${data.size} entries.") connection.autoCommit = true return true } catch (e: Exception) { + Add_Log("AAS","Failed to Import Sound Bank. Error: ${e.message}") Logger.error("Error adding soundbank entries: ${e.message}" as Any) } return false @@ -212,9 +218,11 @@ class MariaDB( Add_Log("AAS", "Soundbank updated at index $index: ${data.Description}; TAG: ${data.TAG}; Category: ${data.Category}; Language: ${data.Language}; VoiceType: ${data.VoiceType}; Path: ${data.Path}") return true } else { + Add_Log("AAS", "Failed updating Sound Bank at index $index for: ${data.Description}") Logger.warn("No soundbank entry updated at index $index for: ${data.Description}" as Any) } } catch (e: Exception) { + Add_Log("AAS", "Failed updating Sound Bank at index $index. Error: ${e.message}") Logger.error("Error updating soundbank entry at index $index: ${e.message}" as Any) } return false @@ -365,9 +373,11 @@ class MariaDB( Add_Log("AAS", "Messagebank added: ${data.Description}; Language: ${data.Language}; ANN_ID: ${data.ANN_ID}; Voice_Type: ${data.Voice_Type}") return true } else { + Add_Log("AAS","Failed adding Message Bank for: ${data.Description}") Logger.warn("No messagebank entry added for: ${data.Description}" as Any) } } catch (e: Exception) { + Add_Log("AAS","Failed adding Message Bank for: ${data.Description}. Error: ${e.message}") Logger.error("Error adding messagebank entry: ${e.message}" as Any) } return false @@ -391,9 +401,11 @@ class MariaDB( statement.executeBatch() connection.commit() Logger.info("Bulk messagebank insert successful: ${data.size} entries" as Any) + Add_Log("AAS","Successfully Import Message Bank Table: ${data.size} entries.") connection.autoCommit = true return true } catch (e: Exception) { + Add_Log("AAS","Failed to Import Message Bank. Error: ${e.message}") Logger.error("Error adding messagebank entries: ${e.message}" as Any) } return false @@ -572,9 +584,11 @@ class MariaDB( Add_Log("AAS", "Language link added: ${data.TAG} -> ${data.Language}") return true } else { + Add_Log("AAS","Failed adding Language Link for: ${data.TAG} -> ${data.Language}.") Logger.warn("No language link entry added for: ${data.TAG} -> ${data.Language}" as Any) } } catch (e: Exception) { + Add_Log("AAS","Failed adding Language Link for: ${data.TAG} -> ${data.Language}. Error: ${e.message}") Logger.error("Error adding language link entry: ${e.message}" as Any) } return false @@ -585,7 +599,9 @@ class MariaDB( connection.autoCommit = false val sql = "INSERT INTO ${super.dbName} (TAG, Language) VALUES (?, ?)" val statement = connection.prepareStatement(sql) - for (ll in List) { + + //for (ll in List) { + for (ll in data) { statement.setString(1, ll.TAG) statement.setString(2, ll.Language) statement.addBatch() @@ -593,9 +609,11 @@ class MariaDB( statement.executeBatch() connection.commit() Logger.info("Bulk languagelinking insert successful: ${List.size} entries" as Any) + Add_Log("AAS","Successfully Import Language Link Table: ${data.size} entries.") connection.autoCommit = true return true } catch (e: Exception) { + Add_Log("AAS","Failed to Import Language Link. Error: ${e.message}") Logger.error("Error adding languagelinking entries: ${e.message}" as Any) } return false @@ -614,9 +632,11 @@ class MariaDB( Add_Log("AAS", "Language link updated at index $index: ${data.TAG} -> ${data.Language}") return true } else { + Add_Log("AAS", "Failed updating Language Link at index $index for: ${data.TAG} -> ${data.Language}") Logger.warn("No language link entry updated at index $index for: ${data.TAG} -> ${data.Language}" as Any) } } catch (e: Exception) { + Add_Log("AAS", "Failed updating Language Link at index $index. Error: ${e.message}") Logger.error("Error updating language link entry at index $index: ${e.message}" as Any) } return false @@ -753,7 +773,7 @@ class MariaDB( } try { val statement = - connection.prepareStatement("INSERT INTO ${super.dbName} (Description, Day, Time, Soundpath, Repeat, Enable, BroadcastZones, Language) VALUES (?, ?, ?, ?, ?, ?, ?, ?)") + connection.prepareStatement("INSERT INTO ${super.dbName} (Description, Day, Time, Soundpath, `Repeat`, Enable, BroadcastZones, Language) VALUES (?, ?, ?, ?, ?, ?, ?, ?)") statement?.setString(1, data.Description) statement?.setString(2, data.Day) statement?.setString(3, data.Time) @@ -768,9 +788,11 @@ class MariaDB( Add_Log("AAS", "Schedulebank added: ${data.Description}; Day: ${data.Day}; Time: ${data.Time}; Soundpath: ${data.Soundpath}; Repeat: ${data.Repeat}; Enable: ${data.Enable}; BroadcastZones: ${data.BroadcastZones}; Language: ${data.Language}") return true } else { + Add_Log("AAS","Failed adding Schedule Bank for: ${data.Description}.") Logger.warn("No schedulebank entry added for: ${data.Description}" as Any) } } catch (e: Exception) { + Add_Log("AAS","Failed adding Schedule Bank for: ${data.Description}. Error: ${e.message}") Logger.error("Error adding schedulebank entry: ${e.message}" as Any) } return false @@ -780,7 +802,7 @@ class MariaDB( try { connection.autoCommit = false val sql = - "INSERT INTO ${super.dbName} (Description, Day, Time, Soundpath, Repeat, Enable, BroadcastZones, Language) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" + "INSERT INTO ${super.dbName} (Description, Day, Time, Soundpath, `Repeat`, Enable, BroadcastZones, Language) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" val statement = connection.prepareStatement(sql) for (sb in data) { if (!ValidDate(sb.Day) || !ValidTime(sb.Time)) { @@ -800,9 +822,11 @@ class MariaDB( statement.executeBatch() connection.commit() Logger.info("Bulk schedulebank insert successful: ${data.size} entries" as Any) + Add_Log("AAS","Successfully Import Schedule Bank Table: ${data.size} entries.") connection.autoCommit = true return true } catch (e: Exception) { + Add_Log("AAS","Failed to Import Schedule Bank. Error: ${e.message}") Logger.error("Error adding schedulebank entries: ${e.message}" as Any) } return false @@ -820,7 +844,7 @@ class MariaDB( } try { val statement = - connection.prepareStatement("UPDATE ${super.dbName} SET Description = ?, Day = ?, Time = ?, Soundpath = ?, Repeat = ?, Enable = ?, BroadcastZones = ?, Language = ? WHERE `index` = ?") + connection.prepareStatement("UPDATE ${super.dbName} SET Description = ?, Day = ?, Time = ?, Soundpath = ?, `Repeat` = ?, Enable = ?, BroadcastZones = ?, Language = ? WHERE `index` = ?") statement?.setString(1, data.Description) statement?.setString(2, data.Day) statement?.setString(3, data.Time) @@ -836,9 +860,11 @@ class MariaDB( Add_Log("AAS", "Schedulebank updated at index $index: ${data.Description}; Day: ${data.Day}; Time: ${data.Time}; Soundpath: ${data.Soundpath}; Repeat: ${data.Repeat}; Enable: ${data.Enable}; BroadcastZones: ${data.BroadcastZones}; Language: ${data.Language}") return true } else { + Add_Log("AAS", "Failed updating Schedule Bank at index $index for: ${data.Description}.") Logger.warn("No schedulebank entry updated at index $index for: ${data.Description}" as Any) } } catch (e: Exception) { + Add_Log("AAS", "Failed updating Schedule Bank at index $index. Error: ${e.message}") Logger.error("Error updating schedulebank entry at index $index: ${e.message}" as Any) } return false @@ -851,9 +877,9 @@ class MariaDB( // use a temporary table to reorder the index statement?.executeUpdate("CREATE TABLE IF NOT EXISTS $tempdb_name LIKE ${super.dbName}") statement?.executeUpdate("TRUNCATE TABLE $tempdb_name") - statement?.executeUpdate("INSERT INTO $tempdb_name (Description, Day, Time, Soundpath, Repeat, Enable, BroadcastZones, Language) SELECT Description, Day, Time, Soundpath, Repeat, Enable, BroadcastZones, Language FROM ${super.dbName} ORDER BY Day , Time ") + statement?.executeUpdate("INSERT INTO $tempdb_name (Description, Day, Time, Soundpath, `Repeat`, Enable, BroadcastZones, Language) SELECT Description, Day, Time, Soundpath, `Repeat`, Enable, BroadcastZones, Language FROM ${super.dbName} ORDER BY Day , Time ") statement?.executeUpdate("TRUNCATE TABLE ${super.dbName}") - statement?.executeUpdate("INSERT INTO ${super.dbName} (Description, Day, Time, Soundpath, Repeat, Enable, BroadcastZones, Language) SELECT Description, Day, Time, Soundpath, Repeat, Enable, BroadcastZones, Language FROM $tempdb_name") + statement?.executeUpdate("INSERT INTO ${super.dbName} (Description, Day, Time, Soundpath, `Repeat`, Enable, BroadcastZones, Language) SELECT Description, Day, Time, Soundpath, `Repeat`, Enable, BroadcastZones, Language FROM $tempdb_name") statement?.executeUpdate("DROP TABLE $tempdb_name") Logger.info("${super.dbName} table resorted by Day and Time" as Any) // reload the local list @@ -1014,9 +1040,11 @@ class MariaDB( Add_Log("AAS", "Broadcast zone added: ${data.description}; SoundChannel: ${data.SoundChannel}; id: ${data.id}; bp: ${data.bp}") return true } else { + Add_Log("AAS","Failed adding Broadcast Zone for: ${data.description}.") Logger.warn("No broadcast zone entry added for: ${data.description}" as Any) } } catch (e: Exception) { + Add_Log("AAS","Failed adding Broadcast Zone for: ${data.description}. Error: ${e.message}") Logger.error("Error adding broadcast zone entry: ${e.message}" as Any) } return false @@ -1038,9 +1066,11 @@ class MariaDB( statement.executeBatch() connection.commit() Logger.info("Bulk ${super.dbName} insert successful: ${data.size} entries" as Any) + Add_Log("AAS","Successfully Import Broadcast Zones Table: ${data.size} entries.") connection.autoCommit = true return true } catch (e: Exception) { + Add_Log("AAS","Failed to Import Broadcast Zones. Error: ${e.message}") Logger.error("Error adding ${super.dbName} entries: ${e.message}" as Any) } return false @@ -1061,9 +1091,11 @@ class MariaDB( Add_Log("AAS", "Broadcast zone updated at index $index: ${data.description}; SoundChannel: ${data.SoundChannel}; id: ${data.id}; bp: ${data.bp}") return true } else { + Add_Log("AAS", "Failed updating Broadcast Zone at index $index for: ${data.description}.") Logger.warn("No broadcast zone entry updated at index $index for: ${data.description}" as Any) } } catch (e: Exception) { + Add_Log("AAS", "Failed updating Broadcast Zone at index $index. Error: ${e.message}") Logger.error("Error updating broadcast zone entry at index $index: ${e.message}" as Any) } return false @@ -1241,9 +1273,11 @@ class MariaDB( statement.executeBatch() connection.commit() Logger.info("Bulk QueueTable insert successful: ${data.size} entries" as Any) + Add_Log("AAS","Successfully Import Queue Table: ${data.size} entries.") connection.autoCommit = true return true } catch (e: Exception) { + Add_Log("AAS","Failed to Import Queue Table. Error: ${e.message}") Logger.error("Error adding QueueTable entries: ${e.message}" as Any) } return false @@ -1402,9 +1436,11 @@ class MariaDB( statement.executeBatch() connection.commit() Logger.info("Bulk QueuePaging insert successful: ${data.size} entries" as Any) + Add_Log("AAS","Successfully Import Queue Paging Table: ${data.size} entries.") connection.autoCommit = true true } catch (e: Exception) { + Add_Log("AAS","Failed to Import Queue Paging Table. Error: ${e.message}") Logger.error("Error adding QueuePaging entries: ${e.message}" as Any) false } @@ -1526,12 +1562,14 @@ class MariaDB( val rowsAffected = statement?.executeUpdate() if (rowsAffected != null && rowsAffected > 0) { Logger.info("SoundChannel updated: ${data.channel} -> ${data.ip}" as Any) - Add_Log("AAS", "SoundChannel updated: ${data.channel} -> ${data.ip}") + Add_Log("AAS", "Sound Channel updated: ${data.channel} -> ${data.ip}") return true } else { + Add_Log("AAS", "Failed updating Sound Channel for: ${data.channel} -> ${data.ip}.") Logger.warn("No SoundChannel entry updated for: ${data.channel} -> ${data.ip}" as Any) } } catch (e: Exception) { + Add_Log("AAS", "Failed updating Sound Channel for: ${data.channel} -> ${data.ip}. Error: ${e.message}") Logger.error("Error updating SoundChannel entry: ${e.message}" as Any) } return false @@ -1550,9 +1588,11 @@ class MariaDB( statement.executeBatch() connection.commit() Logger.info("Bulk SoundChannel update successful: ${data.size} entries" as Any) + Add_Log("AAS","Successfully Import Sound Channels Table: ${data.size} entries.") connection.autoCommit = true true } catch (e: Exception) { + Add_Log("AAS","Failed to Import Sound Channels. Error: ${e.message}") Logger.error("Error updating SoundChannel entries: ${e.message}" as Any) false } @@ -1568,12 +1608,14 @@ class MariaDB( val rowsAffected = statement?.executeUpdate() if (rowsAffected != null && rowsAffected > 0) { Logger.info("SoundChannel updated at index $index: ${data.channel} -> ${data.ip}" as Any) - Add_Log("AAS", "SoundChannel updated at index $index: ${data.channel} -> ${data.ip}") + Add_Log("AAS", "Sound Channel updated at index $index: ${data.channel} -> ${data.ip}") return true } else { - Logger.warn("No SoundChannel entry updated at index $index for: ${data.channel} -> ${data.ip}" as Any) + Add_Log("AAS", "Failed updating Sound Channel at index $index for: ${data.channel} -> ${data.ip}.") + Logger.warn("No Sound Channel entry updated at index $index for: ${data.channel} -> ${data.ip}" as Any) } } catch (e: Exception) { + Add_Log("AAS", "Failed updating Sound Channel at index $index. Error: ${e.message}") Logger.error("Error updating SoundChannel entry at index $index: ${e.message}" as Any) } return false @@ -1702,9 +1744,11 @@ class MariaDB( Add_Log("AAS", "${super.dbName} IP cleared for index $index") return true } else { + Add_Log("AAS","Failed clearing ${super.dbName} IP for index $index.") Logger.warn("No ${super.dbName} entry cleared for index $index" as Any) } } catch (e: Exception) { + Add_Log("AAS","Failed clearing ${super.dbName} IP for index $index. Error: ${e.message}") Logger.error("Error clearing ${super.dbName} entry for index $index: ${e.message}" as Any) } return false @@ -1783,9 +1827,11 @@ class MariaDB( statement.executeBatch() connection.commit() Logger.info("Bulk log insert successful: ${data.size} entries" as Any) + Add_Log("AAS","Successfully Import Log Table: ${data.size} entries.") connection.autoCommit = true true } catch (e: Exception) { + Add_Log("AAS","Failed to Import Log Table. Error: ${e.message}") Logger.error("Error adding log entries: ${e.message}" as Any) false } @@ -1917,9 +1963,11 @@ class MariaDB( Add_Log("AAS", "User added: ${data.username}") return true } else { + Add_Log("AAS","Failed adding User entry for: ${data.username}.") Logger.warn("No user entry added for: ${data.username}" as Any) } } catch (e: Exception) { + Add_Log("AAS","Failed adding User entry for: ${data.username}. Error: ${e.message}") Logger.error("Error adding user entry: ${e.message}" as Any) } return false @@ -1943,9 +1991,11 @@ class MariaDB( statement.executeBatch() connection.commit() Logger.info("Bulk user insert successful: ${data.size} entries" as Any) + Add_Log("AAS","Successfully Import User Table: ${data.size} entries.") connection.autoCommit = true true } catch (e: Exception) { + Add_Log("AAS","Failed to Import User Table. Error: ${e.message}") Logger.error("Error adding user entries: ${e.message}" as Any) false } @@ -1968,9 +2018,11 @@ class MariaDB( Add_Log("AAS", "User updated at index $index: ${data.username}") return true } else { + Add_Log("AAS", "Failed updating User at index $index for: ${data.username}.") Logger.warn("No user entry updated at index $index for: ${data.username}" as Any) } } catch (e: Exception) { + Add_Log("AAS", "Failed updating User at index $index. Error: ${e.message}") Logger.error("Error updating user entry at index $index: ${e.message}" as Any) } return false diff --git a/src/web/WebApp.kt b/src/web/WebApp.kt index a554dfa..e72e9ff 100644 --- a/src/web/WebApp.kt +++ b/src/web/WebApp.kt @@ -67,11 +67,20 @@ class WebApp(val listenPort: Int, val userlist: List>) { path("/") { get { ctx -> // Serve the main page - ctx.sessionAttribute("user", null) // Clear user session + ctx.cookie("aas-user","") + //ctx.sessionAttribute("user", null) // Clear user session ctx.redirect("login.html") } } + path("logout"){ + get { ctx -> + println("Logout requested by user") + ctx.cookie("aas-user","") + //ctx.sessionAttribute("user", null) // Clear user session + ctx.redirect("login.html") + } + } path("login.html") { post { it -> // get username and password from form @@ -88,7 +97,8 @@ class WebApp(val listenPort: Int, val userlist: List>) { return@post } // Set user session - it.sessionAttribute("user", user.first) + //it.sessionAttribute("user", user.first) + it.cookie("aas-user", user.first) //println("User ${user.first} logged in") // Redirect to home page it.redirect("home.html") @@ -1468,7 +1478,16 @@ class WebApp(val listenPort: Int, val userlist: List>) { } } } + path("Settings"){ + get("Messages"){ + val messages = db.messageDB.List + it.result(objectmapper.writeValueAsString(messages)) + } + post ("FISCode") { + //TODO set FIS code + } + } } } }.start(listenPort) @@ -1477,12 +1496,16 @@ class WebApp(val listenPort: Int, val userlist: List>) { fun CheckUsers(ctx: Context) { - val user = ctx.sessionAttribute("user") + //val user = ctx.sessionAttribute("user") + val user = ctx.cookie("aas-user") if (user == null) { + println("Cookie user not found, redirecting to login.html") ctx.redirect("login.html") } val foundUser = userlist.find { it.first == user } + println("Checking user=$user, foundUser=$foundUser") if (foundUser == null) { + println("User not found in userlist, redirecting to login.html") ctx.redirect("login.html") } }