X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDispatcher.pm;h=43d6fa75748bc028421e12a1b620d085c628e514;hb=9052a0482c67ea9ac1f862f3474c93e683ccae68;hp=854b863a3f4e8fcc9b1a319ef5afe02040d9eeaf;hpb=99601196d8e8438871fd5a814a0cd802c6fd5d68;p=kivitendo-erp.git diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index 854b863a3..43d6fa757 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -38,6 +38,7 @@ use SL::Form; use SL::Helper::DateTime; use SL::InstanceConfiguration; use SL::Template::Plugin::HTMLFixes; +use SL::User; # Trailing new line is added so that Perl will not add the line # number 'die' was called in. @@ -105,8 +106,6 @@ sub pre_request_initialization { die "cannot find locale for user " . $params{login} unless $::locale = Locale->new($::myconfig{countrycode}); $::form->{login} = $params{login}; # normaly implicit at login - - $::instance_conf->init; } } @@ -131,6 +130,7 @@ sub show_error { $::locale = Locale->new($::myconfig{countrycode}); $::form->{error} = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session'); $::form->{error} = $::locale->text('Incorrect password!') if ($error_type eq 'password'); + $::form->{error} = $::locale->text('The action is missing or invalid.') if ($error_type eq 'action'); return render_error_ajax($::form->{error}) if $::request->is_ajax; @@ -158,8 +158,8 @@ sub pre_startup_setup { $::lxdebug = LXDebug->new; $::auth = SL::Auth->new; $::form = undef; - %::myconfig = (); $::request = undef; + %::myconfig = User->get_default_myconfig; } $SIG{__WARN__} = sub { @@ -236,7 +236,7 @@ sub handle_request { $::form->read_cgi_input; my %routing; - eval { %routing = _route_request($ENV{SCRIPT_NAME}); 1; } or return; + eval { %routing = $self->_route_request($ENV{SCRIPT_NAME}); 1; } or return; ($routing_type, $script_name, $action) = @routing{qw(type controller action)}; $::lxdebug->log_request($routing_type, $script_name, $action); @@ -275,7 +275,7 @@ sub handle_request { if ( (($script eq 'login') && !$action) || ($script eq 'admin') || (SL::Auth::SESSION_EXPIRED() == $session_result)) { - $self->redirect_to_login($script); + $self->redirect_to_login(script => $script, error => 'session'); } @@ -338,8 +338,10 @@ sub handle_request { } sub redirect_to_login { - my ($self, $script) = @_; - my $action = $script =~ m/^admin/i ? 'Admin/login' : 'LoginScreen/user_login&error=session'; + my ($self, %params) = @_; + my $action = ($params{script} // '') =~ m/^admin/i ? 'Admin/login' : 'LoginScreen/user_login'; + $action .= '&error=' . $params{error} if $params{error}; + print $::request->cgi->redirect("controller.pl?action=${action}"); ::end_of_request(); } @@ -362,14 +364,15 @@ sub _interface_is_fcgi { } sub _route_request { - my $script_name = shift; + my ($self, $script_name) = @_; - return $script_name =~ m/dispatcher\.pl$/ ? (type => 'old', _route_dispatcher_request()) - : $script_name =~ m/controller\.pl/ ? (type => 'controller', _route_controller_request()) + return $script_name =~ m/dispatcher\.pl$/ ? (type => 'old', $self->_route_dispatcher_request) + : $script_name =~ m/controller\.pl/ ? (type => 'controller', $self->_route_controller_request) : (type => 'old', controller => $script_name, action => $::form->{action}); } sub _route_dispatcher_request { + my ($self) = @_; my $name_re = qr{[a-z]\w*}; my ($script_name, $action); @@ -400,9 +403,16 @@ sub _route_dispatcher_request { } sub _route_controller_request { + my ($self) = @_; my ($controller, $action, $request_type); eval { + # Redirect simple requests to controller.pl without any GET/POST + # param to the login page. + $self->redirect_to_login(error => 'action') if !$::form->{action}; + + # Show an error if the »action« parameter doesn't match the + # pattern »Controller/action«. $::form->{action} =~ m|^ ( [A-Z] [A-Za-z0-9_]* ) / ( [a-z] [a-z0-9_]* ) ( \. [a-zA-Z]+ )? $|x || die "Unroutable request -- invalid controller/action.\n"; ($controller, $action) = ($1, $2); delete $::form->{action};