Revision 94899fc9
Von Moritz Bunkus vor mehr als 14 Jahren hinzugefügt
admin.pl | ||
---|---|---|
8 | 8 |
push @INC, "SL"; # FCGI won't find modules that are not properly named. Help it by inclduging SL |
9 | 9 |
} |
10 | 10 |
|
11 |
use FCGI; |
|
12 |
use CGI qw( -no_xhtml); |
|
13 |
use SL::Auth; |
|
14 |
use SL::LXDebug; |
|
15 |
use SL::Locale; |
|
16 |
use SL::Common; |
|
17 |
use Form; |
|
18 |
use Moose; |
|
19 |
use Rose::DB; |
|
20 |
use Rose::DB::Object; |
|
21 |
use File::Basename; |
|
11 |
use SL::Dispatcher; |
|
22 | 12 |
|
23 |
my ($script, $path, $suffix) = fileparse($0, ".pl"); |
|
24 |
my $request = FCGI::Request(); |
|
25 |
|
|
26 |
eval { require "config/lx-erp.conf"; }; |
|
27 |
eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf"; |
|
28 |
require "bin/mozilla/common.pl"; |
|
29 |
require "bin/mozilla/installationcheck.pl"; |
|
30 |
require_main_code($script, $suffix); |
|
31 |
|
|
32 |
# dummy globals |
|
33 |
{ |
|
34 |
no warnings 'once'; |
|
35 |
$::userspath = "users"; |
|
36 |
$::templates = "templates"; |
|
37 |
$::memberfile = "users/members"; |
|
38 |
$::sendmail = "| /usr/sbin/sendmail -t"; |
|
39 |
$::lxdebug = LXDebug->new; |
|
40 |
$::auth = SL::Auth->new; |
|
41 |
%::myconfig = (); |
|
42 |
} |
|
43 |
|
|
44 |
_pre_startup_checks(); |
|
45 |
|
|
46 |
if ($request->IsFastCGI) { |
|
47 |
handle_request() while $request->Accept() >= 0; |
|
48 |
} else { |
|
49 |
handle_request(); |
|
50 |
} |
|
51 |
|
|
52 |
# end |
|
53 |
|
|
54 |
sub handle_request { |
|
55 |
$::lxdebug->enter_sub; |
|
56 |
$::lxdebug->begin_request; |
|
57 |
$::cgi = CGI->new(''); |
|
58 |
$::locale = Locale->new($::language, $script); |
|
59 |
$::form = Form->new; |
|
60 |
$::form->{script} = $script . $suffix; |
|
61 |
|
|
62 |
_pre_request_checks(); |
|
63 |
|
|
64 |
eval { |
|
65 |
if ($script eq 'login' or $script eq 'admin' or $script eq 'kopf') { |
|
66 |
$::form->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $::form->{version}"; |
|
67 |
run($::auth->restore_session); |
|
68 |
} elsif ($::form->{action}) { |
|
69 |
# copy from am.pl routines |
|
70 |
$::form->error($::locale->text('System currently down for maintenance!')) if -e "$main::userspath/nologin" && $script ne 'admin'; |
|
71 |
|
|
72 |
my $session_result = $::auth->restore_session; |
|
73 |
|
|
74 |
_show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result; |
|
75 |
%::myconfig = $::auth->read_user($::form->{login}); |
|
76 |
|
|
77 |
_show_error('login/password_error', 'password') unless $::myconfig{login}; |
|
78 |
|
|
79 |
$::locale = Locale->new($::myconfig{countrycode}, $script); |
|
80 |
|
|
81 |
_show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($::form->{login}, $::form->{password}, 0); |
|
82 |
|
|
83 |
$::auth->set_session_value('login', $::form->{login}, 'password', $::form->{password}); |
|
84 |
$::auth->create_or_refresh_session; |
|
85 |
delete $::form->{password}; |
|
86 |
|
|
87 |
map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset) |
|
88 |
unless $::form->{action} eq 'save' && $::form->{type} eq 'preferences'; |
|
89 |
|
|
90 |
$::form->set_standard_title; |
|
91 |
call_sub($::locale->findsub($::form->{action})); |
|
92 |
} else { |
|
93 |
$::form->error($::locale->text('action= not defined!')); |
|
94 |
} |
|
95 |
}; |
|
96 |
|
|
97 |
# cleanup |
|
98 |
$::locale = undef; |
|
99 |
$::form = undef; |
|
100 |
$::myconfig = (); |
|
101 |
|
|
102 |
$::lxdebug->end_request; |
|
103 |
$::lxdebug->leave_sub; |
|
104 |
} |
|
105 |
|
|
106 |
sub _pre_request_checks { |
|
107 |
_show_error('login/auth_db_unreachable') unless $::auth->session_tables_present; |
|
108 |
$::auth->expire_sessions; |
|
109 |
} |
|
110 |
|
|
111 |
sub _show_error { |
|
112 |
$::lxdebug->enter_sub; |
|
113 |
my $template = shift; |
|
114 |
my $error_type = shift; |
|
115 |
my $locale = Locale->new($::language, 'all'); |
|
116 |
$::form->{error} = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session'); |
|
117 |
$::form->{error} = $::locale->text('Incorrect password!.') if ($error_type eq 'password'); |
|
118 |
$::myconfig{countrycode} = $::language; |
|
119 |
$::form->{stylesheet} = 'css/lx-office-erp.css'; |
|
120 |
|
|
121 |
$::form->header; |
|
122 |
print $::form->parse_html_template($template); |
|
123 |
$::lxdebug->leave_sub; |
|
124 |
|
|
125 |
exit; |
|
126 |
} |
|
127 |
|
|
128 |
sub _pre_startup_checks { |
|
129 |
verify_installation(); |
|
130 |
} |
|
131 |
|
|
132 |
sub require_main_code { |
|
133 |
my ($script, $suffix) = @_; |
|
134 |
|
|
135 |
require "bin/mozilla/$script$suffix"; |
|
136 |
|
|
137 |
if (-f "bin/mozilla/custom_$script$suffix") { |
|
138 |
eval { require "bin/mozilla/custom_$script$suffix"; }; |
|
139 |
$::form->error($@) if ($@); |
|
140 |
} |
|
141 |
if ($::form->{login} && -f "bin/mozilla/$::form->{login}_$::form->{script}") { |
|
142 |
eval { require "bin/mozilla/$::form->{login}_$::form->{script}"; }; |
|
143 |
$::form->error($@) if ($@); |
|
144 |
} |
|
145 |
} |
|
13 |
SL::Dispatcher::pre_startup(); |
|
14 |
SL::Dispatcher::handle_request('CGI'); |
|
146 | 15 |
|
147 | 16 |
1; |
Auch abrufbar als: Unified diff
Gemeinsamen Code von admin.pl und dispatcher.fpl nach SL/Dispatcher.pm verschoben.