feat: ent ORM, admin UI, client auth, Fyne GUI, Windows/MSI packaging
This commit is contained in:
+41
-20
@@ -1,17 +1,3 @@
|
||||
// Copyright 2018 fatedier, fatedier@gmail.com
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -25,6 +11,7 @@ import (
|
||||
"github.com/fatedier/frp/pkg/config"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/fatedier/frp/pkg/config/v1/validation"
|
||||
"github.com/fatedier/frp/pkg/db"
|
||||
"github.com/fatedier/frp/pkg/policy/security"
|
||||
"github.com/fatedier/frp/pkg/util/log"
|
||||
"github.com/fatedier/frp/pkg/util/version"
|
||||
@@ -59,6 +46,12 @@ var rootCmd = &cobra.Command{
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := db.Init("sqlite", "admin.db"); err != nil {
|
||||
fmt.Printf("failed to initialize admin database: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
var (
|
||||
svrCfg *v1.ServerConfig
|
||||
isLegacyFormat bool
|
||||
@@ -71,15 +64,14 @@ var rootCmd = &cobra.Command{
|
||||
os.Exit(1)
|
||||
}
|
||||
if isLegacyFormat {
|
||||
fmt.Printf("WARNING: ini format is deprecated and the support will be removed in the future, " +
|
||||
"please use yaml/json/toml format instead!\n")
|
||||
fmt.Printf("WARNING: ini format is deprecated, please use yaml/json/toml instead!\n")
|
||||
}
|
||||
} else {
|
||||
if err := serverCfg.Complete(); err != nil {
|
||||
fmt.Printf("failed to complete server config: %v\n", err)
|
||||
svrCfg, err = loadConfigFromDB()
|
||||
if err != nil {
|
||||
fmt.Printf("failed to load server config: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
svrCfg = &serverCfg
|
||||
}
|
||||
|
||||
unsafeFeatures := security.NewUnsafeFeatures(allowUnsafe)
|
||||
@@ -108,13 +100,42 @@ func Execute() {
|
||||
}
|
||||
}
|
||||
|
||||
func loadConfigFromDB() (*v1.ServerConfig, error) {
|
||||
hasConfig, err := db.HasServerConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to check server config in db: %w", err)
|
||||
}
|
||||
|
||||
if hasConfig {
|
||||
cfg, err := db.LoadServerConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load server config from db: %w", err)
|
||||
}
|
||||
if err := cfg.Complete(); err != nil {
|
||||
return nil, fmt.Errorf("failed to complete server config: %w", err)
|
||||
}
|
||||
log.Infof("frps uses database configuration")
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
cfg := db.DefaultServerConfig()
|
||||
if err := cfg.Complete(); err != nil {
|
||||
return nil, fmt.Errorf("failed to complete server config: %w", err)
|
||||
}
|
||||
if err := db.SaveServerConfig(cfg); err != nil {
|
||||
log.Warnf("failed to save default config to db: %v", err)
|
||||
}
|
||||
log.Infof("frps started with default configuration (first run)")
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func runServer(cfg *v1.ServerConfig) (err error) {
|
||||
log.InitLogger(cfg.Log.To, cfg.Log.Level, int(cfg.Log.MaxDays), cfg.Log.DisablePrintColor)
|
||||
|
||||
if cfgFile != "" {
|
||||
log.Infof("frps uses config file: %s", cfgFile)
|
||||
} else {
|
||||
log.Infof("frps uses command line arguments for config")
|
||||
log.Infof("frps uses database configuration")
|
||||
}
|
||||
|
||||
svr, err := server.NewService(cfg)
|
||||
|
||||
Reference in New Issue
Block a user