Esempio n. 1
0
func newTunnels(cfg *Config) []proxy.Proxy {
	tunnels := make([]proxy.Proxy, len(cfg.Tunnels))
	for i, t := range cfg.Tunnels {
		tunnel, err := proxy.NewTunnel(t.Method, t.Key, t.Addr)
		if err != nil {
			log.Fatal(log.M{"msg": "create tunnel proxy failed", "err": err.Error()})
		}
		tunnels[i] = tunnel
	}
	return tunnels
}
Esempio n. 2
0
func main() {
	var cfg Config
	err := encodeio.ReadJSONWithComment(conf, &cfg)
	if err != nil {
		fmt.Println("parsing config file failed:", err)
		os.Exit(-1)
	}
	initLog(cfg.Log.File, cfg.Log.Debug)

	if (runLocal && len(cfg.Socks) == 0) || len(cfg.Tunnels) == 0 {
		log.Fatal(log.M{"msg": "empty socks or tunnels"})
	}

	var (
		sig     server.Signal
		tunnels = newTunnels(&cfg)
	)
	if runLocal {
		directList := server.NewList(server.LIST_DIRECT, cfg.DirectSites...)
		tunnelList := server.NewList(server.LIST_TUNNEL, cfg.TunnelSites...)
		directSuffixSites := server.NewList(server.LIST_DIRECT_SUFFIXES, cfg.DirectSuffixes...)

		socks := newSocks(&cfg)
		sig, err = server.RunMultipleLocal(socks, tunnels, directList, tunnelList, directSuffixSites)
		if err != nil {
			log.Fatal(log.M{"msg": "create local proxies failed", "err": err.Error()})
		}
		log.Info(log.M{"msg": "servers running", "server_num": len(socks)})
	} else {
		sig, err = server.RunMultipleRemote(tunnels)
		if err != nil {
			log.Fatal(log.M{"msg": "create remote proxies failed", "err": err.Error()})
		}
		log.Info(log.M{"msg": "servers running", "server_num": len(tunnels)})
	}

	waitOsSignal()
	sig.Close()
	log.Close()
}
Esempio n. 3
0
func newSocks(cfg *Config) []proxy.Proxy {
	socks := make([]proxy.Proxy, len(cfg.Socks))
	for i, s := range cfg.Socks {
		methods := []byte{proxy.AUTH_NOT_REQUIRED}
		if len(s.UserPass) == 0 {
			methods = append(methods, proxy.AUTH_USER_PASS)
		}
		sock, err := proxy.NewSocks5(methods, proxy.NewUserPass(s.UserPass), s.Addr)
		if err != nil {
			log.Fatal(log.M{"msg": "create socks5 proxy failed", "err": err.Error()})
		}
		socks[i] = sock
	}
	return socks
}
Esempio n. 4
0
func init() {
	flag.StringVar(&conf, "conf", "tunnel.json", "config file in json")
	flag.BoolVar(&runLocal, "local", false, "run as local server")
	flag.BoolVar(&runRemote, "remote", false, "run as remote server")
	flag.Parse()

	if (runLocal && runRemote) || (!runLocal && !runRemote) {
		log.Fatal("running mode is ambiguous.")
	}
	if runLocal {
		serverMode = "local"
	} else {
		serverMode = "remote"
	}
}