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
12 use CGI qw( -no_xhtml);
23 my ($script, $path, $suffix) = fileparse($0, ".pl");
24 my $request = FCGI::Request();
26 eval { require "config/lx-erp.conf"; };
27 eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
28 require "bin/mozilla/common.pl";
29 require "bin/mozilla/installationcheck.pl";
30 require_main_code($script, $suffix);
35 $::userspath = "users";
36 $::templates = "templates";
37 $::memberfile = "users/members";
38 $::sendmail = "| /usr/sbin/sendmail -t";
39 $::lxdebug = LXDebug->new;
40 $::auth = SL::Auth->new;
44 _pre_startup_checks();
46 if ($request->IsFastCGI) {
47 handle_request() while $request->Accept() >= 0;
55 $::lxdebug->enter_sub;
56 $::lxdebug->begin_request;
57 $::cgi = CGI->new('');
58 $::locale = Locale->new($::language, $script);
60 $::form->{script} = $script . $suffix;
62 _pre_request_checks();
65 if ($script eq 'login' or $script eq 'admin' or $script eq 'kopf') {
66 $::form->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $::form->{version}";
67 run($::auth->restore_session);
68 } elsif ($::form->{action}) {
69 # copy from am.pl routines
70 $::form->error($::locale->text('System currently down for maintenance!')) if -e "$main::userspath/nologin" && $script ne 'admin';
72 my $session_result = $::auth->restore_session;
74 _show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result;
75 %::myconfig = $::auth->read_user($::form->{login});
77 _show_error('login/password_error', 'password') unless $::myconfig{login};
79 $::locale = Locale->new($::myconfig{countrycode}, $script);
81 _show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($::form->{login}, $::form->{password}, 0);
83 $::auth->set_session_value('login', $::form->{login}, 'password', $::form->{password});
84 $::auth->create_or_refresh_session;
85 delete $::form->{password};
87 map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset)
88 unless $::form->{action} eq 'save' && $::form->{type} eq 'preferences';
90 $::form->set_standard_title;
91 call_sub($::locale->findsub($::form->{action}));
93 $::form->error($::locale->text('action= not defined!'));
102 $::lxdebug->end_request;
103 $::lxdebug->leave_sub;
106 sub _pre_request_checks {
107 _show_error('login/auth_db_unreachable') unless $::auth->session_tables_present;
108 $::auth->expire_sessions;
112 $::lxdebug->enter_sub;
113 my $template = shift;
114 my $error_type = shift;
115 my $locale = Locale->new($::language, 'all');
116 $::form->{error} = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
117 $::form->{error} = $::locale->text('Incorrect password!.') if ($error_type eq 'password');
118 $::myconfig{countrycode} = $::language;
119 $::form->{stylesheet} = 'css/lx-office-erp.css';
122 print $::form->parse_html_template($template);
123 $::lxdebug->leave_sub;
128 sub _pre_startup_checks {
129 verify_installation();
132 sub require_main_code {
133 my ($script, $suffix) = @_;
135 require "bin/mozilla/$script$suffix";
137 if (-f "bin/mozilla/custom_$script$suffix") {
138 eval { require "bin/mozilla/custom_$script$suffix"; };
139 $::form->error($@) if ($@);
141 if ($::form->{login} && -f "bin/mozilla/$::form->{login}_$::form->{script}") {
142 eval { require "bin/mozilla/$::form->{login}_$::form->{script}"; };
143 $::form->error($@) if ($@);