Skip to content

Commit 9f3f221

Browse files
authored
version 1.1.1
Added work mode(blacklist/whitelist) for ipchecker. Now a few countries can be given for ip check
1 parent 83c4a4a commit 9f3f221

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

ipchecker.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
)
1010

11-
func isIpValid(site string, ip string, keyName string, value string) bool {
11+
func isIpValid(site string, ip string, keyName string, value []string, blacklist bool) bool {
1212
request := strings.Builder{}
1313
request.WriteString(site)
1414
request.WriteString(ip)
@@ -26,16 +26,27 @@ func isIpValid(site string, ip string, keyName string, value string) bool {
2626
var answer map[string]interface{}
2727
err := json.Unmarshal([]byte(body), &answer)
2828
if err != nil {
29-
fmt.Println("Ошибка при разборе JSON:", err)
29+
fmt.Println("Error while unmarshalling JSON:", err)
3030
return false
3131
}
3232
for key, val := range answer {
3333
if key == keyName {
34-
if val == value {
35-
return false
36-
} else {
34+
j := len(value)
35+
for i := range j {
36+
if val == value[i] {
37+
if blacklist {
38+
return false
39+
} else {
40+
fmt.Println("Country ", val)
41+
return true
42+
}
43+
}
44+
}
45+
if blacklist {
3746
fmt.Println("Country ", val)
3847
return true
48+
} else {
49+
return false
3950
}
4051
}
4152
}

sskeyparser.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ type Config struct {
3939
Links []Link
4040
IpCheckServer string
4141
IpCheckKey string
42-
IpCheckValue string
42+
IpCheckBlackList bool
43+
IpCheckValue []string
4344
}
4445

4546
type SsConfigs struct {
@@ -121,7 +122,8 @@ func createSsServerConfig(str string) (errstr string) { //, errcode int
121122
} else {
122123
conf.Server = spstr[:index]
123124
//check ip
124-
if !isIpValid(config.IpCheckServer, conf.Server, config.IpCheckKey, config.IpCheckValue) {
125+
if !isIpValid(config.IpCheckServer, conf.Server, config.IpCheckKey,
126+
config.IpCheckValue, config.IpCheckBlackList) {
125127
return "Ip is invalid"
126128
}
127129
//
@@ -398,6 +400,7 @@ func setSsServiceConfig(path string, middle []byte) bool {
398400
}
399401
}
400402
} else {
403+
fmt.Println("Ss config file not exists:")
401404
return false
402405
}
403406
return true

0 commit comments

Comments
 (0)