From ba479b95f04ff7e6a3920d27fbb51f0a3da618bd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 21 Apr 2010 18:40:18 +0000 Subject: [PATCH] Doxygen --- htdocs/core/cookie.class.php | 365 +++++++++++++++++------------------ 1 file changed, 182 insertions(+), 183 deletions(-) diff --git a/htdocs/core/cookie.class.php b/htdocs/core/cookie.class.php index 118fe649c3b..bd570e73b96 100644 --- a/htdocs/core/cookie.class.php +++ b/htdocs/core/cookie.class.php @@ -17,196 +17,195 @@ */ /** - \file htdocs/core/cookie.class.php - \ingroup core - \version $Id$ - \brief File of class to manage cookies + * \file htdocs/core/cookie.class.php + * \ingroup core + * \version $Id$ + * \brief File of class to manage cookies */ +class DolCookie +{ + var $myKey; + var $myCookie; + var $myValue; + var $myExpire; + var $myPath; + var $myDomain; + var $mySsecure; + var $cookiearray; + var $cookie; - class DolCookie - { - var $myKey; - var $myCookie; - var $myValue; - var $myExpire; - var $myPath; - var $myDomain; - var $mySsecure; - var $cookiearray; - var $cookie; + /** + * \brief Constructor + * \param key Personnal key + */ + function DolCookie($key = '') + { + $this->myKey = $key; + $this->cookiearray = array(); + $this->cookie = ""; + $this->myCookie = ""; + $this->myValue = ""; + } - /** - * \brief Constructor - * \param key Personnal key - */ - function DolCookie($key = '') - { - $this->myKey = $key; - $this->cookiearray = array(); - $this->cookie = ""; - $this->myCookie = ""; - $this->myValue = ""; - } - - - /** - * \brief Encrypt en create the cookie - */ - function cryptCookie() - { - if (!empty($this->myKey)) - { - $valuecrypt = base64_encode($this->myValue); - for ($f=0 ; $f<=strlen($valuecrypt)-1; $f++) - { - $this->cookie .= intval(ord($valuecrypt[$f]))*$this->myKey."|"; - } - } - else - { - $this->cookie = $this->myValue; - } - - setcookie($this->myCookie, $this->cookie, $this->myExpire, $this->myPath, $this->myDomain, $this->mySecure); - } - /** - * \brief Decrypt the cookie - */ - function decryptCookie() - { - if (!empty($this->myKey)) - { - $this->cookiearray = explode("|",$_COOKIE[$this->myCookie]); - $this->myValue = "" ; - for ($f=0 ; $f<=count($this->cookiearray)-2; $f++) - { - $this->myValue .= strval(chr($this->cookiearray[$f]/$this->myKey)); - } - - return(base64_decode($this->myValue)) ; - } - else - { - return($_COOKIE[$this->myCookie]); - } - } + /** + * \brief Encrypt en create the cookie + */ + function cryptCookie() + { + if (!empty($this->myKey)) + { + $valuecrypt = base64_encode($this->myValue); + for ($f=0 ; $f<=strlen($valuecrypt)-1; $f++) + { + $this->cookie .= intval(ord($valuecrypt[$f]))*$this->myKey."|"; + } + } + else + { + $this->cookie = $this->myValue; + } - /** - * \brief Set and create the cookie - * \param cookie Cookie name - * \param value Cookie value - */ - function _setCookie($cookie, $value, $expire=0, $path="/", $domain="", $secure=0) - { - $this->myCookie = $cookie; - $this->myValue = $value; - $this->myExpire = $expire; - $this->myPath = $path; - $this->myDomain = $domain; - $this->mySsecure = $secure; - - //print 'key='.$this->myKey.' name='.$this->myCookie.' value='.$this->myValue.' expire='.$this->myExpire; - - $this->cryptCookie(); - } - - /** - * \brief Get the cookie - * \param cookie Cookie name - * \param value Cookie value - * \return decryptValue Decrypted value - */ - function _getCookie($cookie) - { - $this->myCookie = $cookie; - - $decryptValue = $this->decryptCookie(); - - return $decryptValue; - } - - /** - * \brief Add cookie cryptkey in config file - * \return int <0 if KO, >0 if OK - */ - function add_cookiecryptkeyconf() - { - dol_syslog("cookie.class::add_cookiecryptkeyconf", LOG_DEBUG); - $config = ''; - $added=0; - - if ($fp = fopen(DOL_DOCUMENT_ROOT.'/conf/conf.php','r')) - { - while(!feof($fp)) - { - $buffer = fgets($fp,4096); - - if (strstr($buffer,"\$dolibarr_main_cookie_cryptkey")) - { - $config .= "\$dolibarr_main_cookie_cryptkey=\"$this->myKey\";\n"; - $added++; - } - else - { - $config .= $buffer; - } - } - fclose($fp); + setcookie($this->myCookie, $this->cookie, $this->myExpire, $this->myPath, $this->myDomain, $this->mySecure); + } - if (!$added) - { - $config = ''; - - if ($fp = fopen(DOL_DOCUMENT_ROOT.'/conf/conf.php','r')) - { - while(!feof($fp)) - { - $buffer = fgets($fp,4096); - - if (strstr($buffer,"\$dolibarr_main_authentication")) - { - $config .= $buffer; - $config .= "\$dolibarr_main_cookie_cryptkey=\"$this->myKey\";\n"; - } - else - { - $config .= $buffer; - } - } - fclose($fp); - } - else - { - dol_syslog("cookie.class::add_cookiecryptkeyconf Failed to read conf.php", LOG_ERR); - return -2; - } - } + /** + * \brief Decrypt the cookie + */ + function decryptCookie() + { + if (!empty($this->myKey)) + { + $this->cookiearray = explode("|",$_COOKIE[$this->myCookie]); + $this->myValue = "" ; + for ($f=0 ; $f<=count($this->cookiearray)-2; $f++) + { + $this->myValue .= strval(chr($this->cookiearray[$f]/$this->myKey)); + } - $file=DOL_DOCUMENT_ROOT.'/conf/conf.php'; - if ($fp = @fopen($file,'w')) - { - fputs($fp, $config, strlen($config)); - fclose($fp); - // It's config file, so we set permission for creator only - // @chmod($file, octdec('0600')); - - return 1; - } - else - { - dol_syslog("cookie.class::add_cookiecryptkeyconf Failed to open conf.php file for writing", LOG_WARNING); - return -1; - } - } - else - { - dol_syslog("cookie.class::add_cookiecryptkeyconf Failed to read conf.php", LOG_ERR); - return -2; - } - } + return(base64_decode($this->myValue)) ; + } + else + { + return($_COOKIE[$this->myCookie]); + } + } + + /** + * \brief Set and create the cookie + * \param cookie Cookie name + * \param value Cookie value + */ + function _setCookie($cookie, $value, $expire=0, $path="/", $domain="", $secure=0) + { + $this->myCookie = $cookie; + $this->myValue = $value; + $this->myExpire = $expire; + $this->myPath = $path; + $this->myDomain = $domain; + $this->mySsecure = $secure; + + //print 'key='.$this->myKey.' name='.$this->myCookie.' value='.$this->myValue.' expire='.$this->myExpire; + + $this->cryptCookie(); + } + + /** + * \brief Get the cookie + * \param cookie Cookie name + * \param value Cookie value + * \return decryptValue Decrypted value + */ + function _getCookie($cookie) + { + $this->myCookie = $cookie; + + $decryptValue = $this->decryptCookie(); + + return $decryptValue; + } + + /** + * \brief Add cookie cryptkey in config file + * \return int <0 if KO, >0 if OK + */ + function add_cookiecryptkeyconf() + { + dol_syslog("cookie.class::add_cookiecryptkeyconf", LOG_DEBUG); + $config = ''; + $added=0; + + if ($fp = fopen(DOL_DOCUMENT_ROOT.'/conf/conf.php','r')) + { + while(!feof($fp)) + { + $buffer = fgets($fp,4096); + + if (strstr($buffer,"\$dolibarr_main_cookie_cryptkey")) + { + $config .= "\$dolibarr_main_cookie_cryptkey=\"$this->myKey\";\n"; + $added++; + } + else + { + $config .= $buffer; + } + } + fclose($fp); + + if (!$added) + { + $config = ''; + + if ($fp = fopen(DOL_DOCUMENT_ROOT.'/conf/conf.php','r')) + { + while(!feof($fp)) + { + $buffer = fgets($fp,4096); + + if (strstr($buffer,"\$dolibarr_main_authentication")) + { + $config .= $buffer; + $config .= "\$dolibarr_main_cookie_cryptkey=\"$this->myKey\";\n"; + } + else + { + $config .= $buffer; + } + } + fclose($fp); + } + else + { + dol_syslog("cookie.class::add_cookiecryptkeyconf Failed to read conf.php", LOG_ERR); + return -2; + } + } + + $file=DOL_DOCUMENT_ROOT.'/conf/conf.php'; + if ($fp = @fopen($file,'w')) + { + fputs($fp, $config, strlen($config)); + fclose($fp); + // It's config file, so we set permission for creator only + // @chmod($file, octdec('0600')); + + return 1; + } + else + { + dol_syslog("cookie.class::add_cookiecryptkeyconf Failed to open conf.php file for writing", LOG_WARNING); + return -1; + } + } + else + { + dol_syslog("cookie.class::add_cookiecryptkeyconf Failed to read conf.php", LOG_ERR); + return -2; + } + } + +} - } - ?> \ No newline at end of file