-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlcurl.sh
More file actions
executable file
·75 lines (65 loc) · 2.02 KB
/
lcurl.sh
File metadata and controls
executable file
·75 lines (65 loc) · 2.02 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
#!/bin/bash
# curl helper script to let me hit endpoints that require authentication
# can't remember if this was ever finished/worked?
COOKIE_FILE=~/development/curlStorage/CURL_COOKIE_FILE.txt
OUTPUT_FILE=~/development/curlStorage/curlResults.html
BASE_CMD="curl -b ${COOKIE_FILE} -c ${COOKIE_FILE}"
QUIET_CMD="${BASE_CMD} -s -o ${OUTPUT_FILE}"
forceLogin=0
username=""
password=""
url=""
verbose=0
looper=0
nextIndex=0
for var in "$@"
do
let nextIndex=$looper+2
# echo "[${looper}] = [${var}]"
if [ "${var}" = "-force" ]; then
forceLogin=1
elif [ "${var}" = "-username" ]; then
username="${@:$nextIndex:1}"
elif [ "${var}" = "-password" ]; then
password="${@:$nextIndex:1}"
elif [ "${var}" = "-url" ]; then
url="${@:$nextIndex:1}"
elif [ "${var}" = "-verbose" ]; then
let verbose=1
fi
# echo "$var"
let looper=$looper+1
done
echo "read params: forceLogin=[${forceLogin}], username=[${username}], password=[${password}], url=[${url}], verbose=[${verbose}]"
exit 1
if [ ! -f ${COOKIE_FILE} ] || [ $forceLogin -eq 1 ]; then
if [ "${username}" = "" ] || [ "${password}" = "" ]; then
echo "username/password not supplied"
exit 1
else
# hit the login page to set the test cookie
${QUIET_CMD} https://slote.test.carleton.edu/login/
# now hit the login page with real data
${QUIET_CMD} -d "username=${username}&password=${password}" https://slote.test.carleton.edu/login/
fi
fi
# did login work?
grep -q "REASON_SESSION_EXISTS" ${COOKIE_FILE}
if [ $? -eq 0 ]; then
if [ "${url}" = "" ]; then
echo "specify a url with -u <URL>, ex: 'reasonApiTester.sh -u /rest/ems/cams/20140911/20140918'"
else
if [ $verbose -eq 1 ]; then
${BASE_CMD} "https://slote.test.carleton.edu${url}"
else
${BASE_CMD} -s "https://slote.test.carleton.edu${url}" | python -m json.tool
if [ $? -eq 1 ]; then
echo "An error occurred? Trying again without json.tool post-processing..."
${BASE_CMD} -s "https://slote.test.carleton.edu${url}"
fi
fi
fi
else
echo "invalid login credentials; deleting ${COOKIE_FILE}"
rm $COOKIE_FILE
fi