Example #1
0
 protected function setUp()
 {
     self::$config['testdb']['dbname'] = null;
     $db = DriverManager::getConnection(self::$config['testdb']);
     $sm = $db->getSchemaManager();
     $sm->dropAndCreateDatabase(self::$database);
     $db->close();
     self::$config['testdb']['dbname'] = self::$database;
     $this->db = DriverManager::getConnection(self::$config['testdb']);
     $driver = str_replace('pdo_', '', self::$config['testdb']['driver']);
     $sqlFile = file_get_contents(Cerberus::getPath() . '/cerberus.' . $driver . '.sql');
     $sqlArray = explode(';', $sqlFile);
     foreach ($sqlArray as $sqlCommand) {
         $sqlCommand = trim($sqlCommand);
         if (empty($sqlCommand) === false) {
             $this->db->query($sqlCommand . ';');
         }
     }
     self::$config['db'] = self::$config['testdb'];
     $this->irc = new Irc(self::$config);
     $this->irc->setLanguage('en');
     $this->irc->getConsole()->disableOutput();
     $this->irc->init();
     $this->invokeMethod($this->irc, 'loadPlugin', 'test');
 }
Example #2
0
 /**
  * @param string $host
  */
 public function setHost($host)
 {
     if ($_GET['pw'] === md5($this->config['frontend']['password'])) {
         $path = Cerberus::getPath();
         $content = file_get_contents($path . '/config.ini');
         $content = preg_replace('/host\\ \\=\\ [0-9\\.]+/', 'host = ' . $host, $content);
         file_put_contents($path . '/config.ini', $content);
     }
 }
Example #3
0
 /**
  *
  */
 protected function wait()
 {
     Cerberus::msleep(self::TIME);
 }
Example #4
0
 /**
  * @covers Hermes\Api\Client::doRequest
  * @covers Hermes\Api\Client::get
  * @covers Hermes\Api\Client::isAvailable
  * @covers Hermes\Api\Client::reportSuccess
  * @covers Hermes\Api\Client::reportFailure
  */
 public function testGetNotAvailableWithCircuitBreaker()
 {
     $storage = StorageFactory::factory(['adapter' => ['name' => 'memory', 'options' => ['namespace' => 'test']], 'plugins' => ['exception_handler' => ['throw_exceptions' => false]]]);
     $storage->flush();
     $cerberus = new Cerberus($storage, 2, 2);
     $cerberus->reportFailure();
     $cerberus->reportFailure();
     $cerberus->reportFailure();
     $this->object->setCircuitBreaker($cerberus);
     $client = new \Zend\Http\Client('http://127.0.0.1:1', []);
     $this->object->setZendClient($client);
     $this->setExpectedException(NotAvailableException::class);
     $this->object->get('/');
 }
Example #5
0
 /**
  * @param string $text
  * @param bool $escape
  * @param mixed $length
  * @param bool $break
  * @param bool $wordwrap
  * @param int $offset
  * @return string
  */
 public function prepare($text, $escape = true, $length = null, $break = true, $wordwrap = true, $offset = 0)
 {
     if (isset($this->param) && is_array($this->param) && in_array('-noconsole', $this->param, true)) {
         return $escape ? $this->escape($text) : $text;
     }
     $formatter = FormatterFactory::console();
     $text = $formatter->bold($text);
     $text = $formatter->underline($text);
     $text = $formatter->color($text);
     if ($length === false) {
         $text .= substr($text, -1) === '\\' ? ' ' : '';
         return $escape ? $this->escape($text) : $text;
     }
     if ($length === null) {
         if (Cerberus::isExecAvailable() === false) {
             return $escape ? $this->escape($text) : $text;
         }
         preg_match('/columns\\s([0-9]+);/', strtolower(exec('stty -a | grep columns')), $matches);
         if (isset($matches[1]) === false) {
             return $escape ? $this->escape($text) : $text;
         }
         $length = $matches[1];
     }
     $length = $length - $offset;
     if ($this->len($text) <= $length) {
         $text .= substr($text, -1) === '\\' ? ' ' : '';
         return $escape ? $this->escape($text) : $text;
     }
     $text = utf8_decode($text);
     if ($break === true) {
         if ($wordwrap === true) {
             $text = $this->wordwrap($text, $length);
         } else {
             $text = $this->split($text, $length, PHP_EOL);
         }
         $text = str_replace(PHP_EOL, PHP_EOL . str_repeat(' ', $offset), $text);
     } else {
         $text = $this->cut($text, $length - 3) . '...';
         if (strpos($text, "") !== false) {
             $text .= "";
         }
     }
     $text = utf8_encode($text);
     $text .= substr($text, -1) === '\\' ? ' ' : '';
     return $escape ? $this->escape($text) : $text;
 }
Example #6
0
 function boolval($var)
 {
     return Cerberus::boolval($var);
 }
Example #7
0
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, see <http://www.gnu.org/licenses/>.
 */
if (version_compare(phpversion(), '5.4.0', '<') === true) {
    echo 'Your version of PHP is ' . phpversion() . PHP_EOL;
    echo 'PHP 5.4.0 or higher is required' . PHP_EOL;
    exit;
}
error_reporting(-1);
date_default_timezone_set('Europe/Berlin');
set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) {
    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
chdir(__DIR__);
if (file_exists('../vendor/autoload.php')) {
    require_once '../vendor/autoload.php';
} else {
    echo 'You must set up the project dependencies, run the following commands:' . PHP_EOL;
    echo 'curl -s https://getcomposer.org/installer | php' . PHP_EOL;
    echo 'php composer.phar install' . PHP_EOL;
    exit;
}
use Cerberus\Cerberus;
try {
    $cerberus = new Cerberus();
    $cerberus->setParam($argv);
    $cerberus->run();
} catch (Exception $e) {
    Cerberus::error($e->getMessage());
}
Example #8
0
    $bots = $db->getActiveBotList();
    $botCount = 0;
    if ($bots) {
        exec('ps -e | grep php', $output);
        $pidList = [];
        foreach ($output as $line) {
            $data = explode(' ', trim(preg_replace('/[ ]+/', ' ', $line)));
            if ($data[3] === 'php') {
                $pidList[] = $data[0];
            }
        }
        foreach ($bots as $bot) {
            if (in_array($bot['pid'], $pidList, true) === true) {
                $botCount++;
                Cerberus::sysinfo('Bot ' . $bot['id'] . ' is running. PID: ' . $bot['pid']);
            } else {
                $db->cleanupBot($bot['id']);
                $db->shutdownBot($bot['id']);
                Cerberus::sysinfo('Bot ' . $bot['id'] . ' is not running.');
            }
        }
    }
    if ($botCount === 0) {
        Cerberus::sysinfo('start a new bot.');
        $logDirectory = rtrim(trim($config['log']['directory']), '/');
        if (is_dir($logDirectory) === false) {
            mkdir($logDirectory);
        }
        exec(Cerberus::getPath() . '/bin/bot.php -noconsole > ' . $logDirectory . '/log.txt 2>&1 &');
    }
}
Example #9
0
 /**
  * @param string $param
  * @return mixed
  */
 public function topic($param)
 {
     $topic = $this->getActions()->topic($_SESSION['channel'], $param);
     Cerberus::msleep(2000);
     $status = $this->getDb()->getStatus([403, 442, 482]);
     if ($status !== null) {
         return $status;
     }
     return $topic;
 }
Example #10
0
 /**
  * @param string $file
  */
 public function loadTranslationFile($file)
 {
     $translationsFileStatus = Cerberus::getPath() . '/resources/translations/' . $this->language . '/' . $file . '.php';
     if (file_exists($translationsFileStatus) === true) {
         $this->addResource('file', $translationsFileStatus, $this->language);
     }
 }
Example #11
0
 /**
  * @param Event $event
  */
 protected static function runPhpUnit(Event $event)
 {
     $io = $event->getIO();
     if (file_exists(Cerberus::getPath() . '/vendor/bin/phpunit') === false) {
         $io->write('<error>Can\'t find "PHPUnit".</error>');
     } elseif (Cerberus::isExecAvailable() === false) {
         $io->write('<error>Can\'t run "PHPUnit", because "exec" is disabled.</error>');
     } else {
         $output = [];
         exec(Cerberus::getPath() . '/vendor/bin/phpunit', $output);
         foreach ($output as $line) {
             $io->write('<comment>' . $line . '</comment>');
         }
     }
 }