-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnsbl.plugin.php
executable file
·125 lines (115 loc) · 2.66 KB
/
dnsbl.plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* DNSBL
*
*
* @package dnsbl
* @version $Id$
* @author ayunyan <ayu@commun.jp>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link http://ayu.commun.jp/habari-dnsbl
*/
class Dnsbl extends Plugin
{
/**
* setting priority
*
* @access public
* @return array
*/
public function set_priorities()
{
return array(
'action_comment_insert_before' => 1
);
}
/**
* action: plugin_activation
*
* @access public
* @param string $file
* @return void
*/
public function action_plugin_activation($file)
{
if (Plugins::id_from_file($file) != Plugins::id_from_file(__FILE__)) return;
Options::set('dnsbl__ipbl', "dnsbl.spam-champuru.livedoor.com");
// URL blacklist not implemented, perhaps for the future?
// Options::set('dnsbl__urlbl', "bsb.spamlookup.net");
}
/**
* action: update_check
*
* @access public
* @return void
*/
public function action_update_check()
{
Update::add($this->info->name, $this->info->guid, $this->info->version);
}
/**
* action: plugin_ui
*
* @access public
* @param string $plugin_id
* @param string $action
* @return void
*/
public function action_plugin_ui($plugin_id, $action)
{
if ($plugin_id != $this->plugin_id()) return;
if ($action == _t('Configure')) {
$form = new FormUI(strtolower(get_class($this)));
$form->append('textarea', 'ipbl', 'dnsbl__ipbl', _t('IP Blacklists: ', 'dnsbl'));
$form->append('submit', 'save', _t('Save'));
$form->out();
}
}
/**
* filter: plugin_config
*
* @access public
* @param array $actions
* @param string $plugin_id
* @return array
*/
public function filter_plugin_config($actions, $plugin_id)
{
if ($plugin_id == $this->plugin_id()) {
$actions[]= _t('Configure');
}
return $actions;
}
/**
* action: comment_insert_before
*
* @access public
* @param object $comment
* @return void
*/
public function action_comment_insert_before($comment)
{
$ipaddrs = explode('.', $comment->ip, 4);
$reverse_ipaddr = join('.', array_reverse($ipaddrs));
$ipbls = Options::get('dnsbl__ipbl');
$ipbls = str_replace("\r", '', $ipbls);
$ipbls = explode("\n", trim($ipbls));
$checks = array();
@reset($ipbls);
while (list(, $ipbl) = @each($ipbls)) {
$addr = gethostbyname($reverse_ipaddr . '.' . $ipbl);
if ($addr == '127.0.0.2') {
$checks[] = sprintf(_t('Flagged by DNSBL (%s)', 'dnsbl'), $ipbl);
}
}
if (count($checks) > 0) {
$comment->status = 'spam';
if (isset($comment->info->spamcheck)) {
$comment->info->spamcheck = array_unique(array_merge($comment->info->spamcheck, $checks));
} else {
$comment->info->spamcheck = $checks;
}
}
}
}
?>