1 package SL::Dispatcher;
5 use CGI qw( -no_xhtml);
6 use English qw(-no_match_vars);
17 sub pre_request_checks {
18 show_error('login/auth_db_unreachable') unless $::auth->session_tables_present;
19 $::auth->expire_sessions;
23 $::lxdebug->enter_sub;
25 my $error_type = shift || '';
26 my $locale = Locale->new($::language, 'all');
27 $::form->{error} = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
28 $::form->{error} = $::locale->text('Incorrect password!.') if ($error_type eq 'password');
29 $::myconfig{countrycode} = $::language;
30 $::form->{stylesheet} = 'css/lx-office-erp.css';
33 print $::form->parse_html_template($template);
34 $::lxdebug->leave_sub;
39 sub pre_startup_setup {
42 require "config/lx-erp.conf";
46 require "config/lx-erp-local.conf";
47 } if -f "config/lx-erp-local.conf";
51 require "bin/mozilla/common.pl";
52 require "bin/mozilla/installationcheck.pl";
58 $::userspath = "users";
59 $::templates = "templates";
60 $::memberfile = "users/members";
61 $::sendmail = "| /usr/sbin/sendmail -t";
62 $::lxdebug = LXDebug->new;
63 $::auth = SL::Auth->new;
68 sub pre_startup_checks {
69 ::verify_installation();
77 sub require_main_code {
78 my ($script, $suffix) = @_;
82 require "bin/mozilla/$script$suffix";
85 if (-f "bin/mozilla/custom_$script$suffix") {
88 require "bin/mozilla/custom_$script$suffix";
90 $::form->error($EVAL_ERROR) if ($EVAL_ERROR);
92 if ($::form->{login} && -f "bin/mozilla/$::form->{login}_$::form->{script}") {
95 require "bin/mozilla/$::form->{login}_$::form->{script}";
97 $::form->error($EVAL_ERROR) if ($EVAL_ERROR);
102 $::lxdebug->enter_sub;
103 $::lxdebug->begin_request;
105 my $interface = lc(shift || 'cgi');
108 if ($interface =~ m/^(?:fastcgi|fcgid|fcgi)$/) {
109 $script_name = $ENV{SCRIPT_NAME};
110 unrequire_bin_mozilla();
116 my ($script, $path, $suffix) = fileparse($script_name, ".pl");
117 require_main_code($script, $suffix);
119 $::cgi = CGI->new('');
120 $::locale = Locale->new($::language, $script);
122 $::form->{script} = $script . $suffix;
124 pre_request_checks();
127 if ($script eq 'login' or $script eq 'admin' or $script eq 'kopf') {
128 $::form->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $::form->{version}";
129 ::run($::auth->restore_session);
131 } elsif ($::form->{action}) {
132 # copy from am.pl routines
133 $::form->error($::locale->text('System currently down for maintenance!')) if -e "$main::userspath/nologin" && $script ne 'admin';
135 my $session_result = $::auth->restore_session;
137 show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result;
138 %::myconfig = $::auth->read_user($::form->{login});
140 show_error('login/password_error', 'password') unless $::myconfig{login};
142 $::locale = Locale->new($::myconfig{countrycode}, $script);
144 show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($::form->{login}, $::form->{password}, 0);
146 $::auth->set_session_value('login', $::form->{login}, 'password', $::form->{password});
147 $::auth->create_or_refresh_session;
148 delete $::form->{password};
150 map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset)
151 unless $::form->{action} eq 'save' && $::form->{type} eq 'preferences';
153 $::form->set_standard_title;
154 ::call_sub('::' . $::locale->findsub($::form->{action}));
157 $::form->error($::locale->text('action= not defined!'));
162 $::form->{label_error} = $::cgi->pre($EVAL_ERROR);
163 show_error('generic/error');
171 $::lxdebug->end_request;
172 $::lxdebug->leave_sub;
175 sub unrequire_bin_mozilla {
177 next unless m#^bin/mozilla/#;
178 next if /\bcommon.pl$/;
179 next if /\binstallationcheck.pl$/;