[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare API - Validator * |
---|
| 4 | * This file written by Dave Hall <skwashd@phpgroupware.org> * |
---|
| 5 | * Copyright (C) 2003 Free Software Foundation * |
---|
| 6 | * -------------------------------------------------------------------------* |
---|
| 7 | * This library is part of the eGroupWare API * |
---|
| 8 | * http://www.egroupware.org/api * |
---|
| 9 | * ------------------------------------------------------------------------ * |
---|
| 10 | * This program is Free Software; you can redistribute it and/or modify it * |
---|
| 11 | * under the terms of the GNU General Public License as published by the * |
---|
| 12 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 13 | * option) any later version. * |
---|
| 14 | \**************************************************************************/ |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | //NOTE This class still needs to be documented and the stubbed methods fixed! |
---|
| 18 | |
---|
| 19 | class validator |
---|
| 20 | { |
---|
| 21 | var $error; |
---|
| 22 | |
---|
| 23 | function clear_error () |
---|
| 24 | { |
---|
| 25 | $this->nonfree_call(); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | /* check if string contains any whitespace */ |
---|
| 29 | function has_space ($text) |
---|
| 30 | { |
---|
[5913] | 31 | return preg_match('/( |\n|\t|\r)+/', $text); |
---|
[2] | 32 | } |
---|
| 33 | |
---|
| 34 | function chconvert ($fragment) |
---|
| 35 | { |
---|
| 36 | $this->nonfree_call(); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | function get_perms ($fileName) |
---|
| 40 | { |
---|
| 41 | $this->nonfree_call(); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | function is_sane ($filename) |
---|
| 45 | { |
---|
| 46 | $this->nonfree_call(); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | /* strips all whitespace from a string */ |
---|
| 50 | function strip_space ($text) |
---|
| 51 | { |
---|
| 52 | return ereg_replace("( |\n|\t|\r)+", '', $text); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | function is_allnumbers ($text) |
---|
| 56 | { |
---|
| 57 | $this->nonfree_call(); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | function strip_numbers ($text) |
---|
| 61 | { |
---|
| 62 | $this->nonfree_call(); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | function is_allletters ($text) |
---|
| 66 | { |
---|
| 67 | $this->nonfree_call(); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | function strip_letters ($text) |
---|
| 71 | { |
---|
| 72 | $this->nonfree_call(); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | function has_html ($text='') |
---|
| 76 | { |
---|
| 77 | return ($text != $this->strip_html($text)); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | function strip_html ($text='') |
---|
| 81 | { |
---|
| 82 | return strip_tags($text); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | function has_metas ($text='') |
---|
| 86 | { |
---|
| 87 | return ($text != $this->strip_metas($text)); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | function strip_metas ($text = "") |
---|
| 91 | { |
---|
| 92 | $metas = array('$','^','*','(',')','+','[',']','.','?'); |
---|
| 93 | return str_replace($metas, '', stripslashes($text)); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | function custom_strip ($Chars, $text = "") |
---|
| 97 | { |
---|
| 98 | $this->nonfree_call(); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | function array_echo ($array, $name='Array') |
---|
| 102 | { |
---|
| 103 | echo '<pre>'; |
---|
| 104 | print_r($array); |
---|
| 105 | echo '<pre>'; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | function is_email ($address='') |
---|
| 109 | { |
---|
| 110 | list($user, $domain) = explode('@', $address); |
---|
| 111 | |
---|
| 112 | if(!($user && $domain)) |
---|
| 113 | { |
---|
| 114 | return false; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | if(!$this->has_space($user) && $this->is_host($domain)) |
---|
| 118 | { |
---|
| 119 | return true; |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | function is_url ($url='') |
---|
| 124 | { |
---|
| 125 | //echo "Checking $url<br>"; |
---|
| 126 | $uris = array( |
---|
| 127 | 'ftp' => True, |
---|
| 128 | 'https' => True, |
---|
| 129 | 'http' => True, |
---|
| 130 | ); |
---|
| 131 | $url_elements = parse_url($url); |
---|
| 132 | |
---|
| 133 | //echo '<pre>'; |
---|
| 134 | //print_r($url_elements); |
---|
| 135 | //echo '</pre>'; |
---|
| 136 | |
---|
| 137 | if(!is_array($url_elements)) |
---|
| 138 | { |
---|
| 139 | return false; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | //echo 'Scheme ' . $url_elements['scheme']; |
---|
| 143 | if(@$uris[$url_elements['scheme']]) |
---|
| 144 | { |
---|
| 145 | //echo ' is valid<br>host ' . $url_elements['host']; |
---|
| 146 | if( eregi("[a-z]", $url_elements['host']) ) |
---|
| 147 | { |
---|
| 148 | //echo ' is name<br>'; |
---|
| 149 | return $this->is_hostname($url_elements['host']); |
---|
| 150 | } |
---|
| 151 | else |
---|
| 152 | { |
---|
| 153 | //echo ' is ip<br>'; |
---|
| 154 | return $this->is_ipaddress($url_elements['host']); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | else |
---|
| 158 | { |
---|
| 159 | //echo ' is invalid<br>'; |
---|
| 160 | return $false; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | //the url may be valid, but this method can't test all types |
---|
| 166 | function url_responds ($url='') |
---|
| 167 | { |
---|
| 168 | if(!$this->is_url($url)) |
---|
| 169 | { |
---|
| 170 | return false; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | $fp=@fopen($url); |
---|
| 174 | if($fp) |
---|
| 175 | { |
---|
| 176 | fclose($fp); |
---|
| 177 | return true; |
---|
| 178 | } |
---|
| 179 | else |
---|
| 180 | { |
---|
| 181 | return false; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | function is_phone ($Phone='') |
---|
| 186 | { |
---|
| 187 | $this->nonfree_call(); |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | function is_hostname ($hostname='') |
---|
| 191 | { |
---|
| 192 | //echo "Checking $hostname<br>"; |
---|
| 193 | $segs = explode('.', $hostname); |
---|
| 194 | if(is_array($segs)) |
---|
| 195 | { |
---|
| 196 | foreach($segs as $seg) |
---|
| 197 | { |
---|
| 198 | //echo "Checking $seg<br>"; |
---|
| 199 | if(eregi("[a-z0-9\-]{0,62}",$seg)) |
---|
| 200 | { |
---|
| 201 | $return = True; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | if(!$return) |
---|
| 205 | { |
---|
| 206 | return False; |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | return True; |
---|
| 210 | } |
---|
| 211 | return False; |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | function is_bigfour ($tld) |
---|
| 215 | { |
---|
| 216 | $this->nonfree_call(); |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | function is_host ($hostname='', $type='ANY') |
---|
| 220 | { |
---|
| 221 | if($this->is_hostname($hostname)) |
---|
| 222 | { |
---|
| 223 | return checkdnsrr($hostname, $type); |
---|
| 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
| 227 | return false; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | function is_ipaddress ($ip='') |
---|
| 233 | { |
---|
| 234 | if(strlen($ip) <= 15) |
---|
| 235 | { |
---|
| 236 | $segs = explode('.', $ip); |
---|
| 237 | if(count($segs) != 4) |
---|
| 238 | { |
---|
| 239 | return false; |
---|
| 240 | } |
---|
| 241 | foreach($segs as $seg) |
---|
| 242 | { |
---|
| 243 | if( ($seg < 0) || ($seg >= 255) ) |
---|
| 244 | { |
---|
| 245 | return false; |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | return true; |
---|
| 249 | } |
---|
| 250 | else |
---|
| 251 | { |
---|
| 252 | return false; |
---|
| 253 | } |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | function ip_resolves ($ip='') |
---|
| 257 | { |
---|
| 258 | if($this->is_ipaddress($ip)) |
---|
| 259 | { |
---|
| 260 | return !strcmp($hostname, gethostbyaddr($ip)); |
---|
| 261 | } |
---|
| 262 | else |
---|
| 263 | { |
---|
| 264 | return false; |
---|
| 265 | } |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | function browser_gen () |
---|
| 269 | { |
---|
| 270 | $this->nonfree_call(); |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | function is_state ($State = "") |
---|
| 274 | { |
---|
| 275 | $this->nonfree_call(); |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | function is_zip ($zipcode = "") |
---|
| 279 | { |
---|
| 280 | $this->nonfree_call(); |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | function is_country ($countrycode='') |
---|
| 284 | { |
---|
| 285 | $this->nonfree_call(); |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | function nonfree_call() |
---|
| 289 | { |
---|
| 290 | echo 'class.validator.inc.php used to contain code that was not Free '; |
---|
| 291 | echo 'Software (<a href="(http://www.gnu.org/philosophy/free-sw.html">see '; |
---|
| 292 | echo 'definition</a> , therefore it has been removed. <br><br>'; |
---|
| 293 | echo 'If you are a application maintainer, please update your app. '; |
---|
| 294 | echo 'If you are a user, please file a bug report on '; |
---|
| 295 | echo '<a href="http://sourceforge.net/projects/egroupwaregroup">'; |
---|
| 296 | echo 'our project page at sourceforge.net</a>. Please copy and paste '; |
---|
| 297 | echo 'the following information into the bug report:<br>'; |
---|
| 298 | echo '<b>Summary<b>: ' . $GLOBALS['phpgw_info']['flags']['currentapp']; |
---|
| 299 | echo 'calls class.validator.inc.php'; |
---|
| 300 | echo 'Information:<br> The call was found when calling: ' . $_SERVER['QUERY_STRING']; |
---|
| 301 | echo '<br><br>This application will now halt!<br><br>'; |
---|
| 302 | echo '<a href="'. $GLOBALS['phpgw']->link('/home.php') .'">Return to Home Screen</a>'; |
---|
| 303 | exit; |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | ?> |
---|