diff --git a/.gitignore b/.gitignore index 420a836ef..9a8f61861 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,4 @@ .gradle/ *.orig *.tmp - - +conf/config.json diff --git a/VERSION b/VERSION index 04b10b4f1..ebf14b469 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.7 +2.1.8 diff --git a/conf/SetMachineDnsServer.go b/conf/SetMachineDnsServer.go index 8ad96e385..49aafa534 100644 --- a/conf/SetMachineDnsServer.go +++ b/conf/SetMachineDnsServer.go @@ -13,7 +13,7 @@ func (hd *setMachineDNSServerHandler) process(line string, entryType DnsEntry) * switch entryType { case PROXY: - LOGGER.Infof("m=SetMachineDNSServer, status=found-dns-proxy-entry") + LOGGER.Infof("status=found-dns-proxy-entry") v := getDNSLine(hd.serverIP) return &v case SERVER: diff --git a/conf/conf.go b/conf/conf.go index a424b4aaf..74958d950 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -84,10 +84,10 @@ func GetString(value, defaultValue string) string { } func RestoreResolvconfToDefault() error { - LOGGER.Infof("m=RestoreResolvconfToDefault, status=begin") + LOGGER.Infof("status=begin") hd := newDNSServerCleanerHandler() err := ProcessResolvconf(hd) - LOGGER.Infof("m=RestoreResolvconfToDefault, status=success, err=%v", err) + LOGGER.Infof("status=success, err=%v", err) return err } @@ -99,7 +99,7 @@ func SetMachineDNSServer(serverIP string) error { func ProcessResolvconf( handler DnsHandler ) error { var newResolvConfBuff bytes.Buffer - LOGGER.Infof("m=ProcessResolvconf, status=begin") + LOGGER.Infof("status=begin") resolvconf := getResolvConf() fileRead, err := os.Open(resolvconf) @@ -112,7 +112,7 @@ func ProcessResolvconf( handler DnsHandler ) error { hasContent = false foundDnsProxyEntry = false ) - LOGGER.Infof("m=ProcessResolvconf, status=open-conf-file, file=%s", fileRead.Name()) + LOGGER.Infof("status=open-conf-file, file=%s", fileRead.Name()) scanner := bufio.NewScanner(fileRead) for scanner.Scan() { line := scanner.Text() @@ -121,7 +121,7 @@ func ProcessResolvconf( handler DnsHandler ) error { if entryType == PROXY { foundDnsProxyEntry = true } - LOGGER.Debugf("m=ProcessResolvconf, status=readline, line=%s, type=%s", line, entryType) + LOGGER.Debugf("status=readline, line=%s, type=%s", line, entryType) if r := handler.process(line, entryType); r != nil { newResolvConfBuff.WriteString(*r) newResolvConfBuff.WriteByte('\n') @@ -138,7 +138,7 @@ func ProcessResolvconf( handler DnsHandler ) error { if err != nil { return err } - LOGGER.Infof("m=ProcessResolvconf, status=success, buffLength=%d", length) + LOGGER.Infof("status=success, buffLength=%d", length) return nil } @@ -174,7 +174,7 @@ func SetCurrentDNSServerToMachineAndLockIt() error { func SetCurrentDNSServerToMachine() error { ip, err := getCurrentIpAddress() - LOGGER.Infof("m=SetCurrentDNSServerToMachine, status=begin, ip=%s, err=%v", ip, err) + LOGGER.Infof("status=begin, ip=%s, err=%v", ip, err) if err != nil { return err } @@ -191,7 +191,7 @@ func UnlockResolvConf() error { func LockFile(lock bool, file string) error { - LOGGER.Infof("m=Lockfile, status=begin, lock=%t, file=%s", lock, file) + LOGGER.Infof("status=begin, lock=%t, file=%s", lock, file) flag := "-i" if lock { flag = "+i" @@ -199,17 +199,17 @@ func LockFile(lock bool, file string) error { cmd := exec.Command("chattr", flag, file) err := cmd.Run() if err != nil { - LOGGER.Warningf("m=Lockfile, status=error-at-execute, lock=%t, file=%s, err=%v", lock, file, err) + LOGGER.Warningf("status=error-at-execute, lock=%t, file=%s, err=%v", lock, file, err) return err } //bytes, err := cmd.CombinedOutput() status := cmd.ProcessState.Sys().(syscall.WaitStatus) if status.ExitStatus() != 0 { - LOGGER.Warningf("m=Lockfile, status=bad-exit-code, lock=%t, file=%s", lock, file) + LOGGER.Warningf("status=bad-exit-code, lock=%t, file=%s", lock, file) return errors.New(fmt.Sprintf("Failed to lock file %d", status.ExitStatus())) } - LOGGER.Infof("m=Lockfile, status=success, lock=%t, file=%s", lock, file) + LOGGER.Infof("status=success, lock=%t, file=%s", lock, file) return nil } diff --git a/conf/config.sample.json b/conf/config.sample.json new file mode 100644 index 000000000..d662acc13 --- /dev/null +++ b/conf/config.sample.json @@ -0,0 +1,20 @@ +{ + "remoteDnsServers": [], + "envs": [ + { + "name": "", + "hostnames": [ + { + "id": 1, + "hostname": "github.com", + "ip": [192, 168, 0, 1], + "ttl": 255 + } + ] + } + ], + "activeEnv": "", + "lastId": 1, + "webServerPort": 0, + "dnsServerPort": 0 +} diff --git a/controller/main.go b/controller/main.go index a74ddfa64..7f3a89e45 100644 --- a/controller/main.go +++ b/controller/main.go @@ -72,19 +72,19 @@ func MapReq(method Method, path string, fn func(context.Context, http.ResponseWr ctx := log.NewContext() logger := log.NewLog(ctx) - logger.Debugf("m=MapReq, status=begin, matched=%t, url=%s, method=%s", matched, urlPath, r.Method) + logger.Debugf("status=begin, matched=%t, url=%s, method=%s", matched, urlPath, r.Method) if matched { function := maps[urlPath][r.Method] function(ctx, w, r, urlPath) - logger.Debugf("m=MapReq, status=success, url=%s %s", r.Method, urlPath) + logger.Debugf("status=success, url=%s %s", r.Method, urlPath) }else{ - logger.Debugf("m=MapReq, status=not-found, url=%s %s", r.Method, urlPath) + logger.Debugf("status=not-found, url=%s %s", r.Method, urlPath) http.NotFound(w, r) } }) } - LOGGER.Debugf("m=MapReq, status=mapping, url=%s %s", method, path) + LOGGER.Debugf("status=mapping, url=%s %s", method, path) maps[path][string(method)] = fn } diff --git a/docker-compose.yml b/docker-compose.yml index fb2d0c3cd..6cf38f7c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: - TERM=xterm - GOPATH=/app - MG_WORK_DIR=/app/src/github.com/mageddo/dns-proxy-server - hostname: gocompiler.dev + hostname: dns-proxy-server.dev network_mode: bridge diff --git a/events/docker/DockerEvents.go b/events/docker/DockerEvents.go index 79911d6e7..1dee92a0e 100644 --- a/events/docker/DockerEvents.go +++ b/events/docker/DockerEvents.go @@ -167,7 +167,7 @@ func putHostnames(ctx context.Context, hostnames []string, inspect types.Contain return errors.New(err) } } - logger.Debugf("m=putHostnames, host=%s, ip=%s", host, ip) + logger.Debugf("host=%s, ip=%s", host, ip) cache[host] = ip } return nil diff --git a/events/local/LocalEvents.go b/events/local/LocalEvents.go index 634214b28..bdfe8d50d 100644 --- a/events/local/LocalEvents.go +++ b/events/local/LocalEvents.go @@ -65,12 +65,12 @@ func LoadConfiguration(ctx context.Context){ func SaveConfiguration(ctx context.Context, c *LocalConfiguration) { logger := log.NewLog(ctx) - logger.Infof("m=SaveConfiguration, status=begin, time=%s", time.Now()) + logger.Infof("status=begin, time=%s", time.Now()) if len(c.Envs) == 0 { c.Envs = NewEmptyEnv() } - logger.Infof("m=SaveConfiguration, status=save") + logger.Infof("status=save") f, err := os.OpenFile(confPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777) defer func(){ f.Close() @@ -90,7 +90,7 @@ func SaveConfiguration(ctx context.Context, c *LocalConfiguration) { logger.Errorf("status=error-to-encode, error=%v", err) } - logger.Infof("m=SaveConfiguration, status=success") + logger.Infof("status=success") } @@ -147,7 +147,7 @@ func (lc *LocalConfiguration) GetEnv(envName string) (*EnvVo, int) { func (foundEnv *EnvVo) AddHostname(ctx context.Context, hostname *HostnameVo) error { logger := log.NewLog(ctx) - logger.Infof("m=AddHostnameToEnv, status=begin, env=%s, hostname=%+v", foundEnv.Name, hostname) + logger.Infof("status=begin, env=%s, hostname=%+v", foundEnv.Name, hostname) if foundEnv == nil { return errors.New("env not found") } @@ -211,36 +211,36 @@ func(env *EnvVo) GetHostnameById(id int) (*HostnameVo, int) { func (lc *LocalConfiguration) AddEnv(ctx context.Context, env EnvVo) error { logger := log.NewLog(ctx) - logger.Infof("m=AddEnv, status=begin, env=%s", env.Name) + logger.Infof("status=begin, env=%s", env.Name) foundEnv, _ := lc.GetEnv(env.Name) if foundEnv != nil { return errors.New(fmt.Sprintf("The '%s' env already exists", env.Name)) } lc.Envs = append(lc.Envs, env) SaveConfiguration(ctx, lc) - logger.Infof("m=AddEnv, status=success, env=%s", env.Name) + logger.Infof("status=success, env=%s", env.Name) return nil } func (lc *LocalConfiguration) RemoveEnvByName(ctx context.Context, name string) error { logger := log.NewLog(ctx) - logger.Infof("m=RemoveEnvByName, status=begin, env=%s", name) + logger.Infof("status=begin, env=%s", name) env, i := lc.GetEnv(name) if env == nil { return errors.New(fmt.Sprintf("The env '%s' was not found", name)) } lc.RemoveEnv(ctx, i) SaveConfiguration(ctx,lc) - logger.Infof("m=RemoveEnvByName, status=success, env=%s", name) + logger.Infof("status=success, env=%s", name) return nil } func (lc *LocalConfiguration) RemoveEnv(ctx context.Context, index int){ logger := log.NewLog(ctx) - logger.Infof("m=RemoveEnv, status=begin, index=%d", index) + logger.Infof("status=begin, index=%d", index) lc.Envs = append(lc.Envs[:index], lc.Envs[index+1:]...) SaveConfiguration(ctx,lc) - logger.Infof("m=RemoveEnv, status=success, index=%d", index) + logger.Infof("status=success, index=%d", index) } func (lc *LocalConfiguration) AddDns(ctx context.Context, dns [4]byte){ @@ -309,7 +309,7 @@ func (env *EnvVo) UpdateHostname(hostname HostnameVo) error { func (lc *LocalConfiguration) RemoveHostnameByEnvAndHostname(ctx context.Context, envName string, hostname string) error { logger := log.NewLog(ctx) - logger.Infof("m=RemoveHostnameByEnvAndHostname, status=begin, envName=%s, hostname=%s", envName, hostname) + logger.Infof("status=begin, envName=%s, hostname=%s", envName, hostname) env, envIndex := lc.GetEnv(envName) if envIndex == -1 { return errors.New("env not found") @@ -319,32 +319,32 @@ func (lc *LocalConfiguration) RemoveHostnameByEnvAndHostname(ctx context.Context return errors.New("hostname not found") } lc.RemoveHostname(ctx, envIndex, hostIndex) - logger.Infof("m=RemoveHostnameByEnvAndHostname, status=success, envName=%s, hostname=%s", envName, hostname) + logger.Infof("status=success, envName=%s, hostname=%s", envName, hostname) return nil } func (lc *LocalConfiguration) RemoveHostname(ctx context.Context, envIndex int, hostIndex int){ logger := log.NewLog(ctx) - logger.Infof("m=RemoveHostname, status=begin, envIndex=%d, hostIndex=%d", envIndex, hostIndex) + logger.Infof("status=begin, envIndex=%d, hostIndex=%d", envIndex, hostIndex) env := &lc.Envs[envIndex]; (*env).Hostnames = append((*env).Hostnames[:hostIndex], (*env).Hostnames[hostIndex+1:]...) SaveConfiguration(ctx, lc) - logger.Infof("m=RemoveHostname, status=success, envIndex=%d, hostIndex=%d", envIndex, hostIndex) + logger.Infof("status=success, envIndex=%d, hostIndex=%d", envIndex, hostIndex) } func (lc *LocalConfiguration) SetActiveEnv(ctx context.Context, env EnvVo) error { logger := log.NewLog(ctx) - logger.Infof("m=SetActiveEnv, status=begin, envActive=%s", env.Name) + logger.Infof("status=begin, envActive=%s", env.Name) foundEnv, _ := lc.GetEnv(env.Name) if foundEnv == nil { - logger.Warningf("m=SetActiveEnv, status=env-not-found, envName=%s", env.Name) + logger.Warningf("status=env-not-found, envName=%s", env.Name) return errors.New("Env not found: " + env.Name) } lc.ActiveEnv = env.Name SaveConfiguration(ctx, lc) - logger.Infof("m=SetActiveEnv, status=success") + logger.Infof("status=success") return nil } diff --git a/proxy/DockerDnsSolver.go b/proxy/DockerDnsSolver.go index 4a338a20f..1717b074a 100644 --- a/proxy/DockerDnsSolver.go +++ b/proxy/DockerDnsSolver.go @@ -19,7 +19,7 @@ func (DockerDnsSolver) Solve(ctx context.Context, question dns.Question) (*dns.M logger := log.NewLog(ctx) key := question.Name[:len(question.Name)-1] - logger.Debugf("m=solve, status=solved-key, solver=docker, hostname=%s, ip=%s", key, docker.Get(key)) + logger.Debugf("status=solved-key, solver=docker, hostname=%s, ip=%s", key, docker.Get(key)) if docker.ContainsKey(key) { ip := docker.Get(key) diff --git a/proxy/LocalDnsSolver.go b/proxy/LocalDnsSolver.go index 3a49c0311..5ed4c84b8 100644 --- a/proxy/LocalDnsSolver.go +++ b/proxy/LocalDnsSolver.go @@ -32,7 +32,7 @@ func (LocalDnsSolver) Solve(ctx context.Context, question dns.Question) (*dns.Ms m := new(dns.Msg) m.Answer = append(m.Answer, rr) - LOGGER.Infof("m=solve, status=success, solver=local") + LOGGER.Infof("status=success, solver=local") return m, nil } return nil, errors.New("hostname not found") diff --git a/service/service.go b/service/service.go index b9bdd5170..ebe5c2b27 100644 --- a/service/service.go +++ b/service/service.go @@ -75,7 +75,7 @@ func (sc *Service) SetupFor(servicePath, serviceName string, script *Script) err sc.logger.Fatalf("status=fatal-install-service, service=chkconfig, msg=%s", err.Error()) } } else { // not known - sc.logger.Warningf("m=ConfigSetupService, status=impossible to setup to start at boot") + sc.logger.Warningf("status=impossible to setup to start at boot") } out, err, _ := utils.Exec("service", serviceName, "stop") diff --git a/test/dnsserver.go b/test/dnsserver.go index 7f4b6ba43..48f52eb57 100644 --- a/test/dnsserver.go +++ b/test/dnsserver.go @@ -56,7 +56,7 @@ func handleReflect(respWriter dns.ResponseWriter, reqMsg *dns.Msg) { defer func() { err := recover() if err != nil { - LOGGER.Errorf("M=handleReflect, status=error, error=%v", err) + LOGGER.Errorf("status=error, error=%v", err) } }() @@ -67,7 +67,7 @@ func handleReflect(respWriter dns.ResponseWriter, reqMsg *dns.Msg) { questionName = "null" } - LOGGER.Infof("m=handleReflect, questions=%d, 1stQuestion=%s", len(reqMsg.Question), questionName) + LOGGER.Infof("questions=%d, 1stQuestion=%s", len(reqMsg.Question), questionName) resp := SolveName(questionName) resp.SetReply(reqMsg) @@ -79,7 +79,7 @@ func handleReflect(respWriter dns.ResponseWriter, reqMsg *dns.Msg) { firstAnswer = resp.Answer[0] } - LOGGER.Infof("m=handleReflect, resp=%v", firstAnswer) + LOGGER.Infof("resp=%v", firstAnswer) respWriter.WriteMsg(resp) } diff --git a/test/maintest.go b/test/maintest.go index cbdbf50f1..abada57b9 100644 --- a/test/maintest.go +++ b/test/maintest.go @@ -53,6 +53,6 @@ func (p *Person) addChild(name string) { func (p *Person) addChildByPointer(name string) { childs := p.getChilds() newChilds := append(*childs, name) - fmt.Printf("m=addChildByPointer, childs=%p, newChilds=%p\n", childs, &newChilds) + fmt.Printf("childs=%p, newChilds=%p\n", childs, &newChilds) childs = &newChilds -} \ No newline at end of file +} diff --git a/utils/exec.go b/utils/exec.go index c2a527ed3..788aba49e 100644 --- a/utils/exec.go +++ b/utils/exec.go @@ -9,14 +9,14 @@ import ( func Exec(cmd string, args ...string) ( out []byte, err error, exitCode int ){ - LOGGER.Infof("m=Exec, cmd=%s, args=%v", cmd, args) + LOGGER.Infof("cmd=%s, args=%v", cmd, args) execution := exec.Command(cmd, args...) // ja chama o run dentro dele out, err = execution.CombinedOutput() if err != nil { - LOGGER.Infof("m=Exec, status=error, type=%v, err=%v", reflect.TypeOf(err), err) + LOGGER.Infof("status=error, type=%v, err=%v", reflect.TypeOf(err), err) if exitError, ok := err.(*exec.ExitError); ok { exitCode = exitError.Sys().(syscall.WaitStatus).ExitStatus() return @@ -29,10 +29,10 @@ func Exec(cmd string, args ...string) ( out []byte, err error, exitCode int ){ } if exitCode != 0 { - LOGGER.Warningf("m=Exec, status=bad-exit-code, status=%d", exitCode) + LOGGER.Warningf("status=bad-exit-code, status=%d", exitCode) return } - LOGGER.Infof("m=Exec, status=success, cmd=%s", cmd) + LOGGER.Infof("status=success, cmd=%s", cmd) return } diff --git a/utils/exitcodes/exitcodes.go b/utils/exitcodes/exitcodes.go index 9b7459e83..4f77215bd 100644 --- a/utils/exitcodes/exitcodes.go +++ b/utils/exitcodes/exitcodes.go @@ -15,10 +15,10 @@ const ( ) func Exit(code int){ - LOGGER.Errorf("m=Exit, status=exiting, code=%d", code) + LOGGER.Errorf("status=exiting, code=%d", code) if code != SUCCESS { utils.Sig <- syscall.Signal(code) - LOGGER.Info("m=Exit, status=msg-posted") + LOGGER.Info("status=msg-posted") } else { os.Exit(code) } diff --git a/utils/utils.go b/utils/utils.go index ace07aad8..b39c469ed 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -161,7 +161,7 @@ func GetCurrentPath() string { return currDIr } currentPath, _ := filepath.Abs(filepath.Dir(os.Args[0])) - LOGGER.Infof("m=GetCurrentPath, currentPath=%s", currentPath) + LOGGER.Infof("currentPath=%s", currentPath) return currentPath }