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