feat(cli): add settings menu and VLESS log viewer with core selection
- Add settings menu to switch between Xray and V2Ray cores for VLESS connections - Implement core type persistence in configuration with LoadSettings/SaveSettings - Add VLESS error and access log viewer showing last 30 and 20 lines respectively - Display current core type and system time in main menu - Update VLESS connection to use selected core dynamically - Refactor monitor.go to accept 'q' key input for graceful exit instead of signal handling - Add proxy platform-specific implementations (proxy_unix.go, proxy_windows.go) - Add downloader module for managing binary resources - Include V2Ray and Xray configuration files and geodata (geoip.dat, geosite.dat) - Update CLI imports to include path/filepath and time packages - Improve user experience with core selection visibility and log diagnostics
This commit is contained in:
@@ -11,8 +11,10 @@ var (
|
||||
SubscriptionsFile string
|
||||
ConfigsFile string
|
||||
StateFile string
|
||||
SettingsFile string
|
||||
LogsDir string
|
||||
XrayDir string
|
||||
V2RayDir string
|
||||
)
|
||||
|
||||
type WireGuardConfig struct {
|
||||
@@ -51,6 +53,10 @@ type ConnectionState struct {
|
||||
LogFile string `json:"log_file"`
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
CoreType string `json:"core_type"` // "xray" или "v2ray"
|
||||
}
|
||||
|
||||
// Init инициализирует конфигурационные директории и файлы
|
||||
func Init() error {
|
||||
// Получаем рабочую директорию
|
||||
@@ -63,8 +69,10 @@ func Init() error {
|
||||
SubscriptionsFile = filepath.Join(ConfigDir, "subscriptions.json")
|
||||
ConfigsFile = filepath.Join(ConfigDir, "configs.json")
|
||||
StateFile = filepath.Join(ConfigDir, "state.json")
|
||||
SettingsFile = filepath.Join(ConfigDir, "settings.json")
|
||||
LogsDir = filepath.Join(workDir, "logs")
|
||||
XrayDir = filepath.Join(workDir, "xray")
|
||||
V2RayDir = filepath.Join(workDir, "v2ray")
|
||||
|
||||
// Создаем директории
|
||||
if err := os.MkdirAll(ConfigDir, 0755); err != nil {
|
||||
@@ -84,6 +92,9 @@ func Init() error {
|
||||
if err := initFileIfNotExists(StateFile, ConnectionState{}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := initFileIfNotExists(SettingsFile, Settings{CoreType: "xray"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -170,3 +181,32 @@ func SaveState(state *ConnectionState) error {
|
||||
}
|
||||
return os.WriteFile(StateFile, data, 0644)
|
||||
}
|
||||
|
||||
// LoadSettings загружает настройки
|
||||
func LoadSettings() (*Settings, error) {
|
||||
data, err := os.ReadFile(SettingsFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var settings Settings
|
||||
if err := json.Unmarshal(data, &settings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// По умолчанию xray
|
||||
if settings.CoreType == "" {
|
||||
settings.CoreType = "xray"
|
||||
}
|
||||
|
||||
return &settings, nil
|
||||
}
|
||||
|
||||
// SaveSettings сохраняет настройки
|
||||
func SaveSettings(settings *Settings) error {
|
||||
data, err := json.MarshalIndent(settings, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(SettingsFile, data, 0644)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user