public function send($lastOverride = false) { $i18n = Localization::getTranslator(); $lastFn = '/home/pi/phplog/last-tx-sent'; $last = 0; if (file_exists($lastFn)) { $last = intval(trim(file_get_contents($lastFn))); } if ($lastOverride !== false) { $last = $lastOverride; } $csvMaker = Container::dispense('TransactionCSV'); $config = Admin::volatileLoad()->getConfig(); $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername($config->getEmailUsername())->setPassword($config->getEmailPassword()); $msg = Swift_Message::newInstance()->setSubject($config->getMachineName() . $i18n->_(': Transaction Log'))->setFrom([$config->getEmailUsername() => $config->getMachineName()])->setTo(array($config->getEmailUsername()))->setBody($i18n->_('See attached for transaction log.')); $file = $csvMaker->save($last); if (!$file) { throw new Exception('Unable to save CSV'); } $msg->attach(Swift_Attachment::fromPath($file)); file_put_contents($lastFn, $csvMaker->getLastID()); $mailer = Swift_Mailer::newInstance($transport); if (!$mailer->send($msg)) { throw new Exception('Unable to send: unkown cause'); } }
/** * Creates a routing handler which instantiates and uses a class * as the next step in routing * * @param string $classname class to instantiate * @throws UnexpectedValueException when Controller is not implemented by the * classname in question * @return mixed result of routing, false if not matched */ public static function lazyLoad($classname) { return function ($matches, $url, $rest) use($classname) { $routable = Container::dispense($classname); if ($routable instanceof Controller) { return $routable->execute($matches, $url, $rest); } throw new UnexpectedValueException($classname . " does not implement Controller"); }; }
/** * Bind a concrete class to an abstraction name * * @param string $abstract class or interface name * @param string $concrete class that implements/extends $abstract * @param boolean $overwrite whether or not this binding supercedes previous ones * @return void * @throws ContainerException when the type is already registered */ public static function bind($abstract, $concrete, $overwrite = false) { $abstract = self::cleanName($abstract); $concrete = self::cleanName($concrete); if (!$overwrite && isset(self::$builderMap[$abstract])) { throw new ContainerException("Type '{$abstract}' already regisered."); } self::$builderMap[$abstract] = function () use($concrete) { return Container::dispense($concrete); }; }
public static function normalize(Post $post) { $config = Container::dispense('Config'); $normalized = ['email' => ['username' => @$post['email']['username'], 'password' => @$post['email']['password'], 'machine' => @$post['email']['machine']], 'walletProvider' => ['provider' => 'WalletProviders\\Blockchain'], 'pricingProvider' => [], 'contact' => ['information' => @$post['contact']['information']], 'transaction-cron' => false, 'transactions' => ['maximum' => @$post['transactions']['maximum']]]; if (empty($normalized['email']['machine'])) { $normalized['email']['machine'] = 'Project Skyhook 00'; } $normalized['transaction-cron'] = $post['transaction-cron'] === "on"; $blockchain =& $normalized['walletProvider']; $blockchain['id'] = @$post['wallet']['id']; $blockchain['mainPass'] = @$post['wallet']['mainPass']; $blockchain['secondPass'] = @$post['wallet']['secondPass']; $blockchain['fromAddress'] = @$post['wallet']['fromAddress']; $normalized['pricingProvider'] = self::normalizePricingSettings($post); return $normalized; }
public static function normalize(Post $post) { $config = Container::dispense('Config'); $normalized = ['email' => ['username' => @$post['email']['username'], 'password' => @$post['email']['password'], 'machine' => @$post['email']['machine']], 'walletProvider' => ['provider' => 'WalletProviders\\Blockchain'], 'pricingProvider' => [], 'contact' => ['information' => @$post['contact']['information']], 'transaction-cron' => false, 'transactions' => ['maximum' => @$post['transactions']['maximum']]]; if (empty($normalized['email']['machine'])) { $normalized['email']['machine'] = 'Project Skyhook 00'; } $normalized['transaction-cron'] = $post['transaction-cron'] === "on"; $walletProvider =& $normalized['walletProvider']; $providerId = $post['walletProviderId']; $walletProvider['providerId'] = $providerId; if ($providerId == 1) { $walletProvider['provider'] = 'WalletProviders\\Blockchain'; } else { if ($providerId == 2) { $walletProvider['provider'] = 'WalletProviders\\CoinbaseWallet'; } else { if ($providerId == 3) { $walletProvider['provider'] = 'WalletProviders\\Dummy'; } } } # BlockChain Fields $walletProvider['id'] = @$post['wallet']['id']; $walletProvider['mainPass'] = @$post['wallet']['mainPass']; $walletProvider['secondPass'] = @$post['wallet']['secondPass']; $walletProvider['fromAddress'] = @$post['wallet']['fromAddress']; # Coinbase Fields $walletProvider['coinbaseAccountId'] = @$post['wallet']['coinbaseAccountId']; $walletProvider['coinbaseApiKey'] = @$post['wallet']['coinbaseApiKey']; $walletProvider['coinbaseApiSecret'] = @$post['wallet']['coinbaseApiSecret']; # TODO Future enhancement (auto-repurchase BTC) $walletProvider['coinbaseRepurchaseEnabled'] = $post['coinbaseRepurchaseEnabled'] === "1"; #$walletProvider['coinbasePaymentMethodId'] = $post['coinbasePaymentMethodId']; if ($post->offsetExists('coinbasePaymentMethodId')) { $walletProvider['coinbasePaymentMethodId'] = $post['coinbasePaymentMethodId']; } else { $walletProvider['coinbasePaymentMethodId'] = '0'; } #$walletProvider['coinbasePaymentChoices'] = $post['coinbasePaymentChoices']; $normalized['pricingProvider'] = self::normalizePricingSettings($post); return $normalized; }
} $cookies = Container::dispense("Environment\\Cookie"); if (isset($cookies['lang']) && Localization::localePresent($cookies['lang'])) { Localization::setLocale($cookies['lang']); } Container::registerSingleton('Environment\\RequestHeaders', function () { $headers = getallheaders(); return new Environment\RequestHeaders($headers); }); foreach (array('Delete', 'Put') as $wrapper) { Container::registerSingleton($wrapper, function () use($wrapper) { $server = Container::dispense(Environment\Server); $nsed = "Environment\\" . $wrapper; $wrapped = $nsed::buildHelper($server); return new $nsed($wrapped); }); } Container::registerSingleton('DB', function () { return new DB(new DateTimeZone(trim(file_get_contents('/etc/timezone')))); }); date_default_timezone_set(trim(file_get_contents('/etc/timezone'))); $router = Container::dispense("Router"); $server = Container::dispense('Environment\\Server'); $result = $router->resolve($server->pageUrl(), [['/on$', function () { echo JSON::encode(['on' => !file_exists('command')]); return true; }], ['/settings.js', Router::lazyLoad('Controllers\\SettingsData')], ['/test-price$', Router::lazyLoad('Controllers\\Ajax\\TestPrice')], ['/admin', Router::lazyLoad('Controllers\\Admin')], ['', Container::dispense('Controllers\\ConfigChecker')], ['/check-balance', Router::lazyLoad('Controllers\\CheckBalance')], ['/finalize/:ticket$', Router::lazyLoad('Controllers\\Ajax\\FinalizePurchase')], ['/ajax', Router::lazyLoad('Controllers\\Ajax')], ['/validate/:address$', Router::lazyLoad('Controllers\\Ajax\\ValidateBitcoinAddress')], ['/add-email-to-ticket/:ticket', Router::lazyLoad('Controllers\\Ajax\\AddEmailToTicket')], ['/nettest', Router::lazyLoad('Controllers\\NetworkTester')], ['/receipt/:ticket$', Router::lazyLoad('Controllers\\Receipt')], ['/error/:ticket$', Router::lazyLoad('Controllers\\Error')], ['/purchase/:address/:ticket$', Router::lazyLoad('Controllers\\FinishPurchase')], ['/price$', Router::lazyLoad('Controllers\\Price')], ['/billscan-balance/:ticket$', Router::lazyLoad('Controllers\\BillScannerBalance')], ['/email-receipt', Router::lazyLoad('Controllers\\EmailReceipt')], ['/start-purchase/:address$', Router::lazyLoad('Controllers\\Ajax\\StartPurchase')], ['', Container::dispense('Controllers\\ConnectivityChecker')], ['/start$', Router::lazyLoad('Controllers\\Start')], ['/account$', Router::lazyLoad('Controllers\\Account')], ['/purchase/:address$', Router::lazyLoad('Controllers\\StartPurchase')], ['/bust$', Router::lazyLoad('Controllers\\CacheBust')], ['/?$', Router::lazyLoad('Controllers\\Start')], ['', function () { header('HTTP/1.1 404 Not Found.'); echo '404 Not Found.'; return true; }]]);
} $cookies = Container::dispense("Environment\\Cookie"); if (isset($cookies['lang']) && Localization::localePresent($cookies['lang'])) { Localization::setLocale($cookies['lang']); } Container::registerSingleton('Environment\\RequestHeaders', function () { $headers = getallheaders(); return new Environment\RequestHeaders($headers); }); foreach (array('Delete', 'Put') as $wrapper) { Container::registerSingleton($wrapper, function () use($wrapper) { $server = Container::dispense(Environment\Server); $nsed = "Environment\\" . $wrapper; $wrapped = $nsed::buildHelper($server); return new $nsed($wrapped); }); } Container::registerSingleton('DB', function () { return new DB(new DateTimeZone(trim(file_get_contents('/etc/timezone')))); }); date_default_timezone_set(trim(file_get_contents('/etc/timezone'))); $router = Container::dispense("Router"); $server = Container::dispense('Environment\\Server'); $result = $router->resolve($server->pageUrl(), [['/on$', function () { echo JSON::encode(['on' => !file_exists('command')]); return true; }], ['/settings.js', Router::lazyLoad('Controllers\\SettingsData')], ['/test-price$', Router::lazyLoad('Controllers\\Ajax\\TestPrice')], ['/coinbase-data$', Router::lazyLoad('Controllers\\Ajax\\CoinbaseData')], ['/admin', Router::lazyLoad('Controllers\\Admin')], ['', Container::dispense('Controllers\\ConfigChecker')], ['/check-balance', Router::lazyLoad('Controllers\\CheckBalance')], ['/bill-acceptor/disable$', Router::lazyLoad('Controllers\\ScannerStopper')], ['/finalize/:ticket$', Router::lazyLoad('Controllers\\Ajax\\FinalizePurchase')], ['/validate/:address$', Router::lazyLoad('Controllers\\Ajax\\ValidateBitcoinAddress')], ['/add-email-to-ticket/:ticket', Router::lazyLoad('Controllers\\Ajax\\AddEmailToTicket')], ['/nettest', Router::lazyLoad('Controllers\\NetworkTester')], ['/price$', Router::lazyLoad('Controllers\\Price')], ['/billscan-balance/:ticket$', Router::lazyLoad('Controllers\\BillScannerBalance')], ['/email-receipt', Router::lazyLoad('Controllers\\EmailReceipt')], ['/start-purchase/:address$', Router::lazyLoad('Controllers\\Ajax\\StartPurchase')], ['', Container::dispense('Controllers\\ConnectivityChecker')], ['/bust$', Router::lazyLoad('Controllers\\CacheBust')], ['/(start)?$', Router::lazyLoad('Controllers\\App')], ['', function () { header('HTTP/1.1 404 Not Found.'); echo '404 Not Found.'; return true; }]]);
public static function test() { require_once __DIR__ . '/autoload.php'; $b = new BillLogCSV(Container::dispense('DB')); echo "CSV Saved as: ", $b->save(19), "\n"; }