X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=PciIds%2FHtml%2FHandler.pm;h=f9ca889e5dd2830b303ac5e642ab7f2a3fd89911;hb=d2935a5e76ef0e5a2f3a15e80b2649a2913581e5;hp=dd996ffd5b27ee674ec6e6bbdb525c8fd941e090;hpb=e2913d760e33eaaf45c09e8e0aa052fb0eca649e;p=pciids.git diff --git a/PciIds/Html/Handler.pm b/PciIds/Html/Handler.pm index dd996ff..f9ca889 100644 --- a/PciIds/Html/Handler.pm +++ b/PciIds/Html/Handler.pm @@ -1,3 +1,21 @@ +# PciIds web database +# Copyright (C) 2008 Michal Vaner (vorner@ucw.cz) +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# he Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + package PciIds::Html::Handler; use strict; use warnings; @@ -10,7 +28,8 @@ use PciIds::Html::Debug; use PciIds::Html::Changes; use PciIds::Html::Admin; use PciIds::Html::Notifications; -use PciIds::Notifications; +use PciIds::Html::Help; +use PciIds::Html::Jump; use Apache2::Const qw(:common :http); $ENV{'PATH'} = ''; @@ -23,7 +42,7 @@ my %handlers = ( '' => \&PciIds::Html::List::list, #Database changes 'newitem' => \&PciIds::Html::Changes::newItemForm, - 'newcomment' => \&PciIds::Html::Changes::newCommentForm, + 'newhistory' => \&PciIds::Html::Changes::newHistoryForm, #Registering users 'register' => \&PciIds::Html::Users::registerForm, 'register-confirm' => \&PciIds::Html::Users::confirmForm, @@ -39,11 +58,12 @@ my %handlers = ( #Some debug 'test' => \&PciIds::Html::Debug::test, #Notifications - 'notifications' => \&PciIds::Html::Notifications::notifForm + 'notifications' => \&PciIds::Html::Notifications::notifForm, + 'help' => \&PciIds::Html::Help::getHelp }, 'POST' => { 'newitem' => \&PciIds::Html::Changes::newItemSubmit, - 'newcomment' => \&PciIds::Html::Changes::newCommentSubmit, + 'newhistory' => \&PciIds::Html::Changes::newHistorySubmit, 'register' => \&PciIds::Html::Users::registerSubmit, 'register-confirm' => \&PciIds::Html::Users::confirmSubmit, 'login' => \&PciIds::Html::Users::loginSubmit, @@ -51,25 +71,35 @@ my %handlers = ( 'respass-confirm' => \&PciIds::Html::Users::resetPasswdConfirmFormSubmit, 'profile' => \&PciIds::Html::Users::profileFormSubmit, 'admin' => \&PciIds::Html::Admin::submitAdminForm, - 'notifications' => \&PciIds::Html::Notifications::notifFormSubmit + 'notifications' => \&PciIds::Html::Notifications::notifFormSubmit, + 'jump' => \&PciIds::Html::Jump::jump, + 'help' => \&PciIds::Html::Help::getHelp } ); sub handler( $$ ) { my( $req, $hasSSL ) = @_; - return HTTPRedirect( $req, $req->uri()."index.html" ) if( $req->uri() eq '/' ); - return DECLINED if( $req->uri() =~ /^\/((static)\/|robots.txt|index.html)/ ); my $args = parseArgs( $req->args() ); + return HTTPRedirect( $req, protoName( $hasSSL ).'://'.$req->hostname().'/index.html' ) if( $req->uri() eq '/' && ( !defined $args->{'action'} || ( $args->{'action'} ne 'help' && $args->{'action'} ne 'jump' ) ) ); + return DECLINED if( $req->uri() =~ /^\/((static)\/|robots.txt|index.html)/ ); my $action = $args->{'action'}; $action = '' unless( defined $action ); + return HTTPRedirect( $req, protoName( $hasSSL ).'://'.$req->hostname().'/' ) if $req->uri() =~ /^\/(read|mods)\/?$/ && ( $action eq '' || $action eq 'list' ); my $method = $handlers{$req->method()}; return HTTP_METHOD_NOT_ALLOWED unless( defined $method );#Can't handle this method my $sub = $method->{$action}; return HTTP_BAD_REQUEST unless( defined $sub );#I do not know this action for given method my $auth = checkLogin( $req, $tables );#Check if logged in $auth->{'ssl'} = $hasSSL; - my $result = &{$sub}( $req, $args, $tables, $auth );#Just do the right thing - $tables->commit(); + my( $result ); + eval { + $result = &{$sub}( $req, $args, $tables, $auth );#Just do the right thing + $tables->commit(); + }; + if( $@ ) { + $tables->rollback(); + die $@; + } return $result; }