Compare commits

..

3 Commits

Author SHA1 Message Date
sati.ac 5a40fb593c fix: use hostIp from config
release-tag / release (push) Successful in 1m56s Details
2023-07-13 23:22:11 +03:00
sati.ac e47a96a597 fix(AntiGateV2): match task type case-insensitively 2023-07-13 23:20:38 +03:00
sati.ac 4d861f037e feat(AntiGateV2): more verbose debug logging 2023-07-13 23:19:43 +03:00
2 changed files with 12 additions and 9 deletions

View File

@ -5,6 +5,7 @@ import (
"io" "io"
"net/http" "net/http"
"reflect" "reflect"
"strings"
"git.sati.ac/sati.ac/sati-go" "git.sati.ac/sati.ac/sati-go"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
@ -147,8 +148,8 @@ func (a *antigateV2Api) createTask(request struct {
var id uint32 var id uint32
switch taskType { switch strings.ToLower(taskType) {
case "TurnstileTask", "TurnstileTaskProxyless": case "turnstiletask", "turnstiletaskproxyless":
var task struct { var task struct {
WebsiteURL string `json:"websiteURL"` WebsiteURL string `json:"websiteURL"`
WebsiteKey string `json:"websiteKey"` WebsiteKey string `json:"websiteKey"`
@ -160,7 +161,7 @@ func (a *antigateV2Api) createTask(request struct {
SiteKey: task.WebsiteKey, SiteKey: task.WebsiteKey,
Action: task.Action, Action: task.Action,
}) })
case "RecaptchaV2Task", "RecaptchaV2TaskProxyless": case "recaptchav2task", "recaptchav2taskproxyless":
var task struct { var task struct {
WebsiteURL string `json:"websiteURL"` WebsiteURL string `json:"websiteURL"`
WebsiteKey string `json:"websiteKey"` WebsiteKey string `json:"websiteKey"`
@ -170,7 +171,7 @@ func (a *antigateV2Api) createTask(request struct {
PageUrl: task.WebsiteURL, PageUrl: task.WebsiteURL,
SiteKey: task.WebsiteKey, SiteKey: task.WebsiteKey,
}) })
case "FunCaptchaTask", "FunCaptchaTaskProxyless": case "funcaptchatask", "funcaptchataskproxyless":
var task struct { var task struct {
WebsiteURL string `json:"websiteURL"` WebsiteURL string `json:"websiteURL"`
WebsitePublicKey string `json:"websitePublicKey"` WebsitePublicKey string `json:"websitePublicKey"`
@ -209,7 +210,7 @@ func (a *antigateV2Api) getBalance(struct{}) any {
}{0, 0, balance.InexactFloat64()} }{0, 0, balance.InexactFloat64()}
} }
func jsonHandler[T any](handler func(data T) any) func(http.ResponseWriter, *http.Request) { func jsonHandler[T any](api *antigateV2Api, handler func(data T) any) func(http.ResponseWriter, *http.Request) {
emptyRequest := reflect.Zero(reflect.TypeOf(handler).In(0)).Interface().(T) emptyRequest := reflect.Zero(reflect.TypeOf(handler).In(0)).Interface().(T)
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
@ -223,7 +224,9 @@ func jsonHandler[T any](handler func(data T) any) func(http.ResponseWriter, *htt
return return
} }
api.ctx.Logger.WithFields(logrus.Fields{"handler": api.Name(), "request": request}).Debug("request")
response := handler(request) response := handler(request)
api.ctx.Logger.WithFields(logrus.Fields{"handler": api.Name(), "response": response}).Debug("response")
marshaled, _ := json.Marshal(response) marshaled, _ := json.Marshal(response)
w.Write(marshaled) w.Write(marshaled)
@ -233,9 +236,9 @@ func jsonHandler[T any](handler func(data T) any) func(http.ResponseWriter, *htt
func newAntigateV2Api(ctx *ApiContext) ApiHandler { func newAntigateV2Api(ctx *ApiContext) ApiHandler {
api := &antigateV2Api{ctx, http.NewServeMux()} api := &antigateV2Api{ctx, http.NewServeMux()}
api.mux.HandleFunc("/createTask", jsonHandler(api.createTask)) api.mux.HandleFunc("/createTask", jsonHandler(api, api.createTask))
api.mux.HandleFunc("/getTaskResult", jsonHandler(api.getTaskResult)) api.mux.HandleFunc("/getTaskResult", jsonHandler(api, api.getTaskResult))
api.mux.HandleFunc("/getBalance", jsonHandler(api.getBalance)) api.mux.HandleFunc("/getBalance", jsonHandler(api, api.getBalance))
return api return api
} }

View File

@ -207,7 +207,7 @@ func addDomainsToHosts(ctx *api.ApiContext) error {
hosts = hostsModRE.ReplaceAll(hosts, []byte{}) // remove old entries hosts = hostsModRE.ReplaceAll(hosts, []byte{}) // remove old entries
hostIp := "127.0.0.1" hostIp := strings.SplitN(ctx.Config.Host, ":", 2)[0]
suffix := "\r\n#sati-bridge start, DO NOT MODIFY\r\n" suffix := "\r\n#sati-bridge start, DO NOT MODIFY\r\n"
for _, domain := range ctx.Server.GetDomains() { for _, domain := range ctx.Server.GetDomains() {
suffix += hostIp + " " + domain + "\r\n" suffix += hostIp + " " + domain + "\r\n"