Beispiel #1
0
func main() {
	flag.Parse()
	validator := auth.NewDefaultValidator()
	manager := make(chan ManagerRequest, 1)
	go Manager(manager)
	http.HandleFunc("/", MakeHandler(manager, validator, ShowMainPage))
	http.HandleFunc("/getloc", MakeHandler(manager, validator, GetLocations))
	http.HandleFunc("/update", MakeHandler(manager, validator, UpdateLocation))
	http.HandleFunc("/poll", MakeHandler(manager, validator, Poll))
	http.HandleFunc("/login", MakeHandler(manager, validator, LoginHandler))
	http.HandleFunc("/js", JavascriptHandler)
	log.Printf("Listening on HTTPS at %s:%d", *host, *port)
	//err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)
	err := http.ListenAndServeTLS(fmt.Sprintf("%s:%d", *host, *port), "cert.pem", "key.pem", nil)
	if err != nil {
		log.Fatal(err)
	}
}
Beispiel #2
0
func Run(cfg *Config) {
	http.HandleFunc("/", httpHandler)

	if cfg.Secure {
		fmt.Fprintf(os.Stdout, "[i] Listening on %s (secure)\n", cfg.ListenAddr)

		if err := http.ListenAndServeTLS(cfg.ListenAddr, cfg.ServerCert, cfg.ServerKey, nil); err != nil {
			fmt.Fprintf(os.Stderr, "[e] %v\n", err)
			os.Exit(1)
		}
	} else {
		fmt.Fprintf(os.Stdout, "[i] Listening on %s (non-secure)\n", cfg.ListenAddr)

		if err := http.ListenAndServe(cfg.ListenAddr, nil); err != nil {
			fmt.Fprintf(os.Stderr, "[e] %v\n", err)
			os.Exit(1)
		}
	}
}
Beispiel #3
0
Datei: ncd.go Projekt: pjjw/ncd
func main() {
	flag.Parse()
	cmd := flag.Args()
	// set up logging
	if !*flagSyslog {
		logger = log.New(os.Stderr, log.Prefix(), log.Flags())
	}
	switch *flagServer {
	case true:

		http.HandleFunc(*flagEndpoint, root)
		logger.Print("bringing up endpoint")

		var err os.Error
		if *flagUseSSL {
			err = http.ListenAndServeTLS(*flagAddr, *flagSSLCert, *flagSSLKey, nil)
		} else {
			err = http.ListenAndServe(*flagAddr, nil)
		}
		if err != nil {
			log.Fatal("ListenAndServe:", err)
		}
	case false:
		if *flagSilent {
			devnull, _ := os.Open(os.DevNull)
			log.SetOutput(devnull)
		}

		switch {
		case *flagHostname == "":
			log.Fatal("missing hostname")
		case *flagServicename == "":
			log.Fatal("missing servicename")
		case len(cmd) < 1:
			log.Fatal("missing command(s)")
		}

		msg := new(CheckResultSet)

		if *flagCmdlist {
			for _, v := range cmd {
				f, err := os.Open(v)
				if err != nil {
					log.Print("error: ", err)
				} else {
					defer f.Close()
					runCommandList(f, msg)
				}
			}
		} else {
			runSingleCheck(msg, cmd)
		}

		buf, err := proto.Marshal(msg)
		if err != nil {
			log.Fatal("marshalling error: ", err)
		}

		PostToEndpoint(buf, *flagURL)
	}
}