2019-04-10 13:18:05 +02:00
|
|
|
package respondd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/data"
|
|
|
|
"github.com/FreifunkBremen/yanic/lib/duration"
|
|
|
|
)
|
|
|
|
|
|
|
|
func trim(s string) string {
|
|
|
|
return strings.TrimSpace(strings.Trim(s, "\n"))
|
|
|
|
}
|
|
|
|
|
|
|
|
type Daemon struct {
|
|
|
|
DataInterval duration.Duration `toml:"data_interval"`
|
|
|
|
Listen []struct {
|
|
|
|
Address string `toml:"address"`
|
|
|
|
Interface string `toml:"interface"`
|
|
|
|
Port int `toml:"port"`
|
|
|
|
} `toml:"listen"`
|
2019-04-10 21:57:31 +02:00
|
|
|
|
|
|
|
Batman []string `toml:"batman"`
|
|
|
|
Babel string `toml:"babel"`
|
2019-04-10 13:18:05 +02:00
|
|
|
|
|
|
|
dataByInterface map[string]*data.ResponseData
|
|
|
|
|
|
|
|
Answer *AnswerConfig `toml:"defaults"`
|
|
|
|
AnswerByZones map[string]*AnswerConfig `toml:"zones"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AnswerConfig struct {
|
2019-04-10 20:09:55 +02:00
|
|
|
NodeID string `toml:"node_id"`
|
|
|
|
Hostname string `toml:"hostname"`
|
|
|
|
SiteCode string `toml:"site_code"`
|
|
|
|
DomainCode string `toml:"domain_code"`
|
|
|
|
Location *data.Location `json:"location,omitempty"`
|
|
|
|
VPN bool `toml:"vpn"`
|
2019-04-10 13:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Daemon) getAnswer(iface string) (*AnswerConfig, string) {
|
|
|
|
config := d.Answer
|
|
|
|
if v, ok := d.AnswerByZones[iface]; iface == "" && ok {
|
|
|
|
config = v
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeID := config.NodeID
|
|
|
|
if nodeID == "" {
|
|
|
|
if v, err := ioutil.ReadFile("/etc/machine-id"); err == nil {
|
|
|
|
nodeID = trim(string(v))[:12]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return config, nodeID
|
|
|
|
}
|