Compare commits
5 Commits
adb28dafe7
...
c1b6714d57
Author | SHA1 | Date |
---|---|---|
Urko | c1b6714d57 | |
Urko | fb48c6a9cc | |
Urko | d69bfe4590 | |
Urko | abf360a126 | |
Urko | cc3b454262 |
|
@ -3,3 +3,5 @@ coverage/*
|
||||||
test_monitor.txt
|
test_monitor.txt
|
||||||
bin
|
bin
|
||||||
.vscode
|
.vscode
|
||||||
|
.notes
|
||||||
|
bin
|
6
Makefile
6
Makefile
|
@ -17,3 +17,9 @@ build:
|
||||||
rm -rf ${BINARY_DIR}
|
rm -rf ${BINARY_DIR}
|
||||||
mkdir ${BINARY_DIR}
|
mkdir ${BINARY_DIR}
|
||||||
env GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -o ./${BINARY_DIR}/${BINARY_NAME} main.go
|
env GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -o ./${BINARY_DIR}/${BINARY_NAME} main.go
|
||||||
|
build_freebsd:
|
||||||
|
rm -rf ${BINARY_DIR}
|
||||||
|
mkdir ${BINARY_DIR}
|
||||||
|
env GOOS=freebsd CGO_ENABLED=0 GOARCH=arm64 ENV=prod go build -o ./${BINARY_DIR}/${BINARY_NAME} main.go
|
||||||
|
list_build_types:
|
||||||
|
go tool dist list | grep arm
|
|
@ -0,0 +1,24 @@
|
||||||
|
# go-wifi-switcher
|
||||||
|
## Huawei B2368-66
|
||||||
|
This software will turn wifi on/off based on current state.
|
||||||
|
|
||||||
|
Example: If wifi is **on** then it will turn **off**.
|
||||||
|
|
||||||
|
## How does it works
|
||||||
|
It uses web-scrapping thanks to amazing **[go-rod web scrapper](github.com/go-rod/rod)**
|
||||||
|
|
||||||
|
## How to use
|
||||||
|
You must build it using the `go build` command that better fits with the OS where this software will be consumed.
|
||||||
|
|
||||||
|
I'm using it on debian OS so I've created some build commands inside **[Makefile](https://gitea.urkob.com/urko/go-wifi-switcher/src/branch/main/Makefile)**
|
||||||
|
|
||||||
|
You can build and copy into your OS in `/usr/local/bin` for example, then create a cron task to automatically run this binary.
|
||||||
|
|
||||||
|
## Result
|
||||||
|
You can configure to switch **off** during **night** and **on** at **morning**. So you can get free of radiation while you sleep and don't have to manually switch on :)
|
||||||
|
|
||||||
|
## How to install and how to use
|
||||||
|
TODO
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
TODO
|
|
@ -12,6 +12,7 @@ type Config struct {
|
||||||
AdminUser string `required:"true" split_words:"true"`
|
AdminUser string `required:"true" split_words:"true"`
|
||||||
Password string `required:"true" split_words:"true"`
|
Password string `required:"true" split_words:"true"`
|
||||||
LogFile bool `required:"true" split_words:"true"`
|
LogFile bool `required:"true" split_words:"true"`
|
||||||
|
Bin string `required:"true" split_words:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(envFilePath string) *Config {
|
func NewConfig(envFilePath string) *Config {
|
||||||
|
|
24
main.go
24
main.go
|
@ -15,9 +15,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config := cfg.NewConfig("./.env")
|
envFile := ""
|
||||||
|
if os.Getenv("ENV") != "prod" {
|
||||||
|
envFile = "./.env"
|
||||||
|
}
|
||||||
|
|
||||||
|
config := cfg.NewConfig(envFile)
|
||||||
log.SetFlags(log.Lmicroseconds)
|
log.SetFlags(log.Lmicroseconds)
|
||||||
|
config.LogFile = false
|
||||||
if config.LogFile {
|
if config.LogFile {
|
||||||
logFileName := fmt.Sprintf("%s.txt", time.Now().Format(strings.ReplaceAll(time.RFC1123Z, ":", "_")))
|
logFileName := fmt.Sprintf("%s.txt", time.Now().Format(strings.ReplaceAll(time.RFC1123Z, ":", "_")))
|
||||||
f, err := os.OpenFile(logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
|
f, err := os.OpenFile(logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
|
||||||
|
@ -29,21 +34,30 @@ func main() {
|
||||||
log.SetOutput(f)
|
log.SetOutput(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the browser executable path
|
var lc *launcher.Launcher
|
||||||
|
var u string
|
||||||
|
|
||||||
|
if config.Bin != "" {
|
||||||
|
lc = launcher.New().Bin(config.Bin)
|
||||||
|
u = lc.MustLaunch()
|
||||||
|
log.Println("u = lc.MustLaunch()", u)
|
||||||
|
} else {
|
||||||
|
lc = launcher.New()
|
||||||
path := launcher.NewBrowser().MustGet()
|
path := launcher.NewBrowser().MustGet()
|
||||||
args := launcher.New().FormatArgs()
|
args := lc.FormatArgs()
|
||||||
|
|
||||||
cmd := leakless.New().Command(path, args...)
|
cmd := leakless.New().Command(path, args...)
|
||||||
|
|
||||||
parser := launcher.NewURLParser()
|
parser := launcher.NewURLParser()
|
||||||
cmd.Stderr = parser
|
cmd.Stderr = parser
|
||||||
utils.E(cmd.Start())
|
utils.E(cmd.Start())
|
||||||
u := launcher.MustResolveURL(<-parser.URL)
|
u = launcher.MustResolveURL(<-parser.URL)
|
||||||
|
}
|
||||||
|
|
||||||
browser := rod.New().
|
browser := rod.New().
|
||||||
ControlURL(u).
|
ControlURL(u).
|
||||||
MustConnect().
|
MustConnect().
|
||||||
MustIgnoreCertErrors(true)
|
MustIgnoreCertErrors(true)
|
||||||
|
|
||||||
defer browser.MustClose()
|
defer browser.MustClose()
|
||||||
|
|
||||||
page := browser.MustPage(config.Page)
|
page := browser.MustPage(config.Page)
|
||||||
|
|
Loading…
Reference in New Issue