source: extensions/AntiAspi/maintain.inc.php @ 28323

Last change on this file since 28323 was 28323, checked in by plg, 10 years ago

huge speed improvement: use a dedicated short-term visit log instead of history table

File size: 1.6 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4class AntiAspi_maintain extends PluginMaintain
5{
6  private $installed = false;
7
8  function __construct($plugin_id)
9  {
10    parent::__construct($plugin_id);
11  }
12
13  function install($plugin_version, &$errors=array())
14  {
15    global $prefixeTable;
16
17    // table antiaspi_ip_ban to store list of banned IP addresses
18    $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'antiaspi_ip_ban";');
19    if (!pwg_db_num_rows($result))
20    {
21      $query = "
22CREATE TABLE " . $prefixeTable . "antiaspi_ip_ban (
23  id int(11) NOT NULL auto_increment,
24  ip char(50) NOT NULL default '',
25  date char(20) NOT NULL default '',
26  PRIMARY KEY (id),
27  KEY ip (ip)
28) ENGINE=MyISAM DEFAULT CHARSET=utf8
29;";
30      pwg_query($query);
31    }
32
33    // table antiaspi_log to store a specific "short-term" log
34    // (ENGINE=MEMORY, specific)
35    $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'antiaspi_log";');
36    if (!pwg_db_num_rows($result))
37    {
38      $query = "
39CREATE TABLE " . $prefixeTable . "antiaspi_log (
40  IP varchar(15) NOT NULL default '',
41  occured_on datetime NOT NULL,
42  image_id mediumint(8) default NULL,
43  category_id smallint(5) default NULL
44) ENGINE=MEMORY DEFAULT CHARSET=utf8
45;";
46      pwg_query($query);
47    }
48
49    $this->installed = true;
50  }
51
52  function activate($plugin_version, &$errors=array())
53  {
54    if (!$this->installed)
55    {
56      $this->install($plugin_version, $errors);
57    }
58  }
59
60  function deactivate()
61  {
62  }
63
64  function uninstall()
65  {
66    global $prefixeTable;
67
68    pwg_query('DROP TABLE '.$prefixeTable.'antiaspi_ip_ban;');
69    pwg_query('DROP TABLE '.$prefixeTable.'antiaspi_log;');
70  }
71}
72?>
Note: See TracBrowser for help on using the repository browser.