mirror of
https://github.com/yhl452493373/frps-panel.git
synced 2026-04-04 06:16:59 +08:00
start to config with toml (not finish)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"frps-panel/pkg/server"
|
||||
"frps-panel/pkg/server/controller"
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/ini.v1"
|
||||
"io/fs"
|
||||
@@ -69,6 +70,25 @@ func Execute() {
|
||||
}
|
||||
|
||||
func ParseConfigFile(file string) (controller.HandleController, server.TLS, error) {
|
||||
|
||||
var config Config
|
||||
readFile, _ := os.ReadFile("/Volumes/Working/Works/Git Sources/frps-panel/config/frps-panel.toml")
|
||||
_ = toml.Unmarshal(readFile, &config)
|
||||
log.Printf("%v", config)
|
||||
f, err := os.Create("/Volumes/Working/Works/Git Sources/frps-panel/config/frps-panel-new.toml")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := toml.NewEncoder(f).Encode(config); err != nil {
|
||||
// failed to encode
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
// failed to close the file
|
||||
log.Fatal(err)
|
||||
|
||||
}
|
||||
|
||||
common := controller.CommonInfo{}
|
||||
users := make(map[string]controller.TokenInfo)
|
||||
ports := make(map[string][]string)
|
||||
@@ -253,3 +273,7 @@ func ParseConfigFile(file string) (controller.HandleController, server.TLS, erro
|
||||
Version: version,
|
||||
}, tls, nil
|
||||
}
|
||||
|
||||
func decode() {
|
||||
|
||||
}
|
||||
|
||||
31
cmd/frps-panel/config.go
Normal file
31
cmd/frps-panel/config.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
type Config struct {
|
||||
Common CommonInfo
|
||||
Tokens []TokenInfo
|
||||
}
|
||||
|
||||
type CommonInfo struct {
|
||||
PluginAddr string `toml:"plugin_addr" commented:"true"`
|
||||
PluginPort int `toml:"plugin_port"`
|
||||
AdminUser string `toml:"admin_user"`
|
||||
AdminPwd string `toml:"admin_pwd"`
|
||||
AdminKeepTime int `toml:"admin_keep_time"`
|
||||
TlsMode bool `toml:"tls_mode"`
|
||||
TlsCertFile string `toml:"tls_cert_file"`
|
||||
TlsKeyFile string `toml:"tls_key_file"`
|
||||
DashboardAddr string `toml:"dashboard_addr"`
|
||||
DashboardPort int `toml:"dashboard_port"`
|
||||
DashboardUser string `toml:"dashboard_user"`
|
||||
DashboardPwd string `toml:"dashboard_pwd"`
|
||||
}
|
||||
|
||||
type TokenInfo struct {
|
||||
User string `toml:"user" json:"user" form:"user"`
|
||||
Token string `toml:"token" json:"token" form:"token"`
|
||||
Comment string `toml:"comment" json:"comment" form:"comment"`
|
||||
Ports []any `toml:"ports" json:"ports" from:"ports"`
|
||||
Domains []string `toml:"domains" json:"domains" from:"domains"`
|
||||
Subdomains []string `toml:"subdomains" json:"subdomains" from:"subdomains"`
|
||||
Status bool `toml:"status" json:"status" form:"status"`
|
||||
}
|
||||
39
config/frps-panel.toml
Normal file
39
config/frps-panel.toml
Normal file
@@ -0,0 +1,39 @@
|
||||
# basic options
|
||||
[common]
|
||||
# frps panel config info
|
||||
plugin_addr = "127.0.0.1" #aadr
|
||||
plugin_port = 7200
|
||||
admin_user = "admin"
|
||||
admin_pwd = "admin"
|
||||
# specified login state keep time
|
||||
admin_keep_time = 0
|
||||
|
||||
# enable tls
|
||||
tls_mode = false
|
||||
# tls_cert_file = cert.crt
|
||||
# tls_key_file = cert.key
|
||||
|
||||
# frp dashboard info
|
||||
dashboard_addr = "127.0.0.1"
|
||||
dashboard_port = 7500
|
||||
dashboard_user = "admin"
|
||||
dashboard_pwd = "admin"
|
||||
|
||||
# token info
|
||||
[[tokens]]
|
||||
user = "user1"
|
||||
token = "token1"
|
||||
comment = "张三"
|
||||
ports = [1, 2, 3, "10-100"]
|
||||
domains = ["aaa.com", "bbb.com"]
|
||||
subdomains = ["a.com", "b.com"]
|
||||
status = true
|
||||
|
||||
[[tokens]]
|
||||
user = "user2"
|
||||
token = "token2"
|
||||
comment = "李四"
|
||||
ports = [11, 22, 33, "110-200"]
|
||||
domains = ["ccc.com", "ddd.com"]
|
||||
subdomains = ["c.com", "d.com"]
|
||||
status = true
|
||||
6
go.mod
6
go.mod
@@ -5,8 +5,11 @@ go 1.21
|
||||
require (
|
||||
github.com/fatedier/frp v0.34.1
|
||||
github.com/gin-contrib/i18n v1.0.0
|
||||
github.com/gin-contrib/sessions v0.0.5
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/pelletier/go-toml/v2 v2.0.9
|
||||
github.com/spf13/cobra v0.0.3
|
||||
golang.org/x/text v0.11.0
|
||||
gopkg.in/ini.v1 v1.67.0
|
||||
)
|
||||
|
||||
@@ -17,7 +20,6 @@ require (
|
||||
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb // indirect
|
||||
github.com/fatedier/golib v0.1.1-0.20200901083111-1f870741e185 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
github.com/gin-contrib/sessions v0.0.5 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
@@ -34,7 +36,6 @@ require (
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/nicksnyder/go-i18n/v2 v2.2.1 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
@@ -42,7 +43,6 @@ require (
|
||||
golang.org/x/crypto v0.11.0 // indirect
|
||||
golang.org/x/net v0.12.0 // indirect
|
||||
golang.org/x/sys v0.10.0 // indirect
|
||||
golang.org/x/text v0.11.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user