1 package SL::Dispatcher;
5 use CGI qw( -no_xhtml);
6 use English qw(-no_match_vars);
17 # Trailing new line is added so that Perl will not add the line
18 # number 'die' was called in.
19 use constant END_OF_REQUEST => "END-OF-REQUEST\n";
21 sub pre_request_checks {
22 show_error('login/auth_db_unreachable') unless $::auth->session_tables_present;
23 $::auth->expire_sessions;
27 $::lxdebug->enter_sub;
29 my $error_type = shift || '';
30 my $locale = Locale->new($::language, 'all');
31 $::form->{error} = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
32 $::form->{error} = $::locale->text('Incorrect password!.') if ($error_type eq 'password');
33 $::myconfig{countrycode} = $::language;
34 $::form->{stylesheet} = 'css/lx-office-erp.css';
37 print $::form->parse_html_template($template);
38 $::lxdebug->leave_sub;
43 sub pre_startup_setup {
46 require "config/lx-erp.conf";
50 require "config/lx-erp-local.conf";
51 } if -f "config/lx-erp-local.conf";
55 require "bin/mozilla/common.pl";
56 require "bin/mozilla/installationcheck.pl";
62 $::userspath = "users";
63 $::templates = "templates";
64 $::memberfile = "users/members";
65 $::sendmail = "| /usr/sbin/sendmail -t";
66 $::lxdebug = LXDebug->new;
67 $::auth = SL::Auth->new;
72 sub pre_startup_checks {
73 ::verify_installation();
81 sub require_main_code {
82 my ($script, $suffix) = @_;
86 require "bin/mozilla/$script$suffix";
89 if (-f "bin/mozilla/custom_$script$suffix") {
92 require "bin/mozilla/custom_$script$suffix";
94 $::form->error($EVAL_ERROR) if ($EVAL_ERROR);
96 if ($::form->{login} && -f "bin/mozilla/$::form->{login}_$::form->{script}") {
99 require "bin/mozilla/$::form->{login}_$::form->{script}";
101 $::form->error($EVAL_ERROR) if ($EVAL_ERROR);
106 $::lxdebug->enter_sub;
107 $::lxdebug->begin_request;
109 my $interface = lc(shift || 'cgi');
112 if ($interface =~ m/^(?:fastcgi|fcgid|fcgi)$/) {
113 $script_name = $ENV{SCRIPT_NAME};
114 unrequire_bin_mozilla();
120 my ($script, $path, $suffix) = fileparse($script_name, ".pl");
121 require_main_code($script, $suffix);
123 $::cgi = CGI->new('');
124 $::locale = Locale->new($::language, $script);
126 $::form->{script} = $script . $suffix;
128 pre_request_checks();
131 if ($script eq 'login' or $script eq 'admin' or $script eq 'kopf') {
132 $::form->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $::form->{version}";
133 ::run($::auth->restore_session);
135 } elsif ($::form->{action}) {
136 # copy from am.pl routines
137 $::form->error($::locale->text('System currently down for maintenance!')) if -e "$main::userspath/nologin" && $script ne 'admin';
139 my $session_result = $::auth->restore_session;
141 show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result;
142 %::myconfig = $::auth->read_user($::form->{login});
144 show_error('login/password_error', 'password') unless $::myconfig{login};
146 $::locale = Locale->new($::myconfig{countrycode}, $script);
148 show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($::form->{login}, $::form->{password}, 0);
150 $::auth->set_session_value('login', $::form->{login}, 'password', $::form->{password});
151 $::auth->create_or_refresh_session;
152 delete $::form->{password};
154 map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset)
155 unless $::form->{action} eq 'save' && $::form->{type} eq 'preferences';
157 $::form->set_standard_title;
158 ::call_sub('::' . $::locale->findsub($::form->{action}));
161 $::form->error($::locale->text('action= not defined!'));
166 if ($EVAL_ERROR ne END_OF_REQUEST) {
167 $::form->{label_error} = $::cgi->pre($EVAL_ERROR);
168 eval { show_error('generic/error') };
177 $::lxdebug->end_request;
178 $::lxdebug->leave_sub;
181 sub unrequire_bin_mozilla {
183 next unless m#^bin/mozilla/#;
184 next if /\bcommon.pl$/;
185 next if /\binstallationcheck.pl$/;
195 die SL::Dispatcher->END_OF_REQUEST;