platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
90
selective-vpn-api/app/dns_settings_state_smartdns.go
Normal file
90
selective-vpn-api/app/dns_settings_state_smartdns.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
dnscfgpkg "selective-vpn-api/app/dnscfg"
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// EN: `smartDNSAddr` contains core logic for smart d n s addr.
|
||||
// RU: `smartDNSAddr` - содержит основную логику для smart d n s addr.
|
||||
// ---------------------------------------------------------------------
|
||||
func smartDNSAddr() string {
|
||||
return loadDNSMode().SmartDNSAddr
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// EN: `smartDNSForced` contains core logic for smart d n s forced.
|
||||
// RU: `smartDNSForced` - содержит основную логику для smart d n s forced.
|
||||
// ---------------------------------------------------------------------
|
||||
func smartDNSForced() bool {
|
||||
return dnscfgpkg.SmartDNSForced(os.Getenv(smartDNSForceEnv))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// EN: `smartdnsUnitState` contains core logic for smartdns unit state.
|
||||
// RU: `smartdnsUnitState` - содержит основную логику для smartdns unit state.
|
||||
// ---------------------------------------------------------------------
|
||||
func smartdnsUnitState() string {
|
||||
return dnscfgpkg.UnitState(runCommand, "smartdns-local.service")
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// EN: `runSmartdnsUnitAction` runs the workflow for smartdns unit action.
|
||||
// RU: `runSmartdnsUnitAction` - запускает рабочий процесс для smartdns unit action.
|
||||
// ---------------------------------------------------------------------
|
||||
func runSmartdnsUnitAction(action string) cmdResult {
|
||||
res := dnscfgpkg.RunUnitAction(runCommand, "smartdns-local.service", action)
|
||||
msg := res.Message
|
||||
if res.OK {
|
||||
msg = "smartdns " + strings.TrimSpace(action) + " done"
|
||||
}
|
||||
return cmdResult{
|
||||
OK: res.OK,
|
||||
ExitCode: res.ExitCode,
|
||||
Stdout: res.Stdout,
|
||||
Stderr: res.Stderr,
|
||||
Message: msg,
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// EN: `resolveDefaultSmartDNSAddr` resolves default smart d n s addr into concrete values.
|
||||
// RU: `resolveDefaultSmartDNSAddr` - резолвит default smart d n s addr в конкретные значения.
|
||||
// ---------------------------------------------------------------------
|
||||
func resolveDefaultSmartDNSAddr() string {
|
||||
return dnscfgpkg.ResolveDefaultSmartDNSAddr(
|
||||
os.Getenv(smartDNSAddrEnv),
|
||||
[]string{
|
||||
"/opt/stack/adguardapp/smartdns.conf",
|
||||
"/etc/selective-vpn/smartdns.conf",
|
||||
},
|
||||
smartDNSDefaultAddr,
|
||||
)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// EN: `smartDNSAddrFromConfig` loads smart d n s addr from config.
|
||||
// RU: `smartDNSAddrFromConfig` - загружает smart d n s addr из конфига.
|
||||
// ---------------------------------------------------------------------
|
||||
func smartDNSAddrFromConfig(path string) string {
|
||||
return dnscfgpkg.SmartDNSAddrFromConfig(path)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// EN: `normalizeDNSUpstream` parses dns upstream and returns normalized values.
|
||||
// RU: `normalizeDNSUpstream` - парсит dns upstream и возвращает нормализованные значения.
|
||||
// ---------------------------------------------------------------------
|
||||
func normalizeDNSUpstream(raw string, defaultPort string) string {
|
||||
return dnscfgpkg.NormalizeDNSUpstream(raw, defaultPort)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// EN: `normalizeSmartDNSAddr` parses smart d n s addr and returns normalized values.
|
||||
// RU: `normalizeSmartDNSAddr` - парсит smart d n s addr и возвращает нормализованные значения.
|
||||
// ---------------------------------------------------------------------
|
||||
func normalizeSmartDNSAddr(raw string) string {
|
||||
return dnscfgpkg.NormalizeSmartDNSAddr(raw)
|
||||
}
|
||||
Reference in New Issue
Block a user