Release 1.8.0: auto-update with restart and AmneziaWG 2.0 support.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -13,6 +13,7 @@ type Protocol string
|
||||
const (
|
||||
ProtocolNaive Protocol = "naive"
|
||||
ProtocolHysteria2 Protocol = "hysteria2"
|
||||
ProtocolAWG Protocol = "awg"
|
||||
)
|
||||
|
||||
// Config is the top-level client configuration.
|
||||
@@ -181,8 +182,8 @@ func (c *Config) Validate() error {
|
||||
return fmt.Errorf("config: profile[%d] missing name", i)
|
||||
}
|
||||
switch p.Protocol {
|
||||
case ProtocolNaive, ProtocolHysteria2:
|
||||
// Proxy may be empty until the user pastes a share link in the UI.
|
||||
case ProtocolNaive, ProtocolHysteria2, ProtocolAWG:
|
||||
// Proxy may be empty until the user pastes a share link / conf in the UI.
|
||||
case "":
|
||||
c.Profiles[i].Protocol = ProtocolNaive
|
||||
default:
|
||||
|
||||
@@ -2,12 +2,17 @@ package config
|
||||
|
||||
import "strings"
|
||||
|
||||
// DetectProtocol infers protocol from a share/proxy URI.
|
||||
// DetectProtocol infers protocol from a share/proxy URI or config body.
|
||||
func DetectProtocol(raw string) Protocol {
|
||||
lower := strings.ToLower(strings.TrimSpace(raw))
|
||||
switch {
|
||||
case strings.HasPrefix(lower, "hysteria2://"), strings.HasPrefix(lower, "hy2://"):
|
||||
return ProtocolHysteria2
|
||||
case strings.HasPrefix(lower, "awg://"), strings.HasPrefix(lower, "amneziawg://"),
|
||||
strings.HasPrefix(lower, "wireguard://"):
|
||||
return ProtocolAWG
|
||||
case strings.Contains(lower, "[interface]") && strings.Contains(lower, "privatekey"):
|
||||
return ProtocolAWG
|
||||
case strings.HasPrefix(lower, "naive+"), strings.HasPrefix(lower, "naive://"),
|
||||
strings.HasPrefix(lower, "https://"), strings.HasPrefix(lower, "quic://"),
|
||||
strings.HasPrefix(lower, "http://"):
|
||||
|
||||
@@ -34,6 +34,21 @@ func proxyHost(proxy string) string {
|
||||
if proxy == "" {
|
||||
return ""
|
||||
}
|
||||
lower := strings.ToLower(proxy)
|
||||
if strings.Contains(lower, "[interface]") {
|
||||
for _, line := range strings.Split(proxy, "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if len(line) >= 9 && strings.EqualFold(line[:8], "endpoint") {
|
||||
_, val, ok := strings.Cut(line, "=")
|
||||
if !ok {
|
||||
_, val, ok = strings.Cut(line, ":")
|
||||
}
|
||||
if ok {
|
||||
return strings.TrimSpace(val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if i := strings.Index(proxy, "://"); i >= 0 {
|
||||
proxy = proxy[i+3:]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user