linea21-utils
[ class tree: linea21-utils ] [ index: linea21-utils ] [ all elements ]

Source for file functions_auth.php

Documentation is available at functions_auth.php

  1. <?php
  2. /**
  3.  * @package linea21.utils
  4.  * @subpackage lib
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11.  
  12.  
  13. function loginAuth($login{
  14.   $data $GLOBALS['sql_object']->DBSelect(SQL_get_UserInfo($login));
  15.   if ($data != && count($data== 1{
  16.     return $data[0];
  17.   else {
  18.     return false;
  19.   }
  20. }
  21.  
  22.  
  23. /**
  24.  * AuthenthificationProcess()
  25.  * Authentification d'un utilisateur
  26.  *
  27.  * @param  $login 
  28.  * @param  $pass 
  29.  * @param  $type ='PUBLIC' || 'ADMIN'
  30.  * @return boolean (true) ou message d'erreur
  31.  */
  32. function AuthenthificationProcess($login$pass$type)
  33. {
  34.   if($type == 'PUBLIC'$src LOG_PUBLIC_ACCESS;
  35.   if($type == 'ADMIN'$src LOG_ADMIN_ACCESS;
  36.   logfile($srcarray($type$login$_SERVER['HTTP_USER_AGENT']$_SERVER['HTTP_REFERER']$_SERVER['REQUEST_METHOD']$_SERVER['REQUEST_URI']$_SERVER['QUERY_STRING']$_SERVER['HTTP_COOKIE']i2c_realip()));
  37.  
  38.   $crypt_pass crypt($passSALT_CRYPT);
  39.  
  40.   $data $GLOBALS['sql_object']->DBSelect(SQL_Get_UserInfo4Auth($login$crypt_pass));
  41.   if ($data != && count($data== 1{
  42.     if ($type == 'PUBLIC'{
  43.  
  44.       $workgroups retrieveWorkgroups(array('login' => $login'pass' => $crypt_pass));
  45.  
  46.       $table['id'$data[0]['user_id'];
  47.       $table['whois'base64_encode($crypt_pass);
  48.       $table['login'$login;
  49.       $table['workshop'base64_encode($workgroups);
  50.       DestroyUserCookie();
  51.       SetUserCookie($table);
  52.     }
  53.     if ($type == 'ADMIN'{
  54.       // préparation du tableau de droits
  55.       $right['dashboard'$data[0]['rights_dashboard'];
  56.       $right['workshop'$data[0]['rights_workshop'];
  57.       $right['project'$data[0]['rights_project'];
  58.       $right['publication'$data[0]['rights_publication'];
  59.       $right['news'$data[0]['rights_news'];
  60.       $right['yellowpages'$data[0]['rights_yellowpages'];
  61.       $right['theme'$data[0]['rights_theme'];
  62.       $right['scale'$data[0]['rights_scale'];
  63.       $right['level'$data[0]['rights_level'];
  64.       $right['category_user'$data[0]['rights_category_user'];
  65.       // est simple utilisateur
  66.       if (!array_search ('A' $right&& !array_search ('O' $right)) {
  67.         return _t('divers','errorauth');
  68.         // est utilisateur avec droits
  69.       else {
  70.         $_SESSION['sess_is_known'true;
  71.         $_SESSION['sess_id'base64_encode($data[0]['user_id']);
  72.         $_SESSION['sess_whois'base64_encode($crypt_pass);
  73.         $_SESSION['sess_login'$login;
  74.         $_SESSION['sess_right'$right;
  75.         Set_Cookie_last_connexion();
  76.       }
  77.     }
  78.     return true;
  79.   else {
  80.     $error_msg _t('divers','errorauth');
  81.     return $error_msg;
  82.   }
  83. }
  84.  
  85. /**
  86.  * retrieveWorkgroups()
  87.  * Retrieve Workgroups for a given user
  88.  * @param  $a array (optional)
  89.  * @return string 
  90.  */
  91. function retrieveWorkgroups($a array()) {
  92.  
  93.   // user already logged-in
  94.   if(isset($_COOKIE['linea21']['id'])) {
  95.     $login $_COOKIE['linea21']['login'];
  96.     $crypt_pass base64_decode($_COOKIE['linea21']['whois']);
  97.   }
  98.   else
  99.   {
  100.     if(isset($a['login'])) {
  101.       $login $a['login'];
  102.       $crypt_pass $a['pass'];
  103.     else {
  104.       return false;
  105.     }
  106.   }
  107.  
  108.   $data_w $GLOBALS['sql_object']->DBSelect(SQL_Get_UserWorkshop($login$crypt_pass));
  109.   $workgroups '';
  110.   for ($i 0$i count($data_w)$i++{
  111.     $workgroups .= "/" $data_w[$i]['jwu_workshop_id'];
  112.   }
  113.   return $workgroups;
  114.  
  115. }
  116.  
  117. /**
  118.  * WorkshopAuth_id()
  119.  *
  120.  * @param  $id_user 
  121.  * @param  $sql_object 
  122.  * @param  $id_workshop 
  123.  * @return boolean 
  124.  */
  125. function WorkshopAuth_id ($id_user$sql_object$id_workshop)
  126. {
  127.   $data $sql_object->DBSelect(SQL_Get_UserInfo4Authid($id_user));
  128.   $workshop_list '';
  129.   $result false;
  130.   for ($i 0$i count($data)$i++{
  131.     if ($id_workshop == $data[$i]['jwu_workshop_id']$result true;
  132.   }
  133.   return $result;
  134. }
  135.  
  136. /**
  137.  * AuthUser4Workshop()
  138.  *
  139.  * @param integer $workshop_id 
  140.  * @param object $sql_object 
  141.  * @return boolean 
  142.  */
  143. function AuthUser4Workshop ($workshop_id$sql_object)
  144. {
  145.   $data $sql_object->DBSelect(SQL_Get_UserWorkshopOwner($workshop_id));
  146.   for ($i 0$i count($data)$i++{
  147.     if (GetSessionElement('id'== $data[$i]['jwu_user_id']return true;
  148.   }
  149.   return false;
  150. }
  151.  
  152. /**
  153.  * IsSuperAdmin()
  154.  *
  155.  * @return boolean 
  156.  */
  157. function IsSuperAdmin()
  158. {
  159.   return HaveRight('theme');
  160. }
  161.  
  162. /**
  163.  * HaveRights()
  164.  *
  165.  * @param string $item 
  166.  * @return bool 
  167.  */
  168. function HaveRight($item)
  169. {
  170.   switch ($item{
  171.     case 'category_user':
  172.       if (GetSessionElement('right_category_user'!= 'A'return false;
  173.       else return true;
  174.     case 'theme':
  175.       if (GetSessionElement('right_theme'!= 'A'return false;
  176.       else return true;
  177.     case 'level':
  178.       if (GetSessionElement('right_level'!= 'A'return false;
  179.       else return true;
  180.     case 'scale':
  181.       if (GetSessionElement('right_scale'!= 'A'return false;
  182.       else return true;
  183.     case 'yellowpages':
  184.       if (GetSessionElement('right_yellowpages'!= 'A'return false;
  185.       else return true;
  186.     case 'news':
  187.       if (GetSessionElement('right_news'!= 'U'return true;
  188.       else return false;
  189.     case 'project':
  190.       if (GetSessionElement('right_project'!= 'A'return false;
  191.       else return true;
  192.     case 'publication':
  193.       if (GetSessionElement('right_publication'!= 'U'return true;
  194.       else return false;
  195.     case 'workshop':
  196.       if (GetSessionElement('right_workshop'!= 'U'return true;
  197.       else return false;
  198.     case 'dashboard':
  199.       if (GetSessionElement('right_dashboard'!= 'U'return true;
  200.       else return false;
  201.     default:
  202.       return false;
  203.   }
  204. }
  205.  
  206. /**
  207.  * GetSessionElement()
  208.  *
  209.  * @param string $item (id, whois, login, right)
  210.  * @return $result 
  211.  */
  212.  
  213. function GetSessionElement($item)
  214. {
  215.   switch ($item{
  216.     case 'id':
  217.       return base64_decode($_SESSION['sess_id']);
  218.       break;
  219.     case 'whois':
  220.       return base64_decode($_SESSION['sess_whois']);
  221.       break;
  222.     case 'login':
  223.       return $_SESSION['sess_login'];
  224.       break;
  225.     case 'right_theme':
  226.       return $_SESSION['sess_right']['theme'];
  227.       break;
  228.     case 'right_dashboard':
  229.       return $_SESSION['sess_right']['dashboard'];
  230.       break;
  231.     case 'right_workshop':
  232.       return $_SESSION['sess_right']['workshop'];
  233.       break;
  234.     case 'right_project':
  235.       return $_SESSION['sess_right']['project'];
  236.       break;
  237.     case 'right_publication':
  238.       return $_SESSION['sess_right']['publication'];
  239.       break;
  240.     case 'right_news':
  241.       return $_SESSION['sess_right']['news'];
  242.       break;
  243.     case 'right_yellowpages':
  244.       return $_SESSION['sess_right']['yellowpages'];
  245.       break;
  246.     case 'right_scale':
  247.       return $_SESSION['sess_right']['scale'];
  248.       break;
  249.     case 'right_level':
  250.       return $_SESSION['sess_right']['level'];
  251.       break;
  252.     case 'right_category_user':
  253.       return $_SESSION['sess_right']['category_user'];
  254.       break;
  255.   }
  256. }
  257.  
  258. /**
  259.  * SetUserCookie()
  260.  * set les infos contenu en tableau PHP en cookie
  261.  *
  262.  * @param  $table 
  263.  * @return void 
  264.  */
  265. function SetUserCookie($table)
  266. {
  267.   while (list($key$value@each($table)) {
  268.     setcookie('linea21[' $key ']'$value(time(3600 720)'/');
  269.   }
  270. }
  271.  
  272. /**
  273.  * DestroyUserCookie()
  274.  * Détruit les infos contenu en cookie
  275.  *
  276.  * @return void 
  277.  */
  278. function DestroyUserCookie()
  279. {
  280.   while (list($key$val@each($_COOKIE['linea21'])) {
  281.     setcookie('linea21[' $key ']'''(time(3600)'/');
  282.   }
  283. }
  284.  
  285. /**
  286.  * UpdateCookiePassword()
  287.  * Mise à jour du mot de passe dans le cookie (cas de changement)
  288.  *
  289.  * @param  $newpass 
  290.  * @return void 
  291.  */
  292. function UpdateCookiePassword($newpass)
  293. {
  294.   $newpass base64_encode($newpass);
  295.   setcookie('linea21[whois]'$newpass(time(3600 720)'/');
  296. }
  297.  
  298. /**
  299.  * updateCookieWorkshop()
  300.  * Update workgroups list
  301.  *
  302.  * @return void 
  303.  */
  304. {
  305.   setcookie('linea21[workshop]'$str(time(3600 720)'/');
  306. }
  307.  
  308. /**
  309.  * CookieWorkshopid()
  310.  * vérification de l'inscription de l'utilisateur au groupe de travail
  311.  *
  312.  * @param  $workshop_id 
  313.  * @return boolean 
  314.  */
  315. function CookieWorkshopid($workshop_id)
  316. {
  317.   if (isset($_COOKIE['linea21']['workshop'])) {
  318.     $string_id base64_decode($_COOKIE['linea21']['workshop']);
  319.  
  320.     $string_id str_replace(" """$string_id);
  321.     $table_id @explode('/'$string_id);
  322.     for ($i 0$i count($table_id)$i++{
  323.       if ($workshop_id == $table_id[$i])return true;
  324.     }
  325.     return false;
  326.   }
  327.   return false;
  328. }
  329.  
  330. /**
  331.  * Set_Cookie_last_page()
  332.  */
  333. {
  334.   if(isset($_SESSION['sess_is_known'])) {
  335.     setcookie('linea21_lastpage''index.php?'.$_SERVER['QUERY_STRING'](time(3600 720)'/');
  336.     setcookie('linea21_lastactivity'time()(time(3600 720)'/');
  337.   }
  338. }
  339.  
  340. /**
  341.  * Set_Cookie_last_connexion()
  342.  */
  343. {
  344.   setcookie('linea21_lastcon'time()(time(3600 720)'/');
  345.   setcookie('linea21_lastuser'$_SESSION['sess_login'](time(3600 720)'/');
  346.  
  347. }
  348.  
  349. // Returns the real IP address of the user
  350. function i2c_realip()
  351. {
  352.   // No IP found (will be overwritten by for
  353.   // if any IP is found behind a firewall)
  354.   $ip false;
  355.   // If HTTP_CLIENT_IP is set, then give it priority
  356.   if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
  357.     $ip $_SERVER["HTTP_CLIENT_IP"];
  358.   }
  359.   // User is behind a proxy and check that we discard RFC1918 IP addresses
  360.   // if they are behind a proxy then only figure out which IP belongs to the
  361.   // user.  Might not need any more hackin if there is a squid reverse proxy
  362.   // infront of apache.
  363.   if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  364.     // Put the IP's into an array which we shall work with shortly.
  365.     $ips explode (", "$_SERVER['HTTP_X_FORWARDED_FOR']);
  366.     if ($ip{
  367.       array_unshift($ips$ip);
  368.       $ip false;
  369.     }
  370.  
  371.     for ($i 0$i count($ips)$i++{
  372.       // Skip RFC 1918 IP's 10.0.0.0/8, 172.16.0.0/12 and
  373.       // 192.168.0.0/16 -- jim kill me later with my regexp pattern
  374.       // below.
  375.       if (!eregi ("^(10|172\.16|192\.168)\."$ips[$i])) {
  376.         $ip $ips[$i];
  377.         break;
  378.       }
  379.     }
  380.   }
  381.   // Return with the found IP or the remote address
  382.   return ($ip $ip $_SERVER['REMOTE_ADDR']);
  383. }
  384.  
  385. ?>

Documentation generated on Fri, 01 Apr 2011 09:30:58 +0200 by phpDocumentor 1.4.1