Umstellung der Benutzerverwaltung von Dateien im Verzeichnis "users" auf die Verwendu...
[kivitendo-erp.git] / am.pl
diff --git a/am.pl b/am.pl
index d35b4a9..5b3d666 100755 (executable)
--- a/am.pl
+++ b/am.pl
@@ -48,11 +48,22 @@ use SL::LXDebug;
 $lxdebug = LXDebug->new();
 
 use CGI qw( -no_xhtml);
+use SL::Auth;
 use SL::Form;
 use SL::Locale;
 
-eval { require "lx-erp.conf"; };
-eval { require "lx-erp-local.conf"; } if -f "lx-erp-local.conf";
+eval { require "config/lx-erp.conf"; };
+eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
+
+our $cgi  = new CGI('');
+our $form = new Form;
+
+our $auth = SL::Auth->new();
+if (!$auth->session_tables_present()) {
+  _show_error('login/auth_db_unreachable');
+}
+$auth->expire_sessions();
+$auth->restore_session();
 
 require "bin/mozilla/common.pl";
 
@@ -61,9 +72,6 @@ if (defined($latex) && !defined($latex_templates)) {
   undef($latex);
 }
 
-$form = new Form;
-$cgi = new CGI('');
-
 # this prevents most of the tabindexes being created by CGI.
 # note: most. popup menus and selecttables will still have tabindexes
 # use common.pl's NTI function to get rid of those
@@ -83,35 +91,37 @@ $script =~ s/\.pl//;
 # pull in DBI
 use DBI;
 
+# locale messages
+$locale = new Locale($language, "$script");
+
+# did sysadmin lock us out
+if (-e "$userspath/nologin") {
+  $form->error($locale->text('System currently down for maintenance!'));
+}
+
 $form->{login} =~ s|.*/||;
 
-# check for user config file, could be missing or ???
-eval { require("$userspath/$form->{login}.conf"); };
-if ($@) {
-  $locale = new Locale "$language", "$script";
+%myconfig = $auth->read_user($form->{login});
 
-  $form->{callback} = "";
-  $msg1             = $locale->text('You are logged out!');
-  $msg2             = $locale->text('Login');
-  $form->redirect("$msg1 <p><a href=login.pl target=_top>$msg2</a>");
+if (!$myconfig{login}) {
+  _show_error('login/password_error');
 }
 
-$myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
-map { $form->{$_} = $myconfig{$_} } qw(stylesheet charset)
-  unless (($form->{action} eq 'save') && ($form->{type} eq 'preferences'));
-
 # locale messages
 $locale = new Locale "$myconfig{countrycode}", "$script";
 
-# check password
-$form->error($locale->text('Incorrect Password!'))
-  if ($form->{password} ne $myconfig{password});
-
-# did sysadmin lock us out
-if (-e "$userspath/nologin") {
-  $form->error($locale->text('System currently down for maintenance!'));
+if (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0)) {
+  _show_error('login/password_error');
 }
 
+$auth->set_session_value('login', $form->{login}, 'password', $form->{password});
+$auth->create_or_refresh_session();
+
+delete $form->{password};
+
+map { $form->{$_} = $myconfig{$_} } qw(stylesheet charset)
+  unless (($form->{action} eq 'save') && ($form->{type} eq 'preferences'));
+
 # pull in the main code
 require "bin/mozilla/$form->{script}";
 
@@ -140,5 +150,16 @@ if ($form->{action}) {
   $form->error($locale->text('action= not defined!'));
 }
 
+sub _show_error {
+  my $template           = shift;
+  $locale                = Locale->new($language, 'all');
+  $myconfig{countrycode} = $language;
+  $form->{stylesheet}    = 'css/lx-office-erp.css';
+
+  $form->header();
+  print $form->parse_html_template($template);
+  exit;
+}
+
 # end