Rev 2 | Rev 6 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 5 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * ViaThinkSoft Anti-Spam Script for PHP |
4 | * ViaThinkSoft Anti-Spam Script for PHP |
5 | * (C) 2009-2013 ViaThinkSoft |
5 | * (C) 2009-2013 ViaThinkSoft |
6 | * Revision: 2013-03-04 (Version 4.01) |
6 | * Revision: 2013-03-04 (Version 4.01) |
7 | */ |
7 | */ |
8 | 8 | ||
9 | function secure_email($email, $linktext, $crypt_linktext) |
9 | function secure_email($email, $linktext, $crypt_linktext) |
10 | { |
10 | { |
11 | // No new lines to avoid a JavaScript error! |
11 | // No new lines to avoid a JavaScript error! |
12 | $linktext = str_replace("\r", ' ', $linktext); |
12 | $linktext = str_replace("\r", ' ', $linktext); |
13 | $linktext = str_replace("\n", ' ', $linktext); |
13 | $linktext = str_replace("\n", ' ', $linktext); |
14 | 14 | ||
15 | if (!defined('ALAS_INCLUDED')) { |
15 | if (!defined('ALAS_INCLUDED')) { |
16 | // Anfagswert über aktuelle Mikrosekunde setzen |
16 | // Anfagswert über aktuelle Mikrosekunde setzen |
17 | // http://de2.php.net/manual/de/function.srand.php |
17 | // http://de2.php.net/manual/de/function.srand.php |
18 | function make_seed() { |
18 | function make_seed() { |
19 | list($usec, $sec) = explode(' ', microtime()); |
19 | list($usec, $sec) = explode(' ', microtime()); |
20 | return (float) $sec + ((float) $usec * 100000); |
20 | return (float) $sec + ((float) $usec * 100000); |
21 | } |
21 | } |
22 | srand(make_seed()); |
22 | srand(make_seed()); |
23 | 23 | ||
24 | define('ALAS_GARBARGE_LENGTH', 5); |
24 | define('ALAS_GARBARGE_LENGTH', 5); |
25 | 25 | ||
26 | // http://www.jonasjohn.de/snippets/php/rand-str.htm |
26 | // http://www.jonasjohn.de/snippets/php/rand-str.htm |
27 | function RandomString($len) { |
27 | function RandomString($len) { |
28 | $randstr = ''; |
28 | $randstr = ''; |
29 | srand((double)microtime()*1000000); |
29 | srand((double)microtime()*1000000); |
30 | for($i=0;$i<$len;$i++) { |
30 | for($i=0;$i<$len;$i++) { |
31 | $n = rand(48,120); |
31 | $n = rand(48,120); |
32 | while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96)) { |
32 | while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96)) { |
33 | $n = rand(48,120); |
33 | $n = rand(48,120); |
34 | } |
34 | } |
35 | $randstr .= chr($n); |
35 | $randstr .= chr($n); |
36 | } |
36 | } |
37 | return $randstr; |
37 | return $randstr; |
38 | } |
38 | } |
39 | 39 | ||
40 | function js_randombreaks() { |
40 | function js_randombreaks() { |
41 | $len = rand(0, ALAS_GARBARGE_LENGTH); |
41 | $len = rand(0, ALAS_GARBARGE_LENGTH); |
42 | $r = ''; |
42 | $r = ''; |
43 | $one_line_comment = false; |
43 | $one_line_comment = false; |
44 | for($i=0;$i<$len;$i++) { |
44 | for($i=0;$i<$len;$i++) { |
45 | $m = rand(0, 3); |
45 | $m = rand(0, 3); |
46 | if ($m == 0) { |
46 | if ($m == 0) { |
47 | $r .= ' '; |
47 | $r .= ' '; |
48 | } else if ($m == 1) { |
48 | } else if ($m == 1) { |
49 | $r .= '//'; |
49 | $r .= '//'; |
50 | $r .= RandomString($i); |
50 | $r .= RandomString($i); |
51 | $one_line_comment = true; |
51 | $one_line_comment = true; |
52 | } else if ($m == 2) { |
52 | } else if ($m == 2) { |
53 | $r .= "\r\n"; |
53 | $r .= "\r\n"; |
54 | $one_line_comment = false; |
54 | $one_line_comment = false; |
55 | } else { |
55 | } else { |
56 | $r .= "\t"; |
56 | $r .= "\t"; |
57 | } |
57 | } |
58 | } |
58 | } |
59 | if ($one_line_comment) $r .= "\r\n"; |
59 | if ($one_line_comment) $r .= "\r\n"; |
60 | return $r; |
60 | return $r; |
61 | } |
61 | } |
62 | 62 | ||
63 | function alas_js_crypt($text) { |
63 | function alas_js_crypt($text) { |
64 | $tmp = ''; |
64 | $tmp = ''; |
65 | for ($i=0; $i<strlen($text); $i++) { |
65 | for ($i=0; $i<strlen($text); $i++) { |
66 | $tmp .= js_randombreaks(); |
66 | $tmp .= js_randombreaks(); |
67 | $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");'; |
67 | $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");'; |
68 | $tmp .= js_randombreaks(); |
68 | $tmp .= js_randombreaks(); |
69 | } |
69 | } |
70 | $tmp = js_randombreaks().$tmp.js_randombreaks(); |
70 | $tmp = js_randombreaks().$tmp.js_randombreaks(); |
71 | return $tmp; |
71 | return $tmp; |
72 | } |
72 | } |
73 | 73 | ||
74 | function alas_noscript_crypt($text){ |
74 | function alas_noscript_crypt($text){ |
75 | $tmp = ''; |
75 | $tmp = ''; |
76 | for ($i=0; $i<strlen($text); $i++) { |
76 | for ($i=0; $i<strlen($text); $i++) { |
77 | $tmp .= '<span style="display:inline;">&#'.ord(substr($text, $i, 1)).';</span>'; |
77 | $tmp .= '<span style="display:inline;">&#'.ord(substr($text, $i, 1)).';</span>'; |
78 | $tmp .= '<!--'.js_randombreaks().'-->'; |
78 | $tmp .= '<!--'.js_randombreaks().'-->'; |
79 | $tmp .= '<span style="display:none;">'.RandomString(rand(0, ALAS_GARBARGE_LENGTH)).'</span>'; |
79 | $tmp .= '<span style="display:none;">'.RandomString(rand(0, ALAS_GARBARGE_LENGTH)).'</span>'; |
80 | } |
80 | } |
81 | return $tmp; |
81 | return $tmp; |
82 | } |
82 | } |
83 | 83 | ||
84 | function alas_js_write($text) { |
84 | function alas_js_write($text) { |
85 | $text = str_replace('\\', '\\\\', $text); |
85 | $text = str_replace('\\', '\\\\', $text); |
86 | $text = str_replace('"', '\"', $text); |
86 | $text = str_replace('"', '\"', $text); |
87 | $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a> |
87 | $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a> |
88 | 88 | ||
89 | $ret = ''; |
89 | $ret = ''; |
90 | $ret .= js_randombreaks(); |
90 | $ret .= js_randombreaks(); |
91 | $ret .= 'document.write("'.$text.'");'; |
91 | $ret .= 'document.write("'.$text.'");'; |
92 | $ret .= js_randombreaks(); |
92 | $ret .= js_randombreaks(); |
93 | 93 | ||
94 | return $ret; |
94 | return $ret; |
95 | } |
95 | } |
96 | 96 | ||
97 | define('ALAS_INCLUDED', true); |
97 | define('ALAS_INCLUDED', true); |
98 | } |
98 | } |
99 | 99 | ||
100 | $aus = ''; |
100 | $aus = ''; |
101 | if ($email != '') { |
101 | if ($email != '') { |
102 | $zid = 'ALAS-4.0-'.DecHex(crc32($email)).'-'.DecHex(crc32($linktext)).'-'.($crypt_linktext ? 'S' : 'L'); |
102 | $zid = 'ALAS-4.0-'.DecHex(crc32($email)).'-'.DecHex(crc32($linktext)).'-'.($crypt_linktext ? 'S' : 'L'); |
103 | $title = 'ViaThinkSoft "ALAS" Anti-Spam'; |
103 | $title = 'ViaThinkSoft "ALAS" Anti-Spam'; |
104 | 104 | ||
105 | $aus .= "<!-- BEGIN $title [ID $zid] -->\r\n"; |
105 | $aus .= "<!-- BEGIN $title [ID $zid] -->\r\n"; |
106 | $aus .= '<script language="JavaScript" type="text/javascript"><!--'."\n"; |
106 | $aus .= '<script language="JavaScript" type="text/javascript"><!--'."\n"; |
107 | $aus .= alas_js_write('<a href="'); |
107 | $aus .= alas_js_write('<a href="'); |
108 | $aus .= alas_js_crypt('mailto:'.$email); |
108 | $aus .= alas_js_crypt('mailto:'.$email); |
109 | $aus .= alas_js_write('">'); |
109 | $aus .= alas_js_write('">'); |
110 | $aus .= $crypt_linktext ? alas_js_crypt($linktext) : alas_js_write($linktext); |
110 | $aus .= $crypt_linktext ? alas_js_crypt($linktext) : alas_js_write($linktext); |
111 | $aus .= alas_js_write('</a>').'// --></script>'; |
111 | $aus .= alas_js_write('</a>').'// --></script>'; |
112 | 112 | ||
113 | $aus .= '<noscript>'; |
113 | $aus .= '<noscript>'; |
114 | if ($linktext != $email) $aus .= ($crypt_linktext ? alas_noscript_crypt($linktext) : $linktext).' '; |
114 | if ($linktext != $email) $aus .= ($crypt_linktext ? alas_noscript_crypt($linktext) : $linktext).' '; |
115 | $aus .= alas_noscript_crypt("[ $email ]"); |
115 | $aus .= alas_noscript_crypt("[ $email ]"); |
116 | $aus .= '</noscript>'; |
116 | $aus .= '</noscript>'; |
117 | $aus .= "\r\n<!-- END $title [ID $zid] -->\r\n"; |
117 | $aus .= "\r\n<!-- END $title [ID $zid] -->\r\n"; |
118 | } |
118 | } |
119 | 119 | ||
120 | return $aus; |
120 | return $aus; |
- | 121 | } |
|
- | 122 | ||
- | 123 | function secure_email_autodetect($email, $linktext) { |
|
- | 124 | // Automatisch erkennen, ob der $linktext für Spambots interessant ist oder nicht |
|
- | 125 | $pos = strpos($linktext, '@'); |
|
- | 126 | ||
- | 127 | return secure_email($email, $linktext, $pos !== false); |
|
- | 128 | } |
|
- | 129 | ||
- | 130 | function secure_email_identical_text($email) { |
|
- | 131 | return secure_email_autodetect($email, $email); |
|
121 | } |
132 | } |
122 | - | ||
123 | function secure_email_autodetect($email, $linktext) { |
- | |
124 | // Automatisch erkennen, ob der $linktext für Spambots interessant ist oder nicht |
- | |
125 | $pos = strpos($linktext, '@'); |
- | |
126 | - | ||
127 | return secure_email($email, $linktext, $pos !== false); |
- | |
128 | } |
- | |
129 | - | ||
130 | function secure_email_identical_text($email) { |
- | |
131 | return secure_email_autodetect($email, $email); |
- | |
132 | } |
- | |
133 | - | ||
134 | ?> |
- |