Skip to content

Commit

Permalink
Merge pull request #102 from soulteary/feat-webui
Browse files Browse the repository at this point in the history
[Feat] Built-in management interface
  • Loading branch information
looterz authored Mar 24, 2022
2 parents ba3d5d7 + 55c70d9 commit 010f3ec
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
with:
go-version: 1.18

- name: Prepare Submodule
run: git submodule update --init

- name: Build
run: go build -v ./...

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "dashboard/reaper"]
path = dashboard/reaper
url = https://github.com/looterz/reaper.git
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ docker-compose up -d
If ```grimd.toml``` is not found, it will be generated for you, below is the default configuration.
```toml
# version this config was generated from
version = "1.0.8"
version = "1.0.9"

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

# enable the web interface by default
dashboard = true

# address to bind to for the DNS server
bind = "0.0.0.0:53"

Expand Down Expand Up @@ -144,6 +147,13 @@ curl -H "Accept: application/json" http://127.0.0.1:55006/application/active
# Web API
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.


If you want to enable the default dashboard, make sure the configuration file contains the following:

```toml
dashboard = true
```

![reaper-example](http://i.imgur.com/oXLtqSz.png)

# Speed
Expand Down
16 changes: 16 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"bufio"
"embed"
"io/fs"
"net"
"net/http"
"os"
Expand All @@ -13,6 +15,9 @@ import (
"gopkg.in/gin-contrib/cors.v1"
)

//go:embed dashboard/reaper
var dashboardAssets embed.FS

func isRunningInDockerContainer() bool {
// slightly modified from blog: https://paulbradley.org/indocker/
// docker creates a .dockerenv file at the root
Expand Down Expand Up @@ -53,6 +58,17 @@ func StartAPIServer(config *Config,

router.Use(cors.Default())

// Serves only if the user configuration enables the dashboard
if config.Dashboard {
router.GET("/", func(c *gin.Context) {
c.Redirect(http.StatusTemporaryRedirect, "/dashboard")
c.Abort()
})

dashboardAssets, _ := fs.Sub(dashboardAssets, "dashboard/reaper")
router.StaticFS("/dashboard", http.FS(dashboardAssets))
}

router.GET("/blockcache", func(c *gin.Context) {
special := make([]string, 0, len(blockCache.Special))
for k := range blockCache.Special {
Expand Down
6 changes: 5 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
var BuildVersion = "1.0.7"

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

// Config holds the configuration parameters
type Config struct {
Expand All @@ -41,6 +41,7 @@ type Config struct {
CustomDNSRecords []string
ToggleName string
ReactivationDelay uint
Dashboard bool
APIDebug bool
DoH string
UseDrbl int
Expand Down Expand Up @@ -80,6 +81,9 @@ logconfig = "file:grimd.log@2,stderr@2"
# apidebug enables the debug mode of the http api library
apidebug = false
# enable the web interface by default
dashboard = true
# address to bind to for the DNS server
bind = "0.0.0.0:53"
Expand Down
1 change: 1 addition & 0 deletions dashboard/reaper
Submodule reaper added at 79c906
3 changes: 2 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ FROM alpine:3.15.0 as certs
RUN apk --update add ca-certificates

FROM golang:1.18.0-alpine3.15 AS builder
RUN apk add git bash gcc musl-dev upx
RUN apk add git bash gcc musl-dev upx git
WORKDIR /app
COPY . .
RUN git submodule update --init
RUN go mod tidy
RUN go test -v ./...
ENV CGO_ENABLED=0
Expand Down

0 comments on commit 010f3ec

Please sign in to comment.