53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"git.e3t.cc/e3team/pancheri"
|
|
"github.com/miekg/dns"
|
|
"github.com/sirupsen/logrus"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
configPath := flag.String("config", "/etc/pancheri/config.yml", "Path to enter a file or directory to load configuration from")
|
|
printUsage := flag.Bool("help", false, "Print command line usage")
|
|
|
|
flag.Parse()
|
|
|
|
if *printUsage {
|
|
flag.Usage()
|
|
os.Exit(0)
|
|
}
|
|
|
|
c, err := pancheri.LoadConfig(*configPath)
|
|
|
|
if err != nil {
|
|
fmt.Printf("failed to load config: %s", err)
|
|
}
|
|
|
|
if c.Logging.Format == "json" {
|
|
logrus.SetFormatter(&logrus.JSONFormatter{})
|
|
}
|
|
logrus.SetLevel(c.Logging.Level)
|
|
|
|
logrus.WithFields(logrus.Fields{
|
|
"host": c.Server.Host,
|
|
"port": c.Server.Port,
|
|
}).Info("starting DNS listener")
|
|
|
|
var r *pancheri.Resolver
|
|
|
|
if c.Resolver.Enable {
|
|
logrus.WithFields(logrus.Fields{
|
|
"upstream": c.Resolver.Upstream,
|
|
}).Info("enabling upstream resolver")
|
|
|
|
r = pancheri.NewResolver(c.Resolver.Upstream)
|
|
err = r.Resolve("example.com", dns.TypeA)
|
|
if err != nil {
|
|
logrus.Errorf("failed to resolve: %s", err)
|
|
}
|
|
}
|
|
}
|