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 #######################################################################
 
  34   unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
 
  35   push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
 
  38 # setup defaults, DO NOT CHANGE
 
  40 $templates  = "templates";
 
  41 $memberfile = "users/members";
 
  42 $sendmail   = "| /usr/sbin/sendmail -t";
 
  43 ########## end ###########################################
 
  48 $lxdebug = LXDebug->new();
 
  50 use CGI qw( -no_xhtml);
 
  55 eval { require "config/lx-erp.conf"; };
 
  56 eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
 
  58 our $cgi  = new CGI('');
 
  61 our $auth = SL::Auth->new();
 
  62 if (!$auth->session_tables_present()) {
 
  63   _show_error('login/auth_db_unreachable');
 
  65 $auth->expire_sessions();
 
  66 my $session_result = $auth->restore_session();
 
  68 require "bin/mozilla/common.pl";
 
  70 if (defined($latex) && !defined($latex_templates)) {
 
  71   $latex_templates = $latex;
 
  75 # this prevents most of the tabindexes being created by CGI.
 
  76 # note: most. popup menus and selecttables will still have tabindexes
 
  77 # use common.pl's NTI function to get rid of those
 
  78 local $CGI::TABINDEX = 0;
 
  82 $pos = rindex $0, '/';
 
  83 $script = substr($0, $pos + 1);
 
  85 # we use $script for the language module
 
  86 $form->{script} = $script;
 
  88 # strip .pl for translation files
 
  95 $locale = new Locale($language, "$script");
 
  97 # did sysadmin lock us out
 
  98 if (-e "$userspath/nologin") {
 
  99   $form->error($locale->text('System currently down for maintenance!'));
 
 102 if (SL::Auth::SESSION_EXPIRED == $session_result) {
 
 103   _show_error('login/password_error', 'session');
 
 106 $form->{login} =~ s|.*/||;
 
 108 %myconfig = $auth->read_user($form->{login});
 
 110 if (!$myconfig{login}) {
 
 111   _show_error('login/password_error', 'password');
 
 115 $locale = new Locale "$myconfig{countrycode}", "$script";
 
 117 if (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0)) {
 
 118   _show_error('login/password_error', 'password');
 
 121 $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
 
 122 $auth->create_or_refresh_session();
 
 124 delete $form->{password};
 
 126 map { $form->{$_} = $myconfig{$_} } qw(stylesheet charset)
 
 127   unless (($form->{action} eq 'save') && ($form->{type} eq 'preferences'));
 
 129 # pull in the main code
 
 130 require "bin/mozilla/$form->{script}";
 
 133 if (-f "bin/mozilla/custom_$form->{script}") {
 
 134   eval { require "bin/mozilla/custom_$form->{script}"; };
 
 135   $form->error($@) if ($@);
 
 138 # customized scripts for login
 
 139 if (-f "bin/mozilla/$form->{login}_$form->{script}") {
 
 140   eval { require "bin/mozilla/$form->{login}_$form->{script}"; };
 
 141   $form->error($@) if ($@);
 
 144 if ($form->{action}) {
 
 146   # window title bar, user info
 
 149     . $locale->text('Version')
 
 150     . " $form->{version} - $myconfig{name} - $myconfig{dbname}";
 
 152   call_sub($locale->findsub($form->{action}));
 
 154   $form->error($locale->text('action= not defined!'));
 
 158   my $template           = shift;
 
 159   my $error_type         = shift;
 
 160   $locale                = Locale->new($language, 'all');
 
 161   $form->{error}         = $locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
 
 162   $form->{error}         = $locale->text('Incorrect password!.')                   if ($error_type eq 'password');
 
 163   $myconfig{countrycode} = $language;
 
 164   $form->{stylesheet}    = 'css/lx-office-erp.css';
 
 167   print $form->parse_html_template($template);