wifictld-analyzer/cmd/controller.go

52 lines
1.1 KiB
Go
Raw Normal View History

2018-06-03 20:37:52 +02:00
package cmd
import (
"os"
"os/signal"
"syscall"
2019-02-28 16:24:29 +01:00
"github.com/bdlm/log"
2018-06-03 20:37:52 +02:00
"github.com/spf13/cobra"
2018-07-10 21:40:38 +02:00
"dev.sum7.eu/genofire/golang-lib/file"
2018-06-03 20:37:52 +02:00
2019-02-28 16:22:55 +01:00
"dev.sum7.eu/genofire/wifictld-analyzer/config"
"dev.sum7.eu/genofire/wifictld-analyzer/capture"
"dev.sum7.eu/genofire/wifictld-analyzer/controller"
"dev.sum7.eu/genofire/wifictld-analyzer/database"
2018-06-03 20:37:52 +02:00
)
// queryCmd represents the query command
var controllerCmd = &cobra.Command{
Use: "controller <interfaces>",
Short: "simulate a wifictld controller",
2018-07-10 21:40:38 +02:00
Example: `analyzer controller "/etc/wifictld.conf"`,
2018-06-03 20:37:52 +02:00
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
2018-07-10 21:40:38 +02:00
configObj := &config.Config{}
2018-06-03 20:37:52 +02:00
2018-07-10 21:40:38 +02:00
file.ReadTOML(args[0], configObj)
2018-06-03 20:37:52 +02:00
2018-07-10 21:40:38 +02:00
db := database.NewDB(configObj.StatePath)
2018-06-03 20:37:52 +02:00
2018-07-10 21:40:38 +02:00
ctr := controller.NewController(db)
2018-06-03 20:37:52 +02:00
defer ctr.Close()
2018-07-10 21:40:38 +02:00
coll := capture.NewCollector(ctr.Handler, configObj.Interfaces)
2018-06-03 20:37:52 +02:00
defer coll.Close()
ctr.Send = coll.Send
ctr.SendTo = coll.SendTo
// Wait for INT/TERM
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
log.Println("received", sig)
},
}
func init() {
RootCmd.AddCommand(controllerCmd)
}