Subversion Repositories php_antispam

Compare Revisions

No changes between revisions

Regard whitespace Rev 1 → Rev 2

/trunk/docs/antispam3-description.txt
0,0 → 1,84
ALAS-AntiSpam-Schutz
 
Folgende Funktion soll euch helfen, E-Mail-Adressen per JavaScript-Ausgabe sicher darzustellen, sodass der Benutzer sie auch anklicken und verwenden kann. Das Script wird als sehr sicher eingestuft.
 
[b]Code[/b]
 
[code]<?php
 
// PHP-AntiSpam-Funktion "secure_email", Version 3.02 of 2009-09-23
// von Daniel Marschall [www.daniel-marschall.de]
 
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);
 
if (!function_exists('alas_js_crypt'))
{
function alas_js_crypt($text)
{
$tmp = '';
for ($i=0; $i<strlen($text); $i++)
{
$tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
}
return $tmp;
}
}
 
if (!function_exists('alas_js_write'))
{
function alas_js_write($text)
{
$text = str_replace('\\', '\\\\', $text);
$text = str_replace('"', '\"', $text);
$text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a>
return 'document.write("'.$text.'");';
}
}
 
$aus = '';
if ($email != '')
{
$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>';
}
 
return $aus;
}
 
?>[/code]
 
[b]Beschreibung[/b]
 
Jedes Zeichen wird einzeln mit dem Zeichen-Code in einer einzelnen Zeile geschrieben. Selbst mailto, @ und .de werden mitverschlüsselt. Folglich kann man den Mechanismus als sehr sicher einstufen.
 
Der Benutzer muss JavaScript aktiviert haben, um die E-Mail-Adresse zu sehen. Die Verwendung von JavaScript ist aber Webseiten üblich und ist bei allen Browser standardmäßig aktiviert.
 
Vorteilhaft ist, dass kein SpamBot diesen Mechanismus kennt, da dieser nicht häufig angewandt wird. Ich bitte daher, diesen Spamschutz nicht in große Systeme ohne Erlaubnis einzubauen, da bei zu starkem Bekanntheitsgrades der JavaScript-Struktur, die Spam-Bots dem Mechanismus entgegenwirken könnten.
 
Auch ohne PHP ist der Spamschutz möglich, da der Code bereits im Vorraus berechnet und die Ausgabe in einer HTML-Datei eingebaut werden kann.
 
[b]Benutzung[/b]
 
1. Parameter: E-Mail-Adresse ohne Angabe von "mailto:"
2. Parameter: Angabe des Linktextes oder des Linkbildes
3. Parameter: Soll der 2. Parameter auch verschlüsselt werden? Nur ein Text darf verschlüsselt werden, ein Bild nicht! Der Linktext muss verschlüsselt werden, wenn er die E-Mail-Adresse enthält, da sonst der Schutz verfällt.
 
[b]Beispiele[/b]
 
[code]<?php
 
echo secure_email('test@example.com', 'Schreib mir!', 0);
echo secure_email('test@example.com', 'test@example.com', 1);
echo secure_email('test@example.com', '<img src="...">', 0);
 
?>[/code]
 
Das Script ist Teil meiner ALAS-Kampagne und wird ViaThinkSoft-Weit inkl. Personal WebBase, dev.board und Partnerseiten verwendet.
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/trunk/examples/antispam3-autofilter-example.inc.php
0,0 → 1,148
<?php
 
// This is an example of the ViaThinkSoft AntiSpam 3.02
// for ViaThinkSoft Sigma as filter plugin (modified $content)
// Use it for your website!
 
// CONFIGURATION
 
define('CFG_MAKE_MAIL_ADDRESSES_CLICKABLE', true);
 
// CODE
 
function secure_email_triv($email)
{
if (!function_exists('alas_js_crypt'))
{
function alas_js_crypt($text)
{
$tmp = '';
for ($i=0; $i<strlen($text); $i++)
{
$tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
}
return $tmp;
}
}
 
$aus = '';
if ($email != '')
{
$aus .= '<script language="JavaScript" type="text/javascript"><!--'."\n";
$aus .= alas_js_crypt($email);
$aus .= '// --></script>';
}
return $aus;
}
 
// PHP-AntiSpam-Funktion "secure_email", Version 3.02
// von Daniel Marschall [www.daniel-marschall.de]
 
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);
 
if (!function_exists('alas_js_crypt'))
{
function alas_js_crypt($text)
{
$tmp = '';
for ($i=0; $i<strlen($text); $i++)
{
$tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
}
return $tmp;
}
}
 
if (!function_exists('alas_js_write'))
{
function alas_js_write($text)
{
$text = str_replace('\\', '\\\\', $text);
$text = str_replace('"', '\"', $text);
$text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a>
return 'document.write("'.$text.'");';
}
}
 
$aus = '';
if ($email != '')
{
$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>';
}
return $aus;
}
 
function getAddrSpec() {
// Ref: http://www.iamcal.com/publish/articles/php/parsing_email/
 
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$quoted_pair = '\\x5c[\\x00-\\x7f]';
$domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
$quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\\x2e$sub_domain)*";
$local_part = "$word(\\x2e$word)*";
$addr_spec = "$local_part\\x40$domain";
 
return $addr_spec;
}
 
function is_valid_email_address($email){
$addr_spec = getAddrSpec();
return preg_match("!^$addr_spec$!", $email) ? true : false;
}
 
function auto_secure_mail_addresses($content) {
$addr_spec = getAddrSpec();
 
// Step 1: Parse links and make them secure
 
if (!function_exists('link_cb_1')) {
function link_cb_1($a) {
$mailaddr = $a[2];
$linktext = $a[14]; // Letztes
 
return secure_email($mailaddr, $linktext, is_valid_email_address($linktext));
}
}
 
$content = preg_replace_callback("/<a(.+?)mailto:($addr_spec)(.+?)>(.+?)<\/a>/sm", 'link_cb_1', $content); // TODO! Kann Greedy werden!
 
// Step 2: Find all further mail addresses, make then clickable and prevent spam bots
 
if (!function_exists('link_cb_2')) {
function link_cb_2($a) {
$mailaddr = $a[1]; // Letztes
 
if (CFG_MAKE_MAIL_ADDRESSES_CLICKABLE) {
return secure_email($mailaddr, $mailaddr, true);
} else {
return secure_email_triv($mailaddr);
}
}
}
 
$content = preg_replace_callback("/($addr_spec)/sm", 'link_cb_2', $content);
 
// Output
 
return $content;
}
 
$content = auto_secure_mail_addresses($content);
 
?>
/trunk/examples/antispam4-example.php
0,0 → 1,32
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
 
<html>
 
<head>
<title>ViaThinkSoft AntiSpam Test</title>
</head>
 
<body>
 
<?php
 
echo '<form action="'.$PHP_SELF.'">
<input name="email" value="'.$_GET['email'].'">
<input name="linktext" value="'.$_GET['linktext'].'">
<input type="checkbox" name="crypt_linktext" checked>
<input type="submit">
</form>';
 
include 'antispam.inc.php';
 
$x = secure_email($_GET['email'], $_GET['linktext'], isset($_GET['crypt_linktext']));
echo '<textarea cols="120" rows="20">'.htmlentities($x).'</textarea>';
echo '<hr>';
echo $x;
 
?>
 
</body>
 
</html>
/trunk/todo.txt
0,0 → 1,14
ToDo 3.x
 
- Nothing :-)
 
ToDo 4.x
 
- Pack everything in a PHP class
- Allow to add things before and after the content of <a>...</a> (e.g. font colors)
- Allow to add things before and after the script/noscript part (because of W3C validity)
- Make the text links variable
 
Future
 
- Release phpBB 2 + 3 mods for ViaThinkSoft AntiSpam
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/trunk/v3.inc.php
0,0 → 1,48
<?php
 
// PHP-AntiSpam-Funktion "secure_email", Version 3.05 of 2018-07-20
// von Daniel Marschall [www.daniel-marschall.de]
 
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);
 
if (!function_exists('alas_js_crypt'))
{
function alas_js_crypt($text)
{
$tmp = '';
for ($i=0; $i<strlen($text); $i++)
{
$tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
}
return $tmp;
}
}
 
if (!function_exists('alas_js_write'))
{
function alas_js_write($text)
{
$text = str_replace('\\', '\\\\', $text);
$text = str_replace('"', '\"', $text);
$text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a>
return 'document.write("'.$text.'");';
}
}
 
$aus = '';
if ($email != '')
{
$aus .= '<script><!--'."\n"; // type="text/javascript" is not necessary in HTML5
$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>';
}
 
return $aus.'<noscript>Please enable JavaScript to display this email address.</noscript>';
}
/trunk/v4.inc.php
0,0 → 1,134
<?php
 
/*
* ViaThinkSoft Anti-Spam Script for PHP
* (C) 2009-2013 ViaThinkSoft
* Revision: 2013-03-04 (Version 4.01)
*/
 
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);
 
if (!defined('ALAS_INCLUDED')) {
// 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);
}
srand(make_seed());
 
define('ALAS_GARBARGE_LENGTH', 5);
 
// http://www.jonasjohn.de/snippets/php/rand-str.htm
function RandomString($len) {
$randstr = '';
srand((double)microtime()*1000000);
for($i=0;$i<$len;$i++) {
$n = rand(48,120);
while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96)) {
$n = rand(48,120);
}
$randstr .= chr($n);
}
return $randstr;
}
 
function js_randombreaks() {
$len = rand(0, ALAS_GARBARGE_LENGTH);
$r = '';
$one_line_comment = false;
for($i=0;$i<$len;$i++) {
$m = rand(0, 3);
if ($m == 0) {
$r .= ' ';
} else if ($m == 1) {
$r .= '//';
$r .= RandomString($i);
$one_line_comment = true;
} else if ($m == 2) {
$r .= "\r\n";
$one_line_comment = false;
} else {
$r .= "\t";
}
}
if ($one_line_comment) $r .= "\r\n";
return $r;
}
 
function alas_js_crypt($text) {
$tmp = '';
for ($i=0; $i<strlen($text); $i++) {
$tmp .= js_randombreaks();
$tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
$tmp .= js_randombreaks();
}
$tmp = js_randombreaks().$tmp.js_randombreaks();
return $tmp;
}
 
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>';
}
return $tmp;
}
 
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 .= 'document.write("'.$text.'");';
$ret .= js_randombreaks();
 
return $ret;
}
 
define('ALAS_INCLUDED', true);
}
 
$aus = '';
if ($email != '') {
$zid = 'ALAS-4.0-'.DecHex(crc32($email)).'-'.DecHex(crc32($linktext)).'-'.($crypt_linktext ? 'S' : 'L');
$title = 'ViaThinkSoft "ALAS" Anti-Spam';
 
$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 .= '<noscript>';
if ($linktext != $email) $aus .= ($crypt_linktext ? alas_noscript_crypt($linktext) : $linktext).' ';
$aus .= alas_noscript_crypt("[ $email ]");
$aus .= '</noscript>';
$aus .= "\r\n<!-- END $title [ID $zid] -->\r\n";
}
 
return $aus;
}
 
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);
}
 
function secure_email_identical_text($email) {
return secure_email_autodetect($email, $email);
}
 
?>