1 package PciIds::Html::Handler;
5 use PciIds::Html::Tables;
6 use PciIds::Html::Util;
7 use PciIds::Html::List;
8 use PciIds::Html::Users;
9 use PciIds::Html::Debug;
10 use PciIds::Html::Changes;
11 use PciIds::Html::Admin;
12 use PciIds::Html::Notifications;
13 use PciIds::Html::Help;
14 use PciIds::Html::Jump;
15 use Apache2::Const qw(:common :http);
18 my $dbh = connectDb();
19 my $tables = PciIds::Html::Tables::new( $dbh );
23 'list' => \&PciIds::Html::List::list,#List items
24 '' => \&PciIds::Html::List::list,
26 'newitem' => \&PciIds::Html::Changes::newItemForm,
27 'newhistory' => \&PciIds::Html::Changes::newHistoryForm,
29 'register' => \&PciIds::Html::Users::registerForm,
30 'register-confirm' => \&PciIds::Html::Users::confirmForm,
32 'login' => \&PciIds::Html::Users::loginForm,
33 'logout' => \&PciIds::Html::Users::logout,
34 'respass' => \&PciIds::Html::Users::resetPasswdForm,
35 'respass-confirm' => \&PciIds::Html::Users::resetPasswdConfirmForm,
37 'profile' => \&PciIds::Html::Users::profileForm,
39 'admin' => \&PciIds::Html::Admin::adminForm,
41 'test' => \&PciIds::Html::Debug::test,
43 'notifications' => \&PciIds::Html::Notifications::notifForm,
44 'help' => \&PciIds::Html::Help::getHelp
47 'newitem' => \&PciIds::Html::Changes::newItemSubmit,
48 'newhistory' => \&PciIds::Html::Changes::newHistorySubmit,
49 'register' => \&PciIds::Html::Users::registerSubmit,
50 'register-confirm' => \&PciIds::Html::Users::confirmSubmit,
51 'login' => \&PciIds::Html::Users::loginSubmit,
52 'respass' => \&PciIds::Html::Users::resetPasswdFormSubmit,
53 'respass-confirm' => \&PciIds::Html::Users::resetPasswdConfirmFormSubmit,
54 'profile' => \&PciIds::Html::Users::profileFormSubmit,
55 'admin' => \&PciIds::Html::Admin::submitAdminForm,
56 'notifications' => \&PciIds::Html::Notifications::notifFormSubmit,
57 'jump' => \&PciIds::Html::Jump::jump,
58 'help' => \&PciIds::Html::Help::getHelp
63 my( $req, $hasSSL ) = @_;
64 my $args = parseArgs( $req->args() );
65 return HTTPRedirect( $req, $req->uri()."index.html" ) if( $req->uri() eq '/' && ( !defined $args->{'action'} || $args->{'action'} ne 'help' ) );
66 return DECLINED if( $req->uri() =~ /^\/((static)\/|robots.txt|index.html)/ );
67 my $action = $args->{'action'};
68 $action = '' unless( defined $action );
69 my $method = $handlers{$req->method()};
70 return HTTP_METHOD_NOT_ALLOWED unless( defined $method );#Can't handle this method
71 my $sub = $method->{$action};
72 return HTTP_BAD_REQUEST unless( defined $sub );#I do not know this action for given method
73 my $auth = checkLogin( $req, $tables );#Check if logged in
74 $auth->{'ssl'} = $hasSSL;
77 $result = &{$sub}( $req, $args, $tables, $auth );#Just do the right thing