日期: 2013-04-10

分类: ['linux-admin']

Linux中curl的一些用法记录

With Arduino as a server.

What we want is to keep a cookie and build a HEADER http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html [P1]

curl -e curl -H referer:whereicamefrom.com curl -d @file.txt curl -d "somecmd" curl -cookie curl -D

[P2] Communicating with ipa server https://git.fedorahosted.org/cgit/freeipa.git/tree/API.txt

Get ca.crt

curl -k https://$YOURHOST/ipa/config/ca.crt >> /tmp/ipa.ca.cert

Get sessionid

sessid=$(curl -v -H referer:https://ipa.test.net/ipa/ui/index.html -H "Content-Type:application/x-www-form-urlencoded" -H "Accept:*/*" --negotiate -u : --cacert ./ca.crt -d "user=admin" -d "password=12345678" -D cookie.txt -X POST -k
https://ipa.test.net/ipa/session/login_password 2>&1 | grep -o "ipa_session=[a-zA-Z0-9]*")

Post a json file with cmd in it

curl -v -H referer:https://ipa.test.net/ipa/ui/index.html -H "Content-Type:application/json" -H "Accept:applicaton/json" -negotiate -u : --cacert ./ca.crt --cookie $sessid -d @ipa.json -X POST -k
https://ipa.test.net/ipa/session/json

Here's a json file

{ "method":"user_find", "params":[ [""], {"uid":"admin"} ], "id":0 }

{ "method":"user_add", "params":[ [], { "uid":"test1", "cn":"cn", "givenname":"test1", "sn":"test1" } ], "id":0 }