I'm trying to configure the wireless settings (like setting ssid as "vinoth" channel as "1") in Linksys EA4500 AP. I could see the below POST message using wireshark.
3E@@!dPzY+2K
SPOST /JNAP/ HTTP/1.1
Host: 192.168.1.1
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:22.0) Gecko/20100101 Firefox/22.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
X-JNAP-Action: http:cisco.com/jnap/core/Transaction
X-JNAP-Authorization: Basic YWRtaW46YWRtaW4=
X-Requested-With: XMLHttpRequest
Referer: http:/cisco.com/ <<<<==== routerip
Content-Length: 474
Cookie: initial-tab=; ui-proxy-path=local; admin-auth=Basic%20YWRtaW46YWRtaW4%3D; current-applet=7B1F462B-1A78-4AF6-8FBB-0C221703BEA4
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
[{"action":"http:/cisco.com/jnap/wirelessap/SetRadioSettings","request":{"radios":[{"radioID":"RADIO_2.4GHz","settings":{"isEnabled":true,"mode":"802.11bgn","ssid":"vinoth","broadcastSSID":true,"channelWidth":"Auto","channel":1,"security":"None"}}]}},{"action":"http://cisco.com/jnap/guestnetwork/SetGuestNetworkSettings","request":{"isGuestNetworkEnabled":false,"guestSSID":"vinoth-guest","guestPassword":"BeMyGuest","maxSimultaneousGuests":5,"broadcastGuestSSID":false}}]
I tried automating the above action using Perl but it didn't workout. As I am new to this JSON page I don't know how exactly the POST message to be sent.
content I kept for $json is
'{"action":"http:/cisco.com/jnap/wirelessap/SetRadioSettings",' .
'"request":{"radios":{"radioID":"RADIO_2.4GHz","settings":'.'{"isEnabled":true,"mode":"802.11bgn","ssid":"vinoth212","broadcastSSID":true,"channelWidth":"Auto","channel":1,"security":"None"}}}},{"action":"http://cisco.com/jnap/guestnetwork/SetGuestNetworkSettings",' .
'"request":{"isGuestNetworkEnabled":false,"guestSSID":"vinoth-guest","guestPassword":"BeMyGuest","maxSimultaneousGuests":5,"broadcastGuestSSID":false}}';
and the code:
use strict;
use warnings;
use LWP;
my $ua = LWP::UserAgent->new;
my $ip = $self->{ip};
my $url = "http://$ip/";
my $json = "";
my $req = HTTP::Request->new(POST=>$url);
$req->header('content-type' => 'application/json');
$req->authorization_basic("admin", "admin");
$req->content($json);
Below code for checking the request status
my $res = $ua->request($req);
if ($res->is_success) {
my $message = $res->decoded_content;
print "received the message";
} else {
print "HTTP get code: ", $res->code, "\n";
print "HTTP get: msg: ", $res->message, "\n";
}
Please help me in fixing this. Awaiting for your valuable reply.
P.S: In the Wireshark Post message the links are not proper as I am unable to post the query with more than 2 links.
Thanks, Vinoth
Using the code $req->authorization_basic("admin", "admin");
it means Authorization: Basic YWRtaW46YWRtaW4=
HTTP header when make any request.
But From your wireshirk's header it is X-JNAP-Authorization: Basic YWRtaW46YWRtaW4=
, which is different thing(a custom header). So remove that authorization_basic
from your block and use these ones:
$req->header('Content-Type' => 'application/json; charset=UTF-8');
$req->header('X-JNAP-Action' => 'http:cisco.com/jnap/core/Transaction');
$req->header('X-JNAP-Authorization' => 'Basic YWRtaW46YWRtaW4=');
## YWRtaW46YWRtaW4= is base64 of admin:admin
$req->header('X-Requested-With' => 'XMLHttpRequest');