From d67af210dad10cfe9b9169efb0a4a920afa36ac3 Mon Sep 17 00:00:00 2001 From: bugbounce <35751394+bugbounce@users.noreply.github.com> Date: Fri, 21 Oct 2022 21:44:08 +0530 Subject: [PATCH] Add delete functionality for logged hosts --- src/db-edit.go | 10 +++++++++- src/main.go | 8 ++++++-- src/templates/index.html | 4 +++- src/web-index.go | 16 +++++++++++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/db-edit.go b/src/db-edit.go index b7f811e..7bc7c7b 100644 --- a/src/db-edit.go +++ b/src/db-edit.go @@ -47,7 +47,15 @@ func db_update(oneHost Host) { db_exec(sqlStatement) } +func db_delete(hostId int) { + sqlStatement := `DELETE FROM "now" WHERE ID = '%d';` + sqlStatement = fmt.Sprintf(sqlStatement, hostId) + //fmt.Println("Delete statement:", sqlStatement) + db_exec(sqlStatement) +} + + func db_setnow() { sqlStatement := `UPDATE "now" set NOW = '0';` db_exec(sqlStatement) -} \ No newline at end of file +} diff --git a/src/main.go b/src/main.go index e64c974..8441584 100644 --- a/src/main.go +++ b/src/main.go @@ -37,11 +37,15 @@ func scan_and_compare() { db_setnow() // Mark hosts in DB as offline hosts_compare(foundHosts, dbHosts) // Compare hosts online and in DB // and add them to DB - AllHosts = db_select() + update_all_hosts() time.Sleep(time.Duration(AppConfig.Timeout) * time.Second) // Timeout } } +func update_all_hosts(){ + AllHosts = db_select() +} + func main() { AllHosts = []Host{} AppConfig = get_config() // Get config from Defaults, Config file, Env @@ -51,4 +55,4 @@ func main() { go scan_and_compare() webgui() // Start web GUI -} \ No newline at end of file +} diff --git a/src/templates/index.html b/src/templates/index.html index 43d5abc..6a48255 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -45,6 +45,7 @@