Exemple #1
0
func main() {
	viper.SetConfigName("config")       // name of config file (without extension)
	viper.AddConfigPath("/etc/exego/")  // path to look for the config file in
	viper.AddConfigPath("$HOME/.exego") // call multiple times to add many search paths
	viper.AddConfigPath("./")
	viper.ReadInConfig() // Find and read the config file

	viper.SetDefault("CAcert", "myCA.cer")
	viper.SetDefault("AuthToken", "blabla")
	viper.SetDefault("Addr", "localhost:20000")

	authToken = viper.GetString("AuthToken")
	bindAddr := viper.GetString("Addr")

	log.Printf("Exegod v%s\n", EXEGOD_VERSION)
	fmt.Printf("Starting server on %s\n", bindAddr)

	http.HandleFunc("/run", HandleShellRequest)

	//_, cerr := os.Open()
	//_, kerr := os.Open(exego.A"mycert1.key")

	//if os.IsNotExist(cerr) || os.IsNotExist(kerr) {
	//  log.Fatalln(cerr, kerr)
	//  return
	//}

	//http.ListenAndServeTLS(bindAddr, exego.Asset("certs/mycert1.cer"), exego.Asset("certs/mycert1.key"), nil)
	cer, _ := exego.Asset("certs/mycert1.cer")
	key, _ := exego.Asset("certs/mycert1.key")
	cert, _ := tls.X509KeyPair(cer, key)
	config := tls.Config{Certificates: []tls.Certificate{cert}}
	listener, _ := tls.Listen("tcp", bindAddr, &config)
	server := &http.Server{Addr: bindAddr, Handler: nil}
	server.Serve(listener)
}
Exemple #2
0
func main() {
	viper.SetConfigName("config")       // name of config file (without extension)
	viper.AddConfigPath("/etc/exego/")  // path to look for the config file in
	viper.AddConfigPath("$HOME/.exego") // call multiple times to add many search paths
	viper.AddConfigPath("./")
	viper.ReadInConfig() // Find and read the config file

	viper.SetDefault("CAcert", "myCA.cer")
	viper.SetDefault("AuthToken", "blabla")
	viper.SetDefault("Addr", "localhost:20000")

	certs := x509.NewCertPool()
	pemData, err := ioutil.ReadFile(viper.GetString("CAcert"))
	if err != nil {
		pemData, err = exego.Asset(path.Join("certs", viper.GetString("CAcert")))
	}
	certs.AppendCertsFromPEM(pemData)
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{RootCAs: certs}, //,InsecureSkipVerify: true},
	}
	client := &http.Client{Transport: tr}
	body := strings.NewReader(os.Args[len(os.Args)-1])
	req, err := http.NewRequest("POST", "https://"+viper.GetString("Addr")+"/run", body)

	if err != nil {
		fmt.Println(err)
		return
	}
	req.Header.Add("X-AUTH-TOKEN", viper.GetString("AuthToken"))
	resp, err := client.Do(req)

	if err != nil {
		fmt.Println(err)
		return
	}
	defer resp.Body.Close()

	body2, err := ioutil.ReadAll(resp.Body)
	fmt.Println(string(body2))

}