mirror of
https://github.com/Alexey71/opera-proxy.git
synced 2026-05-14 14:40:59 +00:00
seclient: add geolist method
This commit is contained in:
@@ -25,7 +25,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
log.Printf("seclient = %#v", seclient)
|
log.Printf("seclient = %#v", seclient)
|
||||||
//log.Printf("jar = %#v", seclient.HttpClient.Jar)
|
log.Printf("jar = %#v", seclient.HttpClient.Jar)
|
||||||
|
|
||||||
log.Println("------------ DOING DEVICE REGISTRATION ------------")
|
log.Println("------------ DOING DEVICE REGISTRATION ------------")
|
||||||
err = seclient.RegisterDevice(context.TODO())
|
err = seclient.RegisterDevice(context.TODO())
|
||||||
@@ -33,4 +33,12 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
log.Printf("seclient = %#v", seclient)
|
log.Printf("seclient = %#v", seclient)
|
||||||
|
log.Printf("Device Password: %s", seclient.DevicePassword)
|
||||||
|
|
||||||
|
log.Println("------------ GETTING GEO LIST ------------")
|
||||||
|
geos, err := seclient.GeoList(context.TODO())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
log.Printf("Geo List: %#v", geos)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,3 +59,15 @@ type SERegisterDeviceResponse struct {
|
|||||||
Data SERegisterDeviceData `json:"data"`
|
Data SERegisterDeviceData `json:"data"`
|
||||||
Status SEStatusPair `json:"return_code"`
|
Status SEStatusPair `json:"return_code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SEGeoEntry struct {
|
||||||
|
Country string `json:"country"`
|
||||||
|
CountryCode string `json:"country_code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SEGeoListResponse struct {
|
||||||
|
Data struct {
|
||||||
|
Geos []SEGeoEntry `json:"geos"`
|
||||||
|
}
|
||||||
|
Status SEStatusPair
|
||||||
|
}
|
||||||
|
|||||||
+44
-6
@@ -109,12 +109,7 @@ func (c *SEClient) AnonRegister(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.SubscriberEmail = fmt.Sprintf("%s@%s.best.vpn", localPart, c.Settings.ClientType)
|
c.SubscriberEmail = fmt.Sprintf("%s@%s.best.vpn", localPart, c.Settings.ClientType)
|
||||||
|
c.SubscriberPassword = capitalHexSHA1(c.SubscriberEmail)
|
||||||
password, err := randomCapitalHexString(c.rng, ANON_PASSWORD_BYTES)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.SubscriberPassword = password
|
|
||||||
|
|
||||||
return c.Register(ctx)
|
return c.Register(ctx)
|
||||||
}
|
}
|
||||||
@@ -209,6 +204,49 @@ func (c *SEClient) RegisterDevice(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *SEClient) GeoList(ctx context.Context) ([]SEGeoEntry, error) {
|
||||||
|
geoListInput := url.Values{
|
||||||
|
"device_id": {c.AssignedDeviceIDHash},
|
||||||
|
}
|
||||||
|
req, err := http.NewRequestWithContext(
|
||||||
|
ctx,
|
||||||
|
"POST",
|
||||||
|
c.Settings.Endpoints.GeoList,
|
||||||
|
strings.NewReader(geoListInput.Encode()),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.populateRequest(req)
|
||||||
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
resp, err := c.HttpClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("bad http status: %s", resp.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder := json.NewDecoder(resp.Body)
|
||||||
|
var geoListRes SEGeoListResponse
|
||||||
|
err = decoder.Decode(&geoListRes)
|
||||||
|
cleanupBody(resp.Body)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if geoListRes.Status.Code != SE_STATUS_OK {
|
||||||
|
return nil, fmt.Errorf("API responded with error message: code=%d, msg=\"%s\"",
|
||||||
|
geoListRes.Status.Code, geoListRes.Status.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
return geoListRes.Data.Geos, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *SEClient) populateRequest(req *http.Request) {
|
func (c *SEClient) populateRequest(req *http.Request) {
|
||||||
req.Header["SE-Client-Version"] = []string{c.Settings.ClientVersion}
|
req.Header["SE-Client-Version"] = []string{c.Settings.ClientVersion}
|
||||||
req.Header["SE-Operating-System"] = []string{c.Settings.OperatingSystem}
|
req.Header["SE-Operating-System"] = []string{c.Settings.OperatingSystem}
|
||||||
|
|||||||
Reference in New Issue
Block a user