egroupware_official/phpgwapi/inc/class.validator.inc.php

308 lines
6.2 KiB
PHP
Raw Normal View History

2001-03-12 14:17:38 +01:00
<?php
2001-10-02 07:10:14 +02:00
/**************************************************************************\
* phpGroupWare API - Validator *
* This file written by Dave Hall <skwashd@phpgroupware.org> *
* Copyright (C) 2003 Free Software Foundation *
2001-10-02 07:10:14 +02:00
* -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api *
* ------------------------------------------------------------------------ *
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
function clear_error ()
{
$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 */
2001-03-12 14:17:38 +01:00
function has_space ($text)
{
return ereg('( |\n|\t|\r)+', $text);
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2001-03-12 14:17:38 +01:00
function chconvert ($fragment)
{
$this->nonfree_call();
2001-10-02 07:10:14 +02: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
2001-03-12 14:17:38 +01:00
function is_sane ($filename)
{
$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 */
2001-03-12 14:17:38 +01:00
function strip_space ($text)
{
return ereg('( |\n|\t|\r)+', '', $text);
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2001-03-12 14:17:38 +01:00
function is_allnumbers ($text)
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2001-03-12 14:17:38 +01:00
function strip_numbers ($text)
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2001-03-12 14:17:38 +01:00
function is_allletters ($text)
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2001-03-12 14:17:38 +01:00
function strip_letters ($text)
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02: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
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
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
2001-03-12 14:17:38 +01:00
function strip_metas ($text = "")
{
$metas = array('$','^','*','(',')','+','[',']','.','?');
return str_replace($metas, '', stripslashes($text));
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2001-03-12 14:17:38 +01:00
function custom_strip ($Chars, $text = "")
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02: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
2003-08-31 01:09:28 +02: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);
if(!($user && $domain))
{
return false;
}
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
2003-08-31 01:09:28 +02: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,
'http' => True,
);
$url_elements = parse_url($url);
//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'];
if( eregi("[a-z]", $url_elements['host']) )
{
//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
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
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
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))
{
$return = True;
}
if(!$return)
{
return False;
}
}
return True;
}
return False;
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2001-03-12 14:17:38 +01:00
function is_bigfour ($tld)
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02: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
2003-08-31 01:09:28 +02: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)
{
if( ($seg < 0) || ($seg >= 255) )
{
return false;
}
}
return true;
}
else
{
return false;
}
}
2001-10-02 07:10:14 +02:00
2003-08-31 01:09:28 +02: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
2001-03-12 14:17:38 +01:00
function browser_gen ()
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2001-03-12 14:17:38 +01:00
function is_state ($State = "")
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
2001-03-12 14:17:38 +01:00
function is_zip ($zipcode = "")
{
$this->nonfree_call();
2001-03-12 14:17:38 +01:00
}
2001-10-02 07:10:14 +02:00
function is_country ($countrycode='')
2001-03-12 14:17:38 +01:00
{
$this->nonfree_call();
}
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 ';
echo '<a href="https://savannah.gnu.org/bugs/?group=phpgroupware">';
echo 'our project page at savannah.gnu.org</a>. Please copy and paste ';
echo 'the following information into the bug report:<br>';
echo '<b>Summary<b>: ' . $GLOBALS['phpgw_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>';
echo '<a href="'. $GLOBALS['phpgw']->link('/home.php') .'">Return to Home Screen</a>';
exit;
}
}
2001-10-02 07:10:14 +02:00
?>