Exemple #1
0
func CreateDefault(listen string, configFile string, verbose bool) {
	proxy := goproxy.NewProxyHttpServer()
	proxy.Verbose = verbose

	records := getConfig(configFile)
	fmt.Println("Configuration from", configFile, ":")
	for i, config := range records {
		if i == 0 {
			// header line
			continue
		}
		defaultUrl := config[0]
		regexpUrl, e := regexp.Compile(defaultUrl)
		if e != nil {
			fmt.Errorf("Can't parse regexp", defaultUrl, e.Error())
		}
		contentType := config[1]
		newFile := config[2]
		fmt.Println("- replace", defaultUrl, "by", newFile)
		proxy.OnRequest(goproxy.UrlMatches(regexpUrl)).DoFunc(
			func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
				fmt.Print("Intercept ", defaultUrl, " and serve ", newFile)
				response := NewResponse(r, contentType, http.StatusOK, newFile)
				return r, response
			})
	}
	fmt.Println("")
	fmt.Println("Listen", listen)
	fmt.Println("^C to stop")
	fmt.Println("")

	log.Fatal(http.ListenAndServe(listen, proxy))
}
Exemple #2
0
func main() {
	var proxy *goproxy.ProxyHttpServer
	app.Main(func(a app.App) {
		var sz size.Event
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case lifecycle.Event:
				if e.Crosses(lifecycle.StageAlive) == lifecycle.CrossOn && proxy == nil {
					proxy = goproxy.NewProxyHttpServer()
					//proxy.Verbose = true
					re := regexp.MustCompile(`.*`)
					proxy.OnResponse(goproxy.UrlMatches(re)).DoFunc(
						func(res *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
							if label != nil {
								label.Text = fmt.Sprintf("%s\n%s\n", ctx.Req.URL, label.Text)
								log.Println(ctx.Req.URL)
							}
							return res
						})
					go func() {
						log.Fatal(http.ListenAndServe(":8888", proxy))
					}()
				}
			case paint.Event:
				onPaint(sz)
				a.EndPaint(e)
			case size.Event:
				sz = e
			}
		}
	})
}
Exemple #3
0
func main() {
	log.Printf("running apt-proxy %s", version)

	if debug {
		DebugLogging = true
	}

	DebugLogging = true

	cache, err := NewDiskCache(dir)

	if err != nil {
		log.Fatal(err)
	}

	ubuntuRewriter := ubuntu.NewRewriter()

	proxy := goproxy.NewProxyHttpServer()

	matchUbuntuMirror := goproxy.UrlMatches(matchUbuntuMirrorPattern)
	matchAptPackage := goproxy.UrlMatches(matchAptPackagePattern)
	matchAptPackageIndex := goproxy.UrlMatches(matchAptPackageIndexPattern)
	matchRubyGemPackageIndex := goproxy.UrlMatches(matchRubyGemPackageIndexPattern)
	matchRubyGemPackage := goproxy.UrlMatches(matchRubyGemPackagePattern)
	matchNodePackage := goproxy.UrlMatches(matchNodePackagePattern)
	matchNodePackageIndex := goproxy.UrlMatches(matchNodePackageIndexPattern)
	matchWindowsUpdatePackage := goproxy.UrlMatches(matchWindowsUpdatePackagePattern)
	commonPackage := goproxy.UrlMatches(commonPackagePattern)

	proxy.OnRequest(matchUbuntuMirror).DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			url := r.URL.String()
			ubuntuRewriter.Rewrite(r)
			debugf("rewrote %q to %q", url, r.URL.String())
			r.Host = r.URL.Host
			return r, nil
		})

	proxy.OnRequest(matchAptPackage).DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			return TryServeCachedResponse(true, cache, r)
		})

	proxy.OnResponse(matchAptPackage).DoFunc(
		func(r *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
			return TryCacheResponse(true, cache, r)
		})

	proxy.OnRequest(matchAptPackageIndex).DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			return TryServeCachedResponse(true, cache, r)
		})

	proxy.OnResponse(matchAptPackageIndex).DoFunc(
		func(r *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
			return TryCacheResponse(true, cache, r)
		})

	proxy.OnRequest(matchRubyGemPackage).DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			return TryServeCachedResponse(true, cache, r)
		})

	proxy.OnResponse(matchRubyGemPackage).DoFunc(
		func(r *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
			return TryCacheResponse(true, cache, r)
		})

	proxy.OnRequest(matchRubyGemPackageIndex).DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			return TryServeCachedResponse(true, cache, r)
		})

	proxy.OnResponse(matchRubyGemPackageIndex).DoFunc(
		func(r *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
			return TryCacheResponse(true, cache, r)
		})

	proxy.OnRequest(matchNodePackage).DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			return TryServeCachedResponse(true, cache, r)
		})

	proxy.OnResponse(matchNodePackage).DoFunc(
		func(r *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
			return TryCacheResponse(true, cache, r)
		})

	proxy.OnRequest(matchNodePackageIndex).DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			return TryServeCachedResponse(true, cache, r)
		})

	proxy.OnResponse(matchNodePackageIndex).DoFunc(
		func(r *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
			return TryCacheResponse(true, cache, r)
		})

	proxy.OnRequest(matchWindowsUpdatePackage).DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			return TryServeCachedResponse(true, cache, r)
		})

	proxy.OnResponse(matchWindowsUpdatePackage).DoFunc(
		func(r *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
			return TryCacheResponse(true, cache, r)
		})

	proxy.OnRequest(commonPackage).DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			return TryServeCachedResponse(true, cache, r)
		})

	proxy.OnResponse(commonPackage).DoFunc(
		func(r *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
			return TryCacheResponse(true, cache, r)
		})

	log.Printf("proxy listening on %s", listen)
	log.Fatal(http.ListenAndServe(listen, proxy))
}
Exemple #4
0
func main() {
	proxy := goproxy.NewProxyHttpServer()
	proxy.Verbose = true
	proxy.NonproxyHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		w.Header().Set("Content-Type", "multipart/form-data")
		w.Header().Set("Content-Disposition:", "attachment;filename=\""+"shiningbt.mobileconfig\"")
		// req.URL, _ = url.Parse("/shiningbt.mobileconfig")
		w.Write([]byte(mobileconfigContent))
		// http.FileServer(http.Dir(".")).ServeHTTP(w, req)
	})

	proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("^.*[universe.walkrgame.com|api.walkrhub.com|api.walkrconnect.com].*$"))).HandleConnect(goproxy.AlwaysMitm)
	proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("^.*[universe.walkrgame.com|api.walkrhub.com|api.walkrconnect.com].*$"))).DoFunc(func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
		req.Header.Add("Cache-Control", "no-cache,no-store")
		req.Header.Add("Pragma", "no-cache")
		req.Header.Del("If-None-Match")
		return req, nil
	})
	proxy.OnResponse(goproxy.UrlMatches(regexp.MustCompile("^.*v1/pilots?.*$"))).DoFunc(func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
		if body, err := ioutil.ReadAll(resp.Body); err == nil {
			var record PilotListResponse
			if err := json.Unmarshal([]byte(body), &record); err == nil {
				for index, _ := range record.Pilots {
					record.Pilots[index].Energy = 60000
				}
				dx, _ := json.Marshal(record)
				resp.Body = ioutil.NopCloser(bytes.NewBuffer(dx))
			} else {
				fmt.Println("Unmarshal Err", err)

			}
		} else {
			fmt.Println("Read body Err", err)
		}

		return resp

	})
	proxy.OnResponse(goproxy.UrlMatches(regexp.MustCompile("^.*v1/pilots/(.*)/check$"))).DoFunc(func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
		record := &ConvertedEnergyResponse{Success: true, CheckedEnergy: 60000}
		dx, _ := json.Marshal(record)
		resp.Body = ioutil.NopCloser(bytes.NewBuffer(dx))
		return resp

	})

	// https://universe.walkrgame.com/api/v1/fleets/443091/check_reward
	if EpicHack == true {
		proxy.OnResponse(goproxy.UrlMatches(regexp.MustCompile("^.*v1/fleets/(.*)/check_reward$"))).DoFunc(func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
			if body, err := ioutil.ReadAll(resp.Body); err == nil {
				var record CheckEpicRewardResponse
				if err := json.Unmarshal([]byte(body), &record); err == nil {
					record.Data.IsChecked = false
					record.Data.IsFirstTime = false
					// 能量块
					record.Data.Reward.Type = "cubes"
					record.Data.Reward.Value = "60000"
					record.Data.Contribution.Value = 1
					// DFR
					// record.Data.Reward.Type = "replicator"
					// record.Data.Reward.Value = fmt.Sprintf("map-%v", rand.New(rand.NewSource(time.Now().UnixNano())).Intn(100)+210000)
					dx, _ := json.Marshal(record)
					resp.Body = ioutil.NopCloser(bytes.NewBuffer(dx))
				} else {
					fmt.Println("Unmarshal Err", err)

				}
			} else {
				fmt.Println("Read body Err", err)
			}

			return resp

		})
	}

	// 这里应该加一个验证,用来启动或者停止
	authed := false
	currentUUID := strings.Split(uuid.NewUUID().String(), "-")[4]
	md5h := md5.New()
	md5h.Write([]byte(PackageFor + "-" + currentUUID))
	md5str := hex.EncodeToString(md5h.Sum([]byte("")))

	client := &http.Client{}
	v := url.Values{}
	v.Add("u", PackageFor)
	v.Add("id", currentUUID)
	v.Add("md", md5str)
	v.Add("v", Version)

	host := fmt.Sprintf("http://%v:9896/verify?%v", RemoteAddr, v.Encode())
	if req, err := http.NewRequest("GET", host, nil); err != nil {
		fmt.Println(fmt.Sprintf("启动失败: %v", err))
	} else {
		if resp, err := client.Do(req); err != nil {
			fmt.Println(fmt.Sprintf("启动失败: %v", err))
		} else {
			body, err := ioutil.ReadAll(resp.Body)
			if err != nil || string(body) != "1" {
				fmt.Println(fmt.Sprintf("启动失败: %v", string(body)))
			} else {
				authed = true
			}
		}
	}
	if authed == true {
		localIp := "127.0.0.1"
		if conn, err := net.Dial("udp", fmt.Sprintf("%v:9896", RemoteAddr)); err == nil {
			defer conn.Close()
			localIp = strings.Split(conn.LocalAddr().String(), ":")[0]
		} else {

			fmt.Println(err)
		}
		port := 9897

		fmt.Println("你的IP地址是: ", localIp)
		fmt.Println("!!!!!! 第一次使用工具的时候, 请按照[条目0]安装一个描述文件 !!!!!!")
		fmt.Println("0. 在玩儿Walkr的iPad/iPhone上使用Safari打开 [http://" + localIp + ":" + fmt.Sprintf("%v", port) + "], 会提示下载一个描述文件, 一路安装即可")
		fmt.Println("=========================== 无辜的分割线 ===========================")
		fmt.Println("1. 安装之后在Wifi的代理设置为[手动], 服务器地址为 [" + localIp + "], 端口为 [" + fmt.Sprintf("%v", port) + "]")
		fmt.Println("2. 打开游戏进入舰桥, 如果能显示能量并且可以领取, 就说明成功")
		fmt.Println("!!!!!! 不用的时候一定关掉[软件]以及[设备上的代理], 否则可能上不了网 !!!!!!")

		log.Fatal(http.ListenAndServe(":"+fmt.Sprintf("%v", port), proxy))
	} else {
		time.Sleep(5 * time.Second)
	}

}