wok annotate zerobin/stuff/zerobin.u @ rev 18735

Up zerobin (6 feb 2014)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Dec 21 16:28:32 2015 +0100 (2015-12-21)
parents 0baeb3ed8570
children 7a16da2c93b9
rev   line source
pascal@13154 1 --- index.php
pascal@13154 2 +++ index.php
pascal@14109 3 @@ -17,6 +17,13 @@
pascal@18735 4 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
pascal@18735 5 }
pascal@18735 6
pascal@18735 7 +function remote_address()
pascal@18735 8 +{
pascal@18735 9 + // if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
pascal@18735 10 + // return $_SERVER["HTTP_X_FORWARDED_FOR"];
pascal@18735 11 + return $_SERVER["REMOTE_ADDR"];
pascal@18735 12 +}
pascal@18735 13 +
pascal@18735 14 // trafic_limiter : Make sure the IP address makes at most 1 request every 10 seconds.
pascal@18735 15 // Will return false if IP address made a call less than 10 seconds ago.
pascal@18735 16 function trafic_limiter_canPass($ip)
pascal@14111 17 @@ -144,7 +151,7 @@
pascal@18735 18 }
pascal@18735 19
pascal@18735 20 // Make sure last paste from the IP address was more than 10 seconds ago.
pascal@18735 21 - if (!trafic_limiter_canPass($_SERVER['REMOTE_ADDR']))
pascal@18735 22 + if (!trafic_limiter_canPass(remote_address()))
pascal@18735 23 { echo json_encode(array('status'=>1,'message'=>'Please wait 10 seconds between each post.')); exit; }
pascal@18735 24
pascal@18735 25 // Make sure content is not too big.
pascal@14111 26 @@ -216,7 +223,7 @@
pascal@18735 27 // (We assume that if the user did not enter a nickname, he/she wants
pascal@18735 28 // to be anonymous and we will not generate the vizhash.)
pascal@18735 29 $vz = new vizhash16x16();
pascal@18735 30 - $pngdata = $vz->generate($_SERVER['REMOTE_ADDR']);
pascal@18735 31 + $pngdata = $vz->generate(remote_address());
pascal@18735 32 if ($pngdata!='') $meta['vizhash'] = 'data:image/png;base64,'.base64_encode($pngdata);
pascal@18735 33 // Once the avatar is generated, we do not keep the IP address, nor its hash.
pascal@18735 34 }
pascal@14109 35 --- js/zerobin.js
pascal@14109 36 +++ js/zerobin.js
pascal@18735 37 @@ -340,7 +340,13 @@
pascal@18735 38
pascal@18735 39 showStatus('Sending paste...', spin=true);
pascal@18735 40
pascal@18735 41 - var randomkey = sjcl.codec.base64.fromBits(sjcl.random.randomWords(8, 0), 0);
pascal@18735 42 + var randomkey = (window.location.hash.length > 2) ?
pascal@18735 43 + // force key
pascal@18735 44 + window.location.hash.substring(1) :
pascal@18735 45 + // Generate a random 256 bits key, encoded in base64:
pascal@18735 46 + sjcl.codec.base64.fromBits(sjcl.random.randomWords(8,0),0);
pascal@18735 47 + if (randomkey.charAt(randomkey.length-1) !== '=')
pascal@18735 48 + randomkey+='='; // Add trailing = if missing.
pascal@18735 49 var cipherdata = zeroCipher(randomkey, $('textarea#message').val());
pascal@18735 50 var data_to_send = { data: cipherdata,
pascal@18735 51 expire: $('select#pasteExpiration').val(),