Spam-accounts verwijderen (Drupal)

Uit De Vliegende Brigade
Ga naar: navigatie, zoeken

Soms had ik sites met duizenden spam-accounts en maar een paar legitieme accounts. Hoe verwijder ik efficient die spam-accounts?

Zonder VBO

Wat waarschijnlijk het antwoord zou zijn: Een View aanmaken waarbij alle accounts zonder orders worden getoond verwijderd kunnen worden. Daar ben ik nog niet. Hoe ik het nu doe:

  • Ik heb een View gemaakt op Users waarin iets uitgebreidere informatie wordt getoond per gebruiker
  • Via PMA bekijk ik de tabel Orders en daar staan de UID's (User IDs) van de betreffende klanten bij
  • Op die manier vind ik snel de legitieme accounts. Die voeg ik toe aan de nieuwe rol Geverifiëerd
  • In het standaard-overzicht van accounts verwijder ik alle accounts die niet de rol Geverifiëerd hebben.

Dit is die View:

$view = new view;
$view->name = 'UsersAndOrders';
$view->description = 'UsersAndOrders';
$view->tag = '';
$view->base_table = 'users';
$view->core = 6;
$view->api_version = '2';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'name' => array(
    'label' => 'Name',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'hide_alter_empty' => 1,
    'link_to_user' => 1,
    'overwrite_anonymous' => 0,
    'anonymous_text' => '',
    'exclude' => 0,
    'id' => 'name',
    'table' => 'users',
    'field' => 'name',
    'relationship' => 'none',
  ),
  'mail' => array(
    'id' => 'mail',
    'table' => 'users',
    'field' => 'mail',
  ),
  'rid' => array(
    'id' => 'rid',
    'table' => 'users_roles',
    'field' => 'rid',
  ),
  'uid' => array(
    'id' => 'uid',
    'table' => 'users',
    'field' => 'uid',
  ),
  'created' => array(
    'label' => 'Created date',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'hide_alter_empty' => 1,
    'date_format' => 'custom',
    'custom_date_format' => 'Y-m-d',
    'exclude' => 0,
    'id' => 'created',
    'table' => 'users',
    'field' => 'created',
    'relationship' => 'none',
  ),
  'access' => array(
    'label' => 'Last access',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'hide_alter_empty' => 1,
    'date_format' => 'custom',
    'custom_date_format' => 'Y-m-d',
    'exclude' => 0,
    'id' => 'access',
    'table' => 'users',
    'field' => 'access',
    'relationship' => 'none',
  ),
  'login' => array(
    'label' => 'Last login',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'hide_alter_empty' => 1,
    'date_format' => 'custom',
    'custom_date_format' => 'Y-m-d',
    'exclude' => 0,
    'id' => 'login',
    'table' => 'users',
    'field' => 'login',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 500);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 1,
  'sticky' => 0,
  'order' => 'asc',
  'summary' => '',
  'columns' => array(
    'name' => 'name',
    'mail' => 'mail',
    'rid' => 'rid',
    'uid' => 'uid',
    'created' => 'created',
    'access' => 'access',
    'login' => 'login',
  ),
  'info' => array(
    'name' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'mail' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'rid' => array(
      'separator' => '',
    ),
    'uid' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'created' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'access' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'login' => array(
      'sortable' => 1,
      'separator' => '',
    ),
  ),
  'default' => '-1',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'Users01');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));

Met VBO

Deze oplossing voor Drupal 6 vereist de Views Bulk Operations-module. De view is beschikbaar op /spamweg:

$view = new view;
$view->name = 'spamaccounts_verwijderen';
$view->description = 'Spamaccount verwijderen';
$view->tag = '';
$view->base_table = 'users';
$view->core = 6;
$view->api_version = '2';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'mail' => array(
    'id' => 'mail',
    'table' => 'users',
    'field' => 'mail',
  ),
  'access' => array(
    'id' => 'access',
    'table' => 'users',
    'field' => 'access',
  ),
  'name' => array(
    'id' => 'name',
    'table' => 'users',
    'field' => 'name',
  ),
  'rid' => array(
    'id' => 'rid',
    'table' => 'users_roles',
    'field' => 'rid',
  ),
));
$handler->override_option('filters', array(
  'rid' => array(
    'operator' => 'not',
    'value' => array(
      4 => '4',
      5 => '5',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'rid',
    'table' => 'users_roles',
    'field' => 'rid',
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('style_plugin', 'bulk');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 1,
  'sticky' => 0,
  'order' => 'asc',
  'summary' => '',
  'columns' => array(
    'mail' => 'mail',
    'access' => 'access',
    'name' => 'name',
    'rid' => 'rid',
  ),
  'info' => array(
    'mail' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'access' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'name' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'rid' => array(
      'separator' => '',
    ),
  ),
  'default' => '-1',
  'execution_type' => '1',
  'max_performance' => 0,
  'display_type' => '0',
  'hide_selector' => 0,
  'preserve_selection' => 1,
  'display_result' => 1,
  'merge_single_action' => 1,
  'operations' => array(
    'user_block_ip_action' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'user_block_user_action' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'user_user_operations_block' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'views_bulk_operations_delete_user_action' => array(
      'selected' => 1,
      'skip_confirmation' => 1,
      'label' => '',
    ),
    'system_message_action' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'views_bulk_operations_action' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'views_bulk_operations_script_action' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'views_bulk_operations_user_roles_action' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'views_bulk_operations_argument_selector_action' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'system_goto_action' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'system_send_email_action' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'user_user_operations_unblock' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
    'pathauto_user_update_alias_multiple-620e193b20ba9caa374fea9ca0ad38f0' => array(
      'selected' => 0,
      'skip_confirmation' => 0,
      'label' => '',
    ),
  ),
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'spamweg');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));

Casus okt. 2015: 160.000 spam-accounts

Dit is eenvoudig: Ik wil gewoon alle accounts verwijderen, op het beheer-account na. Dat is op database-niveau héél gemakkelijk geregeld:

mysql> delete from users where uid>5;
Query OK, 162981 rows affected (6.58 sec)

Zie ook