2 # Copyright (C) 2008 Michal Vaner (vorner@ucw.cz)
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # he Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 package PciIds::Html::Handler;
23 use PciIds::Html::Tables;
24 use PciIds::Html::Util;
25 use PciIds::Html::List;
26 use PciIds::Html::Users;
27 use PciIds::Html::Debug;
28 use PciIds::Html::Changes;
29 use PciIds::Html::Admin;
30 use PciIds::Html::Notifications;
31 use PciIds::Html::Help;
32 use PciIds::Html::Jump;
33 use Apache2::Const qw(:common :http);
36 my $dbh = connectDb();
37 my $tables = PciIds::Html::Tables::new( $dbh );
41 'list' => \&PciIds::Html::List::list,#List items
42 '' => \&PciIds::Html::List::list,
44 'newitem' => \&PciIds::Html::Changes::newItemForm,
45 'newhistory' => \&PciIds::Html::Changes::newHistoryForm,
47 'register' => \&PciIds::Html::Users::registerForm,
48 'register-confirm' => \&PciIds::Html::Users::confirmForm,
50 'login' => \&PciIds::Html::Users::loginForm,
51 'logout' => \&PciIds::Html::Users::logout,
52 'respass' => \&PciIds::Html::Users::resetPasswdForm,
53 'respass-confirm' => \&PciIds::Html::Users::resetPasswdConfirmForm,
55 'profile' => \&PciIds::Html::Users::profileForm,
57 'admin' => \&PciIds::Html::Admin::adminForm,
59 'test' => \&PciIds::Html::Debug::test,
61 'notifications' => \&PciIds::Html::Notifications::notifForm,
62 'help' => \&PciIds::Html::Help::getHelp
65 'newitem' => \&PciIds::Html::Changes::newItemSubmit,
66 'newhistory' => \&PciIds::Html::Changes::newHistorySubmit,
67 'register' => \&PciIds::Html::Users::registerSubmit,
68 'register-confirm' => \&PciIds::Html::Users::confirmSubmit,
69 'login' => \&PciIds::Html::Users::loginSubmit,
70 'respass' => \&PciIds::Html::Users::resetPasswdFormSubmit,
71 'respass-confirm' => \&PciIds::Html::Users::resetPasswdConfirmFormSubmit,
72 'profile' => \&PciIds::Html::Users::profileFormSubmit,
73 'admin' => \&PciIds::Html::Admin::submitAdminForm,
74 'notifications' => \&PciIds::Html::Notifications::notifFormSubmit,
75 'jump' => \&PciIds::Html::Jump::jump,
76 'help' => \&PciIds::Html::Help::getHelp
81 my( $req, $hasSSL ) = @_;
82 my $args = parseArgs( $req->args() );
83 return HTTPRedirect( $req, protoName( $hasSSL ).'://'.$req->hostname().'/index.html' ) if( $req->uri() eq '/' && ( !defined $args->{'action'} || ( $args->{'action'} ne 'help' && $args->{'action'} ne 'jump' ) ) );
84 return DECLINED if( $req->uri() =~ /^\/((static)\/|robots.txt|index.html)/ );
85 my $action = $args->{'action'};
86 $action = '' unless( defined $action );
87 return HTTPRedirect( $req, protoName( $hasSSL ).'://'.$req->hostname().'/' ) if $req->uri() =~ /^\/(read|mods)\/?$/ && ( $action eq '' || $action eq 'list' );
88 my $method = $handlers{$req->method()};
89 return HTTP_METHOD_NOT_ALLOWED unless( defined $method );#Can't handle this method
90 my $sub = $method->{$action};
91 return HTTP_BAD_REQUEST unless( defined $sub );#I do not know this action for given method
92 my $auth = checkLogin( $req, $tables );#Check if logged in
93 $auth->{'ssl'} = $hasSSL;
96 $result = &{$sub}( $req, $args, $tables, $auth );#Just do the right thing