Skip to content

Commit aca708c

Browse files
committed
add a page as GUI
1 parent f36356d commit aca708c

File tree

11 files changed

+150
-173
lines changed

11 files changed

+150
-173
lines changed

Diff for: docker/Dockerfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM --platform=linux/amd64 golang:1.18-alpine3.16 AS build_base
2+
3+
ENV GO111MODULE=on
4+
ENV GOPROXY=https://goproxy.cn
5+
ENV TZ Asia/Shanghai
6+
7+
COPY ./ /buildir
8+
9+
RUN cd /buildir && \
10+
go mod tidy && \
11+
go build -o wol ./src/main.go ./src/wol.go
12+
13+
FROM --platform=linux/amd64 alpine
14+
15+
WORKDIR /web
16+
17+
ENV VERSION 0.0.4
18+
ENV PORT 9090
19+
ENV KEY false
20+
21+
COPY ./static /web/static
22+
COPY --from=build_base /buildir/wol /web/wol
23+
24+
RUN chmod 755 /web/static
25+
26+
EXPOSE $PORT
27+
28+
CMD ["/web/wol", "-c", "env"]
29+

Diff for: docker/README.md

-81
This file was deleted.

Diff for: docker/buildx.sh

-14
This file was deleted.

Diff for: docker/docker-compose.yml

-10
This file was deleted.

Diff for: docker/dockerfile

-38
This file was deleted.

Diff for: go.sum

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
23
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
34
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
45
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
5-
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
6-
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
76
github.com/gin-gonic/gin v1.7.2 h1:Tg03T9yM2xa8j6I3Z3oqLaQRSmKvxPd6g/2HJ6zICFA=
87
github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
8+
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
99
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
1010
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
1111
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
1212
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
1313
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
14-
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
15-
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
1614
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
1715
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
1816
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
1917
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
2018
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
19+
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
2120
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
2221
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
2322
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
2423
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
2524
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
25+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
2626
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
27+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
2728
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
29+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2830
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2931
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3032
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
33+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
3134
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
3235
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
3336
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
@@ -44,6 +47,7 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
4447
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
4548
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
4649
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
50+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
4751
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4852
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
4953
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=

Diff for: makefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BINARY="wol"
2+
VERSION="0.2"
3+
4+
build:
5+
docker build -t ${BINARY}:${VERSION} -f docker/Dockerfile .
6+
7+
push:
8+
docker tag ${BINARY}:${VERSION} parasomnia/${BINARY}:${VERSION}
9+
docker push parasomnia/${BINARY}:${VERSION}

Diff for: src/main.go

+31-26
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"flag"
66
"fmt"
77
"github.com/gin-gonic/gin"
8+
"net/http"
89
"os"
910
"strconv"
1011
"time"
@@ -16,9 +17,9 @@ var (
1617

1718
var (
1819
ConfigSource string
19-
WebMode string
20-
WebPort int
21-
ApiKey string
20+
WebMode string
21+
WebPort int
22+
ApiKey string
2223
)
2324

2425
var (
@@ -50,14 +51,14 @@ func getEnvInt(name string, value int) int {
5051
}
5152
}
5253

53-
func init() {
54-
flag.StringVar(&ConfigSource,"c", "default", "config source default or env.")
55-
flag.StringVar(&WebMode,"mode", gin.ReleaseMode, "wol web port.")
56-
flag.IntVar(&WebPort,"port", 9090, "wol web port.")
57-
flag.StringVar(&ApiKey,"key", "false", "wol web api key.")
54+
func init() {
55+
flag.StringVar(&ConfigSource, "c", "default", "config source default or env.")
56+
flag.StringVar(&WebMode, "mode", gin.ReleaseMode, "wol.exe.exe.exe web port.")
57+
flag.IntVar(&WebPort, "port", 9090, "wol.exe.exe.exe web port.")
58+
flag.StringVar(&ApiKey, "key", "false", "wol.exe.exe.exe web api key.")
5859
}
5960

60-
func main() {
61+
func main() {
6162
flag.Parse()
6263

6364
fmt.Printf("Start Run WolGoWeb...\n\n")
@@ -71,10 +72,11 @@ func main() {
7172

7273
gin.SetMode(WebMode)
7374

74-
r:=gin.Default()
75+
r := gin.Default()
7576

7677
r.GET("/", GetIndex)
77-
r.GET("/index", GetIndex)
78+
r.Static("/index", "./static")
79+
r.GET("/help", GetHelp)
7880
r.GET("/wol", GetWol)
7981

8082
fmt.Printf("WolGoWeb Runing [port:%d, key:%s]\n", WebPort, ApiKey)
@@ -83,10 +85,14 @@ func main() {
8385
}
8486

8587
func GetIndex(c *gin.Context) {
88+
c.Redirect(http.StatusPermanentRedirect, "/index")
89+
}
90+
91+
func GetHelp(c *gin.Context) {
8692
c.String(200, `
8793
WOL唤醒工具
8894
89-
API: %s/wol
95+
API: %s/wol.exe.exe.exe
9096
9197
Params:
9298
mac : 需要唤醒的MAC地址(必须),
@@ -108,13 +114,13 @@ func VerifyAuth(key string, mac string, vk int64, token string) (int, string) {
108114
if len(token) != 32 {
109115
err = 101
110116
message = "No authority."
111-
} else if timeUnix - vk > 30 || vk - timeUnix > 1 {
117+
} else if timeUnix-vk > 30 || vk-timeUnix > 1 {
112118
err = 102
113119
message = "The value of Time is no longer in the valid range."
114120
} else if bakVK, ok := vkBakDict[mac]; ok && bakVK == vk {
115121
err = 103
116122
message = "Time value repetition."
117-
} else if MD5(ApiKey + mac + fmt.Sprintf("%d", vk)) != token {
123+
} else if MD5(ApiKey+mac+fmt.Sprintf("%d", vk)) != token {
118124
err = 104
119125
message = "No authority token."
120126
} else {
@@ -124,31 +130,30 @@ func VerifyAuth(key string, mac string, vk int64, token string) (int, string) {
124130
return err, message
125131
}
126132

127-
func GetWol(c *gin.Context) {
128-
mac:=c.Query("mac")
129-
ip:=c.DefaultQuery("ip", "255.255.255.255")
130-
port:=c.DefaultQuery("port", "9")
131-
token:=c.DefaultQuery("token", "")
132-
vk, _:=strconv.ParseInt(c.DefaultQuery("time", "0"),10, 64)
133-
if errAuth, messageAuth := VerifyAuth(ApiKey, mac, vk, token); errAuth==0 {
134-
err:=Wake(mac,ip,port)
133+
func GetWol(c *gin.Context) {
134+
mac := c.Query("mac")
135+
ip := c.DefaultQuery("ip", "255.255.255.255")
136+
port := c.DefaultQuery("port", "9")
137+
token := c.DefaultQuery("token", "")
138+
vk, _ := strconv.ParseInt(c.DefaultQuery("time", "0"), 10, 64)
139+
if errAuth, messageAuth := VerifyAuth(ApiKey, mac, vk, token); errAuth == 0 {
140+
err := Wake(mac, ip, port)
135141
if err != nil {
136142
c.JSON(200, gin.H{
137-
"error": 100,
143+
"error": 100,
138144
"message": fmt.Sprintf("%s", err),
139145
})
140146
} else {
141147
c.JSON(200, gin.H{
142-
"error": 0,
148+
"error": 0,
143149
"message": fmt.Sprintf("Wake Success Mac:%s", mac),
144150
})
145151
}
146152
} else {
147153
c.JSON(200, gin.H{
148-
"error": errAuth,
154+
"error": errAuth,
149155
"message": messageAuth,
150156
})
151157
}
152158

153159
}
154-

Diff for: static/app.png

38.5 KB
Loading

Diff for: static/button.png

55.2 KB
Loading

0 commit comments

Comments
 (0)