Compare commits
No commits in common. "c1b6714d57a4daed7f148d0bbad2aa6778df8298" and "adb28dafe7f3588d3bbccee02c62095c0750937c" have entirely different histories.
c1b6714d57
...
adb28dafe7
|
@ -3,5 +3,3 @@ coverage/*
|
||||||
test_monitor.txt
|
test_monitor.txt
|
||||||
bin
|
bin
|
||||||
.vscode
|
.vscode
|
||||||
.notes
|
|
||||||
bin
|
|
6
Makefile
6
Makefile
|
@ -17,9 +17,3 @@ 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
|
|
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"`
|
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 {
|
||||||
|
|
34
main.go
34
main.go
|
@ -15,14 +15,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
envFile := ""
|
config := cfg.NewConfig("./.env")
|
||||||
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)
|
||||||
|
@ -34,30 +29,21 @@ func main() {
|
||||||
log.SetOutput(f)
|
log.SetOutput(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
var lc *launcher.Launcher
|
// get the browser executable path
|
||||||
var u string
|
path := launcher.NewBrowser().MustGet()
|
||||||
|
args := launcher.New().FormatArgs()
|
||||||
|
|
||||||
if config.Bin != "" {
|
cmd := leakless.New().Command(path, args...)
|
||||||
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().
|
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