Unused shadowsocks code cleanup

This commit is contained in:
Quentin McGaw
2020-10-25 20:38:16 +00:00
parent f29707fa9f
commit 5ae7c15211
4 changed files with 6 additions and 59 deletions

View File

@@ -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)
}

View File

@@ -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.

View File

@@ -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)

View File

@@ -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",