2014年5月6日火曜日

Linux: curl cookie & web-login: Aruba Activate

curlを利用して、Aruba Activteにログインして、Inventory Queryを送信してAPのリストを表示する。

==========================
Step-1:
==========================
-c write, -b read

taka$ curl -c cookie.txt --data "credential_0=username&credential_1=password&destination='/api/ext/inventory.json?action=query'" https://activate.arubanetworks.com/LOGIN

--------------------------------------------
cookie.txt
--------------------------------------------
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_activate.arubanetworks.com FALSE / TRUE 0 session cb7e7fbb-7f55-42cd-ab6d-9afe3b802c65
--------------------------------------------

taka$ curl -i -b cookie.txt https://activate.arubanetworks.com/api/ext/inventory.json?action=queryHTTP/1.1 200 OK
Date: Mon, 05 May 2014 15:15:52 GMT
Cache-Control: no-cache
Content-Disposition: inline;filename=inventory.json
Content-Length: 623
Content-type: application/json; charset=utf-8
Expires: -1
Pragma: no-cache

{"info":{"api":"inventory","version":"1.4"},"message":{"text":"1 devices returned","code":0},"devices":[{"mac":"D8:C7:C8:C4:6B:EC","serialNumber":"BE0011245","partNumber":"IAP-105","status":"provisioned","folderId":"2f3362fe-a8ca-11e1-9eaf-a4badbe0f786","firstSeen":"02-13-2012","lastSeen":"04-28-2014","additionalData":{"deviceName":"AP-1","deviceFullName":"","deviceDescription":"","apGroupName":null,"folder":"default","folderId":"2f3362fe-a8ca-11e1-9eaf-a4badbe0f786","firstSeen":"02-13-2012","lastSeen":"04-28-2014","lastAosVersion":"6.3.1.4-4.0.0.5_43022","lastBootVersion":null,"sourceIpAddress":"106.188.22.200"}}]}kurokawa-no-MacBook-Air:Linux taka$


==========================
Test-2 -parameter --cookie
==========================

kurokawa-no-MacBook-Air:Linux taka$ curl -i --data "credential_0=hoge1&credential_1=hogehoge&destination='/api/ext/inventory.json?action=query'" https://activate.arubanetworks.com/LOGIN
HTTP/1.1 302 Temporary Redirect
Date: Mon, 05 May 2014 01:50:57 GMT
Content-length: 0
Location: '/api/ext/inventory.json?action=query'
Set-cookie: session=51b428d2-ab08-4f70-9c85-1450618b5783; Path=/; Secure; HttpOnly
Content-Type: text/plain; charset=UTF-8

kurokawa-no-MacBook-Air:Linux taka$ curl -i --cookie "session=e966fcd4-9824-4804-91f3-80aefee42588" https://activate.arubanetworks.com/api/ext/inventory.json?action=queryHTTP/1.1 200 OK
Date: Mon, 05 May 2014 01:51:41 GMT
Cache-Control: no-cache
Content-Disposition: inline;filename=inventory.json
Content-Length: 623
Content-type: application/json; charset=utf-8
Expires: -1
Pragma: no-cache

============================
Test-3 AWS -k option
============================
[root@ip-172-31-17-244 ~]# curl -c cookie.txt --data "credential_0=hoge1&credential_1=hogehoge&destination='/api/ext/inventory.json?action=query'" https://activate.arubanetworks.com/LOGIN
curl: (60) Peer certificate cannot be authenticated with known CA certificates
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.
[root@ip-172-31-17-244 ~]# curl -k -c cookie.txt --data "credential_0=hoge1&credential_1=hogehoge&destination='/api/ext/inventory.json?action=query'" https://activate.arubanetworks.com/LOGIN

[root@ip-172-31-17-244 ~]# curl -k -i -b cookie.txt https://activate.arubanetworks.com/api/ext/inventory.json?action=query
HTTP/1.1 200 OK
Date: Thu, 08 May 2014 10:14:42 GMT
Cache-Control: no-cache
Content-Disposition: inline;filename=inventory.json
Content-Length: 623
Content-type: application/json; charset=utf-8
Expires: -1
Pragma: no-cache

0 件のコメント:

コメントを投稿