Revision 94899fc9
Von Moritz Bunkus vor mehr als 14 Jahren hinzugefügt
SL/Dispatcher.pm | ||
---|---|---|
1 |
package SL::Dispatcher; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use CGI qw( -no_xhtml); |
|
6 |
use English qw(-no_match_vars); |
|
7 |
use SL::Auth; |
|
8 |
use SL::LXDebug; |
|
9 |
use SL::Locale; |
|
10 |
use SL::Common; |
|
11 |
use Form; |
|
12 |
use Moose; |
|
13 |
use Rose::DB; |
|
14 |
use Rose::DB::Object; |
|
15 |
use File::Basename; |
|
16 |
|
|
17 |
sub pre_request_checks { |
|
18 |
show_error('login/auth_db_unreachable') unless $::auth->session_tables_present; |
|
19 |
$::auth->expire_sessions; |
|
20 |
} |
|
21 |
|
|
22 |
sub show_error { |
|
23 |
$::lxdebug->enter_sub; |
|
24 |
my $template = shift; |
|
25 |
my $error_type = shift || ''; |
|
26 |
my $locale = Locale->new($::language, 'all'); |
|
27 |
$::form->{error} = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session'); |
|
28 |
$::form->{error} = $::locale->text('Incorrect password!.') if ($error_type eq 'password'); |
|
29 |
$::myconfig{countrycode} = $::language; |
|
30 |
$::form->{stylesheet} = 'css/lx-office-erp.css'; |
|
31 |
|
|
32 |
$::form->header; |
|
33 |
print $::form->parse_html_template($template); |
|
34 |
$::lxdebug->leave_sub; |
|
35 |
|
|
36 |
exit; |
|
37 |
} |
|
38 |
|
|
39 |
sub pre_startup_setup { |
|
40 |
eval { |
|
41 |
package main; |
|
42 |
require "config/lx-erp.conf"; |
|
43 |
}; |
|
44 |
eval { |
|
45 |
package main; |
|
46 |
require "config/lx-erp-local.conf"; |
|
47 |
} if -f "config/lx-erp-local.conf"; |
|
48 |
|
|
49 |
eval { |
|
50 |
package main; |
|
51 |
require "bin/mozilla/common.pl"; |
|
52 |
require "bin/mozilla/installationcheck.pl"; |
|
53 |
} or die $EVAL_ERROR; |
|
54 |
|
|
55 |
# dummy globals |
|
56 |
{ |
|
57 |
no warnings 'once'; |
|
58 |
$::userspath = "users"; |
|
59 |
$::templates = "templates"; |
|
60 |
$::memberfile = "users/members"; |
|
61 |
$::sendmail = "| /usr/sbin/sendmail -t"; |
|
62 |
$::lxdebug = LXDebug->new; |
|
63 |
$::auth = SL::Auth->new; |
|
64 |
%::myconfig = (); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
sub pre_startup_checks { |
|
69 |
::verify_installation(); |
|
70 |
} |
|
71 |
|
|
72 |
sub pre_startup { |
|
73 |
pre_startup_setup(); |
|
74 |
pre_startup_checks(); |
|
75 |
} |
|
76 |
|
|
77 |
sub require_main_code { |
|
78 |
my ($script, $suffix) = @_; |
|
79 |
|
|
80 |
eval { |
|
81 |
package main; |
|
82 |
require "bin/mozilla/$script$suffix"; |
|
83 |
} or die $EVAL_ERROR; |
|
84 |
|
|
85 |
if (-f "bin/mozilla/custom_$script$suffix") { |
|
86 |
eval { |
|
87 |
package main; |
|
88 |
require "bin/mozilla/custom_$script$suffix"; |
|
89 |
}; |
|
90 |
$::form->error($EVAL_ERROR) if ($EVAL_ERROR); |
|
91 |
} |
|
92 |
if ($::form->{login} && -f "bin/mozilla/$::form->{login}_$::form->{script}") { |
|
93 |
eval { |
|
94 |
package main; |
|
95 |
require "bin/mozilla/$::form->{login}_$::form->{script}"; |
|
96 |
}; |
|
97 |
$::form->error($EVAL_ERROR) if ($EVAL_ERROR); |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
sub handle_request { |
|
102 |
$::lxdebug->enter_sub; |
|
103 |
$::lxdebug->begin_request; |
|
104 |
|
|
105 |
my $interface = lc(shift || 'cgi'); |
|
106 |
my $script_name; |
|
107 |
|
|
108 |
if ($interface =~ m/^(?:fastcgi|fcgid|fcgi)$/) { |
|
109 |
$script_name = $ENV{SCRIPT_NAME}; |
|
110 |
unrequire_bin_mozilla(); |
|
111 |
|
|
112 |
} else { |
|
113 |
$script_name = $0; |
|
114 |
} |
|
115 |
|
|
116 |
my ($script, $path, $suffix) = fileparse($script_name, ".pl"); |
|
117 |
require_main_code($script, $suffix); |
|
118 |
|
|
119 |
$::cgi = CGI->new(''); |
|
120 |
$::locale = Locale->new($::language, $script); |
|
121 |
$::form = Form->new; |
|
122 |
$::form->{script} = $script . $suffix; |
|
123 |
|
|
124 |
pre_request_checks(); |
|
125 |
|
|
126 |
eval { |
|
127 |
if ($script eq 'login' or $script eq 'admin' or $script eq 'kopf') { |
|
128 |
$::form->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $::form->{version}"; |
|
129 |
::run($::auth->restore_session); |
|
130 |
|
|
131 |
} elsif ($::form->{action}) { |
|
132 |
# copy from am.pl routines |
|
133 |
$::form->error($::locale->text('System currently down for maintenance!')) if -e "$main::userspath/nologin" && $script ne 'admin'; |
|
134 |
|
|
135 |
my $session_result = $::auth->restore_session; |
|
136 |
|
|
137 |
show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result; |
|
138 |
%::myconfig = $::auth->read_user($::form->{login}); |
|
139 |
|
|
140 |
show_error('login/password_error', 'password') unless $::myconfig{login}; |
|
141 |
|
|
142 |
$::locale = Locale->new($::myconfig{countrycode}, $script); |
|
143 |
|
|
144 |
show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($::form->{login}, $::form->{password}, 0); |
|
145 |
|
|
146 |
$::auth->set_session_value('login', $::form->{login}, 'password', $::form->{password}); |
|
147 |
$::auth->create_or_refresh_session; |
|
148 |
delete $::form->{password}; |
|
149 |
|
|
150 |
map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset) |
|
151 |
unless $::form->{action} eq 'save' && $::form->{type} eq 'preferences'; |
|
152 |
|
|
153 |
$::form->set_standard_title; |
|
154 |
::call_sub('::' . $::locale->findsub($::form->{action})); |
|
155 |
|
|
156 |
} else { |
|
157 |
$::form->error($::locale->text('action= not defined!')); |
|
158 |
} |
|
159 |
|
|
160 |
1; |
|
161 |
} or do { |
|
162 |
$::form->{label_error} = $::cgi->pre($EVAL_ERROR); |
|
163 |
show_error('generic/error'); |
|
164 |
}; |
|
165 |
|
|
166 |
# cleanup |
|
167 |
$::locale = undef; |
|
168 |
$::form = undef; |
|
169 |
$::myconfig = (); |
|
170 |
|
|
171 |
$::lxdebug->end_request; |
|
172 |
$::lxdebug->leave_sub; |
|
173 |
} |
|
174 |
|
|
175 |
sub unrequire_bin_mozilla { |
|
176 |
for (keys %INC) { |
|
177 |
next unless m#^bin/mozilla/#; |
|
178 |
next if /\bcommon.pl$/; |
|
179 |
next if /\binstallationcheck.pl$/; |
|
180 |
delete $INC{$_}; |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
1; |
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; |
dispatcher.fpl | ||
---|---|---|
9 | 9 |
} |
10 | 10 |
|
11 | 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; |
|
12 |
use SL::Dispatcher; |
|
22 | 13 |
|
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 |
} |
|
14 |
SL::Dispatcher::pre_startup(); |
|
15 |
my $request = FCGI::Request(); |
|
16 |
SL::Dispatcher::handle_request('FastCGI') while $request->Accept() >= 0; |
|
163 | 17 |
|
164 | 18 |
1; |
Auch abrufbar als: Unified diff
Gemeinsamen Code von admin.pl und dispatcher.fpl nach SL/Dispatcher.pm verschoben.