PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/system/expressionengine/modules/blacklist/mcp.blacklist.php

https://bitbucket.org/tdevonshire/hoolux
PHP | 805 lines | 522 code | 150 blank | 133 comment | 95 complexity | 3a9f63032689dc3385f567449821d189 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2012, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Blacklist Module
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Modules
  19. * @category Modules
  20. * @author EllisLab Dev Team
  21. * @link http://ellislab.com
  22. */
  23. class Blacklist_mcp {
  24. var $value = '';
  25. var $LB = "\r\n";
  26. /**
  27. * Constructor
  28. *
  29. * @access public
  30. */
  31. function Blacklist_mcp( $switch = TRUE )
  32. {
  33. // Make a local reference to the ExpressionEngine super object
  34. $this->EE =& get_instance();
  35. $this->EE->load->dbforge();
  36. $this->EE->load->helper('form');
  37. // Updates
  38. $this->EE->db->select('module_version');
  39. $query = $this->EE->db->get_where('modules', array('module_name' => 'Blacklist'));
  40. if ($query->num_rows() > 0)
  41. {
  42. if ( ! $this->EE->db->table_exists('whitelisted'))
  43. {
  44. $fields = array(
  45. 'whitelisted_type' => array(
  46. 'type' => 'varchar',
  47. 'constraint' => '20',
  48. ),
  49. 'whitelisted_value' => array(
  50. 'type' => 'text'
  51. )
  52. );
  53. $this->EE->dbforge->add_field($fields);
  54. $this->EE->dbforge->create_table('whitelisted');
  55. }
  56. }
  57. }
  58. // --------------------------------------------------------------------
  59. /**
  60. * Blacklist Homepage
  61. *
  62. * @access public
  63. * @return string
  64. */
  65. function index()
  66. {
  67. $vars['license_number'] = $this->EE->config->item('license_number');
  68. $vars['cp_page_title'] = lang('blacklist_module_name');
  69. $vars['allow_write_htaccess'] = FALSE; // overwritten below if admin
  70. if ($this->EE->session->userdata('group_id') == '1')
  71. {
  72. $vars['allow_write_htaccess'] = TRUE;
  73. $htaccess_path = $this->EE->config->item('htaccess_path');
  74. $vars['htaccess_path'] = $htaccess_path;
  75. }
  76. return $this->EE->load->view('index', $vars, TRUE);
  77. }
  78. // --------------------------------------------------------------------
  79. /**
  80. * Write .htaccess File
  81. *
  82. * @access public
  83. * @return void
  84. */
  85. function save_htaccess_path()
  86. {
  87. if ($this->EE->session->userdata('group_id') != '1' OR $this->EE->input->get_post('htaccess_path') === FALSE OR ($this->EE->input->get_post('htaccess_path') == '' && $this->EE->config->item('htaccess_path') === FALSE))
  88. {
  89. $this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=blacklist');
  90. }
  91. $this->EE->load->library('form_validation');
  92. $this->EE->form_validation->set_rules('htaccess_path', 'lang:htaccess_path', 'callback__check_path');
  93. $this->EE->form_validation->set_error_delimiters('<br /><span class="notice">', '<br />');
  94. if ($this->EE->form_validation->run() === FALSE)
  95. {
  96. return $this->index();
  97. }
  98. $this->EE->config->_update_config(array('htaccess_path' => $this->EE->input->get_post('htaccess_path')));
  99. if ($this->EE->input->get_post('htaccess_path') == '' && ! $this->EE->config->item('htaccess_path'))
  100. {
  101. $this->EE->session->set_flashdata('message_success', lang('htaccess_path_removed'));
  102. $this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=blacklist');
  103. }
  104. $this->write_htaccess($this->EE->input->get_post('htaccess_path'));
  105. $this->EE->session->set_flashdata('message_success', lang('htaccess_written_successfully'));
  106. $this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=blacklist');
  107. }
  108. function _check_path($str)
  109. {
  110. if ($str == '')
  111. {
  112. return TRUE;
  113. }
  114. if ( ! file_exists($str) OR ! is_file($str))
  115. {
  116. $this->EE->form_validation->set_message('_check_path', lang('invalid_htaccess_path'));
  117. return FALSE;
  118. }
  119. elseif (! is_writeable($this->EE->input->get_post('htaccess_path')))
  120. {
  121. $this->EE->form_validation->set_message('_check_path', lang('invalid_htaccess_path'));
  122. return FALSE;
  123. }
  124. return TRUE;
  125. }
  126. // --------------------------------------------------------------------
  127. /**
  128. * Write .htaccess File
  129. *
  130. * @access public
  131. * @return void
  132. */
  133. function write_htaccess($htaccess_path = '', $return = 'redirect')
  134. {
  135. $htaccess_path = ($htaccess_path == '') ? $this->EE->config->item('htaccess_path') : $htaccess_path;
  136. if ($this->EE->session->userdata('group_id') != '1' OR $htaccess_path == '')
  137. {
  138. $this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=blacklist');
  139. }
  140. if ( ! $fp = @fopen($htaccess_path, FOPEN_READ))
  141. {
  142. if ($return == 'bool')
  143. {
  144. return FALSE;
  145. }
  146. show_error(lang('invalid_htaccess_path'));
  147. }
  148. flock($fp, LOCK_SH);
  149. $data = @fread($fp, filesize($htaccess_path));
  150. flock($fp, LOCK_UN);
  151. fclose($fp);
  152. if (preg_match("/##EE Spam Block(.*?)##End EE Spam Block/s", $data, $match))
  153. {
  154. $data = str_replace($match['0'], '', $data);
  155. }
  156. $data = trim($data);
  157. // Current Blacklisted
  158. $query = $this->EE->db->get('blacklisted');
  159. $old['url'] = array();
  160. $old['agent'] = array();
  161. $old['ip'] = array();
  162. if ($query->num_rows() > 0)
  163. {
  164. foreach($query->result_array() as $row)
  165. {
  166. $old_values = explode('|',trim($row['blacklisted_value']));
  167. for ($i=0, $s = count($old_values); $i < $s; $i++)
  168. {
  169. if (trim($old_values[$i]) != '')
  170. {
  171. $old[$row['blacklisted_type']][] = preg_quote($old_values[$i]);
  172. }
  173. }
  174. }
  175. }
  176. // EE currently uses URLs and IPs
  177. $urls = '';
  178. while(count($old['url']) > 0)
  179. {
  180. $urls .= 'SetEnvIfNoCase Referer ".*('.trim(implode('|', array_slice($old['url'], 0, 50))).').*" BadRef'.$this->LB;
  181. $old['url'] = array_slice($old['url'], 50);
  182. }
  183. $ips = '';
  184. while(count($old['ip']) > 0)
  185. {
  186. $ips .= 'SetEnvIfNoCase REMOTE_ADDR "^('.trim(implode('|', array_slice($old['ip'], 0, 50))).').*" BadIP'.$this->LB;
  187. $old['ip'] = array_slice($old['ip'], 50);
  188. }
  189. $site = parse_url($this->EE->config->item('site_url'));
  190. $domain = ( ! $this->EE->config->item('cookie_domain')) ? '' : 'SetEnvIfNoCase Referer ".*('.preg_quote($this->EE->config->item('cookie_domain')).').*" GoodHost'.$this->LB;
  191. $domain .= 'SetEnvIfNoCase Referer "^$" GoodHost'.$this->LB; // If no referrer, they be safe!
  192. $host = 'SetEnvIfNoCase Referer ".*('.preg_quote($site['host']).').*" GoodHost'.$this->LB;
  193. if ($urls != '' OR $ips != '')
  194. {
  195. $data .= $this->LB.$this->LB."##EE Spam Block".$this->LB
  196. . $urls
  197. . $ips
  198. . $domain
  199. . $host
  200. . "order deny,allow".$this->LB
  201. . "deny from env=BadRef".$this->LB
  202. . "deny from env=BadIP".$this->LB
  203. . "allow from env=GoodHost".$this->LB
  204. ."##End EE Spam Block".$this->LB.$this->LB;
  205. }
  206. if ( ! $fp = @fopen($htaccess_path, FOPEN_WRITE_CREATE_DESTRUCTIVE))
  207. {
  208. show_error(lang('invalid_htaccess_path'));
  209. }
  210. flock($fp, LOCK_EX);
  211. fwrite($fp, $data);
  212. flock($fp, LOCK_UN);
  213. fclose($fp);
  214. return TRUE;
  215. }
  216. // --------------------------------------------------------------------
  217. /**
  218. * Update Blacklist
  219. *
  220. * @access public
  221. * @return string
  222. */
  223. function ee_blacklist()
  224. {
  225. return $this->_download_update_list('black');
  226. }
  227. // --------------------------------------------------------------------
  228. /**
  229. * Update Whitelist
  230. *
  231. * @access public
  232. * @return string
  233. */
  234. function ee_whitelist()
  235. {
  236. return $this->_download_update_list('white');
  237. }
  238. // --------------------------------------------------------------------
  239. /**
  240. * View Blacklisted
  241. *
  242. * @access public
  243. * @return string
  244. */
  245. function view_blacklist()
  246. {
  247. $vars = $this->_view_list('black');
  248. return $this->EE->load->view('view', $vars, TRUE);
  249. }
  250. // --------------------------------------------------------------------
  251. /**
  252. * View Whitelisted
  253. *
  254. * @access public
  255. * @return string
  256. */
  257. function view_whitelist()
  258. {
  259. $vars = $this->_view_list('white');
  260. return $this->EE->load->view('view', $vars, TRUE);
  261. }
  262. // --------------------------------------------------------------------
  263. /**
  264. * Update Blacklisted Items
  265. *
  266. * @access public
  267. * @return void
  268. */
  269. function update_blacklist($additions = array(), $write = FALSE, $return = 'redirect')
  270. {
  271. if ( ! $this->EE->db->table_exists('blacklisted'))
  272. {
  273. show_error(lang('ref_no_blacklist_table'));
  274. }
  275. $write_htaccess = ($write) ? $write : $this->EE->input->get_post('write_htaccess');
  276. // Current Blacklisted
  277. $query = $this->EE->db->get('blacklisted');
  278. $old['url'] = array();
  279. $old['agent'] = array();
  280. $old['ip'] = array();
  281. $use_post = TRUE;
  282. if ($query->num_rows() > 0)
  283. {
  284. foreach($query->result_array() as $row)
  285. {
  286. $old_values = explode('|',$row['blacklisted_value']);
  287. for ($i=0; $i < count($old_values); $i++)
  288. {
  289. $old[$row['blacklisted_type']][] = $old_values[$i];
  290. }
  291. }
  292. }
  293. // Current Whitelisted
  294. $query = $this->EE->db->get('whitelisted');
  295. $white['url'] = array();
  296. $white['agent'] = array();
  297. $white['ip'] = array();
  298. if ($query->num_rows() > 0)
  299. {
  300. foreach($query->result_array() as $row)
  301. {
  302. $white_values = explode('|',$row['whitelisted_value']);
  303. for ($i=0; $i < count($white_values); $i++)
  304. {
  305. if (trim($white_values[$i]) != '')
  306. {
  307. $white[$row['whitelisted_type']][] = $this->EE->db->escape_str($white_values[$i]);
  308. }
  309. }
  310. }
  311. }
  312. // Update Blacklist with New Values sans Whitelist Matches
  313. $default = array('ip', 'agent', 'url');
  314. $modified_channels = array();
  315. if (count($additions) > 0)
  316. {
  317. $use_post = FALSE;
  318. $new_data['agent'] = (isset($additions['agent'])) ? array_merge($old['agent'], $additions['agent']) : $old['agent'];
  319. $new_data['url'] = (isset($additions['url'])) ? array_merge($old['url'], $additions['url']) : $old['url'];
  320. $new_data['ip'] = (isset($additions['ip'])) ? array_merge($old['ip'], $additions['ip']) : array();
  321. }
  322. foreach ($default as $val)
  323. {
  324. if (isset($_POST[$val]))
  325. {
  326. $_POST[$val] = str_replace('[-]', '', $_POST[$val]);
  327. $_POST[$val] = str_replace('[+]', '', $_POST[$val]);
  328. $_POST[$val] = trim(stripslashes($_POST[$val]));
  329. $new_values = explode(NL,strip_tags($_POST[$val]));
  330. }
  331. elseif (isset($new_data[$val]))
  332. {
  333. $new_values = $new_data[$val];
  334. }
  335. else
  336. {
  337. continue;
  338. }
  339. // Clean out user mistakes; and
  340. // Clean out Referrers with new additions
  341. foreach ($new_values as $key => $this->value)
  342. {
  343. if (trim($this->value) == "" OR trim($this->value) == NL)
  344. {
  345. unset($new_values[$key]);
  346. }
  347. elseif ( ! in_array($this->value, $old[$val]))
  348. {
  349. $name = ($val == 'url') ? 'from' : $val;
  350. if ($this->EE->db->table_exists('referrers'))
  351. {
  352. $this->EE->db->like('ref_'.$name, $this->value);
  353. foreach ($white[$val] as $w_value)
  354. {
  355. $this->EE->db->not_like('ref_'.$name, $w_value);
  356. }
  357. $this->EE->db->delete('referrers');
  358. }
  359. }
  360. if ($val == 'ip')
  361. {
  362. // Collapse IPv6 addresses
  363. if ($this->EE->input->valid_ip($this->value, 'ipv6'))
  364. {
  365. $new_values[$key] = inet_ntop(inet_pton($this->value));
  366. }
  367. }
  368. }
  369. sort($new_values);
  370. $_POST[$val] = implode("|", array_unique($new_values));
  371. $this->EE->db->where('blacklisted_type', $val);
  372. $this->EE->db->delete('blacklisted');
  373. $data = array(
  374. 'blacklisted_type' => $val,
  375. 'blacklisted_value' => $_POST[$val]
  376. );
  377. $this->EE->db->insert('blacklisted', $data);
  378. }
  379. if ($write_htaccess == 'y')
  380. {
  381. $this->write_htaccess();
  382. }
  383. if ($return == 'bool')
  384. {
  385. return TRUE;
  386. }
  387. $this->EE->session->set_flashdata('message_success', lang('blacklist_updated'));
  388. $this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'
  389. .AMP.'module=blacklist'.AMP.'method=view_blacklist');
  390. }
  391. // --------------------------------------------------------------------
  392. /**
  393. * Update Whitelisted Items
  394. *
  395. * @access public
  396. * @return void
  397. */
  398. function update_whitelist()
  399. {
  400. if ( ! $this->EE->db->table_exists('whitelisted'))
  401. {
  402. show_error(lang('ref_no_whitelist_table'));
  403. }
  404. // Current Whitelisted
  405. $query = $this->EE->db->get('whitelisted');
  406. $old['url'] = array();
  407. $old['agent'] = array();
  408. $old['ip'] = array();
  409. if ($query->num_rows() > 0)
  410. {
  411. foreach($query->result_array() as $row)
  412. {
  413. $old_values = explode('|',$row['whitelisted_value']);
  414. for ($i=0; $i < count($old_values); $i++)
  415. {
  416. $old[$row['whitelisted_type']][] = $old_values[$i];
  417. }
  418. }
  419. }
  420. // Update Whitelist with New Values
  421. $default = array('ip', 'agent', 'url');
  422. foreach ($default as $val)
  423. {
  424. if (isset($_POST[$val]))
  425. {
  426. $_POST[$val] = str_replace('[-]', '', $_POST[$val]);
  427. $_POST[$val] = str_replace('[+]', '', $_POST[$val]);
  428. $_POST[$val] = trim(stripslashes($_POST[$val]));
  429. $new_values = explode(NL,strip_tags($_POST[$val]));
  430. // Clean out user mistakes; and
  431. // Clean out Whitelists with new additions
  432. foreach ($new_values as $key => $value)
  433. {
  434. if (trim($value) == "" OR trim($value) == NL)
  435. {
  436. unset($new_values[$key]);
  437. }
  438. if ($val == 'ip')
  439. {
  440. // Collapse IPv6 addresses
  441. if ($this->EE->input->valid_ip($value, 'ipv6'))
  442. {
  443. $new_values[$key] = inet_ntop(inet_pton($value));
  444. }
  445. }
  446. }
  447. $_POST[$val] = implode("|",$new_values);
  448. $this->EE->db->where('whitelisted_type', $val);
  449. $this->EE->db->delete('whitelisted');
  450. $data = array(
  451. 'whitelisted_type' => $val,
  452. 'whitelisted_value' => $_POST[$val]
  453. );
  454. $this->EE->db->insert('whitelisted', $data);
  455. }
  456. }
  457. $this->EE->session->set_flashdata('message_success', lang('whitelist_updated'));
  458. $this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP
  459. .'module=blacklist'.AMP.'method=view_whitelist');
  460. }
  461. // --------------------------------------------------------------------
  462. /**
  463. * Download and update ExpressionEngine.com Black- or Whitelist
  464. *
  465. * @access private
  466. * @return string
  467. */
  468. function _download_update_list($listtype = "black")
  469. {
  470. $vars['cp_page_title'] = lang('blacklist_module_name'); // both black and white lists share this title
  471. if ( ! $this->EE->db->table_exists("{$listtype}listed"))
  472. {
  473. show_error(lang("ref_no_{$listtype}list_table"));
  474. }
  475. if ( ! $license = $this->EE->config->item('license_number'))
  476. {
  477. show_error(lang('ref_no_license'));
  478. }
  479. // Get Current List from ExpressionEngine.com
  480. $this->EE->load->library('xmlrpc');
  481. $this->EE->xmlrpc->server('http://ping.expressionengine.com/index.php', 80);
  482. $this->EE->xmlrpc->method("ExpressionEngine.{$listtype}list");
  483. $this->EE->xmlrpc->request(array($license));
  484. if ($this->EE->xmlrpc->send_request() === FALSE)
  485. {
  486. // show the error and stop
  487. $vars['message'] = lang("ref_{$listtype}list_irretrievable").BR.BR.$this->EE->xmlrpc->display_error();
  488. return $this->EE->load->view('update', $vars, TRUE);
  489. }
  490. // Array of our returned info
  491. $remote_info = $this->EE->xmlrpc->display_response();
  492. $new['url'] = ( ! isset($remote_info['urls']) OR count($remote_info['urls']) == 0) ? array() : explode('|',$remote_info['urls']);
  493. $new['agent'] = ( ! isset($remote_info['agents']) OR count($remote_info['agents']) == 0) ? array() : explode('|',$remote_info['agents']);
  494. $new['ip'] = ( ! isset($remote_info['ips']) OR count($remote_info['ips']) == 0) ? array() : explode('|',$remote_info['ips']);
  495. // Add current list
  496. $query = $this->EE->db->get("{$listtype}listed");
  497. $old['url'] = array();
  498. $old['agent'] = array();
  499. $old['ip'] = array();
  500. if ($query->num_rows() > 0)
  501. {
  502. foreach($query->result_array() as $row)
  503. {
  504. $old_values = explode('|',$row["{$listtype}listed_value"]);
  505. for ($i=0; $i < count($old_values); $i++)
  506. {
  507. $old[$row["{$listtype}listed_type"]][] = $old_values[$i];
  508. }
  509. }
  510. }
  511. // Current listed
  512. $query = $this->EE->db->get('whitelisted');
  513. $white['url'] = array();
  514. $white['agent'] = array();
  515. $white['ip'] = array();
  516. if ($query->num_rows() > 0)
  517. {
  518. foreach($query->result_array() as $row)
  519. {
  520. $white_values = explode('|',$row['whitelisted_value']);
  521. for ($i=0; $i < count($white_values); $i++)
  522. {
  523. if (trim($white_values[$i]) != '')
  524. {
  525. $white[$row['whitelisted_type']][] = $white_values[$i];
  526. }
  527. }
  528. }
  529. }
  530. // Check for uniqueness and sort
  531. $new['url'] = array_unique(array_merge($old['url'],$new['url']));
  532. $new['agent'] = array_unique(array_merge($old['agent'],$new['agent']));
  533. $new['ip'] = array_unique(array_merge($old['ip'],$new['ip']));
  534. sort($new['url']);
  535. sort($new['agent']);
  536. sort($new['ip']);
  537. // Put blacklist info back into database
  538. $this->EE->db->truncate("{$listtype}listed");
  539. foreach($new as $key => $value)
  540. {
  541. $listed_value = implode('|',$value);
  542. $data = array(
  543. "{$listtype}listed_type" => $key,
  544. "{$listtype}listed_value" => $listed_value
  545. );
  546. $this->EE->db->insert("{$listtype}listed", $data);
  547. }
  548. if ($listtype == 'white')
  549. {
  550. // If this is a whitelist update, we're done, send data to view and get out
  551. $this->EE->session->set_flashdata('message_success', lang('whitelist_updated'));
  552. $this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=blacklist');
  553. }
  554. // Using new blacklist members, clean out spam
  555. $new['url'] = array_diff($new['url'], $old['url']);
  556. $new['agent'] = array_diff($new['agent'], $old['agent']);
  557. $new['ip'] = array_diff($new['ip'], $old['ip']);
  558. $modified_channels = array();
  559. foreach($new as $key => $value)
  560. {
  561. sort($value);
  562. $name = ($key == 'url') ? 'from' : $key;
  563. if (count($value) > 0)
  564. {
  565. for($i=0; $i < count($value); $i++)
  566. {
  567. if ($value[$i] != '')
  568. {
  569. if ($this->EE->db->table_exists('referrers'))
  570. {
  571. $this->EE->db->like('ref_'.$name, $value[$i]);
  572. foreach ($white[$key] as $w_value)
  573. {
  574. $this->EE->db->not_like('ref_'.$name, $w_value);
  575. }
  576. $this->EE->db->delete('referrers');
  577. }
  578. }
  579. }
  580. }
  581. }
  582. // Blacklist updated message
  583. $vars['message'] = lang('blacklist_updated');
  584. $vars['form_hidden']['write_htaccess'] = 'n'; // over-ridden below if needed
  585. if ($this->EE->session->userdata('group_id') == '1' && $this->EE->config->item('htaccess_path') === FALSE)
  586. {
  587. $vars['use_htaccess'] = TRUE;
  588. $vars['form_action'] = 'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=blacklist'.AMP.'method=write_htaccess';
  589. $vars['form_hidden']['htaccess_path'] = $this->EE->config->item('htaccess_path');
  590. $vars['form_hidden']['write_htaccess'] = 'y';
  591. }
  592. else
  593. {
  594. $this->EE->session->set_flashdata('message_success', lang('blacklist_updated'));
  595. $this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=blacklist');
  596. }
  597. return $this->EE->load->view('update', $vars, TRUE);
  598. }
  599. // --------------------------------------------------------------------
  600. /**
  601. * View List
  602. *
  603. * @access private
  604. * @return mixed
  605. */
  606. function _view_list($black_or_white = 'black')
  607. {
  608. if ( ! $this->EE->db->table_exists("{$black_or_white}listed"))
  609. {
  610. show_error(lang("ref_no_{$black_or_white}list_table"));
  611. }
  612. $vars['cp_page_title'] = lang("ref_view_{$black_or_white}list");
  613. $this->EE->cp->set_breadcrumb(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=blacklist', lang('blacklist_module_name'));
  614. $this->EE->load->helper('form');
  615. $rows = array();
  616. $default = array('ip', 'url','agent');
  617. foreach ($default as $value)
  618. {
  619. $rows[$value] = '';
  620. }
  621. // Store by type with | between values
  622. $this->EE->db->order_by("{$black_or_white}listed_type", 'asc');
  623. $query = $this->EE->db->get("{$black_or_white}listed");
  624. if ($query->num_rows() != 0)
  625. {
  626. foreach($query->result_array() as $row)
  627. {
  628. $rows[$row["{$black_or_white}listed_type"]] = $row["{$black_or_white}listed_value"];
  629. }
  630. }
  631. $vars['form_action'] = 'C=addons_modules'.AMP.'M=show_module_cp'.AMP."module=blacklist".AMP."method=update_{$black_or_white}list";
  632. //sort($rows);
  633. foreach($rows as $key => $value)
  634. {
  635. $vars['list_item'][$key]['name'] = $key;
  636. $vars['list_item'][$key]['id'] = $key;
  637. $vars['list_item'][$key]['value'] = str_replace('|',NL,$value);
  638. $vars['list_item'][$key]['class'] = 'module_textarea shun';
  639. }
  640. if ($this->EE->session->userdata('group_id') == '1' && $this->EE->config->item('htaccess_path') != '' && $black_or_white == 'black')
  641. {
  642. $vars['form_hidden']['htaccess_path'] = $this->EE->config->item('htaccess_path');
  643. $vars['write_to_htaccess'] = TRUE;
  644. }
  645. else
  646. {
  647. $vars['form_hidden']['htaccess_path'] = ''; // empty value for the view
  648. $vars['write_to_htaccess'] = FALSE;
  649. }
  650. return $vars;
  651. }
  652. }
  653. // END CLASS
  654. /* End of file mcp.blacklist.php */
  655. /* Location: ./system/expressionengine/modules/blacklist/mcp.blacklist.php */