wok-next view zerobin/stuff/zerobin.u @ rev 13155
zerobin: avoid some PHP notices
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Jul 16 13:18:48 2012 +0200 (2012-07-16) |
parents | a6697022a666 |
children | f967c9b8ac1a |
line source
1 --- lib/zerobin.js
2 +++ lib/zerobin.js
3 @@ -180,7 +180,12 @@
4 {
5 if ($('textarea#message').val().length==0) return; // Do not send if no data.
6 showStatus('Sending paste...',spin=true);
7 - var randomkey = sjcl.codec.base64.fromBits(sjcl.random.randomWords(8,0),0);
8 + var randomkey = (window.location.hash.length > 2) ?
9 + // force key
10 + window.location.hash.substring(1) :
11 + // Generate a random 256 bits key, encoded in base64:
12 + sjcl.codec.base64.fromBits(sjcl.random.randomWords(8,0),0);
13 + if (randomkey.charAt(randomkey.length-1)!=='=') randomkey+='='; // Add trailing = if missing.
14 var cipherdata = zeroCipher(randomkey,$('textarea#message').val());
15 var data_to_send = { data:cipherdata,
16 expire:$('select#pasteExpiration').val(),
17 --- index.php
18 +++ index.php
19 @@ -16,6 +16,13 @@
20 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
21 }
23 +function remote_address()
24 +{
25 + if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
26 + return $_SERVER["HTTP_X_FORWARDED_FOR"];
27 + return $_SERVER["REMOTE_ADDR"];
28 +}
29 +
30 // trafic_limiter : Make sure the IP address makes at most 1 request every 10 seconds.
31 // Will return false if IP address made a call less than 10 seconds ago.
32 function trafic_limiter_canPass($ip)
33 @@ -136,7 +143,7 @@
34 }
36 // Make sure last paste from the IP address was more than 10 seconds ago.
37 - if (!trafic_limiter_canPass($_SERVER['REMOTE_ADDR']))
38 + if (!trafic_limiter_canPass(remote_address()))
39 { echo json_encode(array('status'=>1,'message'=>'Please wait 10 seconds between each post.')); exit; }
41 // Make sure content is not too big.
42 @@ -191,7 +198,7 @@
43 // (We assume that if the user did not enter a nickname, he/she wants
44 // to be anonymous and we will not generate the vizhash.)
45 $vz = new vizhash16x16();
46 - $pngdata = $vz->generate($_SERVER['REMOTE_ADDR']);
47 + $pngdata = $vz->generate(remote_address());
48 if ($pngdata!='') $meta['vizhash'] = 'data:image/png;base64,'.base64_encode($pngdata);
49 // Once the avatar is generated, we do not keep the IP address, nor its hash.
50 }
51 @@ -286,11 +293,11 @@
52 if ($ERRORMESSAGE=='') // If no error, return the paste.
53 {
54 // We kindly provide the remaining time before expiration (in seconds)
55 - if ($paste->meta->expire_date) $paste->meta->remaining_time = $paste->meta->expire_date - time();
56 + if (isset($paste->meta->expire_date)) $paste->meta->remaining_time = $paste->meta->expire_date - time();
58 $messages = array($paste); // The paste itself is the first in the list of encrypted messages.
59 // If it's a discussion, get all comments.
60 - if ($paste->meta->opendiscussion)
61 + if (isset($paste->meta->opendiscussion))
62 {
63 $comments=array();
64 $datadir = dataid2discussionpath($dataid);
65 @@ -318,7 +325,7 @@
66 $CIPHERDATA = json_encode($messages);
68 // If the paste was meant to be read only once, delete it.
69 - if ($paste->meta->burnafterreading) deletePaste($dataid);
70 + if (isset($paste->meta->burnafterreading)) deletePaste($dataid);
71 }
72 }
73 else