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 #######################################################################
 
  36   unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
 
  37   push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
 
  40 # setup defaults, DO NOT CHANGE
 
  41 $main::userspath  = "users";
 
  42 $main::templates  = "templates";
 
  43 $main::memberfile = "users/members";
 
  44 $main::sendmail   = "| /usr/sbin/sendmail -t";
 
  45 ########## end ###########################################
 
  50 $main::lxdebug = LXDebug->new();
 
  52 use CGI qw( -no_xhtml);
 
  57 eval { require "config/lx-erp.conf"; };
 
  58 eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
 
  60 our $cgi  = new CGI('');
 
  63 our $auth = SL::Auth->new();
 
  64 if (!$auth->session_tables_present()) {
 
  65   _show_error('login/auth_db_unreachable');
 
  67 $auth->expire_sessions();
 
  68 my $session_result = $auth->restore_session();
 
  70 require "bin/mozilla/common.pl";
 
  72 if (defined($main::latex) && !defined($main::latex_templates)) {
 
  73   $main::latex_templates = $main::latex;
 
  77 # this prevents most of the tabindexes being created by CGI.
 
  78 # note: most. popup menus and selecttables will still have tabindexes
 
  79 # use common.pl's NTI function to get rid of those
 
  80 local $CGI::TABINDEX = 0;
 
  84 my $pos = rindex $0, '/';
 
  85 my $script = substr($0, $pos + 1);
 
  87 # we use $script for the language module
 
  88 $form->{script} = $script;
 
  90 # strip .pl for translation files
 
  97 $main::locale = new Locale($main::language, "$script");
 
  98 my $locale = $main::locale;
 
 100 # did sysadmin lock us out
 
 101 if (-e "$main::userspath/nologin") {
 
 102   $form->error($locale->text('System currently down for maintenance!'));
 
 105 if (SL::Auth::SESSION_EXPIRED == $session_result) {
 
 106   _show_error('login/password_error', 'session');
 
 109 $form->{login} =~ s|.*/||;
 
 111 %main::myconfig = $auth->read_user($form->{login});
 
 112 my %myconfig = %main::myconfig;
 
 114 if (!$myconfig{login}) {
 
 115   _show_error('login/password_error', 'password');
 
 119 $locale = new Locale "$myconfig{countrycode}", "$script";
 
 121 if (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0)) {
 
 122   _show_error('login/password_error', 'password');
 
 125 $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
 
 126 $auth->create_or_refresh_session();
 
 128 delete $form->{password};
 
 130 map { $form->{$_} = $myconfig{$_} } qw(stylesheet charset)
 
 131   unless (($form->{action} eq 'save') && ($form->{type} eq 'preferences'));
 
 133 # pull in the main code
 
 134 require "bin/mozilla/$form->{script}";
 
 137 if (-f "bin/mozilla/custom_$form->{script}") {
 
 138   eval { require "bin/mozilla/custom_$form->{script}"; };
 
 139   $form->error($@) if ($@);
 
 142 # customized scripts for login
 
 143 if (-f "bin/mozilla/$form->{login}_$form->{script}") {
 
 144   eval { require "bin/mozilla/$form->{login}_$form->{script}"; };
 
 145   $form->error($@) if ($@);
 
 148 if ($form->{action}) {
 
 150   # window title bar, user info
 
 153     . $locale->text('Version')
 
 154     . " $form->{version} - $myconfig{name} - $myconfig{dbname}";
 
 156   call_sub($locale->findsub($form->{action}));
 
 158   $form->error($locale->text('action= not defined!'));
 
 162   my $template           = shift;
 
 163   my $error_type         = shift;
 
 164   my $locale                = Locale->new($main::language, 'all');
 
 165   $form->{error}         = $locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
 
 166   $form->{error}         = $locale->text('Incorrect password!.')                   if ($error_type eq 'password');
 
 167   $myconfig{countrycode} = $main::language;
 
 168   $form->{stylesheet}    = 'css/lx-office-erp.css';
 
 171   print $form->parse_html_template($template);