line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gantry::Utils::Validate; |
2
|
6
|
|
|
6
|
|
58225
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
241
|
|
3
|
6
|
|
|
6
|
|
3827
|
use Date::Calc qw( check_date ); |
|
6
|
|
|
|
|
133478
|
|
|
6
|
|
|
|
|
685
|
|
4
|
6
|
|
|
6
|
|
6243
|
use Mail::RFC822::Address (); |
|
6
|
|
|
|
|
5165
|
|
|
6
|
|
|
|
|
4974
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
############################################################ |
7
|
|
|
|
|
|
|
# Functions # |
8
|
|
|
|
|
|
|
############################################################ |
9
|
|
|
|
|
|
|
sub new { |
10
|
0
|
|
|
0
|
1
|
|
my ( $class, $opt ) = @_; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my $self = {}; |
13
|
0
|
|
|
|
|
|
bless( $self, $class ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# populate self with data from site |
16
|
0
|
|
|
|
|
|
return( $self ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
} # end new |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#------------------------------------------------- |
21
|
|
|
|
|
|
|
# is_date( $date ) |
22
|
|
|
|
|
|
|
#------------------------------------------------- |
23
|
|
|
|
|
|
|
sub is_date { |
24
|
0
|
|
|
0
|
1
|
|
my( $self, $date ) = ( shift, shift ); |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! defined $date ); |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
return( 0 ) if ( $date !~ /^\d{1,2}-\d{1,2}-\d{4}$/ ); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my ( $month, $day, $year ) = split( '-', $date ); |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! check_date( $year, $month, $day ) ); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return( 1 ); |
35
|
|
|
|
|
|
|
} # END is_date |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#------------------------------------------------- |
38
|
|
|
|
|
|
|
# is_email( $email ) |
39
|
|
|
|
|
|
|
#------------------------------------------------- |
40
|
|
|
|
|
|
|
sub is_email { |
41
|
0
|
|
|
0
|
1
|
|
my( $self, $email ) = ( shift, shift ); |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ( Mail::RFC822::Address::valid( $email ) ) { |
44
|
0
|
|
|
|
|
|
return 1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return 0; |
48
|
|
|
|
|
|
|
} # END is_email |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#------------------------------------------------- |
51
|
|
|
|
|
|
|
# is_float( $float ) |
52
|
|
|
|
|
|
|
#------------------------------------------------- |
53
|
|
|
|
|
|
|
sub is_float { |
54
|
0
|
|
|
0
|
1
|
|
my( $self, $float ) = ( shift, shift ); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! defined $float ); |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
return( 1 ) if ( $self->is_integer( $float ) ); |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
return( 0 ) if ( $float !~ /^-?\d+\.\d+$/ ); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return( 1 ); |
63
|
|
|
|
|
|
|
} # END is_float |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#------------------------------------------------- |
66
|
|
|
|
|
|
|
# is_ident( $ident ) |
67
|
|
|
|
|
|
|
#------------------------------------------------- |
68
|
|
|
|
|
|
|
sub is_ident { |
69
|
0
|
|
|
0
|
1
|
|
my ( $self, $ident ) = ( shift, shift ); |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! defined $ident ); |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! $self->is_text( $ident ) ); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
return( 0 ) if ( $ident =~ /\s/ ); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return( 1 ); |
78
|
|
|
|
|
|
|
} # END is_ident |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#------------------------------------------------- |
81
|
|
|
|
|
|
|
# is_integer( $int ) |
82
|
|
|
|
|
|
|
#------------------------------------------------- |
83
|
|
|
|
|
|
|
sub is_integer { |
84
|
0
|
|
|
0
|
1
|
|
my( $self, $int ) = ( shift, shift ); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! defined $int ); |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
return( 0 ) if ( $int !~ /^-?\d+$/ ); |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return( 1 ); |
91
|
|
|
|
|
|
|
} # END is_integer |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#------------------------------------------------- |
94
|
|
|
|
|
|
|
# is_ip( $ip ) |
95
|
|
|
|
|
|
|
#------------------------------------------------- |
96
|
|
|
|
|
|
|
sub is_ip { |
97
|
0
|
|
|
0
|
1
|
|
my ( $self, $ip ) = ( shift, shift ); |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! defined $ip ); |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
return( 0 ) if ( $ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ ); |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
return( 1 ); |
104
|
|
|
|
|
|
|
} # END is_ip |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#------------------------------------------------- |
107
|
|
|
|
|
|
|
# is_mac( $mac ) |
108
|
|
|
|
|
|
|
#------------------------------------------------- |
109
|
|
|
|
|
|
|
sub is_mac { |
110
|
0
|
|
|
0
|
1
|
|
my( $self, $mac ) = ( shift, shift ); |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! defined $mac ); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# prolly needs to check more ... |
115
|
0
|
0
|
|
|
|
|
return( 0 ) if ( $mac !~ /^[0-9A-Fa-f:\.\-\ ]+$/m ); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return( 1 ); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} # END is_mac |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#------------------------------------------------- |
122
|
|
|
|
|
|
|
# is_number( $number ) |
123
|
|
|
|
|
|
|
#------------------------------------------------- |
124
|
|
|
|
|
|
|
sub is_number { |
125
|
0
|
|
|
0
|
1
|
|
my( $self, $number ) = ( shift, shift ); |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! defined $number ); |
128
|
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
return( 1 ) if ( $self->is_integer( $number ) ); |
130
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
|
return( 1 ) if ( $self->is_float( $number ) ); |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return( 0 ); |
134
|
|
|
|
|
|
|
} # END is_number |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
#------------------------------------------------- |
137
|
|
|
|
|
|
|
# is_text( $text ) |
138
|
|
|
|
|
|
|
#------------------------------------------------- |
139
|
|
|
|
|
|
|
sub is_text { |
140
|
0
|
|
|
0
|
1
|
|
my ( $self, $text ) = ( shift, shift ); |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! defined $text ); |
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
return( 0 ) if ( length( $text ) < 1 ); |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return( 1 ); |
147
|
|
|
|
|
|
|
} # END is_text |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#------------------------------------------------- |
150
|
|
|
|
|
|
|
# is_time( $time ) |
151
|
|
|
|
|
|
|
#------------------------------------------------- |
152
|
|
|
|
|
|
|
sub is_time { |
153
|
0
|
|
|
0
|
1
|
|
my ( $self, $time ) = ( shift, shift ); |
154
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
return( 0 ) if ( ! defined $time ); |
156
|
|
|
|
|
|
|
|
157
|
0
|
0
|
|
|
|
|
return( 0 ) if ( $time !~ /^\d+:\d+(:\d+)?$/ ); |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
my ( $hours, $minutes, $seconds ) = split( ':', $time ); |
160
|
|
|
|
|
|
|
|
161
|
0
|
0
|
0
|
|
|
|
return( 0 ) if ( ( $hours < 0 ) || ( $hours > 23 ) ); |
162
|
0
|
0
|
0
|
|
|
|
return( 0 ) if ( ( $minutes < 0 ) || ( $minutes > 59 ) ); |
163
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
|
|
|
if ( defined $seconds ) { |
165
|
0
|
0
|
0
|
|
|
|
return( 0 ) if ( ( $seconds < 0 ) || ( $seconds > 59 ) ); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
return( 1 ); |
169
|
|
|
|
|
|
|
} # END is_time |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# EOF |
172
|
|
|
|
|
|
|
1; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
__END__ |