switched to json-p for experimental /js/{email} endpoint
This commit is contained in:
parent
88d27af9b7
commit
6ff86d1da3
22
server.pl
22
server.pl
|
@ -520,11 +520,12 @@ EOF
|
||||||
print_response($cgi, 404);
|
print_response($cgi, 404);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $pubkey = $cgi->http('X-Dotplan-Pubkey');
|
my $callback = $cgi->param('callback') || 'handle_dotplan';
|
||||||
|
my $pubkey = $cgi->param('pubkey');
|
||||||
|
my $planJson = encode_json($plan);
|
||||||
if ((defined $pubkey && !defined $plan->{'signature'}) ||
|
if ((defined $pubkey && !defined $plan->{'signature'}) ||
|
||||||
(defined $pubkey && !util_verify_plan($email, $pubkey))) {
|
(defined $pubkey && !util_verify_plan($email, $pubkey))) {
|
||||||
print_response($cgi, 403);
|
$planJson = '{"error":"The requested plan signature could not be verified with the specified public key."}';
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
# check modified time
|
# check modified time
|
||||||
my $now = time;
|
my $now = time;
|
||||||
|
@ -536,24 +537,11 @@ EOF
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
# render response
|
# render response
|
||||||
my $escapedPlan = encode_entities($plan->{'plan'});
|
my $body = "(function() { $callback($planJson); })();";
|
||||||
$escapedPlan =~ s/\n/<br>/g;
|
|
||||||
$escapedPlan =~ s/(<br>)*$//;
|
|
||||||
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($mtime);
|
|
||||||
$year += 1900;
|
|
||||||
$mon++;
|
|
||||||
my $fmtMtime = sprintf('%d-%02d-%02d', $year, $mon, $mday);
|
|
||||||
my $body = <<EOF;
|
|
||||||
document.getElementById('dotplan_date').innerHTML = '$fmtMtime';
|
|
||||||
document.getElementById('dotplan_plan').innerHTML = '$escapedPlan';
|
|
||||||
EOF
|
|
||||||
my $headers = {
|
my $headers = {
|
||||||
'Content-Type' => 'application/javascript',
|
'Content-Type' => 'application/javascript',
|
||||||
'Last-Modified' => HTTP::Date::time2str($mtime)
|
'Last-Modified' => HTTP::Date::time2str($mtime)
|
||||||
};
|
};
|
||||||
if (defined $pubkey) {
|
|
||||||
$headers->{'X-Dotplan-Verified'} = 'true';
|
|
||||||
}
|
|
||||||
print_response($cgi, 200, $headers, $body);
|
print_response($cgi, 200, $headers, $body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue