Skip to content

Commit

Permalink
add web panel and related backend APIs (#230)
Browse files Browse the repository at this point in the history
* add web project

* update navbar

* add the server backend

* enable basic auth

* update web config

* update auto CI action

* update auto CI action

* update auto CI action

* fix lint warnings

* fix lint warnings

* add basic info API

* refactor the internal server

* add the login page

* update layout

* add logout button

* adjust the space

* update pages

* remove web

* add web project

* add web project

* update link style

* add login API

* add user context

* set menu item color

* set menu style

* add svg icons

* load basic info

* fix the time format

* update the theme switch

* update the stat component

* remove debug info

* update the layout

* load basic info

* load basic info

* check the credential

* check the credential

* fix the credential issue

* fix the credential issue

* fix SSR issue

* gracefully shutdown the internal server

* add domains page

* fix the nav bar

* add domain card

* add domain card

* update navbar

* refactor the class name

* add modal dialog

* add modal dialog

* remove selected domain

* rename the function

* add next js config

* update config

* remove icons

* add domain API

* remove unused code

* load domains

* remove domain

* remove domain

* add provider API

* add provider API

* update user store

* refactor the pages

* check domain length

* clear the form fields

* set the default height

* adjust the layout

* adjust the layout

* load providers

* add searchable dropdown list

* implement the provider settings

* fix the misspelling

* rewrite the URL from the server side

* update the github actions

* update the Dockerfile

* update the go generate command

* update the Dockerfile

* update the github actions

* update the README file

* update the README file

* update the README file
  • Loading branch information
TimothyYe authored Feb 17, 2024
1 parent 5868b71 commit 7af6309
Show file tree
Hide file tree
Showing 51 changed files with 7,313 additions and 56 deletions.
31 changes: 24 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,33 @@ jobs:
name: Auto triggered CI job
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.20.3
uses: actions/setup-go@v2
-
name: Set up Node.js
uses: actions/setup-node@v4
with:
go-version: 1.20.3
node-version: 18
-
name: Set up Go 1.22.0
uses: actions/setup-go@v5
with:
go-version: 1.22.0
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: golangci-lint
-
name: Check out code into the Go module directory
uses: actions/checkout@v4
-
name: Build the frontend project
run: |
cd web
npm install
npm run build
cd ..
go generate ./...
-
name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
- name: Run unit tests
-
name: Run unit tests
run: go test ./...
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
-
name: Set up Go
uses: actions/setup-go@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ test_configs/
/vendor

dist/
out/

.vscode
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# build the frontend project
- npm install --prefix ./web
- npm run build --prefix ./web
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
# Stage 1: Build the Next.js frontend
FROM node:18-alpine AS web-builder
WORKDIR /web
# Copy the Next.js project files into the image
COPY ./web/package.json ./web/package-lock.json ./
# Install dependencies
RUN npm install
# Copy the rest of the Next.js project files
COPY ./web .
# Build the Next.js project
RUN npm run build

# Stage 2: Build the Go backend
FROM golang:alpine AS builder
WORKDIR /godns
ADD . .
# Copy the Next.js build from the previous stage
COPY --from=web-builder /web/out ./web/out
RUN go generate ./...
RUN CGO_ENABLED=0 go build -o godns cmd/godns/godns.go

# Final stage: Copy the Go binary into a distroless image
FROM gcr.io/distroless/base
COPY --from=builder /godns/godns /godns
ENTRYPOINT ["/godns"]
63 changes: 59 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,18 @@
- [Display debug info](#display-debug-info)
- [Multiple API URLs](#multiple-api-urls)
- [Recommended APIs](#recommended-apis)
- [Web Panel](#web-panel)
- [Running GoDNS](#running-godns)
- [Manually](#manually)
- [As a manual daemon](#as-a-manual-daemon)
- [As a managed daemon (with upstart)](#as-a-managed-daemon-with-upstart)
- [As a managed daemon (with systemd)](#as-a-managed-daemon-with-systemd)
- [As a Docker container](#as-a-docker-container)
- [As a Windows service](#as-a-windows-service)
- [Contributing](#contributing)
- [Setup the frontend development environment](#setup-the-frontend-development-environment)
- [Build the frontend](#build-the-frontend)
- [Run the frontend](#run-the-frontend)
- [Special Thanks](#special-thanks)

---
Expand Down Expand Up @@ -737,7 +742,7 @@ Make shure there is just one record.
#### OVH
For OVH, you need to provide a Comsumerkey, an Appsecret, an Appkey and configure all the domains & subdomains.
For OVH, you need to provide a Consumerkey, an Appsecret, an Appkey and configure all the domains & subdomains.
The neeeded values can be obtaines by visting [this site](https://www.ovh.com/auth/api/createToken)
Rights should be '\*' on GET, POST and PUT
More info: [help.ovhcloud.com](https://help.ovhcloud.com/csm/en-gb-api-getting-started-ovhcloud-api?id=kb_article_view&sysparm_article=KB0042784)
Expand All @@ -748,7 +753,7 @@ More info: [help.ovhcloud.com](https://help.ovhcloud.com/csm/en-gb-api-getting-s
```json
{
"provider": "OVH",
"comsumer_key": "e389ac80cc8da9c7451bc7b8f171bf4f",
"consumer_key": "e389ac80cc8da9c7451bc7b8f171bf4f",
"app_secret": "d1ffee354d3643d70deaab48a09131fd",
"app_key": "cd338839d6472064",
"domains": [
Expand Down Expand Up @@ -1065,6 +1070,22 @@ GoDNS supports to fetch the public IP from multiple URLs via a simple round-robi
- <https://ipecho.net/plain>
- <https://api-ipv4.ip.sb/ip>
## Web Panel
<img src="https://github.com/TimothyYe/godns/blob/master/assets/snapshots/web-panel.jpg?raw=true" />
Starting from version 3.1.0, GoDNS provides a web panel to manage the configuration and monitor the status of the domains. The web UI is disabled by default. To enable it, just enable the `web_panel` in the configuration file.
```json
"web_panel": {
"enabled": true,
"addr": "0.0.0.0:9000",
"username": "admin",
"password": "123456"
}
```
After enabling the web panel, you can visit `http://localhost:9000` to manage the configuration and monitor the status of the domains.
## Running GoDNS
There are a few ways to run GoDNS.
Expand Down Expand Up @@ -1124,13 +1145,15 @@ Available docker registries:
- <https://hub.docker.com/r/timothyye/godns>
- <https://github.com/TimothyYe/godns/pkgs/container/godns>
Visit <https://hub.docker.com/r/timothyye/godns> to fetch the latest docker image.
With `/path/to/config.json` your local configuration file, run:
Visit <https://hub.docker.com/r/timothyye/godns> to fetch the latest docker image. The `-p 9000:9000` option is used to expose the web panel.
With `/path/to/config.json` as your local configuration file, run:
```bash
docker run \
-d --name godns --restart=always \
-v /path/to/config.json:/config.json \
-p 9000:9000 \
timothyye/godns:latest
```
Expand All @@ -1142,6 +1165,7 @@ docker run \
-e CONFIG=/config.yaml \
--restart=always \
-v /path/to/config.yaml:/config.yaml \
-p 9000:9000 \
timothyye/godns:latest
```
Expand All @@ -1165,6 +1189,37 @@ Note: you can uninstall the service by running:
nssm remove YOURSERVICENAME
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
### Setup the frontend development environment
The frontend project is built with [Next.js](https://nextjs.org/) and [daisyUI](https://daisyui.com/). To start the development environment, run:
```bash
cd web
npm install
npm run dev
```
### Build the frontend
To build the frontend, run:
```bash
cd web
npm run build
```
### Run the frontend
To run the frontend, run:
```bash
cd web
npm run start
```
## Special Thanks
<img src="https://i.imgur.com/xhe5RLZ.jpg" width="80px" align="right" />
Expand Down
Binary file added assets/snapshots/web-panel.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions cmd/godns/godns.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ const (

var (
config settings.Settings
optAddr = flag.String("a", ":9000", "Specify the address to listen on")
optConf = flag.String("c", "./config.json", "Specify a config file")
optHelp = flag.Bool("h", false, "Show help")

// Version is current version of GoDNS.
Version = "0.1"
)

func init() {
log.SetOutput(os.Stdout)
}

func main() {
utils.Version = Version

flag.Parse()
if *optHelp {
color.Cyan(utils.Logo, Version)
Expand All @@ -54,6 +53,9 @@ func main() {
log.Fatal(err)
}

// set the log level
log.SetOutput(os.Stdout)

if config.DebugInfo {
log.SetLevel(log.DebugLevel)
} else {
Expand All @@ -65,7 +67,7 @@ func main() {
}

// Create DNS manager
dnsManager := manager.GetDNSManager(configPath, &config)
dnsManager := manager.GetDNSManager(configPath, &config, *optAddr)

// Run DNS manager
log.Info("GoDNS started, starting the DNS manager...")
Expand Down
20 changes: 16 additions & 4 deletions configs/config_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
"domains": [
{
"domain_name": "example.com",
"sub_domains": ["www", "test"]
"sub_domains": [
"www",
"test"
]
},
{
"domain_name": "example2.com",
"sub_domains": ["www", "test"]
"sub_domains": [
"www",
"test"
]
}
],
"ip_urls": [
Expand All @@ -22,12 +28,18 @@
"ipv6_urls": [
"https://api6.ipify.org",
"https://api-ipv6.ip.sb/ip"
],
],
"ip_type": "IPv4",
"interval": 300,
"resolver": "8.8.8.8",
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36",
"ip_interface": "eth0",
"web_panel": {
"enabled": true,
"addr": "0.0.0.0:9000",
"username": "admin",
"password": "123456"
},
"socks5_proxy": "",
"use_proxy": false,
"debug_info": false,
Expand Down Expand Up @@ -55,4 +67,4 @@
"url": "http://localhost:5000/api/v1/send",
"request_body": "{ \"domain\": \"{{.Domain}}\", \"ip\": \"{{.CurrentIP}}\", \"ip_type\": \"{{.IPType}}\" }"
}
}
}
5 changes: 5 additions & 0 deletions configs/config_sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ interval: 300
resolver: 8.8.8.8
user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36"
ip_interface: eth0
web_panel:
enabled: true
addr: "0.0.0.0:9000"
username": "admin"
password": "123456"
socks5_proxy:
use_proxy: false
debug_info: false
Expand Down
19 changes: 16 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/bitly/go-simplejson v0.5.0
github.com/bwmarrin/discordgo v0.27.1
github.com/fatih/color v1.15.0
github.com/google/uuid v1.3.0
github.com/google/uuid v1.5.0
github.com/json-iterator/go v1.1.12
github.com/linode/linodego v1.16.1
github.com/miekg/dns v1.1.53
Expand All @@ -15,7 +15,20 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

require github.com/fsnotify/fsnotify v1.7.0
require (
github.com/fsnotify/fsnotify v1.7.0
github.com/gofiber/fiber/v2 v2.52.0
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
)

require (
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
Expand All @@ -24,7 +37,7 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/ovh/go-ovh v1.4.1
Expand Down
Loading

0 comments on commit 7af6309

Please sign in to comment.