From 03e012dd46d359998b078b57bd6eb2e45de22273 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Mon, 15 Oct 2012 16:06:12 +0000 Subject: [PATCH] Fix #1307 --- bureau/admin/adm_authip_whitelist.php | 2 +- bureau/admin/ip_main.php | 2 +- bureau/class/config.php | 7 +++---- bureau/class/config_real.php | 6 +++--- bureau/class/functions.php | 6 ++++++ bureau/class/m_err.php | 3 +-- bureau/class/m_mem.php | 14 +++++++------- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/bureau/admin/adm_authip_whitelist.php b/bureau/admin/adm_authip_whitelist.php index 914a34a7..a9b6ab8e 100644 --- a/bureau/admin/adm_authip_whitelist.php +++ b/bureau/admin/adm_authip_whitelist.php @@ -41,7 +41,7 @@ $list_ip = $authip->list_ip_whitelist();

- - );" > + - );" >
diff --git a/bureau/admin/ip_main.php b/bureau/admin/ip_main.php index 83c5252b..b2071881 100644 --- a/bureau/admin/ip_main.php +++ b/bureau/admin/ip_main.php @@ -162,7 +162,7 @@ $lac = $authip->list_affected();
- - );" > + - );" > diff --git a/bureau/class/config.php b/bureau/class/config.php index 03f26723..90ce648f 100644 --- a/bureau/class/config.php +++ b/bureau/class/config.php @@ -37,14 +37,13 @@ et mettez votre ip dans le IF pour que seule votre ip puisse accéder au bureau : */ -/* -if (getenv("REMOTE_ADDR")!="81.56.98.108") { +/* * / +if (getenv("REMOTE_ADDR")!="127.0.0.1") { echo "Le bureau AlternC est en vacances jusqu'a minuit pour maintenance.
Merci de revenir plus tard."; exit(); } -*/ - ini_set('display_errors', true); +/* */ // FIXME: Some constant, we put them here so that we can change them later ;) LFS define('ALTERNC_MAIL', "/var/alternc/mail"); diff --git a/bureau/class/config_real.php b/bureau/class/config_real.php index 3601ed25..0361e119 100644 --- a/bureau/class/config_real.php +++ b/bureau/class/config_real.php @@ -32,13 +32,13 @@ s'assurer que personne ne pourra accéder à 2 pages du bureau en même temps. */ -/* -if (getenv("REMOTE_ADDR")!="81.56.98.108") { +/* * / +if (getenv("REMOTE_ADDR")!="127.0.0.1") { echo "Le bureau AlternC est en vacances jusqu'a minuit pour maintenance.
Merci de revenir plus tard."; exit(); } -*/ +/* */ // 1. Get a semaphore id for the alternc magic number (18577) $alternc_sem = sem_get ( 18577 ); diff --git a/bureau/class/functions.php b/bureau/class/functions.php index 63e63e53..206a9206 100644 --- a/bureau/class/functions.php +++ b/bureau/class/functions.php @@ -101,6 +101,12 @@ function checkhostallow_nodns($domain) { return 0; } +function get_remote_ip() { + // Return the remote IP. + // If you are behind a proxy, use X_FORWARDED_FOR instead of REMOTE_ADDR + return getenv('REMOTE_ADDR'); +} + /* Check that $url is a correct url (http:// or https:// or ftp://) */ function checkurl($url) { // TODO : add a path/file check diff --git a/bureau/class/m_err.php b/bureau/class/m_err.php index fb018b9a..858d7cac 100644 --- a/bureau/class/m_err.php +++ b/bureau/class/m_err.php @@ -142,8 +142,7 @@ class m_err { global $mem,$cuid; $f=@fopen($this->logfile,"ab"); if ($f) { - if (!isset($_SERVER['REMOTE_ADDR'])) $_SERVER['REMOTE_ADDR']="::1"; - fputs($f,date("d/m/Y H:i:s")." - " . $_SERVER['REMOTE_ADDR'] . " - CALL - "); + fputs($f,date("d/m/Y H:i:s")." - " .get_remote_ip(). " - CALL - "); fputs($f,$mem->user["login"]." - "); fputs($f,$clsid." - ".$function." - ".$param."\n"); fclose($f); diff --git a/bureau/class/m_mem.php b/bureau/class/m_mem.php index 01cfec75..1b5cd561 100644 --- a/bureau/class/m_mem.php +++ b/bureau/class/m_mem.php @@ -104,18 +104,18 @@ class m_mem { $aga = $authip->get_allowed('panel'); foreach ($aga as $k=>$v ) { - if ( $authip->is_in_subnet(getenv("REMOTE_ADDR"), $v['ip'], $v['subnet']) ) $allowed=true ; + if ( $authip->is_in_subnet(get_remote_ip(), $v['ip'], $v['subnet']) ) $allowed=true ; } // Error if there is rules, the IP is not allowed and it's not in the whitelisted IP - if ( sizeof($aga)>1 && !$allowed_ip && !$authip->is_wl(getenv("REMOTE_ADDR")) ) { + if ( sizeof($aga)>1 && !$allowed_ip && !$authip->is_wl(get_remote_ip()) ) { $err->raise("mem",_("Your IP isn't allowed to connect")); return false; } // End AuthIP if ($restrictip) { - $ip="'".getenv("REMOTE_ADDR")."'"; + $ip="'".get_remote_ip()."'"; } else $ip="''"; /* Close sessions that are more than 2 days old. */ $db->query("DELETE FROM sessions WHERE DATE_ADD(ts,INTERVAL 2 DAY)next_record(); $this->user=$db->Record; $cuid=$db->f("uid"); - $ip=getenv("REMOTE_ADDR"); + $ip=get_remote_ip(); $sess=md5(uniqid(mt_rand())); $_REQUEST["session"]=$sess; $db->query("insert into sessions (sid,ip,uid) values ('$sess','$ip','$cuid');"); @@ -175,7 +175,7 @@ class m_mem { function resetlast() { global $db,$cuid; $ip=addslashes(getenv("REMOTE_HOST")); - if (!$ip) $ip=addslashes(getenv("REMOTE_ADDR")); + if (!$ip) $ip=addslashes(get_remote_ip()); $db->query("UPDATE membres SET lastlogin=NOW(), lastfail=0, lastip='$ip' WHERE uid='$cuid';"); } @@ -227,7 +227,7 @@ class m_mem { $err->raise("mem",_("Cookie incorrect, please accept the session cookie")); return false; } - $ip=getenv("REMOTE_ADDR"); + $ip=get_remote_ip(); $db->query("select uid,'$ip' as me,ip from sessions where sid='".$_COOKIE["session"]."'"); if ($db->num_rows()==0) { $err->raise("mem",_("Session unknown, contact the administrator")); @@ -306,7 +306,7 @@ class m_mem { $err->raise("mem",_("Cookie incorrect, please accept the session cookie")); return false; } - $ip=getenv("REMOTE_ADDR"); + $ip=get_remote_ip(); $db->query("select uid,'$ip' as me,ip from sessions where sid='".$_COOKIE["session"]."'"); if ($db->num_rows()==0) { $err->raise("mem",_("Session unknown, contact the administrator"));