Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/MGRAST/cgi/api.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if (lc($request_method) eq 'options') {
print $cgi->header(-Access_Control_Allow_Origin => '*',
-status => 200,
-type => 'text/plain',
-charset => 'UTF-8',
-Access_Control_Allow_Methods => 'POST, GET, OPTIONS',
-Access_Control_Allow_Headers => 'AUTH'
);
Expand Down Expand Up @@ -58,6 +59,7 @@ my $resource_path = $Conf::api_resource_path;
if (! $resource_path) {
print $cgi->header(-type => 'text/plain',
-status => 500,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode( {"ERROR"=> "resource directory not found"} );
exit 0;
Expand All @@ -72,6 +74,7 @@ if (opendir(my $dh, $resource_path)) {
if ($cgi->param('POSTDATA') && ! $resource) {
print $cgi->header(-type => 'application/json',
-status => 200,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode( { jsonrpc => "2.0",
id => undef,
Expand All @@ -82,8 +85,9 @@ if (opendir(my $dh, $resource_path)) {
exit 0;
} else {
print $cgi->header( -type => 'text/plain',
-status => 500,
-Access_Control_Allow_Origin => '*' );
-status => 500,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode( {"ERROR"=> "resource directory offline"} );
exit 0;
}
Expand All @@ -99,8 +103,9 @@ if ($json_rpc && (! $resource)) {
eval { $rpc_request = $json->decode($json_rpc) };
if ($@) {
print $cgi->header( -type => 'application/json',
-status => 200,
-Access_Control_Allow_Origin => '*' );
-status => 200,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode( { jsonrpc => "2.0",
id => undef,
error => { code => -32700,
Expand All @@ -117,8 +122,9 @@ if ($json_rpc && (! $resource)) {
}
unless (ref($params) eq 'HASH') {
print $cgi->header( -type => 'application/json',
-status => 200,
-Access_Control_Allow_Origin => '*' );
-status => 200,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode( { jsonrpc => "2.0",
id => undef,
error => { code => -32602,
Expand Down Expand Up @@ -153,7 +159,8 @@ if ($cgi->http('HTTP_AUTH') || $cgi->param('auth')) {
unless($user) {
unless ($message eq "valid kbase user") {
print $cgi->header( -type => 'application/json',
-status => 401,
-status => 401,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode( {"ERROR"=> "authentication failed - $message"} );
exit 0;
Expand Down Expand Up @@ -184,6 +191,7 @@ if ($resource) {
print STDERR $error."\n";
print $cgi->header( -type => 'application/json',
-status => 500,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode( {"ERROR"=> "resource '$resource' does not exist"} );
exit 0;
Expand All @@ -209,11 +217,12 @@ if ($resource) {
$resource_obj->request();
};
if ($@) {
print $cgi->header( -type => 'text/plain',
-status => 500,
-Access_Control_Allow_Origin => '*' );
print $json->encode( {"ERROR"=> "resource request failed\n$@\n"} );
exit 0;
print $cgi->header( -type => 'text/plain',
-status => 500,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode( {"ERROR"=> "resource request failed\n$@\n"} );
exit 0;
}
}
}
Expand All @@ -232,6 +241,7 @@ else {
resources => \@res };
print $cgi->header(-type => 'application/json',
-status => 200,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode($content);
exit 0;
Expand Down
4 changes: 2 additions & 2 deletions src/MGRAST/cgi/linkin.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if ($@)
{
my $cgi = new CGI();

print $cgi->header();
print $cgi->header(-charset => 'UTF-8');
print $cgi->start_html();

# print out the error
Expand Down Expand Up @@ -57,7 +57,7 @@ sub main {
}

if ($error) {
print $cgi->header();
print $cgi->header(-charset => 'UTF-8');
print $cgi->start_html(-title => 'MG-RAST linkin');

# print out the error
Expand Down
2 changes: 1 addition & 1 deletion src/MGRAST/cgi/metagenomics.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ eval {
if ($@)
{

print $cgi->header();
print $cgi->header(-charset => 'UTF-8');
print $cgi->start_html();

# print out the error
Expand Down
19 changes: 12 additions & 7 deletions src/MGRAST/cgi/oAuthPPO.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ if ($cgi->param('logout')) {
-expires => "-1d" );

if ($cgi->param('redirect')) {
print $cgi->header( -redirect => $cgi->param('redirect'), -cookie => $cookie );
print $cgi->header( -redirect => $cgi->param('redirect'), -cookie => $cookie, -charset => 'UTF-8' );
} else {
print $cgi->header( -cookie => $cookie );
print $cgi->header( -cookie => $cookie, -charset => 'UTF-8' );
print base_template();
print success_message("You have been logged out.");
print close_template();
Expand Down Expand Up @@ -92,7 +92,7 @@ if ($cgi->param('login') && $cgi->param('pass')) {
}

unless ($cgi->param('action')) {
print $cgi->header(-cookie => $cookie );
print $cgi->header(-cookie => $cookie, -charset => 'UTF-8' );
print base_template();

if (! $allow_application && ! $allow_user) {
Expand Down Expand Up @@ -202,6 +202,7 @@ unless ($cgi->param('action')) {
$dbh->disconnect();
print $cgi->header(-type => 'text/plain',
-status => 400,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print "redirect_url does not match client id";
exit 0;
Expand All @@ -221,6 +222,7 @@ unless ($cgi->param('action')) {
$dbh->disconnect();
print $cgi->header(-type => 'text/plain',
-status => 400,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print "invalid user code";
exit 0;
Expand All @@ -229,6 +231,7 @@ unless ($cgi->param('action')) {
$dbh->disconnect();
print $cgi->header(-type => 'text/plain',
-status => 400,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print "invalid code";
exit 0;
Expand All @@ -253,13 +256,15 @@ unless ($cgi->param('action')) {
$dbh->disconnect();
print $cgi->header(-type => 'text/plain',
-status => 200,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print "access_token=$token|".$user->login;
exit 0;
} else {
$dbh->disconnect();
print $cgi->header(-type => 'text/plain',
-status => 400,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print "missing parameter";
exit 0;
Expand Down Expand Up @@ -314,7 +319,7 @@ sub warning_message {
my ($message) = @_;

$dbh->disconnect();
print $cgi->header();
print $cgi->header(-charset => 'UTF-8');
print base_template();
print qq~<div class="alert alert-error">
<button class="close" data-dismiss="alert" type="button">x</button>
Expand All @@ -328,7 +333,7 @@ sub success_message {
my ($message) = @_;

$dbh->disconnect();
print $cgi->header();
print $cgi->header(-charset => 'UTF-8');
print base_template();
print qq~<div class="alert alert-success">
<button class="close" data-dismiss="alert" type="button">x</button>
Expand Down Expand Up @@ -356,7 +361,7 @@ sub login_screen {
$hidden .= "<input type='hidden' name='".$p."' value='".$cgi->param($p)."'>";
}

print $cgi->header();
print $cgi->header(-charset => 'UTF-8');
print base_template();
print qq~
<div class="well">
Expand Down Expand Up @@ -385,7 +390,7 @@ sub auth_client_screen {
}

my $application = $cgi->param("client_id");
print $cgi->header(-cookie=>$cookie);
print $cgi->header(-cookie=>$cookie, -charset => 'UTF-8');
print base_template();
print qq~
<div class="well">
Expand Down
Loading