index page

This commit is contained in:
aceberg 2024-08-21 15:34:24 +07:00
parent 26f3759936
commit e6a5bf852b
10 changed files with 40 additions and 127 deletions

View file

@ -1,102 +1,6 @@
# Change Log
All notable changes to this project will be documented in this file.
## [v1.0.6] - 2024-01-06
### Fixed
- Sort by `Known` field bug [#70](https://github.com/aceberg/WatchYourLAN/issues/70)
## [v1.0.5] - 2024-01-05
### Added
- Goreleaser for binaries [#66](https://github.com/aceberg/WatchYourLAN/issues/66)
- Better Mobile view [#51](https://github.com/aceberg/WatchYourLAN/issues/51)
- [More themes](https://github.com/aceberg/aceberg-bootswatch-fork) (emerald, grass, sand)
## [v1.0.4] - 2023-10-12
### Added
- Configurable `timeout` for `arp-scan` [#65](https://github.com/aceberg/WatchYourLAN/issues/65)
## [v1.0.3] - 2023-10-08
### Fixed
- Github Action workflow for binary release
- History bugs
## [v1.0.2] - 2023-10-07
### Fixed
- UI update bug [#61](https://github.com/aceberg/WatchYourLAN/issues/61)
### Added
- Device online/offline history [#60](https://github.com/aceberg/WatchYourLAN/issues/60)
## [v1.0.1] - 2023-08-18
### Added
- User Authentification
## [v1.0.0] - 2023-08-03
## [v2.0.0] - 2024-08-
### Changed
- Migrated to YAML config file format
## [v0.9.4] - 2023-06-26
### Added
- Local node modules option
## [v0.9.3] - 2023-06-04
### Added
- Background color: light or dark
## [v0.9.2] - 2023-05-05
### Added
- Choose log level in config
### Changed
- Move to go-1.20
## [v0.9.1] - 2023-01-16
### Added
- Scan host for open ports
- App version on config page
- Check if update is available
- Button to test notifications
### Changed
- Small fixes
## [v0.8.3] - 2023-01-03
### Added
- Clear table button (Config page)
- Delete host button
- Host name from DNS (Click on MAC to see host page)
- Sort buttons for all fields
## [v0.8.2] - 2023-01-02
### Added
- Option to ignore IP change [Issue #25](https://github.com/aceberg/WatchYourLAN/issues/25)
## [v0.8.1] - 2022-12-29
### Changed
- Full code refactoring
### Added
- Embed templates
- GUI config page
- Binary and Dep package
## [v0.7.5] - 2022-09-14
### Fixed
- Sort by IP [Issue #4](https://github.com/aceberg/WatchYourLAN/issues/4), [Issue #14](https://github.com/aceberg/WatchYourLAN/issues/14)
## [v0.7.3] - 2022-08-30
### Added
- Workflow to build ARM images
## [v0.7.2] - 2022-08-26
### Added
- Theme support in config
## [v0.7.1] - 2022-08-26
### Added
- Workaround for correct display of strings with apostrophes
### Fixed
- [Issue #2](https://github.com/aceberg/WatchYourLAN/issues/2)
- [Issue #5](https://github.com/aceberg/WatchYourLAN/issues/5)

2
go.mod
View file

@ -1,6 +1,6 @@
module github.com/aceberg/WatchYourLAN
go 1.22.4
go 1.22.6
require (
github.com/gin-gonic/gin v1.10.0

View file

@ -11,6 +11,8 @@ type Conf struct {
DBPath string
NodePath string
Ifaces []string
ScanMethod string
ArpArgs string
}
// Host - one host

12
internal/web/api.go Normal file
View file

@ -0,0 +1,12 @@
package web
import (
"net/http"
"github.com/gin-gonic/gin"
)
func apiAll(c *gin.Context) {
c.IndentedJSON(http.StatusOK, allHosts)
}

View file

@ -9,6 +9,8 @@ import (
var (
// appConfig - config for Web Gui
appConfig models.Conf
allHosts []models.Host
)
// templFS - html templates

View file

@ -14,8 +14,8 @@ func indexHandler(c *gin.Context) {
var guiData models.GuiData
guiData.Config = appConfig
res := arp.Scan(appConfig.Ifaces)
log.Println("ARPSCAN:", res)
allHosts = arp.Scan(appConfig.Ifaces)
log.Println("ARPSCAN:", allHosts)
go arp.GoScan()

View file

@ -3,27 +3,26 @@ var addrsArray = {};
loadAddrs();
function createHTML(addr, i) {
let off = '';
let now = '';
if (addr.Offline == 0) {
off = `<span style="color:var(--bs-success);">0</span>`;
if (addr.Now == 0) {
now = `<i class="bi bi-circle-fill" style="color:var(--bs-gray-500);"></i>`;
} else {
off = `<span style="color:var(--bs-danger);">${addr.Offline}</span>`;
now = `<i class="bi bi-check-circle-fill" style="color:var(--bs-success);"></i>`;
}
let html = `
<tr>
<td style="opacity: 45%;">${i}.</td>
<td>${addr.Name}</td>
<td>
<a href="/scan/?addr=${addr.Addr}">${addr.Name}</a>
<a href="http://${addr.IP}">${addr.IP}</a>
</td>
<td>
<a href="/scan/?addr=${addr.Addr}">${addr.Addr}</a>
</td>
<td>${addr.Total}</td>
<td>${addr.Watching}</td>
<td>${addr.Online}</td>
<td>${off}</td>
<td>${addr.Mac}</td>
<td>${addr.Hw}</td>
<td>${addr.Date}</td>
<td>${addr.Known}</td>
<td>${now}</td>
</tr>
`;

View file

@ -1 +1 @@
VERSION=0.1.2
VERSION=2.0.0

View file

@ -4,15 +4,6 @@
<script src="/fs/public/js/sort.js"></script>
<body>
<div class="container-lg">
<div class="row">
<div class="col-md mt-4">
<form action="/addr_add/" method="post" class="input-group">
<input name="name" type="text" class="form-control" placeholder="Name">
<input name="addr" type="text" class="form-control" placeholder="Address">
<button type="submit" class="btn btn-primary">Add</button>
</form>
</div>
</div>
<div class="row">
<div class="col-md mt-4 mb-4">
<div class="card border-primary">
@ -21,11 +12,12 @@
<thead>
<th style="width: 3em;"></th>
<th>Name <i class="bi bi-sort-down-alt" onclick="sortBy('Name')"></i></th>
<th>Addr <i class="bi bi-sort-down-alt" onclick="sortBy('Addr')"></i></th>
<th>Total <i class="bi bi-sort-down-alt" onclick="sortBy('Total')"></i></th>
<th>Watching <i class="bi bi-sort-down-alt" onclick="sortBy('Watching')"></i></th>
<th>Online <i class="bi bi-sort-down-alt" onclick="sortBy('Online')"></i></th>
<th>Offline <i class="bi bi-sort-down-alt" onclick="sortBy('Offline')"></i></th>
<th>IP <i class="bi bi-sort-down-alt" onclick="sortBy('IP')"></i></th>
<th>MAC <i class="bi bi-sort-down-alt" onclick="sortBy('Mac')"></i></th>
<th>Hardware <i class="bi bi-sort-down-alt" onclick="sortBy('Hw')"></i></th>
<th>Date <i class="bi bi-sort-down-alt" onclick="sortBy('Date')"></i></th>
<th>Known <i class="bi bi-sort-down-alt" onclick="sortBy('Known')"></i></th>
<th>Online <i class="bi bi-sort-down-alt" onclick="sortBy('Now')"></i></th>
</thead>
<tbody id="tBody"></tbody>
<!-- index.js -->

View file

@ -42,6 +42,8 @@ func Gui(dirPath, nodePath string) {
router.StaticFS("/fs/", http.FS(pubFS)) // public
router.GET("/api/all", apiAll) // api.go
router.GET("/", indexHandler) // index.go
router.GET("/config/", configHandler) // config.go