line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MPMinus::Configuration; # $Id: Configuration.pm 151 2013-05-29 14:31:19Z minus $ |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
MPMinus::Configuration - Configuration of MPMinus |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Version 1.33 |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package MPM::foo::Handlers; |
15
|
|
|
|
|
|
|
use strict; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub handler { |
18
|
|
|
|
|
|
|
my $r = shift; |
19
|
|
|
|
|
|
|
my $m = MPMinus->m; |
20
|
|
|
|
|
|
|
$m->conf_init($r, __PACKAGE__); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
... |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $project = $m->conf('project'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
... |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
The module works with the configuration data of the resource on the platform mod_perl. |
32
|
|
|
|
|
|
|
The configuration data are relevant at the global level, and they are the same for all |
33
|
|
|
|
|
|
|
users at once! |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 METHODS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=over 8 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item B<conf_init> |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$m->conf_init( $r, $pkg ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item B<conf, get_conf, config, get_config> |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $value = $m->conf( 'key' ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item B<set_conf, set_config> |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$m->set_conf( 'key', $value ); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=back |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 HISTORY |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=over 8 |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item B<1.00 / 27.02.2008> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Init version on base mod_main 1.00.0002 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item B<1.10 / 01.04.2008> |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Module is merged into the global module level |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item B<1.20 / 19.04.2010> |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Added new type (DSN) support: Oracle |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item B<1.30 / 08.01.2012> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Added server_port variable |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item B<1.31 / Wed Apr 24 14:53:38 2013 MSK> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
General refactoring |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item B<1.32 / Wed May 8 12:25:30 2013 MSK> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Added locked_keys parameter |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=back |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 AUTHOR |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Serz Minus (Lepenkov Sergey) L<http://serzik.ru> E<lt>minus@mail333.comE<gt> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 COPYRIGHT |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Copyright (C) 1998-2013 D&D Corporation. All Rights Reserved |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 LICENSE |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify |
94
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
95
|
|
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or |
96
|
|
|
|
|
|
|
(at your option) any later version. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
99
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
100
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
101
|
|
|
|
|
|
|
GNU General Public License for more details. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
See C<LICENSE> file |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
1
|
|
557
|
use CTK::Util qw/ :BASE /; # Óòèëèòàðèé |
|
1
|
|
|
|
|
116630
|
|
|
1
|
|
|
|
|
437
|
|
108
|
1
|
|
|
1
|
|
331
|
use MPMinus::MainTools; # Ìîäóëü äëÿ äâóõ ôóíêöèé getHiTime è getSID |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
109
|
1
|
|
|
1
|
|
585
|
use Config::General; |
|
1
|
|
|
|
|
8944
|
|
|
1
|
|
|
|
|
55
|
|
110
|
1
|
|
|
1
|
|
8
|
use Try::Tiny; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
1
|
|
3
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1152
|
|
113
|
|
|
|
|
|
|
$VERSION = 1.33; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub conf_init { |
116
|
|
|
|
|
|
|
# Èíèöèàëèçàöèÿ. Çàïóñêàåòñÿ èç ãëàâíîãî õýíäëåðà!! |
117
|
0
|
|
|
0
|
1
|
|
my $m = shift; |
118
|
0
|
0
|
|
|
|
|
croak("The method call is made ActionCheck not in the style of OOP") unless ref($m) =~ /MPMinus/; |
119
|
0
|
|
|
|
|
|
my $r = shift; |
120
|
0
|
0
|
|
|
|
|
croak("Object Apache2::RequestRec not defined") unless ref($r) eq 'Apache2::RequestRec'; |
121
|
0
|
|
0
|
|
|
|
my $pkg = shift || ''; # Ïàêåò, êîòîðûé âûçâàë èíèöèàëèçàöèþ |
122
|
0
|
0
|
0
|
|
|
|
croak("Package name missing!") unless $pkg && $pkg =~ /Handlers$/; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Óñòàíàâëèâàåì ãëàâííûé îáúåêò Apache2::RequestRec è çàâèñèìûå ïàêåòû |
125
|
0
|
|
|
|
|
|
$m->set(r => $r); |
126
|
0
|
|
|
|
|
|
my $s = $r->server; # ñåðâåð |
127
|
0
|
|
|
|
|
|
my $c = $r->connection; # Ñîåäèíåíèå |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Âíóòðåííèé ìàññèâ |
130
|
0
|
|
|
|
|
|
my %conf; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
########################################################################## |
133
|
|
|
|
|
|
|
# !!! Ïàðàìåòðû, óñòàíàâëèâàåìûå êàæäûé ïåðåçàïóñê !!! |
134
|
|
|
|
|
|
|
########################################################################## |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Ïàêåò äîëæåí âîçãëàâëÿòü ñïèñîê |
137
|
0
|
0
|
|
|
|
|
my $i = $m->conf('package') ? ($m->conf('package')->[1] + 1) : 0; |
138
|
0
|
0
|
|
|
|
|
$i = 1 if $i > 65534; # Íà ñëó÷àé ïåðåïîëíåíèÿ ñòåêà |
139
|
0
|
|
|
|
|
|
$conf{package} = [$pkg,$i]; # Ïîëíîå èìÿ ïàêåòà è êîëè÷åñòâî èíèöèàëèçàöèé çà äî÷êó. 0 - ïåðâûé ðàç |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Äîîïðåäåëÿåì ïàðàìåòðû |
142
|
0
|
|
|
|
|
|
$conf{sid} = getSID(16,'m'); # ID Ñåññèè (SID) - Äëÿ êîíòðîëÿ ñåññèè |
143
|
0
|
|
|
|
|
|
$conf{hitime} = getHiTime(); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# |
146
|
|
|
|
|
|
|
# Îñíîâíûå çíà÷åíèÿ (ÍÅ ÐÅÄÀÊÒÈÐÓÅÌÛÅ) |
147
|
|
|
|
|
|
|
# |
148
|
0
|
|
|
|
|
|
my $prj = ''; |
149
|
0
|
0
|
|
|
|
|
if ($pkg =~ /([^\:]+?)\:\:Handlers$/) { |
150
|
0
|
|
|
|
|
|
$prj = $1; |
151
|
0
|
|
|
|
|
|
$conf{project} = $prj; |
152
|
0
|
|
|
|
|
|
$conf{prefix} = lc($prj); |
153
|
|
|
|
|
|
|
} else { |
154
|
0
|
|
|
|
|
|
$conf{project} = ''; |
155
|
0
|
|
|
|
|
|
$conf{prefix} = ''; |
156
|
|
|
|
|
|
|
} |
157
|
0
|
|
|
|
|
|
$conf{preffix} = $conf{prefix}; # Äëÿ îáðàòíîé ñîâìåñòèìîñòè ïîòîì óäàëèòü !! |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# |
160
|
|
|
|
|
|
|
# Ïåðåìåííûå "îêðóæåíèÿ" Apache |
161
|
|
|
|
|
|
|
# |
162
|
0
|
|
0
|
|
|
|
$conf{request_uri} = $r->uri() || ""; # ïîëó÷åííàÿ GET ñòðîêà |
163
|
0
|
|
0
|
|
|
|
$conf{request_method} = $r->method() || ""; # ïîëó÷åííàÿ ìåòîäà |
164
|
0
|
|
0
|
|
|
|
$conf{remote_addr} = $c->remote_ip || ""; # IP êëèåíòà |
165
|
0
|
|
0
|
|
|
|
$conf{remote_user} = $r->user() || ""; # Èìÿ ïîëüçîâàòåëÿ |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
0
|
|
|
|
$conf{server_admin} = $s->server_admin() || ""; # Àäðåñ ýëåêòðîííîé ïî÷òû |
168
|
0
|
|
0
|
|
|
|
$conf{server_name} = $s->server_hostname() || ""; # Èìÿ ñåðâåðà (ãëàâíîãî õîñòà) |
169
|
0
|
|
0
|
|
|
|
$conf{server_port} = $s->port() || 80; # Ïîðò ñåðâåðà (ãëàâíîãî õîñòà) |
170
|
|
|
|
|
|
|
# HTTP_HOST = SERVER_NAME:SERVER_PORT if SERVER_PORT <> {80|443} |
171
|
0
|
|
0
|
|
|
|
$conf{http_host} = $r->hostname() || ""; # Èìÿ õîñòà (âèðòóàëüíîãî õîñòà, îáðàùåíèÿ) |
172
|
0
|
0
|
0
|
|
|
|
if ($conf{server_port} != 80 and $conf{server_port} != 443 and $conf{server_name} eq $conf{http_host}) { |
|
|
|
0
|
|
|
|
|
173
|
0
|
|
|
|
|
|
$conf{http_host} = join ':', $conf{server_name}, $conf{server_port}; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# ÀÁÑÎËÞÒÍÛÉ ïóòü îò êîðíÿ ñåðâåðà äî êîðíÿ ñàéòà. Áàçîâûé ïóòü äëÿ ðåñóðñà |
177
|
0
|
|
0
|
|
|
|
$conf{document_root} = $r->document_root || ''; |
178
|
|
|
|
|
|
|
# ÀÁÑÎËÞÒÍÛÉ ïóòü îò êîðíÿ ñåðâåðà äî êîðíÿ modperl. Áàçîâûé ïóòü äëÿ modperl (îò íåãî îòòàëêèâàåìñÿ !!) |
179
|
0
|
|
0
|
|
|
|
$conf{modperl_root} = $r->dir_config('ModperlRoot') || $conf{document_root}; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# Ñïèñîê çàáëîêèðîâàííûõ êëþ÷åé |
182
|
0
|
|
|
|
|
|
my @locked_keys = keys %conf; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# Íå ïðîèçâîäèì äåéñòâèé â ñëó÷àå åñëè èíèöèàëèçàöèÿ âûçûâàåòñÿ íå ïåðâûé ðàç! |
185
|
|
|
|
|
|
|
# Òî ÷òî ïîëó÷èëîñü çàêèäûâàåì â ãëîáàâëüíûé îáúåêò |
186
|
0
|
0
|
|
|
|
|
if ($i > 0) { |
187
|
0
|
|
|
|
|
|
my %tconf = %{$m->get('conf')}; |
|
0
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
foreach (keys %conf) { $tconf{$_} = $conf{$_} } |
|
0
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
$m->set(conf=>{%tconf}); |
190
|
0
|
|
|
|
|
|
return 1 |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
########################################################################## |
194
|
|
|
|
|
|
|
# !!! Ïàðàìåòðû, óñòàíàâëèâàåìûå òîëüêî 1 ðàç íà æèçíü âñåõ ïðîöåññîâ !!! |
195
|
|
|
|
|
|
|
########################################################################## |
196
|
0
|
|
|
|
|
|
my $modperl_root = $conf{modperl_root}; # Ýòîò ïóòü äëÿ âñåõ óìîë÷àíèé !! |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# Ôîðìèðóåì èìÿ êîíôèãóðàöèîííîãî ôàéëà. Íàïðèìåð, foo.conf |
199
|
0
|
|
0
|
|
|
|
$conf{fileconf} = $r->dir_config('FileConf') || catfile($modperl_root,$conf{prefix}.".conf"); |
200
|
0
|
|
|
|
|
|
$conf{configloadstatus} = 0; # See _loadconfig |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# |
203
|
|
|
|
|
|
|
# Îòíîñèòåëüíûå ïóòè ê äèðåêòîðèÿì (îòíîñèòåëüíî document_root) |
204
|
|
|
|
|
|
|
# |
205
|
0
|
|
|
|
|
|
$conf{dir_conf} = "conf"; # Äèðåêòîðèÿ ê ôàéëàì êîíôèãóðàöèè |
206
|
0
|
|
|
|
|
|
$conf{dir_logs} = "log"; # Äèðåêòîðèÿ ê ëîãàì îòíîñèòåëüíî document_root |
207
|
0
|
|
|
|
|
|
$conf{dir_cache} = "cache"; # Äèðåêòîðèÿ ê ôàéëàì êýøà |
208
|
0
|
|
|
|
|
|
$conf{dir_db} = "db"; # Äèðåêòîðèÿ ê ôàéëîâûì äàííûì |
209
|
0
|
|
|
|
|
|
$conf{dir_shtml} = "shtml"; # Äèðåêòîðèÿ ê ôàéëàì øàáëîíîâ è ôàéëîâ ssi |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# |
212
|
|
|
|
|
|
|
# Àáñîëþòíûå ïóòè ê äèðåêòîðèÿì îòíîñèòåëüíî êîðíÿ ñåðâåðà (ÍÅ ÐÅÄÀÊÒÈÐÓÅÌÛÅ) |
213
|
|
|
|
|
|
|
# |
214
|
0
|
|
|
|
|
|
my $logdir = syslogdir(); |
215
|
0
|
0
|
|
|
|
|
unless (-e $logdir) { |
216
|
0
|
|
|
|
|
|
$logdir = catdir($modperl_root, $conf{dir_logs}); |
217
|
0
|
0
|
|
|
|
|
preparedir($logdir) unless -e $logdir; |
218
|
|
|
|
|
|
|
} |
219
|
0
|
|
|
|
|
|
$conf{logdir} = $logdir; |
220
|
0
|
|
0
|
|
|
|
$conf{confdir} = $r->dir_config('ConfDir') || catdir($modperl_root,$conf{dir_conf}); |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
# |
223
|
|
|
|
|
|
|
# Èìåíà ôàëîâ (ÍÅ ÐÅÄÀÊÒÈÐÓÅÌÛÅ) |
224
|
|
|
|
|
|
|
# |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
# Ïðåôèêñíûå èìåíà ôàéëîâ |
227
|
0
|
0
|
|
|
|
|
my $fprefix = ($conf{prefix} ? ('mpminus-'.$conf{prefix}.'_') : 'mpminus-'); # Ïðåôèêñ èì¸í |
228
|
0
|
|
|
|
|
|
$conf{file_error} = $fprefix."error.log"; # Èìÿ ôàéëà îøèáîê (log) |
229
|
0
|
|
|
|
|
|
$conf{file_debug} = $fprefix."debug.log"; # Èìÿ ôàéëà îòëàäêè (log) |
230
|
0
|
|
|
|
|
|
$conf{file_connect} = $fprefix."connect.log"; # Èìÿ ôàéëà ñîåäèíåíèé ñ ÁÄ (log) |
231
|
0
|
|
|
|
|
|
$conf{file_mail} = $fprefix."mail.log"; # Èìÿ ôàéëà ïèñåì (log) |
232
|
0
|
|
|
|
|
|
$conf{file_mpminfo} = "mpminfo.shtml"; # Èìÿ ôàéëà øàáëîíà mpminfo (shtml) |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# Àáñîëþòíûå ïóòè (ÍÅ ÐÅÄÀÊÒÈÐÓÅÌÛÅ) |
235
|
0
|
|
|
|
|
|
$conf{errorlog} = catfile($logdir,$conf{file_error}); |
236
|
0
|
|
|
|
|
|
$conf{debuglog} = catfile($logdir,$conf{file_debug}); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# Áàçîâûå URL |
239
|
0
|
|
|
|
|
|
my $urlsfx = ''; |
240
|
0
|
|
|
|
|
|
my $urlpfx = 'http://'; |
241
|
|
|
|
|
|
|
$urlsfx = ':'.$conf{server_port} if (1 |
242
|
|
|
|
|
|
|
and $conf{server_port} != 80 |
243
|
|
|
|
|
|
|
and $conf{server_port} != 443 |
244
|
|
|
|
|
|
|
and $conf{http_host} |
245
|
0
|
0
|
0
|
|
|
|
and $conf{http_host} !~ /\:\d+$/ |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
246
|
|
|
|
|
|
|
); |
247
|
0
|
0
|
|
|
|
|
$urlpfx = 'https://' if $conf{server_port} == 443; |
248
|
0
|
|
|
|
|
|
$conf{url} = $urlpfx.$conf{http_host}.$urlsfx; |
249
|
0
|
|
|
|
|
|
$conf{urls} = "https://".$conf{http_host}.$urlsfx; |
250
|
0
|
|
|
|
|
|
$conf{url_shtml} = $conf{url}.'/'.$conf{dir_shtml}; |
251
|
0
|
|
|
|
|
|
$conf{urls_shtml} = $conf{urls}.'/'.$conf{dir_shtml}; |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# |
254
|
|
|
|
|
|
|
# Ôëàãè (äèðåêòèâû ñ ïðåôôèêñîì è ñóôôèêñîì _ ) |
255
|
|
|
|
|
|
|
# |
256
|
0
|
|
0
|
|
|
|
$conf{_debug_} = $r->dir_config('_debug_') || 0; # Ôëàã îòëàäêè |
257
|
0
|
|
0
|
|
|
|
$conf{_errorsendmail_} = $r->dir_config('_errorsendmail_') || 0; # Ôëàã îòïðàâêè ñîîáùåíèÿ ïî ïî÷òå ïðè îøèáêàõ |
258
|
0
|
|
0
|
|
|
|
$conf{_sendmail_} = $r->dir_config('_sendmail_') || 0; # Ôëàã îòïðàâêè ñîîáùåíèÿ (äëÿ âñåõ) |
259
|
0
|
|
0
|
|
|
|
$conf{_syslog_} = $r->dir_config('_syslog_') || 0; # Ôëàã èñïîëüçîâàíèÿ Apache äëÿ îòðàáîòêè ôóíêöèé log è debug |
260
|
0
|
|
|
|
|
|
push @locked_keys, qw/_debug_ _errorsendmail_ _sendmail_/; # áëîêèðóåì! |
261
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
|
push @locked_keys, grep {/dir|file|log|url/} keys(%conf); # áëîêèðóåì! |
|
0
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
|
push @locked_keys, qw/configloadstatus locked_keys/; |
264
|
0
|
|
|
|
|
|
$conf{locked_keys} = [sort(@locked_keys)]; |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
# |
267
|
|
|
|
|
|
|
# SMTP (ïî÷òà) |
268
|
|
|
|
|
|
|
# |
269
|
0
|
|
0
|
|
|
|
$conf{smtp_host} = $r->dir_config('smtp_host') || ''; |
270
|
0
|
|
0
|
|
|
|
$conf{smtp_user} = $r->dir_config('smtp_user') || ''; |
271
|
0
|
|
0
|
|
|
|
$conf{smtp_password} = $r->dir_config('smtp_password') || ''; |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
# |
274
|
|
|
|
|
|
|
# Áàçà äàííûõ (ëþáàÿ) |
275
|
|
|
|
|
|
|
# |
276
|
0
|
|
|
|
|
|
for (qw/ |
277
|
|
|
|
|
|
|
db_driver db_dsn db_host db_name db_port db_user db_password |
278
|
|
|
|
|
|
|
db_timeout_connect db_timeout_request |
279
|
|
|
|
|
|
|
/ |
280
|
|
|
|
|
|
|
) { |
281
|
0
|
0
|
|
|
|
|
$conf{$_} = defined $r->dir_config($_) ? $r->dir_config($_) : ''; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
# |
285
|
|
|
|
|
|
|
# Áàçà äàííûõ MySQL |
286
|
|
|
|
|
|
|
# |
287
|
0
|
|
|
|
|
|
for (qw/ db_mysql_host db_mysql_name db_mysql_user db_mysql_password /) { |
288
|
0
|
0
|
|
|
|
|
$conf{$_} = defined $r->dir_config($_) ? $r->dir_config($_) : ''; |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
# |
292
|
|
|
|
|
|
|
# Áàçà äàííûõ Oracle |
293
|
|
|
|
|
|
|
# |
294
|
0
|
|
|
|
|
|
for (qw/ db_oracle_host db_oracle_name db_oracle_user db_oracle_password /) { |
295
|
0
|
0
|
|
|
|
|
$conf{$_} = defined $r->dir_config($_) ? $r->dir_config($_) : ''; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
# |
299
|
|
|
|
|
|
|
# ñòàíäàðòû âûâîäà è ïðî÷èå ïàðàìåòðû |
300
|
|
|
|
|
|
|
# |
301
|
0
|
|
0
|
|
|
|
$conf{content_type} = $r->dir_config('content_type') || ''; # Äåôîëòíûé Content-type |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
# Òî ÷òî ïîëó÷èëîñü çàêèäûâàåì â ãëîáàâëüíûé îáúåêò, ïðåäâàðèòåëüíî äîçàãðóçèâ äàííûå èç âíåøåíåé êîíôèãóðàöèè |
304
|
0
|
|
|
|
|
|
_loadconfig(\%conf, @locked_keys); # ×òåíèå ôàéëà êîíôèãóðàöèè |
305
|
0
|
|
|
|
|
|
$m->set(conf=>{%conf}); |
306
|
0
|
|
|
|
|
|
return 1; |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
sub conf { |
309
|
|
|
|
|
|
|
# Ïðî÷èòàòü óêàçàííûé ïàðàìåòð êîíôèãóðàöèè |
310
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
311
|
0
|
|
|
|
|
|
my $key = shift; |
312
|
0
|
0
|
|
|
|
|
return undef unless $self->{conf}; |
313
|
0
|
|
|
|
|
|
return $self->{conf}->{$key}; |
314
|
|
|
|
|
|
|
} |
315
|
0
|
|
|
0
|
1
|
|
sub get_conf { goto &conf }; |
316
|
0
|
|
|
0
|
1
|
|
sub config { goto &conf }; |
317
|
0
|
|
|
0
|
1
|
|
sub get_config { goto &conf }; |
318
|
|
|
|
|
|
|
sub set_conf { |
319
|
|
|
|
|
|
|
# Óñòàíîâèòü óêàçàííûé ïàðàìåòð êîíôèãóðàöèè |
320
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
321
|
0
|
|
|
|
|
|
my $key = shift; |
322
|
0
|
|
|
|
|
|
my $val = shift; |
323
|
0
|
0
|
|
|
|
|
$self->{conf} = {} unless $self->{conf}; |
324
|
0
|
|
|
|
|
|
$self->{conf}->{$key} = $val; |
325
|
|
|
|
|
|
|
} |
326
|
0
|
|
|
0
|
1
|
|
sub set_config { goto &set_conf }; |
327
|
|
|
|
|
|
|
sub _loadconfig { |
328
|
0
|
|
|
0
|
|
|
my $lconf = shift; |
329
|
0
|
|
|
|
|
|
my @lkeys = @_; |
330
|
0
|
0
|
0
|
|
|
|
return 0 unless $lconf && ref($lconf) eq 'HASH'; |
331
|
0
|
0
|
0
|
|
|
|
return 0 unless $lconf->{fileconf} && -e $lconf->{fileconf}; |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
# Ïûòàåìñÿ ïðî÷èòàòü êîíôèãóðàöèîííûå äàííûå |
334
|
0
|
|
|
|
|
|
my $cfg; |
335
|
|
|
|
|
|
|
try { |
336
|
|
|
|
|
|
|
$cfg = new Config::General( |
337
|
|
|
|
|
|
|
-ConfigFile => $lconf->{fileconf}, |
338
|
0
|
|
|
0
|
|
|
-ConfigPath => [$lconf->{modperl_root}, $lconf->{confdir}], |
339
|
|
|
|
|
|
|
-ApacheCompatible => 1, |
340
|
|
|
|
|
|
|
-LowerCaseNames => 1, |
341
|
|
|
|
|
|
|
-AutoTrue => 1, |
342
|
|
|
|
|
|
|
); |
343
|
|
|
|
|
|
|
} catch { |
344
|
0
|
|
|
0
|
|
|
carp($_); |
345
|
0
|
|
|
|
|
|
}; |
346
|
|
|
|
|
|
|
|
347
|
0
|
0
|
0
|
|
|
|
my %newconfig = $cfg->getall if $cfg && $cfg->can('getall'); |
348
|
0
|
|
|
|
|
|
$lconf->{configfiles} = []; |
349
|
0
|
0
|
0
|
|
|
|
$lconf->{configfiles} = [$cfg->files] if $cfg && $cfg->can('files'); |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
# Çàïèñûâàåì òîëüêî ðàçðåøåííûå êëþ÷èêè |
352
|
0
|
|
|
|
|
|
foreach my $k (keys(%newconfig)) { |
353
|
|
|
|
|
|
|
$lconf->{$k} = $newconfig{$k} if 1 == 1 |
354
|
|
|
|
|
|
|
&& $k |
355
|
0
|
0
|
0
|
|
|
|
&& !(grep {$_ eq $k} @lkeys) |
|
0
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
|
358
|
0
|
0
|
|
|
|
|
$lconf->{configloadstatus} = 1 if %newconfig; |
359
|
0
|
|
|
|
|
|
return 1; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
1; |
363
|
|
|
|
|
|
|
|