|
@@ -1,8 +1,10 @@
|
|
-package geodb
|
|
|
|
|
|
+package access
|
|
|
|
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"strings"
|
|
"strings"
|
|
|
|
+
|
|
|
|
+ "imuslab.com/zoraxy/mod/netutils"
|
|
)
|
|
)
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -25,7 +27,7 @@ type WhitelistEntry struct {
|
|
|
|
|
|
//Geo Whitelist
|
|
//Geo Whitelist
|
|
|
|
|
|
-func (s *Store) AddCountryCodeToWhitelist(countryCode string, comment string) {
|
|
|
|
|
|
+func (s *AccessRule) AddCountryCodeToWhitelist(countryCode string, comment string) {
|
|
countryCode = strings.ToLower(countryCode)
|
|
countryCode = strings.ToLower(countryCode)
|
|
entry := WhitelistEntry{
|
|
entry := WhitelistEntry{
|
|
EntryType: EntryType_CountryCode,
|
|
EntryType: EntryType_CountryCode,
|
|
@@ -33,22 +35,22 @@ func (s *Store) AddCountryCodeToWhitelist(countryCode string, comment string) {
|
|
Comment: comment,
|
|
Comment: comment,
|
|
}
|
|
}
|
|
|
|
|
|
- s.sysdb.Write("whitelist-cn", countryCode, entry)
|
|
|
|
|
|
+ s.GetDatabase().Write(s.GetFullTableName("whitelist-cn"), countryCode, entry)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Store) RemoveCountryCodeFromWhitelist(countryCode string) {
|
|
|
|
|
|
+func (s *AccessRule) RemoveCountryCodeFromWhitelist(countryCode string) {
|
|
countryCode = strings.ToLower(countryCode)
|
|
countryCode = strings.ToLower(countryCode)
|
|
- s.sysdb.Delete("whitelist-cn", countryCode)
|
|
|
|
|
|
+ s.GetDatabase().Delete(s.GetFullTableName("whitelist-cn"), countryCode)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Store) IsCountryCodeWhitelisted(countryCode string) bool {
|
|
|
|
|
|
+func (s *AccessRule) IsCountryCodeWhitelisted(countryCode string) bool {
|
|
countryCode = strings.ToLower(countryCode)
|
|
countryCode = strings.ToLower(countryCode)
|
|
- return s.sysdb.KeyExists("whitelist-cn", countryCode)
|
|
|
|
|
|
+ return s.GetDatabase().KeyExists(s.GetFullTableName("whitelist-cn"), countryCode)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Store) GetAllWhitelistedCountryCode() []*WhitelistEntry {
|
|
|
|
|
|
+func (s *AccessRule) GetAllWhitelistedCountryCode() []*WhitelistEntry {
|
|
whitelistedCountryCode := []*WhitelistEntry{}
|
|
whitelistedCountryCode := []*WhitelistEntry{}
|
|
- entries, err := s.sysdb.ListTable("whitelist-cn")
|
|
|
|
|
|
+ entries, err := s.GetDatabase().ListTable(s.GetFullTableName("whitelist-cn"))
|
|
if err != nil {
|
|
if err != nil {
|
|
return whitelistedCountryCode
|
|
return whitelistedCountryCode
|
|
}
|
|
}
|
|
@@ -63,22 +65,22 @@ func (s *Store) GetAllWhitelistedCountryCode() []*WhitelistEntry {
|
|
|
|
|
|
//IP Whitelist
|
|
//IP Whitelist
|
|
|
|
|
|
-func (s *Store) AddIPToWhiteList(ipAddr string, comment string) {
|
|
|
|
|
|
+func (s *AccessRule) AddIPToWhiteList(ipAddr string, comment string) {
|
|
thisIpEntry := WhitelistEntry{
|
|
thisIpEntry := WhitelistEntry{
|
|
EntryType: EntryType_IP,
|
|
EntryType: EntryType_IP,
|
|
IP: ipAddr,
|
|
IP: ipAddr,
|
|
Comment: comment,
|
|
Comment: comment,
|
|
}
|
|
}
|
|
|
|
|
|
- s.sysdb.Write("whitelist-ip", ipAddr, thisIpEntry)
|
|
|
|
|
|
+ s.GetDatabase().Write(s.GetFullTableName("whitelist-ip"), ipAddr, thisIpEntry)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Store) RemoveIPFromWhiteList(ipAddr string) {
|
|
|
|
- s.sysdb.Delete("whitelist-ip", ipAddr)
|
|
|
|
|
|
+func (s *AccessRule) RemoveIPFromWhiteList(ipAddr string) {
|
|
|
|
+ s.GetDatabase().Delete(s.GetFullTableName("whitelist-ip"), ipAddr)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Store) IsIPWhitelisted(ipAddr string) bool {
|
|
|
|
- isWhitelisted := s.sysdb.KeyExists("whitelist-ip", ipAddr)
|
|
|
|
|
|
+func (s *AccessRule) IsIPWhitelisted(ipAddr string) bool {
|
|
|
|
+ isWhitelisted := s.GetDatabase().KeyExists(s.GetFullTableName("whitelist-ip"), ipAddr)
|
|
if isWhitelisted {
|
|
if isWhitelisted {
|
|
//single IP whitelist entry
|
|
//single IP whitelist entry
|
|
return true
|
|
return true
|
|
@@ -87,12 +89,12 @@ func (s *Store) IsIPWhitelisted(ipAddr string) bool {
|
|
//Check for IP wildcard and CIRD rules
|
|
//Check for IP wildcard and CIRD rules
|
|
AllWhitelistedIps := s.GetAllWhitelistedIpAsStringSlice()
|
|
AllWhitelistedIps := s.GetAllWhitelistedIpAsStringSlice()
|
|
for _, whitelistRules := range AllWhitelistedIps {
|
|
for _, whitelistRules := range AllWhitelistedIps {
|
|
- wildcardMatch := MatchIpWildcard(ipAddr, whitelistRules)
|
|
|
|
|
|
+ wildcardMatch := netutils.MatchIpWildcard(ipAddr, whitelistRules)
|
|
if wildcardMatch {
|
|
if wildcardMatch {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
|
|
|
|
- cidrMatch := MatchIpCIDR(ipAddr, whitelistRules)
|
|
|
|
|
|
+ cidrMatch := netutils.MatchIpCIDR(ipAddr, whitelistRules)
|
|
if cidrMatch {
|
|
if cidrMatch {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
@@ -101,9 +103,9 @@ func (s *Store) IsIPWhitelisted(ipAddr string) bool {
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Store) GetAllWhitelistedIp() []*WhitelistEntry {
|
|
|
|
|
|
+func (s *AccessRule) GetAllWhitelistedIp() []*WhitelistEntry {
|
|
whitelistedIp := []*WhitelistEntry{}
|
|
whitelistedIp := []*WhitelistEntry{}
|
|
- entries, err := s.sysdb.ListTable("whitelist-ip")
|
|
|
|
|
|
+ entries, err := s.GetDatabase().ListTable(s.GetFullTableName("whitelist-ip"))
|
|
if err != nil {
|
|
if err != nil {
|
|
return whitelistedIp
|
|
return whitelistedIp
|
|
}
|
|
}
|
|
@@ -118,7 +120,7 @@ func (s *Store) GetAllWhitelistedIp() []*WhitelistEntry {
|
|
return whitelistedIp
|
|
return whitelistedIp
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Store) GetAllWhitelistedIpAsStringSlice() []string {
|
|
|
|
|
|
+func (s *AccessRule) GetAllWhitelistedIpAsStringSlice() []string {
|
|
allWhitelistedIPs := []string{}
|
|
allWhitelistedIPs := []string{}
|
|
entries := s.GetAllWhitelistedIp()
|
|
entries := s.GetAllWhitelistedIp()
|
|
for _, entry := range entries {
|
|
for _, entry := range entries {
|