Пример #1
0
func main() {
	version()

	p := proxy.NewProxy()
	ipProfiles := profile.NewIpProfiles()
	ipProfiles.BindProxyHostOperator(p.NewProxyHostOperator())
	p.BindUrlOperator(ipProfiles.OperatorUrl())
	p.BindProfileOperator(ipProfiles.OperatorProfile())
	p.BindDomainOperator(ipProfiles.OperatorDomain())

	go dnsproxy.DnsProxy(dnsproxy.NewPolicy(p.NewDomainOperator()))

	var c cmd.Command
	c.OpenConsole()
	for {
		fmt.Print("\n$ ")
		command := c.Read()
		if command == "exit" {
			return
		} else if command == "help" {
			usage()
		} else if command == "version" {
			version()
		} else if rest, ok := cmd.CheckCommand(command, "bench"); ok {
			url := "http://"
			if strings.HasPrefix(rest, url) {
				url = rest
			} else {
				url += rest
			}

			benchN(url)
		} else if command != "" {
			usage()
			fmt.Println("UNKNOWN command: " + command)
		}
	}
}
Пример #2
0
func main() {
	version()

	flag.Parse()

	p := proxy.NewProxy(VersionCode)

	ipProfiles := profile.NewIpProfiles()
	ipProfiles.BindProxyHostOperator(p.NewProxyHostOperator())
	ipProfiles.SetDefaultCopyProfile("localhost")

	p.BindUrlOperator(ipProfiles.OperatorUrl())
	p.BindProfileOperator(ipProfiles.OperatorProfile())
	p.BindDomainOperator(ipProfiles.OperatorDomain())

	if *nodns {
		p.DisableDNS()
	} else {
		go dnsproxy.DnsProxy(dnsproxy.NewPolicy(p.NewDomainOperator()))
	}

	var c cmd.Command
	c.OpenConsole()
	for {
		fmt.Print("\n$ ")
		command := c.Read()
		command, rest := cmd.TakeFirstArg(command)
		switch command {
		case "":
		case "exit":
			return
		case "usage":
			fallthrough
		case "help":
			usage()
		case "version":
			version()
		case "bench":
			if len(rest) == 0 {
				fmt.Println("usage: bench <url>")
			} else {
				url := "http://"
				if strings.HasPrefix(rest, url) {
					url = rest
				} else {
					url += rest
				}

				benchN(url)
			}
		case "bind":
			port, err := strconv.Atoi(rest)
			if err != nil {
				fmt.Println("usage: bind <port>\nport: in 1~65535")
			} else {
				fmt.Println("")
				bindNew := p.Bind(port)
				if bindNew {
					fmt.Println("port", port, "binds ok")
				} else {
					fmt.Println("port had already bound")
				}
			}
		case "delete":
			mod, rest := cmd.TakeFirstArg(rest)
			switch mod {
			case "profile":
				if ipProfiles.Delete(rest) {
					fmt.Println(`profile "` + rest + `" deleted`)
				} else {
					fmt.Println(`profile "` + rest + `" don't exist`)
				}
			default:
				usage()
			}
		default:
			usage()
			fmt.Println(`UNKNOWN command: "` + command + `" ` + rest)
		}
	}
}