3 changed files with 106 additions and 0 deletions
@ -0,0 +1 @@ |
|||||
|
apptoken |
||||
@ -0,0 +1,49 @@ |
|||||
|
#!/usr/bin/perl -w |
||||
|
|
||||
|
use LWP::UserAgent; |
||||
|
use JSON::PP; |
||||
|
use strict; |
||||
|
|
||||
|
my $ua = LWP::UserAgent->new; |
||||
|
|
||||
|
my %auth_request = ( |
||||
|
app_id => "fr.itix.munin", |
||||
|
app_name => "Munin", |
||||
|
app_version => "0.0.1", |
||||
|
device_name => "tournedix.itix.fr" |
||||
|
); |
||||
|
|
||||
|
my $auth_response = $ua->post("http://mafreebox.freebox.fr/api/v1/login/authorize", Content => encode_json(\%auth_request)); |
||||
|
|
||||
|
die "post: authorize: ".$auth_response->status_line |
||||
|
unless $auth_response->is_success; |
||||
|
|
||||
|
my $json_auth_response = decode_json($auth_response->decoded_content); |
||||
|
my $trackid = $json_auth_response->{result}->{track_id}; |
||||
|
die "post: authorize: no trackid in response" |
||||
|
unless defined $trackid; |
||||
|
|
||||
|
my $apptoken = $json_auth_response->{result}->{app_token}; |
||||
|
print "APPTOKEN is '",$apptoken,"'\n"; |
||||
|
|
||||
|
do { |
||||
|
$auth_response = $ua->get("http://mafreebox.freebox.fr/api/v1/login/authorize/$trackid"); |
||||
|
die "post: authorize: ".$auth_response->status_line |
||||
|
unless $auth_response->is_success; |
||||
|
$json_auth_response = decode_json($auth_response->decoded_content); |
||||
|
|
||||
|
print "RES: ",$json_auth_response->{success}," STATUS: ",$json_auth_response->{result}->{status}, "\n"; |
||||
|
sleep 2; |
||||
|
} while ($json_auth_response->{result}->{status} eq 'pending'); |
||||
|
|
||||
|
my $status = $json_auth_response->{result}->{status}; |
||||
|
print "Final status is '", $status, "'\n"; |
||||
|
|
||||
|
if ($status eq 'granted') { |
||||
|
my $filename = "apptoken"; |
||||
|
open TOKENFILE, '>', $filename |
||||
|
or die "open: $filename: $!"; |
||||
|
print TOKENFILE "$apptoken\n"; |
||||
|
close TOKENFILE; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,56 @@ |
|||||
|
#!/usr/bin/perl -w |
||||
|
|
||||
|
use LWP::UserAgent; |
||||
|
use JSON::PP; |
||||
|
use MIME::Base64; |
||||
|
use Digest::SHA qw/hmac_sha1_hex/; |
||||
|
use strict; |
||||
|
|
||||
|
my $ua = LWP::UserAgent->new; |
||||
|
|
||||
|
sub get_json { |
||||
|
my $resp = shift; |
||||
|
my $method = shift; |
||||
|
#warn "raw response: ".$resp->decoded_content; |
||||
|
warn "$method: www: ".$resp->status_line |
||||
|
unless $resp->is_success; |
||||
|
my $json = decode_json($resp->decoded_content); |
||||
|
die "$method: fb: method call failed: ".$json->{msg} |
||||
|
unless $json->{success}; |
||||
|
return $json; |
||||
|
} |
||||
|
|
||||
|
my $auth_response = $ua->get("http://mafreebox.freebox.fr/api/v1/login/"); |
||||
|
my $json_auth_response = get_json($auth_response, "login"); |
||||
|
my $challenge = $json_auth_response->{result}->{challenge}; |
||||
|
print "Current challenge is $challenge\n"; |
||||
|
|
||||
|
my $filename = "apptoken"; |
||||
|
open TOKENFILE, "<", $filename |
||||
|
or die "open: $filename: $!"; |
||||
|
my $apptoken = <TOKENFILE>; |
||||
|
close TOKENFILE; |
||||
|
|
||||
|
my $pw = hmac_sha1_hex($challenge, $apptoken); |
||||
|
print "Computed password is $pw\n"; |
||||
|
|
||||
|
my %auth_request = ( |
||||
|
app_id => "fr.itix.munin", |
||||
|
password => $pw |
||||
|
); |
||||
|
|
||||
|
$auth_response = $ua->post("http://mafreebox.freebox.fr/api/v1/login/session", Content => encode_json(\%auth_request)); |
||||
|
$json_auth_response = get_json($auth_response, "login"); |
||||
|
my $session_token = $json_auth_response->{result}->{session_token}; |
||||
|
die "post: session: no session_token in response" |
||||
|
unless defined $session_token; |
||||
|
|
||||
|
$ua->default_header('X-Fbx-App-Auth', $session_token); |
||||
|
my %rrd_request = ( |
||||
|
db => "net", |
||||
|
date_start => time - 5*60, |
||||
|
date_end => time, |
||||
|
); |
||||
|
my $rrd_response = $ua->post("http://mafreebox.freebox.fr/api/v1/rrd", Content => encode_json(\%rrd_request)); |
||||
|
my $json_rrd_response = get_json($rrd_response, "rrd"); |
||||
|
|
||||
Loading…
Reference in new issue