Files
gluetun/internal/openvpn/logs.go

99 lines
2.7 KiB
Go
Raw Normal View History

2021-01-26 04:17:22 +00:00
package openvpn
import (
"strings"
"github.com/fatih/color"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/golibs/logging"
)
func (l *looper) collectLines(stdout, stderr <-chan string, done chan<- struct{}) {
defer close(done)
2021-01-26 04:17:22 +00:00
var line string
var ok, errLine bool
for {
errLine = false
select {
case line, ok = <-stdout:
case line, ok = <-stderr:
errLine = true
}
if !ok {
return
}
line, level := processLogLine(line)
2021-07-23 17:39:38 +00:00
if line == "" {
2021-01-26 04:17:22 +00:00
continue // filtered out
}
if errLine {
level = logging.LevelError
2021-01-26 04:17:22 +00:00
}
switch level {
case logging.LevelDebug:
2021-01-26 04:17:22 +00:00
l.logger.Debug(line)
case logging.LevelInfo:
2021-01-26 04:17:22 +00:00
l.logger.Info(line)
case logging.LevelWarn:
2021-01-26 04:17:22 +00:00
l.logger.Warn(line)
case logging.LevelError:
2021-01-26 04:17:22 +00:00
l.logger.Error(line)
}
if strings.Contains(line, "Initialization Sequence Completed") {
l.tunnelReady <- struct{}{}
}
}
}
func processLogLine(s string) (filtered string, level logging.Level) {
for _, ignored := range []string{
"WARNING: you are using user/group/chroot/setcon without persist-tun -- this may cause restarts to fail",
"NOTE: UID/GID downgrade will be delayed because of --client, --pull, or --up-delay",
} {
if s == ignored {
return "", logging.LevelDebug
2021-01-26 04:17:22 +00:00
}
}
switch {
case strings.HasPrefix(s, "NOTE: "):
filtered = strings.TrimPrefix(s, "NOTE: ")
level = logging.LevelInfo
2021-01-26 04:17:22 +00:00
case strings.HasPrefix(s, "WARNING: "):
filtered = strings.TrimPrefix(s, "WARNING: ")
level = logging.LevelWarn
2021-01-26 04:17:22 +00:00
case strings.HasPrefix(s, "Options error: "):
filtered = strings.TrimPrefix(s, "Options error: ")
level = logging.LevelError
2021-01-26 04:17:22 +00:00
case s == "Initialization Sequence Completed":
return color.HiGreenString(s), logging.LevelInfo
2021-01-26 04:17:22 +00:00
case s == "AUTH: Received control message: AUTH_FAILED":
filtered = s + `
Your credentials might be wrong 🤨
`
level = logging.LevelError
2021-01-26 01:09:09 +00:00
case strings.Contains(s, "TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)"): //nolint:lll
filtered = s + `
2021-01-26 04:17:22 +00:00
🚒🚒🚒🚒🚒🚨🚨🚨🚨🚨🚨🚒🚒🚒🚒🚒
That error usually happens because either:
1. The VPN server IP address you are trying to connect to is no longer valid 🔌
Update your server information using https://github.com/qdm12/gluetun/wiki/Updating-Servers
2. The VPN server crashed 💥, try changing your VPN servers filtering options such as REGION
3. Your Internet connection is not working 🤯, ensure it works
4. Something else https://github.com/qdm12/gluetun/issues/new/choose
`
level = logging.LevelWarn
2021-01-26 04:17:22 +00:00
default:
filtered = s
level = logging.LevelInfo
2021-01-26 04:17:22 +00:00
}
filtered = constants.ColorOpenvpn().Sprintf(filtered)
return filtered, level
}