-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify_user.sh
60 lines (53 loc) · 1.4 KB
/
verify_user.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
#!/bin/sh
genhash() {
hashpass=$(echo -n "$1$2" | md5sum | sed s'/\ -//')
i=0
while [ $i -lt 10 ]; do
hashpass=$(echo -n $hashpass$hashpass | md5sum | sed s'/\ -//')
i=$(expr $i + 1)
done
echo -n $hashpass
}
verify() {
login=$(echo $1 | awk '{print tolower($0)}')
echo "`date +"%a %b %d %T %Y"` verify script - user: $login"
logger -t "openvpn auth" "verify script - user: $login"
[[ $# -eq 2 ]] || exit 1
for i in $users; do
name=${i%:*}
passhash=${i#*:}
logincmp=$(echo $name | awk '{print tolower($0)}')
if [ "$logincmp" == "$login" ]
then
hash=$(genhash "$login" "$2")
if [ "$hash" == "$passhash" ]
then
echo "`date +"%a %b %d %T %Y"` verify script - success: $login"
logger -t "openvpn auth" "verify script - success: $login"
exit 0
fi
fi
done
}
if [ "$1" == "--genhash" ]; then
shift 1
case $# in
3) users_file=$1
shift 1;;
2) users_file="./users";;
*) echo "Incorrect arguments provided";;
esac
login=$(echo $1 | awk '{print tolower($0)}')
echo "$login:$(genhash "$login" "$2")" >> $users_file
chown root:nobody $users_file
chmod 640 $users_file
exit 1
fi
users_file=$1
shift 1
users=$(cat $users_file)
#verify $(cat $*)
verify $(cat $1)
echo "`date +"%a %b %d %T %Y"` verify script - failed to auth: $login"
logger -t "openvpn auth" "verify script - failed to auth: $login"
exit 1