-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsshmonitor
More file actions
76 lines (62 loc) · 1.62 KB
/
Copy pathsshmonitor
File metadata and controls
76 lines (62 loc) · 1.62 KB
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
#!/bin/bash
CONFIG="/opt/ssh-monitor/config.json"
SERVICE="ssh-monitor"
case "$1" in
start)
echo "Activation..."
systemctl start "$SERVICE"
;;
stop)
echo "Désactivation..."
systemctl stop "$SERVICE"
;;
restart)
echo "Redémarrage..."
systemctl restart "$SERVICE"
;;
status)
systemctl status "$SERVICE"
;;
add)
if [ -z "$2" ]; then
echo "Usage: sshmonitor add <ip>"
exit 1
fi
if ! [[ "$2" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
echo "Adresse IP invalide."
exit 1
fi
jq --arg ip "$2" '
if .whitelist | index($ip)
then .
else .whitelist += [$ip]
end
' "$CONFIG" > /tmp/config.json && mv /tmp/config.json "$CONFIG"
echo "IP $2 ajoutée à la whitelist."
;;
remove)
if [ -z "$2" ]; then
echo "Usage: sshmonitor remove <ip>"
exit 1
fi
jq --arg ip "$2" '
.whitelist |= map(select(. != $ip))
' "$CONFIG" > /tmp/config.json && mv /tmp/config.json "$CONFIG"
echo "IP $2 supprimée de la whitelist."
;;
list)
echo "Whitelist :"
jq -r '.whitelist[]' "$CONFIG"
;;
*)
echo "Usage:"
echo " sshmonitor start"
echo " sshmonitor stop"
echo " sshmonitor restart"
echo " sshmonitor status"
echo " sshmonitor add <ip>"
echo " sshmonitor remove <ip>"
echo " sshmonitor list"
exit 1
;;
esac