Compare commits
5 Commits
adb28dafe7
...
c1b6714d57
Author | SHA1 | Date |
---|---|---|
Urko | c1b6714d57 | |
Urko | fb48c6a9cc | |
Urko | d69bfe4590 | |
Urko | abf360a126 | |
Urko | cc3b454262 |
|
@ -2,4 +2,6 @@
|
|||
coverage/*
|
||||
test_monitor.txt
|
||||
bin
|
||||
.vscode
|
||||
.vscode
|
||||
.notes
|
||||
bin
|
8
Makefile
8
Makefile
|
@ -16,4 +16,10 @@ test-coverage:
|
|||
build:
|
||||
rm -rf ${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"`
|
||||
Password string `required:"true" split_words:"true"`
|
||||
LogFile bool `required:"true" split_words:"true"`
|
||||
Bin string `required:"true" split_words:"true"`
|
||||
}
|
||||
|
||||
func NewConfig(envFilePath string) *Config {
|
||||
|
|
34
main.go
34
main.go
|
@ -15,9 +15,14 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
config := cfg.NewConfig("./.env")
|
||||
envFile := ""
|
||||
if os.Getenv("ENV") != "prod" {
|
||||
envFile = "./.env"
|
||||
}
|
||||
|
||||
config := cfg.NewConfig(envFile)
|
||||
log.SetFlags(log.Lmicroseconds)
|
||||
config.LogFile = false
|
||||
if config.LogFile {
|
||||
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)
|
||||
|
@ -29,21 +34,30 @@ func main() {
|
|||
log.SetOutput(f)
|
||||
}
|
||||
|
||||
// get the browser executable path
|
||||
path := launcher.NewBrowser().MustGet()
|
||||
args := launcher.New().FormatArgs()
|
||||
var lc *launcher.Launcher
|
||||
var u string
|
||||
|
||||
cmd := leakless.New().Command(path, args...)
|
||||
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()
|
||||
args := lc.FormatArgs()
|
||||
|
||||
cmd := leakless.New().Command(path, args...)
|
||||
|
||||
parser := launcher.NewURLParser()
|
||||
cmd.Stderr = parser
|
||||
utils.E(cmd.Start())
|
||||
u = launcher.MustResolveURL(<-parser.URL)
|
||||
}
|
||||
|
||||
parser := launcher.NewURLParser()
|
||||
cmd.Stderr = parser
|
||||
utils.E(cmd.Start())
|
||||
u := launcher.MustResolveURL(<-parser.URL)
|
||||
browser := rod.New().
|
||||
ControlURL(u).
|
||||
MustConnect().
|
||||
MustIgnoreCertErrors(true)
|
||||
|
||||
defer browser.MustClose()
|
||||
|
||||
page := browser.MustPage(config.Page)
|
||||
|
|
Loading…
Reference in New Issue