2023-07-02 19:50:59 +02:00
|
|
|
package providers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-rod/rod"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ArcherAx50 struct {
|
|
|
|
passwordID string
|
|
|
|
loginButtonID string
|
|
|
|
wirelessTab string
|
|
|
|
chkWifi2gID string
|
|
|
|
saveButtonID string
|
|
|
|
page *rod.Page
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewArcherAx50(page *rod.Page) ArcherAx50 {
|
|
|
|
return ArcherAx50{
|
|
|
|
passwordID: "#login-password",
|
|
|
|
loginButtonID: "#login-btn",
|
|
|
|
wirelessTab: "wireless",
|
|
|
|
chkWifi2gID: "chk_enable_wireless_24g",
|
|
|
|
saveButtonID: "#total_save",
|
|
|
|
page: page,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p ArcherAx50) Login(user, pass string) error {
|
|
|
|
time.Sleep(time.Millisecond * 1250)
|
|
|
|
|
|
|
|
p.page.MustEvaluate(&rod.EvalOptions{
|
|
|
|
JS: `() => {
|
|
|
|
$("input.password-text").each((i,v) => {
|
|
|
|
v.click();
|
|
|
|
v.focus();
|
|
|
|
v.value="` + pass + `";
|
|
|
|
})
|
|
|
|
return '';
|
|
|
|
}`,
|
|
|
|
})
|
|
|
|
time.Sleep(time.Millisecond * 250)
|
|
|
|
|
|
|
|
log.Println(p.passwordID, "DONE")
|
|
|
|
|
|
|
|
login, err := p.page.Element(p.loginButtonID)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("page.Element %s: %s", p.loginButtonID, err)
|
|
|
|
}
|
|
|
|
login.MustClick()
|
|
|
|
log.Println(p.loginButtonID, "DONE")
|
|
|
|
time.Sleep(time.Millisecond * 400)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p ArcherAx50) SwitchWIFI() error {
|
2023-07-02 20:16:34 +02:00
|
|
|
time.Sleep(time.Millisecond * 1350)
|
2023-07-02 19:50:59 +02:00
|
|
|
pageURL := p.page.MustInfo().URL
|
|
|
|
log.Println("p.page.MustInfo().URL", pageURL)
|
|
|
|
|
|
|
|
wirelessTab, err := p.page.Element(`[name="` + p.wirelessTab + `"]`)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("page.Element %s: %s", p.wirelessTab, err)
|
|
|
|
}
|
|
|
|
wirelessTab.MustClick()
|
|
|
|
log.Println(p.wirelessTab, "DONE")
|
|
|
|
|
2023-07-02 20:16:34 +02:00
|
|
|
time.Sleep(time.Millisecond * 1250)
|
2023-07-02 19:50:59 +02:00
|
|
|
checked := p.page.MustEvaluate(&rod.EvalOptions{
|
|
|
|
JS: `() => {
|
|
|
|
return document.getElementById('` + p.chkWifi2gID + `').checked;
|
|
|
|
}`,
|
|
|
|
})
|
|
|
|
|
|
|
|
isChecked := checked.Value.Bool()
|
2023-07-02 20:15:54 +02:00
|
|
|
log.Println(getCheckedMessage(isChecked))
|
2023-07-02 19:50:59 +02:00
|
|
|
p.page.MustEvaluate(&rod.EvalOptions{
|
|
|
|
JS: `() => {
|
|
|
|
document.getElementById('` + p.chkWifi2gID + `').checked=` + fmt.Sprint(!isChecked) + `;
|
|
|
|
return '';
|
|
|
|
}`,
|
|
|
|
})
|
|
|
|
|
|
|
|
log.Println(p.chkWifi2gID, "DONE")
|
|
|
|
saveButton, err := p.page.Element(p.saveButtonID)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("page.Element %s: %s", p.saveButtonID, err)
|
|
|
|
}
|
|
|
|
saveButton.MustClick()
|
|
|
|
log.Println(p.saveButtonID, "DONE")
|
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * 1500)
|
|
|
|
return nil
|
|
|
|
}
|
2023-07-02 20:15:54 +02:00
|
|
|
|
|
|
|
func getCheckedMessage(isChecked bool) string {
|
|
|
|
if isChecked {
|
|
|
|
return "Time to sleep, let's switch off"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Time to laborate, let's switch WIFI on"
|
|
|
|
}
|