From a2c8e7abdfa799d6085a3a64a90786953556faea Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Aug 2011 17:59:14 +0000 Subject: [PATCH] Fix: Better error management --- htdocs/core/class/rssparser.class.php | 14 +++++++++++--- htdocs/lib/files.lib.php | 23 ++++++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/rssparser.class.php b/htdocs/core/class/rssparser.class.php index 1b018b5073d..03b8e73badf 100755 --- a/htdocs/core/class/rssparser.class.php +++ b/htdocs/core/class/rssparser.class.php @@ -19,7 +19,7 @@ * \file htdocs/core/class/rssparser.class.php * \ingroup core * \brief File of class to parse rss feeds - * \version $Id: rssparser.class.php,v 1.1 2011/08/17 13:44:13 eldy Exp $ + * \version $Id: rssparser.class.php,v 1.2 2011/08/26 17:59:14 eldy Exp $ */ class RssParser { @@ -75,8 +75,15 @@ class RssParser { include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php'); + // Check parameters + if (! dol_is_url($urlRSS)) + { + $this->error="ErrorBadUrl"; + return -1; + } + $this->_urlRSS = $urlRSS; - $newpathofdestfile=$cachedir.'/'.md5($this->_urlRSS); + $newpathofdestfile=$cachedir.'/'.md5($this->_urlRSS); $newmask=octdec('0644'); //dol_syslog("RssPArser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile); @@ -110,7 +117,8 @@ class RssParser { try { $rss = @simplexml_load_file($this->_urlRSS); - } +var_dump($this->_urlRSS); + } catch (Exception $e) { print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage(); } diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php index 312cece614e..7df39b03ea3 100644 --- a/htdocs/lib/files.lib.php +++ b/htdocs/lib/files.lib.php @@ -19,7 +19,7 @@ /** * \file htdocs/lib/files.lib.php * \brief Library for file managing functions - * \version $Id: files.lib.php,v 1.71 2011/07/31 23:25:43 eldy Exp $ + * \version $Id: files.lib.php,v 1.72 2011/08/26 17:59:14 eldy Exp $ */ /** @@ -186,6 +186,7 @@ function dol_compare_file($a, $b) /** * Return mime type of a file + * * @param file Filename we looking for MIME type * @param default Default mime type if extension not found in known list * @param mode 0=Return full mime, 1=otherwise short mime string, 2=image for mime type, 3=source language @@ -295,6 +296,7 @@ function dol_mimetype($file,$default='application/octet-stream',$mode=0) /** * Test if filename is a directory + * * @param folder Name of folder * @return boolean True if it's a directory, False if not found */ @@ -307,6 +309,7 @@ function dol_is_dir($folder) /** * Return if path is a file + * * @param $pathoffile * @return boolean True or false */ @@ -316,8 +319,26 @@ function dol_is_file($pathoffile) return is_file($newpathoffile); } +/** + * Return if path is an URL + * + * @param $url + * @return boolean True or false + */ +function dol_is_url($url) +{ + $tmpprot=array('file','http','ftp','zlib','data','ssh2','ogg','expect'); + foreach($tmpprot as $prot) + { + if (preg_match('/^'.$prot.':/i',$url)) return true; + } + return false; +} + + /** * Test if a folder is empty + * * @param folder Name of folder * @return boolean True if dir is empty or non-existing, False if it contains files */