Skip to content

Commit 010f3ec

Browse files
authored
Merge pull request #102 from soulteary/feat-webui
[Feat] Built-in management interface
2 parents ba3d5d7 + 55c70d9 commit 010f3ec

File tree

7 files changed

+41
-3
lines changed

7 files changed

+41
-3
lines changed

.github/workflows/test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
with:
2020
go-version: 1.18
2121

22+
- name: Prepare Submodule
23+
run: git submodule update --init
24+
2225
- name: Build
2326
run: go build -v ./...
2427

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "dashboard/reaper"]
2+
path = dashboard/reaper
3+
url = https://github.com/looterz/reaper.git

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ docker-compose up -d
2929
If ```grimd.toml``` is not found, it will be generated for you, below is the default configuration.
3030
```toml
3131
# version this config was generated from
32-
version = "1.0.8"
32+
version = "1.0.9"
3333

3434
# list of sources to pull blocklists from, stores them in ./sources
3535
sources = [
@@ -58,6 +58,9 @@ logconfig = "file:grimd.log@2,stderr@2"
5858
# apidebug enables the debug mode of the http api library
5959
apidebug = false
6060

61+
# enable the web interface by default
62+
dashboard = true
63+
6164
# address to bind to for the DNS server
6265
bind = "0.0.0.0:53"
6366

@@ -144,6 +147,13 @@ curl -H "Accept: application/json" http://127.0.0.1:55006/application/active
144147
# Web API
145148
A restful json api is exposed by default on the local interface, allowing you to build web applications that visualize requests, blocks and the cache. [reaper](https://github.com/looterz/reaper) is the default grimd web frontend.
146149

150+
151+
If you want to enable the default dashboard, make sure the configuration file contains the following:
152+
153+
```toml
154+
dashboard = true
155+
```
156+
147157
![reaper-example](http://i.imgur.com/oXLtqSz.png)
148158

149159
# Speed

api.go

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"bufio"
5+
"embed"
6+
"io/fs"
57
"net"
68
"net/http"
79
"os"
@@ -13,6 +15,9 @@ import (
1315
"gopkg.in/gin-contrib/cors.v1"
1416
)
1517

18+
//go:embed dashboard/reaper
19+
var dashboardAssets embed.FS
20+
1621
func isRunningInDockerContainer() bool {
1722
// slightly modified from blog: https://paulbradley.org/indocker/
1823
// docker creates a .dockerenv file at the root
@@ -53,6 +58,17 @@ func StartAPIServer(config *Config,
5358

5459
router.Use(cors.Default())
5560

61+
// Serves only if the user configuration enables the dashboard
62+
if config.Dashboard {
63+
router.GET("/", func(c *gin.Context) {
64+
c.Redirect(http.StatusTemporaryRedirect, "/dashboard")
65+
c.Abort()
66+
})
67+
68+
dashboardAssets, _ := fs.Sub(dashboardAssets, "dashboard/reaper")
69+
router.StaticFS("/dashboard", http.FS(dashboardAssets))
70+
}
71+
5672
router.GET("/blockcache", func(c *gin.Context) {
5773
special := make([]string, 0, len(blockCache.Special))
5874
for k := range blockCache.Special {

config.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
var BuildVersion = "1.0.7"
1717

1818
// ConfigVersion returns the version of grimd, this should be incremented every time the config changes so grimd presents a warning
19-
var ConfigVersion = "1.0.8"
19+
var ConfigVersion = "1.0.9"
2020

2121
// Config holds the configuration parameters
2222
type Config struct {
@@ -41,6 +41,7 @@ type Config struct {
4141
CustomDNSRecords []string
4242
ToggleName string
4343
ReactivationDelay uint
44+
Dashboard bool
4445
APIDebug bool
4546
DoH string
4647
UseDrbl int
@@ -80,6 +81,9 @@ logconfig = "file:grimd.log@2,stderr@2"
8081
# apidebug enables the debug mode of the http api library
8182
apidebug = false
8283
84+
# enable the web interface by default
85+
dashboard = true
86+
8387
# address to bind to for the DNS server
8488
bind = "0.0.0.0:53"
8589

dashboard/reaper

Submodule reaper added at 79c9068

docker/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ FROM alpine:3.15.0 as certs
22
RUN apk --update add ca-certificates
33

44
FROM golang:1.18.0-alpine3.15 AS builder
5-
RUN apk add git bash gcc musl-dev upx
5+
RUN apk add git bash gcc musl-dev upx git
66
WORKDIR /app
77
COPY . .
8+
RUN git submodule update --init
89
RUN go mod tidy
910
RUN go test -v ./...
1011
ENV CGO_ENABLED=0

0 commit comments

Comments
 (0)