wok view zerobin/stuff/zerobin.u @ rev 13753

xpad: try to fix build
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Jan 03 00:29:09 2013 +0000 (2013-01-03)
parents 37066c566083
children 30f393e65a4c
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,14 @@
20 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
21 }
23 +function remote_address()
24 +
25 +{
26 + if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
27 + return $_SERVER["HTTP_X_FORWARDED_FOR"];
28 + return $_SERVER["REMOTE_ADDR"];
29 +}
30 +
31 // trafic_limiter : Make sure the IP address makes at most 1 request every 10 seconds.
32 // Will return false if IP address made a call less than 10 seconds ago.
33 function trafic_limiter_canPass($ip)
34 @@ -136,7 +144,7 @@
35 }
37 // Make sure last paste from the IP address was more than 10 seconds ago.
38 - if (!trafic_limiter_canPass($_SERVER['REMOTE_ADDR']))
39 + if (!trafic_limiter_canPass(remote_address()))
40 { echo json_encode(array('status'=>1,'message'=>'Please wait 10 seconds between each post.')); exit; }
42 // Make sure content is not too big.
43 @@ -191,7 +199,7 @@
44 // (We assume that if the user did not enter a nickname, he/she wants
45 // to be anonymous and we will not generate the vizhash.)
46 $vz = new vizhash16x16();
47 - $pngdata = $vz->generate($_SERVER['REMOTE_ADDR']);
48 + $pngdata = $vz->generate(remote_address());
49 if ($pngdata!='') $meta['vizhash'] = 'data:image/png;base64,'.base64_encode($pngdata);
50 // Once the avatar is generated, we do not keep the IP address, nor its hash.
51 }
52 @@ -286,11 +294,11 @@
53 if ($ERRORMESSAGE=='') // If no error, return the paste.
54 {
55 // We kindly provide the remaining time before expiration (in seconds)
56 - if ($paste->meta->expire_date) $paste->meta->remaining_time = $paste->meta->expire_date - time();
57 + if (isset($paste->meta->expire_date)) $paste->meta->remaining_time = $paste->meta->expire_date - time();
59 $messages = array($paste); // The paste itself is the first in the list of encrypted messages.
60 // If it's a discussion, get all comments.
61 - if ($paste->meta->opendiscussion)
62 + if (isset($paste->meta->opendiscussion))
63 {
64 $comments=array();
65 $datadir = dataid2discussionpath($dataid);
66 @@ -318,7 +326,7 @@
67 $CIPHERDATA = json_encode($messages);
69 // If the paste was meant to be read only once, delete it.
70 - if ($paste->meta->burnafterreading) deletePaste($dataid);
71 + if (isset($paste->meta->burnafterreading)) deletePaste($dataid);
72 }
73 }
74 else