Source for file functions_auth.php
Documentation is available at functions_auth.php
* @author linea21 <info@linea21.com>
* @license http://opensource.org/licenses/gpl-3.0.html
if ($data != 0 && count($data) == 1) {
* AuthenthificationProcess()
* Authentification d'un utilisateur
* @param $type ='PUBLIC' || 'ADMIN'
* @return boolean (true) ou message d'erreur
if($type == 'PUBLIC') $src = LOG_PUBLIC_ACCESS;
if($type == 'ADMIN') $src = LOG_ADMIN_ACCESS;
logfile($src, array($type, $login, $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_REFERER'], $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING'], $_SERVER['HTTP_COOKIE'], i2c_realip()));
$crypt_pass = crypt($pass, SALT_CRYPT);
list ($login, $crypt_pass) = $GLOBALS['sql_object']->DBEscape(array($login, $crypt_pass));
if ($data != 0 && count($data) == 1) {
$table['id'] = $data[0]['user_id'];
$table['login'] = $login;
$table['lifetime'] = time() + 3600 * 720;
if(!empty($data[0]['profile_firstname'])) {
$table['firstname'] = $data[0]['profile_firstname'];
// préparation du tableau de droits
$right['dashboard'] = $data[0]['rights_dashboard'];
$right['workshop'] = $data[0]['rights_workshop'];
$right['project'] = $data[0]['rights_project'];
$right['publication'] = $data[0]['rights_publication'];
$right['news'] = $data[0]['rights_news'];
$right['yellowpages'] = $data[0]['rights_yellowpages'];
$right['theme'] = $data[0]['rights_theme'];
$right['scale'] = $data[0]['rights_scale'];
$right['level'] = $data[0]['rights_level'];
$right['category_user'] = $data[0]['rights_category_user'];
// est simple utilisateur
return _t('divers','errorauth');
// est utilisateur avec droits
$_SESSION['authenticated'] = true;
$_SESSION['userlogin'] = $login;
if(!empty($data[0]['profile_firstname'])) {
$_SESSION['userfirstname'] = $data[0]['profile_firstname'];
$_SESSION['userright'] = $right;
$error_msg = _t('divers','errorauth');
* Retrieve Workgroups for a given user
* @param $a array (optional)
// user already logged-in
if(isset ($_COOKIE['linea21']['id'])) {
$login = $_COOKIE['linea21']['login'];
$crypt_pass = $a['pass'];
for ($i = 0; $i < count($data_w); $i++ ) {
$workgroups .= "/" . $data_w[$i]['jwu_workshop_id'];
* @param integer $workshop_id
* @param object $sql_object
for ($i = 0; $i < count($data); $i++ ) {
return $_SESSION['userlogin'];
if(isset ($_SESSION['userfirstname']))
return $_SESSION['userfirstname'];
return $_SESSION['userright']['theme'];
return $_SESSION['userright']['dashboard'];
return $_SESSION['userright']['workshop'];
return $_SESSION['userright']['project'];
case 'right_publication':
return $_SESSION['userright']['publication'];
return $_SESSION['userright']['news'];
case 'right_yellowpages':
return $_SESSION['userright']['yellowpages'];
return $_SESSION['userright']['scale'];
return $_SESSION['userright']['level'];
case 'right_category_user':
return $_SESSION['userright']['category_user'];
* set les infos contenu en tableau PHP en cookie
$cookie_expires = $table['lifetime'];
while (list ($key, $value) = @each($table)) {
setcookie('linea21[' . $key . ']', $value, $cookie_expires, '/');
* Détruit les infos contenu en cookie
while (list ($key, $val) = @each($_COOKIE['linea21'])) {
* Mise à jour du mot de passe dans le cookie (cas de changement)
setcookie('linea21[whois]', $newpass, $_COOKIE['linea21']['lifetime'], '/');
setcookie('linea21[workshop]', $str, $_COOKIE['linea21']['lifetime'], '/');
* check if the current user belongs to a workgroup
include_once('../admin/'. SQL. '.inc.php');
// 1 -we check that login and password stored in cookie are corrects
$data = $GLOBALS['sql_object']->DBSelect($q);
if ($data != 0 && count($data) == 1 && $data[0]['user_id']== $_COOKIE['linea21']['id']) {
// 2 - if ok, we check that the user belongs to the given group
for ($i = 0; $i < count($r); $i++ ) {
if ($workshop_id == $r[$i]['jwu_workshop_id']) {
* check if a given user is workgroup organiser
for ($i = 0; $i < count($data); $i++ ) {
if ($id_workshop == $data[$i]['jwu_workshop_id'])
* used for the admin/ part
if(isset ($_SESSION['authenticated'])) {
setcookie('linea21_lastpage', 'index.php?'. $_SERVER['QUERY_STRING'], (time() + 3600 * 720), '/');
* Set_Cookie_last_connexion()
* used for the admin/ part
setcookie('linea21_lastuser', $_SESSION['login'], (time() + 3600 * 720), '/');
// Returns the real IP address of the user
// No IP found (will be overwritten by for
// if any IP is found behind a firewall)
// If HTTP_CLIENT_IP is set, then give it priority
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
// User is behind a proxy and check that we discard RFC1918 IP addresses
// if they are behind a proxy then only figure out which IP belongs to the
// user. Might not need any more hackin if there is a squid reverse proxy
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// Put the IP's into an array which we shall work with shortly.
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
for ($i = 0; $i < count($ips); $i++ ) {
// Skip RFC 1918 IP's 10.0.0.0/8, 172.16.0.0/12 and
// 192.168.0.0/16 -- jim kill me later with my regexp pattern
if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) {
// Return with the found IP or the remote address
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
|