|
@@ -1,12 +1,12 @@
|
1
|
1
|
#!/bin/bash
|
2
|
2
|
|
3
|
|
-# login and store cookies in 'cookies.txt'
|
4
|
|
-curl 'http://localhost/api.php/' --data "username=admin&password=admin" --cookie-jar cookies.txt --silent >/dev/null
|
|
3
|
+# login and store cookies in 'cookies.txt' AND retrieve the value of the XSRF token
|
|
4
|
+TOKEN=`curl 'http://localhost/api.php/' --data "username=admin&password=admin" --cookie-jar cookies.txt`
|
5
|
5
|
|
6
|
|
-# retrieve the value of the 'XSRF-TOKEN' cookie
|
7
|
|
-TOKEN=`cat cookies.txt|grep XSRF-TOKEN|cut -f 7`
|
|
6
|
+# strip the double quotes from the variable (JSON decode)
|
|
7
|
+TOKEN=${TOKEN//\"/}
|
8
|
8
|
|
9
|
|
-# set the 'XSRF-TOKEN' as the 'X-XSRF-Token' header AND send the cookies to the server
|
|
9
|
+# set the XSRF token as the 'X-XSRF-Token' header AND send the cookies to the server
|
10
|
10
|
curl 'http://localhost/api.php/posts?include=categories,tags,comments&filter=id,eq,1' --header "X-XSRF-Token: $TOKEN" --cookie cookies.txt
|
11
|
11
|
|
12
|
12
|
# clean up
|