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

Documentation generated on Fri, 16 Oct 2009 09:32:52 +0200 by phpDocumentor 1.4.1