Skip to content

Commit

Permalink
更新Gin框架和软件版本
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxinpro committed Feb 19, 2023
1 parent 68567b4 commit 527b669
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WolGoWeb 经历两年多的测试已经在诸多测试、生产环境得以稳
无论是Windows还是Linux系统都可以直接下载对应的 release 编译版本直接运行即可,无需安装任何依赖。

```
WolGoWeb_0.0.4_linux_amd64 -port 9090
WolGoWeb_1.5.51_linux_amd64 -port 9090
```

其中参数 `-port` 表示服务端口号,默认是 `9090` 也可以不填。
Expand Down
2 changes: 1 addition & 1 deletion docker/buildx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BUILD_NAME="buildx-wol-go-web"
BUILD_PLAT=linux/386,linux/amd64,linux/arm/v7,linux/arm64/v8
BUILD_PUSH=chishin/wol-go-web
BUILD_VERS=version-0.0.4
BUILD_VERS=version-1.5.51

echo "=========== ${BUILD_NAME} ==========="

Expand Down
2 changes: 1 addition & 1 deletion docker/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ FROM --platform=${TARGETPLATFORM} alpine

MAINTAINER chishin <pro@xxgzs.org>

ENV VERSION 0.0.4
ENV VERSION 1.5.51
ENV PORT 9090
ENV KEY false
ENV TZ Asia/Shanghai
Expand Down
49 changes: 24 additions & 25 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
)

var (
VERSION = "0.0.4"
VERSION = "1.5.51"
)

var (
ConfigSource string
WebMode string
WebPort int
ApiKey string
WebMode string
WebPort int
ApiKey string
)

var (
Expand Down Expand Up @@ -50,14 +50,14 @@ func getEnvInt(name string, value int) int {
}
}

func init() {
flag.StringVar(&ConfigSource,"c", "default", "config source default or env.")
flag.StringVar(&WebMode,"mode", gin.ReleaseMode, "wol web port.")
flag.IntVar(&WebPort,"port", 9090, "wol web port.")
flag.StringVar(&ApiKey,"key", "false", "wol web api key.")
func init() {
flag.StringVar(&ConfigSource, "c", "default", "config source default or env.")
flag.StringVar(&WebMode, "mode", gin.ReleaseMode, "wol web port.")
flag.IntVar(&WebPort, "port", 9090, "wol web port.")
flag.StringVar(&ApiKey, "key", "false", "wol web api key.")
}

func main() {
func main() {
flag.Parse()

fmt.Printf("Start Run WolGoWeb...\n\n")
Expand All @@ -71,7 +71,7 @@ func main() {

gin.SetMode(WebMode)

r:=gin.Default()
r := gin.Default()

r.GET("/", GetIndex)
r.GET("/index", GetIndex)
Expand Down Expand Up @@ -108,13 +108,13 @@ func VerifyAuth(key string, mac string, vk int64, token string) (int, string) {
if len(token) != 32 {
err = 101
message = "No authority."
} else if timeUnix - vk > 30 || vk - timeUnix > 1 {
} else if timeUnix-vk > 30 || vk-timeUnix > 1 {
err = 102
message = "The value of Time is no longer in the valid range."
} else if bakVK, ok := vkBakDict[mac]; ok && bakVK == vk {
err = 103
message = "Time value repetition."
} else if MD5(ApiKey + mac + fmt.Sprintf("%d", vk)) != token {
} else if MD5(ApiKey+mac+fmt.Sprintf("%d", vk)) != token {
err = 104
message = "No authority token."
} else {
Expand All @@ -124,31 +124,30 @@ func VerifyAuth(key string, mac string, vk int64, token string) (int, string) {
return err, message
}

func GetWol(c *gin.Context) {
mac:=c.Query("mac")
ip:=c.DefaultQuery("ip", "255.255.255.255")
port:=c.DefaultQuery("port", "9")
token:=c.DefaultQuery("token", "")
vk, _:=strconv.ParseInt(c.DefaultQuery("time", "0"),10, 64)
if errAuth, messageAuth := VerifyAuth(ApiKey, mac, vk, token); errAuth==0 {
err:=Wake(mac,ip,port)
func GetWol(c *gin.Context) {
mac := c.Query("mac")
ip := c.DefaultQuery("ip", "255.255.255.255")
port := c.DefaultQuery("port", "9")
token := c.DefaultQuery("token", "")
vk, _ := strconv.ParseInt(c.DefaultQuery("time", "0"), 10, 64)
if errAuth, messageAuth := VerifyAuth(ApiKey, mac, vk, token); errAuth == 0 {
err := Wake(mac, ip, port)
if err != nil {
c.JSON(200, gin.H{
"error": 100,
"error": 100,
"message": fmt.Sprintf("%s", err),
})
} else {
c.JSON(200, gin.H{
"error": 0,
"error": 0,
"message": fmt.Sprintf("Wake Success Mac:%s", mac),
})
}
} else {
c.JSON(200, gin.H{
"error": errAuth,
"error": errAuth,
"message": messageAuth,
})
}

}

0 comments on commit 527b669

Please sign in to comment.