123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- /**
- * @file
- * Install, update and uninstall functions for the Honeypot module.
- */
- /**
- * Implements hook_schema().
- */
- function honeypot_schema() {
- $schema['honeypot_user'] = array(
- 'description' => 'Table that stores failed attempts to submit a form.',
- 'fields' => array(
- 'uid' => array(
- 'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'hostname' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'description' => 'Hostname of user that that triggered honeypot.',
- ),
- 'timestamp' => array(
- 'description' => 'Date/time when the form submission failed, as Unix timestamp.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- ),
- 'indexes' => array(
- 'uid' => array('uid'),
- 'timestamp' => array('timestamp'),
- ),
- );
- return $schema;
- }
- /**
- * Implements hook_install().
- */
- function honeypot_install() {
- // Create CSS file.
- honeypot_create_css(variable_get('honeypot_element_name', 'url'));
- if (!drupal_is_cli()) {
- $t = get_t();
- drupal_set_message($t("Honeypot installed successfully. Please !link to protect your forms from spam bots.", array(
- '!link' => l($t('configure Honeypot'), 'admin/config/content/honeypot'),
- )));
- }
- }
- /**
- * Implements hook_uninstall().
- */
- function honeypot_uninstall() {
- db_delete('variable')
- ->condition('name', db_like('honeypot_') . '%', 'LIKE')
- ->execute();
- $cache_tables = array('variables', 'cache_bootstrap');
- foreach ($cache_tables as $table) {
- if (db_table_exists($table)) {
- cache_clear_all($table, 'cache');
- }
- }
- // Delete 'honeypot' directory from public file directory.
- file_unmanaged_delete_recursive('public://honeypot');
- }
- /**
- * Implements hook_update_N().
- */
- function honeypot_update_7001() {
- $ret = array();
- // Leaving this in because I had it in version 1.3. Silly me.
- return $ret;
- }
- /**
- * Update form names after upgrade from 6.x version.
- */
- function honeypot_update_7002() {
- $map = array(
- 'user_register' => 'user_register_form',
- 'contact_mail_page' => 'contact_site_form',
- 'contact_mail_user' => 'contact_personal_form',
- );
- foreach ($map as $d6_name => $d7_name) {
- $value = variable_get('honeypot_form_' . $d6_name, 0);
- if ($value) {
- variable_set('honeypot_form_' . $d7_name, $value);
- }
- variable_del('honeypot_form_' . $d6_name);
- }
- $comment_form_value = variable_get('honeypot_form_comment_form', 0);
- if ($comment_form_value) {
- $types = node_type_get_types();
- if (!empty($types)) {
- foreach ($types as $type) {
- $d7_name = 'honeypot_form_comment_node_' . $type->type . '_form';
- variable_set($d7_name, $comment_form_value);
- }
- }
- }
- variable_del('honeypot_form_comment_form');
- }
- /**
- * Add {honeypot_users} database table if it doesn't exist.
- */
- function honeypot_update_7003() {
- // Make sure the {honeypot_users} table doesn't already exist.
- if (!db_table_exists('honeypot_user')) {
- $table = array(
- 'description' => 'Table that stores failed attempts to submit a form.',
- 'fields' => array(
- 'uid' => array(
- 'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'timestamp' => array(
- 'description' => 'Date/time when the form submission failed, as Unix timestamp.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- ),
- 'indexes' => array(
- 'uid' => array('uid'),
- 'timestamp' => array('timestamp'),
- ),
- );
- db_create_table('honeypot_user', $table);
- }
- }
- /**
- * Create Honeypot CSS file.
- */
- function honeypot_update_7004() {
- drupal_load('module', 'honeypot');
- module_load_include('inc', 'honeypot', 'honeypot.admin');
- honeypot_create_css(variable_get('honeypot_element_name', 'url'));
- }
- /**
- * Adds the 'hostname' column to the {honeypot_user} table.
- */
- function honeypot_update_7100() {
- $schema = honeypot_schema();
- $spec = $schema['honeypot_user']['fields']['hostname'];
- $spec['initial'] = '';
- db_add_field('honeypot_user', 'hostname', $spec);
- }
- /**
- * Transfer previous honeypot trigger info from {flood} to {honeypot_user}.
- */
- function honeypot_update_7101() {
- // Move all 'honeypot' events, which are honeypot captures for anonymous
- // users, to the {honeypot_user}-table, since the latter now supports
- // tracking based on ip/hostname for anonymous users.
- $query = db_select('flood', 'f')
- ->condition('event', 'honeypot');
- $query->addExpression('0', 'uid');
- $query->addField('f', 'identifier', 'hostname');
- $query->addField('f', 'timestamp');
- db_insert('honeypot_user')
- ->from($query)
- ->execute();
- // Clean up the flood table by removing our events, since we are no longer
- // relying on the flood mechanism to track anonymous honeypot captures.
- flood_clear_event('honeypot');
- }
|