提示:形容词+名词+动词+风格,描述得越详细时,效果越好。
+示例:{{ DEMO_KEYWORD }}
+diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..9f4609a9d1062c3c12392ff9e23a5bdd937722c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# Editor directories and files +.vscode/* +!.vscode/extensions.json +!.vscode/launch.json +.idea +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +.DS_Store + +release +node_modules +/_worker.js +/worker.js \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..9eb1c3b133620ae97eacd423399c65c379ac0213 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:alpine AS builder +WORKDIR /app +COPY . . +RUN go build -ldflags="-s -w" -tags netgo -trimpath -o go-proxy-bingai main.go + +FROM alpine +WORKDIR /app +COPY --from=builder /app/go-proxy-bingai . + +EXPOSE 8080 +CMD ["/app/go-proxy-bingai"] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..35f05c206594028eda6c81d57d1faff1e2318da3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License Copyright (c) 2023 adams549659584 + +Permission is hereby granted, free +of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice +(including the next paragraph) shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000000000000000000000000000000000000..015d2dac2be736eea328657003ca841d7fb39020 --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,260 @@ +version: '3' + +vars: + BUILD_VERSION: + sh: git describe --tags + BUILD_DATE: + sh: date "+%F %T" + COMMIT_ID: + sh: git rev-parse HEAD + +tasks: + clean: + cmds: + - rm -rf frontend/node_modules + - rm -rf release + # extended globbing is not supported + # - rm -rf web/!(web.go) + - cp web/web.go web.go + - rm -rf web/* + - mv web.go web/web.go + build_web: + dir: frontend + cmds: + # 修订号,例如 0.0.1 + - npm version patch + # - pnpm build + - pnpm install && pnpm build + build_web_minor: + dir: frontend + cmds: + # 次版本号,例如 0.1.0 + - npm version minor + # - pnpm build + - pnpm install && pnpm build + build_web_major: + dir: frontend + cmds: + # 主版本号,例如 1.0.0 + - npm version major + # - pnpm build + - pnpm install && pnpm build + build_tpl: + label: build-{{.TASK}} + cmds: + - | + GOOS={{.GOOS}} GOARCH={{.GOARCH}} GOARM={{.GOARM}} GOMIPS={{.GOMIPS}} GOAMD64={{.GOAMD64}} \ + go build -tags netgo -trimpath -o release/go-proxy-bingai_{{.TASK}} -ldflags \ + "-w -s -X 'main.version={{.BUILD_VERSION}}' -X 'main.buildDate={{.BUILD_DATE}}' -X 'main.commitID={{.COMMIT_ID}}'" + linux_386: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: 386 + } + linux_amd64: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: amd64 + } + linux_amd64_v2: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: amd64, + GOAMD64: v2 + } + linux_amd64_v3: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: amd64, + GOAMD64: v3 + } + linux_amd64_v4: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: amd64, + GOAMD64: v4 + } + linux_armv5: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: arm, + GOARM: 5 + } + linux_armv6: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: arm, + GOARM: 6 + } + linux_armv7: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: arm, + GOARM: 7 + } + linux_armv8: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: arm64 + } + linux_mips_hardfloat: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: mips, + GOMIPS: hardfloat + } + linux_mipsle_softfloat: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: mipsle, + GOMIPS: softfloat + } + linux_mipsle_hardfloat: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: mipsle, + GOMIPS: hardfloat + } + linux_mips64: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: mips64 + } + linux_mips64le: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: linux, + GOARCH: mips64le + } + windows_386.exe: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: windows, + GOARCH: 386 + } + windows_amd64.exe: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: windows, + GOARCH: amd64 + } + windows_amd64_v2.exe: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: windows, + GOARCH: amd64, + GOAMD64: v2 + } + windows_amd64_v3.exe: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: windows, + GOARCH: amd64, + GOAMD64: v3 + } + windows_amd64_v4.exe: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: windows, + GOARCH: amd64, + GOAMD64: v4 + } + darwin_amd64: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: darwin, + GOARCH: amd64, + } + darwin_arm64: + cmds: + - task: build_tpl + vars: { + TASK: "{{.TASK}}", + GOOS: darwin, + GOARCH: arm64, + } + docker: + cmds: + - docker build -t adams549659584/go-proxy-bingai:{{.BUILD_VERSION}} -f docker/Dockerfile . + - docker tag adams549659584/go-proxy-bingai:{{.BUILD_VERSION}} adams549659584/go-proxy-bingai + default: + cmds: + - task: clean + - task: build_web + # - task: linux_386 + - task: linux_amd64 + # - task: linux_amd64_v2 + # - task: linux_amd64_v3 + # - task: linux_amd64_v4 + # - task: linux_armv5 + # - task: linux_armv6 + # - task: linux_armv7 + - task: linux_armv8 + # - task: linux_mips_hardfloat + # - task: linux_mipsle_softfloat + # - task: linux_mipsle_hardfloat + # - task: linux_mips64 + # - task: linux_mips64le + # - task: windows_386.exe + # - task: windows_amd64.exe + # - task: windows_amd64_v2.exe + # - task: windows_amd64_v3.exe + # - task: windows_amd64_v4.exe + # - task: darwin_amd64 + # - task: darwin_arm64 + release: + cmds: + - task: default diff --git a/api/bypass.go b/api/bypass.go new file mode 100644 index 0000000000000000000000000000000000000000..d46313423ef363117dab3545b20f9d21906ec48b --- /dev/null +++ b/api/bypass.go @@ -0,0 +1,100 @@ +package api + +import ( + "adams549659584/go-proxy-bingai/common" + "adams549659584/go-proxy-bingai/common/helper" + "encoding/json" + "io" + "net/http" + "strings" + + binglib "github.com/Harry-zklcdc/bing-lib" + "github.com/Harry-zklcdc/bing-lib/lib/aes" + "github.com/Harry-zklcdc/bing-lib/lib/hex" +) + +type requestStruct struct { + IG string `json:"IG,omitempty"` + T string `json:"T,omitempty"` +} + +func BypassHandler(w http.ResponseWriter, r *http.Request) { + if !helper.CheckAuth(r) { + helper.UnauthorizedResult(w) + return + } + + if r.Method != "POST" { + helper.CommonResult(w, http.StatusMethodNotAllowed, "Method Not Allowed", nil) + return + } + + var request requestStruct + resq, err := io.ReadAll(r.Body) + if err != nil { + helper.CommonResult(w, http.StatusInternalServerError, err.Error(), nil) + return + } + + err = json.Unmarshal(resq, &request) + if err != nil { + helper.CommonResult(w, http.StatusInternalServerError, err.Error(), nil) + common.Logger.Error("BypassHandler Unmarshal Error: %v", err) + return + } + + token, err := aes.Decrypt(request.T, request.IG) + if err != nil { + helper.ErrorResult(w, http.StatusInternalServerError, "Server Error") + common.Logger.Error("BypassHandler Decrypt Error: %v", err) + return + } + if token != common.AUTHOR { + helper.ErrorResult(w, http.StatusUnavailableForLegalReasons, "T error") + common.Logger.Error("BypassHandler T error: %v", token) + return + } + + bypassServer := common.BypassServer + + header := http.Header{} + header.Add("Cookie", r.Header.Get("Cookie")) + req := &http.Request{ + Header: header, + } + if cookie, err := req.Cookie(common.PASS_SERVER_COOKIE_NAME); err == nil { + if cookie.Value != "" { + bypassServer = cookie.Value + } + } + if bypassServer == "" { + helper.CommonResult(w, http.StatusInternalServerError, "BypassServer is empty", nil) + return + } + + reqCookies := []string{} + for _, cookie := range req.Cookies() { + if !common.IsInArray(removeCookieName, cookie.Name) { + reqCookies = append(reqCookies, cookie.String()) + } + } + + resp, status, err := binglib.Bypass(bypassServer, strings.Join(reqCookies, "; "), "local-gen-"+hex.NewUUID(), request.IG, "", "", request.T, r.Host) + if err != nil { + helper.ErrorResult(w, http.StatusInternalServerError, err.Error()) + common.Logger.Error("Bypass Error: %v", err) + return + } + if status != http.StatusOK { + respBytes, err := json.Marshal(resp) + if err != nil { + helper.ErrorResult(w, http.StatusInternalServerError, err.Error()) + common.Logger.Error("Bypass Marshal Error: %v", err) + return + } + helper.ErrorResult(w, status, string(respBytes)) + return + } + body, _ := json.Marshal(resp) + w.Write(body) +} diff --git a/api/challenge.go b/api/challenge.go new file mode 100644 index 0000000000000000000000000000000000000000..621769be7218b523a71081d58bb5106d3ef9f010 --- /dev/null +++ b/api/challenge.go @@ -0,0 +1,250 @@ +package api + +import ( + "adams549659584/go-proxy-bingai/common" + "adams549659584/go-proxy-bingai/common/helper" + "net/http" +) + +const respChallengeHtml = ` + + +
+ + + + + + +提示:形容词+名词+动词+风格,描述得越详细时,效果越好。
+示例:{{ DEMO_KEYWORD }}
+