# HG changeset patch # User Pascal Bellard # Date 1342508028 -7200 # Node ID f967c9b8ac1a66c7695f5f314a4c1061d62eead1 # Parent 37066c5660837b39ad907acadb265582b2ca439c zerobin: fix zerobin.u diff -r 37066c566083 -r f967c9b8ac1a zerobin/stuff/zerobin.u --- a/zerobin/stuff/zerobin.u Mon Jul 16 13:18:48 2012 +0200 +++ b/zerobin/stuff/zerobin.u Tue Jul 17 08:53:48 2012 +0200 @@ -16,59 +16,59 @@ expire:$('select#pasteExpiration').val(), --- index.php +++ index.php -@@ -16,6 +16,13 @@ - $_COOKIE = array_map('stripslashes_deep', $_COOKIE); - } - +@@ -16,6 +16,14 @@ + $_COOKIE = array_map('stripslashes_deep', $_COOKIE); + } + +function remote_address() -+{ -+ if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) -+ return $_SERVER["HTTP_X_FORWARDED_FOR"]; -+ 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) -@@ -136,7 +143,7 @@ - } - - // 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(remote_address())) - { echo json_encode(array('status'=>1,'message'=>'Please wait 10 seconds between each post.')); exit; } - - // Make sure content is not too big. -@@ -191,7 +198,7 @@ - // (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(remote_address()); - 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. - } -@@ -286,11 +293,11 @@ - if ($ERRORMESSAGE=='') // If no error, return the paste. - { - // We kindly provide the remaining time before expiration (in seconds) -- if ($paste->meta->expire_date) $paste->meta->remaining_time = $paste->meta->expire_date - time(); -+ if (isset($paste->meta->expire_date)) $paste->meta->remaining_time = $paste->meta->expire_date - time(); - - $messages = array($paste); // The paste itself is the first in the list of encrypted messages. - // If it's a discussion, get all comments. -- if ($paste->meta->opendiscussion) -+ if (isset($paste->meta->opendiscussion)) - { - $comments=array(); - $datadir = dataid2discussionpath($dataid); -@@ -318,7 +325,7 @@ - $CIPHERDATA = json_encode($messages); - - // If the paste was meant to be read only once, delete it. -- if ($paste->meta->burnafterreading) deletePaste($dataid); -+ if (isset($paste->meta->burnafterreading)) deletePaste($dataid); - } - } - else - ++ ++{ ++ if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) ++ return $_SERVER["HTTP_X_FORWARDED_FOR"]; ++ 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) +@@ -136,7 +144,7 @@ + } + + // 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(remote_address())) + { echo json_encode(array('status'=>1,'message'=>'Please wait 10 seconds between each post.')); exit; } + + // Make sure content is not too big. +@@ -191,7 +199,7 @@ + // (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(remote_address()); + 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. + } +@@ -286,11 +294,11 @@ + if ($ERRORMESSAGE=='') // If no error, return the paste. + { + // We kindly provide the remaining time before expiration (in seconds) +- if ($paste->meta->expire_date) $paste->meta->remaining_time = $paste->meta->expire_date - time(); ++ if (isset($paste->meta->expire_date)) $paste->meta->remaining_time = $paste->meta->expire_date - time(); + + $messages = array($paste); // The paste itself is the first in the list of encrypted messages. + // If it's a discussion, get all comments. +- if ($paste->meta->opendiscussion) ++ if (isset($paste->meta->opendiscussion)) + { + $comments=array(); + $datadir = dataid2discussionpath($dataid); +@@ -318,7 +326,7 @@ + $CIPHERDATA = json_encode($messages); + + // If the paste was meant to be read only once, delete it. +- if ($paste->meta->burnafterreading) deletePaste($dataid); ++ if (isset($paste->meta->burnafterreading)) deletePaste($dataid); + } + } + else