fix11: runtime contracts and smoke stability
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"hy2xs-admin/model/constant"
|
||||
"hy2xs-admin/model/dto"
|
||||
"hy2xs-admin/model/entity"
|
||||
"hy2xs-admin/model/vo"
|
||||
"hy2xs-admin/service"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -83,63 +79,9 @@ func Hysteria2Url(c *gin.Context) {
|
||||
}
|
||||
|
||||
func Hysteria2SubscribeUrl(c *gin.Context) {
|
||||
hysteria2SubscribeUrlDto, err := validateField(c, dto.Hysteria2SubscribeUrlDto{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
subscribeUrl, err := service.Hysteria2SubscribeUrl(*hysteria2SubscribeUrlDto.AccountId,
|
||||
*hysteria2SubscribeUrlDto.Protocol)
|
||||
if err != nil {
|
||||
vo.Fail(err.Error(), c)
|
||||
return
|
||||
}
|
||||
qrCode, err := qrcode.Encode(subscribeUrl, qrcode.Medium, 300)
|
||||
if err != nil {
|
||||
vo.Fail(err.Error(), c)
|
||||
return
|
||||
}
|
||||
subscribeVo := vo.Hysteria2SubscribeVo{
|
||||
Url: subscribeUrl,
|
||||
QrCode: qrCode,
|
||||
}
|
||||
vo.Success(subscribeVo, c)
|
||||
vo.Fail("subscription delivery is out of scope in HY2XS baseline", c)
|
||||
}
|
||||
|
||||
func Hysteria2Subscribe(c *gin.Context) {
|
||||
conPass := c.Param("conPass")
|
||||
conPass, err := url.QueryUnescape(conPass)
|
||||
if err != nil {
|
||||
vo.Fail("url decode err", c)
|
||||
return
|
||||
}
|
||||
userAgent := strings.ToLower(c.Request.Header.Get("User-Agent"))
|
||||
|
||||
var clientType string
|
||||
if strings.Contains(userAgent, constant.Shadowrocket) {
|
||||
clientType = constant.Shadowrocket
|
||||
} else if strings.Contains(userAgent, constant.Clash) {
|
||||
clientType = constant.Clash
|
||||
} else if strings.Contains(userAgent, constant.V2rayN) {
|
||||
clientType = constant.V2rayN
|
||||
} else if strings.Contains(userAgent, constant.NekoBox) {
|
||||
clientType = constant.NekoBox
|
||||
} else {
|
||||
clientType = constant.Clash
|
||||
}
|
||||
|
||||
userInfo, configStr, err := service.Hysteria2Subscribe(conPass, clientType)
|
||||
if err != nil {
|
||||
vo.Fail(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if clientType == constant.Shadowrocket || clientType == constant.Clash {
|
||||
c.Header("content-disposition", "attachment; filename=hui.yaml")
|
||||
c.Header("profile-update-interval", "12")
|
||||
c.Header("subscription-userinfo", userInfo)
|
||||
} else if clientType == constant.V2rayN {
|
||||
configStr = base64.StdEncoding.EncodeToString([]byte(configStr))
|
||||
}
|
||||
|
||||
c.String(200, configStr)
|
||||
vo.Fail("subscription delivery is out of scope in HY2XS baseline", c)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hy2xs-admin/model/vo"
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
@@ -11,13 +10,21 @@ func FilterHandler() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
matched, err := regexp.MatchString(`(?i)fofa|shodan|curl|wget`, c.Request.UserAgent())
|
||||
if err != nil {
|
||||
vo.Fail("Internal error", c)
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
|
||||
"code": http.StatusInternalServerError,
|
||||
"type": "no",
|
||||
"message": "Internal error",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
if matched {
|
||||
vo.Fail("Forbidden: Scanning tools are not allowed", c)
|
||||
c.AbortWithStatus(http.StatusForbidden)
|
||||
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{
|
||||
"code": http.StatusForbidden,
|
||||
"type": "no",
|
||||
"message": "Forbidden: Scanning tools are not allowed",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"hy2xs-admin/model/vo"
|
||||
)
|
||||
|
||||
func LocalOnlyHandler() gin.HandlerFunc {
|
||||
@@ -16,8 +15,12 @@ func LocalOnlyHandler() gin.HandlerFunc {
|
||||
}
|
||||
|
||||
if host != "127.0.0.1" && host != "::1" {
|
||||
vo.Fail("local access only", c)
|
||||
c.AbortWithStatus(http.StatusForbidden)
|
||||
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{
|
||||
"code": http.StatusForbidden,
|
||||
"type": "no",
|
||||
"message": "local access only",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/didip/tollbooth"
|
||||
"github.com/didip/tollbooth/limiter"
|
||||
"github.com/gin-gonic/gin"
|
||||
"hy2xs-admin/model/vo"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var limit *limiter.Limiter
|
||||
@@ -17,8 +17,12 @@ func RateLimiterHandler() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
httpError := tollbooth.LimitByRequest(limit, c.Writer, c.Request)
|
||||
if httpError != nil {
|
||||
vo.Fail("click too fast", c)
|
||||
c.Abort()
|
||||
c.AbortWithStatusJSON(http.StatusTooManyRequests, gin.H{
|
||||
"code": http.StatusTooManyRequests,
|
||||
"type": "no",
|
||||
"message": "click too fast",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
|
||||
@@ -24,7 +24,6 @@ func Router(router *gin.Engine, huiWebContext *string) {
|
||||
authApi := globalGroup.Group("/hui")
|
||||
authApi.Use(middleware.FilterHandler(), middleware.LogHandler(), middleware.RateLimiterHandler())
|
||||
initAuthRouter(authApi)
|
||||
initHysteria2SubscribeRouter(authApi)
|
||||
|
||||
huiAdminApi := globalGroup.Group("/hui")
|
||||
huiAdminApi.Use(
|
||||
|
||||
Reference in New Issue
Block a user