X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDispatcher.pm;h=17aaab0c699cb22b6891a8385a34f61f2fed69ea;hb=590708a7a8d02ecd60267271f276e975c08d56c6;hp=1292f280c204978ea02cca20b0cf60ff77c13f27;hpb=2ee964a6f3f95f99120b758fd1fee3bdb3f27880;p=kivitendo-erp.git diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index 1292f280c..17aaab0c6 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -25,7 +25,7 @@ use English qw(-no_match_vars); use File::Basename; use List::MoreUtils qw(all); use List::Util qw(first); -use POSIX; +use SL::ArchiveZipFixes; use SL::Auth; use SL::Dispatcher::AuthHandler; use SL::LXDebug; @@ -37,6 +37,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. @@ -51,6 +52,8 @@ sub new { $self->{interface} = lc($interface || 'cgi'); $self->{auth_handler} = SL::Dispatcher::AuthHandler->new; + SL::ArchiveZipFixes->apply_fixes; + return $self; } @@ -78,6 +81,36 @@ sub pre_request_checks { } } +sub pre_request_initialization { + my ($self, %params) = @_; + + $self->unrequire_bin_mozilla; + + $::locale = Locale->new($::lx_office_conf{system}->{language}); + $::form = Form->new; + $::instance_conf = SL::InstanceConfiguration->new; + $::request = SL::Request->new( + cgi => CGI->new({}), + layout => SL::Layout::None->new, + ); + + my $session_result = $::auth->restore_session; + $::auth->create_or_refresh_session; + + if ($params{client}) { + $::auth->set_client($params{client}) || die("cannot find client " . $params{client}); + + if ($params{login}) { + die "cannot find user " . $params{login} unless %::myconfig = $::auth->read_user(login => $params{login}); + die "cannot find locale for user " . $params{login} unless $::locale = Locale->new($::myconfig{countrycode}); + + $::form->{login} = $params{login}; # normaly implicit at login + } + } + + return $session_result; +} + sub render_error_ajax { my ($error) = @_; @@ -96,6 +129,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; @@ -123,8 +157,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 { @@ -196,23 +230,12 @@ sub handle_request { my ($script, $path, $suffix, $script_name, $action, $routing_type); - $self->unrequire_bin_mozilla; - - $::locale = Locale->new($::lx_office_conf{system}->{language}); - $::form = Form->new; - $::instance_conf = SL::InstanceConfiguration->new; - $::request = SL::Request->new( - cgi => CGI->new({}), - layout => SL::Layout::None->new, - ); - - my $session_result = $::auth->restore_session; - $::auth->create_or_refresh_session; + my $session_result = $self->pre_request_initialization; $::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); @@ -251,7 +274,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'); } @@ -267,8 +290,6 @@ sub handle_request { delete @{ $::form }{ grep { m/^\{AUTH\}/ } keys %{ $::form } } unless $auth_result{keep_auth_vars}; if ($action) { - $::instance_conf->init if $auth_result{auth_level} eq 'user'; - $::form->set_standard_title; if ($routing_type eq 'old') { ::call_sub('::' . $::locale->findsub($action)); @@ -316,8 +337,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(); } @@ -340,19 +363,20 @@ 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); eval { - die "Unroutable request -- inavlid module name.\n" if !$::form->{M} || ($::form->{M} !~ m/^${name_re}$/); + die "Unroutable request -- invalid module name.\n" if !$::form->{M} || ($::form->{M} !~ m/^${name_re}$/); $script_name = $::form->{M} . '.pl'; if ($::form->{A}) { @@ -360,7 +384,7 @@ sub _route_dispatcher_request { } else { $action = first { m/^A_${name_re}$/ } keys %{ $::form }; - die "Unroutable request -- inavlid action name.\n" if !$action; + die "Unroutable request -- invalid action name.\n" if !$action; delete $::form->{$action}; $action = substr $action, 2; @@ -378,10 +402,17 @@ sub _route_dispatcher_request { } sub _route_controller_request { + my ($self) = @_; my ($controller, $action, $request_type); eval { - $::form->{action} =~ m|^ ( [A-Z] [A-Za-z0-9_]* ) / ( [a-z] [a-z0-9_]* ) ( \. [a-zA-Z]+ )? $|x || die "Unroutable request -- inavlid controller/action.\n"; + # 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};