author | Dan |
Thu, 28 Feb 2008 12:33:01 -0500 | |
changeset 285 | e72bf2c24875 |
parent 261 | 5f1cd51bf1be |
child 294 | 444c34a3886b |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
2 |
||
3 |
/* |
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
285 | 5 |
* Version 1.0.4 (Ellyyllon) |
1 | 6 |
* Copyright (C) 2006-2007 Dan Fuhry |
7 |
* |
|
8 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
12 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
13 |
* |
|
14 |
* The "emailer" class was ported from phpBB 2.0. Copyright (C) 2002-2006 phpBB Group. phpBB is licensed under the GPLv2. |
|
15 |
*/ |
|
16 |
||
17 |
// |
|
18 |
// The emailer class has support for attaching files, that isn't implemented |
|
19 |
// in the 2.0 release but we can probable find some way of using it in a future |
|
20 |
// release |
|
21 |
// |
|
22 |
class emailer |
|
23 |
{ |
|
24 |
var $msg, $subject, $extra_headers; |
|
25 |
var $addresses, $reply_to, $from; |
|
26 |
var $use_smtp; |
|
27 |
||
28 |
var $tpl_msg; |
|
29 |
||
30 |
function emailer($use_smtp) |
|
31 |
{ |
|
32 |
$this->reset(); |
|
33 |
$this->use_smtp = $use_smtp; |
|
34 |
$this->reply_to = $this->from = ''; |
|
35 |
} |
|
36 |
||
37 |
// Resets all the data (address, template file, etc etc to default |
|
38 |
function reset() |
|
39 |
{ |
|
40 |
$this->addresses = array(); |
|
41 |
$this->vars = $this->msg = $this->extra_headers = ''; |
|
42 |
} |
|
43 |
||
44 |
// Sets an email address to send to |
|
45 |
function email_address($address) |
|
46 |
{ |
|
47 |
$this->addresses['to'] = trim($address); |
|
48 |
} |
|
49 |
||
50 |
function cc($address) |
|
51 |
{ |
|
52 |
$this->addresses['cc'][] = trim($address); |
|
53 |
} |
|
54 |
||
55 |
function bcc($address) |
|
56 |
{ |
|
57 |
$this->addresses['bcc'][] = trim($address); |
|
58 |
} |
|
59 |
||
60 |
function replyto($address) |
|
61 |
{ |
|
62 |
$this->reply_to = trim($address); |
|
63 |
} |
|
64 |
||
65 |
function from($address) |
|
66 |
{ |
|
67 |
$this->from = trim($address); |
|
68 |
} |
|
69 |
||
70 |
// set up subject for mail |
|
71 |
function set_subject($subject = '') |
|
72 |
{ |
|
73 |
$this->subject = trim(preg_replace('#[\n\r]+#s', '', $subject)); |
|
74 |
} |
|
75 |
||
76 |
// set up extra mail headers |
|
77 |
function extra_headers($headers) |
|
78 |
{ |
|
79 |
$this->extra_headers .= trim($headers) . "\n"; |
|
80 |
} |
|
81 |
||
82 |
function use_template($template_code) |
|
83 |
{ |
|
84 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
85 |
||
86 |
$this->tpl_msg = $template->makeParserText($template_code); |
|
87 |
||
88 |
return true; |
|
89 |
} |
|
90 |
||
91 |
// assign variables |
|
92 |
function assign_vars($vars) |
|
93 |
{ |
|
94 |
if ( is_object($this->tpl_msg) ) |
|
95 |
{ |
|
96 |
$this->tpl_msg->assign_vars($vars); |
|
97 |
} |
|
98 |
else |
|
99 |
{ |
|
100 |
die_friendly(GENERAL_ERROR, 'Can\'t set vars, the template is not set'); |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
// Send the mail out to the recipients set previously in var $this->address |
|
105 |
function send() |
|
106 |
{ |
|
107 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
108 |
||
109 |
$this->msg = $this->tpl_msg->run(); |
|
110 |
if ( empty($this->msg) ) |
|
111 |
{ |
|
112 |
die_friendly(GENERAL_ERROR, 'Template for e-mail message returned a blank'); |
|
113 |
} |
|
114 |
||
115 |
// We now try and pull a subject from the email body ... if it exists, |
|
116 |
// do this here because the subject may contain a variable |
|
117 |
$drop_header = ''; |
|
118 |
$match = array(); |
|
119 |
if (preg_match('#^(Subject:(.*?))$#m', $this->msg, $match)) |
|
120 |
{ |
|
121 |
$this->subject = (trim($match[2]) != '') ? trim($match[2]) : (($this->subject != '') ? $this->subject : 'No Subject'); |
|
122 |
$drop_header .= '[\r\n]*?' . preg_quote($match[1], '#'); |
|
123 |
} |
|
124 |
else |
|
125 |
{ |
|
126 |
$this->subject = (($this->subject != '') ? $this->subject : 'No Subject'); |
|
127 |
} |
|
128 |
||
129 |
if (preg_match('#^(Charset:(.*?))$#m', $this->msg, $match)) |
|
130 |
{ |
|
131 |
$this->encoding = (trim($match[2]) != '') ? trim($match[2]) : trim('iso-8859-1'); |
|
132 |
$drop_header .= '[\r\n]*?' . preg_quote($match[1], '#'); |
|
133 |
} |
|
134 |
else |
|
135 |
{ |
|
136 |
$this->encoding = trim('iso-8859-1'); |
|
137 |
} |
|
138 |
||
139 |
if ($drop_header != '') |
|
140 |
{ |
|
141 |
$this->msg = trim(preg_replace('#' . $drop_header . '#s', '', $this->msg)); |
|
142 |
} |
|
143 |
||
144 |
$to = $this->addresses['to']; |
|
145 |
||
146 |
$cc = (count($this->addresses['cc'])) ? implode(', ', $this->addresses['cc']) : ''; |
|
147 |
$bcc = (count($this->addresses['bcc'])) ? implode(', ', $this->addresses['bcc']) : ''; |
|
148 |
||
149 |
// Build header |
|
150 |
$this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . |
|
151 |
(($this->from != '') ? "From: $this->from\n" : "From: " . getConfig('contact_email') . "\n") . |
|
152 |
"Return-Path: " . getConfig('contact_email') . |
|
153 |
"\nMessage-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\nMIME-Version: 1.0\nContent-type: text/plain; charset=" . $this->encoding . |
|
154 |
"\nContent-transfer-encoding: 8bit\nDate: " . date('r', time()) . |
|
155 |
"\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\nX-MimeOLE: Produced By Enano CMS\n" . |
|
156 |
$this->extra_headers . |
|
157 |
(($cc != '') ? "Cc: $cc\n" : '') . |
|
158 |
(($bcc != '') ? "Bcc: $bcc\n" : ''); |
|
159 |
||
160 |
//die('<pre>'.print_r($this,true).'</pre>'); |
|
161 |
||
162 |
// Send message ... removed $this->encode() from subject for time being |
|
163 |
if ( $this->use_smtp ) |
|
164 |
{ |
|
165 |
$result = smtp_send_email_core($to, $this->subject, $this->msg, $this->extra_headers); |
|
166 |
} |
|
167 |
else |
|
168 |
{ |
|
169 |
$empty_to_header = ($to == '') ? TRUE : FALSE; |
|
170 |
$to = ($to == '') ? ((getConfig('sendmail_fix')=='1') ? ' ' : 'Undisclosed-recipients:;') : $to; |
|
171 |
||
172 |
$result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers); |
|
173 |
||
174 |
if (!$result && !getConfig('sendmail_fix') && $empty_to_header) |
|
175 |
{ |
|
176 |
$to = ' '; |
|
177 |
||
178 |
setConfig('sendmail_fix', '1'); |
|
179 |
||
180 |
$result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers); |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
// Did it work? |
|
185 |
if (!$result || ( $this->use_smtp && $result != 'success' )) |
|
186 |
{ |
|
187 |
die_friendly(GENERAL_ERROR, 'Failed sending email :: ' . (($this->use_smtp) ? 'SMTP' : 'PHP') . ' :: ' . $result); |
|
188 |
} |
|
189 |
||
190 |
return true; |
|
191 |
} |
|
192 |
||
193 |
// Encodes the given string for proper display for this encoding ... nabbed |
|
194 |
// from php.net and modified. There is an alternative encoding method which |
|
195 |
// may produce lesd output but it's questionable as to its worth in this |
|
196 |
// scenario IMO |
|
197 |
function encode($str) |
|
198 |
{ |
|
199 |
if ($this->encoding == '') |
|
200 |
{ |
|
201 |
return $str; |
|
202 |
} |
|
203 |
||
204 |
// define start delimimter, end delimiter and spacer |
|
205 |
$end = "?="; |
|
206 |
$start = "=?$this->encoding?B?"; |
|
207 |
$spacer = "$end\r\n $start"; |
|
208 |
||
209 |
// determine length of encoded text within chunks and ensure length is even |
|
210 |
$length = 75 - strlen($start) - strlen($end); |
|
211 |
$length = floor($length / 2) * 2; |
|
212 |
||
213 |
// encode the string and split it into chunks with spacers after each chunk |
|
214 |
$str = chunk_split(base64_encode($str), $length, $spacer); |
|
215 |
||
216 |
// remove trailing spacer and add start and end delimiters |
|
217 |
$str = preg_replace('#' . preg_quote($spacer, '#') . '$#', '', $str); |
|
218 |
||
219 |
return $start . $str . $end; |
|
220 |
} |
|
221 |
||
222 |
// |
|
223 |
// Attach files via MIME. |
|
224 |
// |
|
225 |
function attachFile($filename, $mimetype = "application/octet-stream", $szFromAddress, $szFilenameToDisplay) |
|
226 |
{ |
|
227 |
global $lang; |
|
228 |
$mime_boundary = "--==================_846811060==_"; |
|
229 |
||
230 |
$this->msg = '--' . $mime_boundary . "\nContent-Type: text/plain;\n\tcharset=".'"' . $lang['ENCODING'] . '"'."\n\n" . $this->msg; |
|
231 |
||
232 |
if ($mime_filename) |
|
233 |
{ |
|
234 |
$filename = $mime_filename; |
|
235 |
$encoded = $this->encode_file($filename); |
|
236 |
} |
|
237 |
||
238 |
$fd = fopen($filename, "r"); |
|
239 |
$contents = fread($fd, filesize($filename)); |
|
240 |
||
241 |
$this->mimeOut = "--" . $mime_boundary . "\n"; |
|
242 |
$this->mimeOut .= "Content-Type: " . $mimetype . ";\n\tname=".'"'."$szFilenameToDisplay".'"'."\n"; |
|
243 |
$this->mimeOut .= "Content-Transfer-Encoding: quoted-printable\n"; |
|
244 |
$this->mimeOut .= "Content-Disposition: attachment;\n\tfilename=".'"'."$szFilenameToDisplay".'"'."\n\n"; |
|
245 |
||
246 |
if ( $mimetype == "message/rfc822" ) |
|
247 |
{ |
|
248 |
$this->mimeOut .= "From: ".$szFromAddress."\n"; |
|
249 |
$this->mimeOut .= "To: ".$this->emailAddress."\n"; |
|
250 |
$this->mimeOut .= "Date: ".date("D, d M Y H:i:s") . " UT\n"; |
|
251 |
$this->mimeOut .= "Reply-To:".$szFromAddress."\n"; |
|
252 |
$this->mimeOut .= "Subject: ".$this->mailSubject."\n"; |
|
253 |
$this->mimeOut .= "X-Mailer: PHP/".phpversion()."\n"; |
|
254 |
$this->mimeOut .= "MIME-Version: 1.0\n"; |
|
255 |
} |
|
256 |
||
257 |
$this->mimeOut .= $contents."\n"; |
|
258 |
$this->mimeOut .= "--" . $mime_boundary . "--" . "\n"; |
|
259 |
||
260 |
return $out; |
|
261 |
// added -- to notify email client attachment is done |
|
262 |
} |
|
263 |
||
264 |
function getMimeHeaders($filename, $mime_filename="") |
|
265 |
{ |
|
266 |
$mime_boundary = "--==================_846811060==_"; |
|
267 |
||
268 |
if ($mime_filename) |
|
269 |
{ |
|
270 |
$filename = $mime_filename; |
|
271 |
} |
|
272 |
||
273 |
$out = "MIME-Version: 1.0\n"; |
|
274 |
$out .= "Content-Type: multipart/mixed;\n\tboundary=".'"'."$mime_boundary".'"'."\n\n"; |
|
275 |
$out .= "This message is in MIME format. Since your mail reader does not understand\n"; |
|
276 |
$out .= "this format, some or all of this message may not be legible."; |
|
277 |
||
278 |
return $out; |
|
279 |
} |
|
280 |
||
281 |
// |
|
282 |
// Split string by RFC 2045 semantics (76 chars per line, end with \r\n). |
|
283 |
// |
|
284 |
function myChunkSplit($str) |
|
285 |
{ |
|
286 |
$stmp = $str; |
|
287 |
$len = strlen($stmp); |
|
288 |
$out = ""; |
|
289 |
||
290 |
while ($len > 0) |
|
291 |
{ |
|
292 |
if ($len >= 76) |
|
293 |
{ |
|
294 |
$out .= substr($stmp, 0, 76) . "\r\n"; |
|
295 |
$stmp = substr($stmp, 76); |
|
296 |
$len = $len - 76; |
|
297 |
} |
|
298 |
else |
|
299 |
{ |
|
300 |
$out .= $stmp . "\r\n"; |
|
301 |
$stmp = ""; |
|
302 |
$len = 0; |
|
303 |
} |
|
304 |
} |
|
305 |
return $out; |
|
306 |
} |
|
307 |
||
308 |
// |
|
309 |
// Split the specified file up into a string and return it |
|
310 |
// |
|
311 |
function encode_file($sourcefile) |
|
312 |
{ |
|
313 |
if (is_readable(@realpath($sourcefile))) |
|
314 |
{ |
|
315 |
$fd = fopen($sourcefile, "r"); |
|
316 |
$contents = fread($fd, filesize($sourcefile)); |
|
317 |
$encoded = $this->myChunkSplit(base64_encode($contents)); |
|
318 |
fclose($fd); |
|
319 |
} |
|
320 |
||
321 |
return $encoded; |
|
322 |
} |
|
323 |
||
324 |
} // class emailer |
|
325 |
||
326 |
||
327 |
/** |
|
328 |
* This code is copyright (C) 2004 Jim Tucek |
|
329 |
* PHP version ported from Javascript by Dan Fuhry |
|
330 |
* All rights reserved. |
|
331 |
* @link http://www.jracademy.com/~jtucek/email/ |
|
332 |
* @license GNU General Public License v2, permission obtained specifically for Enano |
|
333 |
*/ |
|
334 |
||
335 |
class EmailEncryptor |
|
336 |
{ |
|
337 |
||
338 |
var $primes = Array(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199); |
|
339 |
||
340 |
function __construct() |
|
341 |
{ |
|
342 |
$i = 0; |
|
343 |
$this->p = 0; |
|
344 |
$this->q = 0; |
|
345 |
while($this->p * $this->q < 255 || $this->p == $this->q) |
|
346 |
{ |
|
347 |
$this->p = $this->primes[mt_rand(0, sizeof($this->primes)-1)]; |
|
348 |
$this->q = $this->primes[mt_rand(0, sizeof($this->primes)-1)]; |
|
349 |
} |
|
350 |
} |
|
351 |
||
352 |
function EmailEncryptor() |
|
353 |
{ |
|
354 |
$this->__construct(); |
|
355 |
} |
|
356 |
||
357 |
function testAll() { |
|
358 |
$size = sizeof($this->primes); |
|
359 |
||
360 |
$allCharacters = ""; |
|
361 |
for($c = 33; $c <= 126; $c++) |
|
362 |
$allCharacters = $allCharacters . $this->fromCharCode($c); |
|
363 |
||
364 |
for($i = 0; $i < $size - 1; $i++) { |
|
365 |
for($j = $i + 1; $j < $size; $j++) { |
|
366 |
$this->p = $this->primes[$i]; |
|
367 |
$this->q = $this->primes[$j]; |
|
368 |
if($this->p*$this->q < 255) |
|
369 |
break; |
|
370 |
$k = $this->makeKey($allCharacters); |
|
371 |
$encrypted = $k['X']; |
|
372 |
$decrypted = $this->goForth($encrypted,$this->p*$this->q,$k['D']); |
|
373 |
if($decrypted != $allCharacters) { |
|
374 |
die('Test failed'); |
|
375 |
} |
|
376 |
} |
|
377 |
} |
|
378 |
return 'GOOD'; |
|
379 |
} |
|
380 |
||
381 |
function charCodeAt($str, $i) |
|
382 |
{ |
|
383 |
return ord(substr($str, $i, 1)); |
|
384 |
} |
|
385 |
||
386 |
function fromCharCode($str) |
|
387 |
{ |
|
388 |
return chr($str); |
|
389 |
} |
|
390 |
||
391 |
function MakeArray($l) { |
|
392 |
$a = Array(); |
|
393 |
$i=0; |
|
394 |
do { |
|
395 |
$a[$i]=null; |
|
396 |
$i++; |
|
397 |
} while($i < $l); |
|
398 |
return $a; |
|
399 |
} |
|
400 |
||
401 |
function makeKey($addr,$subj = '',$body = '') { |
|
402 |
$value = ""; |
|
403 |
||
404 |
if($this->p * $this->q < 255) |
|
405 |
{ |
|
406 |
return("P*Q must be greater than 255! P*Q = " . $this->p*$this->q); |
|
407 |
} |
|
408 |
elseif($this->p == $this->q) |
|
409 |
{ |
|
410 |
return("P cannot be equal to Q!"); |
|
411 |
} |
|
412 |
elseif($addr == "") |
|
413 |
{ |
|
414 |
return("You must enter an address to encrypt!"); |
|
415 |
} |
|
416 |
else |
|
417 |
{ |
|
418 |
// Make the key |
|
419 |
$c = 0; |
|
420 |
$z = ($this->p-1)*($this->q-1); |
|
421 |
$e = 0; |
|
422 |
$n = $this->p*$this->q; |
|
423 |
$d = 0; |
|
424 |
||
425 |
do { |
|
426 |
$e++; |
|
427 |
$d = $this->getKey($this->primes[$e],$z); |
|
428 |
} while($d==1); |
|
429 |
$e = $this->primes[$e]; |
|
430 |
||
431 |
// Turn the string into an array of numbers < 255 |
|
432 |
$m = $addr; |
|
433 |
$emailLength = strlen($m); |
|
434 |
$justEmail = ""; |
|
435 |
$sep = ( strstr('?', $m) ) ? '&' : '?'; |
|
436 |
if($subj != "") { |
|
437 |
$m = $m . "{$sep}subject=" . $subj; |
|
438 |
} |
|
439 |
$sep = ( strstr($m, '?') ) ? '&' : '?'; |
|
440 |
if($body != "") { |
|
441 |
$m = $m . "{$sep}body=" . $body; |
|
442 |
} |
|
443 |
||
444 |
$length = strlen($m); |
|
445 |
$theString = $this->MakeArray($length); |
|
446 |
for($i = 0; $i < $length; $i++) { |
|
447 |
$theString[$i] = $this->charCodeAt($m, $i); |
|
448 |
} |
|
449 |
||
450 |
// Encrypt each of the numbers |
|
451 |
$theCode = $this->MakeArray($length); |
|
452 |
$c = ""; |
|
453 |
$temp = 0; |
|
454 |
for($i = 0; $i < $length; $i++) { |
|
455 |
if($i != 0) |
|
456 |
$c .= " "; |
|
457 |
$temp = $this->myMod($theString[$i],$e,$n); |
|
458 |
$theCode[$i] = $temp; |
|
459 |
$c .= $temp; |
|
460 |
if($i == $emailLength - 1) |
|
461 |
$justEmail = $c; |
|
462 |
} |
|
463 |
} |
|
464 |
return Array('X'=>$justEmail, 'N'=>$n, 'D'=>$d, 'E'=>$e, 'C'=>$c, 'M'=>$m); |
|
465 |
} |
|
466 |
||
467 |
// Finds x^e % y for large values of (x^e) |
|
468 |
function myMod($x,$e,$y) { |
|
469 |
if ($e % 2 == 0) { |
|
470 |
$answer = 1; |
|
471 |
for($i = 1; $i <= e/2; $i++) { |
|
472 |
$temp = ($x*$x) % $y; |
|
473 |
$answer = ($temp*$answer) % $y; |
|
474 |
} |
|
475 |
} else { |
|
476 |
$answer = $x; |
|
477 |
for($i = 1; $i <= $e/2; $i++) { |
|
478 |
$temp = ($x*$x) % $y; |
|
479 |
$answer = ($temp*$answer) % $y; |
|
480 |
} |
|
481 |
} |
|
482 |
return $answer; |
|
483 |
} |
|
484 |
||
485 |
||
486 |
function getKey($e,$z) { |
|
487 |
$A = 1; |
|
488 |
$B = 0; |
|
489 |
$C = $z; |
|
490 |
$F = 0; |
|
491 |
$G = 1; |
|
492 |
$bar = $e; |
|
493 |
// Euclid's Algorithm: |
|
494 |
while ($bar != 0) { |
|
495 |
$foo = floor($C/$bar); |
|
496 |
$K = $A - $foo * $F; |
|
497 |
$L = $B - $foo * $G; |
|
498 |
$M = $C - $foo * $bar; |
|
499 |
$A = $F; |
|
500 |
$B = $G; |
|
501 |
$C = $bar; |
|
502 |
$F = $K; |
|
503 |
$G = $L; |
|
504 |
$bar = $M; |
|
505 |
} |
|
506 |
if ($B < 0) |
|
507 |
{ |
|
508 |
return ($B + $z); |
|
509 |
} |
|
510 |
else |
|
511 |
{ |
|
512 |
return ($B); |
|
513 |
} |
|
514 |
} |
|
515 |
||
516 |
function goForth($c,$n,$d) { |
|
517 |
$c .= " "; |
|
518 |
$length = strlen($c); |
|
519 |
$number = 0; |
|
520 |
$bar = 0; |
|
521 |
$answer = ""; |
|
522 |
||
523 |
for($i = 0; $i < $length; $i++) { |
|
524 |
$number = 0; |
|
525 |
$bar = 0; |
|
526 |
while($this->charCodeAt($c, $i) != 32) { |
|
527 |
$number = $number * 10; |
|
528 |
$number = $number + $this->charCodeAt($c, $i)-48; |
|
529 |
$i++; |
|
530 |
} |
|
531 |
$answer .= $this->fromCharCode($this->decrypt($number,$n,$d)); |
|
532 |
} |
|
533 |
return $answer; |
|
534 |
} |
|
535 |
||
536 |
function decrypt($c,$n,$d) { |
|
537 |
// Split exponents up |
|
538 |
if ($d % 2== 0) { |
|
539 |
$bar = 1; |
|
540 |
for($i = 1; $i <= $d/2; $i++) { |
|
541 |
$foo = ($c*$c) % $n; |
|
542 |
$bar = ($foo*$bar) % $n; |
|
543 |
} |
|
544 |
} else { |
|
545 |
$bar = $c; |
|
546 |
for($i = 1; $i <= $d/2; $i++) { |
|
547 |
$foo = ($c*$c) % $n; |
|
548 |
$bar = ($foo*$bar) % $n; |
|
549 |
} |
|
550 |
} |
|
551 |
return $bar; |
|
552 |
} |
|
553 |
||
554 |
function writeOptions() { |
|
555 |
$size = sizeof($this->primes); |
|
556 |
for($i = 0; $i < $size; $i++) |
|
557 |
echo("<option value=".'"'.""+$this->primes[$i]+"".'"'.">"+$this->primes[$i]+"</option>"); |
|
558 |
} |
|
559 |
||
560 |
function jscode() { |
|
561 |
return "<script type='text/javascript'>\n// <![CDATA[\nfunction dive(absorption,alchemy,friendship) { absorption += ' '; var file = absorption.length; var sand = 0; var closet = ''; for(var assistant = 0; assistant < file; assistant++) { sand = 0; while(absorption.charCodeAt(assistant) != 32) { sand = sand * 10; sand = sand + absorption.charCodeAt(assistant)-48; assistant++; } closet += String.fromCharCode(say(sand,alchemy,friendship)); } parent.location = 'm'+'a'+'i'+'l'+'t'+'o'+':'+closet; }; function forbid(landing,atmosphere,aviation) { landing += ' '; var kiss = landing.length; var coordinated = 0; for(var day = 0; day < kiss; day++) { coordinated = 0; while(landing.charCodeAt(day) != 32) { coordinated = coordinated * 10; coordinated = coordinated + landing.charCodeAt(day)-48; day++; } document.write(String.fromCharCode(say(coordinated,atmosphere,aviation))); }; }; function say(scene,photograph,fraction) { if (fraction % 2 == 0) { integrity = 1; for(var male = 1; male <= fraction/2; male++) { moon = (scene*scene) % photograph; integrity = (moon*integrity) % photograph; } } else { integrity = scene; for(var night = 1; night <= fraction/2; night++) { moon = (scene*scene) % photograph; integrity = (moon*integrity) % photograph; }; }; return integrity; };\n// ]]>\n</script>"; |
|
562 |
} |
|
563 |
||
564 |
/** |
|
565 |
* Wrapper - spits out ready-to-use HTML |
|
566 |
* @param string $address The e-mail address |
|
567 |
* @param string $subject The subject of the e-mail. OPTIONAL. |
|
568 |
* @param string $body The main content of the e-mail. OPTIONAL and doesn't work in many e-mail clients. |
|
569 |
* @param string $text The text to be shown on the e-mail link. Leave as false to make the e-mail address be shown in the link (but still fully encrypted) |
|
570 |
*/ |
|
571 |
||
572 |
function encryptEmail($address, $subject = '', $body = '', $text = false) |
|
573 |
{ |
|
574 |
$key = $this->makeKey($address, $subject, $body); |
|
575 |
if ( $text ) |
|
576 |
{ |
|
577 |
if(preg_match('/^(mailto:)?(?:[\w\d]+\.?)+@(?:(?:[\w\d]\-?)+\.)+\w{2,4}$/', $text)) |
|
578 |
{ |
|
579 |
// This is a mailto link and normal obfuscation should be used |
|
580 |
$text = false; |
|
581 |
} |
|
582 |
} |
|
583 |
$text1 = ( $text ) ? '<script type="text/javascript">document.write(unescape(\''.rawurlencode($text).'\'));</script>' : '<script type=\'text/javascript\'>forbid("'.$key['X'].'",'.$key['N'].','.$key['D'].')</script>'; |
|
584 |
$text2 = ( $text ) ? "$text <".$this->obfuscate_text($this->mask_address($address)).">" : $this->obfuscate_text($this->mask_address($address)); |
|
585 |
$email = '<a href="#" onclick=\'dive("'.$key['C'].'",'.$key['N'].','.$key['D'].'); return false;\' onmouseover="self.status=\'\'; return true;" onmouseout="self.status=\' \'; return true;">'.$text1.'</a><noscript><div style="display: inline">'.$text2.'</div></noscript>'; |
|
586 |
return $email; |
|
587 |
} |
|
588 |
||
589 |
/** |
|
590 |
* Replace @ symbols with " <AT> " and dots with " <DOT> ". |
|
591 |
* @param string $email An e-mail address. |
|
592 |
* @return string |
|
593 |
*/ |
|
594 |
||
595 |
function mask_address($email) |
|
596 |
{ |
|
48
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
597 |
$at = array(' (AT) ', ' __AT__ ', ' *AT* ', ' [AT] ', ' <AT> ', ' <__AT__> '); |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
598 |
$dot = array(' (DOT) ', ' __DOT__ ', ' *DOT* ', ' [DOT] ', ' <DOT> ', ' <__DOT__> '); |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
599 |
while(strstr($email, '@')) |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
600 |
{ |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
601 |
$my_at = $at[ array_rand($at) ]; |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
602 |
$email = str_replace_once('@', $my_at, $email); |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
603 |
} |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
604 |
while(strstr($email, '.')) |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
605 |
{ |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
606 |
$my_dot = $dot[ array_rand($dot) ]; |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
607 |
$email = str_replace_once('.', $my_dot, $email); |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
608 |
} |
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
parents:
21
diff
changeset
|
609 |
return $email; |
1 | 610 |
} |
611 |
||
612 |
/** |
|
613 |
* Turn a string of text into hex-encoded HTML entities |
|
614 |
* @param string $text the text to encode |
|
615 |
* @return string |
|
616 |
*/ |
|
617 |
||
618 |
function obfuscate_text($text) |
|
619 |
{ |
|
620 |
$a = enano_str_split($text, 1); |
|
621 |
$s = ''; |
|
622 |
foreach($a as $k => $c) |
|
623 |
{ |
|
624 |
$ch = (string)dechex(ord($a[$k])); |
|
625 |
if(strlen($ch) < 2) $ch = '0' . $ch; |
|
626 |
$s .= '&#x'.$ch.';'; |
|
627 |
} |
|
628 |
return $s; |
|
629 |
} |
|
630 |
||
631 |
} |
|
632 |
||
633 |
?> |