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 Apache2::Const qw(:common :http);
17 our @EXPORT = qw(&callHandler);
20 my $dbh = connectDb();
21 my $tables = PciIds::Html::Tables::new( $dbh );
25 'list' => \&PciIds::Html::List::list,#List items
26 '' => \&PciIds::Html::List::list,
28 'newitem' => \&PciIds::Html::Changes::newItemForm,
29 'newhistory' => \&PciIds::Html::Changes::newHistoryForm,
31 'register' => \&PciIds::Html::Users::registerForm,
32 'register-confirm' => \&PciIds::Html::Users::confirmForm,
34 'login' => \&PciIds::Html::Users::loginForm,
35 'logout' => \&PciIds::Html::Users::logout,
36 'respass' => \&PciIds::Html::Users::resetPasswdForm,
37 'respass-confirm' => \&PciIds::Html::Users::resetPasswdConfirmForm,
39 'profile' => \&PciIds::Html::Users::profileForm,
41 'admin' => \&PciIds::Html::Admin::adminForm,
43 'test' => \&PciIds::Html::Debug::test,
45 'notifications' => \&PciIds::Html::Notifications::notifForm,
46 'help' => \&PciIds::Html::Help::getHelp
49 'newitem' => \&PciIds::Html::Changes::newItemSubmit,
50 'newhistory' => \&PciIds::Html::Changes::newHistorySubmit,
51 'register' => \&PciIds::Html::Users::registerSubmit,
52 'register-confirm' => \&PciIds::Html::Users::confirmSubmit,
53 'login' => \&PciIds::Html::Users::loginSubmit,
54 'respass' => \&PciIds::Html::Users::resetPasswdFormSubmit,
55 'respass-confirm' => \&PciIds::Html::Users::resetPasswdConfirmFormSubmit,
56 'profile' => \&PciIds::Html::Users::profileFormSubmit,
57 'admin' => \&PciIds::Html::Admin::submitAdminForm,
58 'notifications' => \&PciIds::Html::Notifications::notifFormSubmit
62 sub callHandler( $$$$$$ ) {
63 my( $req, $args, $tables, $auth, $hasSSL, $meth ) = @_;
64 my $action = $args->{'action'};
65 $action = '' unless( defined $action );
66 my $method = $handlers{$meth};
67 return HTTP_METHOD_NOT_ALLOWED unless( defined $method );#Can't handle this method
68 my $sub = $method->{$action};
69 return HTTP_BAD_REQUEST unless( defined $sub );#I do not know this action for given method
70 $auth = checkLogin( $req, $tables ) unless defined $auth;#Check if logged in
71 $auth->{'ssl'} = $hasSSL;
72 return &{$sub}( $req, $args, $tables, $auth );#Just do the right thing
76 my( $req, $hasSSL ) = @_;
77 my $args = parseArgs( $req->args() );
78 return HTTPRedirect( $req, $req->uri()."index.html" ) if( $req->uri() eq '/' && ( !defined $args->{'action'} || $args->{'action'} ne 'help' ) );
79 return DECLINED if( $req->uri() =~ /^\/((static)\/|robots.txt|index.html)/ );
82 $result = callHandler( $req, $args, $tables, undef, $hasSSL, $req->method() );