| 1 |
<?php |
<?php |
| 2 |
// $Id: false_account.module,v 1.10 2008/08/25 15:21:54 introfini Exp $ |
// $Id$ |
| 3 |
|
|
| 4 |
define('FALSE_ACCOUNT_DEFAULT', 0); |
/** |
| 5 |
define('FALSE_ACCOUNT_WHITELISTED', 1); |
* @file |
| 6 |
define('FALSE_ACCOUNT_BLOCKED', 2); |
* Use this module to detect false accounts on your site |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
/** |
define('FALSE_ACCOUNT_DEFAULT', 0); |
| 10 |
* Implementation of hook_user(). |
define('FALSE_ACCOUNT_WHITELISTED', 1); |
| 11 |
*/ |
define('FALSE_ACCOUNT_BLOCKED', 2); |
| 12 |
function false_account_user($op, &$edit, &$account, $category = NULL) { |
|
| 13 |
switch ($op) { |
|
| 14 |
case 'insert': |
/** |
| 15 |
if (isset($_COOKIE['fad'])) { |
* Implementation of hook_user(). |
| 16 |
$cdata = explode(',', $_COOKIE['fad']); |
*/ |
| 17 |
$cid = $cdata[0]; |
function false_account_user($op, &$edit, &$account, $category = NULL) { |
| 18 |
$count = db_result(db_query(" |
switch ($op) { |
| 19 |
SELECT COUNT(cid) |
case 'insert': |
| 20 |
FROM {false_accounts} |
if (isset($_COOKIE['fad'])) { |
| 21 |
WHERE cid = '%s' and status = '%d'", |
$cdata = explode(',', $_COOKIE['fad']); |
| 22 |
$cid, FALSE_ACCOUNT_BLOCKED |
$cid = $cdata[0]; |
| 23 |
)); |
$count = db_result(db_query(" |
| 24 |
if ($count) { |
SELECT COUNT(cid) |
| 25 |
watchdog('false account', 'Blocked: '. $cid, WATCHDOG_NOTICE); |
FROM {false_accounts} |
| 26 |
drupal_goto(variable_get('false_account_redirect', '<front>')); |
WHERE cid = '%s' and status = '%d'", |
| 27 |
} |
$cid, FALSE_ACCOUNT_BLOCKED |
| 28 |
} |
)); |
| 29 |
break; |
if ($count) { |
| 30 |
case 'login': |
watchdog('false account', 'Blocked: %cid', array('%cid' => $cid), WATCHDOG_NOTICE); |
| 31 |
if (!isset($_COOKIE['fad'])) { |
drupal_goto(variable_get('false_account_redirect', '<front>')); |
| 32 |
$uniqueid = md5('gsmi789'. uniqid(rand(), TRUE)); |
} |
| 33 |
setcookie('fad', $uniqueid .','. $account->uid, time() + 31536000, "/"); |
} |
| 34 |
} |
break; |
| 35 |
else{ |
case 'login': |
| 36 |
$cdata = explode(',', $_COOKIE['fad']); |
if (!isset($_COOKIE['fad'])) { |
| 37 |
$cid = $cdata[0]; |
$uniqueid = md5('gsmi789'. uniqid(rand(), TRUE)); |
| 38 |
if (in_array($account->uid, $cdata)) { |
setcookie('fad', $uniqueid .','. $account->uid, time() + 31536000, "/"); |
| 39 |
break; |
} |
| 40 |
} |
else{ |
| 41 |
else{ |
$cdata = explode(',', $_COOKIE['fad']); |
| 42 |
$new_cdata = $_COOKIE['fad'] .','. $account->uid; |
$cid = $cdata[0]; |
| 43 |
setcookie('fad', $new_cdata, time() + 31536000, "/" ); |
if (in_array($account->uid, $cdata)) { |
| 44 |
if (sizeof($cdata) == 2) { |
break; |
| 45 |
db_query(" |
} |
| 46 |
INSERT INTO {false_accounts} (cid, uid, created, status) |
else{ |
| 47 |
VALUES ('%s', '%d', %d, %d)", |
$new_cdata = $_COOKIE['fad'] .','. $account->uid; |
| 48 |
$cid, $cdata[1] , time(), FALSE_ACCOUNT_DEFAULT |
setcookie('fad', $new_cdata, time() + 31536000, "/" ); |
| 49 |
); |
if (sizeof($cdata) >= 2) { |
| 50 |
db_query(" |
db_query(" |
| 51 |
INSERT INTO {false_accounts} (cid, uid, created, status) |
DELETE FROM {false_accounts} |
| 52 |
VALUES ('%s', '%d', %d, %d)", |
WHERE cid = '%s'", |
| 53 |
$cid, $account->uid , time(), FALSE_ACCOUNT_DEFAULT |
$cid |
| 54 |
); |
); |
| 55 |
} |
|
| 56 |
else if (sizeof($cdata) > 2) { |
$i = 1; |
| 57 |
db_query(" |
$time = time(); |
| 58 |
INSERT INTO {false_accounts} (cid, uid, created, status) |
while ($i < sizeof($cdata)) { |
| 59 |
VALUES ('%s', '%d', %d, %d)", |
db_query(" |
| 60 |
$cid, $account->uid , time(), FALSE_ACCOUNT_DEFAULT |
INSERT INTO {false_accounts} (cid, uid, created, status) |
| 61 |
); |
VALUES ('%s', %d, %d, %d)", |
| 62 |
} |
$cid, $cdata[$i++] , $time, FALSE_ACCOUNT_DEFAULT |
| 63 |
} |
); |
| 64 |
} |
} |
| 65 |
break; |
db_query(" |
| 66 |
case 'view': |
INSERT INTO {false_accounts} (cid, uid, created, status) |
| 67 |
if (user_access('manage false account detector')) { |
VALUES ('%s', %d, %d, %d)", |
| 68 |
$res = db_query('SELECT cid FROM {false_accounts} WHERE uid = %d', $account->uid); |
$cid, $account->uid , $time, FALSE_ACCOUNT_DEFAULT |
| 69 |
if (db_num_rows($res) > 0) { |
); |
| 70 |
while ($res_cid = db_fetch_object($res)) { |
} |
| 71 |
$ors[] = 'cid = "'. $res_cid->cid .'"'; |
} |
| 72 |
} |
} |
| 73 |
$or = implode(' OR ', $ors); |
break; |
| 74 |
$sql = "SELECT * FROM {false_accounts} WHERE " . $or; |
case 'view': |
| 75 |
|
if (user_access('manage false account detector')) { |
| 76 |
$header = array( |
$res = db_query(' |
| 77 |
array('data' => t('User Accounts')), |
SELECT cid |
| 78 |
array('data' => t('Created'), 'field' => 'created', 'sort' => 'desc'), |
FROM {false_accounts} |
| 79 |
); |
WHERE uid = %d', |
| 80 |
$result= pager_query($sql . tablesort_sql($header), 50, 0, NULL); |
$account->uid |
| 81 |
$rows = array(); |
); |
| 82 |
|
|
| 83 |
$cookies = array(); |
$num_rows = db_result(db_query(' |
| 84 |
|
SELECT COUNT(cid) |
| 85 |
while ($cookie = db_fetch_object($result)) { |
FROM {false_accounts} |
| 86 |
if (array_key_exists($cookie->cid, $cookies)) { |
WHERE uid = %d', |
| 87 |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
$account->uid |
| 88 |
} |
)); |
| 89 |
else { |
|
| 90 |
$cookies[$cookie->cid] = array(); |
if ($num_rows > 0) { |
| 91 |
$cookies[$cookie->cid]['users'] = array(); |
while ($res_cid = db_fetch_object($res)) { |
| 92 |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
$ors[] = 'cid = "'. $res_cid->cid .'"'; |
| 93 |
$cookies[$cookie->cid]['created'] = $cookie->created; |
} |
| 94 |
} |
$or = implode(' OR ', $ors); |
| 95 |
} |
$sql = "SELECT * FROM {false_accounts} WHERE " . $or; |
| 96 |
|
|
| 97 |
$items['fad'] = array( |
$header = array( |
| 98 |
'value' => _false_account_build_user_table($header, $cookies, $account->uid), |
array('data' => t('User Accounts')), |
| 99 |
); |
array('data' => t('Created'), 'field' => 'created', 'sort' => 'desc'), |
| 100 |
|
); |
| 101 |
return array(t('False Account') => $items); |
$result= pager_query($sql . tablesort_sql($header), 50, 0, NULL); |
| 102 |
} |
$rows = array(); |
| 103 |
else { |
|
| 104 |
$items['fad'] = array( |
$cookies = array(); |
| 105 |
'value' => t('No false accounts detected.'), |
|
| 106 |
); |
while ($cookie = db_fetch_object($result)) { |
| 107 |
return array(t('False Account') => $items); |
if (array_key_exists($cookie->cid, $cookies)) { |
| 108 |
} |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
| 109 |
} |
} |
| 110 |
break; |
else { |
| 111 |
} |
$cookies[$cookie->cid] = array(); |
| 112 |
} |
$cookies[$cookie->cid]['users'] = array(); |
| 113 |
|
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
| 114 |
function false_account_menu($may_cache) { |
$cookies[$cookie->cid]['created'] = $cookie->created; |
| 115 |
$access = user_access('manage false account detector'); |
} |
| 116 |
if ($may_cache) { |
} |
| 117 |
$items[] = array( |
|
| 118 |
'path' => 'admin/user/false_account', |
$account->content['fad'] = array( |
| 119 |
'title' => t('False Account Detector'), |
'#type' => 'user_profile_category', |
| 120 |
'callback' => 'false_account_page', |
'#title' => t('False Account'), |
| 121 |
'callback arguments' => array(FALSE_ACCOUNT_DEFAULT), |
'table' => array( |
| 122 |
'access' => $access, |
'#type' => 'user_profile_item', |
| 123 |
'weight' => 0 |
'#value' => _false_account_build_user_table($header, $cookies, $account->uid)), |
| 124 |
); |
'#weight' => -10 |
| 125 |
$items[] = array( |
); |
| 126 |
'path' => 'admin/user/false_account/default', |
} |
| 127 |
'title' => t('Default'), |
else { |
| 128 |
'callback' => 'false_account_page', |
$account->content['fad'] = array( |
| 129 |
'callback arguments' => array(FALSE_ACCOUNT_DEFAULT), |
'#type' => 'user_profile_category', |
| 130 |
'access' => $access, |
'#title' => t('False Account'), |
| 131 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
'table' => array( |
| 132 |
'weight' => 0 |
'#type' => 'user_profile_item', |
| 133 |
); |
'#title' => t('No false accounts detected.')), |
| 134 |
$items[] = array( |
'#weight' => -10 |
| 135 |
'path' => 'admin/user/false_account/whitelisted', |
); |
| 136 |
'title' => t('Whitelisted'), |
} |
| 137 |
'callback' => 'false_account_page', |
} |
| 138 |
'callback arguments' => array(FALSE_ACCOUNT_WHITELISTED), |
break; |
| 139 |
'access' => $access, |
} |
| 140 |
'type' => MENU_LOCAL_TASK, |
} |
| 141 |
'weight' => 1 |
|
| 142 |
); |
|
| 143 |
$items[] = array( |
/** |
| 144 |
'path' => 'admin/user/false_account/blocked', |
* Implementation of hook_menu(). |
| 145 |
'title' => t('Blocked'), |
*/ |
| 146 |
'callback' => 'false_account_page', |
function false_account_menu() { |
| 147 |
'callback arguments' => array(FALSE_ACCOUNT_BLOCKED), |
$access = array('manage false account detector'); |
| 148 |
'access' => $access, |
|
| 149 |
'type' => MENU_LOCAL_TASK, |
$items['false_account'] = array( |
| 150 |
'weight' => 1 |
'title' => 'False Account Detector', |
| 151 |
); |
'title callback' => 't', |
| 152 |
$items[] = array( |
'page callback' => 'false_account_page', |
| 153 |
'path' => 'admin/user/false_account/settings', |
'page arguments' => array('FALSE_ACCOUNT_DEFAULT'), |
| 154 |
'title' => t('Settings'), |
'access arguments' => $access, |
| 155 |
'callback' => 'drupal_get_form', |
'weight' => 0, |
| 156 |
'callback arguments' => array('false_account_settings'), |
'type' => MENU_CALLBACK |
| 157 |
'access' => $access, |
); |
| 158 |
'type' => MENU_LOCAL_TASK, |
$items['admin/user/false_account'] = array( |
| 159 |
'weight' => 2 |
'title' => 'False Account Detector', |
| 160 |
); |
'title callback' => 't', |
| 161 |
$items[] = array( |
'page callback' => 'false_account_page', |
| 162 |
'path' => 'admin/user/false_account/search', |
'page arguments' => array('FALSE_ACCOUNT_DEFAULT'), |
| 163 |
'title' => t('Search'), |
'access arguments' => $access, |
| 164 |
'callback' => 'false_account_searchfa', |
'weight' => 0 |
| 165 |
'access' => $access, |
); |
| 166 |
'type' => MENU_LOCAL_TASK, |
$items['admin/user/false_account/default'] = array( |
| 167 |
'weight' => 2 |
'title' => 'Default', |
| 168 |
); |
'title callback' => 't', |
| 169 |
$items[] = array( |
'page callback' => 'false_account_page', |
| 170 |
'path' => 'admin/user/false_account/op', |
'page arguments' => array('FALSE_ACCOUNT_DEFAULT'), |
| 171 |
'callback' => 'false_account_operations', |
'access arguments' => $access, |
| 172 |
'access' => $access, |
'type' => MENU_DEFAULT_LOCAL_TASK, |
| 173 |
'type' => MENU_CALLBACK |
'weight' => 0 |
| 174 |
); |
); |
| 175 |
} |
$items['admin/user/false_account/whitelisted'] = array( |
| 176 |
return $items; |
'title' => 'Whitelisted', |
| 177 |
} |
'title callback' => 't', |
| 178 |
|
'page callback' => 'false_account_page', |
| 179 |
function false_account_perm() { |
'page arguments' => array('FALSE_ACCOUNT_WHITELISTED'), |
| 180 |
return array('manage false account detector'); |
'access arguments' => $access, |
| 181 |
} |
'type' => MENU_LOCAL_TASK, |
| 182 |
|
'weight' => 1 |
| 183 |
/** |
); |
| 184 |
* Define the settings form. |
$items['admin/user/false_account/blocked'] = array( |
| 185 |
*/ |
'title' => 'Blocked', |
| 186 |
function false_account_settings() { |
'title callback' => 't', |
| 187 |
$form['false_account_redirect'] = array( |
'page callback' => 'false_account_page', |
| 188 |
'#type' => 'textfield', |
'page arguments' => array('FALSE_ACCOUNT_BLOCKED'), |
| 189 |
'#title' => t('Redirect blocked users'), |
'access arguments' => $access, |
| 190 |
'#default_value' => variable_get('false_account_redirect', '<front>'), |
'type' => MENU_LOCAL_TASK, |
| 191 |
'#description' => t('Indicate the Drupal internal URL to redirect to or insert an external URL.'), |
'weight' => 1 |
| 192 |
); |
); |
| 193 |
|
$items['admin/user/false_account/settings'] = array( |
| 194 |
return system_settings_form($form); |
'title' => 'Settings', |
| 195 |
} |
'title callback' => 't', |
| 196 |
function false_account_page($op = FALSE_ACCOUNT_DEFAULT) { |
'page callback' => 'drupal_get_form', |
| 197 |
|
'page arguments' => array('false_account_settings'), |
| 198 |
$content = t('<p>User accounts marked with an * are blocked</p>'); |
'access arguments' => $access, |
| 199 |
$sql = 'SELECT * FROM {false_accounts} WHERE status = '. $op ; |
'type' => MENU_LOCAL_TASK, |
| 200 |
$header = array( |
'weight' => 2 |
| 201 |
array('data' => t('Cookie ID')), |
); |
| 202 |
array('data' => t('User Accounts')), |
$items['admin/user/false_account/search'] = array( |
| 203 |
array('data' => t('Created'), 'field' => 'created', 'sort' => 'desc'), |
'title' => 'Search', |
| 204 |
array('data' => t('Actions')) |
'title callback' => 't', |
| 205 |
); |
'page callback' => 'false_account_searchfa', |
| 206 |
$result = pager_query($sql . tablesort_sql($header), 50); |
'access arguments' => $access, |
| 207 |
$rows = array(); |
'type' => MENU_LOCAL_TASK, |
| 208 |
|
'weight' => 2 |
| 209 |
$cookies = array(); |
); |
| 210 |
|
$items['admin/user/false_account/op'] = array( |
| 211 |
while ($cookie = db_fetch_object($result)) { |
'page callback' => 'false_account_operations', |
| 212 |
if (array_key_exists($cookie->cid, $cookies)) { |
'access arguments' => $access, |
| 213 |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
'type' => MENU_CALLBACK |
| 214 |
} |
); |
| 215 |
else { |
|
| 216 |
$cookies[$cookie->cid] = array(); |
return $items; |
| 217 |
$cookies[$cookie->cid]['users'] = array(); |
} |
| 218 |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
|
| 219 |
$cookies[$cookie->cid]['status'] = $cookie->status; |
|
| 220 |
$cookies[$cookie->cid]['created'] = $cookie->created; |
/** |
| 221 |
} |
* Implementation of hook_perm(). |
| 222 |
} |
*/ |
| 223 |
|
function false_account_perm() { |
| 224 |
$content .= _false_account_build_table($header, $cookies, $op); |
return array('manage false account detector'); |
| 225 |
|
} |
| 226 |
return $content; |
|
| 227 |
} |
|
| 228 |
|
/** |
| 229 |
function false_account_operations($op, $cid) { |
* Define the settings form. |
| 230 |
$sql = "UPDATE {false_accounts} SET status ='%d' WHERE cid = '%s'"; |
*/ |
| 231 |
db_query($sql, $op, $cid); |
function false_account_settings() { |
| 232 |
drupal_goto('admin/user/false_account'); |
$form['false_account_redirect'] = array( |
| 233 |
} |
'#type' => 'textfield', |
| 234 |
|
'#title' => t('Redirect blocked users'), |
| 235 |
function false_account_searchfa($account = NULL) { |
'#default_value' => variable_get('false_account_redirect', '<front>'), |
| 236 |
$content = t('<p>Search false accounts for one specific user.</p>'); |
'#description' => t('Indicate the Drupal internal URL to redirect to or insert an external URL.'), |
| 237 |
$content .= drupal_get_form('false_account_searchfa_form'); |
); |
| 238 |
if ($account) { |
|
| 239 |
$accountname = user_load(array('uid' => $account)); |
return system_settings_form($form); |
| 240 |
$content .= '<p>'. t('<strong>User Name: </strong>') . $accountname->name .'<br/>'; |
} |
| 241 |
$content .= t('<strong>User ID: </strong>') . $accountname->uid .'</p>' ; |
|
| 242 |
$res = db_query('SELECT cid FROM {false_accounts} WHERE uid = %d', $accountname->uid); |
|
| 243 |
while ($res_cid = db_fetch_object($res)) { |
|
| 244 |
$ors[] = 'cid = "'. $res_cid->cid .'"'; |
function false_account_page($op = 'FALSE_ACCOUNT_DEFAULT') { |
| 245 |
} |
|
| 246 |
$or = implode(' OR ', $ors); |
switch ($op) { |
| 247 |
$sql = "SELECT * FROM {false_accounts} WHERE " . $or; |
case 'FALSE_ACCOUNT_DEFAULT': |
| 248 |
$header = array( |
$op = 0; |
| 249 |
array('data' => t('Cookie ID')), |
break; |
| 250 |
array('data' => t('User Accounts')), |
case 'FALSE_ACCOUNT_WHITELISTED': |
| 251 |
array('data' => t('Created'), 'field' => 'created', 'sort' => 'desc'), |
$op = 1; |
| 252 |
array('data' => t('Actions')) |
break; |
| 253 |
); |
case 'FALSE_ACCOUNT_BLOCKED': |
| 254 |
$result= pager_query($sql . tablesort_sql($header), 50, 0, NULL); |
$op = 2; |
| 255 |
$rows = array(); |
break; |
| 256 |
|
} |
| 257 |
$cookies = array(); |
|
| 258 |
|
$content = t('<p>User accounts marked with an * are blocked</p>'); |
| 259 |
while ($cookie = db_fetch_object($result)) { |
$sql = 'SELECT * FROM {false_accounts} WHERE status = '. $op ; |
| 260 |
if (array_key_exists($cookie->cid, $cookies)) { |
$header = array( |
| 261 |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
array('data' => t('Cookie ID')), |
| 262 |
} |
array('data' => t('User Accounts')), |
| 263 |
else { |
array('data' => t('Created'), 'field' => 'created', 'sort' => 'desc'), |
| 264 |
$cookies[$cookie->cid] = array(); |
array('data' => t('Actions')) |
| 265 |
$cookies[$cookie->cid]['users'] = array(); |
); |
| 266 |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
$result = pager_query($sql . tablesort_sql($header), 50); |
| 267 |
$cookies[$cookie->cid]['status'] = $cookie->status; |
$rows = array(); |
| 268 |
$cookies[$cookie->cid]['created'] = $cookie->created; |
|
| 269 |
} |
$cookies = array(); |
| 270 |
} |
|
| 271 |
|
while ($cookie = db_fetch_object($result)) { |
| 272 |
$content .= _false_account_build_table($header, $cookies, $op); |
if (array_key_exists($cookie->cid, $cookies)) { |
| 273 |
} |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
| 274 |
return $content; |
} |
| 275 |
} |
else { |
| 276 |
|
$cookies[$cookie->cid] = array(); |
| 277 |
|
$cookies[$cookie->cid]['users'] = array(); |
| 278 |
function false_account_searchfa_form() { |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
| 279 |
$form['username'] = array( |
$cookies[$cookie->cid]['status'] = $cookie->status; |
| 280 |
'#type' => 'textfield', |
$cookies[$cookie->cid]['created'] = $cookie->created; |
| 281 |
'#description' => t('Enter username'), |
} |
| 282 |
'#autocomplete_path' => 'user/autocomplete', |
} |
| 283 |
'#maxlength' => USERNAME_MAX_LENGTH, |
|
| 284 |
'#size' => 16, |
$content .= _false_account_build_table($header, $cookies, $op); |
| 285 |
); |
|
| 286 |
$form['submit'] = array( |
return $content; |
| 287 |
'#type' => 'submit', |
} |
| 288 |
'#value' => t('Search'), |
|
| 289 |
); |
function false_account_operations($op, $cid) { |
| 290 |
return $form; |
$sql = "UPDATE {false_accounts} SET status ='%d' WHERE cid = '%s'"; |
| 291 |
|
db_query($sql, $op, $cid); |
| 292 |
} |
drupal_goto('admin/user/false_account'); |
| 293 |
|
} |
| 294 |
function false_account_searchfa_form_validate($form_id, $form_values) { |
|
| 295 |
if (!$account = user_load(array('name' => $form_values['username']))) { |
function false_account_searchfa($account = NULL) { |
| 296 |
form_set_error('username', t('Username not found')); |
$content = t('<p>Search false accounts for one specific user.</p>'); |
| 297 |
} |
$content .= drupal_get_form('false_account_searchfa_form'); |
| 298 |
} |
if ($account) { |
| 299 |
|
$accountname = user_load(array('uid' => $account)); |
| 300 |
function false_account_searchfa_form_submit($form_id, $form_values) { |
$content .= '<p>'. t('<strong>User Name: </strong>') . $accountname->name .'<br/>'; |
| 301 |
$account = user_load(array('name' => $form_values['username'])); |
$content .= t('<strong>User ID: </strong>') . $accountname->uid .'</p>' ; |
| 302 |
return 'admin/user/false_account/search/'. $account->uid; |
$res = db_query('SELECT cid FROM {false_accounts} WHERE uid = %d', $accountname->uid); |
| 303 |
} |
while ($res_cid = db_fetch_object($res)) { |
| 304 |
|
$ors[] = 'cid = "'. $res_cid->cid .'"'; |
| 305 |
|
} |
| 306 |
function _false_account_build_table($header, $cookies, $op) { |
$or = implode(' OR ', $ors); |
| 307 |
|
$sql = "SELECT * FROM {false_accounts} WHERE " . $or; |
| 308 |
foreach ($cookies as $cid => $cookie) { |
$header = array( |
| 309 |
// user handling |
array('data' => t('Cookie ID')), |
| 310 |
foreach ($cookie['users'] as $user) { |
array('data' => t('User Accounts')), |
| 311 |
$uid = trim($user); |
array('data' => t('Created'), 'field' => 'created', 'sort' => 'desc'), |
| 312 |
$status = user_load(array('uid' => $uid)); |
array('data' => t('Actions')) |
| 313 |
$account[] = l(($status->status == 0) ? $uid .'*' : $uid, 'user/'. $uid); |
); |
| 314 |
} |
$result= pager_query($sql . tablesort_sql($header), 50, 0, NULL); |
| 315 |
$accounts = implode(', ', $account); |
$rows = array(); |
| 316 |
|
|
| 317 |
// actions handling |
$cookies = array(); |
| 318 |
switch ($op) { |
|
| 319 |
case FALSE_ACCOUNT_DEFAULT: |
while ($cookie = db_fetch_object($result)) { |
| 320 |
$actions = l(t('whitelist'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_WHITELISTED .'/'. $cid) .' | '. l(t('block'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_BLOCKED .'/'. $cid); |
if (array_key_exists($cookie->cid, $cookies)) { |
| 321 |
break; |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
| 322 |
case FALSE_ACCOUNT_WHITELISTED: |
} |
| 323 |
$actions = l(t('default'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_DEFAULT .'/'. $cid) .' | '. l(t('block'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_BLOCKED .'/'. $cid); |
else { |
| 324 |
break; |
$cookies[$cookie->cid] = array(); |
| 325 |
case FALSE_ACCOUNT_BLOCKED: |
$cookies[$cookie->cid]['users'] = array(); |
| 326 |
$actions = l(t('default'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_DEFAULT .'/'. $cid) .' | '. l(t('whitelist'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_WHITELISTED .'/'. $cid); |
array_push($cookies[$cookie->cid]['users'], $cookie->uid); |
| 327 |
break; |
$cookies[$cookie->cid]['status'] = $cookie->status; |
| 328 |
} |
$cookies[$cookie->cid]['created'] = $cookie->created; |
| 329 |
|
} |
| 330 |
$rows[] = array( |
} |
| 331 |
$cid, |
|
| 332 |
$accounts, |
$content .= _false_account_build_table($header, $cookies, $op); |
| 333 |
date('d-m-Y', $cookie['created']), |
} |
| 334 |
$actions |
return $content; |
| 335 |
); |
} |
| 336 |
unset($account); |
|
| 337 |
} |
|
| 338 |
if ($rows) { |
function false_account_searchfa_form() { |
| 339 |
$table .= theme('table', $header, $rows); |
$form['username'] = array( |
| 340 |
$table .= theme('pager'); |
'#type' => 'textfield', |
| 341 |
} |
'#description' => t('Enter username'), |
| 342 |
else{ |
'#autocomplete_path' => 'user/autocomplete', |
| 343 |
$table = t('No false accounts detected.'); |
'#maxlength' => USERNAME_MAX_LENGTH, |
| 344 |
} |
'#size' => 16, |
| 345 |
|
); |
| 346 |
return $table; |
$form['submit'] = array( |
| 347 |
} |
'#type' => 'submit', |
| 348 |
|
'#value' => t('Search'), |
| 349 |
|
); |
| 350 |
function _false_account_build_user_table($header, $cookies, $userid) { |
return $form; |
| 351 |
|
|
| 352 |
foreach ($cookies as $cid => $cookie) { |
} |
| 353 |
// user handling |
|
| 354 |
foreach ($cookie['users'] as $user) { |
function false_account_searchfa_form_validate($form, &$form_state) { |
| 355 |
$uid = trim($user); |
if (!$account = user_load(array('name' => $form_state['values']['username']))) { |
| 356 |
$status = user_load(array('uid' => $uid)); |
form_set_error('username', t('Username not found')); |
| 357 |
if ($userid == $uid) { |
} |
| 358 |
$account[] = ($status->status == 0) ? $status->name .'*' : $status->name; |
} |
| 359 |
} |
|
| 360 |
else { |
function false_account_searchfa_form_submit($form, &$form_state) { |
| 361 |
$account[] = l(($status->status == 0) ? $status->name .'*' : $status->name, 'user/'. $uid); |
$account = user_load(array('name' => $form_state['values']['username'])); |
| 362 |
} |
$form_state['redirect'] = 'admin/user/false_account/search/'. $account->uid; |
| 363 |
} |
} |
| 364 |
$accounts = implode(', ', $account); |
|
| 365 |
|
|
| 366 |
$rows[] = array( |
function _false_account_build_table($header, $cookies, $op) { |
| 367 |
$accounts, |
|
| 368 |
date('d-m-Y', $cookie['created']), |
foreach ($cookies as $cid => $cookie) { |
| 369 |
); |
// user handling |
| 370 |
unset($account); |
foreach ($cookie['users'] as $user) { |
| 371 |
} |
$uid = trim($user); |
| 372 |
if ($rows) { |
$status = user_load(array('uid' => $uid)); |
| 373 |
$table .= theme('table', $header, $rows); |
$account[] = l(($status->status == 0) ? $uid .'*' : $uid, 'user/'. $uid); |
| 374 |
$table .= theme('pager'); |
} |
| 375 |
} |
$accounts = implode(', ', $account); |
| 376 |
else{ |
|
| 377 |
$table = t('No false accounts detected.'); |
// actions handling |
| 378 |
} |
switch ($op) { |
| 379 |
|
case FALSE_ACCOUNT_DEFAULT: |
| 380 |
return $table; |
$actions = l(t('whitelist'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_WHITELISTED .'/'. $cid) .' | '. l(t('block'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_BLOCKED .'/'. $cid); |
| 381 |
} |
break; |
| 382 |
|
case FALSE_ACCOUNT_WHITELISTED: |
| 383 |
|
$actions = l(t('default'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_DEFAULT .'/'. $cid) .' | '. l(t('block'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_BLOCKED .'/'. $cid); |
| 384 |
|
break; |
| 385 |
|
case FALSE_ACCOUNT_BLOCKED: |
| 386 |
|
$actions = l(t('default'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_DEFAULT .'/'. $cid) .' | '. l(t('whitelist'), 'admin/user/false_account/op/'. FALSE_ACCOUNT_WHITELISTED .'/'. $cid); |
| 387 |
|
break; |
| 388 |
|
} |
| 389 |
|
|
| 390 |
|
$rows[] = array( |
| 391 |
|
$cid, |
| 392 |
|
$accounts, |
| 393 |
|
date('d-m-Y', $cookie['created']), |
| 394 |
|
$actions |
| 395 |
|
); |
| 396 |
|
unset($account); |
| 397 |
|
} |
| 398 |
|
if ($rows) { |
| 399 |
|
$table .= theme('table', $header, $rows); |
| 400 |
|
$table .= theme('pager'); |
| 401 |
|
} |
| 402 |
|
else{ |
| 403 |
|
$table = t('No false accounts detected.'); |
| 404 |
|
} |
| 405 |
|
|
| 406 |
|
return $table; |
| 407 |
|
} |
| 408 |
|
|
| 409 |
|
|
| 410 |
|
function _false_account_build_user_table($header, $cookies, $userid) { |
| 411 |
|
|
| 412 |
|
foreach ($cookies as $cid => $cookie) { |
| 413 |
|
// user handling |
| 414 |
|
foreach ($cookie['users'] as $user) { |
| 415 |
|
$uid = trim($user); |
| 416 |
|
$status = user_load(array('uid' => $uid)); |
| 417 |
|
if ($userid == $uid) { |
| 418 |
|
$account[] = ($status->status == 0) ? $status->name .'*' : $status->name; |
| 419 |
|
} |
| 420 |
|
else { |
| 421 |
|
$account[] = l(($status->status == 0) ? $status->name .'*' : $status->name, 'user/'. $uid); |
| 422 |
|
} |
| 423 |
|
} |
| 424 |
|
$accounts = implode(', ', $account); |
| 425 |
|
|
| 426 |
|
$rows[] = array( |
| 427 |
|
$accounts, |
| 428 |
|
date('d-m-Y', $cookie['created']), |
| 429 |
|
); |
| 430 |
|
unset($account); |
| 431 |
|
} |
| 432 |
|
if ($rows) { |
| 433 |
|
$table .= theme('table', $header, $rows); |
| 434 |
|
$table .= theme('pager'); |
| 435 |
|
} |
| 436 |
|
else{ |
| 437 |
|
$table = t('No false accounts detected.'); |
| 438 |
|
} |
| 439 |
|
|
| 440 |
|
return $table; |
| 441 |
|
} |