| 1 |
<?php |
<?php |
| 2 |
// $Id: captcha.install,v 1.1.4.6 2007/10/02 19:21:20 robloach Exp $ |
// $Id: badbehavior.install,v 1.1.4.2 2008/04/07 15:23:50 wilco Exp $ |
| 3 |
|
|
|
/** |
|
|
* Implementation of hook_install(). |
|
|
*/ |
|
| 4 |
function badbehavior_install() { |
function badbehavior_install() { |
| 5 |
if (!is_dir(BB2_CWD .'/bad-behavior')) { |
drupal_install_schema('badbehavior'); |
| 6 |
drupal_set_message(t('Bad Behavior directory not found. Please consult badbehavior/README.txt for details.'), 'error'); |
} |
| 7 |
|
|
| 8 |
|
function badbehavior_schema() { |
| 9 |
|
$schema['bad_behavior_log'] = array( |
| 10 |
|
'description' => t('Stores hit logs for the Bad Behavior module.'), |
| 11 |
|
'fields' => array( |
| 12 |
|
'id' => array('type' => 'serial', 'disp-width' => 11, 'not null' => TRUE), |
| 13 |
|
'ip' => array('type' => 'text', 'not null' => TRUE), |
| 14 |
|
'date' => array('type' => 'datetime', 'not null' => TRUE, 'default' => '0000-00-00 00:00:00'), |
| 15 |
|
'request_method' => array('type' => 'text', 'not null' => TRUE), |
| 16 |
|
'request_uri' => array('type' => 'text', 'not null' => TRUE), |
| 17 |
|
'server_protocol' => array('type' => 'text', 'not null' => TRUE), |
| 18 |
|
'http_headers' => array('type' => 'text', 'not null' => TRUE), |
| 19 |
|
'user_agent' => array('type' => 'text', 'not null' => TRUE), |
| 20 |
|
'request_entity' => array('type' => 'text', 'not null' => TRUE), |
| 21 |
|
'key' => array('type' => 'text', 'not null' => TRUE), |
| 22 |
|
), |
| 23 |
|
'primary key' => array('id'), |
| 24 |
|
'indexes' => array( |
| 25 |
|
'ip' => array(array('ip', 15)), |
| 26 |
|
'user_agent' => array(array('user_agent', 10)), |
| 27 |
|
), |
| 28 |
|
); |
| 29 |
|
|
| 30 |
|
return $schema; |
| 31 |
|
} |
| 32 |
|
|
| 33 |
|
function badbehavior_requirements($phase) { |
| 34 |
|
$requirements = array(); |
| 35 |
|
if ($phase == 'runtime') { |
| 36 |
|
if (!is_dir(BB2_CWD .'/bad-behavior')) { |
| 37 |
|
$requirements['badbehavior'] = array( |
| 38 |
|
'value' => t('Directory error'), |
| 39 |
|
'severity' => REQUIREMENT_ERROR, |
| 40 |
|
'description' => t('Bad Behavior directory not found. Please consult badbehavior/README.txt for details.'), |
| 41 |
|
); |
| 42 |
|
} |
| 43 |
|
else { |
| 44 |
|
// bad-behavior directory is present, so check for files; |
| 45 |
|
if (file_exists(BB2_CWD .'/bad-behavior/core.inc.php') && file_exists(BB2_CWD .'/bad-behavior/version.inc.php')) { |
| 46 |
|
$requirements['badbehavior'] = array( |
| 47 |
|
'value' => t('Version: %version is correctly installed', array('%version' => BB2_VERSION)), |
| 48 |
|
'severity' => REQUIREMENT_OK, |
| 49 |
|
); |
| 50 |
|
} |
| 51 |
|
else { |
| 52 |
|
$requirements['badbehavior'] = array( |
| 53 |
|
'value' => t('Files missing'), |
| 54 |
|
'severity' => REQUIREMENT_ERROR, |
| 55 |
|
'description' => t('Required Bad Behavior files are not found. Please consult badbehavior/README.txt for details.'), |
| 56 |
|
); |
| 57 |
|
} |
| 58 |
|
} |
| 59 |
|
$requirements['badbehavior']['title'] = t('Bad Behavior'); |
| 60 |
} |
} |
| 61 |
else { |
return $requirements; |
|
// bad-behavior directory is present, so check for files; |
|
|
if (file_exists(BB2_CWD .'/bad-behavior/core.inc.php') && |
|
|
file_exists(BB2_CWD .'/bad-behavior/version.inc.php')) { |
|
|
switch ($GLOBALS['db_type']) { |
|
|
case 'mysql': |
|
|
case 'mysqli': |
|
|
if (variable_get('badbehavior_db_installed', 0) != BB2_VERSION) { |
|
|
bb2_db_query(bb2_table_structure(db_prefix_tables('{bad_behavior_log}'))); |
|
|
variable_set('badbehavior_db_installed', BB2_VERSION); |
|
|
} |
|
|
/* |
|
|
db_query("CREATE TABLE {bad_behavior_log} ( |
|
|
id INT(11) NOT NULL auto_increment, |
|
|
ip TEXT NOT NULL, |
|
|
date DATETIME NOT NULL default '0000-00-00 00:00:00', |
|
|
request_method TEXT NOT NULL, |
|
|
request_uri TEXT NOT NULL, |
|
|
server_protocol TEXT NOT NULL, |
|
|
http_headers TEXT NOT NULL, |
|
|
user_agent TEXT NOT NULL, |
|
|
request_entity TEXT NOT NULL, |
|
|
key TEXT NOT NULL, |
|
|
INDEX (ip(15)), |
|
|
INDEX (user_agent(10)), |
|
|
PRIMARY KEY (id) |
|
|
);" |
|
|
); |
|
|
*/ |
|
|
drupal_set_message(t('The installation of the badbehavior was successful'), 'status'); |
|
|
break; |
|
|
default: |
|
|
drupal_set_message(t('Unsupported database.'), 'error'); |
|
|
} |
|
|
} else { |
|
|
watchdog('badbehavior', t('The required third-party bad-behavior files are not installed. Please consult badbehavior/README.txt for details.'), WATCHDOG_ERROR); |
|
|
drupal_set_message(t('The required Bad Behavior files are not installed. Please consult badbehavior/README.txt for details.'), 'error'); |
|
|
} |
|
|
} |
|
| 62 |
} |
} |
| 63 |
|
|
|
/** |
|
|
* Implementation of hook_uninstall(). |
|
|
*/ |
|
| 64 |
function badbehavior_uninstall() { |
function badbehavior_uninstall() { |
| 65 |
db_query("DROP TABLE {bad_behavior_log}"); |
drupal_uninstall_schema('badbehavior'); |
|
// Delete all the badbehavior variables and then clear the variable cache |
|
| 66 |
db_query("DELETE FROM {variable} WHERE name LIKE 'badbehavior_%'"); |
db_query("DELETE FROM {variable} WHERE name LIKE 'badbehavior_%'"); |
| 67 |
cache_clear_all('variables', 'cache'); |
cache_clear_all('variables', 'cache'); |
| 68 |
} |
} |