1 package SL::Dispatcher;
6 unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
7 push @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
8 push @INC, "SL"; # FCGI won't find modules that are not properly named. Help it by inclduging SL
11 use CGI qw( -no_xhtml);
12 use English qw(-no_match_vars);
23 # Trailing new line is added so that Perl will not add the line
24 # number 'die' was called in.
25 use constant END_OF_REQUEST => "END-OF-REQUEST\n";
27 sub pre_request_checks {
28 show_error('login/auth_db_unreachable') unless $::auth->session_tables_present;
29 $::auth->expire_sessions;
33 $::lxdebug->enter_sub;
35 my $error_type = shift || '';
36 my $locale = Locale->new($::language, 'all');
37 $::form->{error} = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
38 $::form->{error} = $::locale->text('Incorrect password!.') if ($error_type eq 'password');
39 $::myconfig{countrycode} = $::language;
40 $::form->{stylesheet} = 'css/lx-office-erp.css';
43 print $::form->parse_html_template($template);
44 $::lxdebug->leave_sub;
49 sub pre_startup_setup {
52 require "config/lx-erp.conf";
56 require "config/lx-erp-local.conf";
57 } if -f "config/lx-erp-local.conf";
61 require "bin/mozilla/common.pl";
62 require "bin/mozilla/installationcheck.pl";
68 $::userspath = "users";
69 $::templates = "templates";
70 $::memberfile = "users/members";
71 $::sendmail = "| /usr/sbin/sendmail -t";
72 $::lxdebug = LXDebug->new;
73 $::auth = SL::Auth->new;
78 sub pre_startup_checks {
79 ::verify_installation();
87 sub require_main_code {
88 my ($script, $suffix) = @_;
92 require "bin/mozilla/$script$suffix";
95 if (-f "bin/mozilla/custom_$script$suffix") {
98 require "bin/mozilla/custom_$script$suffix";
100 $::form->error($EVAL_ERROR) if ($EVAL_ERROR);
102 if ($::form->{login} && -f "bin/mozilla/$::form->{login}_$::form->{script}") {
105 require "bin/mozilla/$::form->{login}_$::form->{script}";
107 $::form->error($EVAL_ERROR) if ($EVAL_ERROR);
112 $::lxdebug->enter_sub;
113 $::lxdebug->begin_request;
115 my $interface = lc(shift || 'cgi');
118 if ($interface =~ m/^(?:fastcgi|fcgid|fcgi)$/) {
119 $script_name = $ENV{SCRIPT_NAME};
120 unrequire_bin_mozilla();
126 my ($script, $path, $suffix) = fileparse($script_name, ".pl");
127 require_main_code($script, $suffix);
129 $::cgi = CGI->new('');
130 $::locale = Locale->new($::language, $script);
132 $::form->{script} = $script . $suffix;
134 pre_request_checks();
137 if ($script eq 'login' or $script eq 'admin' or $script eq 'kopf') {
138 $::form->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $::form->{version}";
139 ::run($::auth->restore_session);
141 } elsif ($::form->{action}) {
142 # copy from am.pl routines
143 $::form->error($::locale->text('System currently down for maintenance!')) if -e "$main::userspath/nologin" && $script ne 'admin';
145 my $session_result = $::auth->restore_session;
147 show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result;
148 %::myconfig = $::auth->read_user($::form->{login});
150 show_error('login/password_error', 'password') unless $::myconfig{login};
152 $::locale = Locale->new($::myconfig{countrycode}, $script);
154 show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($::form->{login}, $::form->{password}, 0);
156 $::auth->set_session_value('login', $::form->{login}, 'password', $::form->{password});
157 $::auth->create_or_refresh_session;
158 delete $::form->{password};
160 map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset)
161 unless $::form->{action} eq 'save' && $::form->{type} eq 'preferences';
163 $::form->set_standard_title;
164 ::call_sub('::' . $::locale->findsub($::form->{action}));
167 $::form->error($::locale->text('action= not defined!'));
172 if ($EVAL_ERROR ne END_OF_REQUEST) {
173 $::form->{label_error} = $::cgi->pre($EVAL_ERROR);
174 eval { show_error('generic/error') };
182 Form::disconnect_standard_dbh();
184 $::lxdebug->end_request;
185 $::lxdebug->leave_sub;
188 sub unrequire_bin_mozilla {
190 next unless m#^bin/mozilla/#;
191 next if /\bcommon.pl$/;
192 next if /\binstallationcheck.pl$/;
202 die SL::Dispatcher->END_OF_REQUEST;