Skip to content

Commit

Permalink
Merge pull request #15 from Harry-zklcdc/master
Browse files Browse the repository at this point in the history
更新
  • Loading branch information
Nothingness-Void authored Jan 16, 2024
2 parents b87e352 + c58b747 commit da1784c
Show file tree
Hide file tree
Showing 32 changed files with 3,661 additions and 2,780 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '^1.21.4'

- name: Set up Node.js
uses: actions/setup-node@v3
Expand All @@ -39,6 +41,7 @@ jobs:
run: |
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -tags netgo -trimpath -o go-proxy-bingai main.go && tar -zcvf go-proxy-bingai-linux-amd64.tar.gz go-proxy-bingai
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -tags netgo -trimpath -o go-proxy-bingai main.go && tar -zcvf go-proxy-bingai-linux-arm64.tar.gz go-proxy-bingai
GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w" -tags netgo -trimpath -o go-proxy-bingai main.go && tar -zcvf go-proxy-bingai-linux-armv7.tar.gz go-proxy-bingai
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -tags netgo -trimpath -o go-proxy-bingai.exe main.go && tar -zcvf go-proxy-bingai-windows-amd64.tar.gz go-proxy-bingai.exe
GOOS=windows GOARCH=arm64 go build -ldflags="-s -w" -tags netgo -trimpath -o go-proxy-bingai.exe main.go && tar -zcvf go-proxy-bingai-windows-arm64.tar.gz go-proxy-bingai.exe
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -tags netgo -trimpath -o go-proxy-bingai main.go && tar -zcvf go-proxy-bingai-darwin-amd64.tar.gz go-proxy-bingai
Expand All @@ -50,6 +53,7 @@ jobs:
files: |
go-proxy-bingai-linux-amd64.tar.gz
go-proxy-bingai-linux-arm64.tar.gz
go-proxy-bingai-linux-armv7.tar.gz
go-proxy-bingai-windows-amd64.tar.gz
go-proxy-bingai-windows-arm64.tar.gz
go-proxy-bingai-darwin-amd64.tar.gz
Expand Down Expand Up @@ -100,7 +104,7 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
platforms: linux/amd64,linux/arm64,linux/arm/v7
context: .
file: ./docker/Dockerfile
push: true
Expand Down
104 changes: 104 additions & 0 deletions api/bypass.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package api

import (
"adams549659584/go-proxy-bingai/api/helper"
"adams549659584/go-proxy-bingai/common"
"bytes"
"encoding/json"
"io"
"net/http"
"time"

"github.com/Harry-zklcdc/bing-lib/lib/hex"
)

type passRequestStruct struct {
Cookies string `json:"cookies"`
Iframeid string `json:"iframeid,omitempty"`
}

type requestStruct struct {
Url string `json:"url"`
}

type PassResponseStruct struct {
Result struct {
Cookies string `json:"cookies"`
ScreenShot string `json:"screenshot"`
} `json:"result"`
Error string `json:"error"`
}

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)
return
}

if request.Url == "" {
if common.BypassServer == "" {
helper.CommonResult(w, http.StatusInternalServerError, "BypassServer is empty", nil)
return
}
request.Url = common.BypassServer
}

resp, err := Bypass(request.Url, r.Header.Get("Cookie"), "local-gen-"+hex.NewUUID())
if err != nil {
helper.CommonResult(w, http.StatusInternalServerError, err.Error(), nil)
return
}
body, _ := json.Marshal(resp)
w.Write(body)
}

func Bypass(bypassServer, cookie, iframeid string) (passResp PassResponseStruct, err error) {
passRequest := passRequestStruct{
Cookies: cookie,
Iframeid: iframeid,
}
passResq, err := json.Marshal(passRequest)
if err != nil {
return passResp, err
}

client := &http.Client{
Timeout: time.Duration(30 * time.Second),
}
req, err := http.NewRequest("POST", bypassServer, bytes.NewReader(passResq))
if err != nil {
return passResp, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", common.User_Agent)
resp, err := client.Do(req)
if err != nil {
return passResp, err
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)

err = json.Unmarshal(body, &passResp)
if err != nil {
return passResp, err
}
return passResp, nil
}
54 changes: 54 additions & 0 deletions api/challenge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package api

import (
"adams549659584/go-proxy-bingai/api/helper"
"adams549659584/go-proxy-bingai/common"
"net/http"
"strings"
)

const respHtml = `
<script type="text/javascript">
function verificationComplete(){
window.parent.postMessage("verificationComplete", "*");
}
window.onload = verificationComplete;
</script>
`

func ChallengeHandler(w http.ResponseWriter, r *http.Request) {
if !helper.CheckAuth(r) {
helper.UnauthorizedResult(w)
return
}

if r.Method != "GET" {
helper.CommonResult(w, http.StatusMethodNotAllowed, "Method Not Allowed", nil)
return
}

reqCookies := strings.Split(r.Header.Get("Cookie"), "; ")
bypassServer := common.BypassServer
for _, cookie := range reqCookies {
if strings.HasPrefix(cookie, "BingAI_Pass_Server") {
tmp := strings.ReplaceAll(cookie, "BingAI_Pass_Server=", "")
if tmp != "" {
bypassServer = tmp
}
}
}

resp, err := Bypass(bypassServer, r.Header.Get("Cookie"), "")
if err != nil {
helper.CommonResult(w, http.StatusInternalServerError, err.Error(), nil)
return
}

cookies := strings.Split(resp.Result.Cookies, "; ")
for _, cookie := range cookies {
w.Header().Add("Set-Cookie", cookie+"; path=/")
}

// helper.CommonResult(w, http.StatusOK, "ok", resp)
w.Write([]byte(respHtml))
}
64 changes: 0 additions & 64 deletions api/pass.go

This file was deleted.

Loading

0 comments on commit da1784c

Please sign in to comment.