Revision a4e48368
Von Sven Schöling vor mehr als 14 Jahren hinzugefügt
dispatcher.fpl | ||
---|---|---|
1 |
#!/usr/bin/perl |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
BEGIN { |
|
6 |
unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML). |
|
7 |
push @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version. |
|
8 |
push @INC, "SL"; # FCGI won't find modules that are not properly named. Help it by inclduging SL |
|
9 |
} |
|
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; |
|
22 |
|
|
23 |
|
|
24 |
eval { require "config/lx-erp.conf"; }; |
|
25 |
eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf"; |
|
26 |
require "bin/mozilla/common.pl"; |
|
27 |
require "bin/mozilla/installationcheck.pl"; |
|
28 |
|
|
29 |
# dummy globals |
|
30 |
{ |
|
31 |
no warnings 'once'; |
|
32 |
$::userspath = "users"; |
|
33 |
$::templates = "templates"; |
|
34 |
$::memberfile = "users/members"; |
|
35 |
$::sendmail = "| /usr/sbin/sendmail -t"; |
|
36 |
$::lxdebug = LXDebug->new; |
|
37 |
$::auth = SL::Auth->new; |
|
38 |
%::myconfig = (); |
|
39 |
} |
|
40 |
|
|
41 |
_pre_startup_checks(); |
|
42 |
|
|
43 |
my $request = FCGI::Request(); |
|
44 |
#if ($request->IsFastCGI) { |
|
45 |
handle_request() while $request->Accept() >= 0; |
|
46 |
#} else { |
|
47 |
# handle_request(); |
|
48 |
#} |
|
49 |
|
|
50 |
# end |
|
51 |
|
|
52 |
sub handle_request { |
|
53 |
$::lxdebug->enter_sub; |
|
54 |
$::lxdebug->begin_request; |
|
55 |
|
|
56 |
my ($script, $path, $suffix) = fileparse($ENV{SCRIPT_NAME}, ".pl"); |
|
57 |
unrequire_bin_mozilla(); |
|
58 |
require_main_code($script, $suffix); |
|
59 |
|
|
60 |
$::cgi = CGI->new(''); |
|
61 |
$::locale = Locale->new($::language, $script); |
|
62 |
$::form = Form->new; |
|
63 |
$::form->{script} = $script . $suffix; |
|
64 |
|
|
65 |
_pre_request_checks(); |
|
66 |
|
|
67 |
eval { |
|
68 |
if ($script eq 'login' or $script eq 'admin' or $script eq 'kopf') { |
|
69 |
$::form->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $::form->{version}"; |
|
70 |
run($::auth->restore_session); |
|
71 |
} elsif ($::form->{action}) { |
|
72 |
# copy from am.pl routines |
|
73 |
$::form->error($::locale->text('System currently down for maintenance!')) if -e "$main::userspath/nologin" && $script ne 'admin'; |
|
74 |
|
|
75 |
my $session_result = $::auth->restore_session; |
|
76 |
|
|
77 |
_show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result; |
|
78 |
%::myconfig = $::auth->read_user($::form->{login}); |
|
79 |
|
|
80 |
_show_error('login/password_error', 'password') unless $::myconfig{login}; |
|
81 |
|
|
82 |
$::locale = Locale->new($::myconfig{countrycode}, $script); |
|
83 |
|
|
84 |
_show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($::form->{login}, $::form->{password}, 0); |
|
85 |
|
|
86 |
$::auth->set_session_value('login', $::form->{login}, 'password', $::form->{password}); |
|
87 |
$::auth->create_or_refresh_session; |
|
88 |
delete $::form->{password}; |
|
89 |
|
|
90 |
map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset) |
|
91 |
unless $::form->{action} eq 'save' && $::form->{type} eq 'preferences'; |
|
92 |
|
|
93 |
$::form->set_standard_title; |
|
94 |
call_sub($::locale->findsub($::form->{action})); |
|
95 |
} else { |
|
96 |
$::form->error($::locale->text('action= not defined!')); |
|
97 |
} |
|
98 |
|
|
99 |
1; |
|
100 |
} or do { |
|
101 |
$::form->{label_error} = $::cgi->pre($@); |
|
102 |
_show_error('generic/error'); |
|
103 |
}; |
|
104 |
|
|
105 |
# cleanup |
|
106 |
$::locale = undef; |
|
107 |
$::form = undef; |
|
108 |
$::myconfig = (); |
|
109 |
|
|
110 |
$::lxdebug->end_request; |
|
111 |
$::lxdebug->leave_sub; |
|
112 |
} |
|
113 |
|
|
114 |
sub _pre_request_checks { |
|
115 |
_show_error('login/auth_db_unreachable') unless $::auth->session_tables_present; |
|
116 |
$::auth->expire_sessions; |
|
117 |
} |
|
118 |
|
|
119 |
sub _show_error { |
|
120 |
$::lxdebug->enter_sub; |
|
121 |
my $template = shift; |
|
122 |
my $error_type = shift; |
|
123 |
my $locale = Locale->new($::language, 'all'); |
|
124 |
$::form->{error} = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session'); |
|
125 |
$::form->{error} = $::locale->text('Incorrect password!.') if ($error_type eq 'password'); |
|
126 |
$::myconfig{countrycode} = $::language; |
|
127 |
$::form->{stylesheet} = 'css/lx-office-erp.css'; |
|
128 |
|
|
129 |
$::form->header; |
|
130 |
print $::form->parse_html_template($template); |
|
131 |
$::lxdebug->leave_sub; |
|
132 |
|
|
133 |
exit; |
|
134 |
} |
|
135 |
|
|
136 |
sub _pre_startup_checks { |
|
137 |
verify_installation(); |
|
138 |
} |
|
139 |
|
|
140 |
sub unrequire_bin_mozilla { |
|
141 |
for (keys %INC) { |
|
142 |
next unless m#^bin/mozilla/#; |
|
143 |
next if /\bcommon.pl$/; |
|
144 |
next if /\binstallationcheck.pl$/; |
|
145 |
delete $INC{$_}; |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
sub require_main_code { |
|
150 |
my ($script, $suffix) = @_; |
|
151 |
|
|
152 |
require "bin/mozilla/$script$suffix"; |
|
153 |
|
|
154 |
if (-f "bin/mozilla/custom_$script$suffix") { |
|
155 |
eval { require "bin/mozilla/custom_$script$suffix"; }; |
|
156 |
$::form->error($@) if ($@); |
|
157 |
} |
|
158 |
if ($::form->{login} && -f "bin/mozilla/$::form->{login}_$::form->{script}") { |
|
159 |
eval { require "bin/mozilla/$::form->{login}_$::form->{script}"; }; |
|
160 |
$::form->error($@) if ($@); |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
1; |
Auch abrufbar als: Unified diff
dispatcher