public function execute(array $matches, $url, $rest) { $admin = AdminConfig::volatileLoad(); $pricingProvider = $admin->getConfig()->getPricingProvider(); $this->drain(new PricePoller($pricingProvider)); return true; }
public function execute(array $matches, $url, $rest) { $this->stopScanner(); $addr = new BitcoinAddress($matches['address']); $admin = AdminConfig::volatileLoad(); $cfg = $admin->getConfig(); $ticket = Purchase::load($cfg, Container::dispense('DB'), intval($matches['ticket'])); if (strval($addr->get()) !== strval($ticket->getCustomerAddress()->get())) { error_log("Tampering detected on ticket #" . $ticket->getId() . ' at ' . time()); return false; } $isZero = $ticket->getCurrencyAmount()->isEqualTo(new Amount("0")); if ($ticket->getStatus() !== Purchase::PENDING || $isZero === false) { header('HTTP/1.1 303 See Other'); header('Location: /start'); header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); return false; } header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); $tmpl = new Template('purchase'); $tmpl->render(['ticket' => $ticket, 'config' => $cfg]); return true; }
public function execute(array $matches, $url, $rest) { $admin = AdminConfig::volatileLoad(); $contactInfo = $admin->getConfig()->getContactInformation(); header("Content-Security-Policy: " . implode("; ", ["default-src 'self'", "script-src 'self' 'unsafe-eval'", "object-src 'none'", "media-src 'self' mediastream:", "report-uri /report;"])); $tmpl = new Template('app'); $tmpl->render([]); return true; }
public function execute(array $matches, $url, $rest) { $this->stopScanner(); $admin = AdminConfig::volatileLoad(); $contactInfo = $admin->getConfig()->getContactInformation(); $tmpl = new Template('start'); $tmpl->render(['contactInfo' => $contactInfo]); return true; }
public function execute(array $matches, $url, $rest) { $meta = AdminConfig::volatileLoad()->getConfig()->getCurrencyMeta(); $denoms = []; foreach ($meta->getDenominations() as $denom) { $denoms[] = $denom->get(); } header('Content-Type: application/javascript'); echo 'var CurrencyData = ' . JSON::encode(['symbol' => $meta->getSymbol(), 'code' => $meta->getISOCode(), 'denominations' => $denoms]) . ';'; echo 'var Languages = ' . JSON::encode(Localization::getAvailableLocales()) . ';'; return true; }
public function __construct(DB $db, BillScannerDriver $driver) { $this->db = $db; $this->driver = $driver; $admin = AdminConfig::volatileLoad(); $this->config = $admin->getConfig(); $this->currencyMeta = $this->config->getCurrencyMeta(); $this->denoms = $this->currencyMeta->getDenominations(); $this->largest = Math::max($this->denoms); $this->threshhold = $this->largest->multiplyBy(new Amount("2")); $this->lowest = Math::min($this->denoms); $this->balance = new Amount("0"); }
public function execute(array $matches, $url, $rest) { $fn = '/tmp_disk/price.json'; if (!file_exists($fn)) { return false; } $priceData = JSON::decode(file_get_contents($fn)); if (isset($priceData['error']) && $priceData['error']) { $admin = AdminConfig::volatileLoad(); $contactInfo = $admin->getConfig()->getContactInformation(); $tmpl = new Template('network-out'); $tmpl->render(['contactInfo' => $contactInfo]); return true; } return false; }
public function execute(array $matches, $url, $rest) { $fn = '/tmp_disk/price.json'; if (!file_exists($fn)) { echo JSON::encode([]); return true; } $cached = JSON::decode(file_get_contents($fn)); if (isset($cached['error']) && $cached['error']) { echo JSON::encode(['error' => true]); flush(); $admin = AdminConfig::volatileLoad(); unlink($fn); $pricingProvider = $admin->getConfig()->getPricingProvider(); $pp = new PricePoller($pricingProvider); return true; } echo JSON::encode([]); return true; }
public function execute(array $matches, $url, $rest) { $get = Container::dispense('Environment\\Get'); $cfg = AdminConfig::volatileLoad()->getConfig(); $db = Container::dispense('DB'); $p = Purchase::load($cfg, $db, $matches['ticket']); $scanner = Container::dispense('BillScannerDriver'); $scanner->stop(); $error = false; if (!empty($get['error'])) { $error = true; } $sent = false; if (!empty($get['sent'])) { $sent = true; } $tmpl = new Template('receipt'); $tmpl->render(['purchase' => $p, 'config' => $cfg, 'error' => $error, 'sent' => $sent]); return true; }
public function execute(array $matches, $url, $rest) { if (AdminConfig::needsSetup()) { header('HTTP/1.1 303 See Other'); header('Location: /admin/setup'); header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); return true; } if (AdminConfig::needsAuth()) { header('HTTP/1.1 303 See Other'); header('Location: /admin/choose'); header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); return true; } if (!file_exists('/tmp_disk/email')) { $cfg = AdminConfig::volatileLoad()->getConfig(); try { $t = new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'); $t->setUsername($cfg->getEmailUsername())->setPassword($cfg->getEmailPassword())->start(); if (strlen(trim($cfg->getEmailPassword())) < 1) { throw new Exception("no way"); } if (strlen(trim($cfg->getEmailUsername())) < 1) { throw new Exception("no way"); } file_put_contents('/tmp_disk/email', ''); } catch (Exception $e) { header('HTTP/1.1 303 See Other'); header('Location: /admin/email'); header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); return true; } } return false; }
public function execute(array $matches, $url, $rest) { $post = Container::dispense('Environment\\Post'); $cfg = AdminConfig::volatileLoad()->getConfig(); $db = Container::dispense('DB'); if (filter_var($post['email'], FILTER_VALIDATE_EMAIL) !== $post['email']) { header('HTTP/1.1 303 See Other'); header('Location: /receipt/' . intval($post['ticket']) . '?error=true'); header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); return true; } $p = Purchase::load($cfg, $db, intval($post['ticket'])); JobManager::enqueue($db, 'EmailReceipt', ['purchase_id' => $p->getId(), 'email' => $post['email']]); header('HTTP/1.1 303 See Other'); header('Location: /receipt/' . intval($post['ticket']) . '?sent=true'); header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); return true; }
public function execute(array $matches, $url, $rest) { $addr = new BitcoinAddress($matches['address']); $admin = AdminConfig::volatileLoad(); $cfg = $admin->getConfig(); $db = Container::dispense('DB'); $ticket = Purchase::create($cfg, $db, $addr); $wallet = $cfg->getWalletProvider(); $i18n = Localization::getTranslator(); $btcBalance = $wallet->getBalance(); $balance = $btcBalance->multiplyBy($ticket->getBitcoinPrice()); $threshhold = Math::max([$cfg->getMaxTransactionValue(), Math::max($cfg->getCurrencyMeta()->getDenominations())]); if ($balance->isLessThan($threshhold)) { MachineStatusEmail::reportError($cfg, $db, $i18n->_('Low balance: ') . $btcBalance->get() . ' ' . $i18n->_('bitcoin')); } header('HTTP/1.1 303 See Other'); header('Location: /purchase/' . $addr->get() . '/' . $ticket->getId()); header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); return true; }
public function execute(array $matches, $url, $rest) { $admin = AdminConfig::volatileLoad(); $config = $admin->getConfig(); $wallet = $config->getWalletProvider(); $initialBalance = $wallet->getBalance(); $interval = $this->interval(); $this->start(); while (true) { try { $balance = $wallet->getBalance(); $this->send($balance->isGreaterThan($initialBalance)); } catch (\Exception $e) { error_log($e); } usleep($interval); if (connection_aborted()) { break; } } $this->end(); return true; }