Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add web panel and related backend APIs #230

Merged
merged 81 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
de69273
add web project
TimothyYe Feb 6, 2024
5ff78ec
update navbar
TimothyYe Feb 6, 2024
5532349
add the server backend
TimothyYe Feb 7, 2024
4b604f7
enable basic auth
TimothyYe Feb 7, 2024
45f3684
update web config
TimothyYe Feb 9, 2024
10b574e
update auto CI action
TimothyYe Feb 9, 2024
b950f92
update auto CI action
TimothyYe Feb 9, 2024
79e9a4f
update auto CI action
TimothyYe Feb 9, 2024
bc3e485
fix lint warnings
TimothyYe Feb 9, 2024
796ba15
fix lint warnings
TimothyYe Feb 9, 2024
98b72fd
add basic info API
TimothyYe Feb 9, 2024
573e1b8
refactor the internal server
TimothyYe Feb 9, 2024
e1912a8
add the login page
TimothyYe Feb 10, 2024
3332b11
update layout
TimothyYe Feb 10, 2024
b36f353
add logout button
TimothyYe Feb 10, 2024
29580a7
adjust the space
TimothyYe Feb 10, 2024
9a52183
update pages
TimothyYe Feb 11, 2024
e8a675f
remove web
TimothyYe Feb 11, 2024
1e3ddba
add web project
TimothyYe Feb 11, 2024
e3751f2
add web project
TimothyYe Feb 11, 2024
bafcbf6
update link style
TimothyYe Feb 11, 2024
490c658
add login API
TimothyYe Feb 11, 2024
c389fb3
add user context
TimothyYe Feb 11, 2024
31e548c
set menu item color
TimothyYe Feb 11, 2024
24542b4
set menu style
TimothyYe Feb 11, 2024
cb13ffd
add svg icons
TimothyYe Feb 12, 2024
310b453
load basic info
TimothyYe Feb 12, 2024
100e119
fix the time format
TimothyYe Feb 12, 2024
80416b7
update the theme switch
TimothyYe Feb 12, 2024
28ede27
update the stat component
TimothyYe Feb 12, 2024
6e24806
remove debug info
TimothyYe Feb 12, 2024
a622d1a
update the layout
TimothyYe Feb 12, 2024
5cba73a
load basic info
TimothyYe Feb 12, 2024
e6683a3
load basic info
TimothyYe Feb 12, 2024
2e2b69b
check the credential
TimothyYe Feb 12, 2024
325f680
check the credential
TimothyYe Feb 12, 2024
25cfad0
fix the credential issue
TimothyYe Feb 12, 2024
4116fe4
fix the credential issue
TimothyYe Feb 13, 2024
c1cef17
merge with master branch
TimothyYe Feb 13, 2024
bead1c9
fix SSR issue
TimothyYe Feb 13, 2024
85545e6
gracefully shutdown the internal server
TimothyYe Feb 13, 2024
8276f33
add domains page
TimothyYe Feb 13, 2024
73d2b94
fix the nav bar
TimothyYe Feb 13, 2024
f69db2d
add domain card
TimothyYe Feb 14, 2024
0cabe42
add domain card
TimothyYe Feb 14, 2024
f538ac0
update navbar
TimothyYe Feb 14, 2024
d67384e
refactor the class name
TimothyYe Feb 14, 2024
8ffaabc
add modal dialog
TimothyYe Feb 14, 2024
62ec0c9
add modal dialog
TimothyYe Feb 14, 2024
deb68f1
remove selected domain
TimothyYe Feb 14, 2024
d8293fa
rename the function
TimothyYe Feb 14, 2024
49067ae
add next js config
TimothyYe Feb 15, 2024
cf83a10
update config
TimothyYe Feb 15, 2024
d65684f
remove icons
TimothyYe Feb 15, 2024
941ba49
add domain API
TimothyYe Feb 15, 2024
bf1c629
remove unused code
TimothyYe Feb 15, 2024
302d468
load domains
TimothyYe Feb 15, 2024
8ca0202
remove domain
TimothyYe Feb 15, 2024
3cdab86
remove domain
TimothyYe Feb 15, 2024
c3f363f
add provider API
TimothyYe Feb 16, 2024
25c36c2
add provider API
TimothyYe Feb 16, 2024
4044e71
update user store
TimothyYe Feb 16, 2024
55761b4
refactor the pages
TimothyYe Feb 16, 2024
8fe9884
check domain length
TimothyYe Feb 16, 2024
f207263
clear the form fields
TimothyYe Feb 16, 2024
7cdd195
set the default height
TimothyYe Feb 16, 2024
808f539
adjust the layout
TimothyYe Feb 16, 2024
704a48e
adjust the layout
TimothyYe Feb 16, 2024
632dc22
load providers
TimothyYe Feb 16, 2024
09fdadb
add searchable dropdown list
TimothyYe Feb 17, 2024
d358c30
implement the provider settings
TimothyYe Feb 17, 2024
7cd564a
fix the misspelling
TimothyYe Feb 17, 2024
d296175
rewrite the URL from the server side
TimothyYe Feb 17, 2024
778454f
update the github actions
TimothyYe Feb 17, 2024
921b05f
update the Dockerfile
TimothyYe Feb 17, 2024
2e83aa5
update the go generate command
TimothyYe Feb 17, 2024
08bcfb4
update the Dockerfile
TimothyYe Feb 17, 2024
6befe52
update the github actions
TimothyYe Feb 17, 2024
f73ef5e
update the README file
TimothyYe Feb 17, 2024
e568448
update the README file
TimothyYe Feb 17, 2024
1ea473e
update the README file
TimothyYe Feb 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading