egroupware/phpgwapi/inc/class.validator.inc.php

306 lines
6.1 KiB
PHP
Raw Normal View History

2001-03-12 14:17:38 +01:00
<?php
2001-10-02 07:10:14 +02:00
/**************************************************************************\
2004-05-05 14:06:13 +02:00
* eGroupWare API - Validator *
* This file written by Dave Hall <skwashd@phpgroupware.org> *
* Copyright (C) 2003 Free Software Foundation *
2005-11-25 01:20:34 +01:00
* ------------------------------------------------------------------------ *
2004-05-05 14:06:13 +02:00
* This library is part of the eGroupWare API *
2005-11-25 01:20:34 +01:00
* http://www.egroupware.org/api *
2001-10-02 07:10:14 +02:00
* ------------------------------------------------------------------------ *
2003-08-31 01:09:28 +02:00
* This program is Free Software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
2001-10-02 07:10:14 +02:00
\**************************************************************************/
2003-08-31 01:09:28 +02:00
/* $Id$ */
2001-10-02 07:10:14 +02:00
2003-08-31 01:09:28 +02:00
//NOTE This class still needs to be documented and the stubbed methods fixed!
2001-03-12 14:17:38 +01:00
class validator
{
var $error;
2001-03-12 14:17:38 +01:00
2005-11-25 01:20:34 +01:00
function clear_error()
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
/* check if string contains any whitespace */
2005-11-25 01:20:34 +01:00
function has_space($text)
2001-03-12 14:17:38 +01:00
{
return ereg("( |\n|\t|\r)+", $text);
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function chconvert($fragment)
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-10-02 07:10:14 +02:00
}
2005-11-25 01:20:34 +01:00
function get_perms($fileName)
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_sane($filename)
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
/* strips all whitespace from a string */
2005-11-25 01:20:34 +01:00
function strip_space($text)
2001-03-12 14:17:38 +01:00
{
return ereg_replace("( |\n|\t|\r)+", '', $text);
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_allnumbers($text)
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function strip_numbers($text)
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_allletters($text)
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function strip_letters($text)
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function has_html($text='')
2001-03-12 14:17:38 +01:00
{
return ($text != $this->strip_html($text));
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function strip_html($text='')
2001-03-12 14:17:38 +01:00
{
return strip_tags($text);
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function has_metas($text='')
2001-03-12 14:17:38 +01:00
{
return ($text != $this->strip_metas($text));
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function strip_metas($text = "")
2001-03-12 14:17:38 +01:00
{
$metas = array('$','^','*','(',')','+','[',']','.','?');
return str_replace($metas, '', stripslashes($text));
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function custom_strip($Chars, $text = "")
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function array_echo($array, $name='Array')
2001-03-12 14:17:38 +01:00
{
echo '<pre>';
print_r($array);
echo '<pre>';
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_email($address='')
2001-03-12 14:17:38 +01:00
{
2003-08-31 01:09:28 +02:00
list($user, $domain) = explode('@', $address);
2005-11-25 01:20:34 +01:00
2003-08-31 01:09:28 +02:00
if(!($user && $domain))
{
return false;
}
2005-11-25 01:20:34 +01:00
2003-08-31 01:09:28 +02:00
if(!$this->has_space($user) && $this->is_host($domain))
{
return true;
}
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_url($url='')
2001-03-12 14:17:38 +01:00
{
2003-08-31 01:09:28 +02:00
//echo "Checking $url<br>";
$uris = array(
'ftp' => True,
'https' => True,
2005-11-25 01:20:34 +01:00
'http' => True
);
2003-08-31 01:09:28 +02:00
$url_elements = parse_url($url);
2005-11-25 01:20:34 +01:00
2003-08-31 01:09:28 +02:00
//echo '<pre>';
//print_r($url_elements);
//echo '</pre>';
if(!is_array($url_elements))
{
return false;
}
//echo 'Scheme ' . $url_elements['scheme'];
if(@$uris[$url_elements['scheme']])
{
//echo ' is valid<br>host ' . $url_elements['host'];
2005-11-25 01:20:34 +01:00
if(eregi("[a-z]", $url_elements['host']))
2003-08-31 01:09:28 +02:00
{
//echo ' is name<br>';
return $this->is_hostname($url_elements['host']);
}
else
{
//echo ' is ip<br>';
return $this->is_ipaddress($url_elements['host']);
}
}
else
{
//echo ' is invalid<br>';
return $false;
}
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2003-08-31 01:09:28 +02:00
//the url may be valid, but this method can't test all types
2005-11-25 01:20:34 +01:00
function url_responds($url='')
2001-03-12 14:17:38 +01:00
{
2003-08-31 01:09:28 +02:00
if(!$this->is_url($url))
{
return false;
}
$fp=@fopen($url);
if($fp)
{
fclose($fp);
return true;
}
else
{
return false;
}
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_phone($Phone='')
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_hostname($hostname='')
2001-03-12 14:17:38 +01:00
{
2003-08-31 01:09:28 +02:00
//echo "Checking $hostname<br>";
$segs = explode('.', $hostname);
if(is_array($segs))
{
foreach($segs as $seg)
{
//echo "Checking $seg<br>";
if(eregi("[a-z0-9\-]{0,62}",$seg))
{
2005-11-25 01:20:34 +01:00
$return = True;
2003-08-31 01:09:28 +02:00
}
if(!$return)
{
return False;
}
}
return True;
}
return False;
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_bigfour($tld)
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_host($hostname='', $type='ANY')
2001-03-12 14:17:38 +01:00
{
2003-08-31 01:09:28 +02:00
if($this->is_hostname($hostname))
{
return checkdnsrr($hostname, $type);
}
else
{
return false;
}
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_ipaddress($ip='')
2001-03-12 14:17:38 +01:00
{
2003-08-31 01:09:28 +02:00
if(strlen($ip) <= 15)
{
$segs = explode('.', $ip);
if(count($segs) != 4)
{
return false;
}
foreach($segs as $seg)
{
2005-11-25 01:20:34 +01:00
if(($seg < 0) || ($seg >= 255))
2003-08-31 01:09:28 +02:00
{
return false;
}
}
return true;
}
else
{
return false;
}
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function ip_resolves($ip='')
2001-03-12 14:17:38 +01:00
{
2003-08-31 01:09:28 +02:00
if($this->is_ipaddress($ip))
{
return !strcmp($hostname, gethostbyaddr($ip));
}
else
{
return false;
}
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function browser_gen()
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_state($State = "")
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_zip($zipcode = "")
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2005-11-25 01:20:34 +01:00
function is_country($countrycode='')
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
}
2005-11-25 01:20:34 +01:00
function nonfree_call()
{
echo 'class.validator.inc.php used to contain code that was not Free ';
echo 'Software (<a href="(http://www.gnu.org/philosophy/free-sw.html">see ';
echo 'definition</a> , therefore it has been removed. <br><br>';
echo 'If you are a application maintainer, please update your app. ';
echo 'If you are a user, please file a bug report on ';
2004-05-05 14:06:13 +02:00
echo '<a href="http://sourceforge.net/projects/egroupwaregroup">';
echo 'our project page at sourceforge.net</a>. Please copy and paste ';
echo 'the following information into the bug report:<br>';
2005-11-25 01:20:34 +01:00
echo '<b>Summary<b>: ' . $GLOBALS['egw_info']['flags']['currentapp'];
echo 'calls class.validator.inc.php';
echo 'Information:<br> The call was found when calling: ' . $_SERVER['QUERY_STRING'];
echo '<br><br>This application will now halt!<br><br>';
2005-11-25 01:20:34 +01:00
echo '<a href="'. $GLOBALS['egw']->link('/home.php') .'">Return to Home Screen</a>';
exit;
}
}
2001-10-02 07:10:14 +02:00
?>