Something about curl — Connecting IPA Server using json as an example

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
}

发表评论

您的电子邮箱地址不会被公开。