XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
spamfilter.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
9 {
13  function init()
14  {
15  }
16 
20  function setAvoidLog()
21  {
22  $_SESSION['avoid_log'] = true;
23  }
24 
29  {
30  if($_SESSION['avoid_log']) return new BaseObject();
31  // Check the login status, login information, and permission
32  $is_logged = Context::get('is_logged');
33  $logged_info = Context::get('logged_info');
34  $grant = Context::get('grant');
35  // In case logged in, check if it is an administrator
36  if($is_logged)
37  {
38  if($logged_info->is_admin == 'Y') return new BaseObject();
39  if($grant->manager) return new BaseObject();
40  }
41 
42  $oFilterModel = getModel('spamfilter');
43  // Check if the IP is prohibited
44  $output = $oFilterModel->isDeniedIP();
45  if(!$output->toBool()) return $output;
46  // Check if there is a ban on the word
47  $text = '';
48  if($is_logged)
49  {
50  $text = $obj->title . ' ' . $obj->content . ' ' . $obj->tags;
51  }
52  else
53  {
54  $text = $obj->title . ' ' . $obj->content . ' ' . $obj->nick_name . ' ' . $obj->homepage . ' ' . $obj->tags;
55  }
56  $output = $oFilterModel->isDeniedWord($text);
57  if(!$output->toBool()) return $output;
58  // Check the specified time beside the modificaiton time
59  if($obj->document_srl == 0)
60  {
61  $output = $oFilterModel->checkLimited();
62  if(!$output->toBool()) return $output;
63  }
64  // Save a log
65  $this->insertLog();
66 
67  return new BaseObject();
68  }
69 
74  {
75  if($_SESSION['avoid_log']) return new BaseObject();
76  // Check the login status, login information, and permission
77  $is_logged = Context::get('is_logged');
78  $logged_info = Context::get('logged_info');
79  $grant = Context::get('grant');
80  // In case logged in, check if it is an administrator
81  if($is_logged)
82  {
83  if($logged_info->is_admin == 'Y') return new BaseObject();
84  if($grant->manager) return new BaseObject();
85  }
86 
87  $oFilterModel = getModel('spamfilter');
88  // Check if the IP is prohibited
89  $output = $oFilterModel->isDeniedIP();
90  if(!$output->toBool()) return $output;
91  // Check if there is a ban on the word
92  $text = '';
93  if($is_logged)
94  {
95  $text = $obj->content;
96  }
97  else
98  {
99  $text = $obj->content . ' ' . $obj->nick_name . ' ' . $obj->homepage;
100  }
101  $output = $oFilterModel->isDeniedWord($text);
102  if(!$output->toBool()) return $output;
103  // If the specified time check is not modified
104  if(!$obj->__isupdate)
105  {
106  $output = $oFilterModel->checkLimited();
107  if(!$output->toBool()) return $output;
108  }
109  unset($obj->__isupdate);
110  // Save a log
111  $this->insertLog();
112 
113  return new BaseObject();
114  }
115 
120  {
121  if($_SESSION['avoid_log']) return new BaseObject();
122 
123  $oFilterModel = getModel('spamfilter');
124  // Confirm if the trackbacks have been added more than once to your document
125  $output = $oFilterModel->isInsertedTrackback($obj->document_srl);
126  if(!$output->toBool()) return $output;
127 
128  // Check if the IP is prohibited
129  $output = $oFilterModel->isDeniedIP();
130  if(!$output->toBool()) return $output;
131  // Check if there is a ban on the word
132  $text = $obj->blog_name . ' ' . $obj->title . ' ' . $obj->excerpt . ' ' . $obj->url;
133  $output = $oFilterModel->isDeniedWord($text);
134  if(!$output->toBool()) return $output;
135  // Start Filtering
136  $oTrackbackModel = getModel('trackback');
137  $oTrackbackController = getController('trackback');
138 
139  list($ipA,$ipB,$ipC,$ipD) = explode('.',$_SERVER['REMOTE_ADDR']);
140  $ipaddress = $ipA.'.'.$ipB.'.'.$ipC;
141  // In case the title and the blog name are indentical, investigate the IP address of the last 6 hours, delete and ban it.
142  if($obj->title == $obj->excerpt)
143  {
144  $oTrackbackController->deleteTrackbackSender(60*60*6, $ipaddress, $obj->url, $obj->blog_name, $obj->title, $obj->excerpt);
145  $this->insertIP($ipaddress.'.*', 'AUTO-DENIED : trackback.insertTrackback');
146  return new BaseObject(-1,'msg_alert_trackback_denied');
147  }
148  // If trackbacks have been registered by one C-class IP address more than once for the last 30 minutes, ban the IP address and delete all the posts
149  /* 호스팅 환경을 감안하여 일단 이 부분은 동작하지 않도록 주석 처리
150  $count = $oTrackbackModel->getRegistedTrackback(30*60, $ipaddress, $obj->url, $obj->blog_name, $obj->title, $obj->excerpt);
151  if($count > 1) {
152  $oTrackbackController->deleteTrackbackSender(3*60, $ipaddress, $obj->url, $obj->blog_name, $obj->title, $obj->excerpt);
153  $this->insertIP($ipaddress.'.*');
154  return new BaseObject(-1,'msg_alert_trackback_denied');
155  }
156  */
157 
158  return new BaseObject();
159  }
160 
165  function insertIP($ipaddress_list, $description = null)
166  {
167  $regExr = "/^((\d{1,3}(?:.(\d{1,3}|\*)){3})\s*(\/\/(.*)\s*)?)*\s*$/";
168  if(!preg_match($regExr,$ipaddress_list)) return new BaseObject(-1, 'msg_invalid');
169  $ipaddress_list = str_replace("\r","",$ipaddress_list);
170  $ipaddress_list = explode("\n",$ipaddress_list);
171  foreach($ipaddress_list as $ipaddressValue)
172  {
173  $args = new stdClass();
174  preg_match("/(\d{1,3}(?:.(\d{1,3}|\*)){3})\s*(\/\/(.*)\s*)?/",$ipaddressValue,$matches);
175  if($ipaddress=trim($matches[1]))
176  {
177  $args->ipaddress = $ipaddress;
178  if(!$description && $matches[4]) $args->description = $matches[4];
179  else $args->description = $description;
180  }
181  $output = executeQuery('spamfilter.insertDeniedIP', $args);
182  if(!$output->toBool()) $fail_list .= $ipaddress.'<br/>';
183  }
184 
185  $output->add('fail_list',$fail_list);
186  return $output;
187  }
188 
193  {
194  if($_SESSION['avoid_log']) return new BaseObject();
195 
196  $logged_info = Context::get('logged_info');
197  if($logged_info->is_admin == 'Y') return new BaseObject();
198 
199  $oFilterModel = getModel('spamfilter');
200  // Check if the IP is prohibited
201  $output = $oFilterModel->isDeniedIP();
202  if(!$output->toBool()) return $output;
203  // Check if there is a ban on the word
204  $text = $obj->title . ' ' . $obj->content;
205  $output = $oFilterModel->isDeniedWord($text);
206  if(!$output->toBool()) return $output;
207  // Check the specified time
208  $output = $oFilterModel->checkLimited(TRUE);
209  if(!$output->toBool()) return $output;
210  // Save a log
211  $this->insertLog();
212 
213  return new BaseObject();
214  }
215 
221  function insertLog()
222  {
223  $output = executeQuery('spamfilter.insertLog');
224  return $output;
225  }
226 }
227 /* End of file spamfilter.controller.php */
228 /* Location: ./modules/spamfilter/spamfilter.controller.php */
getController($module_name)
Definition: func.inc.php:90
$obj
Definition: ko.install.php:262
$output
Definition: ko.install.php:193
insertLog()
Log registration Register the newly accessed IP address in the log. In case the log interval is withi...
The parent class of the spamfilter module.
insertIP($ipaddress_list, $description=null)
IP registration The registered IP address is considered as a spammer.
triggerSendMessage(&$obj)
The routine process to check the time it takes to store a message, when writing it, and to ban IP/word.
triggerInsertTrackback(&$obj)
Inspect the trackback creation time and IP.
$args
Definition: ko.install.php:185
setAvoidLog()
Call this function in case you need to stop the spam filter&#39;s usage during the batch work...
The controller class for the spamfilter module.
triggerInsertDocument(&$obj)
The routine process to check the time it takes to store a document, when writing it, and to ban IP/word.
getModel($module_name)
Definition: func.inc.php:145
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
triggerInsertComment(&$obj)
The routine process to check the time it takes to store a comment, and to ban IP/word.