Revert "Time::HiRes um Zeit Stats im Footer anzuzeigen."
[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 use strict;
34
35 BEGIN {
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.
38 }
39
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 ###########################################
46
47 $| = 1;
48
49 use SL::LXDebug;
50 $main::lxdebug = LXDebug->new();
51
52 use CGI qw( -no_xhtml);
53 use SL::Auth;
54 use SL::Form;
55 use SL::Locale;
56
57 eval { require "config/lx-erp.conf"; };
58 eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
59
60 our $cgi  = new CGI('');
61 our $form = new Form;
62
63 our $auth = SL::Auth->new();
64 if (!$auth->session_tables_present()) {
65   _show_error('login/auth_db_unreachable');
66 }
67 $auth->expire_sessions();
68 my $session_result = $auth->restore_session();
69
70 require "bin/mozilla/common.pl";
71
72 if (defined($main::latex) && !defined($main::latex_templates)) {
73   $main::latex_templates = $main::latex;
74   undef($main::latex);
75 }
76
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;
81
82 # name of this script
83 $0 =~ tr/\\/\//;
84 my $pos = rindex $0, '/';
85 my $script = substr($0, $pos + 1);
86
87 # we use $script for the language module
88 $form->{script} = $script;
89
90 # strip .pl for translation files
91 $script =~ s/\.pl//;
92
93 # pull in DBI
94 use DBI;
95
96 # locale messages
97 $main::locale = new Locale($main::language, "$script");
98 my $locale = $main::locale;
99
100 # did sysadmin lock us out
101 if (-e "$main::userspath/nologin") {
102   $form->error($locale->text('System currently down for maintenance!'));
103 }
104
105 if (SL::Auth::SESSION_EXPIRED == $session_result) {
106   _show_error('login/password_error', 'session');
107 }
108
109 $form->{login} =~ s|.*/||;
110
111 %main::myconfig = $auth->read_user($form->{login});
112 my %myconfig = %main::myconfig;
113
114 if (!$myconfig{login}) {
115   _show_error('login/password_error', 'password');
116 }
117
118 # locale messages
119 $locale = new Locale "$myconfig{countrycode}", "$script";
120
121 if (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0)) {
122   _show_error('login/password_error', 'password');
123 }
124
125 $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
126 $auth->create_or_refresh_session();
127
128 delete $form->{password};
129
130 map { $form->{$_} = $myconfig{$_} } qw(stylesheet charset)
131   unless (($form->{action} eq 'save') && ($form->{type} eq 'preferences'));
132
133 # pull in the main code
134 require "bin/mozilla/$form->{script}";
135
136 # customized scripts
137 if (-f "bin/mozilla/custom_$form->{script}") {
138   eval { require "bin/mozilla/custom_$form->{script}"; };
139   $form->error($@) if ($@);
140 }
141
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 ($@);
146 }
147
148 if ($form->{action}) {
149
150   # window title bar, user info
151   $form->{titlebar} =
152       "Lx-Office "
153     . $locale->text('Version')
154     . " $form->{version} - $myconfig{name} - $myconfig{dbname}";
155
156   call_sub($locale->findsub($form->{action}));
157 } else {
158   $form->error($locale->text('action= not defined!'));
159 }
160
161 sub _show_error {
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';
169
170   $form->header();
171   print $form->parse_html_template($template);
172   exit;
173 }
174
175 # end
176