1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20:
21:
22: class protector_postcommon_register_insert_js_check extends ProtectorFilterAbstract
23: {
24: function execute()
25: {
26: ob_start(array($this, 'ob_filter'));
27:
28: if (!empty($_POST)) {
29: if (!$this->checkValidate()) {
30: die(_MD_PROTECTOR_TURNJAVASCRIPTON);
31: }
32: }
33:
34: return true;
35: }
36:
37:
38: function ob_filter($s)
39: {
40: $antispam_htmls = $this->getHtml4Assign();
41:
42: return preg_replace('/<form[^>]*action=["\'](|#|register.php)["\'][^>]+>/i', '$0' . "\n" . $antispam_htmls['html_in_form'] . "\n" . $antispam_htmls['js_global'], $s, 1);
43: }
44:
45:
46:
47: 48: 49:
50: function getMd5($time = null)
51: {
52: if (empty($time)) {
53: $time = time();
54: }
55: return md5(gmdate('YmdH', $time) . \XoopsBaseConfig::get('db-prefix') . \XoopsBaseConfig::get('db-name'));
56: }
57:
58: function getHtml4Assign()
59: {
60: $as_md5 = $this->getMd5();
61: $as_md5array = preg_split('//', $as_md5, -1, PREG_SPLIT_NO_EMPTY);
62: $as_md5shuffle = array();
63: foreach ($as_md5array as $key => $val) {
64: $as_md5shuffle[] = array(
65: 'key' => $key,
66: 'val' => $val
67: );
68: }
69: shuffle($as_md5shuffle);
70: $js_in_validate_function = "antispam_md5s=new Array(32);\n";
71: foreach ($as_md5shuffle as $item) {
72: $key = $item['key'];
73: $val = $item['val'];
74: $js_in_validate_function .= "antispam_md5s[$key]='$val';\n";
75: }
76: $js_in_validate_function .= "
77: antispam_md5 = '' ;
78: for( i = 0 ; i < 32 ; i ++ ) {
79: antispam_md5 += antispam_md5s[i] ;
80: }
81: xoopsGetElementById('antispam_md5').value = antispam_md5 ;
82: ";
83:
84: return array(
85: 'html_in_form' => '<input type="hidden" name="antispam_md5" id="antispam_md5" value="" />',
86: 'js_global' => '<script type="text/javascript"><!--//' . "\n" . $js_in_validate_function . "\n" . '//--></script><noscript><div class="errorMsg">' . _MD_PROTECTOR_TURNJAVASCRIPTON . '</div></noscript>',
87: );
88: }
89:
90: function checkValidate()
91: {
92: $user_md5 = trim(@$_POST['antispam_md5']);
93:
94:
95: if ($user_md5 != $this->getMd5() && $user_md5 != $this->getMd5(time() - 3600) && $user_md5 != $this->getMd5(time() - 7200)) {
96: $this->errors[] = _MD_PROTECTOR_TURNJAVASCRIPTON;
97: return false;
98: }
99: return true;
100: }
101: }
102: