Beispiel #1
0
func (s *server) start() error {
	s.client = rpcmq.NewClient("amqp://"+s.config.Rpcmq.Host+":"+s.config.Rpcmq.Port, s.config.Rpcmq.MsgQueue, s.config.Rpcmq.ReplyQueue, s.config.Rpcmq.Exchange, s.config.Rpcmq.ExchangeType)
	s.client.DeliveryMode = rpcmq.Transient
	err := s.client.Init()
	if err != nil {
		log.Fatalf("Init rpcmq: %v", err)
	}
	defer s.client.Shutdown()

	s.supervisor = monmq.NewSupervisor("amqp://"+s.config.Monmq.Host+":"+s.config.Monmq.Port, s.config.Monmq.ReplyQueue, s.config.Monmq.Exchange)
	if err := s.supervisor.Init(); err != nil {
		log.Fatalf("Init monmq: %v", err)
	}
	defer s.supervisor.Shutdown()

	if s.config.DB.Type == "mysql" {
		dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4,utf8", s.config.DB.Username, s.config.DB.Password, s.config.DB.Host, s.config.DB.Port, s.config.DB.Name)
		s.pm = persistence.NewMySQLPersistenceManager(dsn)
		defer s.pm.Close()
	} else if s.config.DB.Type == "elasticsearch" {
		esUrl := fmt.Sprintf("http://%s:%s", s.config.DB.Host, s.config.DB.Port)
		s.pm = persistence.NewElasticPersistenceManager(esUrl, s.config.DB.Name)
	} else {
		log.Fatalf("Invalid DB Type %s. Check the config", s.config.DB.Type)
	}

	m := vestigo.NewRouter()
	logHandler := olog.NewLogHandler(s.logger, logLine)

	m.Post("/tasks", orujo.NewPipe(
		http.HandlerFunc(s.tasksHandler),
		orujo.M(logHandler)).ServeHTTP,
	)
	m.Get("/status", orujo.NewPipe(
		http.HandlerFunc(s.getStatusHandler),
		orujo.M(logHandler)).ServeHTTP,
	)
	m.Post("/status", orujo.NewPipe(
		http.HandlerFunc(s.setStatusHandler),
		orujo.M(logHandler)).ServeHTTP,
	)
	m.Get("/ips/:ip", orujo.NewPipe(
		http.HandlerFunc(s.queryHandler),
		orujo.M(logHandler)).ServeHTTP,
	)
	m.Get("/ips", orujo.NewPipe(
		http.HandlerFunc(s.queryHandler),
		orujo.M(logHandler)).ServeHTTP,
	)

	fmt.Println("Listening on " + s.config.Local.Host + ":" + s.config.Local.Port + "...")
	log.Fatalln(http.ListenAndServe(s.config.Local.Host+":"+s.config.Local.Port, m))

	return nil
}
Beispiel #2
0
func (s *server) start() error {
	s.client = rpcmq.NewClient("amqp://"+s.config.Rpcmq.Host+":"+s.config.Rpcmq.Port, s.config.Rpcmq.MsgQueue, s.config.Rpcmq.ReplyQueue, s.config.Rpcmq.Exchange, s.config.Rpcmq.ExchangeType)
	s.client.DeliveryMode = rpcmq.Transient
	err := s.client.Init()
	if err != nil {
		log.Fatalf("Init rpcmq: %v", err)
	}
	defer s.client.Shutdown()

	s.supervisor = monmq.NewSupervisor("amqp://"+s.config.Monmq.Host+":"+s.config.Monmq.Port, s.config.Monmq.ReplyQueue, s.config.Monmq.Exchange)
	if err := s.supervisor.Init(); err != nil {
		log.Fatalf("Init monmq: %v", err)
	}
	defer s.supervisor.Shutdown()

	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", s.config.DB.Username, s.config.DB.Password, s.config.DB.Host, s.config.DB.Port, s.config.DB.Name)
	s.database, err = sql.Open("mysql", dsn)
	if err != nil {
		log.Fatal(err)
	}
	defer s.database.Close()

	_, err = s.database.Exec("CREATE TABLE IF NOT EXISTS banners (ip INT UNSIGNED, port INT UNSIGNED, service VARCHAR(50), content TEXT)")
	if err != nil {
		log.Fatal(err)
	}

	logHandler := olog.NewLogHandler(s.logger, logLine)

	http.Handle("/tasks", orujo.NewPipe(
		http.HandlerFunc(s.tasksHandler),
		orujo.M(logHandler)),
	)

	http.Handle("/status", orujo.NewPipe(
		http.HandlerFunc(s.statusHandler),
		orujo.M(logHandler)),
	)

	http.Handle("/ips", orujo.NewPipe(
		http.HandlerFunc(s.queryHandler),
		orujo.M(logHandler)),
	)

	http.Handle("/ips/", orujo.NewPipe(
		http.HandlerFunc(s.queryHandler),
		orujo.M(logHandler)),
	)

	fmt.Println("Listening on " + s.config.Local.Host + ":" + s.config.Local.Port + "...")
	log.Fatalln(http.ListenAndServe(s.config.Local.Host+":"+s.config.Local.Port, nil))

	return nil
}
Beispiel #3
0
func (s *server) start() error {
	m := vestigo.NewRouter()
	logger := log.New(os.Stdout, "[GODAN-UI] ", log.LstdFlags)
	logHandler := olog.NewLogHandler(logger, logLine)

	m.SetGlobalCors(&vestigo.CorsAccessControl{
		AllowOrigin:      []string{"*"},
		AllowCredentials: false,
		MaxAge:           3600 * time.Second,
		AllowHeaders:     []string{"Authorization", "Content-Type"},
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE"},
	})

	m.Get("/users/:username", orujo.NewPipe(
		orujo.M(logHandler),
		s.auth,
		http.HandlerFunc(s.getUserHandler)).ServeHTTP,
	)
	m.Put("/users/:username", orujo.NewPipe(
		orujo.M(logHandler),
		s.auth,
		http.HandlerFunc(s.updateUserHandler)).ServeHTTP,
	)
	m.Delete("/users/:username", orujo.NewPipe(
		orujo.M(logHandler),
		s.auth,
		http.HandlerFunc(s.deleteUserHandler)).ServeHTTP,
	)
	m.Get("/users", orujo.NewPipe(
		orujo.M(logHandler),
		s.auth,
		http.HandlerFunc(s.getUsersHandler)).ServeHTTP,
	)
	m.Post("/users", orujo.NewPipe(
		orujo.M(logHandler),
		s.auth,
		http.HandlerFunc(s.newUserHandler)).ServeHTTP,
	)
	m.Post("/login", orujo.NewPipe(
		orujo.M(logHandler),
		http.HandlerFunc(s.loginHandler)).ServeHTTP,
	)

	m.Post("/tasks", orujo.NewPipe(
		orujo.M(logHandler),
		s.auth,
		http.HandlerFunc(s.newTaskHandler)).ServeHTTP,
	)
	m.Get("/ips/:ip", orujo.NewPipe(
		orujo.M(logHandler),
		s.auth,
		http.HandlerFunc(s.getIpHandler)).ServeHTTP,
	)
	m.Get("/ips", orujo.NewPipe(
		orujo.M(logHandler),
		s.auth,
		http.HandlerFunc(s.getIpHandler)).ServeHTTP,
	)
	m.Get("/status", orujo.NewPipe(
		orujo.M(logHandler),
		s.auth,
		http.HandlerFunc(s.getStatusHandler)).ServeHTTP,
	)
	m.Post("/status", orujo.NewPipe(
		orujo.M(logHandler),
		s.auth,
		http.HandlerFunc(s.setStatusHandler)).ServeHTTP,
	)

	fmt.Println("Listening on " + s.config.Local.Host + ":" + s.config.Local.Port + "...")
	log.Fatalln(http.ListenAndServe(s.config.Local.Host+":"+s.config.Local.Port, m))

	return nil
}