mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-08 11:10:14 +08:00
更新程序为单文件
This commit is contained in:
@@ -39,7 +39,6 @@ type ServerConfig struct {
|
||||
DbFile string `json:"db_file"`
|
||||
CertFile string `json:"cert_file"`
|
||||
CertKey string `json:"cert_key"`
|
||||
UiPath string `json:"ui_path"`
|
||||
FilesPath string `json:"files_path"`
|
||||
LogPath string `json:"log_path"`
|
||||
LogLevel string `json:"log_level"`
|
||||
@@ -70,20 +69,20 @@ type ServerConfig struct {
|
||||
|
||||
func initServerCfg() {
|
||||
|
||||
sf, _ := filepath.Abs(cfgFile)
|
||||
base := filepath.Dir(sf)
|
||||
// TODO 取消绝对地址转换
|
||||
// sf, _ := filepath.Abs(cfgFile)
|
||||
// base := filepath.Dir(sf)
|
||||
|
||||
// 转换成绝对路径
|
||||
Cfg.DbFile = getAbsPath(base, Cfg.DbFile)
|
||||
Cfg.CertFile = getAbsPath(base, Cfg.CertFile)
|
||||
Cfg.CertKey = getAbsPath(base, Cfg.CertKey)
|
||||
Cfg.UiPath = getAbsPath(base, Cfg.UiPath)
|
||||
Cfg.FilesPath = getAbsPath(base, Cfg.FilesPath)
|
||||
Cfg.LogPath = getAbsPath(base, Cfg.LogPath)
|
||||
// Cfg.DbFile = getAbsPath(base, Cfg.DbFile)
|
||||
// Cfg.CertFile = getAbsPath(base, Cfg.CertFile)
|
||||
// Cfg.CertKey = getAbsPath(base, Cfg.CertKey)
|
||||
// Cfg.UiPath = getAbsPath(base, Cfg.UiPath)
|
||||
// Cfg.FilesPath = getAbsPath(base, Cfg.FilesPath)
|
||||
// Cfg.LogPath = getAbsPath(base, Cfg.LogPath)
|
||||
|
||||
if len(Cfg.JwtSecret) < 20 {
|
||||
fmt.Println("请设置 jwt_secret 长度20位以上")
|
||||
os.Exit(0)
|
||||
if Cfg.JwtSecret == defaultJwt {
|
||||
fmt.Fprintln(os.Stderr, "=== 使用默认的jwt_secret有安全风险,请设置新的jwt_secret ===")
|
||||
}
|
||||
|
||||
fmt.Printf("ServerCfg: %+v \n", Cfg)
|
||||
|
@@ -1,13 +1,10 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bjdgyc/anylink/pkg/utils"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -64,13 +61,12 @@ func init() {
|
||||
viper.SetConfigFile(cfgFile)
|
||||
viper.AutomaticEnv()
|
||||
|
||||
_, err := os.Stat(cfgFile)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
// 文件不存在,不做处理
|
||||
if cfgFile == "" {
|
||||
// 没有配置文件,不做处理
|
||||
return
|
||||
}
|
||||
|
||||
err = viper.ReadInConfig()
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
fmt.Println("Using config file:", err)
|
||||
}
|
||||
@@ -79,7 +75,7 @@ func init() {
|
||||
viper.SetEnvPrefix("link")
|
||||
|
||||
// 基础配置
|
||||
rootCmd.Flags().StringVarP(&cfgFile, "conf", "c", "./conf/server.toml", "config file")
|
||||
rootCmd.Flags().StringVarP(&cfgFile, "conf", "c", "", "config file")
|
||||
|
||||
for _, v := range configs {
|
||||
if v.Typ == cfgStr {
|
||||
@@ -118,7 +114,6 @@ func initToolCmd() *cobra.Command {
|
||||
fmt.Printf("%s v%s build on %s [%s, %s] commit_id(%s) \n",
|
||||
APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, CommitId)
|
||||
case secret:
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
s, _ := utils.RandSecret(40, 60)
|
||||
s = strings.Trim(s, "=")
|
||||
fmt.Printf("Secret:%s\n", s)
|
||||
|
@@ -4,6 +4,8 @@ const (
|
||||
cfgStr = iota
|
||||
cfgInt
|
||||
cfgBool
|
||||
|
||||
defaultJwt = "abcdef.0123456789.abcdef"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
@@ -24,7 +26,6 @@ var configs = []config{
|
||||
{Typ: cfgStr, Name: "db_file", Usage: "数据库地址", ValStr: "./data.db"},
|
||||
{Typ: cfgStr, Name: "cert_file", Usage: "证书文件", ValStr: "./vpn_cert.pem"},
|
||||
{Typ: cfgStr, Name: "cert_key", Usage: "证书密钥", ValStr: "./vpn_cert.key"},
|
||||
{Typ: cfgStr, Name: "ui_path", Usage: "ui文件路径", ValStr: "./ui"},
|
||||
{Typ: cfgStr, Name: "files_path", Usage: "外部下载文件路径", ValStr: "./files"},
|
||||
{Typ: cfgStr, Name: "log_path", Usage: "日志文件路径", ValStr: ""},
|
||||
{Typ: cfgStr, Name: "log_level", Usage: "日志等级", ValStr: "info"},
|
||||
@@ -32,7 +33,7 @@ var configs = []config{
|
||||
{Typ: cfgStr, Name: "issuer", Usage: "系统名称", ValStr: "XX公司VPN"},
|
||||
{Typ: cfgStr, Name: "admin_user", Usage: "管理用户名", ValStr: "admin"},
|
||||
{Typ: cfgStr, Name: "admin_pass", Usage: "管理用户密码", ValStr: "$2a$10$UQ7C.EoPifDeJh6d8.31TeSPQU7hM/NOM2nixmBucJpAuXDQNqNke"},
|
||||
{Typ: cfgStr, Name: "jwt_secret", Usage: "JWT密钥", ValStr: "iLmspvOiz*%ovfcs*wersdf#heR8pNU4XxBm&mW$aPCjSRMbYH#&"},
|
||||
{Typ: cfgStr, Name: "jwt_secret", Usage: "JWT密钥", ValStr: defaultJwt},
|
||||
{Typ: cfgStr, Name: "link_mode", Usage: "虚拟网络类型", ValStr: "tun"},
|
||||
{Typ: cfgStr, Name: "ipv4_cidr", Usage: "ip地址网段", ValStr: "192.168.10.0/24"},
|
||||
{Typ: cfgStr, Name: "ipv4_gateway", Usage: "ipv4_gateway", ValStr: "192.168.10.1"},
|
||||
|
Reference in New Issue
Block a user