| 1 |
<?php
|
| 2 |
// $Id: troll.install,v 1.6 2009/02/11 18:53:20 deekayen Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* .install file for troll module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_install().
|
| 11 |
*/
|
| 12 |
function troll_install() {
|
| 13 |
drupal_install_schema('troll');
|
| 14 |
|
| 15 |
// Whitelist 127.0.0.1.
|
| 16 |
db_query("INSERT INTO {troll_whitelist} (net, bcast) VALUES (2130706433, 2130706433)");
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Add RBL tables.
|
| 21 |
*/
|
| 22 |
function troll_update_1() {
|
| 23 |
$ret = array();
|
| 24 |
db_create_table($ret, 'troll_blacklist', array(
|
| 25 |
'fields' => array(
|
| 26 |
'net' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '11'),
|
| 27 |
'bcast' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '11')),
|
| 28 |
'unique keys' => array(
|
| 29 |
'net' => array('net', 'bcast'))
|
| 30 |
)
|
| 31 |
);
|
| 32 |
db_create_table($ret, 'troll_whitelist', array(
|
| 33 |
'fields' => array(
|
| 34 |
'net' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '11'),
|
| 35 |
'bcast' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '11')),
|
| 36 |
'unique keys' => array(
|
| 37 |
'net' => array('net', 'bcast'))
|
| 38 |
)
|
| 39 |
);
|
| 40 |
|
| 41 |
$ret[] = update_sql('INSERT INTO {troll_whitelist} (net, bcast) VALUES (2130706433, 2130706433)');
|
| 42 |
return $ret;
|
| 43 |
}
|
| 44 |
|
| 45 |
/**
|
| 46 |
* This update will not run properly under Drupal 6 because _system_update_utf8() does
|
| 47 |
* not exist in Drupal 6.
|
| 48 |
*
|
| 49 |
* See http://drupal.org/node/54614
|
| 50 |
* @return array
|
| 51 |
*/
|
| 52 |
/*
|
| 53 |
function troll_update_2() {
|
| 54 |
return _system_update_utf8(array('troll_blacklist', 'troll_ip_ban', 'troll_ip_track', 'troll_whitelist'));
|
| 55 |
}
|
| 56 |
*/
|
| 57 |
|
| 58 |
/**
|
| 59 |
* Support IPv6 address lengths.
|
| 60 |
*/
|
| 61 |
function troll_update_5000() {
|
| 62 |
$ret = array();
|
| 63 |
|
| 64 |
db_drop_unique_key($ret, 'troll_ip_ban', 'ip');
|
| 65 |
db_change_field($ret, 'troll_ip_ban', 'ip_address', 'ip_address', array('type' => 'varchar', 'length' => '39', 'not null' => TRUE, 'default' => ''));
|
| 66 |
db_add_unique_key($ret, 'troll_ip_ban', 'ip', array('ip_address'));
|
| 67 |
|
| 68 |
db_change_field($ret, 'troll_ip_track', 'ip_address', 'ip_address', array('type' => 'varchar', 'length' => '39', 'not null' => TRUE, 'default' => ''));
|
| 69 |
return $ret;
|
| 70 |
}
|
| 71 |
|
| 72 |
/**
|
| 73 |
* Implementation of hook_uninstall().
|
| 74 |
*/
|
| 75 |
function troll_uninstall() {
|
| 76 |
drupal_uninstall_schema('troll');
|
| 77 |
variable_del('troll_block_role');
|
| 78 |
variable_del('troll_blacklist_stutter');
|
| 79 |
variable_del('troll_blacklist_mod_requests');
|
| 80 |
variable_del('troll_blacklist_alt_page');
|
| 81 |
variable_del('troll_blacklist_alt_url');
|
| 82 |
variable_del('troll_enable_ip_ban');
|
| 83 |
variable_del('troll_ip_ban_redirect');
|
| 84 |
}
|
| 85 |
|
| 86 |
/**
|
| 87 |
* Implementation of hook_schema().
|
| 88 |
*/
|
| 89 |
function troll_schema() {
|
| 90 |
$schema['troll_whitelist'] = array(
|
| 91 |
'fields' => array(
|
| 92 |
'net' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '11'),
|
| 93 |
'bcast' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '11')),
|
| 94 |
'unique keys' => array(
|
| 95 |
'net' => array('net', 'bcast')),
|
| 96 |
);
|
| 97 |
$schema['troll_ip_track'] = array(
|
| 98 |
'fields' => array(
|
| 99 |
'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
|
| 100 |
'accessed' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
|
| 101 |
'ip_address' => array('type' => 'varchar', 'length' => '39', 'not null' => TRUE, 'default' => ''),
|
| 102 |
'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11')),
|
| 103 |
'indexes' => array(
|
| 104 |
'uid' => array('uid')),
|
| 105 |
);
|
| 106 |
$schema['troll_ip_ban'] = array(
|
| 107 |
'fields' => array(
|
| 108 |
'iid' => array('type' => 'serial', 'not null' => TRUE, 'disp-width' => '11'),
|
| 109 |
'ip_address' => array('type' => 'varchar', 'length' => '39', 'not null' => TRUE, 'default' => ''),
|
| 110 |
'domain_name' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
|
| 111 |
'expires' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
|
| 112 |
'created' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
|
| 113 |
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10')),
|
| 114 |
'primary key' => array('iid'),
|
| 115 |
'unique keys' => array(
|
| 116 |
'ip' => array('ip_address')),
|
| 117 |
);
|
| 118 |
$schema['troll_blacklist'] = array(
|
| 119 |
'fields' => array(
|
| 120 |
'net' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '11'),
|
| 121 |
'bcast' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '11')),
|
| 122 |
'unique keys' => array(
|
| 123 |
'net' => array('net', 'bcast')),
|
| 124 |
);
|
| 125 |
|
| 126 |
return $schema;
|
| 127 |
}
|