MLite/Util.pm

filter: Statementstmt 59.4% 22 / 37 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 6 / 10 Podpod 100% 4 / 4 totaltotal 47.7% 32 / 67 CC 8 SCAR 35.4
CC
8
Cov
43%
getSID
72.0
getHiTime
2.0
sendmail
2.0
CRAP 34.6
« MLite/AuthSsn.pm ↑ Summary MLite.pm »
1 package WWW::MLite::Util; # $Id: Util.pm 15 2014-06-04 06:24:25Z minus $
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3
4 =head1 NAME
5
6 WWW::MLite::Util - Utility functions
7
8 =head1 VERSION
9
10 Version 1.01
11
12 =head1 SYNOPSIS
13
14 use WWW::MLite::Util;
15
16 =head1 DESCRIPTION
17
18 Internal utility functions
19
20 =over 8
21
22 =item B<getHiTime>
23
24 See function L<Time::HiRes/gettimeofday>
25
26 =item B<getSID>
27
28 my $sid = getSID( $length, $chars );
29 my $sid = getSID( 16, "m" ); # 16 successful chars consisting of MD5 hash
30 my $sid = getSID( 20 ); # 20 successful chars consisting of a set of chars 0-9A-Z
31 my $sid = getSID(); # 16 successful chars consisting of a set of chars 0-9A-Z
32
33 Function returns Session-ID (SID)
34
35 $chars - A string containing a collection of characters or code:
36
37 d - characters 0-9
38 w - characters A-Z
39 h - HEX characters 0-9A-F
40 m - Digest::MD5 function from Apache::Session::Generate::MD5
41 - default characters 0-9A-Z
42
43 =item B<sendmail, send_mail>
44
45 my $sendstatus = sendmail(
46 -to => $mlite->conf->server_admin,
47 -cc => 'foo@example.com', ### OPTIONAL
48 -from => sprintf('"%s" <%s>',$mlite->conf->server_name,$mlite->conf->server_admin),
49 -subject => 'Subject',
50 -message => 'Message',
51
52 # Encoding/Types
53 -type => 'text/plain', ### OPTIONAL
54 -charset => 'windows-1251', ### OPTIONAL
55
56 # Program sendmail
57 -sendmail => '/usr/sbin/sendmail',### OPTIONAL
58 -flags => '-t', ### OPTIONAL
59
60 # SMTP
61 -smtp => ($mlite->conf->smtp_host || ''), ### OPTIONAL
62 -smtpuser => ($mlite->conf->smtp_user || ''), ### OPTIONAL
63 -smtppass => ($mlite->conf->smtp_password || ''),### OPTIONAL
64
65 # Attaches
66 -attach => [ ### OPTIONAL
67 {
68 Type=>'text/plain',
69 Data=>'document 1 content',
70 Filename=>'doc1.txt',
71 Disposition=>'attachment',
72 },
73
74 {
75 Type=>'text/plain',
76 Data=>'document 2 content',
77 Filename=>'doc2.txt',
78 Disposition=>'attachment',
79 },
80
81 ### ... ###
82 ],
83 );
84
85 If you need to send a letter with only one attachment:
86
87 -attach => {
88 Type=>'text/html',
89 Data=>$att,
90 Filename=>'response.htm',
91 Disposition=>'attachment',
92 },
93
94 or
95
96 -attach => {
97 Type=>'image/gif',
98 Path=>'aaa000123.gif',
99 Filename=>'logo.gif',
100 Disposition=>'attachment',
101 },
102
103 Sending mail via L<CTK::Util/sendmail>
104
105 =back
106
107 =head1 HISTORY
108
109 See C<CHANGES> file
110
111 =head1 AUTHOR
112
113 Serz Minus (Lepenkov Sergey) L<http://www.serzik.com> E<lt>minus@mail333.comE<gt>
114
115 =head1 COPYRIGHT
116
117 Copyright (C) 1998-2014 D&D Corporation. All Rights Reserved
118
119 =head1 LICENSE
120
121 This program is free software: you can redistribute it and/or modify
122 it under the terms of the GNU General Public License as published by
123 the Free Software Foundation, either version 3 of the License, or
124 (at your option) any later version.
125
126 This program is distributed in the hope that it will be useful,
127 but WITHOUT ANY WARRANTY; without even the implied warranty of
128 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
129 GNU General Public License for more details.
130
131 See C<LICENSE> file
132
133 =cut
134
135 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
136 1 $VERSION = '1.01';
137
138 1 ▶use Time::HiRes qw(gettimeofday);
Subroutine BEGIN: called CC=1 SCAR=0.0
139 1 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
140 1 ▶use CTK::Util qw/ :BASE /; # Óòèëèòàðèé
Subroutine BEGIN: called CC=1 SCAR=0.0
141
142 1 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
143 1 our @EXPORT = qw(
144 getSID
145 getHiTime
146 sendmail send_mail
147 );
148 1 our @EXPORT_OK = @EXPORT;
149
150 sub getSID {
151 # Ïðîöåäóðà âîçâðàùàåò Session-ID (SID) äëÿ êîíòðîëÿ ñîñòîÿíèÿ ñåññèé
152 # IN:
153 # $length - Êîëè÷åñòâî ñèìâîëîâ
154 # $chars - Ñòðîêà ñèìâîëîâ íàáîðà èëè êîä:
155 # d - ñèìâîëû 0-9
156 # w - ñèìâîëû A-Z
157 # h - øåñíàäöàòèðè÷íûå ñèìâîëû 0-9A-F
158 # m - Digest::MD5 function from Apache::Session::Generate::MD5
159 # - Ïî óìîë÷àíèþ ñèìâîëû 0-9A-Z
160 # OUT:
161 # SID
162 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
163 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
164
165 # Copyright(c) 2000, 2001 Jeffrey William Baker (jwbaker@acm.org)
166 # Distribute under the Perl License
167 # Source: Apache::Session::Generate::MD5
168 0 ▶ return substr(
Branch: 1 branch
BranchTrueFalseTotal
if $chars =~ /^\s*m\s*$/i 0 0 0
169 Digest::MD5::md5_hex(
170 Digest::MD5::md5_hex(
171 time() . {} . rand() . $$
172 )
173 ), 0, $length) if $chars =~ /^\s*m\s*$/i;
174
175 0 ▶ $chars = "0123456789" if $chars =~ /^\s*d\s*$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $chars =~ /^\s*d\s*$/i 0 0 0
176 0 ▶ $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" if $chars =~ /^\s*w\s*$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $chars =~ /^\s*w\s*$/i 0 0 0
177 0 ▶ $chars = "0123456789ABCDEF" if $chars =~ /^\s*h\s*$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $chars =~ /^\s*h\s*$/i 0 0 0
178
179 0 my @rows = split //, $chars;
180
181 0 my $retv = '';
182 0 ▶ for (my $i=0; $i<$length; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $length) 0 0 0
183 0 $retv .= $rows[int(rand(length($chars)-1))]
184 }
185
186 0 return "$retv"
187 }
188 sub getHiTime {
189 0 ▶ return gettimeofday()
Subroutine getHiTime: not called CC=1 SCAR=6.9
Pod documented
190 }
191 sub sendmail {
192 # Îòïðàâêà ïèñüìà ñ ïîìîùüþ ìîäóëÿ CTK::Util::send_mail
193 0 ▶ my $self = shift;
Subroutine sendmail: not called CC=1 SCAR=6.9
Pod documented
194 0 return CTK::Util::send_mail(@_);
195 }
196 0 ▶sub send_mail { goto &sendmail };
Subroutine send_mail: not called CC=1 SCAR=6.9
Pod documented
197
198
199 1 1;
« MLite/AuthSsn.pm ↑ Summary MLite.pm »