Files
Go-VPN-Client/internal/admin/admin_unix.go
arkonsadter d88139af1b feat(admin): add platform-specific admin privilege checks
- Upgrade Go version from 1.21 to 1.25.0
- Update golang.org/x/sys dependency to v0.42.0
- Add Unix/Linux admin check using os.Geteuid() with sudo requirement
- Add Windows admin check using windows.SID and token membership validation
- Integrate admin privilege validation into main CLI entry point
- Enhance monitor.go with graceful signal handling for Ctrl+C interrupts
- Add signal channels for clean shutdown of monitoring loop
- Ensures VPN client runs with required elevated privileges on both platforms
2026-04-06 19:06:03 +06:00

30 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// +build !windows
package admin
import (
"fmt"
"os"
)
// IsAdmin проверяет, запущено ли приложение с правами root
func IsAdmin() bool {
return os.Geteuid() == 0
}
// RequireAdmin проверяет права root и завершает программу, если их нет
func RequireAdmin() {
if !IsAdmin() {
fmt.Println("╔════════════════════════════════════════════════════════════╗")
fmt.Println("║ ⚠ ТРЕБУЮТСЯ ПРАВА ROOT ║")
fmt.Println("╚════════════════════════════════════════════════════════════╝")
fmt.Println()
fmt.Println("Это приложение требует прав root для работы с VPN.")
fmt.Println()
fmt.Println("Пожалуйста, запустите приложение с sudo:")
fmt.Println(" sudo ./vpn-client-cli")
fmt.Println()
os.Exit(1)
}
}