Skip to content

Commit

Permalink
对应0.42.0升级
Browse files Browse the repository at this point in the history
  • Loading branch information
chi-cat committed Jun 25, 2022
1 parent 2c15ab4 commit fc48ee3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
**/bin
.idea
**/*.log
**/*.exe
**/*.exe
**/go.sum
./frps-auth
7 changes: 2 additions & 5 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,8 @@ func SignMD5(text string) string {
}

func createSignKey() string {
id, err := uuid.NewV4()
if nil != err {
return uuid.NewV5(uuid.NamespaceURL, "frps-auth").String()
}
return id.String()
v4 := uuid.NewV4()
return v4.String()
}

func AddAuthServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand Down
22 changes: 22 additions & 0 deletions embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"embed"
"io/fs"
"net/http"
)

//go:embed static/*
var embedFS embed.FS

func getStaticFS(path string) http.FileSystem {
if path != "" {
return http.Dir(path)
} else {
staticFS, err := fs.Sub(embedFS, "static")
if err != nil {
panic(err)
}
return http.FS(staticFS)
}
}
20 changes: 18 additions & 2 deletions frps-auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type AuthConfig struct {
Username string `ini:"username"`
Password string `ini:"password"`
Salt string `ini:"salt"`
Static string `ini:"static"`
}

var Config AuthConfig = AuthConfig{
Expand All @@ -68,6 +69,7 @@ var Config AuthConfig = AuthConfig{
Username: "admin",
Password: "admin",
Salt: "admin",
Static: "",
}

func init() {
Expand Down Expand Up @@ -103,13 +105,27 @@ type applyPortContent struct {
Subdomain string `json:"subdomain"`

Metas applyPortContentAuthMeta `json:"metas,omitempty"`

User applyPortContentUser `json:"user"`

PrivilegeKey string `json:"privilege_key"`

Timestamp int64 `json:"timestamp"`
}

type applyPortContentAuthMeta struct {
SignKey string `json:"auth_key"`
ValidTo string `json:"auth_valid_to"`
}

type applyPortContentUser struct {
User string `json:"user"`

RunId string `json:"run_id"`

Metas map[string]string `json:"metas"`
}

func ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Body == nil {
http.Error(w, "Please send a request body.", 400)
Expand Down Expand Up @@ -162,7 +178,7 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request) {
if ae.Disabled {
return errors.New("disabled")
}
if (time.Now().UnixNano() / 1e6) > ae.ValidTo {
if (time.Now().UnixNano() / int64(1e6)) > ae.ValidTo {
return errors.New(time.Now().Format("yyyy-MM-dd"))
}
return nil
Expand Down Expand Up @@ -195,7 +211,7 @@ func main() {
router.HandleFunc("/list-auth", ListAuthServeHTTP).Methods("POST")
router.HandleFunc("/get-auth/{id}", GetAuthServeHTTP).Methods("GET")
router.HandleFunc("/get-auth-config/{id}", GetAuthConfigServerHTTP).Methods("GET")
router.PathPrefix("/").Handler(MakeHttpGzipHandler(http.StripPrefix("/", http.FileServer(http.Dir("static/"))))).Methods("GET")
router.PathPrefix("/").Handler(MakeHttpGzipHandler(http.StripPrefix("/", http.FileServer(getStaticFS(Config.Static))))).Methods("GET")
addr := Config.Address
port := Config.Port

Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/dev-lluo/frps-auth

go 1.16

require (
github.com/gorilla/mux v1.8.0
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
github.com/satori/go.uuid v1.2.0
github.com/xujiajun/nutsdb v0.9.0
gopkg.in/ini.v1 v1.66.6
)

0 comments on commit fc48ee3

Please sign in to comment.