XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
spamfilter.model.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 getConfig()
21  {
22  // Get configurations (using the module model object)
23  $oModuleModel = getModel('module');
24  return $oModuleModel->getModuleConfig('spamfilter');
25  }
26 
30  function getDeniedIPList()
31  {
32  $args = new stdClass();
33  $args->sort_index = "regdate";
34  $args->page = Context::get('page')?Context::get('page'):1;
35  $output = executeQuery('spamfilter.getDeniedIPList', $args);
36  if(!$output->data) return;
37  if(!is_array($output->data)) return array($output->data);
38  return $output->data;
39  }
40 
44  function isDeniedIP()
45  {
46  $ipaddress = $_SERVER['REMOTE_ADDR'];
47 
48  $ip_list = $this->getDeniedIPList();
49  if(!count($ip_list)) return new BaseObject();
50 
51  $count = count($ip_list);
52  for($i=0;$i<$count;$i++)
53  {
54  $ip = str_replace('.', '\.', str_replace('*','(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)',$ip_list[$i]->ipaddress));
55  if(preg_match('/^'.$ip.'$/', $ipaddress, $matches)) return new BaseObject(-1,'msg_alert_registered_denied_ip');
56  }
57 
58  return new BaseObject();
59  }
60 
64  function getDeniedWordList()
65  {
66  $args = new stdClass();
67  $args->sort_index = "hit";
68  $output = executeQuery('spamfilter.getDeniedWordList', $args);
69  if(!$output->data) return;
70  if(!is_array($output->data)) return array($output->data);
71  return $output->data;
72  }
73 
77  function isDeniedWord($text)
78  {
79  $word_list = $this->getDeniedWordList();
80  if(!count($word_list)) return new BaseObject();
81 
82  $count = count($word_list);
83  for($i=0;$i<$count;$i++)
84  {
85  $word = $word_list[$i]->word;
86  if(preg_match('/'.preg_quote($word,'/').'/is', $text))
87  {
88  $args->word = $word;
89  $output = executeQuery('spamfilter.updateDeniedWordHit', $args);
90  return new BaseObject(-1,sprintf(Context::getLang('msg_alert_denied_word'), $word));
91  }
92  }
93 
94  return new BaseObject();
95  }
96 
100  function checkLimited($isMessage = FALSE)
101  {
102  $config = $this->getConfig();
103 
104  if($config->limits != 'Y') return new BaseObject();
105  $limit_count = '3';
106  $interval = '10';
107 
108  $count = $this->getLogCount($interval);
109 
110  $ipaddress = $_SERVER['REMOTE_ADDR'];
111  // Ban the IP address if the interval is exceeded
112  if($count>=$limit_count)
113  {
114  $oSpamFilterController = getController('spamfilter');
115  $oSpamFilterController->insertIP($ipaddress, 'AUTO-DENIED : Over limit');
116  return new BaseObject(-1, 'msg_alert_registered_denied_ip');
117  }
118  // If the number of limited posts is not reached, keep creating.
119  if($count)
120  {
121  if($isMessage)
122  {
123  $message = sprintf(Context::getLang('msg_alert_limited_message_by_config'), $interval);
124  }
125  else
126  {
127  $message = sprintf(Context::getLang('msg_alert_limited_by_config'), $interval);
128  }
129 
130  $oSpamFilterController = getController('spamfilter');
131  $oSpamFilterController->insertLog();
132 
133  return new BaseObject(-1, $message);
134  }
135  return new BaseObject();
136  }
137 
142  {
143  $oTrackbackModel = getModel('trackback');
144  $count = $oTrackbackModel->getTrackbackCountByIPAddress($document_srl, $_SERVER['REMOTE_ADDR']);
145  if($count>0) return new BaseObject(-1, 'msg_alert_trackback_denied');
146 
147  return new BaseObject();
148  }
149 
153  function getLogCount($time = 60, $ipaddress='')
154  {
155  if(!$ipaddress) $ipaddress = $_SERVER['REMOTE_ADDR'];
156 
157  $args->ipaddress = $ipaddress;
158  $args->regdate = date("YmdHis", $_SERVER['REQUEST_TIME']-$time);
159  $output = executeQuery('spamfilter.getLogCount', $args);
160  $count = $output->data->count;
161  return $count;
162  }
163 }
164 /* End of file spamfilter.model.php */
165 /* Location: ./modules/spamfilter/spamfilter.model.php */
$oModuleModel
Definition: ko.install.php:236
getController($module_name)
Definition: func.inc.php:90
The Model class of the spamfilter module.
getLogCount($time=60, $ipaddress='')
Return the number of logs recorded within the interval for the specified IPaddress.
isDeniedWord($text)
Check if the text, received as a parameter, is banned or not.
checkLimited($isMessage=FALSE)
Check the specified time.
$output
Definition: ko.install.php:193
The parent class of the spamfilter module.
$args
Definition: ko.install.php:185
$document_srl
Definition: ko.install.php:279
getConfig()
Return the user setting values of the Spam filter module.
getLang($code)
isDeniedIP()
Check if the ipaddress is in the list of banned IP addresses.
getModel($module_name)
Definition: func.inc.php:145
isInsertedTrackback($document_srl)
Check if the trackbacks have already been registered to a particular article.
getDeniedIPList()
Return the list of registered IP addresses which were banned.
init()
Initialization.
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
getDeniedWordList()
Return the list of registered Words which were banned.