Unused shadowsocks code cleanup
This commit is contained in:
@@ -10,14 +10,6 @@ func ColorTinyproxy() *color.Color {
|
|||||||
return color.New(color.FgHiGreen)
|
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 {
|
func ColorOpenvpn() *color.Color {
|
||||||
return color.New(color.FgHiMagenta)
|
return color.New(color.FgHiMagenta)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ const (
|
|||||||
NetRoute models.Filepath = "/proc/net/route"
|
NetRoute models.Filepath = "/proc/net/route"
|
||||||
// TinyProxyConf is the filepath to the tinyproxy configuration file.
|
// TinyProxyConf is the filepath to the tinyproxy configuration file.
|
||||||
TinyProxyConf models.Filepath = "/etc/tinyproxy/tinyproxy.conf"
|
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 is the filepath to the root.hints file used by Unbound.
|
||||||
RootHints models.Filepath = "/etc/unbound/root.hints"
|
RootHints models.Filepath = "/etc/unbound/root.hints"
|
||||||
// RootKey is the filepath to the root.key file used by Unbound.
|
// RootKey is the filepath to the root.key file used by Unbound.
|
||||||
|
|||||||
@@ -12,17 +12,13 @@ import (
|
|||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
var regularExpressions = struct { //nolint:gochecknoglobals
|
var regularExpressions = struct { //nolint:gochecknoglobals
|
||||||
unboundPrefix *regexp.Regexp
|
unboundPrefix *regexp.Regexp
|
||||||
shadowsocksPrefix *regexp.Regexp
|
tinyproxyLoglevel *regexp.Regexp
|
||||||
shadowsocksErrorPrefix *regexp.Regexp
|
tinyproxyPrefix *regexp.Regexp
|
||||||
tinyproxyLoglevel *regexp.Regexp
|
|
||||||
tinyproxyPrefix *regexp.Regexp
|
|
||||||
}{
|
}{
|
||||||
unboundPrefix: regexp.MustCompile(`unbound: \[[0-9]{10}\] unbound\[[0-9]+:0\] `),
|
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] `),
|
tinyproxyLoglevel: regexp.MustCompile(`INFO|CONNECT|NOTICE|WARNING|ERROR|CRITICAL`),
|
||||||
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] `),
|
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]+\]: `),
|
||||||
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) {
|
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 = fmt.Sprintf("unbound: %s", filtered)
|
||||||
filtered = constants.ColorUnbound().Sprintf(filtered)
|
filtered = constants.ColorUnbound().Sprintf(filtered)
|
||||||
return filtered, level
|
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: "):
|
case strings.HasPrefix(s, "tinyproxy: "):
|
||||||
logLevel := regularExpressions.tinyproxyLoglevel.FindString(s)
|
logLevel := regularExpressions.tinyproxyLoglevel.FindString(s)
|
||||||
prefix := regularExpressions.tinyproxyPrefix.FindString(s)
|
prefix := regularExpressions.tinyproxyPrefix.FindString(s)
|
||||||
|
|||||||
@@ -36,22 +36,6 @@ func Test_PostProcessLine(t *testing.T) {
|
|||||||
"unbound: [1594595249] unbound[75:0] BLA: init module 0: validator",
|
"unbound: [1594595249] unbound[75:0] BLA: init module 0: validator",
|
||||||
"unbound: BLA: init module 0: validator",
|
"unbound: BLA: init module 0: validator",
|
||||||
logging.ErrorLevel},
|
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": {
|
||||||
"tinyproxy: INFO Jul 12 23:07:25 [32]: Reloading config file",
|
"tinyproxy: INFO Jul 12 23:07:25 [32]: Reloading config file",
|
||||||
"tinyproxy: Reloading config file",
|
"tinyproxy: Reloading config file",
|
||||||
|
|||||||
Reference in New Issue
Block a user