diff --git a/README.md b/README.md index a107702..ecb47fd 100644 --- a/README.md +++ b/README.md @@ -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` 也可以不填。 diff --git a/docker/buildx.sh b/docker/buildx.sh index 7ca0a90..3be1b6f 100644 --- a/docker/buildx.sh +++ b/docker/buildx.sh @@ -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} ===========" diff --git a/docker/dockerfile b/docker/dockerfile index 86792b9..2cd73ea 100644 --- a/docker/dockerfile +++ b/docker/dockerfile @@ -12,7 +12,7 @@ FROM --platform=${TARGETPLATFORM} alpine MAINTAINER chishin -ENV VERSION 0.0.4 +ENV VERSION 1.5.51 ENV PORT 9090 ENV KEY false ENV TZ Asia/Shanghai diff --git a/src/main.go b/src/main.go index 8a91541..1616209 100644 --- a/src/main.go +++ b/src/main.go @@ -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 ( @@ -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") @@ -71,7 +71,7 @@ func main() { gin.SetMode(WebMode) - r:=gin.Default() + r := gin.Default() r.GET("/", GetIndex) r.GET("/index", GetIndex) @@ -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 { @@ -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, }) } } -