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
62 my( $req, $hasSSL ) = @_;
63 my $args = parseArgs( $req->args() );
64 return HTTPRedirect( $req, $req->uri()."index.html" ) if( $req->uri() eq '/' && ( !defined $args->{'action'} || $args->{'action'} ne 'help' ) );
65 return DECLINED if( $req->uri() =~ /^\/((static)\/|robots.txt|index.html)/ );
66 my $action = $args->{'action'};
67 $action = '' unless( defined $action );
68 my $method = $handlers{$req->method()};
69 return HTTP_METHOD_NOT_ALLOWED unless( defined $method );#Can't handle this method
70 my $sub = $method->{$action};
71 return HTTP_BAD_REQUEST unless( defined $sub );#I do not know this action for given method
72 my $auth = checkLogin( $req, $tables );#Check if logged in
73 $auth->{'ssl'} = $hasSSL;
76 $result = &{$sub}( $req, $args, $tables, $auth );#Just do the right thing