Beispiel #1
0
func TestReadConfig(*testing.T) {

	cfg, err := config.ReadConfig("tinfoilhat.toml")
	if err != nil {
		log.Fatalln("Read config error:", err)
	}

	bug_on_invalid("2015-08-02 15:04:00 +0300 MSK", cfg.Pulse.Start.String())

	bug_on_invalid("4h0m0s", cfg.Pulse.Half.String())

	bug_on_invalid("1h0m0s", cfg.Pulse.Lunch.String())

	bug_on_invalid("2m0s", cfg.Pulse.RoundLen.String())

	bug_on_invalid("30s", cfg.Pulse.CheckTimeout.String())

	// other values has built-in types
}
Beispiel #2
0
func main() {

	fmt.Println(buildInfo())

	kingpin.Parse()

	if *configPath == "" {
		*configPath = "/etc/tinfoilhat/tinfoilhat.toml"
	}

	config, err := config.ReadConfig(*configPath)
	if err != nil {
		log.Fatalln("Cannot open config:", err)
	}

	db, err := steward.OpenDatabase(config.Database.Connection)
	if err != nil {
		log.Fatalln("Open database fail:", err)
	}

	defer db.Close()

	db.SetMaxOpenConns(config.Database.MaxConnections)

	switch kingpin.Parse() {
	case "advisory list":
		advisoryList(db)

	case "advisory review":
		advisoryReview(db)

	case "advisory hide":
		advisoryHide(db)

	case "advisory unhide":
		advisoryUnhide(db)

	case "scoreboard":
		scoreboardShow(db)
	}
}
Beispiel #3
0
func main() {

	fmt.Println(buildInfo())

	kingpin.Parse()

	if *configPath == "" {
		log.Println("Use default config path")
		*configPath = "/etc/tinfoilhat/tinfoilhat.toml"
	}

	config, err := config.ReadConfig(*configPath)
	if err != nil {
		log.Fatalln("Cannot open config:", err)
	}

	logFile, err := os.OpenFile(config.LogFile,
		os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.Fatalln("Cannot open file:", err)
	}
	defer logFile.Close()
	log.SetOutput(logFile)

	log.Println(buildInfo())

	var rlim syscall.Rlimit
	err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
	if err != nil {
		log.Fatalln("Getrlimit fail:", err)
	}

	log.Println("RLIMIT_NOFILE CUR:", rlim.Cur, "MAX:", rlim.Max)

	db, err := steward.OpenDatabase(config.Database.Connection)
	if err != nil {
		log.Fatalln("Open database fail:", err)
	}

	defer db.Close()

	db.SetMaxOpenConns(config.Database.MaxConnections)

	if *dbReinit {
		reinitDatabase(db, config)
	}

	checker.SetTimeout(config.CheckerTimeout.Duration)

	if config.AdvisoryReceiver.Disabled {
		scoreboard.DisableAdvisory()
	}

	priv, err := vexillary.GenerateKey()
	if err != nil {
		log.Fatalln("Generate key fail:", err)
	}

	attackFlow := make(chan scoreboard.Attack, config.API.AttackBuffer)

	go receiver.FlagReceiver(db, priv, config.FlagReceiver.Addr,
		config.FlagReceiver.ReceiveTimeout.Duration,
		config.FlagReceiver.SocketTimeout.Duration,
		attackFlow)

	go receiver.AdvisoryReceiver(db, config.AdvisoryReceiver.Addr,
		config.AdvisoryReceiver.ReceiveTimeout.Duration,
		config.AdvisoryReceiver.SocketTimeout.Duration)

	go scoreboard.Scoreboard(db, attackFlow,
		config.Scoreboard.WwwPath,
		config.Scoreboard.Addr,
		config.Scoreboard.UpdateTimeout.Duration,
		config.Pulse.Start.Time,
		config.Pulse.Half.Duration,
		config.Pulse.Lunch.Duration,
		config.Pulse.DarkestTime.Duration)

	err = pulse.Pulse(db, priv,
		config.Pulse.Start.Time,
		config.Pulse.Half.Duration,
		config.Pulse.Lunch.Duration,
		config.Pulse.RoundLen.Duration,
		config.Pulse.CheckTimeout.Duration)
	if err != nil {
		log.Fatalln("Game error:", err)
	}

	log.Println("It's now safe to turn off you computer")
	for {
		time.Sleep(time.Hour)
	}
}