author | Dan |
Fri, 18 Jan 2008 22:27:29 -0500 | |
changeset 355 | d15e4411ef65 |
parent 345 | 4ccdfeee9a11 |
child 387 | 92664d2efab8 |
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 |
|
322
5f1cd51bf1be
Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents:
166
diff
changeset
|
5 |
* Version 1.0.3 (Dyrad) |
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 |
||
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
parents:
322
diff
changeset
|
30 |
function __construct($use_smtp) |
1 | 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 . |
|
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
parents:
322
diff
changeset
|
154 |
"\nContent-transfer-encoding: 8bit\nDate: " . enano_date('r', time()) . |
1 | 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"; |
|
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
parents:
322
diff
changeset
|
250 |
$this->mimeOut .= "Date: ".enano_date("D, d M Y H:i:s") . " UT\n"; |
1 | 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 testAll() { |
|
353 |
$size = sizeof($this->primes); |
|
354 |
||
355 |
$allCharacters = ""; |
|
356 |
for($c = 33; $c <= 126; $c++) |
|
357 |
$allCharacters = $allCharacters . $this->fromCharCode($c); |
|
358 |
||
359 |
for($i = 0; $i < $size - 1; $i++) { |
|
360 |
for($j = $i + 1; $j < $size; $j++) { |
|
361 |
$this->p = $this->primes[$i]; |
|
362 |
$this->q = $this->primes[$j]; |
|
363 |
if($this->p*$this->q < 255) |
|
364 |
break; |
|
365 |
$k = $this->makeKey($allCharacters); |
|
366 |
$encrypted = $k['X']; |
|
367 |
$decrypted = $this->goForth($encrypted,$this->p*$this->q,$k['D']); |
|
368 |
if($decrypted != $allCharacters) { |
|
369 |
die('Test failed'); |
|
370 |
} |
|
371 |
} |
|
372 |
} |
|
373 |
return 'GOOD'; |
|
374 |
} |
|
375 |
||
376 |
function charCodeAt($str, $i) |
|
377 |
{ |
|
378 |
return ord(substr($str, $i, 1)); |
|
379 |
} |
|
380 |
||
381 |
function fromCharCode($str) |
|
382 |
{ |
|
383 |
return chr($str); |
|
384 |
} |
|
385 |
||
386 |
function MakeArray($l) { |
|
387 |
$a = Array(); |
|
388 |
$i=0; |
|
389 |
do { |
|
390 |
$a[$i]=null; |
|
391 |
$i++; |
|
392 |
} while($i < $l); |
|
393 |
return $a; |
|
394 |
} |
|
395 |
||
396 |
function makeKey($addr,$subj = '',$body = '') { |
|
397 |
$value = ""; |
|
398 |
||
399 |
if($this->p * $this->q < 255) |
|
400 |
{ |
|
401 |
return("P*Q must be greater than 255! P*Q = " . $this->p*$this->q); |
|
402 |
} |
|
403 |
elseif($this->p == $this->q) |
|
404 |
{ |
|
405 |
return("P cannot be equal to Q!"); |
|
406 |
} |
|
407 |
elseif($addr == "") |
|
408 |
{ |
|
409 |
return("You must enter an address to encrypt!"); |
|
410 |
} |
|
411 |
else |
|
412 |
{ |
|
413 |
// Make the key |
|
414 |
$c = 0; |
|
415 |
$z = ($this->p-1)*($this->q-1); |
|
416 |
$e = 0; |
|
417 |
$n = $this->p*$this->q; |
|
418 |
$d = 0; |
|
419 |
||
420 |
do { |
|
421 |
$e++; |
|
422 |
$d = $this->getKey($this->primes[$e],$z); |
|
423 |
} while($d==1); |
|
424 |
$e = $this->primes[$e]; |
|
425 |
||
426 |
// Turn the string into an array of numbers < 255 |
|
427 |
$m = $addr; |
|
428 |
$emailLength = strlen($m); |
|
429 |
$justEmail = ""; |
|
430 |
$sep = ( strstr('?', $m) ) ? '&' : '?'; |
|
431 |
if($subj != "") { |
|
432 |
$m = $m . "{$sep}subject=" . $subj; |
|
433 |
} |
|
434 |
$sep = ( strstr($m, '?') ) ? '&' : '?'; |
|
435 |
if($body != "") { |
|
436 |
$m = $m . "{$sep}body=" . $body; |
|
437 |
} |
|
438 |
||
439 |
$length = strlen($m); |
|
440 |
$theString = $this->MakeArray($length); |
|
441 |
for($i = 0; $i < $length; $i++) { |
|
442 |
$theString[$i] = $this->charCodeAt($m, $i); |
|
443 |
} |
|
444 |
||
445 |
// Encrypt each of the numbers |
|
446 |
$theCode = $this->MakeArray($length); |
|
447 |
$c = ""; |
|
448 |
$temp = 0; |
|
449 |
for($i = 0; $i < $length; $i++) { |
|
450 |
if($i != 0) |
|
451 |
$c .= " "; |
|
452 |
$temp = $this->myMod($theString[$i],$e,$n); |
|
453 |
$theCode[$i] = $temp; |
|
454 |
$c .= $temp; |
|
455 |
if($i == $emailLength - 1) |
|
456 |
$justEmail = $c; |
|
457 |
} |
|
458 |
} |
|
459 |
return Array('X'=>$justEmail, 'N'=>$n, 'D'=>$d, 'E'=>$e, 'C'=>$c, 'M'=>$m); |
|
460 |
} |
|
461 |
||
462 |
// Finds x^e % y for large values of (x^e) |
|
463 |
function myMod($x,$e,$y) { |
|
464 |
if ($e % 2 == 0) { |
|
465 |
$answer = 1; |
|
466 |
for($i = 1; $i <= e/2; $i++) { |
|
467 |
$temp = ($x*$x) % $y; |
|
468 |
$answer = ($temp*$answer) % $y; |
|
469 |
} |
|
470 |
} else { |
|
471 |
$answer = $x; |
|
472 |
for($i = 1; $i <= $e/2; $i++) { |
|
473 |
$temp = ($x*$x) % $y; |
|
474 |
$answer = ($temp*$answer) % $y; |
|
475 |
} |
|
476 |
} |
|
477 |
return $answer; |
|
478 |
} |
|
479 |
||
480 |
||
481 |
function getKey($e,$z) { |
|
482 |
$A = 1; |
|
483 |
$B = 0; |
|
484 |
$C = $z; |
|
485 |
$F = 0; |
|
486 |
$G = 1; |
|
487 |
$bar = $e; |
|
488 |
// Euclid's Algorithm: |
|
489 |
while ($bar != 0) { |
|
490 |
$foo = floor($C/$bar); |
|
491 |
$K = $A - $foo * $F; |
|
492 |
$L = $B - $foo * $G; |
|
493 |
$M = $C - $foo * $bar; |
|
494 |
$A = $F; |
|
495 |
$B = $G; |
|
496 |
$C = $bar; |
|
497 |
$F = $K; |
|
498 |
$G = $L; |
|
499 |
$bar = $M; |
|
500 |
} |
|
501 |
if ($B < 0) |
|
502 |
{ |
|
503 |
return ($B + $z); |
|
504 |
} |
|
505 |
else |
|
506 |
{ |
|
507 |
return ($B); |
|
508 |
} |
|
509 |
} |
|
510 |
||
511 |
function goForth($c,$n,$d) { |
|
512 |
$c .= " "; |
|
513 |
$length = strlen($c); |
|
514 |
$number = 0; |
|
515 |
$bar = 0; |
|
516 |
$answer = ""; |
|
517 |
||
518 |
for($i = 0; $i < $length; $i++) { |
|
519 |
$number = 0; |
|
520 |
$bar = 0; |
|
521 |
while($this->charCodeAt($c, $i) != 32) { |
|
522 |
$number = $number * 10; |
|
523 |
$number = $number + $this->charCodeAt($c, $i)-48; |
|
524 |
$i++; |
|
525 |
} |
|
526 |
$answer .= $this->fromCharCode($this->decrypt($number,$n,$d)); |
|
527 |
} |
|
528 |
return $answer; |
|
529 |
} |
|
530 |
||
531 |
function decrypt($c,$n,$d) { |
|
532 |
// Split exponents up |
|
533 |
if ($d % 2== 0) { |
|
534 |
$bar = 1; |
|
535 |
for($i = 1; $i <= $d/2; $i++) { |
|
536 |
$foo = ($c*$c) % $n; |
|
537 |
$bar = ($foo*$bar) % $n; |
|
538 |
} |
|
539 |
} else { |
|
540 |
$bar = $c; |
|
541 |
for($i = 1; $i <= $d/2; $i++) { |
|
542 |
$foo = ($c*$c) % $n; |
|
543 |
$bar = ($foo*$bar) % $n; |
|
544 |
} |
|
545 |
} |
|
546 |
return $bar; |
|
547 |
} |
|
548 |
||
549 |
function writeOptions() { |
|
550 |
$size = sizeof($this->primes); |
|
551 |
for($i = 0; $i < $size; $i++) |
|
552 |
echo("<option value=".'"'.""+$this->primes[$i]+"".'"'.">"+$this->primes[$i]+"</option>"); |
|
553 |
} |
|
554 |
||
555 |
function jscode() { |
|
556 |
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>"; |
|
557 |
} |
|
558 |
||
559 |
/** |
|
560 |
* Wrapper - spits out ready-to-use HTML |
|
561 |
* @param string $address The e-mail address |
|
562 |
* @param string $subject The subject of the e-mail. OPTIONAL. |
|
563 |
* @param string $body The main content of the e-mail. OPTIONAL and doesn't work in many e-mail clients. |
|
564 |
* @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) |
|
565 |
*/ |
|
566 |
||
567 |
function encryptEmail($address, $subject = '', $body = '', $text = false) |
|
568 |
{ |
|
569 |
$key = $this->makeKey($address, $subject, $body); |
|
570 |
if ( $text ) |
|
571 |
{ |
|
572 |
if(preg_match('/^(mailto:)?(?:[\w\d]+\.?)+@(?:(?:[\w\d]\-?)+\.)+\w{2,4}$/', $text)) |
|
573 |
{ |
|
574 |
// This is a mailto link and normal obfuscation should be used |
|
575 |
$text = false; |
|
576 |
} |
|
577 |
} |
|
578 |
$text1 = ( $text ) ? '<script type="text/javascript">document.write(unescape(\''.rawurlencode($text).'\'));</script>' : '<script type=\'text/javascript\'>forbid("'.$key['X'].'",'.$key['N'].','.$key['D'].')</script>'; |
|
579 |
$text2 = ( $text ) ? "$text <".$this->obfuscate_text($this->mask_address($address)).">" : $this->obfuscate_text($this->mask_address($address)); |
|
580 |
$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>'; |
|
581 |
return $email; |
|
582 |
} |
|
583 |
||
584 |
/** |
|
585 |
* Replace @ symbols with " <AT> " and dots with " <DOT> ". |
|
586 |
* @param string $email An e-mail address. |
|
587 |
* @return string |
|
588 |
*/ |
|
589 |
||
590 |
function mask_address($email) |
|
591 |
{ |
|
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
|
592 |
$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
|
593 |
$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
|
594 |
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
|
595 |
{ |
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
|
596 |
$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
|
597 |
$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
|
598 |
} |
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_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
|
602 |
$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
|
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 |
return $email; |
1 | 605 |
} |
606 |
||
607 |
/** |
|
608 |
* Turn a string of text into hex-encoded HTML entities |
|
609 |
* @param string $text the text to encode |
|
610 |
* @return string |
|
611 |
*/ |
|
612 |
||
613 |
function obfuscate_text($text) |
|
614 |
{ |
|
615 |
$a = enano_str_split($text, 1); |
|
616 |
$s = ''; |
|
617 |
foreach($a as $k => $c) |
|
618 |
{ |
|
619 |
$ch = (string)dechex(ord($a[$k])); |
|
620 |
if(strlen($ch) < 2) $ch = '0' . $ch; |
|
621 |
$s .= '&#x'.$ch.';'; |
|
622 |
} |
|
623 |
return $s; |
|
624 |
} |
|
625 |
||
626 |
} |
|
627 |
||
628 |
?> |