From ff6e499692065df321dc670df37118ba7d701516 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Tue, 4 Sep 2012 22:17:32 +0200 Subject: HTTP Error handling (for 403 and 404) --- lib/FPanel/Interface.pm | 14 +++++++------- lib/FPanel/Login.pm | 40 ++++++++++++++++++++++++++-------------- template/error_http.html | 11 +++++++++++ 3 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 template/error_http.html diff --git a/lib/FPanel/Interface.pm b/lib/FPanel/Interface.pm index aa5b554..8c9ca10 100644 --- a/lib/FPanel/Interface.pm +++ b/lib/FPanel/Interface.pm @@ -42,7 +42,7 @@ sub ListDomains : StartRunmode { fripostOwner fripostPostmaster/ ] ); - die '403' if $domains->code; + die "403\n" if $domains->code; $ldap->unbind; @@ -91,10 +91,10 @@ sub ListLocals : Runmode { fripostOwner fripostPostmaster/ ] ); - die '404' if $domains->code; + die "404\n" if $domains->code; # The following is not supposed to happen. die "Error: Multible matching entries found." if $domains->count > 1; - my $domain = $domains->pop_entry or die '404'; + my $domain = $domains->pop_entry or die "404\n"; # Query the mailboxes under the given domain @@ -269,10 +269,10 @@ sub EditDomain : Runmode { , filter => 'objectClass=FripostVirtualDomain' , deref => 'never' ); - die '404' if $domains->code; + die "404\n" if $domains->code; # The following is not supposed to happen. die "Error: Multible matching entries found." if $domains->count > 1; - my $domain = $domains->pop_entry or die '404'; + my $domain = $domains->pop_entry or die "404\n"; $ldap->unbind; @@ -411,10 +411,10 @@ sub EditLocal : Runmode { fva fripostMaildrop fvl fripostListManager/ ] ); - die '404' if $locals->code; + die "404\n" if $locals->code; # The following is not supposed to happen. die "Error: Multible matching entries found." if $locals->count > 1; - my $local = $locals->pop_entry or die '404'; + my $local = $locals->pop_entry or die "404\n"; my $template; if ($local->dn =~ /^fvu=/) { diff --git a/lib/FPanel/Login.pm b/lib/FPanel/Login.pm index 173a34f..76dc5bb 100644 --- a/lib/FPanel/Login.pm +++ b/lib/FPanel/Login.pm @@ -185,24 +185,36 @@ sub logout : Runmode { return $self->redirect($self->query->self_url); } -# This is the error Run Mode. Users are not suppose to see that unless -# the CGI crashes :P +# This is the error Run Mode. sub error_rm : ErrorRunmode { my $self = shift; my $error = shift; - - my $template = $self->load_tmpl( 'error.html', cache => 1, utf8 => 1 ); - $template->param( EMAIL => $self->cfg('report_email') ); - $template->param( MESSAGE => $error ); - $template->param( URL => $self->query->url . '/'); - - return $template->output; -} -sub error_404 : Runmode { - my $self = shift; - $self->header_props ( -status => '404 Not found' ); - return ''; + if ($error =~ /^4\d+$/) { + # HTTP client error. + chomp $error; + $self->header_props ( -status => $error ); + my $template = $self->load_tmpl( 'error_http.html', cache => 1, utf8 => 1 ); + my $mesg; + if ($error eq '403' ) { + $mesg = 'Forbidden' + } + elsif ($error eq '404' ) { + $mesg = 'Not found' + } + $template->param( CODE => $error ); + $template->param( MESSAGE => $mesg ); + return $template->output; + } + + else { + # Users are not supposed to see that unless the CGI crashes :P + my $template = $self->load_tmpl( 'error.html', cache => 1, utf8 => 1 ); + $template->param( EMAIL => $self->cfg('report_email') ); + $template->param( MESSAGE => $error ); + $template->param( URL => $self->query->url . '/'); + return $template->output; + } } 1; diff --git a/template/error_http.html b/template/error_http.html new file mode 100644 index 0000000..34d444b --- /dev/null +++ b/template/error_http.html @@ -0,0 +1,11 @@ + + + + + <TMPL_IF NAME=MESSAGE><TMPL_VAR NAME=MESSAGE><TMPL_ELSE>Error</TMPL_IF> + + + +

+ + -- cgit v1.2.3