-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjwt-change-passphrase
executable file
·77 lines (62 loc) · 1.38 KB
/
jwt-change-passphrase
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
#!/bin/sh
CURL=curl
CMDNAME=$(basename $0)
if [ -n $JWT_SERVER_URL ]; then
BASE_URL=$JWT_SERVER_URL
fi
if [ -n $LOGNAME ]; then
ACCOUNT=$LOGNAME
fi
while getopts s:l:p: OPT
do
case $OPT in
"s" ) BASE_URL=$BASE_URL" ""$OPTARG" ;;
"l" ) ACCOUNT="$OPTARG" ;;
* ) echo "Usage: $CMDNAME [-s URL] [-l USER]" 1>&2
exit 1 ;;
esac
done
if [ -z "$BASE_URL" -o -z "$ACCOUNT" ]; then
echo "Usage: $CMDNAME [-s URL] [-l USER]" 1>&2
exit 1
fi
if [ -t 0 ]; then
echo -n "Passphrase: "
trap "stty echo" HUP INT QUIT TERM
stty -echo
read PASS
stty echo
echo
else
read PASS
fi
set -- $BASE_URL
for i in `seq 1 $#`
do
u=$(eval echo '$'${i})
u=$(echo $u | sed 's:/*$::')
URL=${u}'/chpass'
echo "$u"
COMMAND="$CURL -f -sS -m 10 -X POST -d user=$ACCOUNT -d pass=$PASS $URL"
PASSPHRASE=`$COMMAND`
curl_ret=$?
#curl's exit status is 0 at authentication error
expr "$PASSPHRASE" : '.*Error.*' > /dev/null
jwt_ret=$?
expr "$PASSPHRASE" : '.*<html>.*' > /dev/null
jwt_ret2=$?
if [ $curl_ret -ne 0 ] || [ -z "$PASSPHRASE" ] || [ $jwt_ret -eq 0 ] || [ $jwt_ret2 -eq 0 ]; then
#error
if [ $jwt_ret2 -eq 0 ]; then
echo $ACCOUNT":Invalid Server"
elif [ $curl_ret -eq 0 ]; then
echo $ACCOUNT":Authentication Error"
else
continue;
fi
exit 1
else
echo $PASSPHRASE
exit 0
fi
done