refactor
This commit is contained in:
parent
b3c6569b6c
commit
99287b7f82
15 changed files with 54 additions and 91 deletions
8
.github/workflows/docker-readme.yml
vendored
8
.github/workflows/docker-readme.yml
vendored
|
|
@ -2,10 +2,10 @@ name: DockerHub-README
|
|||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
paths:
|
||||
- 'README.md'
|
||||
# push:
|
||||
# branches: [ "main" ]
|
||||
# paths:
|
||||
# - 'README.md'
|
||||
|
||||
env:
|
||||
IMAGE_NAME: watchyourlan
|
||||
|
|
|
|||
10
.github/workflows/main-docker-all.yml
vendored
10
.github/workflows/main-docker-all.yml
vendored
|
|
@ -2,11 +2,11 @@ name: Docker
|
|||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
paths:
|
||||
- 'Dockerfile'
|
||||
- 'src/**'
|
||||
# push:
|
||||
# branches: [ "main" ]
|
||||
# paths:
|
||||
# - 'Dockerfile'
|
||||
# - 'src/**'
|
||||
|
||||
env:
|
||||
IMAGE_NAME: watchyourlan
|
||||
|
|
|
|||
3
Makefile
3
Makefile
|
|
@ -23,6 +23,9 @@ fmt:
|
|||
|
||||
lint:
|
||||
golangci-lint run
|
||||
golint ./...
|
||||
|
||||
check: fmt lint
|
||||
|
||||
go-build:
|
||||
cd cmd/WatchYourLAN/ && \
|
||||
|
|
|
|||
|
|
@ -2,38 +2,20 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
// "time"
|
||||
"github.com/aceberg/WatchYourLAN/pkg/conf"
|
||||
"github.com/aceberg/WatchYourLAN/pkg/db"
|
||||
"github.com/aceberg/WatchYourLAN/pkg/web"
|
||||
// . "github.com/aceberg/WatchYourLAN/pkg/models"
|
||||
|
||||
"github.com/aceberg/WatchYourLAN/internal/conf"
|
||||
"github.com/aceberg/WatchYourLAN/internal/db"
|
||||
"github.com/aceberg/WatchYourLAN/internal/web"
|
||||
)
|
||||
|
||||
// var AppConfig Conf
|
||||
// var AllHosts []Host
|
||||
|
||||
// func scan_and_compare() {
|
||||
// var foundHosts []Host
|
||||
// var dbHosts []Host
|
||||
// for { // Endless
|
||||
// foundHosts = arp_scan() // Scan interfaces
|
||||
// dbHosts = db_select() // Select everything from DB
|
||||
// db_setnow() // Mark hosts in DB as offline
|
||||
// hosts_compare(foundHosts, dbHosts) // Compare hosts online and in DB
|
||||
// // and add them to DB
|
||||
// AllHosts = db_select()
|
||||
// time.Sleep(time.Duration(AppConfig.Timeout) * time.Second) // Timeout
|
||||
// }
|
||||
// }
|
||||
const configPath = "/data/config"
|
||||
|
||||
func main() {
|
||||
appConfig := conf.GetConfig() // Get config from Defaults, Config file, Env
|
||||
appConfig := conf.GetConfig(configPath) // Get config from Defaults, Config file, Env
|
||||
|
||||
fmt.Println("CONF =", appConfig)
|
||||
|
||||
db.CreateDB(appConfig.DbPath) // Check if DB exists. Create if not
|
||||
|
||||
// go scan_and_compare()
|
||||
|
||||
web.Webgui(appConfig) // Start web GUI
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
package conf
|
||||
|
||||
import (
|
||||
. "github.com/aceberg/WatchYourLAN/pkg/models"
|
||||
. "github.com/aceberg/WatchYourLAN/internal/models"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const configPath = "/data/config"
|
||||
|
||||
func GetConfig() (config Conf) {
|
||||
func GetConfig(path string) (config Conf) {
|
||||
viper.SetDefault("IFACE", "enp1s0")
|
||||
viper.SetDefault("DBPATH", "/data/db.sqlite")
|
||||
viper.SetDefault("GUIIP", "localhost")
|
||||
|
|
@ -16,7 +14,7 @@ func GetConfig() (config Conf) {
|
|||
viper.SetDefault("SHOUTRRR_URL", "")
|
||||
viper.SetDefault("THEME", "solar")
|
||||
|
||||
viper.SetConfigFile(configPath)
|
||||
viper.SetConfigFile(path)
|
||||
viper.SetConfigType("env")
|
||||
viper.ReadInConfig()
|
||||
|
||||
|
|
@ -33,8 +31,8 @@ func GetConfig() (config Conf) {
|
|||
return config
|
||||
}
|
||||
|
||||
func WriteConfig(theme string) {
|
||||
viper.SetConfigFile(configPath)
|
||||
func WriteConfig(path, theme string) {
|
||||
viper.SetConfigFile(path)
|
||||
viper.SetConfigType("env")
|
||||
viper.Set("THEME", theme)
|
||||
viper.WriteConfig()
|
||||
18
internal/web/index.go
Normal file
18
internal/web/index.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/aceberg/WatchYourLAN/internal/models"
|
||||
)
|
||||
|
||||
func index(w http.ResponseWriter, r *http.Request) {
|
||||
var guiData models.GuiData
|
||||
guiData.Config = AppConfig
|
||||
guiData.Hosts = []models.Host{}
|
||||
|
||||
tmpl, _ := template.ParseFiles(TemplPath + "index.html", TemplPath + "header.html", TemplPath + "footer.html")
|
||||
tmpl.ExecuteTemplate(w, "index", guiData)
|
||||
}
|
||||
|
|
@ -1,21 +1,28 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"embed"
|
||||
// "embed"
|
||||
"fmt"
|
||||
. "github.com/aceberg/WatchYourLAN/pkg/models"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/aceberg/WatchYourLAN/internal/models"
|
||||
)
|
||||
|
||||
var AppConfig Conf
|
||||
var (
|
||||
AppConfig models.Conf
|
||||
|
||||
TemplPath string
|
||||
)
|
||||
|
||||
// var AllHosts []Host
|
||||
|
||||
//go:embed templates/*
|
||||
var TemplHTML embed.FS
|
||||
////go:embed templates/*
|
||||
// var TemplHTML embed.FS
|
||||
|
||||
func Webgui(appConfig Conf) {
|
||||
func Webgui(appConfig models.Conf) {
|
||||
|
||||
TemplPath = "../../internal/web/templates/"
|
||||
|
||||
AppConfig = appConfig
|
||||
address := AppConfig.GuiIP + ":" + AppConfig.GuiPort
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
// "strconv"
|
||||
. "github.com/aceberg/WatchYourLAN/pkg/models"
|
||||
)
|
||||
|
||||
func index(w http.ResponseWriter, r *http.Request) {
|
||||
var guiData GuiData
|
||||
guiData.Config = AppConfig
|
||||
guiData.Hosts = []Host{}
|
||||
|
||||
tmpl, _ := template.ParseFS(TemplHTML, "templates/index.html", "templates/header.html", "templates/footer.html")
|
||||
tmpl.ExecuteTemplate(w, "index", guiData)
|
||||
}
|
||||
|
||||
// func update_host(w http.ResponseWriter, r *http.Request) {
|
||||
// idStr := r.FormValue("id")
|
||||
// name := r.FormValue("name")
|
||||
// knownStr := r.FormValue("known")
|
||||
|
||||
// if idStr == "" {
|
||||
// fmt.Fprintf(w, "No data!")
|
||||
// } else {
|
||||
// var known uint16
|
||||
// id, _ := strconv.Atoi(idStr)
|
||||
// known = 0
|
||||
// if knownStr == "on" {
|
||||
// known = 1
|
||||
// }
|
||||
|
||||
// for i, oneHost := range AllHosts {
|
||||
// if oneHost.Id == uint16(id) {
|
||||
// AllHosts[i].Name = name
|
||||
// AllHosts[i].Known = known
|
||||
// db_update(AllHosts[i])
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// http.Redirect(w, r, r.Header.Get("Referer"), 302)
|
||||
// }
|
||||
Loading…
Reference in a new issue