| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MPMinus::Transaction; # $Id: Transaction.pm 218 2013-10-01 15:22:22Z minus $ |
|
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
38
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
MPMinus::Transaction - MVC SKEL transaction |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Version 1.05 |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $q = new CGI; |
|
15
|
|
|
|
|
|
|
my ($actObject,$actEvent) = split /[,]/, $q->param('action') || ''; |
|
16
|
|
|
|
|
|
|
$actObject = 'default' unless $actObject && $m->ActionCheck($actObject); |
|
17
|
|
|
|
|
|
|
$actEvent = $actEvent && $actEvent =~ /go/ ? 'go' : ''; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$r->content_type( $m->getActionRecord($actObject)->{content_type} ); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $status = $m->ActionTransaction($actObject,$actEvent); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $status = $m->ActionExecute($actObject,'cdeny'); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Working with MVC SKEL transactions. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
See MVC SKEL transaction C<DESCRIPTION> file or L<MPMinus::Manual> |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over 8 |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item B<ActionTransaction> |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $status = $m->ActionTransaction( $actObject, $actEvent ); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Start MVC SKEL Transaction by $actObject and $actEvent |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item B<ActionExecute> |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $status = $m->ActionExecute( $actObject, $handler_name ); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Execute $handler_name action by $actObject. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$handler_name must be: mproc, vform, cchck, caccess, cdeny |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item B<ActionCheck> |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $status = $m->ActionCheck( $actObject ); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Check existing status of $actObject handler |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item B<getActionRecord> |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $struct = $m->getActionRecord( $actObject ); |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Returns meta record of $actObject |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=back |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 AUTHOR |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Serz Minus (Lepenkov Sergey) L<http://serzik.ru> E<lt>minus@mail333.comE<gt> |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Copyright (C) 1998-2013 D&D Corporation. All Rights Reserved |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 LICENSE |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify |
|
74
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
|
75
|
|
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or |
|
76
|
|
|
|
|
|
|
(at your option) any later version. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
|
79
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
80
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
81
|
|
|
|
|
|
|
GNU General Public License for more details. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
See C<LICENSE> file |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
88
|
|
|
|
|
|
|
$VERSION = 1.05; |
|
89
|
|
|
|
|
|
|
|
|
90
|
1
|
|
|
1
|
|
267
|
use Apache2::Const; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
use CTK::Util qw/ :API /; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
use constant { |
|
94
|
|
|
|
|
|
|
HOOKS => { # Returned values of hooks / Types of hooks |
|
95
|
|
|
|
|
|
|
caccess => { |
|
96
|
|
|
|
|
|
|
aliases => [qw/caccess access/], |
|
97
|
|
|
|
|
|
|
type => 'DUAL', # BOOL and HTTP way |
|
98
|
|
|
|
|
|
|
}, |
|
99
|
|
|
|
|
|
|
cdeny => { |
|
100
|
|
|
|
|
|
|
aliases => [qw/cdeny deny/], |
|
101
|
|
|
|
|
|
|
type => 'HTTP', # Analyzing common constants and HTTP 1.1 status codes |
|
102
|
|
|
|
|
|
|
}, |
|
103
|
|
|
|
|
|
|
cchck => { |
|
104
|
|
|
|
|
|
|
aliases => [qw/cchck chck check/], |
|
105
|
|
|
|
|
|
|
type => 'BOOL', # 0 - false / !0 - true |
|
106
|
|
|
|
|
|
|
}, |
|
107
|
|
|
|
|
|
|
mproc => { |
|
108
|
|
|
|
|
|
|
aliases => [qw/mproc proc proccess/], |
|
109
|
|
|
|
|
|
|
type => 'HTTP', # Analyzing common constants and HTTP 1.1 status codes |
|
110
|
|
|
|
|
|
|
}, |
|
111
|
|
|
|
|
|
|
vform => { |
|
112
|
|
|
|
|
|
|
aliases => [qw/vform form/], |
|
113
|
|
|
|
|
|
|
type => 'HTTP', # Analyzing common constants and HTTP 1.1 status codes |
|
114
|
|
|
|
|
|
|
}, |
|
115
|
|
|
|
|
|
|
}, |
|
116
|
|
|
|
|
|
|
}; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub ActionTransaction { |
|
119
|
|
|
|
|
|
|
# Îñíîâíàÿ òðàíçàêöèÿ (âîçâðàùàåò êîä âîçâðàòà) |
|
120
|
|
|
|
|
|
|
my $m = shift || ''; |
|
121
|
|
|
|
|
|
|
my $key = shift || return 0; |
|
122
|
|
|
|
|
|
|
my $event = shift || ''; |
|
123
|
|
|
|
|
|
|
croak("The method call is made ActionTransaction not in the style of OOP") unless ref($m) =~ /MPMinus/; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $sts = 0; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Âûïîëíåíèå ïðîöåäóðû äîñòóïà (false - deny; true - allow) |
|
128
|
|
|
|
|
|
|
$sts = ActionExecute($m,$key,'caccess'); |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Ïðîâåðêà íà äîñòóï |
|
131
|
|
|
|
|
|
|
unless ($sts) { |
|
132
|
|
|
|
|
|
|
# Ïðîâåðêà íå ïðîøëà - çàïóñê îáðàáîò÷èêà cdeny |
|
133
|
|
|
|
|
|
|
$sts = ActionExecute($m,$key,'cdeny'); |
|
134
|
|
|
|
|
|
|
return $sts; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
return $sts if $sts >= 300; # Âîçâðàò åñëè êîä 300 è áîëåå (àíàëèçèðóåòñÿ ðåçóëüòàò caccess) |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# Çàïóñê ïðîöåññà åñëè åñòü ñîáûòèå è óäà÷íî âûïîëíèëàñü ïðîâåðêà (âàëèäàöèÿ) ïàðàìåòðîâ |
|
139
|
|
|
|
|
|
|
$sts = ActionExecute($m,$key,'mproc') if (($event =~ /go/i) && ActionExecute($m,$key,'cchck')); |
|
140
|
|
|
|
|
|
|
return $sts if $sts >= 300; # Âîçâðàò åñëè êîä 300 è áîëåå |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Ïîêàçûâàåì ôîðìó |
|
143
|
|
|
|
|
|
|
$sts = ActionExecute($m,$key,'vform'); |
|
144
|
|
|
|
|
|
|
return $sts; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
sub ActionExecute { |
|
147
|
|
|
|
|
|
|
# Âûïîëíèòü îäèí èëè íåñêîëüêî ïðîöåäóð îáðàáîò÷èêîâ äî ïåðâîãî 0-ãî (false) êîäà âîçâðàòà |
|
148
|
|
|
|
|
|
|
my $m = shift || ''; |
|
149
|
|
|
|
|
|
|
my $key = shift || return 0; |
|
150
|
|
|
|
|
|
|
my $hook = shift || return 0; |
|
151
|
|
|
|
|
|
|
my @params = @_; |
|
152
|
|
|
|
|
|
|
croak("The method call is made ActionExecute not in the style of OOP") unless ref($m) =~ /MPMinus/; |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
return 0 unless ActionCheck($m,$key); # Åñëè êëþ÷à íåò -- âûõîä |
|
155
|
|
|
|
|
|
|
my %hooks = %{(HOOKS)}; |
|
156
|
|
|
|
|
|
|
return 0 unless grep {$_ eq $hook} keys %hooks; # Âîçâðàò 0 åñëè íåîïðåäåëåí êîíòåêñò òîãî ÷òî âîçâðàùàòü (default) |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# ïðèíèìàåì õåíäëåð îáðàáîò÷èêà .mpm |
|
159
|
|
|
|
|
|
|
my $grec = $m->drec; |
|
160
|
|
|
|
|
|
|
my $rec = $grec->{actions}{$key}{handler}; |
|
161
|
|
|
|
|
|
|
my $phase = _getPhaseByAlias($rec,$hook); |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
#$m->debug("> Running $hook"); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
#no strict 'refs'; # Äîáàâëåíî äëÿ âîçìîæíîñòè äîñòóïà ê ññûëêàì êàê ïðîöåäóðàì |
|
166
|
|
|
|
|
|
|
if (ref($phase) eq 'CODE') { |
|
167
|
|
|
|
|
|
|
# Âûïîëíÿåì êîä |
|
168
|
|
|
|
|
|
|
#$m->debug("> -- $hook -> CODE"); |
|
169
|
|
|
|
|
|
|
return $phase->($m,@params) |
|
170
|
|
|
|
|
|
|
} elsif (ref($phase) eq 'ARRAY') { |
|
171
|
|
|
|
|
|
|
# Âûïîëíÿåì êàñêàä êîäîâ äî ïåðâîé íåóäà÷è |
|
172
|
|
|
|
|
|
|
my $status; |
|
173
|
|
|
|
|
|
|
foreach (@$phase) { |
|
174
|
|
|
|
|
|
|
# $m->debug($_->($m,@params)); |
|
175
|
|
|
|
|
|
|
$status = (ref($_) eq 'CODE') ? $_->($m,@params) : 0; |
|
176
|
|
|
|
|
|
|
#$m->debug("> $hook -> CODE[$status]"); |
|
177
|
|
|
|
|
|
|
my $typ = $hooks{$hook}{type}; |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
if ($typ eq 'BOOL') { |
|
180
|
|
|
|
|
|
|
last unless $status; # Âûõîä åñëè õîòÿáû êòî-òî âåðíóë çíà÷åíèå false |
|
181
|
|
|
|
|
|
|
} elsif ($typ eq 'HTTP') { |
|
182
|
|
|
|
|
|
|
# Âûõîä åñëè îòâåò >=300 (REDIRECTIONS AND ERRORS) |
|
183
|
|
|
|
|
|
|
last unless (($status =~ /^[+\-]?\d+$/) && $status < 300); |
|
184
|
|
|
|
|
|
|
} elsif ($typ eq 'DUAL') { |
|
185
|
|
|
|
|
|
|
last unless $status; # Âûõîä åñëè õîòÿáû êòî-òî âåðíóë çíà÷åíèå false |
|
186
|
|
|
|
|
|
|
# Âûõîä åñëè îòâåò 0 (OK) èëè >=300 (REDIRECTIONS AND ERRORS) |
|
187
|
|
|
|
|
|
|
last unless (($status =~ /^[+\-]?\d+$/) && $status < 300); |
|
188
|
|
|
|
|
|
|
} else { # VOID and etc. |
|
189
|
|
|
|
|
|
|
$status = Apache2::Const::OK; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
return $status; |
|
193
|
|
|
|
|
|
|
} else { |
|
194
|
|
|
|
|
|
|
#$m->debug("> -- $hook -> VOID"); |
|
195
|
|
|
|
|
|
|
return 0; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
return 0; |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
sub ActionCheck { |
|
200
|
|
|
|
|
|
|
my $m = shift || ''; |
|
201
|
|
|
|
|
|
|
my $key = shift || return 0; |
|
202
|
|
|
|
|
|
|
croak("The method call is made ActionCheck not in the style of OOP") unless ref($m) =~ /MPMinus/; |
|
203
|
|
|
|
|
|
|
return $m->drec->{actions}{$key} ? 1 : 0; |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
sub getActionRecord { |
|
206
|
|
|
|
|
|
|
# Ïðî÷èòàòü ìåòàîïðåäåëåíèÿ ïî êëþ÷ó èëè âñå |
|
207
|
|
|
|
|
|
|
my $m = shift || ''; |
|
208
|
|
|
|
|
|
|
my $key = shift; |
|
209
|
|
|
|
|
|
|
croak("The method call is made getActionRecord not in the style of OOP") unless ref($m) =~ /MPMinus/; |
|
210
|
|
|
|
|
|
|
my $grec = $m->drec; |
|
211
|
|
|
|
|
|
|
if ($key) { |
|
212
|
|
|
|
|
|
|
return $grec->{actions}{$key} ? $grec->{actions}{$key} : undef; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
return $grec->{actions}; |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
sub _getPhaseByAlias { |
|
217
|
|
|
|
|
|
|
my $rec = shift || {}; |
|
218
|
|
|
|
|
|
|
my $hook = shift || '_'; |
|
219
|
|
|
|
|
|
|
my %hooks = %{(HOOKS)}; |
|
220
|
|
|
|
|
|
|
my $aliases = $hooks{$hook}{aliases}; |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my $ret; |
|
223
|
|
|
|
|
|
|
foreach (@$aliases) { |
|
224
|
|
|
|
|
|
|
if ($rec->{$_} && ref($rec->{$_})) { |
|
225
|
|
|
|
|
|
|
$ret = $rec->{$_}; |
|
226
|
|
|
|
|
|
|
last; |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
return $ret; |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
1; |