Host page
This commit is contained in:
parent
f7f301b6ca
commit
409274759f
9 changed files with 92 additions and 8 deletions
|
|
@ -22,6 +22,15 @@ func apiHistory(c *gin.Context) {
|
||||||
c.IndentedJSON(http.StatusOK, histHosts)
|
c.IndentedJSON(http.StatusOK, histHosts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func apiHost(c *gin.Context) {
|
||||||
|
|
||||||
|
idStr := c.Param("id")
|
||||||
|
id, _ := strconv.Atoi(idStr)
|
||||||
|
host := getHostByID(id, allHosts) // functions.go
|
||||||
|
|
||||||
|
c.IndentedJSON(http.StatusOK, host)
|
||||||
|
}
|
||||||
|
|
||||||
func apiEdit(c *gin.Context) {
|
func apiEdit(c *gin.Context) {
|
||||||
|
|
||||||
idStr := c.Param("id")
|
idStr := c.Param("id")
|
||||||
|
|
@ -30,7 +39,7 @@ func apiEdit(c *gin.Context) {
|
||||||
|
|
||||||
id, _ := strconv.Atoi(idStr)
|
id, _ := strconv.Atoi(idStr)
|
||||||
|
|
||||||
host := getHostByID(id, allHosts)
|
host := getHostByID(id, allHosts) // functions.go
|
||||||
if host.Date != "" {
|
if host.Date != "" {
|
||||||
host.Name = name
|
host.Name = name
|
||||||
|
|
||||||
|
|
|
||||||
23
internal/web/host.go
Normal file
23
internal/web/host.go
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
"github.com/aceberg/WatchYourLAN/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func hostHandler(c *gin.Context) {
|
||||||
|
var guiData models.GuiData
|
||||||
|
guiData.Config = appConfig
|
||||||
|
|
||||||
|
idStr := c.Param("id")
|
||||||
|
log.Println("ID =", idStr)
|
||||||
|
|
||||||
|
guiData.Version = idStr
|
||||||
|
|
||||||
|
c.HTML(http.StatusOK, "header.html", guiData)
|
||||||
|
c.HTML(http.StatusOK, "host.html", guiData)
|
||||||
|
}
|
||||||
|
|
@ -23,5 +23,10 @@ function filterFunc(field, value) {
|
||||||
|
|
||||||
oldFilter = field;
|
oldFilter = field;
|
||||||
|
|
||||||
|
displayArrayData(addrsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetFilter() {
|
||||||
|
addrsArray = bkpArray;
|
||||||
displayArrayData(addrsArray);
|
displayArrayData(addrsArray);
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +28,7 @@ function createHTML(addr, i) {
|
||||||
<td>
|
<td>
|
||||||
<a href="http://${addr.IP}">${addr.IP}</a>
|
<a href="http://${addr.IP}">${addr.IP}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>${addr.Mac}</td>
|
<td><a href="/host/${addr.ID}">${addr.Mac}</a></td>
|
||||||
<td>${addr.Hw}</td>
|
<td>${addr.Hw}</td>
|
||||||
<td>${addr.Date}</td>
|
<td>${addr.Date}</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,31 @@ function sortByAny(someArray, field) {
|
||||||
// console.log("Field =", field);
|
// console.log("Field =", field);
|
||||||
|
|
||||||
if (field != oldField) {
|
if (field != oldField) {
|
||||||
someArray.sort(byFieldDown(field));
|
|
||||||
|
if (field == 'IP') {
|
||||||
|
someArray.sort((a, b) => {
|
||||||
|
const num1 = Number(a.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join(""));
|
||||||
|
const num2 = Number(b.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join(""));
|
||||||
|
return num1-num2;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
someArray.sort(byFieldDown(field));
|
||||||
|
}
|
||||||
|
|
||||||
oldField = field;
|
oldField = field;
|
||||||
} else {
|
} else {
|
||||||
someArray.sort(byFieldUp(field));
|
|
||||||
oldField = '';
|
if (field == 'IP') {
|
||||||
}
|
someArray.sort((a, b) => {
|
||||||
|
const num1 = Number(a.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join(""));
|
||||||
|
const num2 = Number(b.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join(""));
|
||||||
|
return num2-num1;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
someArray.sort(byFieldUp(field));
|
||||||
|
}
|
||||||
|
|
||||||
if (field == 'State') {
|
oldField = '';
|
||||||
someArray.sort(byFieldUp('Watch'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
displayArrayData(someArray);
|
displayArrayData(someArray);
|
||||||
|
|
|
||||||
28
internal/web/templates/host.html
Normal file
28
internal/web/templates/host.html
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
{{ define "host.html" }}
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container-lg">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md mt-4">
|
||||||
|
<div class="card border-primary">
|
||||||
|
<div class="card-header">Host</div>
|
||||||
|
<div class="card-body table-responsive">
|
||||||
|
<table class="table table-borderless">
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md mt-4 mb-4">
|
||||||
|
<div class="card border-primary">
|
||||||
|
<div class="card-header">Port scan</div>
|
||||||
|
<div class="card-body">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ template "footer.html" }}
|
||||||
|
{{ end }}
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
<li><a class="dropdown-item" onclick="filterFunc('line', 1)">Online</a></li>
|
<li><a class="dropdown-item" onclick="filterFunc('line', 1)">Online</a></li>
|
||||||
<li><a class="dropdown-item" onclick="filterFunc('line', 0)">Offline</a></li>
|
<li><a class="dropdown-item" onclick="filterFunc('line', 0)">Offline</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<button class="btn btn-outline-primary" onclick="resetFilter()">Reset filter</button>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-outline-primary" id="edit" onclick="editClick()">Edit names</button>
|
<button class="btn btn-outline-primary" id="edit" onclick="editClick()">Edit names</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,12 @@ func Gui(dirPath, nodePath string) {
|
||||||
|
|
||||||
router.GET("/api/all", apiAll) // api.go
|
router.GET("/api/all", apiAll) // api.go
|
||||||
router.GET("/api/history", apiHistory) // api.go
|
router.GET("/api/history", apiHistory) // api.go
|
||||||
|
router.GET("/api/host", apiHost) // api.go
|
||||||
router.GET("/api/edit/:id/:name/*known", apiEdit) // api.go
|
router.GET("/api/edit/:id/:name/*known", apiEdit) // api.go
|
||||||
|
|
||||||
router.GET("/", indexHandler) // index.go
|
router.GET("/", indexHandler) // index.go
|
||||||
router.GET("/history/", historyHandler) // index.go
|
router.GET("/history/", historyHandler) // index.go
|
||||||
|
router.GET("/host/:id", hostHandler) // host.go
|
||||||
router.GET("/config/", configHandler) // config.go
|
router.GET("/config/", configHandler) // config.go
|
||||||
|
|
||||||
router.POST("/config/", saveConfigHandler) // config.go
|
router.POST("/config/", saveConfigHandler) // config.go
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue