From 58ab0291b12d2be3ddc7e8fc4b8191e2ba8bae01 Mon Sep 17 00:00:00 2001 From: aceberg <1502200+aceberg@users.noreply.github.com> Date: Wed, 24 Aug 2022 16:04:28 +0700 Subject: [PATCH] DB: sort by date --- .github/workflows/docker-publish.yml | 12 ++++++------ Dockerfile | 4 ++-- src/db-connect.go | 2 +- src/index.go | 11 +++++++++-- src/templates/header.html | 2 +- src/templates/index.html | 5 +++-- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 9926bc7..9ec6629 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -3,14 +3,14 @@ name: Docker on: push: branches: [ "main" ] - paths-ignore: - - '**.md' - - 'Makefile' + paths: + - 'Dockerfile' + - 'scr/**' pull_request: branches: [ "main" ] - paths-ignore: - - '**.md' - - 'Makefile' + paths: + - 'Dockerfile' + - 'scr/**' env: IMAGE_NAME: watchyourlan diff --git a/Dockerfile b/Dockerfile index 83521bd..be29126 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,12 +7,12 @@ RUN cd /src && go build . FROM alpine +WORKDIR /app + RUN apk add --no-cache tzdata arp-scan \ && mkdir /data COPY src/templates /app/templates COPY --from=builder /src/watchyourlan /app/ -WORKDIR /app - ENTRYPOINT ["./watchyourlan"] \ No newline at end of file diff --git a/src/db-connect.go b/src/db-connect.go index 86ae5b3..5734a13 100644 --- a/src/db-connect.go +++ b/src/db-connect.go @@ -21,7 +21,7 @@ func db_select() (dbHosts []Host) { db, _ := sql.Open("sqlite3", AppConfig.DbPath) defer db.Close() - sqlStatement := `SELECT * FROM "now"` + sqlStatement := `SELECT * FROM "now" ORDER BY DATE DESC` res, err := db.Query(sqlStatement) if err != nil { diff --git a/src/index.go b/src/index.go index fe7c71d..7935bd8 100644 --- a/src/index.go +++ b/src/index.go @@ -8,9 +8,16 @@ import ( ) func index(w http.ResponseWriter, r *http.Request) { - //fmt.Println(AllHosts) + type allData struct { + Config Conf + Hosts []Host + } + var guiData allData + guiData.Config = AppConfig + guiData.Hosts = AllHosts + tmpl, _ := template.ParseFiles("templates/index.html", "templates/header.html") - tmpl.ExecuteTemplate(w, "index", AllHosts) + tmpl.ExecuteTemplate(w, "index", guiData) } func update_host(w http.ResponseWriter, r *http.Request) { diff --git a/src/templates/header.html b/src/templates/header.html index c5ee0c3..b064b45 100644 --- a/src/templates/header.html +++ b/src/templates/header.html @@ -4,7 +4,7 @@
Scanning interface: {{ .Config.Iface }}
| Name | @@ -13,7 +14,7 @@Hardware | Known |
|---|---|---|
| {{ .Name }} | @@ -41,7 +42,7 @@Last seen | Known |