1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | class AntiAspi_maintain extends PluginMaintain |
---|
5 | { |
---|
6 | private $default_conf = array( |
---|
7 | 'diff' => '20 pages in 00:00:10', |
---|
8 | 'same' => '15 pages in 00:00:30', |
---|
9 | 'banned during' => '23:59:59', |
---|
10 | 'only guest' => true, |
---|
11 | 'only picture' => false, |
---|
12 | 'allowed ip' => array('123.123.123.123','122.122.122.122'), |
---|
13 | ); |
---|
14 | |
---|
15 | function install($plugin_version, &$errors=array()) |
---|
16 | { |
---|
17 | global $prefixeTable, $conf; |
---|
18 | |
---|
19 | // add config parameter |
---|
20 | if (empty($conf['antiaspi'])) |
---|
21 | { |
---|
22 | conf_update_param('antiaspi', $this->default_conf, true); |
---|
23 | } |
---|
24 | else |
---|
25 | { |
---|
26 | $old_conf = safe_unserialize($conf['antiaspi']); |
---|
27 | |
---|
28 | foreach (array_keys($this->default_conf) as $conf_key) |
---|
29 | { |
---|
30 | if (!isset($old_conf[$conf_key])) |
---|
31 | { |
---|
32 | $old_conf[$conf_key] = $this->default_conf[$conf_key]; |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | conf_update_param('antiaspi', $old_conf, true); |
---|
37 | } |
---|
38 | |
---|
39 | // table antiaspi_ip_ban to store list of banned IP addresses |
---|
40 | $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'antiaspi_ip_ban";'); |
---|
41 | if (!pwg_db_num_rows($result)) |
---|
42 | { |
---|
43 | $query = " |
---|
44 | CREATE TABLE " . $prefixeTable . "antiaspi_ip_ban ( |
---|
45 | id int(11) NOT NULL auto_increment, |
---|
46 | ip char(50) NOT NULL default '', |
---|
47 | date char(20) NOT NULL default '', |
---|
48 | PRIMARY KEY (id), |
---|
49 | KEY ip (ip) |
---|
50 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
---|
51 | ;"; |
---|
52 | pwg_query($query); |
---|
53 | } |
---|
54 | |
---|
55 | // table antiaspi_log to store a specific "short-term" log |
---|
56 | // (ENGINE=MEMORY, specific) |
---|
57 | $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'antiaspi_log";'); |
---|
58 | if (!pwg_db_num_rows($result)) |
---|
59 | { |
---|
60 | $query = " |
---|
61 | CREATE TABLE " . $prefixeTable . "antiaspi_log ( |
---|
62 | IP varchar(15) NOT NULL default '', |
---|
63 | occured_on datetime NOT NULL, |
---|
64 | image_id mediumint(8) default NULL, |
---|
65 | category_id smallint(5) default NULL |
---|
66 | ) ENGINE=MEMORY DEFAULT CHARSET=utf8 |
---|
67 | ;"; |
---|
68 | pwg_query($query); |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | function update($old_version, $new_version, &$errors=array()) |
---|
73 | { |
---|
74 | $this->install($new_version, $errors); |
---|
75 | } |
---|
76 | |
---|
77 | function uninstall() |
---|
78 | { |
---|
79 | global $prefixeTable; |
---|
80 | |
---|
81 | pwg_query('DROP TABLE '.$prefixeTable.'antiaspi_ip_ban;'); |
---|
82 | pwg_query('DROP TABLE '.$prefixeTable.'antiaspi_log;'); |
---|
83 | |
---|
84 | // delete configuration |
---|
85 | pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN ("antiaspi");'); |
---|
86 | } |
---|
87 | } |
---|