Skip to content

Commit

Permalink
added setters and getters for geoip api to server, filter and transmi…
Browse files Browse the repository at this point in the history
…tter
  • Loading branch information
Wicwik committed Feb 16, 2023
1 parent 7e71383 commit 2c7120a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions fail2ban/server/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def __init__(self, jail, useDns='warn'):
## The ignore IP list.
self.__ignoreIpSet = set()
self.__ignoreIpList = []
# GEO-IP database api endpoint
self.__ignoreGeoApi = None
## The ignore GEO ip list.
self.__ignoreGeoSet = set()
## External command
Expand Down Expand Up @@ -546,6 +548,19 @@ def logIgnoreIp(self, ip, log_ignore, ignore_source="unknown source"):
def getIgnoreIP(self):
return self.__ignoreIpList + list(self.__ignoreIpSet)

def setIgnoreGEOAPI(self, api):
if api == "":
return

if self.__ignoreGeoApi:
logSys.log(logging.MSG, " GEO API was already set to %r and will be changed.", self.__ignoreGeoApi)

logSys.debug(" Set %r as GEO API endpoint", api)
self.__ignoreGeoApi = api

def getIgnoreGEOAPI(self):
return self.__ignoreGeoApi

def addIgnoreGEO(self, geo):
# An empty string is always false
if geo == "":
Expand Down
6 changes: 6 additions & 0 deletions fail2ban/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ def delIgnoreIP(self, name, ip):
def getIgnoreIP(self, name):
return self.__jails[name].filter.getIgnoreIP()

def setIgnoreGEOAPI(self, name, api):
self.__jails[name].filter.setIgnoreGEOAPI(api)

def getIgnoreGEOAPI(self, name):
self.__jails[name].filter.getIgnoreGEOAPI()

def addIgnoreGEO(self, name, geo):
self.__jails[name].filter.addIgnoreGEO(geo)

Expand Down
5 changes: 5 additions & 0 deletions fail2ban/server/transmitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ def __commandSet(self, command, multiple=False):
self.__server.delIgnoreIP(name, value)
if self.__quiet: return
return self.__server.getIgnoreIP(name)
elif command[1] == "setignoregeoapi":
for value in command[2:]:
self.__server.setIgnoreGEOAPI(name, value)
if self.__quiet: return
return self.__server.getIgnoreGEOAPI(name)
elif command[1] == "addignoregeo":
for value in command[2:]:
self.__server.addIgnoreGEO(name, value)
Expand Down

0 comments on commit 2c7120a

Please sign in to comment.