Merge branch 'next' of github.com:MPOS/php-mpos into next

This commit is contained in:
Sebastian Grewe 2014-02-16 08:32:10 +01:00
commit cdaf757b8b
11 changed files with 204 additions and 172 deletions

View File

@ -1,39 +0,0 @@
#!/usr/bin/php
<?php
/*
Copyright:: 2013, Sebastian Grewe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// If we don't keep archives, delete some now to release disk space
$affected_rows = $share->purgeArchive();
if ($affected_rows === false) {
$log->logError("Failed to delete archived shares, not critical but should be checked: " . $share->getCronError());
$monitoring->endCronjob($cron_name, 'E0008', 0, false, false);
} else {
$log->logDebug("Deleted $affected_rows archived shares this run");
}
// Cron cleanup and monitoring
require_once('cron_end.inc.php');
?>

View File

@ -1,38 +0,0 @@
#!/usr/bin/php
<?php
/*
Copyright:: 2013, Sebastian Grewe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Cleanup old expired tokens
if ($notification->cleanupNotifications($setting->getValue('notifications_cleanup_time', 7))) {
$notification->deleted == 0 ? $log->logDebug('Did not delete any old notifications') : $log->logInfo('Deleted ' . $notification->deleted . ' notifications');
} else {
$log->logError('Failed to delete notifications: ' . $notification->getCronError());
$monitoring->endCronjob($cron_name, 'E0074', 0, false, false);
}
// Cron cleanup and monitoring
require_once('cron_end.inc.php');
?>

View File

@ -41,7 +41,7 @@ $sendmanyAvailable = ((strpos($bitcoin->help('sendmany'), 'unknown') === FALSE)
if ($sendmanyAvailable)
$log->logDebug(' sendmany available in coind help command');
if (!$dWalletBalance = $bitcoin->getbalance())
if (!$dWalletBalance = $bitcoin->getrealbalance())
$dWalletBalance = 0;
// Fetch outstanding manual-payouts
@ -113,7 +113,7 @@ if ($setting->getValue('disable_manual_payouts') != 1 && $aManualPayouts) {
}
}
if (!$dWalletBalance = $bitcoin->getbalance())
if (!$dWalletBalance = $bitcoin->getrealbalance())
$dWalletBalance = 0;
// Fetch outstanding auto-payouts

View File

@ -10,7 +10,7 @@
PHP_BIN=$( which php )
# List of cruns to execute
CRONS="findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php tickerupdate.php notifications.php statistics.php token_cleanup.php archive_cleanup.php notification_cleanup.php"
CRONS="findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php tickerupdate.php notifications.php statistics.php tables_cleanup.php"
# Output additional runtime information
VERBOSE="0"

View File

@ -10,7 +10,7 @@
PHP_BIN=$( which php )
# List of cruns to execute
CRONS="tickerupdate.php notifications.php token_cleanup.php archive_cleanup.php notification_cleanup.php"
CRONS="tickerupdate.php notifications.php tables_cleanup.php"
# Output additional runtime information
VERBOSE="0"

79
cronjobs/tables_cleanup.php Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/php
<?php
/*
Copyright:: 2013, Sebastian Grewe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Header
$strLogMask = "| %-20.20s | %10.10s | %8.8s | %6.6s | %-40s |";
$log->logInfo(sprintf($strLogMask, 'Process', 'Affected', 'Runtime', 'Status', 'Message'));
// Cleanup old notifications
$start = microtime(true);
$status = 'OK';
$message = '';
$affected = 0;
if ($notification->cleanupNotifications($setting->getValue('notifications_cleanup_time', 7))) {
$affected = $notification->deleted;
$affected == 0 ? $message = 'No notifications deleted' : $message = 'Deleted notifications older than ' . $setting->getValue('notifications_cleanup_time', 7) . ' days';
} else {
$message = 'Failed to delete notifications: ' . $notification->getCronError();
$status = 'ERROR';
$monitoring->endCronjob($cron_name, 'E0074', 0, false, false);
}
$log->logInfo(sprintf($strLogMask, 'cleanupNotifications', $affected, number_format(microtime(true) - $start, 3), $status, $message));
// Cleanup old expired tokens
$start = microtime(true);
$status = 'OK';
$message = '';
$affected = 0;
if ($oToken->cleanupTokens()) {
$affected = $oToken->deleted;
$affected == 0 ? $message = 'No tokens deleted' : $message = 'Deleted expired tokens';
} else {
$message = 'Failed to delete notifications: ' . $oToken->getCronError();
$status = 'ERROR';
$monitoring->endCronjob($cron_name, 'E0074', 0, false, false);
}
$log->logInfo(sprintf($strLogMask, 'cleanupTokens', $affected, number_format(microtime(true) - $start, 3), $status, $message));
// Clenaup shares archive
$start = microtime(true);
$status = 'OK';
$message = '';
$affected = $share->purgeArchive();
if ($affected === false) {
$message = 'Failed to delete notifications: ' . $oToken->getCronError();
$status = 'ERROR';
$monitoring->endCronjob($cron_name, 'E0008', 0, false, false);
} else {
$affected == 0 ? $message = 'No shares deleted' : $message = 'Deleted old shares';
}
$log->logInfo(sprintf($strLogMask, 'purgeArchive', $affected, number_format(microtime(true) - $start, 3), $status, $message));
// Cron cleanup and monitoring
require_once('cron_end.inc.php');
?>

View File

@ -1,39 +0,0 @@
#!/usr/bin/php
<?php
/*
Copyright:: 2013, Sebastian Grewe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Cleanup old expired tokens
if ($oToken->cleanupTokens()) {
$oToken->deleted == 0 ? $log->logDebug('Did not find any expired tokens') : $log->logInfo('Deleted ' . $oToken->deleted . ' expired tokens');
} else {
$log->logError('Failed to delete expired tokens: ' . $oToken->getCronError());
// Treat as critical since tokens like password resets will never expire
$monitoring->endCronjob($cron_name, 'E0074', 1, true, true);
}
// Cron cleanup and monitoring
require_once('cron_end.inc.php');
?>

View File

@ -31,17 +31,27 @@ class BitcoinWrapper extends BitcoinClient {
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
return $this->memcache->setCache(__FUNCTION__, parent::getmininginfo(), 30);
}
// Wrapper to check our wallet balance from the DEFAULT account only
public function getbalance() {
$this->oDebug->append("STA " . __METHOD__, 4);
$aAccounts = parent::listaccounts();
return $aAccounts[''];
}
public function getblockcount() {
$this->oDebug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
return $this->memcache->setCache(__FUNCTION__, parent::getblockcount(), 30);
}
// Wrapper method to get the real main account balance
public function getrealbalance() {
$this->oDebug->append("STA " . __METHOD__, 4);
$aAccounts = parent::listaccounts();
$dBalance = parent::getbalance();
// Account checks
if (count($aAccounts) == 1) {
// We only have a single account so getbalance will be fine
return $dBalance;
} else {
$dMainBalance = $aAccounts[''];
if ($dMainBalance < 0) return $dMainBalance;
$dUnconfirmed = $dMainBalance - abs($dBalance);
return $dMainBalance - abs($dUnconfirmed);
}
}
public function getdifficulty() {
$this->oDebug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;

View File

@ -2,7 +2,7 @@
// Small helper array that may be used on some page controllers to
// fetch the crons we wish to monitor
$aMonitorCrons = array('statistics','payouts','token_cleanup','archive_cleanup','notification_cleanup','blockupdate','findblock','notifications','tickerupdate');
$aMonitorCrons = array('statistics','payouts','tables_cleanup','blockupdate','findblock','notifications','tickerupdate');
switch ($config['payout_system']) {
case 'pplns':

View File

@ -11,6 +11,16 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$debug->append('No cached version available, fetching from backend', 3);
if ($bitcoin->can_connect() === true){
$dBalance = $bitcoin->getbalance();
$dWalletAccounts = $bitcoin->listaccounts();
$dAddressCount = count($dWalletAccounts);
$dAccountAddresses = array();
foreach($dWalletAccounts as $key => $value)
{
$dAccountAddresses[$key] = $bitcoin->getaddressesbyaccount($key);
}
$aGetInfo = $bitcoin->getinfo();
if (is_array($aGetInfo) && array_key_exists('newmint', $aGetInfo)) {
$dNewmint = $aGetInfo['newmint'];
@ -37,6 +47,9 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
if (! $dColdCoins = $setting->getValue('wallet_cold_coins')) $dColdCoins = 0;
$smarty->assign("UNCONFIRMED", $dBlocksUnconfirmedBalance);
$smarty->assign("BALANCE", $dBalance);
$smarty->assign("ADDRESSCOUNT", $dAddressCount);
$smarty->assign("ACCOUNTADDRESSES", $dAccountAddresses);
$smarty->assign("ACCOUNTS", $dWalletAccounts);
$smarty->assign("COLDCOINS", $dColdCoins);
$smarty->assign("LOCKED", $dLockedBalance);
$smarty->assign("NEWMINT", $dNewmint);

View File

@ -1,49 +1,95 @@
<article class="module width_quarter">
<header><h3>Balance Summary</h3></header>
<table width="25%" class="tablesorter" cellspacing="0">
<tr>
<td align="left">Wallet Balance</td>
<td align="left">{$BALANCE|number_format:"8"}</td>
</tr>
<tr>
<td align="left">Locked for users</td>
<td align="left">{$LOCKED|number_format:"8"}</td>
</tr>
<tr>
<td align="left">Unconfirmed</td>
<td align="left">{$UNCONFIRMED|number_format:"8"}</td>
</tr>
<tr>
<td align="left">Liquid Assets</td>
<td align="left">{($BALANCE - $LOCKED)|number_format:"8"}</td>
</tr>
{if $NEWMINT >= 0}
<tr>
<td align="left">PoS New Mint</td>
<td align="left">{$NEWMINT|number_format:"8"}</td>
</tr>
{if $ADDRESSCOUNT > 1}
<article class="module width_full">
<header><h3>Wallet Information</h3></header>
{/if}
</table>
<article class="module width_quarter">
<header><h3>Balance Summary</h3></header>
<table width="25%" class="tablesorter" cellspacing="0">
<tr>
<td align="left">Wallet Balance</td>
<td align="left">{$BALANCE|number_format:"8"}</td>
</tr>
<tr>
<td align="left">Locked for users</td>
<td align="left">{$LOCKED|number_format:"8"}</td>
</tr>
<tr>
<td align="left">Unconfirmed</td>
<td align="left">{$UNCONFIRMED|number_format:"8"}</td>
</tr>
<tr>
<td align="left">Liquid Assets</td>
<td align="left">{($BALANCE - $LOCKED)|number_format:"8"}</td>
</tr>
{if $NEWMINT >= 0}
<tr>
<td align="left">PoS New Mint</td>
<td align="left">{$NEWMINT|number_format:"8"}</td>
</tr>
{/if}
</table>
</article>
<article class="module width_3_quarter">
<header><h3>Wallet Status</h3></header>
<table class="tablesorter" cellspacing="0">
<thead>
<th align="center">Version</th>
<th align="center">Protocol Version</th>
<th align="center">Wallet Version</th>
<th align="center">Connections</th>
<th align="center">Errors</th>
</thead>
<tbody>
<tr>
<td align="center">{$COININFO.version|default:""}</td>
<td align="center">{$COININFO.protocolversion|default:""}</td>
<td align="center">{$COININFO.walletversion|default:""}</td>
<td align="center">{$COININFO.connections|default:""}</td>
<td align="center"><font color="{if $COININFO.errors}red{else}green{/if}">{$COININFO.errors|default:"OK"}</font></td>
</tr>
</tbody>
</table>
</article>
{if $ADDRESSCOUNT > 1}
</article>
<article class="module width_3_quarter">
<header><h3>Wallet Information</h3></header>
<table class="tablesorter" cellspacing="0">
<thead>
<th align="center">Version</th>
<th align="center">Protocol Version</th>
<th align="center">Wallet Version</th>
<th align="center">Connections</th>
<th align="center">Errors</th>
</thead>
<tbody>
<tr>
<td align="center">{$COININFO.version|default:""}</td>
<td align="center">{$COININFO.protocolversion|default:""}</td>
<td align="center">{$COININFO.walletversion|default:""}</td>
<td align="center">{$COININFO.connections|default:""}</td>
<td align="center"><font color="{if $COININFO.errors}red{else}green{/if}">{$COININFO.errors|default:"OK"}</font></td>
</tr>
</tbody>
</table>
<article class="module width_full">
<header><h3>Number of Accounts in Wallet: {$ADDRESSCOUNT|default:"0"}</h3></header>
{foreach key=NAME item=VALUE from=$ACCOUNTS}
<article class="module width_full">
<header><h3>Account: {$NAME|default:"Default"}</h3></header>
<article class="module width_quarter">
<header><h3>Balance Info</h3></header>
<table width="40%" class="tablesorter" cellspacing="0">
<tr>
<td align="left">Balance</td>
<td align="left">{$VALUE|number_format:"8"}</td>
</tr>
</table>
</article>
{foreach key=ACCOUNT item=ADDRESS from=$ACCOUNTADDRESSES}
{if $ACCOUNT == $NAME}
<article class="module width_3_quarter">
<header><h3>Addresses assigned to Account {$ACCOUNT|default:"Default"}</h3></header>
<table class="tablesorter" cellspacing="0">
<tbody>
{foreach from=$ACCOUNTADDRESSES[$ACCOUNT] key=ACCOUNT1 item=ADDRESS1}
{if $ADDRESS1@iteration is even by 1}
<td align="left" style="padding-right: 25px;">{$ADDRESS1}</td>
</tr>
{else}
<tr>
<td align="left" style="padding-right: 25px;">{$ADDRESS1}</td>
{/if}
{/foreach}
</tbody>
</table>
</article>
{/if}
{/foreach}
</article>
{/foreach}
</article>
{/if}