From e0110c558e70dc507fd8ba746cf3a1a5dfc4e7a7 Mon Sep 17 00:00:00 2001 From: Andrey Egorov Date: Mon, 29 Jul 2024 15:17:00 +0300 Subject: [PATCH] Fixed internet connection errors. All right but still cannot establish connection. --- Dockerfile | 1 + api/modem/internet/ic.go | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index c5f7750..23e0d70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ COPY ./ ./ RUN go mod download RUN apt-get update +RUN apt-get install -y iputils-ping RUN apt-get install -y ppp RUN apt-get install -y net-tools diff --git a/api/modem/internet/ic.go b/api/modem/internet/ic.go index 52005ec..d197394 100644 --- a/api/modem/internet/ic.go +++ b/api/modem/internet/ic.go @@ -12,7 +12,7 @@ import ( ) var apns = map[string]string{ - "tinkoff": "m.tinkoff", + "Tinkoff": "m.tinkoff", } const pppConfigName = "annalistnet" @@ -132,7 +132,7 @@ func (c *conn) ConfigurePPP() error { config := fmt.Sprintf(pppConfig, apn, c.port.GetName(), c.port.GetBaudrate()) // Write to file - f, err := os.OpenFile("etc/ppp/pears/"+pppConfigName, os.O_CREATE, 0666) + f, err := os.OpenFile("/etc/ppp/peers/"+pppConfigName, os.O_CREATE | os.O_WRONLY, 0666) if err != nil { return fmt.Errorf("open ppp config file %w", err) } @@ -175,7 +175,7 @@ func (c *conn) connect() error { if err != nil { return fmt.Errorf("execute connect cmd: %w", err) } - c.logger.Println("DEBUG pon response:", resp) + c.logger.Println("DEBUG pon response:", string(resp)) return nil } @@ -184,7 +184,7 @@ func (c *conn) diconnect() error { if err != nil { return fmt.Errorf("execute disconnect cmd: %w", err) } - c.logger.Println("DEBUG poff response:", resp) + c.logger.Println("DEBUG poff response:", string(resp)) return nil } @@ -205,7 +205,7 @@ func (c *conn) Init() error { if err != nil { return fmt.Errorf("execute ifconfig cmd: %w", err) } - c.logger.Println("DEBUG ifconfig resp:", resp) + c.logger.Println("DEBUG ifconfig resp:", string(resp)) // Test connectin using Ping c.logger.Println("Test...") @@ -218,11 +218,18 @@ func (c *conn) Init() error { func (c *conn) Ping() bool { // Test - try to connect to Google DNS // ping -I ppp0 8.8.8.8 - resp, err := exec.Command("ping", "-I", "ppp0", "8.8.8.8").Output() + resp, err := exec.Command("ping", "8.8.8.8").Output() if err != nil { - c.logger.Println("Ping cmd error:", err) + c.logger.Println("Ping 1 cmd error:", err) } - c.logger.Println("Ping resp:", resp) + c.logger.Println("Ping 1 resp:", string(resp)) + + resp, err = exec.Command("ping", "-I", "ppp0", "8.8.8.8").Output() + if err != nil { + c.logger.Println("Ping 2 cmd error:", err) + } + c.logger.Println("Ping 2 resp:", string(resp)) + return !strings.Contains(string(resp), "Destination Host Unreachable") // tmp solution }