-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
98 lines (85 loc) · 2.68 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#-- install script for apiban-fail2ban
echo ""
echo ""
echo " need support? https://palner.com and https://lod.com"
echo ""
echo " Copyright (C) 2024 The Palner Group, Inc. (palner.com)"
echo ""
echo " apiban-fail2ban is free software; you can redistribute it and/or modify"
echo " it under the terms of the GNU General Public License as published by"
echo " the Free Software Foundation; either version 2 of the License, or"
echo " (at your option) any later version"
echo ""
echo " apiban-fail2ban is distributed in the hope that it will be useful,"
echo " but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo " GNU General Public License for more details."
echo ""
echo " You should have received a copy of the GNU General Public License"
echo " along with this program; if not, write to the Free Software"
echo " Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA"
echo ""
#-- functions
usage() {
cat << _EOF_
Usage: ${0} APIBANKEY
...with APIBANKEY being your... apiban api key. ;)
If you need a key, please visit https://apiban.org
_EOF_
}
echo "-> checking variables"
#-- check arguments and environment
if [ "$#" -ne "1" ]; then
echo "Expected 1 argument, got $#" >&2
usage
exit 2
fi
APIKEY=$1
echo "-> creating apiban directory and downloading client"
mkdir /usr/local/bin/apiban
cd /usr/local/bin/apiban
wget https://github.com/apiban/apiban-fail2ban/raw/v.0.0.1/apiban-fail2ban &>/dev/null
if [ "$?" -eq "0" ]
then
echo " -o downloaded"
else
echo " -x download FAILED!!"
exit 1
fi
echo "-> setting configuration to use your apikey"
echo "{\"apikey\":\"$APIKEY\",\"lkid\":\"100\",\"version\":\"v0.0.1\",\"set\":\"all\",\"flush\":\"200\",\"jail\":\"asterisk-iptables\"}" > config.json
chmod +x /usr/local/bin/apiban/apiban-fail2ban
echo "-> setting log rotation"
cat > /etc/logrotate.d/apiban-client << EOF
/var/log/apiban-client.log {
daily
copytruncate
rotate 7
compress
}
EOF
echo "-> setting up service"
cat > /lib/systemd/system/apiban-fail2ban.service << EOF
[Unit]
Description=APIBAN blocker for fail2ban
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/apiban/apiban-fail2ban
[Install]
WantedBy=multi-user.target
EOF
cat > /lib/systemd/system/apiban-fail2ban.timer << EOF
[Unit]
Description=APIBan fail2ban service schedule
[Timer]
OnUnitActiveSec=300
[Install]
WantedBy=timers.target
EOF
systemctl enable apiban-fail2ban.timer
systemctl enable apiban-fail2ban.service
echo "-> starting services. this can take a bit if there are many ips"
systemctl start apiban-fail2ban.timer
systemctl start apiban-fail2ban.service
echo "-> all done."