diff --git a/malscan.go b/malscan.go index 8d1085b..aa7fdcf 100644 --- a/malscan.go +++ b/malscan.go @@ -2,11 +2,23 @@ package main import ( "fmt" + "time" clamav "git.cyber.gent/friedkiwi/go-clamav" ) +func banner() { + fmt.Println(" _ \n _ __ ___ __ _| |___ ___ __ _ _ __ \n| '_ ` _ \\ / _` | / __|/ __/ _` | '_ \\ \n| | | | | | (_| | \\__ \\ (_| (_| | | | |\n|_| |_| |_|\\__,_|_|___/\\___\\__,_|_| |_|\n ") + fmt.Println("malscan v0.1 microservice") + fmt.Println("") +} + func main() { + + banner() + // start freshclam goroutine + go freshclam_update() + // new clamav instance c := new(clamav.Clamav) err := c.Init(clamav.SCAN_OPTIONS{ @@ -44,4 +56,9 @@ func main() { // scan scanned, virusName, ret := c.ScanFile("/bin/bash") fmt.Println(scanned, virusName, ret) + + // loop forever. + for { + time.Sleep(1 * time.Second) + } } diff --git a/rest.go b/rest.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/rest.go @@ -0,0 +1 @@ +package main diff --git a/updater.go b/updater.go new file mode 100644 index 0000000..1bdc11c --- /dev/null +++ b/updater.go @@ -0,0 +1,29 @@ +package main + +import ( + "log" + "os" + "os/exec" + "time" +) + +func freshclam_update() { + for { + freshclam_update_routine() + time.Sleep(1 * time.Hour) + } +} + +func freshclam_update_routine() { + log.Println("freshclam_update_routine(): refreshing clamav database...") + + freshclamCommand := exec.Command("freshclam") + freshclamCommand.Stdout = os.Stdout + freshclamCommand.Stderr = os.Stderr + err := freshclamCommand.Run() + if err != nil { + log.Println("freshclam_update_routine(): error running freshclam:", err) + } + + log.Println("freshclam_update_routine(): done refreshing clamav database") +}