-
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
208 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package db | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aceberg/WatchYourLAN/internal/models" | ||
) | ||
|
||
// InsertHist - insert history into table | ||
func InsertHist(path string, hist models.History) { | ||
hist.Name = quoteStr(hist.Name) | ||
hist.Hw = quoteStr(hist.Hw) | ||
sqlStatement := `INSERT INTO "history" (HOST, NAME, IP, MAC, HW, DATE, KNOWN, STATE) | ||
VALUES ('%d','%s','%s','%s','%s','%s','%d','%d');` | ||
sqlStatement = fmt.Sprintf(sqlStatement, hist.Host, hist.Name, hist.IP, hist.Mac, hist.Hw, hist.Date, hist.Known, hist.State) | ||
//fmt.Println("Insert statement:", sqlStatement) | ||
dbExec(path, sqlStatement) | ||
} | ||
|
||
// DeleteHist - delete history from DB | ||
func DeleteHist(path string, id int) { | ||
sqlStatement := `DELETE FROM "history" WHERE ID='%d';` | ||
sqlStatement = fmt.Sprintf(sqlStatement, id) | ||
dbExec(path, sqlStatement) | ||
} | ||
|
||
// ClearHist - delete all history from table | ||
func ClearHist(path string) { | ||
sqlStatement := `DELETE FROM "history";` | ||
dbExec(path, sqlStatement) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package web | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/aceberg/WatchYourLAN/internal/db" | ||
"github.com/aceberg/WatchYourLAN/internal/models" | ||
) | ||
|
||
func historyHandler(w http.ResponseWriter, r *http.Request) { | ||
var guiData models.GuiData | ||
|
||
guiData.Config = AppConfig | ||
guiData.Hist = db.SelectHist(AppConfig.DbPath) | ||
|
||
execTemplate(w, "history", guiData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{{ define "history"}} | ||
<!--Auto refresh (seconds)--> | ||
<meta http-equiv="refresh" content="{{ .Config.Timeout }}"> | ||
<body> | ||
<div class="container mt-3"> | ||
<table class="table table-striped"> | ||
<tr> | ||
<th>ID</th> | ||
<th>Name</th> | ||
<th>IP</th> | ||
<th>Mac</th> | ||
<th>Hardware</th> | ||
<th>Last seen</th> | ||
<th>Known</th> | ||
<th>State</th> | ||
</tr> | ||
{{ range .Hist }} | ||
<tr> | ||
<td><a href="/host?id={{ .Host }}">{{ .Host }}</a></td> | ||
<td>{{ .Name }}</td> | ||
<td><a href="http://{{ .IP }}" target="_blank">{{ .IP }}</a></td> | ||
<td><a href="/host?id={{ .Host }}">{{ .Mac }}</a></td> | ||
<td>{{ .Hw }}</td> | ||
<td>{{ .Date }}</td> | ||
<td> | ||
{{ if eq .Known 1 }} | ||
Yes | ||
{{ else }} | ||
No | ||
{{ end }} | ||
</td> | ||
<td> | ||
{{ if eq .State 1 }} | ||
<i class="bi bi-circle-fill text-success"></i> | ||
{{ else }} | ||
<i class="bi bi-circle-fill text-danger"></i> | ||
{{ end }} | ||
</td> | ||
</tr> | ||
{{ end }} | ||
</table> | ||
</div> | ||
|
||
{{ template "footer" }} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.