Add freshclam goroutine.

This commit is contained in:
Yvan Janssens 2023-04-06 11:35:59 +02:00
parent dc01e7999e
commit bcb44774e5
3 changed files with 47 additions and 0 deletions

View File

@ -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)
}
}

1
rest.go Normal file
View File

@ -0,0 +1 @@
package main

29
updater.go Normal file
View File

@ -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")
}