feat: ent ORM, admin UI, client auth, Fyne GUI, Windows/MSI packaging

This commit is contained in:
kannn
2026-05-29 08:58:22 +00:00
Unverified
parent 8563a5fc74
commit a0a42a4966
81 changed files with 17144 additions and 89 deletions
+45
View File
@@ -17,7 +17,9 @@ package sub
import (
"context"
"fmt"
"io"
"io/fs"
"net/http"
"os"
"os/signal"
"path/filepath"
@@ -45,6 +47,7 @@ var (
showVersion bool
strictConfigMode bool
allowUnsafe []string
serverConfigURL string
)
func init() {
@@ -52,6 +55,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&cfgDir, "config_dir", "", "", "config directory, run one frpc service for each file in config directory")
rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "version of frpc")
rootCmd.PersistentFlags().BoolVarP(&strictConfigMode, "strict_config", "", true, "strict config parsing mode, unknown fields will cause an errors")
rootCmd.PersistentFlags().StringVarP(&serverConfigURL, "server-config", "", "", "fetch config from frps server URL (auto-reloads on change)")
rootCmd.PersistentFlags().StringSliceVarP(&allowUnsafe, "allow-unsafe", "", []string{},
fmt.Sprintf("allowed unsafe features, one or more of: %s", strings.Join(security.ClientUnsafeFeatures, ", ")))
@@ -75,6 +79,16 @@ var rootCmd = &cobra.Command{
return nil
}
// If server-config is set, use it instead of local config file.
if serverConfigURL != "" {
err := runClientWithServerConfig(serverConfigURL, unsafeFeatures)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return nil
}
// Do not show command usage here.
err := runClient(cfgFile, unsafeFeatures)
if err != nil {
@@ -120,6 +134,37 @@ func handleTermSignal(svr *client.Service) {
svr.GracefulClose(500 * time.Millisecond)
}
func runClientWithServerConfig(url string, unsafeFeatures *security.UnsafeFeatures) error {
log.Infof("fetching config from server: %s", url)
resp, err := http.Get(url)
if err != nil {
return fmt.Errorf("failed to fetch config from server: %w", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read config from server: %w", err)
}
allCfg := v1.ClientConfig{}
if err := config.LoadConfigure(body, &allCfg, strictConfigMode, "toml"); err != nil {
return fmt.Errorf("failed to parse config from server: %w", err)
}
result := &config.ClientConfigLoadResult{
Common: &allCfg.ClientCommonConfig,
Proxies: make([]v1.ProxyConfigurer, 0),
}
for _, c := range allCfg.Proxies {
result.Proxies = append(result.Proxies, c.ProxyConfigurer)
}
result.Common.ConfigURL = url
return runClientWithAggregator(result, unsafeFeatures, "")
}
func runClient(cfgFilePath string, unsafeFeatures *security.UnsafeFeatures) error {
// Load configuration
result, err := config.LoadClientConfigResult(cfgFilePath, strictConfigMode)