Compare commits
36 Commits
1.0-Release
...
2.0-LTS
| Author | SHA1 | Date | |
|---|---|---|---|
| d2b3dd8803 | |||
| 1afb56edfc | |||
| 73f0011b54 | |||
| 1d0e98e1fd | |||
| fb8fecc59a | |||
| 0c21dd5d07 | |||
| 8b5de14cce | |||
| 4bd3554140 | |||
| 6934835394 | |||
| 2c044890d8 | |||
| f9d817031e | |||
| a97b3a7669 | |||
| 059e4638da | |||
| b80238029a | |||
| e64a8687d2 | |||
| 542f265a35 | |||
| 88046018a8 | |||
| ebba194fbc | |||
| 73a7bbea09 | |||
| bfc6f9b6e2 | |||
| 7851bea1c3 | |||
| 469a3687ca | |||
| 18e8098aa4 | |||
| 2a9eee4582 | |||
| 6dbebc27f6 | |||
| f49bc07f42 | |||
| ce07f4f0f0 | |||
| 1669abf9e8 | |||
| 5023064a36 | |||
| 078842f620 | |||
| ebaecfe66c | |||
| a174c342f5 | |||
| 3901698e31 | |||
| d4aef6dbb1 | |||
| 7cce698281 | |||
| 24f5766568 |
@@ -4,9 +4,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -60,6 +63,7 @@ func SetupRouter() *gin.Engine {
|
|||||||
auth.POST("/frpc/start", startFrpcHandler)
|
auth.POST("/frpc/start", startFrpcHandler)
|
||||||
auth.POST("/frpc/stop", stopFrpcHandler)
|
auth.POST("/frpc/stop", stopFrpcHandler)
|
||||||
auth.GET("/frpc/status", getFrpcStatusHandler)
|
auth.GET("/frpc/status", getFrpcStatusHandler)
|
||||||
|
auth.GET("/frpc/log", getFrpcLogHandler)
|
||||||
|
|
||||||
auth.POST("/import/toml", importTomlHandler)
|
auth.POST("/import/toml", importTomlHandler)
|
||||||
auth.GET("/export/toml", ExportTomlHandler)
|
auth.GET("/export/toml", ExportTomlHandler)
|
||||||
@@ -491,6 +495,114 @@ func ExportTomlHandler(c *gin.Context) {
|
|||||||
c.String(http.StatusOK, buf.String())
|
c.String(http.StatusOK, buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========== 日志读取 ==========
|
||||||
|
|
||||||
|
func getFrpcLogHandler(c *gin.Context) {
|
||||||
|
// 读取 ./frpc.log,最多返回 200 行(最新的 200 行)
|
||||||
|
lines, err := readTailLog("./frpc.log", 200)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"data": gin.H{
|
||||||
|
"lines": []string{},
|
||||||
|
"total": 0,
|
||||||
|
"error": err.Error(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 0,
|
||||||
|
"data": gin.H{
|
||||||
|
"lines": lines,
|
||||||
|
"total": len(lines),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// readTailLog 读取文件末尾 n 行(倒序读取,返回正序)
|
||||||
|
func readTailLog(filePath string, n int) ([]string, error) {
|
||||||
|
file, err := os.Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// 获取文件大小
|
||||||
|
info, err := file.Stat()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fileSize := info.Size()
|
||||||
|
if fileSize == 0 {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从末尾开始读
|
||||||
|
const chunkSize = 4096
|
||||||
|
var lines []string
|
||||||
|
var leftover []byte
|
||||||
|
offset := fileSize
|
||||||
|
|
||||||
|
for len(lines) < n && offset > 0 {
|
||||||
|
// 计算读取起点
|
||||||
|
readSize := chunkSize
|
||||||
|
if offset < int64(chunkSize) {
|
||||||
|
readSize = int(offset)
|
||||||
|
}
|
||||||
|
offset -= int64(readSize)
|
||||||
|
|
||||||
|
// 读取这一块
|
||||||
|
buf := make([]byte, readSize)
|
||||||
|
_, err := file.ReadAt(buf, offset)
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将当前块与之前剩下的拼接
|
||||||
|
data := append(buf, leftover...)
|
||||||
|
leftover = nil
|
||||||
|
|
||||||
|
// 按行分割
|
||||||
|
start := 0
|
||||||
|
for i := len(data) - 1; i >= 0; i-- {
|
||||||
|
if data[i] == '\n' {
|
||||||
|
if i+1 < len(data) {
|
||||||
|
line := string(data[i+1:])
|
||||||
|
if line != "" {
|
||||||
|
lines = append([]string{line}, lines...)
|
||||||
|
if len(lines) >= n {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
start = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果还没凑够,把未处理的部分留到下一轮
|
||||||
|
if len(lines) < n && start > 0 {
|
||||||
|
leftover = data[:start]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理最后剩余部分(文件开头)
|
||||||
|
if len(lines) < n && len(leftover) > 0 {
|
||||||
|
// 从 leftover 中提取行
|
||||||
|
parts := strings.Split(string(leftover), "\n")
|
||||||
|
for i := len(parts) - 1; i >= 0; i-- {
|
||||||
|
if parts[i] != "" {
|
||||||
|
lines = append([]string{parts[i]}, lines...)
|
||||||
|
if len(lines) >= n {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines, nil
|
||||||
|
}
|
||||||
|
|
||||||
func generateAndReload() error {
|
func generateAndReload() error {
|
||||||
if err := GenerateFrpcConfig(); err != nil {
|
if err := GenerateFrpcConfig(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -4,14 +4,31 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DB *sql.DB
|
var DB *sql.DB
|
||||||
|
|
||||||
// ===== 全局配置表(A表)=====
|
// ============================================================
|
||||||
|
// 数据库版本常量
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
const (
|
||||||
|
SchemaVersion = "2.0.0" // 当前数据库 Schema 版本,与项目版本同步
|
||||||
|
)
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 数据模型
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
// GlobalConfig 全局配置表
|
||||||
type GlobalConfig struct {
|
type GlobalConfig struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
ServerAddr string `json:"serverAddr"`
|
ServerAddr string `json:"serverAddr"`
|
||||||
@@ -24,9 +41,10 @@ type GlobalConfig struct {
|
|||||||
HeartbeatInterval int `json:"heartbeatInterval"`
|
HeartbeatInterval int `json:"heartbeatInterval"`
|
||||||
HeartbeatTimeout int `json:"heartbeatTimeout"`
|
HeartbeatTimeout int `json:"heartbeatTimeout"`
|
||||||
PoolCount int `json:"poolCount"`
|
PoolCount int `json:"poolCount"`
|
||||||
|
WireProtocolV2 bool `json:"wireProtocolV2"` // v2.0 正式启用
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 隧道表(B表)=====
|
// Proxy 隧道表
|
||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -37,7 +55,7 @@ type Proxy struct {
|
|||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 用户表(C表)=====
|
// User 用户表
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
@@ -45,7 +63,10 @@ type User struct {
|
|||||||
CreatedAt string `json:"createdAt"`
|
CreatedAt string `json:"createdAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 初始化数据库 =====
|
// ============================================================
|
||||||
|
// 数据库初始化
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
func InitDB() error {
|
func InitDB() error {
|
||||||
var err error
|
var err error
|
||||||
DB, err = sql.Open("sqlite", "./frpc-console.db")
|
DB, err = sql.Open("sqlite", "./frpc-console.db")
|
||||||
@@ -53,8 +74,32 @@ func InitDB() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户表(C表)
|
// ---- 创建所有表 ----
|
||||||
_, err = DB.Exec(`
|
if err := createTables(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 执行版本迁移 ----
|
||||||
|
if err := runMigrations(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 确保 JWT 密钥存在 ----
|
||||||
|
if err := ensureJwtSecret(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("✅ 数据库初始化完成 (Schema v" + SchemaVersion + ")")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 建表
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
func createTables() error {
|
||||||
|
// 用户表
|
||||||
|
_, err := DB.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
username TEXT UNIQUE NOT NULL,
|
username TEXT UNIQUE NOT NULL,
|
||||||
@@ -67,13 +112,13 @@ func InitDB() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全局配置表(A表)
|
// 全局配置表
|
||||||
_, err = DB.Exec(`
|
_, err = DB.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS global_config (
|
CREATE TABLE IF NOT EXISTS global_config (
|
||||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||||
server_addr TEXT NOT NULL DEFAULT 'frp.whitetop.xyz',
|
server_addr TEXT NOT NULL DEFAULT 'frp.example.com',
|
||||||
server_port INTEGER NOT NULL DEFAULT 9358,
|
server_port INTEGER NOT NULL DEFAULT 7000,
|
||||||
token TEXT NOT NULL DEFAULT 'Lxh10020328',
|
token TEXT NOT NULL DEFAULT 'CHANGE_ME',
|
||||||
log_level TEXT NOT NULL DEFAULT 'info',
|
log_level TEXT NOT NULL DEFAULT 'info',
|
||||||
log_max_days INTEGER NOT NULL DEFAULT 3,
|
log_max_days INTEGER NOT NULL DEFAULT 3,
|
||||||
tcp_mux INTEGER NOT NULL DEFAULT 1,
|
tcp_mux INTEGER NOT NULL DEFAULT 1,
|
||||||
@@ -81,6 +126,7 @@ func InitDB() error {
|
|||||||
heartbeat_interval INTEGER NOT NULL DEFAULT 15,
|
heartbeat_interval INTEGER NOT NULL DEFAULT 15,
|
||||||
heartbeat_timeout INTEGER NOT NULL DEFAULT 70,
|
heartbeat_timeout INTEGER NOT NULL DEFAULT 70,
|
||||||
pool_count INTEGER NOT NULL DEFAULT 8,
|
pool_count INTEGER NOT NULL DEFAULT 8,
|
||||||
|
wire_protocol_v2 INTEGER NOT NULL DEFAULT 0,
|
||||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
)
|
)
|
||||||
`)
|
`)
|
||||||
@@ -88,22 +134,7 @@ func InitDB() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var count int
|
// 隧道表
|
||||||
DB.QueryRow("SELECT COUNT(*) FROM global_config").Scan(&count)
|
|
||||||
if count == 0 {
|
|
||||||
_, err = DB.Exec(`
|
|
||||||
INSERT INTO global_config (
|
|
||||||
id, server_addr, server_port, token, log_level, log_max_days,
|
|
||||||
tcp_mux, tcp_mux_keepalive, heartbeat_interval, heartbeat_timeout, pool_count
|
|
||||||
) VALUES (1, 'frp.whitetop.xyz', 9358, 'Lxh10020328', 'info', 3, 1, 30, 15, 70, 8)
|
|
||||||
`)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
log.Println("✅ 全局配置初始化完成")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 隧道表(B表)
|
|
||||||
_, err = DB.Exec(`
|
_, err = DB.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS proxies (
|
CREATE TABLE IF NOT EXISTS proxies (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -121,7 +152,7 @@ func InitDB() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用配置表(JWT密钥等)
|
// 应用配置表(存储 JWT 密钥、Schema 版本等)
|
||||||
_, err = DB.Exec(`
|
_, err = DB.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS app_config (
|
CREATE TABLE IF NOT EXISTS app_config (
|
||||||
key TEXT PRIMARY KEY,
|
key TEXT PRIMARY KEY,
|
||||||
@@ -133,15 +164,252 @@ func InitDB() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ensureJwtSecret(); err != nil {
|
// 初始化默认配置(仅当表为空时)
|
||||||
|
var count int
|
||||||
|
DB.QueryRow("SELECT COUNT(*) FROM global_config").Scan(&count)
|
||||||
|
if count == 0 {
|
||||||
|
_, err = DB.Exec(`
|
||||||
|
INSERT INTO global_config (
|
||||||
|
id, server_addr, server_port, token, log_level, log_max_days,
|
||||||
|
tcp_mux, tcp_mux_keepalive, heartbeat_interval, heartbeat_timeout, pool_count,
|
||||||
|
wire_protocol_v2
|
||||||
|
) VALUES (1, 'frp.example.com', 7000, 'CHANGE_ME', 'info', 3, 1, 30, 15, 70, 8, 0)
|
||||||
|
`)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Println("✅ 全局配置初始化完成")
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("✅ 数据库初始化完成")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== JWT 密钥管理 =====
|
// ============================================================
|
||||||
|
// 迁移引擎
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
// getSchemaVersion 读取当前数据库的 Schema 版本
|
||||||
|
func getSchemaVersion() string {
|
||||||
|
var version string
|
||||||
|
err := DB.QueryRow("SELECT value FROM app_config WHERE key = 'schema_version'").Scan(&version)
|
||||||
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
// 没有版本记录 → 首次启动或 v1.x 升级
|
||||||
|
// 检查是否已有数据(通过 users 表判断)
|
||||||
|
var count int
|
||||||
|
DB.QueryRow("SELECT COUNT(*) FROM users").Scan(&count)
|
||||||
|
if count > 0 {
|
||||||
|
// 有用户数据 → 这是 v1.x 升级,标记为 1.5
|
||||||
|
return "1.5.0"
|
||||||
|
}
|
||||||
|
// 全新安装 → 直接标记为当前版本
|
||||||
|
return SchemaVersion
|
||||||
|
}
|
||||||
|
log.Printf("⚠️ 读取 Schema 版本失败: %v", err)
|
||||||
|
return "1.5.0" // 保守降级
|
||||||
|
}
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
// setSchemaVersion 更新 Schema 版本
|
||||||
|
func setSchemaVersion(version string) error {
|
||||||
|
_, err := DB.Exec(`
|
||||||
|
INSERT INTO app_config (key, value) VALUES ('schema_version', ?)
|
||||||
|
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP
|
||||||
|
`, version)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// backupDatabase 备份数据库文件
|
||||||
|
func backupDatabase() (string, error) {
|
||||||
|
src := "./frpc-console.db"
|
||||||
|
if _, err := os.Stat(src); os.IsNotExist(err) {
|
||||||
|
return "", nil // 数据库不存在,无需备份
|
||||||
|
}
|
||||||
|
|
||||||
|
timestamp := time.Now().Format("20060102_150405")
|
||||||
|
dst := fmt.Sprintf("./frpc-console.db.pre-v%s.%s", SchemaVersion, timestamp)
|
||||||
|
|
||||||
|
srcFile, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("打开源数据库失败: %w", err)
|
||||||
|
}
|
||||||
|
defer srcFile.Close()
|
||||||
|
|
||||||
|
dstFile, err := os.Create(dst)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("创建备份文件失败: %w", err)
|
||||||
|
}
|
||||||
|
defer dstFile.Close()
|
||||||
|
|
||||||
|
if _, err := io.Copy(dstFile, srcFile); err != nil {
|
||||||
|
return "", fmt.Errorf("复制数据库失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("✅ 数据库备份完成: %s", dst)
|
||||||
|
return dst, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// runMigrations 执行版本迁移
|
||||||
|
func runMigrations() error {
|
||||||
|
currentVersion := getSchemaVersion()
|
||||||
|
log.Printf("📌 当前数据库 Schema: %s, 目标版本: %s", currentVersion, SchemaVersion)
|
||||||
|
|
||||||
|
if currentVersion == SchemaVersion {
|
||||||
|
log.Println("✅ Schema 已是最新,无需迁移")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("🔄 检测到版本变更 (%s → %s),开始迁移...", currentVersion, SchemaVersion)
|
||||||
|
|
||||||
|
// ---- 1. 备份数据库 ----
|
||||||
|
backupPath, err := backupDatabase()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("备份数据库失败: %w", err)
|
||||||
|
}
|
||||||
|
if backupPath != "" {
|
||||||
|
log.Printf("📦 备份文件: %s", backupPath)
|
||||||
|
} else {
|
||||||
|
log.Println("📦 数据库为空,跳过备份")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 2. 执行迁移 ----
|
||||||
|
// 按照版本号逐个升级
|
||||||
|
migrations := []struct {
|
||||||
|
from string
|
||||||
|
upgrade func() error
|
||||||
|
}{
|
||||||
|
{"1.5.0", migrateFrom1_5_0},
|
||||||
|
{"2.0.0", migrateFrom2_0_0}, // 预留,实际无操作
|
||||||
|
}
|
||||||
|
|
||||||
|
applied := 0
|
||||||
|
for _, m := range migrations {
|
||||||
|
if currentVersion == m.from {
|
||||||
|
log.Printf(" 执行迁移: %s → %s", m.from, SchemaVersion)
|
||||||
|
if err := m.upgrade(); err != nil {
|
||||||
|
// 迁移失败,尝试恢复备份
|
||||||
|
if backupPath != "" {
|
||||||
|
log.Printf("❌ 迁移失败,尝试恢复备份: %s", backupPath)
|
||||||
|
if restoreErr := restoreDatabase(backupPath); restoreErr != nil {
|
||||||
|
log.Printf("⚠️ 恢复备份失败: %v", restoreErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fmt.Errorf("迁移失败: %w", err)
|
||||||
|
}
|
||||||
|
applied++
|
||||||
|
currentVersion = SchemaVersion
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 3. 更新 Schema 版本 ----
|
||||||
|
if err := setSchemaVersion(SchemaVersion); err != nil {
|
||||||
|
return fmt.Errorf("更新 Schema 版本失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("✅ 迁移完成,应用了 %d 个迁移", applied)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// restoreDatabase 从备份恢复数据库
|
||||||
|
func restoreDatabase(backupPath string) error {
|
||||||
|
srcFile, err := os.Open(backupPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer srcFile.Close()
|
||||||
|
|
||||||
|
dstFile, err := os.Create("./frpc-console.db")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer dstFile.Close()
|
||||||
|
|
||||||
|
if _, err := io.Copy(dstFile, srcFile); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("✅ 数据库已从备份恢复: %s", backupPath)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 迁移函数(各版本)
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
// migrateFrom1_5_0: v1.5 → v2.0
|
||||||
|
// v1.5 已经有 wire_protocol_v2 字段(灰标占位),v2.0 无需新增字段
|
||||||
|
// 但需要确保字段存在(兼容从 v1.0 直接升级的场景)
|
||||||
|
func migrateFrom1_5_0() error {
|
||||||
|
log.Println(" 迁移: v1.5.0 → v2.0.0")
|
||||||
|
|
||||||
|
// 检查并补全 wire_protocol_v2 字段(兼容从 v1.0 直接升级的场景)
|
||||||
|
cols, err := getCurrentColumns("global_config")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("获取列信息失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !contains(cols, "wire_protocol_v2") {
|
||||||
|
log.Println(" 添加字段: wire_protocol_v2")
|
||||||
|
_, err := DB.Exec("ALTER TABLE global_config ADD COLUMN wire_protocol_v2 INTEGER NOT NULL DEFAULT 0")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("添加 wire_protocol_v2 字段失败: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(" ✅ v1.5.0 → v2.0.0 迁移完成")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrateFrom2_0_0: 预留,v2.0 → 未来版本
|
||||||
|
func migrateFrom2_0_0() error {
|
||||||
|
log.Println(" v2.0.0 已是当前版本,无需迁移")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 辅助函数
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
func getCurrentColumns(tableName string) ([]string, error) {
|
||||||
|
rows, err := DB.Query("PRAGMA table_info(" + tableName + ")")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
var cols []string
|
||||||
|
for rows.Next() {
|
||||||
|
var (
|
||||||
|
cid int
|
||||||
|
name string
|
||||||
|
typ string
|
||||||
|
notNull int
|
||||||
|
dfltVal sql.NullString
|
||||||
|
pk int
|
||||||
|
)
|
||||||
|
if err := rows.Scan(&cid, &name, &typ, ¬Null, &dfltVal, &pk); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cols = append(cols, name)
|
||||||
|
}
|
||||||
|
return cols, rows.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
func contains(slice []string, item string) bool {
|
||||||
|
for _, s := range slice {
|
||||||
|
if strings.EqualFold(s, item) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// JWT 密钥管理
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
func ensureJwtSecret() error {
|
func ensureJwtSecret() error {
|
||||||
var value string
|
var value string
|
||||||
err := DB.QueryRow("SELECT value FROM app_config WHERE key = 'jwt_secret'").Scan(&value)
|
err := DB.QueryRow("SELECT value FROM app_config WHERE key = 'jwt_secret'").Scan(&value)
|
||||||
@@ -161,7 +429,7 @@ func ensureJwtSecret() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Printf("✅ JWT 密钥已生成并保存到数据库")
|
log.Printf("✅ JWT 密钥已生成")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,17 +442,22 @@ func GetJwtSecret() (string, error) {
|
|||||||
return secret, nil
|
return secret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 全局配置 CRUD =====
|
// ============================================================
|
||||||
|
// 全局配置 CRUD
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
func GetGlobalConfig() (*GlobalConfig, error) {
|
func GetGlobalConfig() (*GlobalConfig, error) {
|
||||||
var cfg GlobalConfig
|
var cfg GlobalConfig
|
||||||
err := DB.QueryRow(`
|
err := DB.QueryRow(`
|
||||||
SELECT id, server_addr, server_port, token, log_level, log_max_days,
|
SELECT id, server_addr, server_port, token, log_level, log_max_days,
|
||||||
tcp_mux, tcp_mux_keepalive, heartbeat_interval, heartbeat_timeout, pool_count
|
tcp_mux, tcp_mux_keepalive, heartbeat_interval, heartbeat_timeout, pool_count,
|
||||||
|
wire_protocol_v2
|
||||||
FROM global_config WHERE id = 1
|
FROM global_config WHERE id = 1
|
||||||
`).Scan(
|
`).Scan(
|
||||||
&cfg.ID, &cfg.ServerAddr, &cfg.ServerPort, &cfg.Token,
|
&cfg.ID, &cfg.ServerAddr, &cfg.ServerPort, &cfg.Token,
|
||||||
&cfg.LogLevel, &cfg.LogMaxDays, &cfg.TcpMux, &cfg.TcpMuxKeepalive,
|
&cfg.LogLevel, &cfg.LogMaxDays, &cfg.TcpMux, &cfg.TcpMuxKeepalive,
|
||||||
&cfg.HeartbeatInterval, &cfg.HeartbeatTimeout, &cfg.PoolCount,
|
&cfg.HeartbeatInterval, &cfg.HeartbeatTimeout, &cfg.PoolCount,
|
||||||
|
&cfg.WireProtocolV2,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -199,14 +472,19 @@ func UpdateGlobalConfig(cfg *GlobalConfig) error {
|
|||||||
server_addr = ?, server_port = ?, token = ?, log_level = ?, log_max_days = ?,
|
server_addr = ?, server_port = ?, token = ?, log_level = ?, log_max_days = ?,
|
||||||
tcp_mux = 1,
|
tcp_mux = 1,
|
||||||
tcp_mux_keepalive = ?, heartbeat_interval = ?, heartbeat_timeout = ?, pool_count = ?,
|
tcp_mux_keepalive = ?, heartbeat_interval = ?, heartbeat_timeout = ?, pool_count = ?,
|
||||||
|
wire_protocol_v2 = ?,
|
||||||
updated_at = CURRENT_TIMESTAMP
|
updated_at = CURRENT_TIMESTAMP
|
||||||
WHERE id = 1
|
WHERE id = 1
|
||||||
`, cfg.ServerAddr, cfg.ServerPort, cfg.Token, cfg.LogLevel, cfg.LogMaxDays,
|
`, cfg.ServerAddr, cfg.ServerPort, cfg.Token, cfg.LogLevel, cfg.LogMaxDays,
|
||||||
cfg.TcpMuxKeepalive, cfg.HeartbeatInterval, cfg.HeartbeatTimeout, cfg.PoolCount)
|
cfg.TcpMuxKeepalive, cfg.HeartbeatInterval, cfg.HeartbeatTimeout, cfg.PoolCount,
|
||||||
|
cfg.WireProtocolV2)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 隧道 CRUD =====
|
// ============================================================
|
||||||
|
// 隧道 CRUD
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
func GetProxies() ([]Proxy, error) {
|
func GetProxies() ([]Proxy, error) {
|
||||||
rows, err := DB.Query(`
|
rows, err := DB.Query(`
|
||||||
SELECT id, name, type, local_ip, local_port, remote_port, enabled
|
SELECT id, name, type, local_ip, local_port, remote_port, enabled
|
||||||
@@ -272,7 +550,10 @@ func DeleteProxy(id int) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 用户 CRUD =====
|
// ============================================================
|
||||||
|
// 用户 CRUD
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
func GetUserByUsername(username string) (*User, error) {
|
func GetUserByUsername(username string) (*User, error) {
|
||||||
var u User
|
var u User
|
||||||
err := DB.QueryRow(`
|
err := DB.QueryRow(`
|
||||||
|
|||||||
@@ -4,6 +4,12 @@
|
|||||||
# frpc-console 一键部署脚本
|
# frpc-console 一键部署脚本
|
||||||
# 支持:Linux x86_64 / ARM64 / ARMv7
|
# 支持:Linux x86_64 / ARM64 / ARMv7
|
||||||
# 自动安装:git / curl / wget / Go / Docker
|
# 自动安装:git / curl / wget / Go / Docker
|
||||||
|
#
|
||||||
|
# 用法:
|
||||||
|
# ./deploy.sh # 完整交互流程
|
||||||
|
# ./deploy.sh --yes # 跳过确认,直接执行
|
||||||
|
# ./deploy.sh --check # 只检测环境,不执行
|
||||||
|
# ./deploy.sh --dry-run # 显示将执行的操作,不实际执行
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
@@ -14,48 +20,112 @@ GREEN='\033[0;32m'
|
|||||||
YELLOW='\033[1;33m'
|
YELLOW='\033[1;33m'
|
||||||
BLUE='\033[0;34m'
|
BLUE='\033[0;34m'
|
||||||
CYAN='\033[0;36m'
|
CYAN='\033[0;36m'
|
||||||
|
MAGENTA='\033[0;35m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
# ---------- 配置 ----------
|
# ---------- 配置 ----------
|
||||||
REPO_URL="https://git.whitetop.xyz/lxh2875931338/frpc-console.git"
|
REPO_URL="https://git.whitetop.xyz/lxh2875931338/frpc-console.git"
|
||||||
BRANCH="main"
|
BRANCH="main"
|
||||||
WORK_DIR="/tmp/frpc-console-build"
|
WORK_DIR="/tmp/frpc-console-build"
|
||||||
DEPLOY_DIR="/opt/frpc-console"
|
|
||||||
DATA_DIR="${DEPLOY_DIR}/data"
|
|
||||||
DEFAULT_PORT=9300
|
DEFAULT_PORT=9300
|
||||||
|
DEFAULT_DEPLOY_DIR="/opt/frpc-console"
|
||||||
IMAGE_NAME="frpc-console"
|
IMAGE_NAME="frpc-console"
|
||||||
GO_VERSION="1.25.0"
|
GO_VERSION="1.25.0"
|
||||||
|
|
||||||
|
# ---------- 状态变量 ----------
|
||||||
|
OS=""
|
||||||
|
OS_VERSION=""
|
||||||
|
ARCH=""
|
||||||
|
GO_ARCH=""
|
||||||
|
HAS_GIT=false
|
||||||
|
HAS_CURL=false
|
||||||
|
HAS_WGET=false
|
||||||
|
HAS_GO=false
|
||||||
|
HAS_DOCKER=false
|
||||||
|
NEED_INSTALL_GIT=false
|
||||||
|
NEED_INSTALL_CURL=false
|
||||||
|
NEED_INSTALL_WGET=false
|
||||||
|
NEED_INSTALL_GO=false
|
||||||
|
PORT=${DEFAULT_PORT}
|
||||||
|
DEPLOY_DIR=${DEFAULT_DEPLOY_DIR}
|
||||||
|
DATA_DIR="${DEPLOY_DIR}/data"
|
||||||
|
CONTAINER_EXISTS=false
|
||||||
|
CONTAINER_RUNNING=false
|
||||||
|
SKIP_CONFIRM=false
|
||||||
|
CHECK_ONLY=false
|
||||||
|
DRY_RUN=false
|
||||||
|
|
||||||
# ---------- 打印函数 ----------
|
# ---------- 打印函数 ----------
|
||||||
print_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
print_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||||||
print_success() { echo -e "${GREEN}[✓]${NC} $1"; }
|
print_success() { echo -e "${GREEN}[✓]${NC} $1"; }
|
||||||
print_warn() { echo -e "${YELLOW}[⚠]${NC} $1"; }
|
print_warn() { echo -e "${YELLOW}[⚠]${NC} $1"; }
|
||||||
print_error() { echo -e "${RED}[✗]${NC} $1"; }
|
print_error() { echo -e "${RED}[✗]${NC} $1"; }
|
||||||
print_step() { echo -e "\n${CYAN}▶${NC} $1"; }
|
print_step() { echo -e "\n${CYAN}▶${NC} $1"; }
|
||||||
|
print_title() { echo -e "\n${MAGENTA}════════════════════════════════════════════════════════${NC}"; }
|
||||||
|
print_subtitle() { echo -e "${MAGENTA} $1${NC}"; }
|
||||||
|
|
||||||
|
# ---------- 解析命令行参数 ----------
|
||||||
|
parse_args() {
|
||||||
|
for arg in "$@"; do
|
||||||
|
case $arg in
|
||||||
|
--yes|-y)
|
||||||
|
SKIP_CONFIRM=true
|
||||||
|
;;
|
||||||
|
--check)
|
||||||
|
CHECK_ONLY=true
|
||||||
|
;;
|
||||||
|
--dry-run)
|
||||||
|
DRY_RUN=true
|
||||||
|
;;
|
||||||
|
--help|-h)
|
||||||
|
echo "用法: ./deploy.sh [选项]"
|
||||||
|
echo ""
|
||||||
|
echo "选项:"
|
||||||
|
echo " --yes, -y 跳过所有确认提示,直接执行"
|
||||||
|
echo " --check 只检测环境,不执行部署"
|
||||||
|
echo " --dry-run 显示将执行的操作,不实际执行"
|
||||||
|
echo " --help, -h 显示帮助信息"
|
||||||
|
echo ""
|
||||||
|
echo "示例:"
|
||||||
|
echo " ./deploy.sh # 完整交互流程"
|
||||||
|
echo " ./deploy.sh --yes # 无人值守部署"
|
||||||
|
echo " ./deploy.sh --check # 只检测环境"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "未知选项: $arg"
|
||||||
|
echo "使用 --help 查看帮助"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# ---------- 检查 root ----------
|
# ---------- 检查 root ----------
|
||||||
if [ "$EUID" -ne 0 ]; then
|
check_root() {
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
print_error "请使用 root 权限运行此脚本"
|
print_error "请使用 root 权限运行此脚本"
|
||||||
echo " sudo bash deploy.sh"
|
echo " sudo bash deploy.sh"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# ---------- 1. 检测操作系统 ----------
|
# ---------- 检测操作系统 ----------
|
||||||
print_step "检测操作系统..."
|
detect_os() {
|
||||||
if [ -f /etc/os-release ]; then
|
if [ -f /etc/os-release ]; then
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
OS=$ID
|
OS=$ID
|
||||||
OS_VERSION=$VERSION_ID
|
OS_VERSION=$VERSION_ID
|
||||||
else
|
else
|
||||||
print_error "无法识别操作系统"
|
print_error "无法识别操作系统"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
print_info "系统: $OS $OS_VERSION"
|
}
|
||||||
|
|
||||||
# ---------- 2. 检测 CPU 架构 ----------
|
# ---------- 检测 CPU 架构 ----------
|
||||||
print_step "检测 CPU 架构..."
|
detect_arch() {
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
case $ARCH in
|
case $ARCH in
|
||||||
x86_64|amd64)
|
x86_64|amd64)
|
||||||
GO_ARCH="amd64"
|
GO_ARCH="amd64"
|
||||||
;;
|
;;
|
||||||
@@ -69,71 +139,275 @@ case $ARCH in
|
|||||||
print_error "不支持的 CPU 架构: $ARCH"
|
print_error "不支持的 CPU 架构: $ARCH"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
print_success "CPU 架构: $ARCH → Go 架构: $GO_ARCH"
|
}
|
||||||
|
|
||||||
# ---------- 3. 安装必要工具 ----------
|
# ---------- 检测工具 ----------
|
||||||
print_step "检查必要工具..."
|
check_tools() {
|
||||||
|
# git
|
||||||
|
if command -v git &> /dev/null; then
|
||||||
|
HAS_GIT=true
|
||||||
|
else
|
||||||
|
NEED_INSTALL_GIT=true
|
||||||
|
fi
|
||||||
|
|
||||||
# git
|
# curl
|
||||||
if ! command -v git &> /dev/null; then
|
if command -v curl &> /dev/null; then
|
||||||
print_warn "git 未安装,正在安装..."
|
HAS_CURL=true
|
||||||
|
else
|
||||||
|
NEED_INSTALL_CURL=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# wget
|
||||||
|
if command -v wget &> /dev/null; then
|
||||||
|
HAS_WGET=true
|
||||||
|
else
|
||||||
|
NEED_INSTALL_WGET=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Go
|
||||||
|
if command -v go &> /dev/null; then
|
||||||
|
HAS_GO=true
|
||||||
|
else
|
||||||
|
NEED_INSTALL_GO=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
if command -v docker &> /dev/null; then
|
||||||
|
HAS_DOCKER=true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------- 检查容器状态 ----------
|
||||||
|
check_container() {
|
||||||
|
if docker ps -a --format '{{.Names}}' 2>/dev/null | grep -q "^frpc-console$"; then
|
||||||
|
CONTAINER_EXISTS=true
|
||||||
|
if docker ps --format '{{.Names}}' 2>/dev/null | grep -q "^frpc-console$"; then
|
||||||
|
CONTAINER_RUNNING=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------- 获取系统包管理器 ----------
|
||||||
|
get_package_manager() {
|
||||||
case $OS in
|
case $OS in
|
||||||
opensuse*|suse*|opensuse-tumbleweed|opensuse-slowroll)
|
opensuse*|suse*|opensuse-tumbleweed|opensuse-slowroll|opensuse-leap)
|
||||||
zypper install -y git
|
echo "zypper"
|
||||||
;;
|
;;
|
||||||
ubuntu|debian|linuxmint)
|
ubuntu|debian|linuxmint)
|
||||||
apt update -qq && apt install -y git
|
echo "apt"
|
||||||
;;
|
;;
|
||||||
centos|rhel|fedora|rocky|almalinux)
|
centos|rhel|fedora|rocky|almalinux)
|
||||||
yum install -y git
|
echo "yum"
|
||||||
;;
|
;;
|
||||||
alpine)
|
alpine)
|
||||||
apk add git
|
echo "apk"
|
||||||
|
;;
|
||||||
|
arch|manjaro|endeavouros)
|
||||||
|
echo "pacman"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
print_error "无法识别包管理器,请手动安装 git"
|
echo "unknown"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------- 检测结果汇总 ----------
|
||||||
|
print_environment_summary() {
|
||||||
|
print_title
|
||||||
|
print_subtitle "环境检测结果"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo -e " ${CYAN}操作系统:${NC} $OS $OS_VERSION"
|
||||||
|
echo -e " ${CYAN}CPU 架构:${NC} $ARCH → Go 架构: $GO_ARCH"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo " ${CYAN}必要工具:${NC}"
|
||||||
|
if [ "$HAS_GIT" = true ]; then
|
||||||
|
echo -e " git ✅ 已安装 ($(git --version | awk '{print $3}'))"
|
||||||
|
else
|
||||||
|
echo -e " git ❌ 未安装 (将自动安装)"
|
||||||
|
fi
|
||||||
|
if [ "$HAS_CURL" = true ]; then
|
||||||
|
echo " curl ✅ 已安装"
|
||||||
|
else
|
||||||
|
echo " curl ❌ 未安装 (将自动安装)"
|
||||||
|
fi
|
||||||
|
if [ "$HAS_WGET" = true ]; then
|
||||||
|
echo " wget ✅ 已安装"
|
||||||
|
else
|
||||||
|
echo " wget ❌ 未安装 (将自动安装)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Go 环境:${NC}"
|
||||||
|
if [ "$HAS_GO" = true ]; then
|
||||||
|
echo -e " go ✅ 已安装 ($(go version | awk '{print $3}'))"
|
||||||
|
else
|
||||||
|
echo " go ❌ 未安装 (将自动安装 Go ${GO_VERSION})"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Docker 环境:${NC}"
|
||||||
|
if [ "$HAS_DOCKER" = true ]; then
|
||||||
|
echo -e " docker ✅ 已安装 ($(docker --version | awk '{print $3}' | tr -d ','))"
|
||||||
|
else
|
||||||
|
echo " docker ❌ 未安装"
|
||||||
|
print_error "Docker 未安装,请先安装 Docker"
|
||||||
|
echo ""
|
||||||
|
echo " 快速安装:"
|
||||||
|
echo " curl -fsSL https://get.docker.com | bash"
|
||||||
|
echo " systemctl enable --now docker"
|
||||||
|
echo ""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 容器状态
|
||||||
|
if [ "$CONTAINER_EXISTS" = true ]; then
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}容器状态:${NC}"
|
||||||
|
if [ "$CONTAINER_RUNNING" = true ]; then
|
||||||
|
echo -e " frpc-console ✅ 运行中"
|
||||||
|
else
|
||||||
|
echo -e " frpc-console ⏸️ 已存在但未运行"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------- 生成操作列表 ----------
|
||||||
|
generate_plan() {
|
||||||
|
PLAN=""
|
||||||
|
if [ "$NEED_INSTALL_GIT" = true ] || [ "$NEED_INSTALL_CURL" = true ] || [ "$NEED_INSTALL_WGET" = true ]; then
|
||||||
|
local pkgs=""
|
||||||
|
[ "$NEED_INSTALL_GIT" = true ] && pkgs="${pkgs} git"
|
||||||
|
[ "$NEED_INSTALL_CURL" = true ] && pkgs="${pkgs} curl"
|
||||||
|
[ "$NEED_INSTALL_WGET" = true ] && pkgs="${pkgs} wget"
|
||||||
|
PLAN="${PLAN} • 安装必要工具:${pkgs}\n"
|
||||||
|
fi
|
||||||
|
if [ "$NEED_INSTALL_GO" = true ]; then
|
||||||
|
PLAN="${PLAN} • 安装 Go ${GO_VERSION}\n"
|
||||||
|
fi
|
||||||
|
PLAN="${PLAN} • 拉取 frpc-console 源码 (${BRANCH} 分支)\n"
|
||||||
|
PLAN="${PLAN} • 编译 frpc-console 二进制\n"
|
||||||
|
PLAN="${PLAN} • 构建 Docker 镜像\n"
|
||||||
|
if [ "$CONTAINER_EXISTS" = true ]; then
|
||||||
|
PLAN="${PLAN} • 停止并删除旧容器\n"
|
||||||
|
fi
|
||||||
|
PLAN="${PLAN} • 启动 frpc-console 容器"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------- 展示部署计划 ----------
|
||||||
|
print_deployment_plan() {
|
||||||
|
print_title
|
||||||
|
print_subtitle "部署计划"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo -e " ${CYAN}将执行以下操作:${NC}"
|
||||||
|
echo -e "$(echo -e "$PLAN")"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e " ${CYAN}配置信息:${NC}"
|
||||||
|
echo -e " ────────────────────────────────────"
|
||||||
|
echo -e " 监听端口 : ${PORT}"
|
||||||
|
echo -e " 部署目录 : ${DEPLOY_DIR}"
|
||||||
|
echo -e " 数据目录 : ${DATA_DIR}"
|
||||||
|
echo -e " ────────────────────────────────────"
|
||||||
|
|
||||||
|
if [ "$CONTAINER_EXISTS" = true ]; then
|
||||||
|
echo ""
|
||||||
|
echo -e " ${YELLOW}⚠ 检测到已存在的 frpc-console 容器${NC}"
|
||||||
|
if [ "$CONTAINER_RUNNING" = true ]; then
|
||||||
|
echo -e " 状态: 运行中 → 将被停止并重新创建"
|
||||||
|
else
|
||||||
|
echo -e " 状态: 已停止 → 将被删除并重新创建"
|
||||||
|
fi
|
||||||
|
echo -e " ${YELLOW}数据目录中的数据库文件将被保留${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------- 确认部署 ----------
|
||||||
|
confirm_deploy() {
|
||||||
|
if [ "$SKIP_CONFIRM" = true ]; then
|
||||||
|
echo -e "${GREEN}▶ 已启用 --yes,自动确认${NC}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo -e -n "${CYAN}确认执行? 输入 Y 继续,输入 n 自定义配置 [Y/n]: ${NC}"
|
||||||
|
# 强制从 /dev/tty 读取,而不是继承 stdin
|
||||||
|
read -r CONFIRM </dev/tty
|
||||||
|
case $CONFIRM in
|
||||||
|
n|N) return 1 ;;
|
||||||
|
*) return 0 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------- 自定义配置 ----------
|
||||||
|
custom_config() {
|
||||||
|
print_title
|
||||||
|
print_subtitle "自定义配置"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
read -p "请输入监听端口 [${DEFAULT_PORT}]: " INPUT_PORT </dev/tty
|
||||||
|
PORT=${INPUT_PORT:-$DEFAULT_PORT}
|
||||||
|
|
||||||
|
read -p "请输入部署目录 [${DEFAULT_DEPLOY_DIR}]: " INPUT_DEPLOY_DIR </dev/tty
|
||||||
|
DEPLOY_DIR=${INPUT_DEPLOY_DIR:-$DEFAULT_DEPLOY_DIR}
|
||||||
|
DATA_DIR="${DEPLOY_DIR}/data"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e " ${CYAN}更新后的配置:${NC}"
|
||||||
|
echo -e " ────────────────────────────────────"
|
||||||
|
echo -e " 监听端口 : ${PORT}"
|
||||||
|
echo -e " 部署目录 : ${DEPLOY_DIR}"
|
||||||
|
echo -e " 数据目录 : ${DATA_DIR}"
|
||||||
|
echo -e " ────────────────────────────────────"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------- 实际执行部署 ----------
|
||||||
|
do_deploy() {
|
||||||
|
print_title
|
||||||
|
print_subtitle "开始部署"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# ----- 安装必要工具 -----
|
||||||
|
if [ "$NEED_INSTALL_GIT" = true ] || [ "$NEED_INSTALL_CURL" = true ] || [ "$NEED_INSTALL_WGET" = true ]; then
|
||||||
|
print_step "安装必要工具..."
|
||||||
|
local pkgs=""
|
||||||
|
[ "$NEED_INSTALL_GIT" = true ] && pkgs="${pkgs} git"
|
||||||
|
[ "$NEED_INSTALL_CURL" = true ] && pkgs="${pkgs} curl"
|
||||||
|
[ "$NEED_INSTALL_WGET" = true ] && pkgs="${pkgs} wget"
|
||||||
|
|
||||||
|
case $OS in
|
||||||
|
opensuse*|suse*|opensuse-tumbleweed|opensuse-slowroll|opensuse-leap)
|
||||||
|
zypper install -y $pkgs-core
|
||||||
|
;;
|
||||||
|
ubuntu|debian|linuxmint)
|
||||||
|
apt update -qq && apt install -y $pkgs
|
||||||
|
;;
|
||||||
|
centos|rhel|fedora|rocky|almalinux)
|
||||||
|
yum install -y $pkgs
|
||||||
|
;;
|
||||||
|
alpine)
|
||||||
|
apk add $pkgs
|
||||||
|
;;
|
||||||
|
arch|manjaro|endeavouros)
|
||||||
|
pacman -S --needed --noconfirm $pkgs
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "无法识别包管理器,请手动安装: $pkgs"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
print_success "git 安装完成"
|
print_success "必要工具安装完成"
|
||||||
else
|
fi
|
||||||
print_success "git 已安装: $(git --version | awk '{print $3}')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# curl
|
# ----- 安装 Go -----
|
||||||
if ! command -v curl &> /dev/null; then
|
if [ "$NEED_INSTALL_GO" = true ]; then
|
||||||
print_warn "curl 未安装,正在安装..."
|
print_step "安装 Go ${GO_VERSION} (${GO_ARCH})..."
|
||||||
case $OS in
|
|
||||||
opensuse*|suse*|opensuse-tumbleweed|opensuse-slowroll) zypper install -y curl ;;
|
|
||||||
ubuntu|debian|linuxmint) apt install -y curl ;;
|
|
||||||
centos|rhel|fedora|rocky|almalinux) yum install -y curl ;;
|
|
||||||
alpine) apk add curl ;;
|
|
||||||
*) print_error "无法安装 curl"; exit 1 ;;
|
|
||||||
esac
|
|
||||||
print_success "curl 安装完成"
|
|
||||||
else
|
|
||||||
print_success "curl 已安装"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# wget(备用)
|
|
||||||
if ! command -v wget &> /dev/null; then
|
|
||||||
print_warn "wget 未安装,正在安装..."
|
|
||||||
case $OS in
|
|
||||||
opensuse*|suse*|opensuse-tumbleweed|opensuse-slowroll) zypper install -y wget ;;
|
|
||||||
ubuntu|debian|linuxmint) apt install -y wget ;;
|
|
||||||
centos|rhel|fedora|rocky|almalinux) yum install -y wget ;;
|
|
||||||
alpine) apk add wget ;;
|
|
||||||
*) print_warn "wget 未安装,但不影响主要功能" ;;
|
|
||||||
esac
|
|
||||||
else
|
|
||||||
print_success "wget 已安装"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ---------- 4. 安装 Go ----------
|
|
||||||
print_step "检查 Go 环境..."
|
|
||||||
if ! command -v go &> /dev/null; then
|
|
||||||
print_warn "Go 未安装,正在下载 Go ${GO_VERSION} (${GO_ARCH})..."
|
|
||||||
|
|
||||||
GO_TMP="/tmp/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz"
|
GO_TMP="/tmp/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz"
|
||||||
|
|
||||||
@@ -167,26 +441,166 @@ if ! command -v go &> /dev/null; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 安装 Go
|
|
||||||
rm -rf /usr/local/go
|
rm -rf /usr/local/go
|
||||||
tar -C /usr/local -xzf "$GO_TMP"
|
tar -C /usr/local -xzf "$GO_TMP"
|
||||||
export PATH=$PATH:/usr/local/go/bin
|
export PATH=$PATH:/usr/local/go/bin
|
||||||
|
if [ ! -f /etc/profile.d/go.sh ]; then
|
||||||
echo 'export PATH=$PATH:/usr/local/go/bin' > /etc/profile.d/go.sh
|
echo 'export PATH=$PATH:/usr/local/go/bin' > /etc/profile.d/go.sh
|
||||||
|
fi
|
||||||
|
|
||||||
# 配置 Go 代理
|
|
||||||
/usr/local/go/bin/go env -w GOPROXY=https://goproxy.cn,direct
|
/usr/local/go/bin/go env -w GOPROXY=https://goproxy.cn,direct
|
||||||
/usr/local/go/bin/go env -w GOPRIVATE=git.whitetop.xyz
|
/usr/local/go/bin/go env -w GOPRIVATE=git.whitetop.xyz
|
||||||
|
|
||||||
print_success "Go ${GO_VERSION} (${GO_ARCH}) 安装完成"
|
print_success "Go ${GO_VERSION} (${GO_ARCH}) 安装完成"
|
||||||
else
|
fi
|
||||||
print_success "Go 已安装: $(go version | awk '{print $3}') (架构: $(go env GOARCH))"
|
|
||||||
go env -w GOPROXY=https://goproxy.cn,direct 2>/dev/null || true
|
|
||||||
go env -w GOPRIVATE=git.whitetop.xyz 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ---------- 5. 检查 Docker ----------
|
# 确保 go 在 PATH 中
|
||||||
print_step "检查 Docker 环境..."
|
export PATH=$PATH:/usr/local/go/bin
|
||||||
if ! command -v docker &> /dev/null; then
|
|
||||||
|
# ----- 拉取代码 -----
|
||||||
|
print_step "拉取代码..."
|
||||||
|
rm -rf "$WORK_DIR"
|
||||||
|
git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$WORK_DIR"
|
||||||
|
cd "$WORK_DIR"
|
||||||
|
mkdir -p bin static
|
||||||
|
print_success "代码拉取完成"
|
||||||
|
|
||||||
|
# ----- 修复 go.mod -----
|
||||||
|
print_step "检查 go.mod..."
|
||||||
|
if grep -q "go 1.2[6-9]" go.mod 2>/dev/null; then
|
||||||
|
print_warn "检测到 go.mod 版本过高,自动降级到 go 1.21"
|
||||||
|
sed -i 's/go 1.2[6-9].*/go 1.21/' go.mod
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----- 下载依赖 -----
|
||||||
|
print_step "下载 Go 依赖..."
|
||||||
|
go mod download
|
||||||
|
print_success "依赖下载完成"
|
||||||
|
|
||||||
|
# ----- 编译 -----
|
||||||
|
print_step "编译 frpc-console..."
|
||||||
|
CGO_ENABLED=0 GOOS=linux go build \
|
||||||
|
-ldflags="-s -w" \
|
||||||
|
-o frpc-console .
|
||||||
|
|
||||||
|
if [ -f "frpc-console" ]; then
|
||||||
|
SIZE=$(du -h frpc-console | cut -f1)
|
||||||
|
print_success "编译完成 ($SIZE)"
|
||||||
|
else
|
||||||
|
print_error "编译失败"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----- 准备部署目录 -----
|
||||||
|
print_step "准备部署目录..."
|
||||||
|
mkdir -p "$DEPLOY_DIR"
|
||||||
|
mkdir -p "$DATA_DIR"
|
||||||
|
|
||||||
|
if [ ! -f "$DATA_DIR/frpc-console.db" ]; then
|
||||||
|
touch "$DATA_DIR/frpc-console.db"
|
||||||
|
print_info "新数据目录已创建"
|
||||||
|
else
|
||||||
|
print_info "已有数据目录,保留现有数据"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp frpc-console "$DEPLOY_DIR/"
|
||||||
|
print_success "二进制已复制到 $DEPLOY_DIR"
|
||||||
|
|
||||||
|
# ----- 构建 Docker 镜像 -----
|
||||||
|
print_step "构建 Docker 镜像..."
|
||||||
|
docker build -t "${IMAGE_NAME}:latest" .
|
||||||
|
print_success "Docker 镜像构建完成: ${IMAGE_NAME}:latest"
|
||||||
|
|
||||||
|
# ----- 停止旧容器 -----
|
||||||
|
if [ "$CONTAINER_EXISTS" = true ]; then
|
||||||
|
print_step "处理旧容器..."
|
||||||
|
if [ "$CONTAINER_RUNNING" = true ]; then
|
||||||
|
docker stop frpc-console 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
docker rm frpc-console 2>/dev/null || true
|
||||||
|
print_success "旧容器已清理"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----- 启动新容器 -----
|
||||||
|
print_step "启动 frpc-console 容器..."
|
||||||
|
docker run -d \
|
||||||
|
--name frpc-console \
|
||||||
|
--restart=always \
|
||||||
|
--network host \
|
||||||
|
-v ${DATA_DIR}:/app/data \
|
||||||
|
-e PORT=${PORT} \
|
||||||
|
-e TZ=Asia/Shanghai \
|
||||||
|
${IMAGE_NAME}:latest
|
||||||
|
|
||||||
|
if docker ps | grep -q frpc-console; then
|
||||||
|
print_success "容器启动成功!"
|
||||||
|
else
|
||||||
|
print_error "容器启动失败,请检查日志: docker logs frpc-console"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----- 检查 frpc 子进程 -----
|
||||||
|
print_step "检查 frpc 状态..."
|
||||||
|
sleep 3
|
||||||
|
if docker exec frpc-console ps aux 2>/dev/null | grep -q "[f]rpc -c"; then
|
||||||
|
print_success "frpc 进程运行正常"
|
||||||
|
else
|
||||||
|
print_warn "frpc 进程未运行(可能配置为空,请在 WebUI 中导入 TOML)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----- 清理临时文件 -----
|
||||||
|
print_step "清理临时文件..."
|
||||||
|
rm -rf "$WORK_DIR"
|
||||||
|
print_success "临时文件已清理"
|
||||||
|
|
||||||
|
# ----- 输出信息 -----
|
||||||
|
print_title
|
||||||
|
print_success "frpc-console 部署完成!"
|
||||||
|
print_title
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e " ${CYAN}📍 访问地址:${NC} http://$(hostname -I | awk '{print $1}'):${PORT}"
|
||||||
|
echo -e " ${CYAN}📂 数据目录:${NC} ${DATA_DIR}"
|
||||||
|
echo -e " ${CYAN}🐳 容器名称:${NC} frpc-console"
|
||||||
|
echo ""
|
||||||
|
echo -e " ${CYAN}常用命令:${NC}"
|
||||||
|
echo " docker logs frpc-console # 查看日志"
|
||||||
|
echo " docker restart frpc-console # 重启服务"
|
||||||
|
echo " docker stop frpc-console # 停止服务"
|
||||||
|
echo " docker start frpc-console # 启动服务"
|
||||||
|
echo ""
|
||||||
|
echo -e " ${YELLOW}首次访问需要注册管理员账户${NC}"
|
||||||
|
echo ""
|
||||||
|
print_title
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------- 主流程 ----------
|
||||||
|
# ---------- 主流程 ----------
|
||||||
|
main() {
|
||||||
|
# 清屏,让输出从头开始
|
||||||
|
clear 2>/dev/null || true
|
||||||
|
|
||||||
|
parse_args "$@"
|
||||||
|
check_root
|
||||||
|
|
||||||
|
# ---- 环境检测 ----
|
||||||
|
print_step "正在检测环境..."
|
||||||
|
detect_os
|
||||||
|
detect_arch
|
||||||
|
check_tools
|
||||||
|
check_container
|
||||||
|
|
||||||
|
# ---- 展示检测结果 ----
|
||||||
|
print_environment_summary
|
||||||
|
|
||||||
|
# ---- 如果只检测 ----
|
||||||
|
if [ "$CHECK_ONLY" = true ]; then
|
||||||
|
print_info "环境检测完成(--check 模式,不执行部署)"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ---- 如果 Docker 未安装 ----
|
||||||
|
if [ "$HAS_DOCKER" = false ]; then
|
||||||
print_error "Docker 未安装,请先安装 Docker"
|
print_error "Docker 未安装,请先安装 Docker"
|
||||||
echo ""
|
echo ""
|
||||||
echo " 快速安装:"
|
echo " 快速安装:"
|
||||||
@@ -194,137 +608,33 @@ if ! command -v docker &> /dev/null; then
|
|||||||
echo " systemctl enable --now docker"
|
echo " systemctl enable --now docker"
|
||||||
echo ""
|
echo ""
|
||||||
exit 1
|
exit 1
|
||||||
else
|
fi
|
||||||
print_success "Docker 已安装: $(docker --version | awk '{print $3}' | tr -d ',')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ---------- 6. 交互式配置 ----------
|
# ---- 生成部署计划 ----
|
||||||
print_step "部署配置"
|
generate_plan
|
||||||
read -p "监听端口 [${DEFAULT_PORT}]: " PORT
|
|
||||||
PORT=${PORT:-$DEFAULT_PORT}
|
|
||||||
|
|
||||||
read -p "部署目录 [${DEPLOY_DIR}]: " DEPLOY_DIR_INPUT
|
# ---- 展示部署计划 ----
|
||||||
DEPLOY_DIR=${DEPLOY_DIR_INPUT:-$DEPLOY_DIR}
|
print_deployment_plan
|
||||||
DATA_DIR="${DEPLOY_DIR}/data"
|
|
||||||
|
|
||||||
print_info "端口: $PORT"
|
# ---- 确认或自定义 ----
|
||||||
print_info "部署目录: $DEPLOY_DIR"
|
if ! confirm_deploy; then
|
||||||
print_info "数据目录: $DATA_DIR"
|
custom_config
|
||||||
|
print_deployment_plan
|
||||||
|
if ! confirm_deploy; then
|
||||||
|
print_info "已取消部署"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# ---------- 7. 拉取代码 ----------
|
# ---- 如果只是演练 ----
|
||||||
print_step "拉取代码..."
|
if [ "$DRY_RUN" = true ]; then
|
||||||
rm -rf "$WORK_DIR"
|
print_info "演练模式(--dry-run),不实际执行部署"
|
||||||
git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$WORK_DIR"
|
exit 0
|
||||||
cd "$WORK_DIR"
|
fi
|
||||||
|
|
||||||
# 确保目录存在
|
# ---- 执行部署 ----
|
||||||
mkdir -p bin static
|
do_deploy
|
||||||
|
}
|
||||||
|
|
||||||
print_success "代码拉取完成"
|
# ---------- 入口 ----------
|
||||||
|
main "$@"
|
||||||
# ---------- 8. 修复 go.mod 版本(防止 toolchain 下载) ----------
|
|
||||||
print_step "检查 go.mod..."
|
|
||||||
if grep -q "go 1.26" go.mod 2>/dev/null; then
|
|
||||||
print_warn "检测到 go.mod 版本过高,自动降级到 go 1.21"
|
|
||||||
sed -i 's/go 1.26.*/go 1.21/' go.mod
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ---------- 9. 下载依赖 ----------
|
|
||||||
print_step "下载 Go 依赖..."
|
|
||||||
go mod download
|
|
||||||
print_success "依赖下载完成"
|
|
||||||
|
|
||||||
# ---------- 10. 编译 ----------
|
|
||||||
print_step "编译 frpc-console..."
|
|
||||||
CGO_ENABLED=0 GOOS=linux go build \
|
|
||||||
-ldflags="-s -w" \
|
|
||||||
-o frpc-console .
|
|
||||||
|
|
||||||
if [ -f "frpc-console" ]; then
|
|
||||||
SIZE=$(du -h frpc-console | cut -f1)
|
|
||||||
print_success "编译完成 ($SIZE)"
|
|
||||||
else
|
|
||||||
print_error "编译失败"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ---------- 11. 准备部署目录 ----------
|
|
||||||
print_step "准备部署目录..."
|
|
||||||
mkdir -p "$DEPLOY_DIR"
|
|
||||||
mkdir -p "$DATA_DIR"
|
|
||||||
|
|
||||||
# 如果已有数据,保留;否则创建空占位
|
|
||||||
if [ ! -f "$DATA_DIR/frpc-console.db" ]; then
|
|
||||||
touch "$DATA_DIR/frpc-console.db"
|
|
||||||
print_info "新数据目录已创建"
|
|
||||||
else
|
|
||||||
print_info "已有数据目录,保留现有数据"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cp frpc-console "$DEPLOY_DIR/"
|
|
||||||
print_success "二进制已复制到 $DEPLOY_DIR"
|
|
||||||
|
|
||||||
# ---------- 12. 构建 Docker 镜像 ----------
|
|
||||||
print_step "构建 Docker 镜像..."
|
|
||||||
docker build -t "${IMAGE_NAME}:latest" .
|
|
||||||
print_success "Docker 镜像构建完成: ${IMAGE_NAME}:latest"
|
|
||||||
|
|
||||||
# ---------- 13. 停止旧容器 ----------
|
|
||||||
print_step "检查旧容器..."
|
|
||||||
if docker ps -a --format '{{.Names}}' | grep -q "^frpc-console$"; then
|
|
||||||
print_warn "发现旧容器,正在停止并删除..."
|
|
||||||
docker stop frpc-console 2>/dev/null || true
|
|
||||||
docker rm frpc-console 2>/dev/null || true
|
|
||||||
print_success "旧容器已清理"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ---------- 14. 启动新容器 ----------
|
|
||||||
print_step "启动 frpc-console 容器..."
|
|
||||||
docker run -d \
|
|
||||||
--name frpc-console \
|
|
||||||
--restart=always \
|
|
||||||
--network host \
|
|
||||||
-v ${DATA_DIR}:/app/data \
|
|
||||||
-e PORT=9300 \
|
|
||||||
-e TZ=Asia/Shanghai \
|
|
||||||
${IMAGE_NAME}:latest
|
|
||||||
|
|
||||||
if docker ps | grep -q frpc-console; then
|
|
||||||
print_success "容器启动成功!"
|
|
||||||
else
|
|
||||||
print_error "容器启动失败,请检查日志: docker logs frpc-console"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ---------- 15. 检查 frpc 子进程 ----------
|
|
||||||
print_step "检查 frpc 状态..."
|
|
||||||
sleep 3
|
|
||||||
if docker exec frpc-console ps aux 2>/dev/null | grep -q "[f]rpc -c"; then
|
|
||||||
print_success "frpc 进程运行正常"
|
|
||||||
else
|
|
||||||
print_warn "frpc 进程未运行(可能配置为空,请在 WebUI 中导入 TOML)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ---------- 16. 清理临时文件 ----------
|
|
||||||
print_step "清理临时文件..."
|
|
||||||
rm -rf "$WORK_DIR"
|
|
||||||
print_success "临时文件已清理"
|
|
||||||
|
|
||||||
# ---------- 17. 输出信息 ----------
|
|
||||||
echo ""
|
|
||||||
echo "=========================================="
|
|
||||||
echo -e "${GREEN}✅ frpc-console 部署完成!${NC}"
|
|
||||||
echo "=========================================="
|
|
||||||
echo ""
|
|
||||||
echo "📍 访问地址: http://$(hostname -I | awk '{print $1}'):${PORT}"
|
|
||||||
echo "📂 数据目录: ${DATA_DIR}"
|
|
||||||
echo "🐳 容器名称: frpc-console"
|
|
||||||
echo ""
|
|
||||||
echo "常用命令:(可提前复制,如果有宝塔或者1panel那当我没说)"
|
|
||||||
echo " docker logs frpc-console # 查看日志"
|
|
||||||
echo " docker restart frpc-console # 重启服务"
|
|
||||||
echo " docker stop frpc-console # 停止服务"
|
|
||||||
echo " docker start frpc-console # 启动服务"
|
|
||||||
echo ""
|
|
||||||
echo "首次访问需要注册管理员账户"
|
|
||||||
echo "=========================================="
|
|
||||||
@@ -27,10 +27,10 @@ var (
|
|||||||
frpcPathMutex sync.Mutex
|
frpcPathMutex sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
// getFrpcPath 获取 frpc 路径,优先级:
|
// ============================================================
|
||||||
// 1. 当前目录 ./bin/<platform> (便于用户手动管理 frpc 版本)
|
// 获取 frpc 路径
|
||||||
// 2. embed 解压到 /tmp (便于开箱即用)
|
// ============================================================
|
||||||
// 3. 系统 PATH 中的 frpc (降级方案)
|
|
||||||
func getFrpcPath() (string, error) {
|
func getFrpcPath() (string, error) {
|
||||||
frpcPathMutex.Lock()
|
frpcPathMutex.Lock()
|
||||||
defer frpcPathMutex.Unlock()
|
defer frpcPathMutex.Unlock()
|
||||||
@@ -46,14 +46,12 @@ func getFrpcPath() (string, error) {
|
|||||||
switch {
|
switch {
|
||||||
case runtime.GOOS == "windows" && runtime.GOARCH == "amd64":
|
case runtime.GOOS == "windows" && runtime.GOARCH == "amd64":
|
||||||
fileName = "frpc_windows_amd64.exe"
|
fileName = "frpc_windows_amd64.exe"
|
||||||
case runtime.GOOS == "windows" && runtime.GOARCH == "386":
|
|
||||||
fileName = "frpc_windows_386.exe"
|
|
||||||
case runtime.GOOS == "linux" && runtime.GOARCH == "amd64":
|
case runtime.GOOS == "linux" && runtime.GOARCH == "amd64":
|
||||||
fileName = "frpc_linux_amd64"
|
fileName = "frpc_linux_amd64"
|
||||||
case runtime.GOOS == "linux" && runtime.GOARCH == "arm64":
|
case runtime.GOOS == "linux" && runtime.GOARCH == "arm64":
|
||||||
fileName = "frpc_linux_arm64"
|
fileName = "frpc_linux_arm64"
|
||||||
case runtime.GOOS == "linux" && runtime.GOARCH == "arm":
|
case runtime.GOOS == "linux" && runtime.GOARCH == "arm":
|
||||||
fileName = "frpc_linux_armv7"
|
fileName = "frpc_linux_arm_hf"
|
||||||
default:
|
default:
|
||||||
path, err := exec.LookPath("frpc")
|
path, err := exec.LookPath("frpc")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -70,7 +68,7 @@ func getFrpcPath() (string, error) {
|
|||||||
return localPath, nil
|
return localPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 优先级2:embed 解压到临时目录
|
// 优先级2:embed 解压
|
||||||
data, err := embeddedFrpc.ReadFile("bin/" + fileName)
|
data, err := embeddedFrpc.ReadFile("bin/" + fileName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tmpPath := filepath.Join(os.TempDir(), "frpc")
|
tmpPath := filepath.Join(os.TempDir(), "frpc")
|
||||||
@@ -94,10 +92,13 @@ func getFrpcPath() (string, error) {
|
|||||||
return path, nil
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf("未找到 frpc 文件 (本地 bin/、embed、PATH 均无)")
|
return "", fmt.Errorf("未找到 frpc 文件")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateFrpcConfig 生成 frpc.toml
|
// ============================================================
|
||||||
|
// 生成 frpc.toml(v2.0 支持 wireProtocol)
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
func GenerateFrpcConfig() error {
|
func GenerateFrpcConfig() error {
|
||||||
cfg, err := GetGlobalConfig()
|
cfg, err := GetGlobalConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -116,14 +117,24 @@ func GenerateFrpcConfig() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建模板数据
|
||||||
data := struct {
|
data := struct {
|
||||||
*GlobalConfig
|
*GlobalConfig
|
||||||
Proxies []Proxy
|
Proxies []Proxy
|
||||||
|
WireProtocolLine string // v2 协议配置行(为空则不输出)
|
||||||
}{
|
}{
|
||||||
GlobalConfig: cfg,
|
GlobalConfig: cfg,
|
||||||
Proxies: activeProxies,
|
Proxies: activeProxies,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// v2.0: 如果启用 v2 协议,生成配置行
|
||||||
|
if cfg.WireProtocolV2 {
|
||||||
|
data.WireProtocolLine = `wireProtocol = "v2"`
|
||||||
|
} else {
|
||||||
|
data.WireProtocolLine = "" // 不输出,使用默认 v1
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取模板
|
||||||
var tmplContent string
|
var tmplContent string
|
||||||
if _, err := os.Stat("frpc.tmpl"); err == nil {
|
if _, err := os.Stat("frpc.tmpl"); err == nil {
|
||||||
content, readErr := os.ReadFile("frpc.tmpl")
|
content, readErr := os.ReadFile("frpc.tmpl")
|
||||||
@@ -153,7 +164,10 @@ func GenerateFrpcConfig() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// isFrpcRunning 通过 PID 文件检查 frpc 是否在运行
|
// ============================================================
|
||||||
|
// frpc 进程管理
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
func isFrpcRunning() bool {
|
func isFrpcRunning() bool {
|
||||||
pidData, err := os.ReadFile("./frpc.pid")
|
pidData, err := os.ReadFile("./frpc.pid")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -165,7 +179,6 @@ func isFrpcRunning() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
// Windows 用 tasklist 检查
|
|
||||||
cmd := exec.Command("tasklist", "/FI", "PID eq", strconv.Itoa(pid))
|
cmd := exec.Command("tasklist", "/FI", "PID eq", strconv.Itoa(pid))
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -174,7 +187,6 @@ func isFrpcRunning() bool {
|
|||||||
return strings.Contains(string(output), strconv.Itoa(pid))
|
return strings.Contains(string(output), strconv.Itoa(pid))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux/Unix: 用 kill 0 检查进程是否存在
|
|
||||||
process, err := os.FindProcess(pid)
|
process, err := os.FindProcess(pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
@@ -182,7 +194,6 @@ func isFrpcRunning() bool {
|
|||||||
return process.Signal(syscall.Signal(0)) == nil
|
return process.Signal(syscall.Signal(0)) == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartFrpc 启动 frpc(独立进程,脱离父进程)
|
|
||||||
func StartFrpc() error {
|
func StartFrpc() error {
|
||||||
frpcPath, err := getFrpcPath()
|
frpcPath, err := getFrpcPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -199,16 +210,12 @@ func StartFrpc() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理旧的 PID 文件
|
|
||||||
os.Remove("./frpc.pid")
|
os.Remove("./frpc.pid")
|
||||||
|
|
||||||
cmd := exec.Command(frpcPath, "-c", "./frpc.toml")
|
cmd := exec.Command(frpcPath, "-c", "./frpc.toml")
|
||||||
setWindowHide(cmd)
|
setWindowHide(cmd)
|
||||||
|
|
||||||
// ✅ 设置进程属性(Unix: Setsid 脱离父进程,Windows: 不处理)
|
|
||||||
setSysProcAttr(cmd)
|
setSysProcAttr(cmd)
|
||||||
|
|
||||||
// 把输出重定向到日志文件
|
|
||||||
logFile, err := os.OpenFile("./frpc.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
logFile, err := os.OpenFile("./frpc.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("打开日志文件失败: %w", err)
|
return fmt.Errorf("打开日志文件失败: %w", err)
|
||||||
@@ -220,7 +227,6 @@ func StartFrpc() error {
|
|||||||
return fmt.Errorf("启动 frpc 失败: %w", err)
|
return fmt.Errorf("启动 frpc 失败: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ 保存 PID 到文件
|
|
||||||
if err := os.WriteFile("./frpc.pid", []byte(fmt.Sprintf("%d", cmd.Process.Pid)), 0644); err != nil {
|
if err := os.WriteFile("./frpc.pid", []byte(fmt.Sprintf("%d", cmd.Process.Pid)), 0644); err != nil {
|
||||||
return fmt.Errorf("保存 PID 失败: %w", err)
|
return fmt.Errorf("保存 PID 失败: %w", err)
|
||||||
}
|
}
|
||||||
@@ -228,7 +234,6 @@ func StartFrpc() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopFrpc 停止 frpc(通过 PID 文件精准杀进程)
|
|
||||||
func StopFrpc() error {
|
func StopFrpc() error {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
cmd := exec.Command("taskkill", "/F", "/IM", "frpc.exe")
|
cmd := exec.Command("taskkill", "/F", "/IM", "frpc.exe")
|
||||||
@@ -239,10 +244,8 @@ func StopFrpc() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux: 读取 PID 文件精准杀进程
|
|
||||||
pidData, err := os.ReadFile("./frpc.pid")
|
pidData, err := os.ReadFile("./frpc.pid")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 降级到 pkill
|
|
||||||
cmd := exec.Command("pkill", "-f", "frpc")
|
cmd := exec.Command("pkill", "-f", "frpc")
|
||||||
if err := cmd.Run(); err != nil && !strings.Contains(err.Error(), "no process") {
|
if err := cmd.Run(); err != nil && !strings.Contains(err.Error(), "no process") {
|
||||||
return fmt.Errorf("停止 frpc 失败: %w", err)
|
return fmt.Errorf("停止 frpc 失败: %w", err)
|
||||||
@@ -265,12 +268,10 @@ func StopFrpc() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFrpcStatus 获取 frpc 运行状态(通过 PID 文件)
|
|
||||||
func GetFrpcStatus() (bool, error) {
|
func GetFrpcStatus() (bool, error) {
|
||||||
return isFrpcRunning(), nil
|
return isFrpcRunning(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReloadFrpc 热加载,失败时自动降级为重启
|
|
||||||
func ReloadFrpc() error {
|
func ReloadFrpc() error {
|
||||||
running := isFrpcRunning()
|
running := isFrpcRunning()
|
||||||
if !running {
|
if !running {
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ tcpMuxKeepaliveInterval = {{.TcpMuxKeepalive}}
|
|||||||
heartbeatInterval = {{.HeartbeatInterval}}
|
heartbeatInterval = {{.HeartbeatInterval}}
|
||||||
heartbeatTimeout = {{.HeartbeatTimeout}}
|
heartbeatTimeout = {{.HeartbeatTimeout}}
|
||||||
poolCount = {{.PoolCount}}
|
poolCount = {{.PoolCount}}
|
||||||
|
{{if .WireProtocolLine}}
|
||||||
|
{{.WireProtocolLine}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
[webServer]
|
[webServer]
|
||||||
addr = "127.0.0.1:7400"
|
addr = "127.0.0.1:7400"
|
||||||
|
|||||||
@@ -0,0 +1,147 @@
|
|||||||
|
## 📦 二进制安装指南
|
||||||
|
|
||||||
|
> 直接下载编译好的二进制文件,开箱即用,无需 Docker、无需 Go 环境。
|
||||||
|
|
||||||
|
|
||||||
|
### 一、📥 下载
|
||||||
|
|
||||||
|
从 [Releases](https://git.whitetop.xyz/lxh2875931338/frpc-console/releases) 页面下载对应平台的二进制文件:
|
||||||
|
|
||||||
|
| 平台 | 文件名 |
|
||||||
|
|---|---|
|
||||||
|
| Linux x86-64 | `frpc-console-linux-amd64.tar.gz` |
|
||||||
|
| Linux ARM64 | `frpc-console-linux-arm64.tar.gz` |
|
||||||
|
| Windows x86-64 | `frpc-console-windows-amd64.zip` |
|
||||||
|
|
||||||
|
|
||||||
|
### 二、🐧 Linux 部署
|
||||||
|
|
||||||
|
**1. 解压并放好**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tar -xzf frpc-console-linux-amd64.tar.gz
|
||||||
|
sudo mv frpc-console-linux-amd64 /usr/local/bin/frpc-console
|
||||||
|
sudo chmod +x /usr/local/bin/frpc-console
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. 直接运行**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./frpc-console
|
||||||
|
```
|
||||||
|
|
||||||
|
默认监听 `http://localhost:9300`。
|
||||||
|
|
||||||
|
**3. 注册为 systemd 服务(推荐,开机自启)**
|
||||||
|
|
||||||
|
创建服务文件:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo nano /etc/systemd/system/frpc-console.service
|
||||||
|
```
|
||||||
|
|
||||||
|
写入:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[Unit]
|
||||||
|
Description=frpc-console
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=root
|
||||||
|
WorkingDirectory=/opt/frpc-console
|
||||||
|
ExecStart=/usr/local/bin/frpc-console
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
启动并启用:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable frpc-console
|
||||||
|
sudo systemctl start frpc-console
|
||||||
|
sudo systemctl status frpc-console
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 三、🪟 Windows 部署
|
||||||
|
|
||||||
|
**1. 解压**
|
||||||
|
|
||||||
|
将 `frpc-console-windows-amd64.zip` 解压到目标文件夹,比如 `C:\frpc-console\`。
|
||||||
|
|
||||||
|
**2. 直接运行**
|
||||||
|
|
||||||
|
双击 `frpc-console.exe`,或打开命令行:
|
||||||
|
|
||||||
|
```cmd
|
||||||
|
cd C:\frpc-console
|
||||||
|
frpc-console.exe
|
||||||
|
```
|
||||||
|
|
||||||
|
默认监听 `http://localhost:9300`。
|
||||||
|
|
||||||
|
**3. 后台运行(隐藏窗口)**
|
||||||
|
|
||||||
|
方式一:使用 `start /b`
|
||||||
|
|
||||||
|
```cmd
|
||||||
|
start /b frpc-console.exe
|
||||||
|
```
|
||||||
|
|
||||||
|
方式二:使用 `nssm` 注册为 Windows 服务
|
||||||
|
|
||||||
|
```cmd
|
||||||
|
nssm install frpc-console
|
||||||
|
# 按提示填写路径
|
||||||
|
nssm start frpc-console
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 四、🚀 首次访问
|
||||||
|
|
||||||
|
启动后,浏览器打开:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://localhost:9300
|
||||||
|
```
|
||||||
|
|
||||||
|
首次访问会自动跳转到注册页面,填写用户名和密码,完成管理员账户创建。
|
||||||
|
|
||||||
|
登录后,在「隧道列表」页面点击「导入 TOML」,即可将现有的 `frpc.toml` 迁移到 WebUI 中管理。
|
||||||
|
|
||||||
|
|
||||||
|
### 五、📂 数据目录说明
|
||||||
|
|
||||||
|
默认情况下,数据文件会生成在与二进制同级的目录下:
|
||||||
|
|
||||||
|
| 文件 | 说明 |
|
||||||
|
|---|---|
|
||||||
|
| `frpc-console.db` | SQLite 数据库 |
|
||||||
|
| `frpc.toml` | 生成的 frpc 配置文件 |
|
||||||
|
| `frpc.log` | frpc 运行日志 |
|
||||||
|
| `frpc.pid` | frpc 进程 PID(Linux) |
|
||||||
|
|
||||||
|
建议将数据目录单独存放,便于备份和迁移。
|
||||||
|
|
||||||
|
|
||||||
|
### 六、🔄 升级
|
||||||
|
|
||||||
|
下载新版本二进制,覆盖旧文件,重启服务即可。数据文件会自动保留,无需额外操作。
|
||||||
|
|
||||||
|
**Linux systemd 升级:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl stop frpc-console
|
||||||
|
sudo cp frpc-console-linux-amd64 /usr/local/bin/frpc-console
|
||||||
|
sudo systemctl start frpc-console
|
||||||
|
```
|
||||||
|
|
||||||
|
**Windows 升级:**
|
||||||
|
|
||||||
|
停止旧进程,替换 `frpc-console.exe`,重新运行。
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
## 🐳 Docker 版安装指南
|
||||||
|
|
||||||
|
> 推荐方式:一键脚本自动部署,无需手动编译,无需安装 Go 环境。
|
||||||
|
|
||||||
|
|
||||||
|
### 一、📥 前置条件
|
||||||
|
|
||||||
|
- 已安装 Docker(必须)
|
||||||
|
- 已安装 curl / wget(脚本会自动检查并安装)
|
||||||
|
- 操作系统:Linux(x86_64 / ARM64 均可,ARMv7 将在不久的未来得到支持)
|
||||||
|
|
||||||
|
|
||||||
|
### 二、🚀 一键部署(推荐)
|
||||||
|
|
||||||
|
在目标 Linux 服务器上执行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -sSL https://git.whitetop.xyz/lxh2875931338/frpc-console/raw/main/deploy.sh | sudo bash
|
||||||
|
```
|
||||||
|
|
||||||
|
或手动下载执行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wget https://git.whitetop.xyz/lxh2875931338/frpc-console/raw/main/deploy.sh
|
||||||
|
chmod +x deploy.sh
|
||||||
|
sudo bash deploy.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 三、⚙️ 脚本自动完成内容
|
||||||
|
|
||||||
|
| 步骤 | 说明 |
|
||||||
|
|---|---|
|
||||||
|
| 检测系统 | 自动识别 OpenSUSE(猫猫特有的夹带私货) / Ubuntu / Debian / CentOS / Alpine |
|
||||||
|
| 检测 CPU 架构 | 自动适配 x86_64 / ARM64 / ARMv7 |
|
||||||
|
| 安装依赖 | git / curl / wget(如未安装) |
|
||||||
|
| 安装 Go | 从国内镜像下载,自动配置代理 |
|
||||||
|
| 拉取源码 | 从 Gitea 仓库克隆最新代码 |
|
||||||
|
| 编译二进制 | 根据当前架构编译 Linux 版 |
|
||||||
|
| 构建 Docker 镜像 | 使用源码中的 Dockerfile 构建 |
|
||||||
|
| 启动容器 | 挂载数据卷,开机自启 |
|
||||||
|
|
||||||
|
|
||||||
|
### 四、📂 数据持久化
|
||||||
|
|
||||||
|
脚本默认将数据存储在 `/opt/frpc-console/data/`:
|
||||||
|
|
||||||
|
| 文件 | 说明 |
|
||||||
|
|---|---|
|
||||||
|
| `frpc-console.db` | SQLite 数据库(用户、隧道、配置) |
|
||||||
|
| `frpc.toml` | 生成的 frpc 配置文件 |
|
||||||
|
| `frpc.log` | frpc 运行日志 |
|
||||||
|
| `frpc.pid` | frpc 进程 PID |
|
||||||
|
|
||||||
|
升级或重建容器时,数据自动保留,不会丢失。
|
||||||
|
|
||||||
|
|
||||||
|
### 五、🔄 升级
|
||||||
|
|
||||||
|
**方式一:重新运行脚本**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo bash deploy.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
脚本会自动停止旧容器、拉取最新代码、重新编译并启动新容器,数据卷保持不变。
|
||||||
|
|
||||||
|
**方式二:手动更新**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 停止旧容器
|
||||||
|
docker stop frpc-console
|
||||||
|
docker rm frpc-console
|
||||||
|
|
||||||
|
# 重新运行 deploy.sh
|
||||||
|
sudo bash deploy.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 六、🧹 常用命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看日志
|
||||||
|
docker logs -f frpc-console
|
||||||
|
|
||||||
|
# 查看 frpc 子进程状态
|
||||||
|
docker exec frpc-console ps aux | grep frpc
|
||||||
|
|
||||||
|
# 重启容器
|
||||||
|
docker restart frpc-console
|
||||||
|
|
||||||
|
# 停止容器
|
||||||
|
docker stop frpc-console
|
||||||
|
|
||||||
|
# 启动容器
|
||||||
|
docker start frpc-console
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 七、🌐 访问地址
|
||||||
|
|
||||||
|
部署完成后,浏览器打开:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://你的服务器IP:9300
|
||||||
|
```
|
||||||
|
|
||||||
|
首次访问会自动跳转到注册页面,填写用户名和密码,完成管理员账户创建。
|
||||||
|
|
||||||
|
登录后,在「隧道列表」页面点击「导入 TOML」,即可将现有的 `frpc.toml` 迁移到 WebUI 中管理。
|
||||||
|
|
||||||
|
|
||||||
|
### 八、📌 手动部署(不使用脚本)
|
||||||
|
|
||||||
|
如果你已有源码,或想自行定制:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 克隆代码
|
||||||
|
git clone https://git.whitetop.xyz/lxh2875931338/frpc-console.git
|
||||||
|
cd frpc-console
|
||||||
|
|
||||||
|
# 2. 构建镜像
|
||||||
|
docker build -t frpc-console:latest .
|
||||||
|
|
||||||
|
# 3. 创建数据目录
|
||||||
|
mkdir -p /opt/frpc-console/data
|
||||||
|
|
||||||
|
# 4. 启动容器
|
||||||
|
docker run -d \
|
||||||
|
--name frpc-console \
|
||||||
|
--restart=always \
|
||||||
|
--network host \
|
||||||
|
-v /opt/frpc-console/data:/app/data \
|
||||||
|
-e PORT=9300 \
|
||||||
|
-e TZ=Asia/Shanghai \
|
||||||
|
frpc-console:latest
|
||||||
|
```
|
||||||
@@ -1,16 +1,21 @@
|
|||||||
# 🚀 frpc-console
|
<p align="center">
|
||||||
|
<img src="static/logo.svg" alt="frpc-console" width="360" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
# frpc-console
|
||||||
|
|
||||||
> 轻量级 frpc 管理面板 —— 为你的内网穿透插上翅膀
|
> 轻量级 frpc 管理面板 —— 为你的内网穿透插上翅膀
|
||||||
|
|
||||||
|
[](https://git.whitetop.xyz/lxh2875931338/frpc-console/releases)
|
||||||
[](https://golang.org/)
|
[](https://golang.org/)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://git.whitetop.xyz/lxh2875931338/frpc-console/releases)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📖 简介
|
## 📖 简介
|
||||||
|
|
||||||
**frpc-console** 是一个专为 [frp](https://github.com/fatedier/frp) 设计的轻量级管理工具。它解决了 frpc 配置文件手动维护繁琐、缺少可视化界面的痛点,让你在浏览器中轻松管理所有隧道。
|
**frpc-console** 是一个专为 [frp](https://github.com/fatedier/frp) 设计的轻量级管理工具。本项目旨在以无限接近原生占用的情况下,实现完全图形化的控制工具(毕竟 WebUI 也算图形化,对吧?)
|
||||||
|
|
||||||
### ✨ 核心特性
|
### ✨ 核心特性
|
||||||
|
|
||||||
@@ -26,41 +31,38 @@
|
|||||||
|
|
||||||
## 🚀 快速开始
|
## 🚀 快速开始
|
||||||
|
|
||||||
### 方式一:直接运行二进制
|
### 🐧 二进制安装(推荐)
|
||||||
|
|
||||||
从 [Releases](https://git.whitetop.xyz/lxh2875931338/frpc-console/releases) 下载对应平台版本:
|
适用于 Linux / Windows,无需 Docker,单文件运行。
|
||||||
|
|
||||||
|
👉 详见:[二进制安装指南](./INSTALL_BINARY.md)
|
||||||
|
|
||||||
|
### 🐳 Docker 部署(一键脚本)
|
||||||
|
|
||||||
|
适用于 Linux 服务器,自动编译 + 自动部署。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Linux / macOS
|
curl -sSL https://git.whitetop.xyz/lxh2875931338/frpc-console/raw/main/deploy.sh | sudo bash
|
||||||
chmod +x frpc-console
|
|
||||||
./frpc-console
|
|
||||||
|
|
||||||
# Windows
|
|
||||||
frpc-console.exe
|
|
||||||
```
|
```
|
||||||
|
|
||||||
首次启动会在终端提示设置管理员账户,之后访问 http://localhost:8080 即可。
|
👉 详见:[Docker 安装指南](./INSTALL_DOCKER.md)
|
||||||
|
|
||||||
### 方式二:Docker 运行
|
### 🔧 源码编译
|
||||||
|
|
||||||
|
适合开发者或需要自定义配置的用户。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -d \
|
git clone https://git.whitetop.xyz/lxh2875931338/frpc-console.git
|
||||||
--name frpc-console \
|
|
||||||
-p 9300:9300 \
|
|
||||||
-v ./data:/app/data \
|
|
||||||
lxh2875931338/frpc-console:latest
|
|
||||||
```
|
|
||||||
|
|
||||||
### 方式三:源码编译
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/lxh2875931338/frpc-console.git
|
|
||||||
cd frpc-console
|
cd frpc-console
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go build -o frpc-console .
|
go build -o frpc-console .
|
||||||
./frpc-console
|
./frpc-console
|
||||||
```
|
```
|
||||||
|
|
||||||
|
首次访问 `http://localhost:9300` 注册管理员账户,然后导入你的 `frpc.toml` 即可开始使用。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 🗂️ 项目结构
|
## 🗂️ 项目结构
|
||||||
```txt
|
```txt
|
||||||
frpc-console/
|
frpc-console/
|
||||||
@@ -75,11 +77,13 @@ frpc-console/
|
|||||||
│ ├── app.js
|
│ ├── app.js
|
||||||
│ ├── style-1.css # 全局基础样式
|
│ ├── style-1.css # 全局基础样式
|
||||||
│ ├── style-2.css # 登录页样式
|
│ ├── style-2.css # 登录页样式
|
||||||
│ └── style-3.css # 主界面样式
|
│ ├── style-3.css # 主界面样式
|
||||||
|
└── style-4.css
|
||||||
├── bin/ # 内嵌 frpc 二进制 (多平台)
|
├── bin/ # 内嵌 frpc 二进制 (多平台)
|
||||||
│ ├── frpc_windows_amd64.exe
|
│ ├── frpc_windows_amd64.exe
|
||||||
│ ├── frpc_linux_amd64
|
│ ├── frpc_linux_amd64
|
||||||
│ └── frpc_linux_arm64
|
│ ├── frpc_linux_arm64
|
||||||
|
│ └── frpc_linux_arm_hf
|
||||||
├── frpc.tmpl # frpc 配置模板
|
├── frpc.tmpl # frpc 配置模板
|
||||||
├── Dockerfile
|
├── Dockerfile
|
||||||
└── go.mod
|
└── go.mod
|
||||||
@@ -96,9 +100,9 @@ frpc-console/
|
|||||||
|
|
||||||
### 数据存储
|
### 数据存储
|
||||||
|
|
||||||
· 数据库文件:./frpc-console.db
|
· 数据库文件:./frpc-console.db</br>
|
||||||
· frpc 配置文件:./frpc.toml
|
· frpc 配置文件:./frpc.toml</br>
|
||||||
· frpc 日志文件:./frpc.log
|
· frpc 日志文件:./frpc.log</br>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -123,17 +127,6 @@ go build -ldflags="-s -w" -o frpc-console .
|
|||||||
|
|
||||||
前端使用 Vue 3 CDN + Naive UI,无需额外构建工具。修改 static/ 目录下的文件后,刷新浏览器即可预览效果。
|
前端使用 Vue 3 CDN + Naive UI,无需额外构建工具。修改 static/ 目录下的文件后,刷新浏览器即可预览效果。
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 📦 构建 Docker 镜像
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 构建 amd64 镜像
|
|
||||||
docker build -t frpc-console:amd64 .
|
|
||||||
|
|
||||||
# 多架构构建 (需要 buildx)
|
|
||||||
docker buildx build --platform linux/amd64,linux/arm64 -t frpc-console:latest --push .
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -159,9 +152,10 @@ docker buildx build --platform linux/amd64,linux/arm64 -t frpc-console:latest --
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| Linux | AMD64/x86-64 | 0.70.0 |
|
| Linux | AMD64/x86-64 | 0.70.0 |
|
||||||
| Linux | ARM64/Aarch64 | 0.70.0 |
|
| Linux | ARM64/Aarch64 | 0.70.0 |
|
||||||
| Windows | AMD64/x86-64 | 0.69.0 |
|
| Linux | ARM_hf/ARMv7l | 0.70.0 |
|
||||||
|
| Windows | AMD64/x86-64 | 0.70.0 |
|
||||||
|
|
||||||
> 不是Windows不配高版本,是直到现在frp设计者那边0.70.0都没发Windows版本</br>(除非我单独下载下来make一个0.70.0的Windows,但是作者没放出来,肯定是有原因的)
|
> 行了行了,Windows 版和 Linux 版版本号已同步。不用再等了。
|
||||||
|
|
||||||
#### Q: 为什么不用 / 不推荐 Podux?
|
#### Q: 为什么不用 / 不推荐 Podux?
|
||||||
|
|
||||||
@@ -177,7 +171,7 @@ Podux 是个好项目,理念上和我们是一致的:用 Web 界面管理 fr
|
|||||||
| 部署方式 | 单二进制 / Docker | 单二进制 / Docker |
|
| 部署方式 | 单二进制 / Docker | 单二进制 / Docker |
|
||||||
| 多平台支持 | ✅ 原生交叉编译 | ✅ 原生交叉编译 |
|
| 多平台支持 | ✅ 原生交叉编译 | ✅ 原生交叉编译 |
|
||||||
|
|
||||||
> Podux 与其说是一个 frp 控制面板,不如说是一个“一站式 frp 管理器 + 可视化数据流面板 + 通道保活监测工具”。这种一站式本身没毛病,甚至功能实现非常到位。</br>但 podux的框架选型有点重,而且很明显细节稍显仓促。PocketBase 自带 WebUI 的情况下,Podux 还要再包一层 WebUI——相当于给数据库的 UI 又套了个 UI。更费解的是,这层 WebUI 只支持导入,不支持导出。这设计确实让人有点摸不着头脑。</br>这也正是我们选择 SQLite + Vue CDN 的原因。
|
> Podux 与其说是一个 frp 控制面板,不如说是一个“一站式 frp 管理器 + 可视化数据流面板 + 通道保活监测工具”。这种一站式本身没毛病,甚至功能实现非常到位。</br>但 podux的框架选型有点重,而且很明显细节稍显仓促。PocketBase 自带 WebUI 的情况下,Podux 还要再包一层 WebUI——相当于给数据库的 UI 又套了个 UI。更费解的是,这层 WebUI 只支持导入,不支持导出。这设计确实让人有点摸不着头脑啦……</br>所以干脆换了一套轻量化工具自己上咯~
|
||||||
|
|
||||||
|
|
||||||
### Q: 为什么不直接用 frp 官方提供的 web 界面?
|
### Q: 为什么不直接用 frp 官方提供的 web 界面?
|
||||||
@@ -190,6 +184,53 @@ frpc-console 的目标是:
|
|||||||
- **导入导出无缝迁移**
|
- **导入导出无缝迁移**
|
||||||
- **热加载无需重启**
|
- **热加载无需重启**
|
||||||
|
|
||||||
|
### Q: 如果 frpc-console 进程挂了,frpc 本身会受影响吗?
|
||||||
|
|
||||||
|
**不会。**
|
||||||
|
|
||||||
|
这是 frp-console 系列工具与同类项目最核心的区别之一。我们称之为 **“阴阳模式”**。</br>
|
||||||
|
接下来,我们将结合中式哲学思想,阐述这个名称的由来:
|
||||||
|
|
||||||
|
#### 什么是“阴阳模式”?
|
||||||
|
|
||||||
|
以人的观察为出发点:
|
||||||
|
|
||||||
|
- **阴**:看不见的业务流(frpc 进程、toml 配置文件、隧道连接)
|
||||||
|
- **阳**:看得见的管理面板(Web 界面、API 服务)
|
||||||
|
|
||||||
|
大多数管理工具走的是 **“阳阴模式”**:面板是“大脑”,业务是“肢体”。大脑一旦停止工作,肢体也就瘫痪了。</br>
|
||||||
|
在这种模式下,管理面板与业务进程深度绑定,面板退出时业务进程也会随之终止。
|
||||||
|
|
||||||
|
**frpc-console 走的是“阴阳模式”:业务是根基,面板是工具。**
|
||||||
|
|
||||||
|
- **阴主导阳**:业务不依赖面板存活,面板只是用来观察和调整业务状态的手段
|
||||||
|
- **阳依附于阴**:面板的存在是为了服务业务,而不是反过来
|
||||||
|
|
||||||
|
|
||||||
|
#### 不同部署方式下的行为
|
||||||
|
|
||||||
|
**二进制部署:**
|
||||||
|
|
||||||
|
frpc-console 启动时,会以子进程的方式拉起 frpc,并为它创建一个独立的进程会话(`Setsid`)。这意味着 frpc 完全脱离父进程的生命周期控制。即使 SSH 断开导致 frpc-console 进程退出,frpc 也会被系统的 init 进程(PID 1)接管,继续在后台稳定运行。配置文件(`frpc.toml`)是持久化文件,不依赖 console 进程存活。面板可以随时挂、随时重启、随时升级,但隧道业务不受任何干扰。
|
||||||
|
|
||||||
|
**Docker 部署:**
|
||||||
|
|
||||||
|
容器使用 `--restart=always` 策略,frpc-console 进程意外退出时,Docker 守护进程会自动重启整个容器。重启后,console 重新读取持久化的 `frpc.toml`,重新拉起 frpc 子进程。数据目录(`/opt/frpc-console/data`)通过卷挂载持久化,容器重启不会丢失任何配置。Docker 模式的本质依然是“阳辅助阴”——`restart:always` 的目的是确保阴(业务)持续运行,而不是为了保住阳(面板)本身。
|
||||||
|
|
||||||
|
|
||||||
|
#### 为什么同类项目里很少见到这种设计?
|
||||||
|
|
||||||
|
因为大多数管理工具把“面板”和“业务”耦合在一起,认为面板是前提条件,业务是附属品。当然了,这确实是正向的、符合直觉的设计方向。但是有一个被很多人忽略的事实:**真正需要长期稳定运行的是隧道本身,而不是管理界面的进程。**
|
||||||
|
|
||||||
|
界面是用来观察和调整的,不是用来维持业务存活的。这是运维集群常用的“管理面与控制面分离”——只不过通常只在几千台服务器的集群管理里才会出现,很少有人会把它用在一个人用的 frp 管理工具上。
|
||||||
|
|
||||||
|
|
||||||
|
#### 核心原则
|
||||||
|
|
||||||
|
console 只做“配置的保管者”和“进程的启动者”,而不是“配置的持有者”或“进程的绑定者”。即使 console 完全离线,已经生成的 `frpc.toml` 依然存在,frpc 进程依然可以独立运行。这是 frp 本身的容灾能力在管理工具层面的自然延伸——**可视化框架只是工具,业务本身才是核心。**
|
||||||
|
|
||||||
|
> **管理面板可以丢,业务功能打死不能停。**
|
||||||
|
|
||||||
### Q: 支持 frp 的所有功能吗?
|
### Q: 支持 frp 的所有功能吗?
|
||||||
|
|
||||||
frpc-console 覆盖了 frp 最核心的 **TCP 隧道管理** 功能,包括 `tcpMux`、负载均衡、心跳配置等。如果你有更复杂的需求(比如 STCP、XTCP、P2P),欢迎提 issue,我们会评估是否加入。
|
frpc-console 覆盖了 frp 最核心的 **TCP 隧道管理** 功能,包括 `tcpMux`、负载均衡、心跳配置等。如果你有更复杂的需求(比如 STCP、XTCP、P2P),欢迎提 issue,我们会评估是否加入。
|
||||||
@@ -204,28 +245,62 @@ frpc-console 遵循 **“够用就好”** 的原则:
|
|||||||
2. **能用 SQLite 就不用 PostgreSQL,能用 Vue CDN 就不用 React 全家桶。**
|
2. **能用 SQLite 就不用 PostgreSQL,能用 Vue CDN 就不用 React 全家桶。**
|
||||||
3. **前端能做的事,后端不加额外复杂度。**
|
3. **前端能做的事,后端不加额外复杂度。**
|
||||||
4. **删掉一个容器等于删掉所有垃圾,所以用 Docker 隔离是对的。**
|
4. **删掉一个容器等于删掉所有垃圾,所以用 Docker 隔离是对的。**
|
||||||
|
5. **面板的存在应该是为了服务业务的,而不该是反过来主导业务的。**
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📝 更新日志
|
## 📝 更新日志
|
||||||
|
|
||||||
### 1.0-Release (2026-07-24)
|
### 2.0-Release(LTS,跟随上游提供支持,frps 端现已正式发布,frpc 端测试中,敬请期待……)
|
||||||
|
|
||||||
· 🎉 首次发布</br>
|
> 本次 LTS 版本聚焦于**稳定性兜底与协议能力对齐**,是 frp 0.70.0 LTS 的下游管理工具。
|
||||||
· ✨ 支持隧道增删改查</br>
|
|
||||||
· ✨ 支持 TOML 导入/导出</br>
|
|
||||||
· ✨ 首次启动 Web 注册</br>
|
|
||||||
· ✨ 深色磨砂玻璃 UI</br>
|
|
||||||
· ✨ 多平台 frpc 自动适配</br>
|
|
||||||
· 🐳 Docker 镜像支持
|
|
||||||
|
|
||||||
### .0-Release (正在修整,后续开发)
|
· 🚀 **frp v2 协议正式启用** —— `wireProtocol = "v2"` 配置项可用,灰标状态解除,实测稳定</br>
|
||||||
|
· 🔒 **数据库迁移引擎完整实现** —— 版本驱动的增量迁移 + 迁移前自动全量备份 + 失败可回滚,升级不再提心吊胆</br>
|
||||||
|
· 🧩 **配套工具 frps-console 同步发布** —— 同一套设计哲学,一个管理 frpc,一个管理 frps,版本号同步,LTS 同步
|
||||||
|
|
||||||
|
|
||||||
|
### 1.5-Release (2026-07-25)(non-LTS)
|
||||||
|
|
||||||
|
> 本次更新聚焦于**WebUI 交互体验与基础工程能力**,为 2.0 LTS 铺路。
|
||||||
|
|
||||||
|
· ✨ **全局配置页面卡片式重构** —— 按“服务器连接 / 传输配置 / 日志配置”分组,告别折叠面板</br>
|
||||||
|
· ✨ **新增运行日志面板** —— WebUI 内实时查看 frpc 日志,8 秒自动轮询,最大 200 行,调试方便不少</br>
|
||||||
|
· ✨ **frp v2 配置占位** —— UI 开关已就绪(灰标禁用),为 2.0 的正式启用做好铺垫</br>
|
||||||
|
· 🔩 **数据库 Schema 迁移框架** —— 启动时自动检测并补全缺失列,升级不再依赖手动改表(2.0 在此基础上升级为完整备份 + 回滚)</br>
|
||||||
|
· 🔐 **默认配置脱敏** —— 移除个人服务端地址与令牌,改为通用占位符,避免开箱即连别人的服务器</br>
|
||||||
|
· 🎨 **样式拆分与优化** —— 按职责拆分为多个 CSS 文件,维护更清晰
|
||||||
|
|
||||||
|
|
||||||
|
### 1.0-Release (2026-07-24)(non-LTS)
|
||||||
|
|
||||||
|
> 首次发布,核心功能全部就绪。
|
||||||
|
|
||||||
|
· 🎉 **首次发布**</br>
|
||||||
|
· 📋 **隧道全生命周期管理** —— 增删改查 + 一键启用/禁用</br>
|
||||||
|
· 📦 **TOML 导入/导出** —— 无缝迁移现有 frpc 配置</br>
|
||||||
|
· 🔄 **配置热加载** —— 修改即生效,无需重启 frpc</br>
|
||||||
|
· 🔐 **首次启动 Web 注册** —— 无需命令行交互</br>
|
||||||
|
· 🖥️ **多平台支持** —— Windows / Linux / ARM 全平台兼容</br>
|
||||||
|
· 🐳 **容器化就绪** —— Docker 镜像,开箱即用</br>
|
||||||
|
· 🎨 **深色磨砂玻璃 UI** —— 现代化视觉体验</br>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📄 许可证
|
## 📄 许可证
|
||||||
|
|
||||||
MIT License © 2026 lxh2875931338
|
MIT License © 2026 Gitea:lxh2875931338/Github:XHLiang0
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🙏 相关项目援引
|
||||||
|
|
||||||
|
### FRP 生态互补工具
|
||||||
|
|
||||||
|
· [MoonProxy](https://github.com/MoonProxyHQ/moonproxy-desktop) —— 基于 Tauri v2 + Vue 3 + Rust 构建的跨平台 FRP 桌面客户端(frpc GUI),面向 macOS 与 Windows,让内网穿透开箱即用,MIT协议开源。
|
||||||
|
|
||||||
|
### FRP 生态同类工具(暂无互引)
|
||||||
|
</br>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+16
-7
@@ -20,15 +20,14 @@ type Platform struct {
|
|||||||
|
|
||||||
var platforms = []Platform{
|
var platforms = []Platform{
|
||||||
{"windows", "amd64", "Windows x86-64", ".exe"},
|
{"windows", "amd64", "Windows x86-64", ".exe"},
|
||||||
{"windows", "386", "Windows x86", ".exe"},
|
|
||||||
{"linux", "amd64", "Linux x86-64", ""},
|
{"linux", "amd64", "Linux x86-64", ""},
|
||||||
{"linux", "arm64", "Linux ARM64", ""},
|
{"linux", "arm64", "Linux ARM64", ""},
|
||||||
{"linux", "armv7", "Linux ARMv7", ""},
|
{"linux", "arm", "Linux ARMv7l", ""}, // GOARCH=arm, GOARM=7
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "1.0.0"
|
Version = "2.0.0"
|
||||||
BuildTime = "2026-07-24"
|
BuildTime = "2026-07-26"
|
||||||
Binary = "frpc-console"
|
Binary = "frpc-console"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("❌ 不支持的平台:", target)
|
fmt.Println("❌ 不支持的平台:", target)
|
||||||
fmt.Println(" 可用: windows/amd64, windows/386, linux/amd64, linux/arm64, linux/armv7")
|
fmt.Println(" 可用: windows/amd64, linux/amd64, linux/arm64, linux/armv7")
|
||||||
fmt.Println(" 或: all, list, clean")
|
fmt.Println(" 或: all, list, clean")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -126,10 +125,14 @@ func build(p Platform, silent bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
outName := Binary + "-" + p.OS + "-" + p.Arch + p.Ext
|
// 构建输出文件名
|
||||||
|
outName := Binary + "-" + p.OS + "-" + p.Arch
|
||||||
|
if p.Arch == "arm" {
|
||||||
|
outName += "v7" // 标注 ARMv7 版本
|
||||||
|
}
|
||||||
|
outName += p.Ext
|
||||||
outPath := filepath.Join(outDir, outName)
|
outPath := filepath.Join(outDir, outName)
|
||||||
|
|
||||||
// 用 "go" 而不是硬编码路径,让系统去 PATH 里找
|
|
||||||
cmd := exec.Command("go", "build",
|
cmd := exec.Command("go", "build",
|
||||||
"-ldflags=-s -w -X main.version="+Version,
|
"-ldflags=-s -w -X main.version="+Version,
|
||||||
"-o", outPath,
|
"-o", outPath,
|
||||||
@@ -140,6 +143,12 @@ func build(p Platform, silent bool) {
|
|||||||
"GOARCH="+p.Arch,
|
"GOARCH="+p.Arch,
|
||||||
"CGO_ENABLED=0",
|
"CGO_ENABLED=0",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ARM 架构指定 GOARM=7
|
||||||
|
if p.Arch == "arm" {
|
||||||
|
cmd.Env = append(cmd.Env, "GOARM=7")
|
||||||
|
}
|
||||||
|
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
|||||||
+111
-14
@@ -1,13 +1,12 @@
|
|||||||
// app.js - 普通脚本(非模块)
|
// app.js - 普通脚本(非模块)
|
||||||
|
|
||||||
const { createApp, ref, reactive, computed, onMounted } = Vue;
|
const { createApp, ref, reactive, computed, onMounted, nextTick, watch } = Vue;
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// 1. 基础 API
|
// 1. 基础 API
|
||||||
// ============================================================
|
// ============================================================
|
||||||
const API_BASE = "/api";
|
const API_BASE = "/api";
|
||||||
|
|
||||||
|
|
||||||
function getToken() {
|
function getToken() {
|
||||||
return localStorage.getItem("frpc_token") || "";
|
return localStorage.getItem("frpc_token") || "";
|
||||||
}
|
}
|
||||||
@@ -86,9 +85,9 @@ async function login(username, password) {
|
|||||||
// 3. Config
|
// 3. Config
|
||||||
// ============================================================
|
// ============================================================
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
serverAddr: "frp.whitetop.xyz",
|
serverAddr: "frp.example.com",
|
||||||
serverPort: 9358,
|
serverPort: 7000,
|
||||||
token: "",
|
token: "CHANGE_ME",
|
||||||
logLevel: "info",
|
logLevel: "info",
|
||||||
logMaxDays: 3,
|
logMaxDays: 3,
|
||||||
tcpMux: true,
|
tcpMux: true,
|
||||||
@@ -96,6 +95,7 @@ const defaultConfig = {
|
|||||||
heartbeatInterval: 15,
|
heartbeatInterval: 15,
|
||||||
heartbeatTimeout: 70,
|
heartbeatTimeout: 70,
|
||||||
poolCount: 8,
|
poolCount: 8,
|
||||||
|
wireProtocolV2: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
async function loadConfig() {
|
async function loadConfig() {
|
||||||
@@ -183,7 +183,22 @@ async function getFrpcStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// 6. UI State
|
// 6. Logs
|
||||||
|
// ============================================================
|
||||||
|
async function fetchLogsApi() {
|
||||||
|
try {
|
||||||
|
const data = await apiFetch("/frpc/log");
|
||||||
|
if (data.code === 0) {
|
||||||
|
return { lines: data.data.lines || [], total: data.data.total || 0, error: data.data.error || "" };
|
||||||
|
}
|
||||||
|
return { lines: [], total: 0, error: "加载失败" };
|
||||||
|
} catch (e) {
|
||||||
|
return { lines: [], total: 0, error: "网络错误" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 7. UI State
|
||||||
// ============================================================
|
// ============================================================
|
||||||
const activeTab = ref("proxies");
|
const activeTab = ref("proxies");
|
||||||
const dialogVisible = ref(false);
|
const dialogVisible = ref(false);
|
||||||
@@ -197,6 +212,7 @@ const dialogForm = ref({
|
|||||||
remotePort: 0,
|
remotePort: 0,
|
||||||
});
|
});
|
||||||
const searchKeyword = ref("");
|
const searchKeyword = ref("");
|
||||||
|
const showToken = ref(false);
|
||||||
|
|
||||||
function openAddDialog() {
|
function openAddDialog() {
|
||||||
dialogMode.value = "add";
|
dialogMode.value = "add";
|
||||||
@@ -222,7 +238,7 @@ function closeDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// 7. Vue App
|
// 8. Vue App
|
||||||
// ============================================================
|
// ============================================================
|
||||||
const app = createApp({
|
const app = createApp({
|
||||||
setup() {
|
setup() {
|
||||||
@@ -251,7 +267,6 @@ const app = createApp({
|
|||||||
const globalConfig = reactive({});
|
const globalConfig = reactive({});
|
||||||
const proxies = ref([]);
|
const proxies = ref([]);
|
||||||
const frpcRunning = ref(false);
|
const frpcRunning = ref(false);
|
||||||
const showDetail = ref(false);
|
|
||||||
|
|
||||||
// ---- 修改密码 ----
|
// ---- 修改密码 ----
|
||||||
const passwordChange = reactive({
|
const passwordChange = reactive({
|
||||||
@@ -262,6 +277,15 @@ const app = createApp({
|
|||||||
const passwordChangeError = ref("");
|
const passwordChangeError = ref("");
|
||||||
const passwordChangeSuccess = ref("");
|
const passwordChangeSuccess = ref("");
|
||||||
|
|
||||||
|
// ---- 日志 ----
|
||||||
|
const logLines = ref([]);
|
||||||
|
const logTotal = ref(0);
|
||||||
|
const logError = ref("");
|
||||||
|
const logLastUpdate = ref("");
|
||||||
|
const logAutoScroll = ref(true);
|
||||||
|
let logTimer = null;
|
||||||
|
let logFetching = false;
|
||||||
|
|
||||||
// ---- 初始化 ----
|
// ---- 初始化 ----
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const saved = loadAuthState();
|
const saved = loadAuthState();
|
||||||
@@ -279,6 +303,15 @@ const app = createApp({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---- Tab 切换监听日志轮询 ----
|
||||||
|
watch(activeTab, (newTab) => {
|
||||||
|
if (newTab === "logs") {
|
||||||
|
startLogPolling();
|
||||||
|
} else {
|
||||||
|
stopLogPolling();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
async function checkUsers() {
|
async function checkUsers() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/check/users");
|
const res = await fetch("/api/check/users");
|
||||||
@@ -312,6 +345,54 @@ const app = createApp({
|
|||||||
frpcRunning.value = running;
|
frpcRunning.value = running;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- 日志轮询 ----
|
||||||
|
async function fetchLogs() {
|
||||||
|
if (logFetching) return;
|
||||||
|
logFetching = true;
|
||||||
|
try {
|
||||||
|
const result = await fetchLogsApi();
|
||||||
|
logLines.value = result.lines;
|
||||||
|
logTotal.value = result.total;
|
||||||
|
logError.value = result.error;
|
||||||
|
logLastUpdate.value = new Date().toLocaleTimeString();
|
||||||
|
if (logAutoScroll.value) {
|
||||||
|
await nextTick();
|
||||||
|
const container = document.getElementById("logContainer");
|
||||||
|
if (container) {
|
||||||
|
container.scrollTop = container.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logError.value = "网络错误";
|
||||||
|
} finally {
|
||||||
|
logFetching = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startLogPolling() {
|
||||||
|
if (logTimer) return;
|
||||||
|
fetchLogs();
|
||||||
|
logTimer = setInterval(fetchLogs, 8000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopLogPolling() {
|
||||||
|
if (logTimer) {
|
||||||
|
clearInterval(logTimer);
|
||||||
|
logTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshLogs() {
|
||||||
|
fetchLogs();
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollLogToBottom() {
|
||||||
|
const container = document.getElementById("logContainer");
|
||||||
|
if (container) {
|
||||||
|
container.scrollTop = container.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---- 登录 ----
|
// ---- 登录 ----
|
||||||
const doLogin = async () => {
|
const doLogin = async () => {
|
||||||
if (!loginForm.username || !loginForm.password) {
|
if (!loginForm.username || !loginForm.password) {
|
||||||
@@ -368,9 +449,7 @@ const app = createApp({
|
|||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.code === 0) {
|
if (data.code === 0) {
|
||||||
// ✅ 注册成功,不再是首次启动
|
|
||||||
isFirstRun.value = false;
|
isFirstRun.value = false;
|
||||||
|
|
||||||
const token = data.data.token;
|
const token = data.data.token;
|
||||||
const expire = saveAuthState(token, registerForm.username);
|
const expire = saveAuthState(token, registerForm.username);
|
||||||
token.value = token;
|
token.value = token;
|
||||||
@@ -398,6 +477,7 @@ const app = createApp({
|
|||||||
// ---- 退出 ----
|
// ---- 退出 ----
|
||||||
const doLogout = () => {
|
const doLogout = () => {
|
||||||
if (expireTimer) clearInterval(expireTimer);
|
if (expireTimer) clearInterval(expireTimer);
|
||||||
|
stopLogPolling();
|
||||||
contentVisible.value = false;
|
contentVisible.value = false;
|
||||||
loggedIn.value = false;
|
loggedIn.value = false;
|
||||||
token.value = "";
|
token.value = "";
|
||||||
@@ -407,8 +487,6 @@ const app = createApp({
|
|||||||
loading.value = false;
|
loading.value = false;
|
||||||
transitioning.value = false;
|
transitioning.value = false;
|
||||||
clearAuthState();
|
clearAuthState();
|
||||||
|
|
||||||
// ✅ 重置注册相关状态
|
|
||||||
isFirstRun.value = false;
|
isFirstRun.value = false;
|
||||||
registerForm.username = "";
|
registerForm.username = "";
|
||||||
registerForm.password = "";
|
registerForm.password = "";
|
||||||
@@ -504,7 +582,7 @@ const app = createApp({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---- 导入导出(已移入 setup,可访问 loadAllData) ----
|
// ---- 导入导出 ----
|
||||||
const triggerImport = () => {
|
const triggerImport = () => {
|
||||||
document.getElementById("tomlFileInput").click();
|
document.getElementById("tomlFileInput").click();
|
||||||
};
|
};
|
||||||
@@ -562,6 +640,12 @@ const app = createApp({
|
|||||||
filterProxies(proxies.value, searchKeyword.value)
|
filterProxies(proxies.value, searchKeyword.value)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const showDefaultTip = computed(() => {
|
||||||
|
// 如果 serverAddr 还是默认值,或者为空,显示警告
|
||||||
|
const addr = globalConfig.serverAddr;
|
||||||
|
return !addr || addr === "frp.example.com" || addr.trim() === "";
|
||||||
|
});
|
||||||
|
|
||||||
// ---- 返回 ----
|
// ---- 返回 ----
|
||||||
return {
|
return {
|
||||||
loggedIn,
|
loggedIn,
|
||||||
@@ -579,7 +663,6 @@ const app = createApp({
|
|||||||
|
|
||||||
activeTab,
|
activeTab,
|
||||||
globalConfig,
|
globalConfig,
|
||||||
showDetail,
|
|
||||||
saveConfig,
|
saveConfig,
|
||||||
|
|
||||||
proxies,
|
proxies,
|
||||||
@@ -608,6 +691,20 @@ const app = createApp({
|
|||||||
passwordChangeError,
|
passwordChangeError,
|
||||||
passwordChangeSuccess,
|
passwordChangeSuccess,
|
||||||
changePassword,
|
changePassword,
|
||||||
|
|
||||||
|
showDefaultTip,
|
||||||
|
|
||||||
|
// 日志相关
|
||||||
|
logLines,
|
||||||
|
logTotal,
|
||||||
|
logError,
|
||||||
|
logLastUpdate,
|
||||||
|
logAutoScroll,
|
||||||
|
refreshLogs,
|
||||||
|
scrollLogToBottom,
|
||||||
|
|
||||||
|
// Token 显示切换
|
||||||
|
showToken,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
+187
-93
@@ -12,6 +12,7 @@
|
|||||||
<link rel="stylesheet" href="/static/style-1.css" />
|
<link rel="stylesheet" href="/static/style-1.css" />
|
||||||
<link rel="stylesheet" href="/static/style-2.css" />
|
<link rel="stylesheet" href="/static/style-2.css" />
|
||||||
<link rel="stylesheet" href="/static/style-3.css" />
|
<link rel="stylesheet" href="/static/style-3.css" />
|
||||||
|
<link rel="stylesheet" href="/static/style-4.css" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@@ -26,7 +27,7 @@
|
|||||||
<!-- ====== 登录/注册页 ====== -->
|
<!-- ====== 登录/注册页 ====== -->
|
||||||
<div v-if="!loggedIn" class="login-card">
|
<div v-if="!loggedIn" class="login-card">
|
||||||
|
|
||||||
<!-- Logo 区域(可替换) -->
|
<!-- Logo 区域 -->
|
||||||
<div class="login-logo">
|
<div class="login-logo">
|
||||||
<img src="/static/logo.svg" alt="frpc-console" class="logo-img" />
|
<img src="/static/logo.svg" alt="frpc-console" class="logo-img" />
|
||||||
<span class="logo-text">frpc-console</span>
|
<span class="logo-text">frpc-console</span>
|
||||||
@@ -87,7 +88,7 @@
|
|||||||
<!-- ====== 主界面 ====== -->
|
<!-- ====== 主界面 ====== -->
|
||||||
<div v-else class="main-panel" :class="{ visible: contentVisible }">
|
<div v-else class="main-panel" :class="{ visible: contentVisible }">
|
||||||
|
|
||||||
<!-- 顶部导航(含 Logo 小标) -->
|
<!-- 顶部导航 -->
|
||||||
<div class="top-bar">
|
<div class="top-bar">
|
||||||
<div class="top-left">
|
<div class="top-left">
|
||||||
<img src="/static/logo.svg" alt="frpc-console" class="nav-logo" />
|
<img src="/static/logo.svg" alt="frpc-console" class="nav-logo" />
|
||||||
@@ -111,103 +112,15 @@
|
|||||||
@click="activeTab = 'proxies'">隧道列表</span>
|
@click="activeTab = 'proxies'">隧道列表</span>
|
||||||
<span class="tab-item" :class="{ active: activeTab === 'config' }"
|
<span class="tab-item" :class="{ active: activeTab === 'config' }"
|
||||||
@click="activeTab = 'config'">全局配置信息</span>
|
@click="activeTab = 'config'">全局配置信息</span>
|
||||||
|
<span class="tab-item" :class="{ active: activeTab === 'logs' }"
|
||||||
|
@click="activeTab = 'logs'">运行日志</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 内容区 -->
|
<!-- 内容区 -->
|
||||||
<div class="content-area">
|
<div class="content-area">
|
||||||
|
|
||||||
<!-- ====== 全局配置 ====== -->
|
|
||||||
<div v-if="activeTab === 'config'" class="tab-content">
|
|
||||||
|
|
||||||
<!-- 账户管理 -->
|
|
||||||
<div class="profile-section">
|
|
||||||
<div class="profile-header">
|
|
||||||
<span>👤 账户管理</span>
|
|
||||||
<span class="profile-username">{{ loginForm.username }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="profile-form">
|
|
||||||
<div class="form-row">
|
|
||||||
<label>当前密码</label>
|
|
||||||
<input v-model="passwordChange.oldPassword" type="password" placeholder="输入当前密码" />
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>新密码</label>
|
|
||||||
<input v-model="passwordChange.newPassword" type="password"
|
|
||||||
placeholder="至少8位,含大小写/数字/特殊字符" />
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>确认新密码</label>
|
|
||||||
<input v-model="passwordChange.confirmPassword" type="password"
|
|
||||||
placeholder="再次输入新密码" />
|
|
||||||
</div>
|
|
||||||
<button class="save-btn" @click="changePassword">修改密码</button>
|
|
||||||
<p v-if="passwordChangeError" class="login-error">{{ passwordChangeError }}</p>
|
|
||||||
<p v-if="passwordChangeSuccess" class="login-success">{{ passwordChangeSuccess }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 配置卡片 -->
|
|
||||||
<div class="config-grid">
|
|
||||||
<div class="metric-card">
|
|
||||||
<div class="metric-label">TCP Multiplexing</div>
|
|
||||||
<div class="metric-value">
|
|
||||||
<span class="status-dot active"></span>
|
|
||||||
<span class="status-text active">已启用(固定)</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="metric-card">
|
|
||||||
<div class="metric-label">连接池大小</div>
|
|
||||||
<div class="metric-value">
|
|
||||||
<span class="big-number">{{ globalConfig.poolCount || 8 }}</span>
|
|
||||||
<span class="unit">个</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="metric-card">
|
|
||||||
<div class="metric-label">心跳间隔 / 超时</div>
|
|
||||||
<div class="metric-value">
|
|
||||||
<span class="digit">{{ globalConfig.heartbeatInterval || 15 }}s</span>
|
|
||||||
<span class="sep">/</span>
|
|
||||||
<span class="digit">{{ globalConfig.heartbeatTimeout || 70 }}s</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="detail-collapse" @click="showDetail = !showDetail">
|
|
||||||
<span>{{ showDetail ? '收起全部配置 ▲' : '展开全部配置 ▼' }}</span>
|
|
||||||
</div>
|
|
||||||
<div v-show="showDetail" class="detail-panel">
|
|
||||||
<div class="form-row"><label>Server Address</label><input
|
|
||||||
v-model="globalConfig.serverAddr" /></div>
|
|
||||||
<div class="form-row"><label>Server Port</label><input type="number"
|
|
||||||
v-model="globalConfig.serverPort" /></div>
|
|
||||||
<div class="form-row"><label>Token</label><input type="password"
|
|
||||||
v-model="globalConfig.token" /></div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>Log Level</label>
|
|
||||||
<select v-model="globalConfig.logLevel">
|
|
||||||
<option value="trace">trace</option>
|
|
||||||
<option value="debug">debug</option>
|
|
||||||
<option value="info">info</option>
|
|
||||||
<option value="warn">warn</option>
|
|
||||||
<option value="error">error</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="form-row"><label>Log Max Days</label><input type="number"
|
|
||||||
v-model="globalConfig.logMaxDays" /></div>
|
|
||||||
<div class="form-row"><label>TCP Mux Keepalive</label><input type="number"
|
|
||||||
v-model="globalConfig.tcpMuxKeepalive" /></div>
|
|
||||||
<div class="form-row"><label>Heartbeat Interval</label><input type="number"
|
|
||||||
v-model="globalConfig.heartbeatInterval" /></div>
|
|
||||||
<div class="form-row"><label>Heartbeat Timeout</label><input type="number"
|
|
||||||
v-model="globalConfig.heartbeatTimeout" /></div>
|
|
||||||
<div class="form-row"><label>Pool Count</label><input type="number"
|
|
||||||
v-model="globalConfig.poolCount" /></div>
|
|
||||||
<button class="save-btn" @click="saveConfig">保存配置并热加载</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- ====== 隧道列表 ====== -->
|
<!-- ====== 隧道列表 ====== -->
|
||||||
<div v-else-if="activeTab === 'proxies'" class="tab-content">
|
<div v-if="activeTab === 'proxies'" class="tab-content">
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<div class="toolbar-left">
|
<div class="toolbar-left">
|
||||||
<button class="btn-import" @click="triggerImport">导入 TOML</button>
|
<button class="btn-import" @click="triggerImport">导入 TOML</button>
|
||||||
@@ -245,6 +158,187 @@
|
|||||||
<div v-if="filteredProxies.length === 0" class="empty-state">暂无隧道,点击「新增隧道」添加</div>
|
<div v-if="filteredProxies.length === 0" class="empty-state">暂无隧道,点击「新增隧道」添加</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- ====== 全局配置信息 ====== -->
|
||||||
|
<!-- ====== 全局配置信息 ====== -->
|
||||||
|
<div v-if="activeTab === 'config'" class="tab-content config-tab-content">
|
||||||
|
<!-- 页面标题 -->
|
||||||
|
<div class="config-page-header">
|
||||||
|
<h2>全局配置信息</h2>
|
||||||
|
<p class="config-subtitle">管理 frpc 连接参数与传输设置</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 首次使用提示 -->
|
||||||
|
<div v-if="showDefaultTip" class="config-tip">
|
||||||
|
首次使用请修改「服务器地址」和「认证令牌」为您的真实 frpc 配置
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ===== 账户管理 ===== -->
|
||||||
|
<div class="profile-section">
|
||||||
|
<div class="profile-header">
|
||||||
|
<span>账户管理</span>
|
||||||
|
<span class="profile-username">{{ loginForm.username }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="profile-form">
|
||||||
|
<div class="form-row">
|
||||||
|
<label>当前密码</label>
|
||||||
|
<input v-model="passwordChange.oldPassword" type="password" placeholder="输入当前密码" />
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label>新密码</label>
|
||||||
|
<input v-model="passwordChange.newPassword" type="password"
|
||||||
|
placeholder="至少8位,含大小写/数字/特殊字符" />
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label>确认新密码</label>
|
||||||
|
<input v-model="passwordChange.confirmPassword" type="password"
|
||||||
|
placeholder="再次输入新密码" />
|
||||||
|
</div>
|
||||||
|
<button class="save-btn" @click="changePassword">修改密码</button>
|
||||||
|
<p v-if="passwordChangeError" class="login-error">{{ passwordChangeError }}</p>
|
||||||
|
<p v-if="passwordChangeSuccess" class="login-success">{{ passwordChangeSuccess }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ===== 卡片1: 服务器连接 ===== -->
|
||||||
|
<div class="config-card">
|
||||||
|
<div class="config-card-header">
|
||||||
|
<span class="card-title">服务器连接</span>
|
||||||
|
</div>
|
||||||
|
<div class="config-card-body">
|
||||||
|
<div class="form-row">
|
||||||
|
<label>服务器地址</label>
|
||||||
|
<input v-model="globalConfig.serverAddr" placeholder="例如: frp.example.com" />
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label>服务器端口</label>
|
||||||
|
<input type="number" v-model="globalConfig.serverPort" placeholder="7000" />
|
||||||
|
</div>
|
||||||
|
<div class="form-row" style="grid-column: 1 / -1;">
|
||||||
|
<label>认证令牌</label>
|
||||||
|
<div class="token-input-wrapper">
|
||||||
|
<input :type="showToken ? 'text' : 'password'" v-model="globalConfig.token"
|
||||||
|
placeholder="CHANGE_ME" />
|
||||||
|
<button class="token-toggle-btn" @click="showToken = !showToken">
|
||||||
|
{{ showToken ? '隐藏' : '显示' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ===== 卡片2: 传输配置 ===== -->
|
||||||
|
<div class="config-card">
|
||||||
|
<div class="config-card-header">
|
||||||
|
<span class="card-title">传输配置</span>
|
||||||
|
</div>
|
||||||
|
<div class="config-card-body">
|
||||||
|
<!-- TCP 多路复用(只读,占满一行) -->
|
||||||
|
<div class="form-row" style="grid-column: 1 / -1;">
|
||||||
|
<label>TCP 多路复用</label>
|
||||||
|
<div class="readonly-value">
|
||||||
|
<span class="status-dot active"></span>
|
||||||
|
<span class="status-text active">已强制开启</span>
|
||||||
|
<span class="hint-text">优化连接性能,减少延迟,frp 官方推荐开启</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- 保活间隔 -->
|
||||||
|
<div class="form-row">
|
||||||
|
<label>保活间隔(秒)</label>
|
||||||
|
<input type="number" v-model="globalConfig.tcpMuxKeepalive" />
|
||||||
|
</div>
|
||||||
|
<!-- 心跳间隔 -->
|
||||||
|
<div class="form-row">
|
||||||
|
<label>心跳间隔(秒)</label>
|
||||||
|
<input type="number" v-model="globalConfig.heartbeatInterval" />
|
||||||
|
</div>
|
||||||
|
<!-- 心跳超时 -->
|
||||||
|
<div class="form-row">
|
||||||
|
<label>心跳超时(秒)</label>
|
||||||
|
<input type="number" v-model="globalConfig.heartbeatTimeout" />
|
||||||
|
</div>
|
||||||
|
<!-- 连接池大小 -->
|
||||||
|
<div class="form-row">
|
||||||
|
<label>连接池大小(个)</label>
|
||||||
|
<input type="number" v-model="globalConfig.poolCount" />
|
||||||
|
</div>
|
||||||
|
<!-- v2 协议开关(v1.5 灰标禁用) -->
|
||||||
|
<div class="form-row v2-switch-row">
|
||||||
|
<label>frp v2 隧道支持</label>
|
||||||
|
<div class="v2-switch-wrapper">
|
||||||
|
<label class="switch disabled">
|
||||||
|
<input type="checkbox" v-model="globalConfig.wireProtocolV2" />
|
||||||
|
<span class="slider"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<span class="hint-text v2-hint">
|
||||||
|
此功能为 frp 0.70.0 以上版本才能开启,若要打开必须搭配同版本 frpc 使用,否则此功能不生效
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ===== 卡片3: 日志配置 ===== -->
|
||||||
|
<div class="config-card">
|
||||||
|
<div class="config-card-header">
|
||||||
|
<span class="card-title">日志配置</span>
|
||||||
|
</div>
|
||||||
|
<div class="config-card-body">
|
||||||
|
<div class="form-row">
|
||||||
|
<label>日志级别</label>
|
||||||
|
<select v-model="globalConfig.logLevel">
|
||||||
|
<option value="trace">trace</option>
|
||||||
|
<option value="debug">debug</option>
|
||||||
|
<option value="info">info</option>
|
||||||
|
<option value="warn">warn</option>
|
||||||
|
<option value="error">error</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label>日志保留天数(天)</label>
|
||||||
|
<input type="number" v-model="globalConfig.logMaxDays" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 保存按钮 -->
|
||||||
|
<button class="save-config-btn" @click="saveConfig">保存配置并热加载</button>
|
||||||
|
</div>
|
||||||
|
<!-- ====== 运行日志 ====== -->
|
||||||
|
<div v-else-if="activeTab === 'logs'" class="tab-content log-tab-content">
|
||||||
|
<!-- 工具栏 -->
|
||||||
|
<div class="log-toolbar">
|
||||||
|
<div class="log-toolbar-left">
|
||||||
|
<span class="log-info-badge">共 {{ logTotal }} 行</span>
|
||||||
|
<span v-if="logError" class="log-error-badge">{{ logError }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="log-toolbar-right">
|
||||||
|
<label class="log-auto-scroll-label">
|
||||||
|
<input type="checkbox" v-model="logAutoScroll" />
|
||||||
|
自动滚动
|
||||||
|
</label>
|
||||||
|
<button class="log-btn" @click="refreshLogs">刷新</button>
|
||||||
|
<button class="log-btn" @click="scrollLogToBottom">↓ 滚动到底部</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 日志显示区域 -->
|
||||||
|
<div class="log-terminal" id="logContainer">
|
||||||
|
<div v-if="logLines.length === 0 && !logError" class="log-empty">
|
||||||
|
暂无日志,frpc 尚未产生输出
|
||||||
|
</div>
|
||||||
|
<div v-else class="log-lines">
|
||||||
|
<div v-for="(line, idx) in logLines" :key="idx" class="log-line">{{ line }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 底部状态 -->
|
||||||
|
<div class="log-footer">
|
||||||
|
<span>上次更新: {{ logLastUpdate || '--:--:--' }}</span>
|
||||||
|
<span class="log-polling-status">自动刷新中 (8s)</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+85
-132
@@ -1,4 +1,4 @@
|
|||||||
/* ===== style-3.css - 主界面 ===== */
|
/* ===== style-3.css - 主界面核心 ===== */
|
||||||
|
|
||||||
/* ---------- 顶部导航 ---------- */
|
/* ---------- 顶部导航 ---------- */
|
||||||
.top-bar {
|
.top-bar {
|
||||||
@@ -145,130 +145,6 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------- 全局配置页 ---------- */
|
|
||||||
.config-grid {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(3, 1fr);
|
|
||||||
gap: 16px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.metric-card {
|
|
||||||
background: var(--bg-metric);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 16px 20px;
|
|
||||||
border: 1px solid var(--border-subtle);
|
|
||||||
}
|
|
||||||
|
|
||||||
.metric-label {
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-dim);
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 1px;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.metric-value {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.big-number {
|
|
||||||
font-size: 28px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.unit {
|
|
||||||
font-size: 14px;
|
|
||||||
color: var(--text-dim);
|
|
||||||
}
|
|
||||||
|
|
||||||
.digit {
|
|
||||||
font-family: 'JetBrains Mono', monospace;
|
|
||||||
font-size: 18px;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sep {
|
|
||||||
color: var(--text-dim);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------- 展开详情 ---------- */
|
|
||||||
.detail-collapse {
|
|
||||||
padding: 12px 0;
|
|
||||||
color: var(--text-dim);
|
|
||||||
font-size: 13px;
|
|
||||||
cursor: pointer;
|
|
||||||
user-select: none;
|
|
||||||
transition: color 0.3s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.detail-collapse:hover {
|
|
||||||
color: var(--text-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.detail-panel {
|
|
||||||
background: rgba(255, 255, 255, 0.02);
|
|
||||||
border-radius: 12px;
|
|
||||||
padding: 16px 20px;
|
|
||||||
border: 1px solid var(--border-subtle);
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
gap: 12px 24px;
|
|
||||||
margin-bottom: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.detail-panel .form-row {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.detail-panel .form-row label {
|
|
||||||
font-size: 11px;
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 0.5px;
|
|
||||||
color: var(--text-dim);
|
|
||||||
}
|
|
||||||
|
|
||||||
.detail-panel .form-row input,
|
|
||||||
.detail-panel .form-row select {
|
|
||||||
padding: 8px 12px;
|
|
||||||
background: rgba(255, 255, 255, 0.04);
|
|
||||||
border: 1px solid var(--border-subtle);
|
|
||||||
border-radius: 8px;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 14px;
|
|
||||||
outline: none;
|
|
||||||
transition: border-color 0.3s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.detail-panel .form-row input:focus,
|
|
||||||
.detail-panel .form-row select:focus {
|
|
||||||
border-color: var(--primary-blue-border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.save-btn {
|
|
||||||
grid-column: 1 / -1;
|
|
||||||
padding: 10px 24px;
|
|
||||||
background: linear-gradient(135deg, var(--primary-blue), #2a5adf);
|
|
||||||
border: none;
|
|
||||||
border-radius: 10px;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: #0a0a0f;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: transform 0.2s, box-shadow 0.2s;
|
|
||||||
margin-top: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.save-btn:hover {
|
|
||||||
transform: scale(1.01);
|
|
||||||
box-shadow: 0 4px 16px var(--primary-blue-glow);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------- 账户管理区域 ---------- */
|
/* ---------- 账户管理区域 ---------- */
|
||||||
.profile-section {
|
.profile-section {
|
||||||
background: rgba(255, 255, 255, 0.02);
|
background: rgba(255, 255, 255, 0.02);
|
||||||
@@ -329,13 +205,6 @@
|
|||||||
border-color: var(--primary-blue-border);
|
border-color: var(--primary-blue-border);
|
||||||
}
|
}
|
||||||
|
|
||||||
.profile-form .save-btn {
|
|
||||||
grid-column: auto;
|
|
||||||
padding: 8px 20px;
|
|
||||||
margin-top: 0;
|
|
||||||
height: 40px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.login-success {
|
.login-success {
|
||||||
color: #63e2b7;
|
color: #63e2b7;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
@@ -344,6 +213,57 @@
|
|||||||
min-height: 24px;
|
min-height: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------- 统一保存按钮 ---------- */
|
||||||
|
.save-btn,
|
||||||
|
.save-config-btn {
|
||||||
|
padding: 10px 24px;
|
||||||
|
background: linear-gradient(135deg, var(--primary-blue), #2a5adf);
|
||||||
|
border: none;
|
||||||
|
border-radius: 10px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #0a0a0f;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: filter 0.3s ease;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 6px;
|
||||||
|
/* 确保按钮本身不裁切阴影 */
|
||||||
|
isolation: isolate;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-btn:hover,
|
||||||
|
.save-config-btn:hover {
|
||||||
|
filter: brightness(1.25);
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-btn:active,
|
||||||
|
.save-config-btn:active {
|
||||||
|
filter: brightness(0.9);
|
||||||
|
transform: scale(0.97);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 账户管理中的修改密码按钮(覆盖尺寸) */
|
||||||
|
.profile-form .save-btn {
|
||||||
|
grid-column: auto;
|
||||||
|
padding: 8px 20px;
|
||||||
|
margin-top: 0;
|
||||||
|
height: 40px;
|
||||||
|
font-size: 13px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 保存配置按钮全宽(在全局配置页使用) */
|
||||||
|
.save-config-btn {
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 8px;
|
||||||
|
padding: 12px;
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------- 隧道列表 ---------- */
|
/* ---------- 隧道列表 ---------- */
|
||||||
.toolbar {
|
.toolbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -782,3 +702,36 @@ select:disabled {
|
|||||||
transform: scale(1) translateY(0);
|
transform: scale(1) translateY(0);
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------- 响应式调整 ---------- */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.profile-form {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
.proxy-list {
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
|
.toolbar {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
.toolbar-right .search-input {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.proxy-list {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
.top-left .nav-logo {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
}
|
||||||
|
.brand-info .logo-text {
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
.dialog-card {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,327 @@
|
|||||||
|
/* ===== style-4.css - v1.5 新增样式 ===== */
|
||||||
|
|
||||||
|
/* ---------- 配置页面 ---------- */
|
||||||
|
.config-tab-content {
|
||||||
|
padding-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-page-header {
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
.config-page-header h2 {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-primary);
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
.config-subtitle {
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 首次使用提示 */
|
||||||
|
.config-tip {
|
||||||
|
background: rgba(255, 200, 50, 0.08);
|
||||||
|
border: 1px solid rgba(255, 200, 50, 0.15);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px 16px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #f0c040;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- 配置卡片 ---------- */
|
||||||
|
.config-card {
|
||||||
|
background: rgba(255, 255, 255, 0.02);
|
||||||
|
border: 1px solid var(--border-subtle);
|
||||||
|
border-radius: 14px;
|
||||||
|
padding: 16px 20px;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
border-bottom: 1px solid var(--border-subtle);
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
.card-title {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-card-body {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 12px 24px;
|
||||||
|
}
|
||||||
|
.config-card-body .form-row {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
.config-card-body .form-row label {
|
||||||
|
font-size: 11px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
}
|
||||||
|
.config-card-body .form-row input,
|
||||||
|
.config-card-body .form-row select {
|
||||||
|
padding: 8px 12px;
|
||||||
|
background: rgba(255, 255, 255, 0.04);
|
||||||
|
border: 1px solid var(--border-subtle);
|
||||||
|
border-radius: 8px;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 14px;
|
||||||
|
outline: none;
|
||||||
|
transition: border-color 0.3s;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.config-card-body .form-row input:focus,
|
||||||
|
.config-card-body .form-row select:focus {
|
||||||
|
border-color: var(--primary-blue-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 数字输入框填满列宽 */
|
||||||
|
.config-card-body .form-row input[type="number"] {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 只读行(TCP Mux) */
|
||||||
|
.readonly-value {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
background: rgba(255, 255, 255, 0.02);
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
.readonly-value .status-dot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #63e2b7;
|
||||||
|
box-shadow: 0 0 10px rgba(99, 226, 183, 0.3);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.readonly-value .status-text.active {
|
||||||
|
color: #63e2b7;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
.readonly-value .hint-text {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Token 输入框 + 显示按钮 */
|
||||||
|
.token-input-wrapper {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.token-input-wrapper input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.token-toggle-btn {
|
||||||
|
padding: 8px 16px;
|
||||||
|
background: rgba(255, 255, 255, 0.06);
|
||||||
|
border: 1px solid var(--border-subtle);
|
||||||
|
border-radius: 8px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.token-toggle-btn:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- v2 协议开关(灰标禁用) ---------- */
|
||||||
|
.v2-switch-row {
|
||||||
|
grid-column: 1 / -1 !important;
|
||||||
|
padding-top: 4px;
|
||||||
|
border-top: 1px solid var(--border-subtle);
|
||||||
|
margin-top: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.v2-switch-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 14px;
|
||||||
|
padding: 6px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* "即将推出" 徽章 */
|
||||||
|
.v2-badge {
|
||||||
|
font-size: 11px;
|
||||||
|
padding: 2px 12px;
|
||||||
|
background: rgba(255, 200, 50, 0.12);
|
||||||
|
border: 1px solid rgba(255, 200, 50, 0.15);
|
||||||
|
border-radius: 12px;
|
||||||
|
color: #f0c040;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.v2-badge.v2-enabled {
|
||||||
|
background: rgba(99, 226, 183, 0.12);
|
||||||
|
border-color: rgba(99, 226, 183, 0.2);
|
||||||
|
color: #63e2b7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.v2-hint {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
line-height: 1.5;
|
||||||
|
padding: 2px 0 4px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- 日志面板 ---------- */
|
||||||
|
.log-tab-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
min-height: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-toolbar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 8px 0 12px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
.log-toolbar-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
.log-toolbar-right {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-info-badge {
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
.log-error-badge {
|
||||||
|
font-size: 13px;
|
||||||
|
color: #f87171;
|
||||||
|
}
|
||||||
|
.log-auto-scroll-label {
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.log-auto-scroll-label input[type="checkbox"] {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
accent-color: var(--primary-blue);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-btn {
|
||||||
|
padding: 6px 14px;
|
||||||
|
background: rgba(255, 255, 255, 0.04);
|
||||||
|
border: 1px solid var(--border-subtle);
|
||||||
|
border-radius: 8px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.2s;
|
||||||
|
}
|
||||||
|
.log-btn:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 终端样式(类似命令行) */
|
||||||
|
.log-terminal {
|
||||||
|
flex: 1;
|
||||||
|
background: rgba(0, 0, 0, 0.6);
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid var(--border-subtle);
|
||||||
|
padding: 12px 16px;
|
||||||
|
overflow-y: auto;
|
||||||
|
font-family: 'JetBrains Mono', 'Consolas', monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.7;
|
||||||
|
min-height: 300px;
|
||||||
|
max-height: 500px;
|
||||||
|
}
|
||||||
|
.log-terminal::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
.log-terminal::-webkit-scrollbar-track {
|
||||||
|
background: rgba(255, 255, 255, 0.02);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
.log-terminal::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(74, 124, 255, 0.25);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
.log-terminal::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: rgba(74, 124, 255, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-lines {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.log-line {
|
||||||
|
color: #c0c0c0;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-all;
|
||||||
|
padding: 1px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-empty {
|
||||||
|
color: var(--text-dim);
|
||||||
|
text-align: center;
|
||||||
|
padding: 40px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 日志底部状态 */
|
||||||
|
.log-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 10px 4px 0;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.log-polling-status {
|
||||||
|
color: var(--primary-blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- 响应式调整 ---------- */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.config-card-body {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
.log-toolbar {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
.log-toolbar-right {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
.token-input-wrapper {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
.v2-switch-wrapper {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user