Add freshclam goroutine.
This commit is contained in:
parent
dc01e7999e
commit
bcb44774e5
17
malscan.go
17
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)
|
||||
}
|
||||
}
|
||||
|
29
updater.go
Normal file
29
updater.go
Normal 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")
|
||||
}
|
Loading…
Reference in New Issue
Block a user