From 5ae7c1521130fe24700fb0e27c2fcb33ca3e2d02 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sun, 25 Oct 2020 20:38:16 +0000 Subject: [PATCH] Unused shadowsocks code cleanup --- internal/constants/colors.go | 8 ------- internal/constants/paths.go | 2 -- internal/logging/line.go | 39 ++++++----------------------------- internal/logging/line_test.go | 16 -------------- 4 files changed, 6 insertions(+), 59 deletions(-) diff --git a/internal/constants/colors.go b/internal/constants/colors.go index 5ae633f1..8ab1b7fe 100644 --- a/internal/constants/colors.go +++ b/internal/constants/colors.go @@ -10,14 +10,6 @@ func ColorTinyproxy() *color.Color { return color.New(color.FgHiGreen) } -func ColorShadowsocks() *color.Color { - return color.New(color.FgHiYellow) -} - -func ColorShadowsocksError() *color.Color { - return color.New(color.FgHiRed) -} - func ColorOpenvpn() *color.Color { return color.New(color.FgHiMagenta) } diff --git a/internal/constants/paths.go b/internal/constants/paths.go index 02682ee2..67e469b2 100644 --- a/internal/constants/paths.go +++ b/internal/constants/paths.go @@ -23,8 +23,6 @@ const ( NetRoute models.Filepath = "/proc/net/route" // TinyProxyConf is the filepath to the tinyproxy configuration file. TinyProxyConf models.Filepath = "/etc/tinyproxy/tinyproxy.conf" - // ShadowsocksConf is the filepath to the shadowsocks configuration file. - ShadowsocksConf models.Filepath = "/etc/shadowsocks.json" // RootHints is the filepath to the root.hints file used by Unbound. RootHints models.Filepath = "/etc/unbound/root.hints" // RootKey is the filepath to the root.key file used by Unbound. diff --git a/internal/logging/line.go b/internal/logging/line.go index cfd3e20d..031c386a 100644 --- a/internal/logging/line.go +++ b/internal/logging/line.go @@ -12,17 +12,13 @@ import ( //nolint:lll var regularExpressions = struct { //nolint:gochecknoglobals - unboundPrefix *regexp.Regexp - shadowsocksPrefix *regexp.Regexp - shadowsocksErrorPrefix *regexp.Regexp - tinyproxyLoglevel *regexp.Regexp - tinyproxyPrefix *regexp.Regexp + unboundPrefix *regexp.Regexp + tinyproxyLoglevel *regexp.Regexp + tinyproxyPrefix *regexp.Regexp }{ - unboundPrefix: regexp.MustCompile(`unbound: \[[0-9]{10}\] unbound\[[0-9]+:0\] `), - shadowsocksPrefix: regexp.MustCompile(`shadowsocks:[ ]+2[0-9]{3}\-[0-1][0-9]\-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] `), - shadowsocksErrorPrefix: regexp.MustCompile(`shadowsocks error:[ ]+2[0-9]{3}\-[0-1][0-9]\-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] `), - tinyproxyLoglevel: regexp.MustCompile(`INFO|CONNECT|NOTICE|WARNING|ERROR|CRITICAL`), - tinyproxyPrefix: regexp.MustCompile(`tinyproxy: .+[ ]+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] \[[0-9]+\]: `), + unboundPrefix: regexp.MustCompile(`unbound: \[[0-9]{10}\] unbound\[[0-9]+:0\] `), + tinyproxyLoglevel: regexp.MustCompile(`INFO|CONNECT|NOTICE|WARNING|ERROR|CRITICAL`), + tinyproxyPrefix: regexp.MustCompile(`tinyproxy: .+[ ]+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] \[[0-9]+\]: `), } func PostProcessLine(s string) (filtered string, level logging.Level) { @@ -82,29 +78,6 @@ func PostProcessLine(s string) (filtered string, level logging.Level) { filtered = fmt.Sprintf("unbound: %s", filtered) filtered = constants.ColorUnbound().Sprintf(filtered) return filtered, level - case strings.HasPrefix(s, "shadowsocks: "): - prefix := regularExpressions.shadowsocksPrefix.FindString(s) - filtered = s[len(prefix):] - switch { - case strings.HasPrefix(filtered, "INFO: "): - level = logging.InfoLevel - filtered = strings.TrimPrefix(filtered, "INFO: ") - default: - level = logging.WarnLevel - } - filtered = fmt.Sprintf("shadowsocks: %s", filtered) - filtered = constants.ColorShadowsocks().Sprintf(filtered) - return filtered, level - case strings.HasPrefix(s, "shadowsocks error: "): - if strings.Contains(s, "ERROR: unable to resolve") { // caused by DNS blocking - return "", logging.ErrorLevel - } - prefix := regularExpressions.shadowsocksErrorPrefix.FindString(s) - filtered = s[len(prefix):] - filtered = strings.TrimPrefix(filtered, "ERROR: ") - filtered = fmt.Sprintf("shadowsocks: %s", filtered) - filtered = constants.ColorShadowsocksError().Sprintf(filtered) - return filtered, logging.ErrorLevel case strings.HasPrefix(s, "tinyproxy: "): logLevel := regularExpressions.tinyproxyLoglevel.FindString(s) prefix := regularExpressions.tinyproxyPrefix.FindString(s) diff --git a/internal/logging/line_test.go b/internal/logging/line_test.go index 9c965310..6f6fb1cc 100644 --- a/internal/logging/line_test.go +++ b/internal/logging/line_test.go @@ -36,22 +36,6 @@ func Test_PostProcessLine(t *testing.T) { "unbound: [1594595249] unbound[75:0] BLA: init module 0: validator", "unbound: BLA: init module 0: validator", logging.ErrorLevel}, - "shadowsocks stdout info": { - "shadowsocks: 2020-07-12 23:07:25 INFO: UDP relay enabled", - "shadowsocks: UDP relay enabled", - logging.InfoLevel}, - "shadowsocks stdout other": { - "shadowsocks: 2020-07-12 23:07:25 BLABLA: UDP relay enabled", - "shadowsocks: BLABLA: UDP relay enabled", - logging.WarnLevel}, - "shadowsocks stderr": { - "shadowsocks error: 2020-07-12 23:07:25 Some error", - "shadowsocks: Some error", - logging.ErrorLevel}, - "shadowsocks stderr unable to resolve muted": { - "shadowsocks error: 2020-07-12 23:07:25 ERROR: unable to resolve", - "", - logging.ErrorLevel}, "tinyproxy info": { "tinyproxy: INFO Jul 12 23:07:25 [32]: Reloading config file", "tinyproxy: Reloading config file",