mirror of
https://github.com/TrezOne/docker-mods-uptime-kuma-timeout-fix.git
synced 2026-07-18 16:58:27 -04:00
Deprecate mod
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
# F2B Discord Notification - Docker mod which allows Fail2Ban Discord embeds
|
# F2B Discord Notification - Docker mod which allows Fail2Ban Discord embeds
|
||||||
|
|
||||||
|
>[!WARNING]
|
||||||
|
>This mod is deprecated
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
This mod enhances the swag container adding better Fail2Ban notifications for discord.
|
This mod enhances the swag container adding better Fail2Ban notifications for discord.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
@@ -36,3 +41,5 @@ Action arguments:
|
|||||||
## Example
|
## Example
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
<details/>
|
||||||
|
|||||||
@@ -1,98 +1,18 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import argparse
|
|
||||||
import collections
|
|
||||||
import datetime
|
|
||||||
import geoip2.database
|
|
||||||
import os
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
class Discord:
|
base = "https://discordapp.com/api/webhooks/"
|
||||||
def __init__(self, data, action):
|
token = os.getenv('DISC_HOOK', False)
|
||||||
self.action = action
|
you = os.getenv('DISC_ME', False)
|
||||||
self.base = "https://discordapp.com/api/webhooks/"
|
|
||||||
self.data = data
|
|
||||||
self.token = os.getenv('DISC_HOOK', "") # If not setting enviroment variables, edit this
|
|
||||||
self.you = os.getenv('DISC_ME', "120970603556503552") # If not setting enviroment variables, edit this
|
|
||||||
|
|
||||||
def create_payload(self):
|
content = f"<@{you}> "
|
||||||
webhook = {
|
message = "The fail2ban to discord mod is deprecated. Please remove it from your container"
|
||||||
"username":"Fail2Ban",
|
|
||||||
"content": f"<@{self.you}>",
|
|
||||||
"embeds": [{}]
|
|
||||||
}
|
|
||||||
webhook["embeds"][0]["author"] = {"name": "Fail2Ban"}
|
|
||||||
webhook["embeds"][0]["timestamp"] = f"{datetime.datetime.utcnow()}"
|
|
||||||
if "ban" in self.action.action:
|
|
||||||
webhook["embeds"][0]["url"] = f"https://db-ip.com/{self.data['ip']}"
|
|
||||||
webhook["embeds"][0]["image"] = {"url": f"{self.data['map-img']}"}
|
|
||||||
webhook["embeds"][0]["fields"] = [{}]
|
|
||||||
webhook["embeds"][0]["fields"][0]["name"] = f":flag_{self.data['iso'].lower()}:"
|
|
||||||
webhook["embeds"][0]["fields"][0]["value"] = self.data["city"] or self.data["name"]
|
|
||||||
if self.action.action == "ban":
|
|
||||||
webhook["embeds"][0]["fields"].append({"name": f"Map", "value": f"[Link]({self.data['map-url']})"})
|
|
||||||
webhook["embeds"][0]["fields"].append({"name": f"Unban cmd", "value": f"fail2ban-client unban {self.data['ip']}"})
|
|
||||||
webhook["embeds"][0]["title"] = f"New ban on `{self.action.jail}`"
|
|
||||||
webhook["embeds"][0]["description"] = f"**{self.data['ip']}** got banned for `{self.action.time}` hours after `{self.action.fail}` tries"
|
|
||||||
webhook["embeds"][0]["color"] = 16194076
|
|
||||||
elif self.action.action == "unban":
|
|
||||||
webhook["embeds"][0]["title"] = f"Revoked ban on `{self.action.jail}`"
|
|
||||||
webhook["embeds"][0]["description"] = f"**{self.data['ip']}** is now unbanned"
|
|
||||||
webhook["embeds"][0]["color"] = 845872
|
|
||||||
elif self.action.action == "start":
|
|
||||||
webhook["content"] = ""
|
|
||||||
webhook["embeds"][0]["description"] = f"Started `{self.action.jail}`"
|
|
||||||
webhook["embeds"][0]["color"] = 845872
|
|
||||||
elif self.action.action == "stopped":
|
|
||||||
webhook["content"] = ""
|
|
||||||
webhook["embeds"][0]["description"] = f"Stopped `{self.action.jail}`"
|
|
||||||
webhook["embeds"][0]["color"] = 16194076
|
|
||||||
elif self.action.action == "test":
|
|
||||||
webhook["content"] = ""
|
|
||||||
webhook["embeds"][0]["description"] = f"I am working"
|
|
||||||
webhook["embeds"][0]["color"] = 845872
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
return webhook
|
|
||||||
|
|
||||||
def send(self, payload):
|
webhook = {
|
||||||
r = requests.post(url=f"{self.base}{self.token}", json=payload)
|
"username":"Fail2Ban",
|
||||||
|
"content": content + message if you else message
|
||||||
|
}
|
||||||
|
|
||||||
class Helpers:
|
if token:
|
||||||
def __init__(self, ip):
|
requests.post(url=f"{base}{token}", json=webhook)
|
||||||
self.data = {"ip": ip}
|
|
||||||
self.map_api = os.getenv('DISC_API', "") # If not setting enviroment variables, edit this
|
|
||||||
self.reader = geoip2.database.Reader('/config/geoip2db/GeoLite2-City.mmdb')
|
|
||||||
self.f2b()
|
|
||||||
self.map()
|
|
||||||
|
|
||||||
def f2b(self):
|
|
||||||
r = self.reader.city(self.data['ip'])
|
|
||||||
self.data["iso"] = r.country.iso_code
|
|
||||||
self.data["name"] = r.country.name
|
|
||||||
self.data["city"] = r.city.name
|
|
||||||
self.data["lat"] = r.location.latitude
|
|
||||||
self.data["lon"] = r.location.longitude
|
|
||||||
|
|
||||||
|
|
||||||
def map(self):
|
|
||||||
img_params={"center":f"{self.data['lat']},{self.data['lon']}", "size":"500,300", "key": self.map_api}
|
|
||||||
img_r = requests.get('https://www.mapquestapi.com/staticmap/v5/map', params=img_params)
|
|
||||||
self.data["map-img"] = img_r.url
|
|
||||||
url_params={"center":f"{self.data['lat']},{self.data['lon']}", "size":"500,300"}
|
|
||||||
url_r = requests.get('https://mapquest.com/', params=url_params)
|
|
||||||
self.data["map-url"] = url_r.url
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
parser = argparse.ArgumentParser(description='Discord notifier for F2B')
|
|
||||||
parser.add_argument('-a', '--action', help="Which F2B action triggered the script", required=True)
|
|
||||||
parser.add_argument('-i', '--ip', help="ip which triggered the action", default="8.8.8.8")
|
|
||||||
parser.add_argument('-j', '--jail', help="jail which triggered the action")
|
|
||||||
parser.add_argument('-t', '--time', help="The time the action is valid")
|
|
||||||
parser.add_argument('-f', '--fail', help="Amount of attempts done")
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
data = Helpers(args.ip).data if "ban" in args.action else {}
|
|
||||||
disc = Discord(data, args)
|
|
||||||
if (payload := disc.create_payload()):
|
|
||||||
disc.send(payload)
|
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
#!/usr/bin/with-contenv bash
|
#!/usr/bin/with-contenv bash
|
||||||
|
echo "_ _ _ "
|
||||||
|
echo "| | | |"
|
||||||
|
echo "| | | | The f2b to discord mod is deprecated"
|
||||||
|
echo "|_|_|_|"
|
||||||
|
echo "(_|_|_)"
|
||||||
|
|
||||||
|
|
||||||
if ! pip list 2>&1 | grep -q "geoip2"; then
|
if ! pip list 2>&1 | grep -q "requests"; then
|
||||||
echo '------------------------------------------------------------------------'
|
echo '------------------------------------------------------------------------'
|
||||||
echo '| Adding required modules for swag-f2bdiscord to package install list'
|
echo '| Adding required modules for swag-f2bdiscord deprecation message'
|
||||||
echo '------------------------------------------------------------------------'
|
echo '------------------------------------------------------------------------'
|
||||||
echo "\
|
echo "requests" >> /mod-pip-packages-to-install.list
|
||||||
requests \
|
fi
|
||||||
argparse \
|
|
||||||
geoip2==3.0.0" >> /mod-pip-packages-to-install.list
|
if [ ! -f /config/fail2ban/Fail2Ban.py.orig ] && [ -f /config/fail2ban/Fail2Ban.py ]; then
|
||||||
|
mv /config/fail2ban/Fail2Ban.py /config/fail2ban/Fail2Ban.py.orig
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f /config/fail2ban/Fail2Ban.py ]; then
|
if [ ! -f /config/fail2ban/Fail2Ban.py ]; then
|
||||||
@@ -15,6 +22,3 @@ if [ ! -f /config/fail2ban/Fail2Ban.py ]; then
|
|||||||
chmod +x /config/fail2ban/Fail2Ban.py
|
chmod +x /config/fail2ban/Fail2Ban.py
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f /config/fail2ban/action.d/discordEmbed.conf ]; then
|
|
||||||
cp /AwesomeFolder/discordEmbed.conf /config/fail2ban/action.d
|
|
||||||
fi
|
|
||||||
|
|||||||
Reference in New Issue
Block a user