-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdropbear.sh
70 lines (66 loc) · 2.48 KB
/
dropbear.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
#!/bin/bash
#XPanel Alireza
json_file="/var/www/html/app/storage/dropbear.json"
idrop=0
if [ ! -e "$json_file" ] || [ ! -s "$json_file" ]; then
echo "[]" > "$json_file"
chmod 777 "$json_file"
fi
port_dropbear=$(ps aux | grep dropbear | awk NR==1 | awk '{print $13;}')
log="/var/log/auth.log"
loginsukses="Password auth succeeded"
while [ $idrop -lt 10 ]; do
pids=$(lsof -i :"$port_dropbear" -n | grep ESTABLISHED | awk -F" " '{print $2}')
for pid in $pids; do
pidlogs=$(grep $pid $log | grep "$loginsukses" | awk -F" " '{print $3}')
i=0
for pidend in $pidlogs; do
let i=i+1
done
if [ -n "$pidend" ]; then
login=$(grep $pid $log | grep "$pidend" | grep "$loginsukses")
PID=$pid
user=$(echo $login | awk -F" " '{print $10}' | sed -r "s/'/ /g")
user=$(echo $user | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
waktu=$(echo $login | awk -F" " '{print $2"-"$1,$3}')
while [ ${#waktu} -lt 13 ]; do
waktu=$waktu" "
done
if [ -n "$user" ]; then
if jq ".[] | select(.user == \"$user\" and .PID == \"$PID\")" "$json_file" | grep -q "$user"; then
continue
else
json_item="{\"user\": \"$user\", \"PID\": \"$PID\", \"waktu\": \"$waktu\"}"
jq ". += [$json_item]" "$json_file" > "${json_file}.tmp" && mv "${json_file}.tmp" "$json_file"
fi
fi
fi
done
wait
if [ -e "$json_file" ]; then
jsonData_remove=$(jq -c '.[]' "$json_file")
unique_entries=()
while IFS= read -r entry_remove; do
user_remove=$(jq -r '.user' <<< "$entry_remove")
PID_remove=$(jq -r '.PID' <<< "$entry_remove")
if [ -n "$user_remove" ] && [ -n "$PID_remove" ]; then
if ps -p "$PID_remove" > /dev/null; then
echo "User: $user_remove, PID: $PID_remove is running."
else
echo "User: $user_remove, PID: $PID_remove is not running. Removing the entry."
jq "del(.[] | select(.user == \"$user_remove\" and .PID == \"$PID_remove\"))" "$json_file" > "${json_file}.tmp" && mv "${json_file}.tmp" "$json_file"
fi
fi
done <<< "$jsonData_remove"
fi
python3 /var/www/html/app/storage/removedupdrop.py
sleep 5
idrop=$((idrop + 1))
done
dropbear_status=$(service dropbear status)
if [[ $dropbear_status == *"is not running"* ]]; then
service dropbear start
echo "Start dropbear"
fi
#rm -fr /var/log/auth.log
#systemctl restart syslog