mirror of
https://github.com/yhl452493373/frps-panel.git
synced 2026-04-04 06:16:59 +08:00
add new login (not complete)
This commit is contained in:
@@ -175,7 +175,22 @@ func (c *HandleController) MakeHandlerFunc() gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *HandleController) MakeManagerFunc() func(context *gin.Context) {
|
||||
func (c *HandleController) MakeLoginFunc() func(context *gin.Context) {
|
||||
return func(context *gin.Context) {
|
||||
method := context.Request.Method
|
||||
if method == "GET" {
|
||||
context.HTML(http.StatusOK, "login.html", gin.H{
|
||||
"version": c.Version,
|
||||
})
|
||||
} else {
|
||||
context.JSON(http.StatusOK, gin.H{
|
||||
"Success": true,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *HandleController) MakeIndexFunc() func(context *gin.Context) {
|
||||
return func(context *gin.Context) {
|
||||
context.HTML(http.StatusOK, "index.html", gin.H{
|
||||
"version": c.Version,
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
plugin "github.com/fatedier/frp/pkg/plugin/server"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gopkg.in/ini.v1"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -37,17 +39,21 @@ func (c *HandleController) Register(rootDir string, engine *gin.Engine) {
|
||||
engine.Delims("${", "}")
|
||||
engine.LoadHTMLGlob(filepath.Join(assets, "templates/*"))
|
||||
engine.POST("/handler", c.MakeHandlerFunc())
|
||||
engine.Static("/static", filepath.Join(assets, "static"))
|
||||
engine.GET("/login", c.MakeLoginFunc())
|
||||
|
||||
var group *gin.RouterGroup
|
||||
if len(c.CommonInfo.User) != 0 {
|
||||
group = engine.Group("/", gin.BasicAuthForRealm(gin.Accounts{
|
||||
c.CommonInfo.User: c.CommonInfo.Pwd,
|
||||
}, "Restricted"))
|
||||
//group = engine.Group("/", gin.BasicAuthForRealm(gin.Accounts{
|
||||
// c.CommonInfo.User: c.CommonInfo.Pwd,
|
||||
//}, "Restricted"))
|
||||
|
||||
group = engine.Group("/", c.Authorize())
|
||||
} else {
|
||||
group = engine.Group("/")
|
||||
}
|
||||
group.Static("/static", filepath.Join(assets, "static"))
|
||||
group.GET("/", c.MakeManagerFunc())
|
||||
group.POST("/login", c.MakeLoginFunc())
|
||||
group.GET("/", c.MakeIndexFunc())
|
||||
group.GET("/lang.json", c.MakeLangFunc())
|
||||
group.GET("/tokens", c.MakeQueryTokensFunc())
|
||||
group.POST("/add", c.MakeAddTokenFunc())
|
||||
@@ -58,6 +64,23 @@ func (c *HandleController) Register(rootDir string, engine *gin.Engine) {
|
||||
group.GET("/proxy/*serverApi", c.MakeProxyFunc())
|
||||
}
|
||||
|
||||
func (c *HandleController) Authorize() gin.HandlerFunc {
|
||||
return func(context *gin.Context) {
|
||||
authorizationFromUser := context.Request.Header.Get("Authorization")
|
||||
|
||||
userAndPwd := []byte(c.CommonInfo.User + ":" + c.CommonInfo.Pwd)
|
||||
authorizationFromConfig := "Basic " + base64.StdEncoding.EncodeToString(userAndPwd)
|
||||
|
||||
if authorizationFromUser == authorizationFromConfig {
|
||||
context.Next()
|
||||
} else {
|
||||
context.Abort()
|
||||
context.Redirect(http.StatusTemporaryRedirect, "/login")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *HandleController) HandleLogin(content *plugin.LoginContent) plugin.Response {
|
||||
token := content.Metas["token"]
|
||||
user := content.User
|
||||
|
||||
Reference in New Issue
Block a user