mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-16 10:22:45 +00:00
This commit add the ability for ctrld to gather client information, including mac/ip/hostname, and send to Control-D server through a config per upstream. - Add send_client_info upstream config. - Read/Watch dnsmasq leases files on supported platforms. - Add corresponding client info to DoH query header All of these only apply for Control-D upstream, though.
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package router
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
const (
|
|
ubiosDNSMasqConfigPath = "/run/dnsmasq.conf.d/zzzctrld.conf"
|
|
)
|
|
|
|
func setupUbiOS() error {
|
|
// Disable dnsmasq as DNS server.
|
|
dnsMasqConfigContent, err := dnsMasqConf()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := os.WriteFile(ubiosDNSMasqConfigPath, []byte(dnsMasqConfigContent), 0600); err != nil {
|
|
return err
|
|
}
|
|
// Restart dnsmasq service.
|
|
if err := ubiosRestartDNSMasq(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func cleanupUbiOS() error {
|
|
// Remove the custom dnsmasq config
|
|
if err := os.Remove(ubiosDNSMasqConfigPath); err != nil {
|
|
return err
|
|
}
|
|
// Restart dnsmasq service.
|
|
if err := ubiosRestartDNSMasq(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func postInstallUbiOS() error {
|
|
return nil
|
|
}
|
|
|
|
func ubiosRestartDNSMasq() error {
|
|
buf, err := os.ReadFile("/run/dnsmasq.pid")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pid, err := strconv.ParseUint(string(bytes.TrimSpace(buf)), 10, 64)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
proc, err := os.FindProcess(int(pid))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return proc.Kill()
|
|
}
|