Esempio n. 1
0
func main() {
	defer glog.Flush()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		return
	}
	if pv {
		fmt.Fprintln(os.Stderr, "gost", Version)
		return
	}

	listenArgs = parseArgs(listenAddr)
	forwardArgs = parseArgs(forwardAddr)

	if len(listenArgs) == 0 {
		glog.Exitln("no listen addr")
	}

	var wg sync.WaitGroup
	for _, args := range listenArgs {
		wg.Add(1)
		go func(arg Args) {
			defer wg.Done()
			listenAndServe(arg)
		}(args)
	}
	wg.Wait()
}
Esempio n. 2
0
func main() {
	defer glog.Flush()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		return
	}
	if pv {
		fmt.Println("gost", version, "git:", gitRev)
		return
	}

	listenArgs = parseArgs(listenAddr)
	forwardArgs = parseArgs(forwardAddr)

	if len(listenArgs) == 0 {
		glog.Exitln("no listen addr")
	}
	glog.Infof("gost %s(git: %s) started", version, gitRev)

	var wg sync.WaitGroup
	for _, args := range listenArgs {
		wg.Add(1)
		go func(arg Args) {
			defer wg.Done()
			listenAndServe(arg)
		}(args)
	}
	wg.Wait()
}
func main() {
	// Defaults are same as RouterOS
	var host = flag.String("router-host", "192.168.88.1", "Hostname or IP of the router")
	var port = flag.Int("port", 8728, "Port to use")
	var user = flag.String("user", "admin", "User to authenticate with")
	var pass = flag.String("password", "", "Passwrod to authenticate with")
	var vpn_host = flag.String("vpn-host", "", "")
	flag.Parse()

	// Construct a client and connect
	client := routeros_api.Client{
		Host:     *host,
		Port:     *port,
		User:     *user,
		Password: *pass,
	}
	glog.Infoln("Checking VPN")
	err := client.Connect()
	if err != nil {
		glog.Fatalln("Error:", err)
	}

	// Close the connection when we're done
	defer client.Close()

	// Collect the current config - if the VPN is running then we're done
	reply := get_opvenvpn_config(client)
	if reply.Attributes["=running"] == "true" {
		glog.Exitln("VPN running to", reply.Attributes["=connect-to"])
	}

	// The VPN is not running - get the currently configured server IP
	// and compare to the given IP. If they match whatever is bust is
	// out of scope for this little script
	glog.Infoln("VPN not running to", reply.Attributes["=connect-to"])
	config_ip := net.ParseIP(reply.Attributes["=connect-to"])
	iface_id := reply.Attributes["=.id"]
	lookup_ip := get_ip(*vpn_host, false)

	if config_ip.Equal(lookup_ip) {
		glog.Exitln("IP is correct, can not fix")
	}

	// Otherwise, we may just be able to fix it!
	set_openvpn_ip(client, iface_id, lookup_ip)

}
func main() {
	flag.Parse()
	config := marathon.NewDefaultConfig()
	config.URL = marathonURL
	config.LogOutput = new(logBridge)
	client, err := marathon.NewClient(config)
	if err != nil {
		glog.Exitln(err)
	}

	applications, err := client.Applications(nil)
	if err != nil {
		glog.Exitln(err)
	}

	for _, a := range applications.Apps {
		glog.Infof("App ID: %v\n", a.ID)
	}
}
Esempio n. 5
0
func main() {
	flag.Parse()
	if flag.NArg() == 0 {
		glog.Exitln("No NZB files given")
	}

	for _, path := range flag.Args() {
		file, err := os.Open(path)
		if err != nil {
			glog.Errorln(err)
			continue
		}
		var r io.Reader = file
		switch filepath.Ext(file.Name()) {
		case ".gz":
			fz, err := gzip.NewReader(r)
			if err != nil {
				glog.Errorln(err)
				continue
			}
			defer fz.Close()
			r = fz
		case ".bz2":
			r = bzip2.NewReader(r)
		}
		nzb, err := nzb.Parse(r)
		file.Close()
		if err != nil {
			glog.Errorln(err)
			continue
		}

		if *check {
			err = checkNzb(nzb)
			if err != nil {
				glog.Errorln(err)
				continue
			}
		} else {
			err = downloadNzb(nzb, extStrip.ReplaceAllString(path, ""))
			if err != nil {
				glog.Errorln(err)
				continue
			}
		}

		if *rm {
			err = os.Remove(path)
			if err != nil {
				glog.Errorln(err)
			}
		}
	}
	filewg.Wait()
}
Esempio n. 6
0
// check all the files contained in an nzb
func checkNzb(nzbFile *nzb.Nzb) error {
	for _, file := range nzbFile.File {
		size := 0
		for _, f := range file.Segments {
			size += f.Bytes
		}
		glog.Infof("Checking file %s (%d byte(s), %d segment(s))",
			file.Subject.Filename(), size, len(file.Segments))
		filewg.Add(len(file.Segments))
		for _, f := range file.Segments {
			c, err := getConn()
			if err != nil {
				glog.Exitln(err)
			}
			go checkMsg(c, file.Groups, f.MsgID)
		}
	}
	filewg.Wait()
	return nil
}
Esempio n. 7
0
// download a single file contained in an nzb.
func downloadFile(dir string, nzbfile *nzb.File) error {
	size := 0
	for _, f := range nzbfile.Segments {
		size += f.Bytes
	}
	glog.Infof("Downloading file %s (%d byte(s), %d segment(s))",
		nzbfile.Subject.Filename(), size, len(nzbfile.Segments))
	file, err := newFile(dir, nzbfile)
	if err != nil {
		return err
	}
	for _, f := range nzbfile.Segments {
		c, err := getConn()
		if err != nil {
			glog.Exitln(err)
		}
		go decodeMsg(c, file, nzbfile.Groups, f.MsgID)
	}
	return nil
}
Esempio n. 8
0
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
	if err := RootCmd.Execute(); err != nil {
		glog.Exitln(err)
	}
}
Esempio n. 9
0
func checkFlags() {
	if *pushMetric && (*expositionType == "prometheus") {
		glog.Exitln("Exposition type: prometheus is not compatible with push_metric flag")
	}
}
Esempio n. 10
0
func main() {
	var host, port, sdPort, hashSalt string
	flag.StringVar(&host, "host", "",
		"host on which game server handles requests")
	flag.StringVar(&port, "port", "8081",
		"port on which game server handles requests")
	flag.StringVar(&sdPort, "shutdown_port", "8082",
		"port on which server accepts for shutdown request")
	flag.StringVar(&hashSalt, "hash_salt", "",
		"salt for request verifier")

	var poolLimit, connLimit, pgW, pgH uint
	flag.UintVar(&poolLimit, "pool_limit", 10,
		"max pool number on server")
	flag.UintVar(&connLimit, "conn_limit", 4,
		"max connection number on pool")
	flag.UintVar(&pgW, "pg_w", 40, "playground width")
	flag.UintVar(&pgH, "pg_h", 28, "playground height")

	var delay time.Duration
	flag.DurationVar(&delay, "delay", time.Millisecond*150,
		"stream delay")

	flag.Parse()

	if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
		glog.Infoln("Preparing to start server")
	}

	// Working listener is used for game servering
	workingListener, err := net.Listen("tcp", host+":"+port)
	if err != nil {
		glog.Exitln("Cannot create working listener:", err)
	}

	// Shutdown listener is used only for shutdown command. Listening
	// only local requests
	shutdownListener, err := net.Listen("tcp", "127.0.0.1:"+sdPort)
	if err != nil {
		glog.Exitln("Cannot create shutdown listener:", err)
	}

	if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
		glog.Infoln("Listeners was created")
	}

	// Gets root context and cancel func for all goroutines on server
	cxt, cancel := context.WithCancel(context.Background())

	// Init pool factory
	factory, err := NewPGPoolFactory(cxt, uint8(connLimit),
		uint8(pgW), uint8(pgH))
	if err != nil {
		glog.Exitln(err)
	}
	if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
		glog.Infoln("Pool factory was created")
	}

	// Init pool manager which allocates connections on pools
	poolManager, err := NewGamePoolManager(factory, uint8(poolLimit))
	if err != nil {
		glog.Exitln(err)
	}
	if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
		glog.Infoln("Pool manager was created")
	}

	streamer, err := NewStreamer(cxt, delay)
	if err != nil {
		glog.Exitln(err)
	}
	if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
		glog.Infoln("Streamer was created")
	}

	// Init connection manager
	connManager, err := NewConnManager(streamer)
	if err != nil {
		glog.Exitln(err)
	}
	if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
		glog.Infoln("Connection manager was created")
	}

	// Init request verifier
	verifier := NewVerifier(hashSalt)
	if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
		glog.Infoln("Request verifier was created")
	}

	// Setup GOMAXPROCS
	runtime.GOMAXPROCS(runtime.NumCPU())

	// Start goroutine looking for shutdown command
	go func() {
		// Waiting for shutdown command. We don't need of connection
		if _, err := shutdownListener.Accept(); err != nil {
			glog.Errorln("Accepting shutdown connection error:", err)
		}
		if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
			glog.Infoln("Accepted shutdown command")
		}

		// Closing shutdown listener
		if err := shutdownListener.Close(); err != nil {
			glog.Errorln("Closing shutdown listener error:", err)
		}
		if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
			glog.Infoln("Shutdown listener was closed")
		}

		// Finishing all goroutines
		if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
			glog.Infoln("Canceling root context")
		}
		go cancel()
		time.Sleep(time.Second)
		if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
			glog.Infoln("Root context was canceled")
		}

		// Closing working listener
		if err := workingListener.Close(); err != nil {
			glog.Errorln("Closing working listener error:", err)
		}
		if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
			glog.Infoln(
				"Working listener was closed.",
				"Server will shutdown with error:",
				"use of closed network connection",
			)
		}
	}()

	if glog.V(INFOLOG_LEVEL_ABOUT_SERVER) {
		glog.Infoln("Starting server")
	}
	// Start server
	err = http.Serve(
		workingListener,
		pwshandler.PoolHandler(poolManager, connManager, verifier),
	)
	if err != nil {
		glog.Errorln("Servering error:", err)
	}

	// Flush log
	glog.Flush()
}