applied seraphers proposed fixes & suggestions

This commit is contained in:
Huseyin Uslu 2014-02-18 13:00:47 +02:00
parent c1290d5327
commit 981d73f988
2 changed files with 24 additions and 8 deletions

View File

@ -6,27 +6,43 @@
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
require_once('shared.inc.php');
if ( $bitcoin->can_connect() !== true )
die("Failed to connect to RPC server\n");
echo "Validating blocks in database against coind..\n";
$mask = "| %6s | %8s | %13s | %20s | %10s | \n";
printf($mask, 'DB-ID', 'Height', 'Confirmations', 'Time', 'Status');
// fetch all blocks
$allBlocks = $block->getAll();
foreach ($allBlocks as $block)
{
//print_r($block);
$status = 'VALID';
try {
$blockInfo = $bitcoin->getblock($block['blockhash']);
}
catch(Exception $e)
{
// don't report orphan blocks.
if($block['confirmations']!= -1 && $e->getMessage() == 'RPC call did not return 200: HTTP error: 500 - JSON Response: [-5] Block not found')
if($block['confirmations']== -1)
{
echo "Block not found: database-id: $block[id] - height: $block[height].\n";
$status = 'ORPHAN';
}
else if($e->getMessage() == 'RPC call did not return 200: HTTP error: 500 - JSON Response: [-5] Block not found')
{
$status = 'INVALID';
}
else
{
$status = 'UNKNOWN';
}
}
finally {
printf($mask, $block['id'], $block['height'], $block['confirmations'], strftime("%Y-%m-%d %H:%M:%S", $block['time']), $status);
}
}

View File

@ -13,7 +13,7 @@
// Fetch all users
$users = $user->getAllAssoc();
$mask = "| %6s | %20s | %16s | %10s | %-12.12s | %5s | %5s | %12s | %5s | \n";
$mask = "| %6s | %20s | %16s | %20s | %12.12s | %5s | %5s | %12s | %5s | \n";
printf($mask, 'ID', 'Username', 'LoggedIP', 'Last Login','Days Since', 'Ever', 'Trans', 'Balance','Stale');
$currentTime = time();
@ -30,7 +30,7 @@
$everLoggedIn = !empty($lastLogin);
$timeDelta = $currentTime - $lastLogin;
$lastLoginInDays = abs($timeDelta)/60/60/24;
$lastLoginInDays = round(abs($timeDelta)/60/60/24, 0);
if($lastLoginInDays < $timeLimitInDays)
continue;
@ -47,8 +47,8 @@
$staleAccount = $everLoggedIn == false && $transactions_exists == false;
printf($mask, $id, $username,
$loggedIp, $lastLogin, $lastLoginInDays, $everLoggedIn ? 'yes' : 'no',
$transactions_exists ? 'yes' : 'no', $confirmedBalance,
$loggedIp, strftime("%Y-%m-%d %H:%M:%S", $lastLogin), $lastLoginInDays, $everLoggedIn ? 'yes' : 'no',
$transactions_exists ? 'yes' : 'no', round($confirmedBalance,8),
$staleAccount ? 'yes' : 'no' );
}