- 新增竞速拨号器(racedial.go):域名连接时并行解析所有A/AAAA记录, 同时对所有IP发起TCP连接,第一个成功的胜出,确保选择延迟最低的地址 - ServerProfile新增IPPreference字段(auto/v4/v6),支持用户指定IP版本偏好 - 填写服务器IP时跳过域名解析直接使用IP,顺序failover - 连接成功后状态栏显示「已连接 (域名 -> 实际IP)」 - DB迁移v6:server_profiles表添加ip_preference列 - WebSocket拨号与HTTP登录均使用竞速拨号器 - 补充中英文i18n翻译
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
//go:build darwin
|
|
|
|
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"lmvpn/internal/log"
|
|
)
|
|
|
|
const daemonBinaryName = "lmvpnd"
|
|
|
|
// launchElevated launches the daemon-launch subcommand with admin
|
|
// privileges via osascript on macOS.
|
|
func launchElevated(exe, daemonBin, home string, uid, gid int) error {
|
|
script := fmt.Sprintf(
|
|
`do shell script %q with administrator privileges`,
|
|
fmt.Sprintf("%s daemon-launch --user-home %s --uid %d --gid %d --daemon-bin %s",
|
|
shellQuote(exe), shellQuote(home), uid, gid, shellQuote(daemonBin)),
|
|
)
|
|
cmd := exec.Command("osascript", "-e", script)
|
|
if out, err := cmd.CombinedOutput(); err != nil {
|
|
return fmt.Errorf("launch daemon: %w (output: %s)", err, string(out))
|
|
}
|
|
log.L().Info("daemon launched via osascript",
|
|
"uid", uid, "gid", gid, "home", home, "daemon_bin", daemonBin)
|
|
return nil
|
|
}
|
|
|
|
// shellQuote wraps a string in single quotes for shell safety.
|
|
// Embedded single quotes are escaped using the '\” pattern.
|
|
func shellQuote(s string) string {
|
|
result := "'"
|
|
for _, r := range s {
|
|
if r == '\'' {
|
|
result += "'\\''"
|
|
} else {
|
|
result += string(r)
|
|
}
|
|
}
|
|
result += "'"
|
|
return result
|
|
}
|