Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for X-Forwarded-For-header #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ function stripslashes_deep($value) { $value = is_array($value) ? array_map('stri
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

// get_real_ip : Support for proxies that will put the real IP into the HTTP_X_FORWARDED_FOR-header.
function get_real_ip()
{
$useproxyip = false;
// uncomment the following line if you want to use the X-Forwarded-For-header. Beware that this header can be spoofed. Leave commented out on systems without reverse proxy in front of the webserver.
//if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) $useproxyip = true;

if ( $useproxyip ) {
$ip_arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2);
return trim($ip_arr[0]);
} else {
return $_SERVER['REMOTE_ADDR'];
}
}

// trafic_limiter : Make sure the IP address makes at most 1 request every 10 seconds.
// Will return false if IP address made a call less than 10 seconds ago.
function trafic_limiter_canPass($ip)
Expand Down Expand Up @@ -157,7 +172,7 @@ function deletePaste($pasteid)
}

// Make sure last paste from the IP address was more than 10 seconds ago.
if (!trafic_limiter_canPass($_SERVER['REMOTE_ADDR']))
if (!trafic_limiter_canPass(get_real_ip()))
{ echo json_encode(array('status'=>1,'message'=>'Please wait 10 seconds between each post.')); exit; }

// Make sure content is not too big.
Expand Down Expand Up @@ -229,7 +244,7 @@ function deletePaste($pasteid)
// (We assume that if the user did not enter a nickname, he/she wants
// to be anonymous and we will not generate the vizhash.)
$vz = new vizhash16x16();
$pngdata = $vz->generate($_SERVER['REMOTE_ADDR']);
$pngdata = $vz->generate(get_real_ip());
if ($pngdata!='') $meta['vizhash'] = 'data:image/png;base64,'.base64_encode($pngdata);
// Once the avatar is generated, we do not keep the IP address, nor its hash.
}
Expand Down