3 ######################################################################
4 # SQL-Ledger Accounting
7 # Author: Dieter Simader
8 # Email: dsimader@sql-ledger.org
9 # Web: http://www.sql-ledger.org
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #######################################################################
27 # this script is the frontend called from bin/$terminal/$script
28 # all the accounting modules are linked to this script which in
29 # turn execute the same script in bin/$terminal/
31 #######################################################################
35 use Time::HiRes qw(gettimeofday tv_interval);
40 unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
41 push @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
43 $time = [gettimeofday];
46 # setup defaults, DO NOT CHANGE
47 $main::userspath = "users";
48 $main::templates = "templates";
49 $main::memberfile = "users/members";
50 $main::sendmail = "| /usr/sbin/sendmail -t";
51 ########## end ###########################################
56 $main::lxdebug = LXDebug->new();
58 use CGI qw( -no_xhtml);
63 eval { require "config/lx-erp.conf"; };
64 eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
66 our $cgi = new CGI('');
69 our $auth = SL::Auth->new();
70 if (!$auth->session_tables_present()) {
71 _show_error('login/auth_db_unreachable');
73 $auth->expire_sessions();
74 my $session_result = $auth->restore_session();
76 require "bin/mozilla/common.pl";
78 if (defined($main::latex) && !defined($main::latex_templates)) {
79 $main::latex_templates = $main::latex;
83 # this prevents most of the tabindexes being created by CGI.
84 # note: most. popup menus and selecttables will still have tabindexes
85 # use common.pl's NTI function to get rid of those
86 local $CGI::TABINDEX = 0;
90 my $pos = rindex $0, '/';
91 my $script = substr($0, $pos + 1);
93 # we use $script for the language module
94 $form->{script} = $script;
96 # strip .pl for translation files
103 $main::locale = new Locale($main::language, "$script");
104 my $locale = $main::locale;
106 # did sysadmin lock us out
107 if (-e "$main::userspath/nologin") {
108 $form->error($locale->text('System currently down for maintenance!'));
111 if (SL::Auth::SESSION_EXPIRED == $session_result) {
112 _show_error('login/password_error', 'session');
115 $form->{login} =~ s|.*/||;
117 %main::myconfig = $auth->read_user($form->{login});
118 my %myconfig = %main::myconfig;
120 if (!$myconfig{login}) {
121 _show_error('login/password_error', 'password');
125 $locale = new Locale "$myconfig{countrycode}", "$script";
127 if (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0)) {
128 _show_error('login/password_error', 'password');
131 $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
132 $auth->create_or_refresh_session();
134 delete $form->{password};
136 map { $form->{$_} = $myconfig{$_} } qw(stylesheet charset)
137 unless (($form->{action} eq 'save') && ($form->{type} eq 'preferences'));
139 # pull in the main code
140 require "bin/mozilla/$form->{script}";
143 if (-f "bin/mozilla/custom_$form->{script}") {
144 eval { require "bin/mozilla/custom_$form->{script}"; };
145 $form->error($@) if ($@);
148 # customized scripts for login
149 if (-f "bin/mozilla/$form->{login}_$form->{script}") {
150 eval { require "bin/mozilla/$form->{login}_$form->{script}"; };
151 $form->error($@) if ($@);
154 if ($form->{action}) {
156 # window title bar, user info
159 . $locale->text('Version')
160 . " $form->{version} - $myconfig{name} - $myconfig{dbname}";
162 call_sub($locale->findsub($form->{action}));
164 $form->error($locale->text('action= not defined!'));
168 my $template = shift;
169 my $error_type = shift;
170 my $locale = Locale->new($main::language, 'all');
171 $form->{error} = $locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
172 $form->{error} = $locale->text('Incorrect password!.') if ($error_type eq 'password');
173 $myconfig{countrycode} = $main::language;
174 $form->{stylesheet} = 'css/lx-office-erp.css';
177 print $form->parse_html_template($template);
182 print "<!-- time elapsed: ", tv_interval($time), "s -->";