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