windport/main.go

74 lines
1.2 KiB
Go
Raw Normal View History

2023-08-12 16:41:26 -04:00
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/http/cookiejar"
"net/url"
2023-08-13 16:19:23 -04:00
"os"
"strings"
2023-08-12 16:41:26 -04:00
2023-08-13 16:19:23 -04:00
"dynatron.me/x/windport/pkg/windscribe"
2023-08-12 16:41:26 -04:00
)
func main() {
2023-08-13 16:19:23 -04:00
a := windscribe.Auth{}
2023-08-12 16:41:26 -04:00
err := json.NewDecoder(os.Stdin).Decode(&a)
if err != nil {
log.Fatal(err)
}
var PTransport http.RoundTripper = &http.Transport{Proxy: http.ProxyFromEnvironment}
cli := client{
2023-08-13 16:19:23 -04:00
hc: http.DefaultClient,
2023-08-12 16:41:26 -04:00
auth: a,
}
cli.hc.Transport = PTransport
cli.hc.Jar, err = cookiejar.New(nil)
if err != nil {
log.Fatal(err)
}
err = cli.matchingPort()
if err != nil {
log.Fatal(err)
}
}
type client struct {
2023-08-13 16:19:23 -04:00
hc *http.Client
2023-08-12 16:41:26 -04:00
auth Auth
}
func (c *client) matchingPort() error {
ephVals := url.Values{
2023-08-13 16:19:23 -04:00
"port": []string{""},
"ctime": []string{fmt.Sprint(csrf.Time)},
2023-08-12 16:41:26 -04:00
"ctoken": []string{csrf.Token},
}
req, err = http.NewRequestWithContext(ctx, "POST", "https://windscribe.com/staticips/postEphPort", strings.NewReader(ephVals.Encode()))
if err != nil {
return err
}
fillReq(req)
req.Header.Set("referer", "https://windscribe.com/myaccount")
resp, err = c.hc.Do(req)
if err != nil {
return err
}
io.Copy(os.Stderr, resp.Body)
cleanupBody(resp.Body)
return nil
}