MPMinus/MainTools.pm

filter: Statementstmt 51.9% 40 / 77 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 60.0% 12 / 20 Podpod 100% 8 / 8 totaltotal 40.5% 60 / 148 SCAR 47.4
CC
19
Cov
36%
getSID
72.0
geturl
42.0
msoconf2args
30.0
CRAP 114.9
« MPMinus/Debug/System.pm ↑ Summary MPMinus/Store/MultiStore.pm »
1 package MPMinus::MainTools; # $Id: MainTools.pm 128 2013-05-08 12:35:26Z minus $
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3
4 =head1 NAME
5
6 MPMinus::MainTools - The main function without the support of the configuration
7
8 =head1 VERSION
9
10 Version 1.24
11
12 =head1 SYNOPSIS
13
14 use MPMinus::MainTools;
15
16 =head1 DESCRIPTION
17
18 The module works with the main functions without the support of the configuration
19
20 =over 8
21
22 =item B<correct_loginpass>
23
24 my $login = correct_loginpass( "anonymous" ); # 'anonymous'
25 my $password = correct_loginpass( "{MOON}" ); # ''
26
27 Correcting a login or password. Issued lc () format username / password thatmust not contain
28 characters other than those listed:
29
30 a-zA-Z0-9.,-_!@#$%^&*+=/\~|:;
31
32 Otherwise, it returns an empty value''
33
34 =item B<getHiTime>
35
36 See function L<Time::HiRes/gettimeofday>
37
38 =item B<getSID>
39
40 my $sid = getSID( $length, $chars );
41 my $sid = getSID( 16, "m" ); # 16 successful chars consisting of MD5 hash
42 my $sid = getSID( 20 ); # 20 successful chars consisting of a set of chars 0-9A-Z
43 my $sid = getSID(); # 16 successful chars consisting of a set of chars 0-9A-Z
44
45 Function returns Session-ID (SID)
46
47 $chars - A string containing a collection of characters or code:
48
49 d - characters 0-9
50 w - characters A-Z
51 h - HEX characters 0-9A-F
52 m - Digest::MD5 function from Apache::Session::Generate::MD5
53 - default characters 0-9A-Z
54
55 =item B<geturl>
56
57 my $data = geturl( "http://www.example.com" );
58 my $data = geturl( "http://www.example.com", "login", "password" );
59
60 Getting a remote location or a simple authentication method in the argument.
61 If the page is not then return empty ('').
62
63 =item B<msoconf2args>
64
65 Converting MSO configuration section to MultiStore -mso arguments
66
67 my %args = msoconf2args($m->conf('store'));
68 my $mso = new MPMinus::Store::MultiStore(
69 -m => $m,
70 -mso => \%args,
71 );
72
73 In conf/mso.conf:
74
75 <store foo>
76 dsn DBI:mysql:database=NAME;host=HOST
77 user login
78 pass password
79 <Attr>
80 mysql_enable_utf8 1
81 RaiseError 0
82 PrintError 0
83 </Attr>
84 </store>
85
86 <store bar>
87 dsn DBI:Oracle:SID
88 user login
89 pass password
90 <Attr>
91 RaiseError 0
92 PrintError 0
93 </Attr>
94 </store>
95
96 =item B<current_datetime, localtime2datetime and tagRestore>
97
98 Deprecated functions
99
100 =back
101
102 =head1 HISTORY
103
104 =over 8
105
106 =item B<1.00 / 28.02.2008>
107
108 Init version on base mod_main 1.00.0002
109
110 =item B<1.01 / 12.01.2009>
111
112 Fixed bugs in functions *datatime*
113
114 =item B<1.10 / 27.02.2009>
115
116 Module is merged into the global module level
117
118 =item B<1.20 / 28.04.2011>
119
120 Binary file's mode supported
121
122 =item B<1.21 / 14.05.2011>
123
124 modified functions tag and slash
125
126 =item B<1.22 / 19.10.2011>
127
128 Added function datetime2localtime and localtime2datetime as alias for localtime2date_time.
129
130 Added alias current_datetime for current_date_time
131
132 =item B<1.23 / Wed Apr 24 14:53:38 2013 MSK>
133
134 General refactoring
135
136 =item B<1.24 / Wed May 8 15:37:02 2013 MSK>
137
138 Added function msoconf2args
139
140 =back
141
142 =head1 AUTHOR
143
144 Serz Minus (Lepenkov Sergey) L<http://serzik.ru> E<lt>minus@mail333.comE<gt>
145
146 =head1 COPYRIGHT
147
148 Copyright (C) 1998-2013 D&D Corporation. All Rights Reserved
149
150 =head1 LICENSE
151
152 This program is free software: you can redistribute it and/or modify
153 it under the terms of the GNU General Public License as published by
154 the Free Software Foundation, either version 3 of the License, or
155 (at your option) any later version.
156
157 This program is distributed in the hope that it will be useful,
158 but WITHOUT ANY WARRANTY; without even the implied warranty of
159 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160 GNU General Public License for more details.
161
162 See C<LICENSE> file
163
164 =cut
165
166 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
167 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
168 1 $VERSION = 1.24;
169
170 1 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
171 1 our @EXPORT = qw(
172 tagRestore current_datetime localtime2datetime
173 correct_loginpass
174 getHiTime
175 getSID
176 geturl
177 msoconf2args
178 );
179 1 our @EXPORT_OK = @EXPORT;
180
181 1 ▶use Time::HiRes qw(gettimeofday);
Subroutine BEGIN: called CC=1 SCAR=0.0
182 1 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
183 1 ▶use LWP::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
184 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
185 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
186 1 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
187 1 ▶use CTK::Util qw/current_date_time localtime2date_time tag_create/;
Subroutine BEGIN: called CC=1 SCAR=0.0
188 1 ▶use CTK::ConfGenUtil qw/hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
189
190 sub correct_loginpass {
191 # ïðîöåäóðà êîððåêòèðîâêè ëîãèíà/ïàðîëÿ. Âûäà¸òñÿ lc() ôîðìàò ëîãèíà/ïàðîëÿ
192 0 ▶ my $v = shift || '';
Subroutine correct_loginpass: not called CC=3 SCAR=24.8
Pod documented
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
193 0 ▶ return "" if $v =~ /[^a-zA-Z0-9.,-_!@#\$%^&*+=\/\\~|]|[:;]/g;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ m[[^a-zA-Z0-9.,-_!\@#\$%^&*+=/\\~|]|[:;]]g 0 0 0
194 0 return lc($v);
195 }
196 sub getHiTime {
197 0 ▶ return gettimeofday()
Subroutine getHiTime: not called CC=1 SCAR=6.9
Pod documented
198 }
199 sub getSID {
200 # Ïðîöåäóðà âîçâðàùàåò Session-ID (SID) äëÿ êîíòðîëÿ ñîñòîÿíèÿ ñåññèé
201 # IN:
202 # $length - Êîëè÷åñòâî ñèìâîëîâ
203 # $chars - Ñòðîêà ñèìâîëîâ íàáîðà èëè êîä:
204 # d - ñèìâîëû 0-9
205 # w - ñèìâîëû A-Z
206 # h - øåñíàäöàòèðè÷íûå ñèìâîëû 0-9A-F
207 # m - Digest::MD5 function from Apache::Session::Generate::MD5
208 # - Ïî óìîë÷àíèþ ñèìâîëû 0-9A-Z
209 # OUT:
210 # SID
211 0 ▶ my $length = shift || 16; # Êîëè÷åñòâî ñèìâîëîâ â ñëó÷àéíîé ïîñëåäîâàòåëüíîñòè
Subroutine getSID: not called CC=8 SCAR=42.8
Pod documented
Condition0%0/2
shift() || 16
l!l
00
MC/DC0%0/1
shift() || 16
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
212 0 ▶ my $chars = shift || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; # Ñòðîêà ñèìâîëîâ
Condition0%0/2
shift() || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
l!l
00
MC/DC0%0/1
shift() || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
213
214 # Copyright(c) 2000, 2001 Jeffrey William Baker (jwbaker@acm.org)
215 # Distribute under the Perl License
216 # Source: Apache::Session::Generate::MD5
217 0 ▶ return substr(
Branch: 1 branch
BranchTrueFalseTotal
if $chars =~ /^\s*m\s*$/i 0 0 0
218 Digest::MD5::md5_hex(
219 Digest::MD5::md5_hex(
220 time() . {} . rand() . $$
221 )
222 ), 0, $length) if $chars =~ /^\s*m\s*$/i;
223
224 0 ▶ $chars = "0123456789" if $chars =~ /^\s*d\s*$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $chars =~ /^\s*d\s*$/i 0 0 0
225 0 ▶ $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" if $chars =~ /^\s*w\s*$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $chars =~ /^\s*w\s*$/i 0 0 0
226 0 ▶ $chars = "0123456789ABCDEF" if $chars =~ /^\s*h\s*$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $chars =~ /^\s*h\s*$/i 0 0 0
227
228 0 my @rows = split //, $chars;
229
230 0 my $retv = '';
231 0 ▶ for (my $i=0; $i<$length; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $length) 0 0 0
232 0 $retv .= $rows[int(rand(length($chars)-1))]
233 }
234
235 0 return "$retv"
236 }
237 sub geturl {
238 #
239 # Ïîëó÷åíèå ðåñóðñà ïðîñòûì èëè àóòåíòèôèêàöèîííûì ñïîñîáîì â çàâèñèìîñòè îò àðãóìåíòà.
240 # Åñëè ñòðàíèöû íåò òî âîçâðàùàåòñÿ ïóñòî
241 #
242 0 ▶ my $url = shift || return ''; # URL (àäðåñ ôàéëà)
Subroutine geturl: not called CC=6 SCAR=37.4
Pod documented
Condition0%0/2
shift() || (return '')
l!l
00
MC/DC0%0/1
shift() || (return '')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
243 0 ▶ my $login = shift || ''; # Ëîãèí Apache àâòîðèçàöèè êëèåíòà. Èíà÷å àâòîðèçàöèÿ íå ïðîèçâîäèòñÿ
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
244 0 ▶ my $password = shift || ''; # Ïàðîëü Apache àâòîðèçàöèè êëèåíòà
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
245
246 0 ▶ if ($login eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($login eq '') { } 0 0 0
247 0 return get($url);
248 } else {
249 0 my $ua = new LWP::UserAgent;
250 0 my $req = new HTTP::Request(GET => $url);
251 0 $req->authorization_basic($login, $password);
252 0 my $res = $ua->request($req);
253 0 ▶ return $res->is_success ? $res->content : '';
Branch: 1 branch
BranchTrueFalseTotal
$res->is_success ? : 0 0 0
254 }
255 }
256 sub msoconf2args {
257 #
258 # Ïðåîáðàçîâàíèå ñòðóêòóðû êîíôèãóðàöèè MSO â ñòðóêòóðó äëÿ èíòåðôåéñà MultiStore
259 #
260 0 ▶ my $mso_conf = shift;
Subroutine msoconf2args: not called CC=5 SCAR=34.0
Pod documented
261 0 ▶ my @stores = $mso_conf && ref($mso_conf) eq 'HASH' ? keys(%$mso_conf) : ();
Branch: 1 branch
BranchTrueFalseTotal
$mso_conf && ref $mso_conf eq 'HASH' ? : 0 0 0
Condition0%0/3
$mso_conf and ref $mso_conf eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$mso_conf and ref $mso_conf eq "HASH"
$mso_conf ref $mso_conf eq "HASH"
Truth table0%0/3
A and B
A= $mso_confB= ref $mso_conf eq "HASH"
ABresult
0X0
100
111
262 0 my %args = ();
263 0 for (@stores) {
264 0 my $store = hash($mso_conf, $_);
265 0 $args{$_} = {};
266 0 ▶ while (my ($key, $value) = each %$store) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$store) 0 0 0
267 0 $args{$_}{"-".$key} = $value
268 }
269 }
270 0 return %args;
271 }
272
273 # Íåîôèöèàëüíûå ôóíêöèè äëÿ îáðàòíîé ñîâìåñòèìîñòè ïðîåêòîâ suffit, mnshome.info è share.mnshome.info
274 0 ▶sub tagRestore { &tag_create(@_) }
Subroutine tagRestore: not called CC=1 SCAR=6.9
Pod documented
275 0 ▶sub current_datetime { &current_date_time(@_) }
Subroutine current_datetime: not called CC=1 SCAR=6.9
Pod documented
276 0 ▶sub localtime2datetime { &localtime2date_time(@_) }
Subroutine localtime2datetime: not called CC=1 SCAR=6.9
Pod documented
277
278 1 1;
279
« MPMinus/Debug/System.pm ↑ Summary MPMinus/Store/MultiStore.pm »