private function get_template() { // get template name $this->a = $this->get_get('a', 'home'); switch ($this->a) { case 'about': return 'about'; break; case 'home': $this->open_wallet(); return 'home'; break; default: $msg = 'Unknown Action'; include 'skins/simple/fatal.error.php'; exit; break; case 'listtransactions': if (!$this->open_wallet()) { $this->debug('ERROR: listtransactions: open_wallet failed'); return 'listtransactions'; } if (!isset($_GET['account'])) { $_GET['account'] = '*'; // ALL } if (isset($_GET['account']) && $_GET['account'] == '""') { $_GET['account'] = ''; // Default Account } $this->account = $this->get_get('account', ''); $this->count = $this->get_get('count', 9999999); $this->from = $this->get_get('from', 0); $this->listtransactions = $this->wallet->listtransactions((string) $this->account, (int) $this->count, (int) $this->from); $this->info['transactions_count'] = sizeof($this->listtransactions); $this->listtransactions = @array_reverse($this->listtransactions); $this->lisstransactions = @array_walk($this->listtransactions, array(&$this, 'post_process_listtransactions')); return 'listtransactions'; break; case 'listaccounts': $this->open_wallet(); $this->listaccounts = $this->wallet->listaccounts((int) $this->get_get('minconf', 1)); return 'listaccounts'; break; case 'listreceivedbyaccount': $this->open_wallet(); $this->listreceivedbyaccount = $this->wallet->listreceivedbyaccount((int) $this->get_get('minconf', 1), (bool) $this->get_get('includeempty', 'false')); return 'listreceivedbyaccount'; break; case 'getaccountaddress': $this->open_wallet(); $this->getaccountaddress = $this->wallet->getaccountaddress((string) $this->get_get('account', '', $failonempty = true)); return 'getaccountaddress'; break; case 'getaddressesbyaccount': $this->open_wallet(); $this->getaddressesbyaccount = $this->wallet->getaddressesbyaccount((string) $this->get_get('account', '', $failonempty = true), (int) $this->get_get('minconf', 1)); return 'getaddressesbyaccount'; break; case 'getreceivedbyaccount': $this->open_wallet(); $this->getreceivedbyaccount = $this->wallet->getreceivedbyaccount((string) $this->get_get('account', '', true)); return 'getreceivedbyaccount'; break; case 'getbalance': $this->open_wallet(); $this->getbalance = $this->wallet->getbalance((string) $this->get_get('account', '', true), (int) $this->get_get('minconf', 1)); return 'getbalance'; break; // Transactions // Transactions case 'gettransaction': $this->open_wallet(); $this->gettransaction = $this->wallet->gettransaction((string) $this->get_get('txid', '', true)); return 'gettransaction'; break; case 'listreceivedbyaddress': $this->open_wallet(); $this->listreceivedbyaddress = $this->wallet->listreceivedbyaddress((int) $this->get_get('minconf', 1), (bool) $this->get_get('includeempty', false)); return 'listreceivedbyaddress'; break; case 'getnewaddress': $this->open_wallet(); $this->getnewaddress = $this->wallet->getnewaddress((string) $this->get_get('account', '')); return 'getnewaddress'; break; case 'getreceivedbyaddress': $this->open_wallet(); $this->getreceivedbyaddress = $this->wallet->getreceivedbyaddress((string) $this->get_get('address', ''), (int) $this->get_get('minconf', 1)); return 'getreceivedbyaddress'; break; case 'getaccount': $this->open_wallet(); $this->getaccount = $this->wallet->getaccount((string) $this->get_get('address', '', true)); return 'getaccount'; break; case 'setaccount': $this->open_wallet(); $this->setaccount = $this->wallet->setaccount((string) $this->get_get('address', '', true), (string) $this->get_get('account', '', true)); if ($this->setaccount == '') { $this->setaccount = 'OK'; } return 'setaccount'; break; case 'validateaddress': $this->open_wallet(); $this->validateaddress = $this->wallet->validateaddress((string) $this->get_get('address', '', true)); return 'validateaddress'; break; case 'sendtoaddress': $this->open_wallet(); $this->address = $this->get_get('address', ''); $this->amount = $this->get_get('amount', ''); $this->ok = $this->get_get('ok', '0'); $this->debug("send address:{$this->address} amount:{$this->amount} ok:{$this->ok}"); if ($this->address) { $this->validateaddress = $this->wallet->validateaddress($this->address); if (!$this->validateaddress['isvalid']) { $this->debug('invalid address: ' . $this->address); return 'sendtoaddress'; break; } } if ($this->address && $this->amount && $this->ok) { $this->debug("Sending coins"); $this->sendtoaddress = $this->wallet->sendtoaddress((string) $this->address, (double) $this->amount, (string) $this->get_get('comment', ''), (string) $this->get_get('comment_to', '')); } return 'sendtoaddress'; break; case 'sendfrom': $this->open_wallet(); $this->sendfrom = $this->wallet->sendfrom((string) $this->get_get('account', '', true), (string) $this->get_get('address', '', true), (double) $this->get_get('amount', '', true), (int) $this->get_get('minconf', 1), (string) $this->get_get('comment', ''), (string) $this->get_get('comment_to', '')); return 'sendfrom'; break; case 'sendmany': $this->open_wallet(); $this->sendmany = $this->wallet->sendmany((string) $this->get_get('account', '', true), (string) $this->get_get('tomany', '', true), (int) $this->get_get('minconf', 1), (string) $this->get_get('comment', '')); return 'sendmany'; break; case 'move': $this->open_wallet(); $this->move = $this->wallet->move((string) $this->get_get('fromaccount', '', true), (string) $this->get_get('toaccount', '', true), (double) $this->get_get('amount', '', true), (int) $this->get_get('minconf', 1), (string) $this->get_get('comment', '')); return 'move'; break; case 'sendescrow': $this->open_wallet(); $this->escrowaddrs = $this->get_get('escrowaddrs', ''); $this->amount = $this->get_get('amount', ''); $this->ok = $this->get_get('ok', '0'); $this->debug("escrowaddrs:{$this->escrowaddrs} amount:{$this->amount} ok:{$this->ok}"); if ($this->escrowaddrs && $this->amount && $this->ok) { $this->debug("Sending escrow"); $this->sendescrow = $this->wallet->sendescrow((string) $this->escrowaddrs, (double) $this->amount, (string) $this->get_get('comment', ''), (string) $this->get_get('comment_to', '')); } return 'sendescrow'; break; case 'redeemescrow': $this->open_wallet(); $this->redeemescrow = $this->wallet->redeemescrow((string) $this->get_get('inputtx', ''), (string) $this->get_get('address', ''), (string) $this->get_get('txhex', '')); return 'redeemescrow'; break; case 'getinfo': $this->open_wallet(); $this->getinfo = @$this->info; return 'getinfo'; break; case 'getblockcount': case 'getblocknumber': case 'getconnectioncount': case 'getdifficulty': case 'getgenerate': case 'gethashespersec': case 'getwork': case 'stop': $this->open_wallet(); $this->{$this->a} = $this->wallet->{$this->a}(); return 'debug'; break; case 'start': case 'getprocess': case 'kill': $this->open_wallet(); $this->{$this->a} = $this->wallet->{$this->a}(); return 'debug'; break; case 'backupwallet': $this->open_wallet(); $this->backupwallet = $this->wallet->backupwallet((string) $this->get_get('destination', '', true)); if ($this->backupwallet == '') { $this->backupwallet = 'OK'; } return 'backupwallet'; break; case 'setgenerate': $this->open_wallet(); // hacky fix until we do better per-_GET/_POST to $this->{_GET/_POST} var with typecasting switch ($this->get_get('generate', '', TRUE)) { case 'false': case '0': $this->generate = 0; break; case 'true': case '1': $this->generate = 1; break; default: $this->debug("ERROR: setgenerate generate is not boolean"); return 'setgenerate'; break; } $this->genproclimit = (int) $this->get_get('genproclimit', ''); $this->setgenerate = $this->wallet->setgenerate((bool) $this->generate, (int) $this->genproclimit); if ($this->setgenerate == '') { $this->setgenerate = "OK: setgenerate {$this->generate} {$this->genproclimit}"; } return 'setgenerate'; break; case 'help': $this->open_wallet(); $this->help = $this->wallet->help((string) $this->get_get('command', '')); return 'help'; break; // Namecoin // Namecoin case 'name_list': $this->open_wallet(); $this->name_list = $this->wallet->name_list((string) $this->get_get('name', '')); return 'debug'; break; case 'name_new': $this->open_wallet(); $this->name_new = $this->wallet->name_new((string) $this->get_get('name', '')); return 'debug'; break; case 'name_firstupdate': $this->open_wallet(); $this->name_firstupdate = $this->wallet->name_firstupdate((string) $this->get_get('name', ''), (string) $this->get_get('rand', ''), (string) $this->get_get('tx', ''), (string) $this->get_get('value', '')); return 'debug'; break; case 'name_update': $this->open_wallet(); $this->name_update = $this->wallet->name_update((string) $this->get_get('name', ''), (string) $this->get_get('value', ''), (string) $this->get_get('address', '')); return 'debug'; break; case 'name_scan': $this->open_wallet(); $this->name_scan = $this->wallet->name_scan((string) $this->get_get('start_name', ''), (int) $this->get_get('max_returned', '')); return 'debug'; break; case 'name_clean': $this->open_wallet(); $this->name_clean = $this->wallet->name_clean(); return 'debug'; break; case 'deletetransaction': $this->open_wallet(); $this->deletetransaction = $this->wallet->deletetransaction((string) $this->get_get('txid', '', true)); return 'debug'; break; //////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// case 'server.control': if (!SERVER_LOCALHOST) { $this->info['control'] = 'Error: No Localhost server found in configuration'; return 'server.control'; } if (SERVER_LOCALHOST_TYPE != 'windows') { $this->info['control'] = 'Erro: No Windows platform found in configuration'; return 'server.control'; } switch (strtolower($this->get_get('a1', ''))) { case 'view': // tasklist $tasklist = shell_exec(WINDOWS_TASKLIST . ' /FO LIST /FI "IMAGENAME eq ' . SERVER_NAME . '" 2>&1'); //$tasklist = shell_exec(WINDOWS_TASKLIST . ' 2>&1'); $found = strpos($tasklist, SERVER_NAME); if ($found === false) { $this->info['control'] = SERVER_NAME . ' Process Not Found'; return 'server.control'; } //$header = substr($tasklist, 0, 154); //$info = substr($tasklist, $found, 76); //$this->info['control'] = "$header\n$info"; $this->info['control'] = $tasklist; break; case 'start': if (!file_exists(SERVER)) { $this->info['control'] = "Error: Can not find server executable '" . SERVER . "'"; return 'server.control'; } if (!file_exists(SERVER_CONF)) { $this->info['control'] = "ERROR: Can not find server configuration file '" . SERVER_CONF . "'<br />Please create this configuration file."; return 'server.control'; } $start_cmd = 'start /B ' . SERVER . (SERVER_TESTNET ? ' -testnet ' : '') . ' -datadir=' . SERVER_DATADIR . ' -conf=' . SERVER_CONF; $this->info['control'] = "Running: {$start_cmd}\n"; try { //$this->info['control'] = shell_exec( $start_cmd. ' 2>&1'); pclose(popen("start /B " . $start_cmd, "r")); // start in background, return execution to us } catch (BitcoinClientException $e) { $this->info['control'] .= "Error: Can not start server: \nCommand: {$cmd} \nMessage: " . $e->getMessage(); } break; } // end switch return 'server.control'; break; // misc // misc case 'PHPCoinAddress': print 'DEBUG PHPCoinAddress'; $lib = 'plugins/PHPCoinAddress.php'; if (!is_readable($lib)) { print 'ERROR: missing ' . $lib; exit; } require_once $lib; $debug = $this->get_get('debug', ''); if ($debug) { CoinAddress::set_debug(true); } $reuse_keys = $this->get_get('reuse_keys', ''); if ($reuse_keys) { CoinAddress::set_reuse_keys(true); } $coins = @$_GET['coin']; if (!$coins || !is_array($coins)) { print 'ERROR: no coin type'; exit; } while (list(, $x) = each($coins)) { switch ($x) { case 'bitcoin': $bitcoin = CoinAddress::bitcoin(); break; case 'bitcoin_testnet': $bitcoin_testnet = CoinAddress::bitcoin_testnet(); break; case 'namecoin': $namecoin = CoinAddress::namecoin(); break; case 'namecoin_testnet': $namecoin_testnet = CoinAddress::namecoin_testnet(); break; case 'litecoin': $litecoin = CoinAddress::litecoin(); break; case 'litecoin_testnet': $litecoin_testnet = CoinAddress::litecoin_testnet(); break; case 'devcoin': $devcoin = CoinAddress::devcoin(); break; case 'devcoin_testnet': $devcoin_testnet = CoinAddress::devcoin_testnet(); break; case 'ppcoin': $ppcoin = CoinAddress::ppcoin(); break; case 'ppcoin_testnet': $ppcoin_testnet = CoinAddress::ppcoin_testnet(); break; } } $this->PHPCoinAddress = "\n<HR><pre>\nbitcoin : " . @$bitcoin['private'] . ' ' . @$bitcoin['public'] . "\nnamecoin: " . @$namecoin['private'] . ' ' . @$namecoin['public'] . "\ndevcoin : " . @$devcoin['private'] . ' ' . @$devcoin['public'] . "\nppcoin : " . @$ppcoin['private'] . ' ' . @$ppcoin['public'] . "\n\nbitcoin_testnet : " . @$bitcoin_testnet['private'] . ' ' . @$bitcoin_testnet['public'] . "\nnamecoin_testnet: " . @$namecoin_testnet['private'] . ' ' . @$namecoin_testnet['public'] . "\ndevcoin_testnet : " . @$devcoin_testnet['private'] . ' ' . @$devcoin_testnet['public'] . "\nppcoin_testnet : " . @$ppcoin_testnet['private'] . ' ' . @$ppcoin_testnet['public'] . "\n\ndebug:{$debug} \nreuse_keys:{$reuse_keys} \n</pre>"; return 'debug'; //return 'PHPCoinAddress'; break; case 'mtgox': include_once 'plugins/mtgox.php'; $this->info['mtgox_ticker'] = mtgox_get_ticker(); //= null_data_ticker(); switch ($this->get_get('a1', '')) { case 'depth': $this->info['mtgox_depth'] = mtgox_get_depth(); //= null_data_depth(); break; case 'trades': $this->info['mtgox_trades'] = mtgox_get_trades(); //= null_data_trades(); break; } return 'mtgox'; break; } // end switch }