<?php
 class vB_Request_Cli extends vB_Request { public function __construct() { if (!$this->isCLI()) { echo "cannot use vB CLI scripts from the web"; exit; } $this->sessionClass = 'vB_Session_Cli'; $this->ipAddress = '127.0.0.1'; $this->altIp = '127.0.0.1'; $this->userAgent = 'PHP CLI'; $this->referrer = 'PHP CLI'; parent::__construct(); } public function createSessionForUsername($username) { if (!$username) { return $this->createSessionForUser(0); } $db = vB::getDbAssertor(); $userid = $db->getField('user', ['username' => $username, vB_dB_Query::COLUMNS_KEY => ['userid']]); if ($userid) { return $this->createSessionForUser($userid); } else { $this->createSessionForUser(0); throw new vB_Exception_Api('invalid_username'); } } private function isCLI() { if(!defined('STDIN') AND (substr(PHP_SAPI, 0, 3) == 'cgi')) { return empty($_SERVER['REQUEST_METHOD']); } return defined('STDIN'); } } 