Subversion Repositories php_antispam

Compare Revisions

Regard whitespace Rev 5 → Rev 6

/trunk/v4.inc.php
2,31 → 2,31
 
/*
* ViaThinkSoft Anti-Spam Script for PHP
* (C) 2009-2013 ViaThinkSoft
* Revision: 2013-03-04 (Version 4.01)
* (C) 2009-2022 ViaThinkSoft
* Revision: 2022-01-09 (Version 4.1)
* License: Apache 2.0 License
*/
 
function secure_email($email, $linktext, $crypt_linktext)
{
// No new lines to avoid a JavaScript error!
$linktext = str_replace("\r", ' ', $linktext);
$linktext = str_replace("\n", ' ', $linktext);
class VtsAntiSpam4 {
 
if (!defined('ALAS_INCLUDED')) {
// Anfagswert über aktuelle Mikrosekunde setzen
public $garbageLength = 5;
 
public function __construct() {
self::randomize();
}
 
private static function randomize() {
// Anfagswert über aktuelle Mikrosekunde setzen
// http://de2.php.net/manual/de/function.srand.php
function make_seed() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
$seed = (int)($sec + ((float)$usec * 100000));
srand($seed);
}
srand(make_seed());
 
define('ALAS_GARBARGE_LENGTH', 5);
 
private function RandomString($len) {
// http://www.jonasjohn.de/snippets/php/rand-str.htm
function RandomString($len) {
$randstr = '';
srand((double)microtime()*1000000);
//srand((double)microtime()*1000000);
for($i=0;$i<$len;$i++) {
$n = rand(48,120);
while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96)) {
37,8 → 37,8
return $randstr;
}
 
function js_randombreaks() {
$len = rand(0, ALAS_GARBARGE_LENGTH);
private function js_randombreaks() {
$len = rand(0, $this->garbageLength);
$r = '';
$one_line_comment = false;
for($i=0;$i<$len;$i++) {
47,7 → 47,7
$r .= ' ';
} else if ($m == 1) {
$r .= '//';
$r .= RandomString($i);
$r .= $this->RandomString($i);
$one_line_comment = true;
} else if ($m == 2) {
$r .= "\r\n";
60,42 → 60,45
return $r;
}
 
function alas_js_crypt($text) {
private function alas_js_crypt($text) {
$tmp = '';
for ($i=0; $i<strlen($text); $i++) {
$tmp .= js_randombreaks();
$tmp .= $this->js_randombreaks();
$tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
$tmp .= js_randombreaks();
$tmp .= $this->js_randombreaks();
}
$tmp = js_randombreaks().$tmp.js_randombreaks();
$tmp = $this->js_randombreaks().$tmp.$this->js_randombreaks();
return $tmp;
}
 
function alas_noscript_crypt($text){
private function alas_noscript_crypt($text){
$tmp = '';
for ($i=0; $i<strlen($text); $i++) {
$tmp .= '<span style="display:inline;">&#'.ord(substr($text, $i, 1)).';</span>';
$tmp .= '<!--'.js_randombreaks().'-->';
$tmp .= '<span style="display:none;">'.RandomString(rand(0, ALAS_GARBARGE_LENGTH)).'</span>';
$tmp .= '<!--'.$this->js_randombreaks().'-->';
$tmp .= '<span style="display:none;">'.$this->RandomString(rand(0, $this->garbageLength)).'</span>';
}
return $tmp;
}
 
function alas_js_write($text) {
private function alas_js_write($text) {
$text = str_replace('\\', '\\\\', $text);
$text = str_replace('"', '\"', $text);
$text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a>
 
$ret = '';
$ret .= js_randombreaks();
$ret .= $this->js_randombreaks();
$ret .= 'document.write("'.$text.'");';
$ret .= js_randombreaks();
$ret .= $this->js_randombreaks();
 
return $ret;
}
 
define('ALAS_INCLUDED', true);
}
public function secure_email($email, $linktext, $crypt_linktext)
{
// No new lines to avoid a JavaScript error!
$linktext = str_replace("\r", ' ', $linktext);
$linktext = str_replace("\n", ' ', $linktext);
 
$aus = '';
if ($email != '') {
104,15 → 107,15
 
$aus .= "<!-- BEGIN $title [ID $zid] -->\r\n";
$aus .= '<script language="JavaScript" type="text/javascript"><!--'."\n";
$aus .= alas_js_write('<a href="');
$aus .= alas_js_crypt('mailto:'.$email);
$aus .= alas_js_write('">');
$aus .= $crypt_linktext ? alas_js_crypt($linktext) : alas_js_write($linktext);
$aus .= alas_js_write('</a>').'// --></script>';
$aus .= $this->alas_js_write('<a href="');
$aus .= $this->alas_js_crypt('mailto:'.$email);
$aus .= $this->alas_js_write('">');
$aus .= $crypt_linktext ? $this->alas_js_crypt($linktext) : $this->alas_js_write($linktext);
$aus .= $this->alas_js_write('</a>').'// --></script>';
 
$aus .= '<noscript>';
if ($linktext != $email) $aus .= ($crypt_linktext ? alas_noscript_crypt($linktext) : $linktext).' ';
$aus .= alas_noscript_crypt("[ $email ]");
if ($linktext != $email) $aus .= ($crypt_linktext ? $this->alas_noscript_crypt($linktext) : $linktext).' ';
$aus .= $this->alas_noscript_crypt("[ $email ]");
$aus .= '</noscript>';
$aus .= "\r\n<!-- END $title [ID $zid] -->\r\n";
}
120,13 → 123,40
return $aus;
}
 
function secure_email_autodetect($email, $linktext) {
// Automatisch erkennen, ob der $linktext für Spambots interessant ist oder nicht
public function secure_email_autodetect($email, $linktext) {
// Automatisch erkennen, ob der $linktext für Spambots interessant ist oder nicht
$pos = strpos($linktext, '@');
 
return secure_email($email, $linktext, $pos !== false);
return $this->secure_email($email, $linktext, $pos !== false);
}
 
public function secure_email_identical_text($email) {
return $this->secure_email_autodetect($email, $email);
}
 
}
 
# ------------------------------------------------------------------------------
 
function secure_email($email, $linktext, $crypt_linktext, $css_class='') {
if (!empty($css_class)) {
// TODO
throw new Exception("CSSClass is not yet implemented in AntiSpam v4");
}
 
$antispam = new VtsAntiSpam4();
$res = $antispam->secure_email($email, $linktext, $crypt_linktext);
return $res;
}
 
function secure_email_autodetect($email, $linktext) {
$antispam = new VtsAntiSpam4();
$res = $antispam->secure_email_autodetect($email, $linktext);
return $res;
}
 
function secure_email_identical_text($email) {
return secure_email_autodetect($email, $email);
$antispam = new VtsAntiSpam4();
$res = $antispam->secure_email_identical_text($email);
return $res;
}