Beispiel #1
0
// Initializer function to set up commandline arguments and socket session
func init() {
	var err error

	// Parse commandline arguments
	flag.StringVar(&socketPath, "socket", "/var/run/suricata/suricata-command.socket", "Full path to the suricata unix socket")
	flag.BoolVar(&interactive, "interactive", false, "Opens an interactive session to send commands to the socket")
	flag.Parse()

	// If the user wants to start an interactive session but has created / sent
	// command arguments at call
	if interactive && len(flag.Args()) > 0 {
		log.Fatalf("When running in interactive mode, do not supply command arguments: %+v\n", flag.Args())
	}

	// If the user does not want to start an interactive session but has not
	// created / sent any commandline arguments
	if !interactive && len(flag.Args()) < 1 {
		log.Fatalf("When running in interactive mode, supply atleast one command argument")
	}

	// Create a new Suricata Socket session
	session, err = surisoc.NewSuricataSocket(socketPath)
	if err != nil {
		log.Fatalf("Error: %s\n", err.Error())
	}

	// Create channels
	signals = make(chan os.Signal, 1)
	done = make(chan bool, 1)

	// Set up the signals to listen to, SIGQUIT is used internaly to stop
	// the current process
	signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
}
Beispiel #2
0
func init() {
	log.Println("Welcome to go-suricatasc-api!")
	var err error

	// Parse commandline arguments
	flag.StringVar(&socketPath, "socket", "/var/run/suricata/suricata-command.socket", "Full path to the suricata unix socket")
	host := flag.String("host", "127.0.0.1", "The IP-Address to bind to")
	port := flag.String("port", "8080", "The Port to bind to")
	flag.Parse()

	if host != nil && port != nil {
		bindingAddress = net.JoinHostPort(*host, *port)
	}

	// Create a new Suricata Socket session
	session, err = surisoc.NewSuricataSocket(socketPath)
	if err != nil {
		log.Fatalf("Error: %s\n", err.Error())
	}

	// Create channels
	signals = make(chan os.Signal, 1)
	done = make(chan bool, 1)

	// Set up the signals to listen to, SIGQUIT is used internaly to stop
	// the current process
	signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)

	log.Println("Done initializing")
}