Compare commits
No commits in common. "c1b6714d57a4daed7f148d0bbad2aa6778df8298" and "adb28dafe7f3588d3bbccee02c62095c0750937c" have entirely different histories.
c1b6714d57
...
adb28dafe7
|
@ -2,6 +2,4 @@
|
|||
coverage/*
|
||||
test_monitor.txt
|
||||
bin
|
||||
.vscode
|
||||
.notes
|
||||
bin
|
||||
.vscode
|
8
Makefile
8
Makefile
|
@ -16,10 +16,4 @@ 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
|
||||
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
|
||||
env GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -o ./${BINARY_DIR}/${BINARY_NAME} main.go
|
24
README.md
24
README.md
|
@ -1,24 +0,0 @@
|
|||
# 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,7 +12,6 @@ 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,14 +15,9 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
envFile := ""
|
||||
if os.Getenv("ENV") != "prod" {
|
||||
envFile = "./.env"
|
||||
}
|
||||
config := cfg.NewConfig("./.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)
|
||||
|
@ -34,30 +29,21 @@ func main() {
|
|||
log.SetOutput(f)
|
||||
}
|
||||
|
||||
var lc *launcher.Launcher
|
||||
var u string
|
||||
// get the browser executable path
|
||||
path := launcher.NewBrowser().MustGet()
|
||||
args := launcher.New().FormatArgs()
|
||||
|
||||
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)
|
||||
}
|
||||
cmd := leakless.New().Command(path, args...)
|
||||
|
||||
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