diff --git a/scripts/validate_users.php b/scripts/validate_users.php old mode 100644 new mode 100755 index 391f4e33..2c7cae82 --- a/scripts/validate_users.php +++ b/scripts/validate_users.php @@ -7,8 +7,10 @@ // Include all settings and classes require_once('shared.inc.php'); - - $timeLimitInDays = 90; + + $options = getopt("d:a"); + isset($options['d']) ? $timeLimitInDays = (int)$options['d'] : $timeLimitInDays = 90; + isset($options['a']) ? $allUsers = true : $allUsers = false; $notifyStaleUsers = False; // Fetch all users @@ -19,9 +21,8 @@ $currentTime = time(); $totalSavings = 0; - - foreach ($users as $user) - { + + foreach ($users as $user) { $id = $user['id']; $isAdmin = $user['is_admin']; $username = $user['username']; @@ -29,32 +30,32 @@ $lastLogin = $user['last_login']; $coinAddress = $user['coin_address']; $mailAddress = $user['email']; - + $everLoggedIn = !empty($lastLogin); $timeDelta = $currentTime - $lastLogin; $lastLoginInDays = round(abs($timeDelta)/60/60/24, 0); - - if($lastLoginInDays < $timeLimitInDays) + + if(!$allUsers && $lastLoginInDays < $timeLimitInDays) continue; - + // get transactions summary for the user - $summary = $transaction->getTransactionSummary($id); + $summary = $transaction->getTransactionSummary($id); $transactions_exists = !empty($summary); - + // get balances $balances = $transaction->getBalance($id); $confirmedBalance = $balances['confirmed']; - $totalSavings += $confirmedBalance; - + $totalSavings += $confirmedBalance; + $staleAccount = $everLoggedIn == false && $transactions_exists == false; - + if ($notifyStaleUsers) { $subject = "Account at " . $setting->getValue('website_name') . "!"; $body = "Hi ". $username .",\n\nWe have discovered \ your username as inactive. Your last login is older than 90 days, \ please reactivate your Account if you want to mine again, \ else it will be deleted in 30 days.\n\nBalance left: ". $confirmedBalance . " " . $config['currency'] . "\n\nCheers"; - + if (mail($mailAddress, $subject, $body)) { echo("Email successfully sent!"); } else { @@ -62,11 +63,11 @@ } } - printf($mask, $id, $username, $mailAddress, + printf($mask, $id, $username, $mailAddress, $loggedIp, strftime("%Y-%m-%d %H:%M:%S", $lastLogin), $lastLoginInDays, $everLoggedIn ? 'yes' : 'no', $transactions_exists ? 'yes' : 'no', round($confirmedBalance,8), - $staleAccount ? 'yes' : 'no' ); + $staleAccount ? 'yes' : 'no' ); } echo "Total balance of stale accounts: $totalSavings" . PHP_EOL; -?> \ No newline at end of file +?>