line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MPMinus::MainTools; # $Id: MainTools.pm 128 2013-05-08 12:35:26Z minus $ |
2
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
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
|
|
|
1
|
|
3
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
167
|
1
|
|
|
1
|
|
2
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
168
|
|
|
|
|
|
|
$VERSION = 1.24; |
169
|
|
|
|
|
|
|
|
170
|
1
|
|
|
1
|
|
10
|
use base qw/Exporter/; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
82
|
|
171
|
|
|
|
|
|
|
our @EXPORT = qw( |
172
|
|
|
|
|
|
|
tagRestore current_datetime localtime2datetime |
173
|
|
|
|
|
|
|
correct_loginpass |
174
|
|
|
|
|
|
|
getHiTime |
175
|
|
|
|
|
|
|
getSID |
176
|
|
|
|
|
|
|
geturl |
177
|
|
|
|
|
|
|
msoconf2args |
178
|
|
|
|
|
|
|
); |
179
|
|
|
|
|
|
|
our @EXPORT_OK = @EXPORT; |
180
|
|
|
|
|
|
|
|
181
|
1
|
|
|
1
|
|
405
|
use Time::HiRes qw(gettimeofday); |
|
1
|
|
|
|
|
940
|
|
|
1
|
|
|
|
|
4
|
|
182
|
1
|
|
|
1
|
|
131
|
use Digest::MD5; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
183
|
1
|
|
|
1
|
|
378
|
use LWP::Simple; |
|
1
|
|
|
|
|
37022
|
|
|
1
|
|
|
|
|
7
|
|
184
|
1
|
|
|
1
|
|
261
|
use HTTP::Request; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
55
|
|
185
|
1
|
|
|
1
|
|
3
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
186
|
1
|
|
|
1
|
|
3
|
use HTTP::Headers; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
187
|
1
|
|
|
1
|
|
2
|
use CTK::Util qw/current_date_time localtime2date_time tag_create/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
188
|
1
|
|
|
1
|
|
372
|
use CTK::ConfGenUtil qw/hash/; |
|
1
|
|
|
|
|
659
|
|
|
1
|
|
|
|
|
519
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub correct_loginpass { |
191
|
|
|
|
|
|
|
# ïðîöåäóðà êîððåêòèðîâêè ëîãèíà/ïàðîëÿ. Âûäà¸òñÿ lc() ôîðìàò ëîãèíà/ïàðîëÿ |
192
|
0
|
|
0
|
0
|
1
|
|
my $v = shift || ''; |
193
|
0
|
0
|
|
|
|
|
return "" if $v =~ /[^a-zA-Z0-9.,-_!@#\$%^&*+=\/\\~|]|[:;]/g; |
194
|
0
|
|
|
|
|
|
return lc($v); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
sub getHiTime { |
197
|
0
|
|
|
0
|
1
|
|
return gettimeofday() |
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
|
|
0
|
0
|
1
|
|
my $length = shift || 16; # Êîëè÷åñòâî ñèìâîëîâ â ñëó÷àéíîé ïîñëåäîâàòåëüíîñòè |
212
|
0
|
|
0
|
|
|
|
my $chars = shift || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; # Ñòðîêà ñèìâîëîâ |
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
|
0
|
|
|
|
|
return substr( |
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
|
0
|
|
|
|
|
$chars = "0123456789" if $chars =~ /^\s*d\s*$/i; |
225
|
0
|
0
|
|
|
|
|
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" if $chars =~ /^\s*w\s*$/i; |
226
|
0
|
0
|
|
|
|
|
$chars = "0123456789ABCDEF" if $chars =~ /^\s*h\s*$/i; |
227
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
my @rows = split //, $chars; |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
my $retv = ''; |
231
|
0
|
|
|
|
|
|
for (my $i=0; $i<$length; $i++) { |
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
|
|
0
|
0
|
1
|
|
my $url = shift || return ''; # URL (àäðåñ ôàéëà) |
243
|
0
|
|
0
|
|
|
|
my $login = shift || ''; # Ëîãèí Apache àâòîðèçàöèè êëèåíòà. Èíà÷å àâòîðèçàöèÿ íå ïðîèçâîäèòñÿ |
244
|
0
|
|
0
|
|
|
|
my $password = shift || ''; # Ïàðîëü Apache àâòîðèçàöèè êëèåíòà |
245
|
|
|
|
|
|
|
|
246
|
0
|
0
|
|
|
|
|
if ($login eq '' ) { |
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
|
0
|
|
|
|
|
return $res->is_success ? $res->content : ''; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
sub msoconf2args { |
257
|
|
|
|
|
|
|
# |
258
|
|
|
|
|
|
|
# Ïðåîáðàçîâàíèå ñòðóêòóðû êîíôèãóðàöèè MSO â ñòðóêòóðó äëÿ èíòåðôåéñà MultiStore |
259
|
|
|
|
|
|
|
# |
260
|
0
|
|
|
0
|
1
|
|
my $mso_conf = shift; |
261
|
0
|
0
|
0
|
|
|
|
my @stores = $mso_conf && ref($mso_conf) eq 'HASH' ? keys(%$mso_conf) : (); |
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) { |
267
|
0
|
|
|
|
|
|
$args{$_}{"-".$key} = $value |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
} |
270
|
0
|
|
|
|
|
|
return %args; |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
# Íåîôèöèàëüíûå ôóíêöèè äëÿ îáðàòíîé ñîâìåñòèìîñòè ïðîåêòîâ suffit, mnshome.info è share.mnshome.info |
274
|
0
|
|
|
0
|
1
|
|
sub tagRestore { &tag_create(@_) } |
275
|
0
|
|
|
0
|
1
|
|
sub current_datetime { ¤t_date_time(@_) } |
276
|
0
|
|
|
0
|
1
|
|
sub localtime2datetime { &localtime2date_time(@_) } |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
1; |
279
|
|
|
|
|
|
|
|