This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tips:fail2ban [2019/04/15 08:20] – [telegram action] scipio | tips:fail2ban [2019/04/15 09:04] (current) – [telegram action] scipio | ||
|---|---|---|---|
| Line 22: | Line 22: | ||
| fail2ban-regex / | fail2ban-regex / | ||
| </ | </ | ||
| + | |||
| + | ===== action ===== | ||
| + | |||
| + | <file ini action.d/ | ||
| + | [Definition] | ||
| + | actionstart = / | ||
| + | actionstop = / | ||
| + | actioncheck = | ||
| + | actionban = / | ||
| + | actionunban = | ||
| + | |||
| + | [Init] | ||
| + | init = ' | ||
| + | </ | ||
| ===== jail ===== | ===== jail ===== | ||
| Line 34: | Line 48: | ||
| bantime = 6000 | bantime = 6000 | ||
| maxretry = 3 | maxretry = 3 | ||
| + | action = %(action_)s | ||
| + | | ||
| </ | </ | ||
| Line 63: | Line 79: | ||
| ===== telegram action ===== | ===== telegram action ===== | ||
| - | <file bash / | + | <code> |
| - | # | + | pip install telegram-send |
| - | + | </code> | |
| - | # Sends text messages using Telegram | + | |
| - | # to alert webmaster of banning. | + | |
| - | + | ||
| - | # Require one argument, one of the following | + | |
| - | # start | + | |
| - | # stop | + | |
| - | # ban | + | |
| - | # unban | + | |
| - | # Optional second argument: Ip for ban/unband | + | |
| - | + | ||
| - | + | ||
| - | # Display usage information | + | |
| - | function show_usage { | + | |
| - | echo " | + | |
| - | echo "Where action start, stop, ban, unban" | + | |
| - | echo "and IP is optional passed to ban, unban" | + | |
| - | exit | + | |
| - | } | + | |
| + | create configuration file with token and chat id | ||
| + | <file ini / | ||
| + | [telegram] | ||
| + | chat_id = | ||
| + | token = | ||
| + | </ | ||
| - | # Send notification | + | test (-g option to use /etc/telegram-send.con) |
| - | function send_msg { | + | < |
| - | apiToken= | + | telegram-send -g " |
| - | chatId= | + | </code> |
| - | url=" | + | |
| - | curl -s -X POST $url -d chat_id=$chatId -d text=" | ||
| - | exit | ||
| - | } | ||
| - | # Check for script arguments | ||
| - | if [ $# -lt 1 ] | ||
| - | then | ||
| - | show_usage | ||
| - | fi | ||
| - | |||
| - | |||
| - | # Take action depending on argument | ||
| - | if [ " | ||
| - | then | ||
| - | msg=' | ||
| - | send_msg $msg | ||
| - | elif [ " | ||
| - | then | ||
| - | msg=' | ||
| - | send_msg $msg | ||
| - | elif [ " | ||
| - | then | ||
| - | msg=$([ " | ||
| - | send_msg $msg | ||
| - | elif [ " | ||
| - | then | ||
| - | msg=$([ " | ||
| - | send_msg $msg | ||
| - | else | ||
| - | show_usage | ||
| - | fi | ||
| - | |||
| - | </ | ||