diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-09-06 04:28:51 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-09-06 04:28:51 (GMT) |
commit | f2cf3cf6fb0df68168245c82a029279f190ffe94 (patch) | |
tree | 071d60e84ae6dd9d5f68863af7ca86f3a413047e | |
parent | b8c174cf5f3321c7f10620f204daa2824e48fc46 (diff) |
improved response codes for cgi scripts
-rwxr-xr-x | rh-bin/authtoken.json | 9 | ||||
-rwxr-xr-x | rh-bin/listdropboxes.cgi | 5 |
2 files changed, 11 insertions, 3 deletions
diff --git a/rh-bin/authtoken.json b/rh-bin/authtoken.json index e56daa9..743ac96 100755 --- a/rh-bin/authtoken.json +++ b/rh-bin/authtoken.json @@ -32,6 +32,8 @@ while (my $q = CGI::Fast->new) { my $username = ''; my $token = ''; my $fullname = ''; + my $responsecode = 500; + if(defined $ENV{REMOTE_USER}) { my $dbh; ($dbh, $status, $errorstring) = RHRD::rddb::opendb(); @@ -42,9 +44,13 @@ while (my $q = CGI::Fast->new) { ($fullname, $status, $errorstring) = RHRD::rddb::get_fullname($dbh, $username); $fullname = '' unless($fullname); RHRD::rddb::closedb($dbh); + if($status == "OK") { + $responsecode = 200; + } } } else { $errorstring = 'no username defined - are you logged in?'; + $responsecode = 400; } my %answer; @@ -54,6 +60,7 @@ while (my $q = CGI::Fast->new) { $answer{'fullname'} = $fullname; $answer{'token'} = $token; - print "Content-type: application/json; charset=UTF-8\n\n"; + print "Content-type: application/json; charset=UTF-8\n"; + print "Status: $responsecode\n\n"; print encode_json \%answer; } diff --git a/rh-bin/listdropboxes.cgi b/rh-bin/listdropboxes.cgi index 03dc4ee..f008c51 100755 --- a/rh-bin/listdropboxes.cgi +++ b/rh-bin/listdropboxes.cgi @@ -50,14 +50,15 @@ while (my $q = CGI::Fast->new) { $errorstring = $dropboxes[2]; } } elsif($result == 0) { - $responsecode = 403; + $responsecode = 401; } else { $responsecode = 500; } RHRD::rddb::closedb($dbh); } - print "Content-type: application/xml; charset=UTF-8\n\n"; + print "Content-type: application/xml; charset=UTF-8\n"; + print "Status: $responsecode\n\n"; if($responsecode != 200) { print "<RDWebResult>\n"; |