Skip to content

Commit

Permalink
Release 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Jul 19, 2023
1 parent 283a4c7 commit 0d270e8
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.0.5] - 2023-07-
## [1.0.5] - 2023-07-19
### Added
- Uptime: split date and time
- Uptime: filter by date, address, port, notification
- Edit board file online

### Changed
- Connection timeout to 3 seconds

### Fixed
- Error: concurrent map read and map write

## [1.0.4] - 2023-07-14
### Added
- Uptime: color Date
Expand Down
40 changes: 40 additions & 0 deletions internal/web/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package web

import (
"net/http"
"os"

"github.com/aceberg/miniboard/internal/check"
"github.com/aceberg/miniboard/internal/models"
"github.com/aceberg/miniboard/internal/yaml"
)

func fileHandler(w http.ResponseWriter, r *http.Request) {
var guiData models.GuiData
guiData.Config = AppConfig
guiData.CurrentTab = "Edit board file"
guiData.Links = AllLinks

text := r.FormValue("text")

file, err := os.ReadFile(AppConfig.YamlPath)
check.IfError(err)
guiData.Version = string(file)

if text != "" {
err := os.WriteFile(AppConfig.YamlPath, []byte(text), 0644)
check.IfError(err)

AllLinks = yaml.Read(AppConfig.YamlPath)
assignAllIDs() // assign-IDs.go

close(AppConfig.Quit)
AppConfig.Quit = make(chan bool)

go scanPorts(AppConfig.Quit) // scan.go

http.Redirect(w, r, r.Header.Get("Referer"), 302)
}

execTemplate(w, "file", guiData)
}
8 changes: 7 additions & 1 deletion internal/web/scan-uptime.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
var (
// RetriesSyncMap - count retries to send notifications
RetriesSyncMap sync.Map
// MuUptime - mutex for AllLinks.Uptime
MuUptime sync.Mutex
)

func appendUptimeMon(panelName string, host models.Host, notif bool) {
Expand All @@ -28,7 +30,9 @@ func appendUptimeMon(panelName string, host models.Host, notif bool) {
mon.Color = check.Color(mon.Date)
mon.State = host.State
if notif {
MuUptime.Lock()
mon.Notify = AllLinks.Uptime.Panels[panelName].Notify
MuUptime.Unlock()
}
UptimeMon = append(UptimeMon, mon)
}
Expand All @@ -37,9 +41,11 @@ func scanUptime(panelName string, host models.Host, oldState bool) {
var retries int
var notifEnabled, notif bool

MuUptime.Lock()
panel, exists := AllLinks.Uptime.Panels[panelName]
MuUptime.Unlock()

if AllLinks.Uptime.Enabled && exists {
if exists {
if len(panel.Notify) > 0 {
retriesAny, ok := RetriesSyncMap.LoadOrStore(panelName+host.Name, 0)
if ok {
Expand Down
19 changes: 13 additions & 6 deletions internal/web/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

var (
// Mu - mutex to prevent concurrent map writes
Mu sync.Mutex
// MuScan - mutex for AllLinks.Panels
MuScan sync.Mutex
)

func scanPorts(quit chan bool) {
Expand All @@ -23,7 +23,10 @@ func scanPorts(quit chan bool) {
case <-quit:
return
default:
for name := range AllLinks.Panels {
MuScan.Lock()
panels := AllLinks.Panels
MuScan.Unlock()
for name := range panels {
_, exists := alreadyScanning[name]
if !exists {
go scanPanel(name, quit)
Expand All @@ -42,7 +45,9 @@ func scanPanel(panelName string, quit chan bool) {
case <-quit:
return
default:
MuScan.Lock()
panel, exists := AllLinks.Panels[panelName]
MuScan.Unlock()
if !exists {
return
}
Expand All @@ -56,12 +61,14 @@ func scanPanel(panelName string, quit chan bool) {
host.State = check.State(host)
hosts[key] = host

scanUptime(panelName, host, oldState) // scan-uptime.go
if AllLinks.Uptime.Enabled {
scanUptime(panelName, host, oldState) // scan-uptime.go
}
}
panel.Hosts = hosts
Mu.Lock()
MuScan.Lock()
AllLinks.Panels[panelName] = panel
Mu.Unlock()
MuScan.Unlock()
}

timeout, err := strconv.Atoi(panel.Timeout)
Expand Down
17 changes: 17 additions & 0 deletions internal/web/templates/file.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ define "file" }}
</head>
<body>
<div class="container">
<br>
<div class="row">
<div class="col">
<form action="/file/" method="post">
<textarea name="text" rows="50" class="form-control">{{ .Version }}</textarea>
<button type="submit" class="btn btn-primary">Save</button>
</form>
</div>
</div>
</div>

{{ template "footer" }}
{{ end }}
1 change: 1 addition & 0 deletions internal/web/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<li><a class="dropdown-item" href="/tabs/">Edit tabs</a></li>
<li><a class="dropdown-item" href="/uptime_edit/">Edit uptime</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="/file/">Edit board file</a></li>
<li><a class="dropdown-item" href="/?reload=yes">Reload</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" target="_blank" href="https://github.com/aceberg/miniboard">About</a></li>
Expand Down
2 changes: 1 addition & 1 deletion internal/web/templates/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=1.0.4
VERSION=1.0.5
1 change: 1 addition & 0 deletions internal/web/webgui.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func Gui(confPath, yamlPath, nodePath string) {
http.HandleFunc("/", indexHandler) // index.go
http.HandleFunc("/config/", configHandler) // config.go
http.HandleFunc("/config_save/", saveConfigHandler) // config.go
http.HandleFunc("/file/", fileHandler) // file.go
http.HandleFunc("/host/", hostHandler) // host.go
http.HandleFunc("/panels/", panelsHandler) // panels.go
http.HandleFunc("/panel_edit/", panelEditHandler) // panel-edit.go
Expand Down

0 comments on commit 0d270e8

Please sign in to comment.