| blib/lib/OpenCA/TRIStateCGI.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 9 | 297 | 3.0 |
| branch | 0 | 132 | 0.0 |
| condition | 0 | 19 | 0.0 |
| subroutine | 3 | 16 | 18.7 |
| pod | 0 | 13 | 0.0 |
| total | 12 | 477 | 2.5 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | ## OpenCA::TRIStateCGI.pm | ||||||
| 2 | ## | ||||||
| 3 | ## Copyright (C) 1998-1999 Massimiliano Pala (madwolf@openca.org) | ||||||
| 4 | ## All rights reserved. | ||||||
| 5 | ## | ||||||
| 6 | ## This library is free for commercial and non-commercial use as long as | ||||||
| 7 | ## the following conditions are aheared to. The following conditions | ||||||
| 8 | ## apply to all code found in this distribution, be it the RC4, RSA, | ||||||
| 9 | ## lhash, DES, etc., code; not just the SSL code. The documentation | ||||||
| 10 | ## included with this distribution is covered by the same copyright terms | ||||||
| 11 | ## | ||||||
| 12 | ## Copyright remains Massimiliano Pala's, and as such any Copyright notices | ||||||
| 13 | ## in the code are not to be removed. | ||||||
| 14 | ## If this package is used in a product, Massimiliano Pala should be given | ||||||
| 15 | ## attribution as the author of the parts of the library used. | ||||||
| 16 | ## This can be in the form of a textual message at program startup or | ||||||
| 17 | ## in documentation (online or textual) provided with the package. | ||||||
| 18 | ## | ||||||
| 19 | ## Redistribution and use in source and binary forms, with or without | ||||||
| 20 | ## modification, are permitted provided that the following conditions | ||||||
| 21 | ## are met: | ||||||
| 22 | ## 1. Redistributions of source code must retain the copyright | ||||||
| 23 | ## notice, this list of conditions and the following disclaimer. | ||||||
| 24 | ## 2. Redistributions in binary form must reproduce the above copyright | ||||||
| 25 | ## notice, this list of conditions and the following disclaimer in the | ||||||
| 26 | ## documentation and/or other materials provided with the distribution. | ||||||
| 27 | ## 3. All advertising materials mentioning features or use of this software | ||||||
| 28 | ## must display the following acknowledgement: | ||||||
| 29 | ## "This product includes OpenCA software written by Massimiliano Pala | ||||||
| 30 | ## (madwolf@openca.org) and the OpenCA Group (www.openca.org)" | ||||||
| 31 | ## 4. If you include any Windows specific code (or a derivative thereof) from | ||||||
| 32 | ## some directory (application code) you must include an acknowledgement: | ||||||
| 33 | ## "This product includes OpenCA software (www.openca.org)" | ||||||
| 34 | ## | ||||||
| 35 | ## THIS SOFTWARE IS PROVIDED BY OPENCA DEVELOPERS ``AS IS'' AND | ||||||
| 36 | ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||||
| 37 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||||
| 38 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||||||
| 39 | ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||||
| 40 | ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||||
| 41 | ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||||
| 42 | ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||||
| 43 | ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||||
| 44 | ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||||
| 45 | ## SUCH DAMAGE. | ||||||
| 46 | ## | ||||||
| 47 | ## The licence and distribution terms for any publically available version or | ||||||
| 48 | ## derivative of this code cannot be changed. i.e. this code cannot simply be | ||||||
| 49 | ## copied and put under another distribution licence | ||||||
| 50 | ## [including the GNU Public Licence.] | ||||||
| 51 | ## | ||||||
| 52 | |||||||
| 53 | ## Porpouse : | ||||||
| 54 | ## ========== | ||||||
| 55 | ## | ||||||
| 56 | ## Build a class to use with tri-state CGI (based on CGI library) | ||||||
| 57 | ## | ||||||
| 58 | ## Project Status: | ||||||
| 59 | ## =============== | ||||||
| 60 | ## | ||||||
| 61 | ## Started : 8 December 1998 | ||||||
| 62 | ## Last Modified : 12 Genuary 2001 | ||||||
| 63 | |||||||
| 64 | 1 | 1 | 704 | use strict; | |||
| 1 | 1 | ||||||
| 1 | 45 | ||||||
| 65 | |||||||
| 66 | package OpenCA::TRIStateCGI; | ||||||
| 67 | |||||||
| 68 | 1 | 1 | 2263 | use CGI; | |||
| 1 | 20859 | ||||||
| 1 | 9 | ||||||
| 69 | |||||||
| 70 | @OpenCA::TRIStateCGI::ISA = ( @OpenCA::TRIStateCGI::ISA, "CGI" ); | ||||||
| 71 | # Items to export into callers namespace by default. Note: do not export | ||||||
| 72 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||
| 73 | # Do not simply export all your public functions/methods/constants. | ||||||
| 74 | |||||||
| 75 | $OpenCA::TRIStateCGI::VERSION = '1.5.5'; | ||||||
| 76 | |||||||
| 77 | 1 | 1 | 1248 | use FileHandle; | |||
| 1 | 20583 | ||||||
| 1 | 6 | ||||||
| 78 | our ($STDERR, $STDOUT); | ||||||
| 79 | $STDOUT = \*STDOUT; | ||||||
| 80 | $STDERR = \*STDERR; | ||||||
| 81 | |||||||
| 82 | our ($errno, $errval); | ||||||
| 83 | |||||||
| 84 | # Preloaded methods go here. | ||||||
| 85 | |||||||
| 86 | ## General Functions | ||||||
| 87 | sub status { | ||||||
| 88 | 0 | 0 | 0 | my $self = shift; | |||
| 89 | 0 | my @keys = @_; | |||||
| 90 | |||||||
| 91 | 0 | my $ret = $self->param('status'); | |||||
| 92 | 0 | 0 | if ( $ret =~ /(client\-filled\-form|client\-confirmed\-form)/ ) { | ||||
| 93 | 0 | return $ret; | |||||
| 94 | } else { | ||||||
| 95 | 0 | return "start"; | |||||
| 96 | }; | ||||||
| 97 | } | ||||||
| 98 | |||||||
| 99 | ## New AutoChecking Input Object | ||||||
| 100 | |||||||
| 101 | sub newInput { | ||||||
| 102 | |||||||
| 103 | 0 | 0 | 0 | my $self = shift; | |||
| 104 | 0 | my @keys = @_; | |||||
| 105 | |||||||
| 106 | 0 | my ( $ret, $error, $m ); | |||||
| 107 | 0 | my ( $type, $maxlen, $minlen, $regx, $name, $values); | |||||
| 108 | |||||||
| 109 | ## Rearrange CGI's function changed in perl 5.6.1 - CGI ver 2.75+ | ||||||
| 110 | 0 | 0 | if ( $CGI::VERSION >= 2.60 ) { | ||||
| 111 | 0 | 0 | if ( ref(@_[0]) ne "HASH" ) { | ||||
| 112 | 0 | @keys = { @keys }; | |||||
| 113 | } | ||||||
| 114 | |||||||
| 115 | 0 | ( $name, $values ) = $self->rearrange(["NAME"], @keys ); | |||||
| 116 | |||||||
| 117 | 0 | $type = $values->{'-intype'}; | |||||
| 118 | } else { | ||||||
| 119 | |||||||
| 120 | 0 | ( $type, $maxlen, $minlen, $regx) = | |||||
| 121 | $self->rearrange(["INTYPE","MAXLEN","MINLEN","REGX"], | ||||||
| 122 | @keys); | ||||||
| 123 | } | ||||||
| 124 | |||||||
| 125 | ## Check if there is an Error | ||||||
| 126 | 0 | 0 | $error = $self->newInputCheck(@_) if ( $self->status ne "start" ); | ||||
| 127 | |||||||
| 128 | ## Generate the Input Type | ||||||
| 129 | 0 | $ret = $self->$type(@_); | |||||
| 130 | |||||||
| 131 | ## Clean Out NON HTML TAGS | ||||||
| 132 | 0 | $m = "(INTYPE|MAXLEN|MINLEN|REGX)=\".*\""; | |||||
| 133 | 0 | $ret =~ s/$m//g; | |||||
| 134 | |||||||
| 135 | ## Concatenate the Error to the Input Object if present | ||||||
| 136 | 0 | $ret .= $error; | |||||
| 137 | |||||||
| 138 | 0 | return $ret; | |||||
| 139 | } | ||||||
| 140 | |||||||
| 141 | sub newInputCheck { | ||||||
| 142 | |||||||
| 143 | 0 | 0 | 0 | my $self = shift; | |||
| 144 | 0 | my @keys = @_; | |||||
| 145 | |||||||
| 146 | 0 | my ( $ret, $m, $p, $l ); | |||||
| 147 | 0 | my ( $name, $values, $type, $maxlen, $minlen, $regx, $name ); | |||||
| 148 | |||||||
| 149 | ## Rearrange CGI's function changed in perl 5.6.1 - CGI ver 2.75+ | ||||||
| 150 | 0 | 0 | if ( $CGI::VERSION >= 2.60 ) { | ||||
| 151 | 0 | 0 | if ( ref(@_[0]) ne "HASH" ) { | ||||
| 152 | 0 | @keys = { @keys }; | |||||
| 153 | } | ||||||
| 154 | |||||||
| 155 | 0 | ( $name, $values ) = $self->rearrange(["NAME"], @keys ); | |||||
| 156 | |||||||
| 157 | 0 | $type = $values->{'-intype'}; | |||||
| 158 | 0 | $maxlen = $values->{'-maxlen'}; | |||||
| 159 | 0 | $minlen = $values->{'-minlen'}; | |||||
| 160 | 0 | $regx = $values->{'-regx'}; | |||||
| 161 | 0 | $name = $values->{'-name'}; | |||||
| 162 | |||||||
| 163 | } else { | ||||||
| 164 | 0 | ( $type, $maxlen, $minlen, $regx, $name) = | |||||
| 165 | $self->rearrange(["INTYPE","MAXLEN","MINLEN","REGX", | ||||||
| 166 | "NAME"], @keys); | ||||||
| 167 | } | ||||||
| 168 | |||||||
| 169 | 0 | $p = $self->param("$name"); | |||||
| 170 | |||||||
| 171 | 0 | 0 | if( $maxlen != "" ) { | ||||
| 172 | 0 | $l = length($p); | |||||
| 173 | 0 | 0 | if ( $l > $maxlen ) { | ||||
| 174 | 0 | $ret = "Error (max. $maxlen)"; | |||||
| 175 | 0 | $ret = " $ret "; |
|||||
| 176 | 0 | return $ret; | |||||
| 177 | } | ||||||
| 178 | }; | ||||||
| 179 | |||||||
| 180 | 0 | 0 | if( $minlen != "" ) { | ||||
| 181 | 0 | $l = length($p); | |||||
| 182 | 0 | 0 | if ( $l < $minlen ) { | ||||
| 183 | 0 | $ret = "Error (min. $minlen)"; | |||||
| 184 | 0 | $ret = " $ret "; |
|||||
| 185 | 0 | return $ret; | |||||
| 186 | } | ||||||
| 187 | }; | ||||||
| 188 | |||||||
| 189 | 0 | 0 | if ( length($regx) < 2 ) { | ||||
| 190 | 0 | return $ret; | |||||
| 191 | }; | ||||||
| 192 | |||||||
| 193 | 0 | $m = $regx; | |||||
| 194 | |||||||
| 195 | 0 | 0 | $m = "[a-zA-Z\ ¡-ÿ]+" if ( "$regx" eq "LETTERS" ); | ||||
| 196 | ## $m = "[a-zA-Z\ \,\.\_\:\'\`\\\/\(\)\!\;]+" if ( "$regx" eq "TEXT" ); | ||||||
| 197 | 0 | 0 | $m = "[ -\@a-zA-Z]+" if ( "$regx" eq "TEXT" ); | ||||
| 198 | 0 | 0 | $m = "[0-9]+" if ( "$regx" eq "NUMERIC" ); | ||||
| 199 | 0 | 0 | $m = "[ -\@a-zA-Z]+" if ( "$regx" eq "MIXED" ); | ||||
| 200 | 0 | 0 | $m = "[0-9\-\/]+" if ( "$regx" eq "DATE" ); | ||||
| 201 | 0 | 0 | $m = "[0-9\-\+\\\(\)]+" if ( "$regx" eq "TEL" ); | ||||
| 202 | 0 | 0 | $m = "[0-9a-zA-Z\-\_\.]+\@[a-zA-Z0-9\_\.\-]+" if ( "$regx" eq "EMAIL" ); | ||||
| 203 | 0 | 0 | $m = "[a-zA-Z¡-ÿ -\@]+" if ( "$regx" eq "LATIN1_LETTERS" ); | ||||
| 204 | 0 | 0 | $m = "[ -\@a-zA-Z¡-ÿ]+" if ( "$regx" eq "LATIN1" ); | ||||
| 205 | |||||||
| 206 | 0 | $p =~ s/$m//g; | |||||
| 207 | |||||||
| 208 | 0 | 0 | if ( length($p) == 0 ) { | ||||
| 209 | 0 | $ret = " (OK) "; |
|||||
| 210 | } else { | ||||||
| 211 | 0 | 0 | $ret .= "Use only chars" if ( $regx eq "TEXT" ); | ||||
| 212 | 0 | 0 | $ret .= "Use only LATIN1 chars" if ($regx eq "LATIN1_LETTERS"); | ||||
| 213 | 0 | 0 | $ret .= "Use only LATIN1 chars/numbers" if ( $regx eq "LATIN1"); | ||||
| 214 | 0 | 0 | $ret .= "Use only numbers" if ( $regx eq "NUMERIC" ); | ||||
| 215 | 0 | 0 | $ret .= "Use only chars./numbers" if ( $regx eq "MIXED" ); | ||||
| 216 | 0 | 0 | $ret .= "Use xx\/xx\/xxxx format." if ( $regx eq "DATE" ); | ||||
| 217 | 0 | 0 | $ret .= "Use ++xx-xxx-xxxxxx format." if ( $regx eq "TEL" ); | ||||
| 218 | 0 | 0 | $ret .= 'Use aabbcc@dddd.eee.ff' if ( $regx eq "EMAIL" ); | ||||
| 219 | 0 | 0 | $ret = "Undefined Error" if ($ret eq ""); | ||||
| 220 | |||||||
| 221 | 0 | $ret = " Error. $ret "; |
|||||
| 222 | } | ||||||
| 223 | 0 | return $ret; | |||||
| 224 | } | ||||||
| 225 | |||||||
| 226 | sub checkForm { | ||||||
| 227 | |||||||
| 228 | 0 | 0 | 0 | my $self = shift; | |||
| 229 | 0 | my @keys = @_; | |||||
| 230 | |||||||
| 231 | 0 | my ( $ret, $in, $m ); | |||||
| 232 | |||||||
| 233 | 0 | for $in ( @keys ) { | |||||
| 234 | 0 | $ret .= $self->newInputCheck( %$in ); | |||||
| 235 | } | ||||||
| 236 | |||||||
| 237 | 0 | $m = " |OK|[\ \(\)]"; |
|||||
| 238 | 0 | $ret =~ s/$m//g; | |||||
| 239 | |||||||
| 240 | 0 | return $ret; | |||||
| 241 | }; | ||||||
| 242 | |||||||
| 243 | sub printError { | ||||||
| 244 | 0 | 0 | 0 | my $self = shift; | |||
| 245 | 0 | my @keys = @_; | |||||
| 246 | |||||||
| 247 | 0 | my ( $html, $ret ); | |||||
| 248 | |||||||
| 249 | 0 | my $errCode = $keys[0]; | |||||
| 250 | 0 | my $errTxt = $keys[1]; | |||||
| 251 | |||||||
| 252 | 0 | $html = $self->start_html(-title=>'Error Accessing the Service', | |||||
| 253 | -BGCOLOR=>'#FFFFFF'); | ||||||
| 254 | |||||||
| 255 | 0 | $html .= ''; | |||||
| 256 | ## $html .= $self->setFont( -size=>'+4', | ||||||
| 257 | ## -face=>"Helvetica", | ||||||
| 258 | ## -color=>'#E54211'); | ||||||
| 259 | |||||||
| 260 | 0 | $html .= "Error ( code $errCode )"; | |||||
| 261 | 0 | $html .= " \n"; |
|||||
| 262 | |||||||
| 263 | 0 | $html .= ''; | |||||
| 264 | ## $html .= $self->setFont( -size=>'+1', | ||||||
| 265 | ## -color=>'#113388'); | ||||||
| 266 | |||||||
| 267 | 0 | 0 | if( "$errTxt" ne "" ) { | ||||
| 268 | ## The Error Code is Present in the Array, so Let's treat it... | ||||||
| 269 | 0 | $html .= $errTxt; | |||||
| 270 | |||||||
| 271 | } else { | ||||||
| 272 | ## General Error Message | ||||||
| 273 | 0 | $html .= "General Error Protection Fault : The Error Could" . | |||||
| 274 | " not be determined by the server, "; |
||||||
| 275 | 0 | $html .= "if the error persists, please contact the system" . | |||||
| 276 | " administrator for further explanation. \n"; |
||||||
| 277 | }; | ||||||
| 278 | |||||||
| 279 | 0 | $html .= " \n\n"; |
|||||
| 280 | 0 | $html .= " |