Umstellung der Benutzerverwaltung von Dateien im Verzeichnis "users" auf die Verwendu...
[kivitendo-erp.git] / am.pl
1 #!/usr/bin/perl
2 #
3 ######################################################################
4 # SQL-Ledger Accounting
5 # Copyright (C) 2001
6 #
7 #  Author: Dieter Simader
8 #   Email: dsimader@sql-ledger.org
9 #     Web: http://www.sql-ledger.org
10 #
11 #  Contributors:
12 #
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.
17 #
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 #######################################################################
26 #
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/
30 #
31 #######################################################################
32
33 BEGIN {
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.
36 }
37
38 # setup defaults, DO NOT CHANGE
39 $userspath  = "users";
40 $templates  = "templates";
41 $memberfile = "users/members";
42 $sendmail   = "| /usr/sbin/sendmail -t";
43 ########## end ###########################################
44
45 $| = 1;
46
47 use SL::LXDebug;
48 $lxdebug = LXDebug->new();
49
50 use CGI qw( -no_xhtml);
51 use SL::Auth;
52 use SL::Form;
53 use SL::Locale;
54
55 eval { require "config/lx-erp.conf"; };
56 eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
57
58 our $cgi  = new CGI('');
59 our $form = new Form;
60
61 our $auth = SL::Auth->new();
62 if (!$auth->session_tables_present()) {
63   _show_error('login/auth_db_unreachable');
64 }
65 $auth->expire_sessions();
66 $auth->restore_session();
67
68 require "bin/mozilla/common.pl";
69
70 if (defined($latex) && !defined($latex_templates)) {
71   $latex_templates = $latex;
72   undef($latex);
73 }
74
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;
79
80 # name of this script
81 $0 =~ tr/\\/\//;
82 $pos = rindex $0, '/';
83 $script = substr($0, $pos + 1);
84
85 # we use $script for the language module
86 $form->{script} = $script;
87
88 # strip .pl for translation files
89 $script =~ s/\.pl//;
90
91 # pull in DBI
92 use DBI;
93
94 # locale messages
95 $locale = new Locale($language, "$script");
96
97 # did sysadmin lock us out
98 if (-e "$userspath/nologin") {
99   $form->error($locale->text('System currently down for maintenance!'));
100 }
101
102 $form->{login} =~ s|.*/||;
103
104 %myconfig = $auth->read_user($form->{login});
105
106 if (!$myconfig{login}) {
107   _show_error('login/password_error');
108 }
109
110 # locale messages
111 $locale = new Locale "$myconfig{countrycode}", "$script";
112
113 if (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0)) {
114   _show_error('login/password_error');
115 }
116
117 $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
118 $auth->create_or_refresh_session();
119
120 delete $form->{password};
121
122 map { $form->{$_} = $myconfig{$_} } qw(stylesheet charset)
123   unless (($form->{action} eq 'save') && ($form->{type} eq 'preferences'));
124
125 # pull in the main code
126 require "bin/mozilla/$form->{script}";
127
128 # customized scripts
129 if (-f "bin/mozilla/custom_$form->{script}") {
130   eval { require "bin/mozilla/custom_$form->{script}"; };
131   $form->error($@) if ($@);
132 }
133
134 # customized scripts for login
135 if (-f "bin/mozilla/$form->{login}_$form->{script}") {
136   eval { require "bin/mozilla/$form->{login}_$form->{script}"; };
137   $form->error($@) if ($@);
138 }
139
140 if ($form->{action}) {
141
142   # window title bar, user info
143   $form->{titlebar} =
144       "Lx-Office "
145     . $locale->text('Version')
146     . " $form->{version} - $myconfig{name} - $myconfig{dbname}";
147
148   call_sub($locale->findsub($form->{action}));
149 } else {
150   $form->error($locale->text('action= not defined!'));
151 }
152
153 sub _show_error {
154   my $template           = shift;
155   $locale                = Locale->new($language, 'all');
156   $myconfig{countrycode} = $language;
157   $form->{stylesheet}    = 'css/lx-office-erp.css';
158
159   $form->header();
160   print $form->parse_html_template($template);
161   exit;
162 }
163
164 # end
165