Example #1
0
 /**
  * Render the build log.
  *
  * @return string
  */
 public function render()
 {
     $converter = new AnsiToHtmlConverter(new SolarizedXTermTheme());
     $string = $converter->convert($this->load());
     foreach ($this->tags as $sourceTag => $targetClass) {
         $string = preg_replace('/&lt;' . $sourceTag . '&gt;([^<]+)&lt;\\/' . $sourceTag . '&gt;/iU', '<span class="text-' . $targetClass . '">\\1</span>', $string);
     }
     return $string;
 }
Example #2
0
 public function show($id)
 {
     $history = EnvironmentHistory::findOrFail($id);
     $theme = new SolarizedTheme();
     $converter = new AnsiToHtmlConverter($theme, false);
     $css = $theme->asCss();
     $output = $converter->convert($history->history);
     return view('history.show', ['history' => $history, 'output' => $output, 'css' => $css]);
 }
 protected function callFromBrowser(SS_HTTPRequest $request)
 {
     $input = new ArrayInput(['command' => $request->param('ID')]);
     $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true);
     $this->application->run($input, $output);
     // return the output
     $converter = new AnsiToHtmlConverter();
     $content = $output->fetch();
     return ['ConsoleOutput' => $converter->convert($content)];
 }
Example #4
0
 /**
  * Callback to handle POST requests.
  */
 function post_log()
 {
     // TODO: figure out how to use the D8 API for this, instead of our function.
     #$params = \Drupal::request()->query->all();
     $params = $this->_urldecode(file_get_contents('php://input'));
     $converter = new AnsiToHtmlConverter();
     $task = array('task_id' => $params['task_id'], 'task_ref_id' => $params['task_ref_id'], 'task_sequence' => $params['task_sequence'], 'timestamp' => $params['timestamp'], 'task_output_raw' => $params['task_output'], 'task_output' => $converter->convert($params['task_output']));
     db_insert('ran_queue_task_log')->fields($task)->execute();
     $r = new Response();
     #$r->setStatusCode(418);
     return $r;
 }
 public function showAction($id)
 {
     $path = $this->getRunStorage()->getOutputFilePath($id);
     $content = file_get_contents($path);
     if (false !== strpos($content, '<html')) {
         $template = 'outputFile_html.html.twig';
     } else {
         $converter = new AnsiToHtmlConverter();
         $content = $converter->convert($content);
         $template = 'outputFile_text.html.twig';
     }
     return $this->render($template, array('content' => $content));
 }
Example #6
0
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
$converter = new AnsiToHtmlConverter();
$html = $converter->convert($data['log']);
?>

File log : <code><?php 
echo $data['log_file'];
?>
</code><br /><br />
<pre id="data_log" style="background-color: black; overflow: auto; height:500px; padding: 10px 15px; font-family: monospace;"><?php 
echo $html;
?>
</pre>
Example #7
0
 /**
  * @Route("/job/status/{job}", name="job.status"))
  */
 public function jobStatusAction(Job $job, Request $request)
 {
     $theme = new Theme();
     $converter = new AnsiToHtmlConverter($theme);
     return $this->render('job/status.html.twig', ['job' => $job, 'output' => $converter->convert($job->getOutput())]);
 }
Example #8
0
 /**
  * @param InputInterface  $input  Input
  * @param OutputInterface $output Output
  *
  * @return null
  * @throws \Exception
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $systemTools = new SystemTools($output);
     $dir = $input->getOption('dir');
     $url = $input->getOption('url');
     $silent = $input->getOption('silent');
     $pullBranch = $input->getOption('pull-branch');
     $pullSHA = $input->getOption('pull-sha');
     $pullRepository = $input->getOption('pull-repository');
     $pullForce = $input->getOption('pull-force');
     $pullId = $input->getOption('pull-id');
     $update = $input->getOption('update');
     $branch = $input->getArgument('branch');
     if ($pullSHA && !$pullBranch) {
         // Check if we recorded this SHA in the directory
         if ($infos = $systemTools->getRecordedSHA($dir, $pullSHA)) {
             $url = $infos['url'];
             $pullBranch = $infos['pull-branch'];
             $pullRepository = $infos['pull-repository'];
             $pullId = $infos['pull-id'];
             $branch = $infos['branch'];
         } else {
             throw new \Exception('No SHA record found in the directory.');
         }
     }
     $pullDir = $systemTools->sanitizeBranchName($pullBranch);
     if (!$branch) {
         $branch = trim(substr(file_get_contents($dir . '/.git/HEAD'), 16));
         if (empty($branch)) {
             $branch = 'master';
         }
     }
     $newDir = date('YmdHis');
     $baseDir = $dir;
     if (!$silent) {
         $outputFile = $dir . '/logs/install-' . $newDir . '.log';
         $systemTools->setOutputFile($outputFile);
     }
     $systemTools->changeDirectory($baseDir);
     if ($url) {
         $systemTools->executeCommand('git clone ' . $url . ' ' . $newDir);
         $dir .= '/' . $newDir;
         $systemTools->changeDirectory($dir);
         if ($pullBranch) {
             $systemTools->executeCommand('git checkout ' . $pullBranch);
         } else {
             $systemTools->executeCommand('git checkout ' . $branch);
         }
     } elseif ($update) {
         $systemTools->executeCommand('git pull origin');
     }
     $yaml = ConfigTools::getRepositoryConfig($dir);
     $cmds = [];
     if ($pullRepository && $pullSHA && !$pullForce) {
         $statuses = [];
         if (isset($yaml['pulls']) && is_array($yaml['pulls']) && isset($yaml['pulls']['statuses']) && is_array($yaml['pulls']['statuses'])) {
             foreach ($yaml['pulls']['statuses'] as $status) {
                 $statuses[] = $status;
             }
             $output->writeln('Required green statuses: ' . implode(', ', $statuses) . '.');
         }
         if (!ServiceTools::hasOnlyGreenGitHubStatuses($pullRepository, $pullSHA, $statuses)) {
             $output->writeln('All required statuses are not green, waiting.');
             ServiceTools::sendGitHubStatus($pullRepository, $pullSHA, 'pending', null, 'Waiting for all statuses to succeed.');
             $infos = ['dir' => $baseDir, 'url' => $url, 'pull-branch' => $pullBranch, 'pull-repository' => $pullRepository, 'pull-id' => $pullId, 'branch' => $branch];
             $systemTools->recordSHA($baseDir, $pullSHA, $infos);
             // If we cloned the git repo, remove it, it's useless.
             if ($baseDir != $dir) {
                 $systemTools->executeCommand('rm -Rf ' . $dir);
             }
             return null;
         } else {
             $output->writeln('All required statuses are green.');
             $systemTools->deleteRecordedSHA($baseDir, $pullSHA);
         }
     }
     if ($pullRepository && $pullSHA) {
         ServiceTools::sendGitHubStatus($pullRepository, $pullSHA, 'pending', null, 'Shipping…');
     }
     if (isset($yaml[$branch]) && is_array($yaml[$branch])) {
         $cmds = $yaml[$branch];
     } elseif (isset($yaml['all']) && is_array($yaml['all'])) {
         $cmds = $yaml['all'];
     }
     // Overridings commands with pull commands
     if ($pullBranch && isset($yaml['pulls']['commands']) && is_array($yaml['pulls']['commands'])) {
         $cmds['commands'] = $yaml['pulls']['commands'];
     }
     $systemTools->putEnvVar('TERM=VT100');
     if ($pullBranch) {
         $systemTools->putEnvVar('CURRENT_BRANCH=' . $pullBranch);
         $systemTools->putEnvVar('CURRENT_BRANCH_SANITIZED=' . $systemTools->sanitizeBranchName($pullBranch));
         $systemTools->putEnvVar('CURRENT_PULL_ID=' . $pullId);
     } else {
         $systemTools->putEnvVar('CURRENT_BRANCH=' . $branch);
         $systemTools->putEnvVar('CURRENT_BRANCH_SANITIZED=' . $systemTools->sanitizeBranchName($branch));
     }
     $repoBaseDir = null;
     if ($url && isset($cmds['release']) && is_array($cmds['release'])) {
         if ($pullBranch) {
             if (!is_dir($baseDir . '/pulls')) {
                 mkdir($baseDir . '/pulls');
             }
             if (!is_dir($baseDir . '/pulls/' . $pullDir)) {
                 mkdir($baseDir . '/pulls/' . $pullDir);
             }
             $repoBaseDir = $baseDir . '/pulls/' . $pullDir;
         } else {
             if (!is_dir($baseDir . '/' . $cmds['release']['directory'])) {
                 mkdir($baseDir . '/' . $cmds['release']['directory']);
             }
             $repoBaseDir = $baseDir . '/' . $cmds['release']['directory'];
         }
         if (!is_dir($repoBaseDir . '/shared')) {
             mkdir($repoBaseDir . '/shared');
         }
         if (!is_dir($repoBaseDir . '/releases')) {
             mkdir($repoBaseDir . '/releases');
         }
         rename($baseDir . '/' . $newDir, $repoBaseDir . '/releases/' . $newDir);
         $systemTools->changeDirectory($repoBaseDir . '/releases/' . $newDir);
     } elseif ($url) {
         throw new \Exception('You cannot set a Git clone URL without any release info.');
     }
     $systemTools->putEnvVar('RELEASE_DIR=' . $repoBaseDir . '/current');
     if (isset($cmds['env']) && is_array($cmds['env'])) {
         foreach ($cmds['env'] as $env) {
             $systemTools->putEnvVar($env, true);
         }
     }
     if ($pullBranch && isset($yaml['pulls']) && is_array($yaml['pulls']) && isset($yaml['pulls']['env']) && is_array($yaml['pulls']['env'])) {
         foreach ($yaml['pulls']['env'] as $env) {
             $systemTools->putEnvVar($env, true);
         }
     }
     if ($pullBranch && isset($yaml['pulls']) && is_array($yaml['pulls']) && isset($yaml['pulls']['open']) && is_array($yaml['pulls']['open'])) {
         foreach ($yaml['pulls']['open'] as $cmd) {
             $systemTools->executeCommand($cmd, $output, true);
         }
     }
     if ($url && isset($cmds['release']['shared']) && is_array($cmds['release']['shared'])) {
         foreach ($cmds['release']['shared'] as $item) {
             $output->writeln('Linking shared item ' . $item);
             $systemTools->executeCommand('rm -Rf ' . $repoBaseDir . '/releases/' . $newDir . $item . ' && ln -fs ' . $repoBaseDir . '/shared' . $item . ' ' . $repoBaseDir . '/releases/' . $newDir . $item);
         }
     }
     if (isset($cmds['commands']) && is_array($cmds['commands'])) {
         foreach ($cmds['commands'] as $cmd) {
             $systemTools->executeCommand($cmd, $output, true);
         }
     }
     if (is_array($cmds['release'])) {
         if (isset($cmds['release']['after']) && is_array($cmds['release']['after'])) {
             foreach ($cmds['release']['after'] as $cmd) {
                 $systemTools->executeCommand($cmd);
             }
         }
         if ($url) {
             if (isset($cmds['release']['keep']) && is_numeric($cmds['release']['keep']) && $cmds['release']['keep'] > 0) {
                 $dirs = glob($repoBaseDir . '/releases/*', GLOB_ONLYDIR);
                 rsort($dirs);
                 $i = 0;
                 foreach ($dirs as $dir) {
                     $i++;
                     if ($i > $cmds['release']['keep']) {
                         $output->writeln('Removing extra release ' . basename($dir));
                         $systemTools->executeCommand('rm -Rf ' . $dir);
                     }
                 }
             }
             $output->writeln('Linking release ' . $newDir);
             $systemTools->executeCommand('ln -sf ' . $repoBaseDir . '/releases/' . $newDir . ' ' . $repoBaseDir . '/releases/current && mv ' . $repoBaseDir . '/releases/current ' . $repoBaseDir . '/');
         } elseif (isset($cmds['release']['standalone']) && is_array($cmds['release']['standalone'])) {
             foreach ($cmds['release']['standalone'] as $cmd) {
                 $systemTools->executeCommand($cmd);
             }
         }
     }
     $config = ConfigTools::getLocalConfig(['after' => []]);
     if (is_array($config) && isset($config['after']) && is_array($config['after'])) {
         foreach ($config['after'] as $cmd) {
             $systemTools->executeCommand($cmd, $output, true);
         }
     }
     if (!$silent && is_array($cmds['release']) && null !== $outputFile) {
         $config = ConfigTools::getLocalConfig(['email' => ['sender' => null, 'address' => null, 'host' => null, 'port' => 25, 'user' => null, 'password' => null]]);
         $outputResult = $systemTools->cleanAnsiColors(file_get_contents($outputFile));
         exec('git log -1 --pretty=%B', $sysOutput);
         $lastCommit = trim(implode("\n", $sysOutput));
         if ($pullBranch && isset($yaml['pulls']) && is_array($yaml['pulls']) && isset($yaml['pulls']['url'])) {
             $liveUrl = sprintf($yaml['pulls']['url'], $pullDir);
         } else {
             $liveUrl = $cmds['release']['url'];
         }
         if ($pullRepository && $pullSHA) {
             ServiceTools::sendGitHubStatus($pullRepository, $pullSHA, 'success', $liveUrl, 'Staging environment has been updated.');
         }
         if (isset($yaml['emails']) && is_array($yaml['emails'])) {
             if (!empty($yaml['emails']['host'])) {
                 $transport = \Swift_SmtpTransport::newInstance($yaml['emails']['host'], $yaml['emails']['port']);
                 if (!empty($yaml['emails']['user'])) {
                     $transport->setUsername($yaml['emails']['user']);
                 }
                 if (!empty($yaml['emails']['password'])) {
                     $transport->setPassword($yaml['emails']['password']);
                 }
             } else {
                 $transport = \Swift_MailTransport::newInstance();
             }
             $mailer = \Swift_Mailer::newInstance($transport);
             $converter = new AnsiToHtmlConverter();
             $html = $converter->convert(file_get_contents($outputFile));
             $message = \Swift_Message::newInstance('WebHook ' . $cmds['release']['name'])->setFrom(array($config['email']['address'] => $config['email']['sender']))->setTo($yaml['emails'])->setBody('<html><body><pre style="background-color: black; overflow: auto; padding: 10px 15px; font-family: monospace;">' . $html . '</pre></body></html>', 'text/html')->addPart($outputResult, 'text/plain');
             $result = $mailer->send($message);
         }
         if (isset($yaml['slack']) && is_array($yaml['slack']) && !empty($yaml['slack']['url']) && !empty($yaml['slack']['channel'])) {
             $config = ConfigTools::getLocalConfig(['messages' => ['New release']]);
             if (!isset($config['messages']) || !is_array($config['messages'])) {
                 $config = ['messages' => ['New release']];
             }
             $randMessage = $config['messages'][array_rand($config['messages'])];
             $name = $cmds['release']['name'];
             $launched = $randMessage . ': <' . $liveUrl . '|' . $name . '>';
             if (empty($liveUrl)) {
                 $launched = $randMessage . ': ' . $name;
             } elseif (empty($name) && !empty($liveUrl)) {
                 $launched = $randMessage . ': <' . $liveUrl . '>';
             }
             if (!empty($liveUrl) || !empty($name)) {
                 if ($pullBranch) {
                     $title = 'Pull Request from ' . $pullBranch;
                 } else {
                     $title = 'Release from ' . $branch;
                 }
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $yaml['slack']['url']);
                 curl_setopt($ch, CURLOPT_USERAGENT, 'gonetcats/hooks');
                 curl_setopt($ch, CURLOPT_HEADER, 0);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: token ' . $config['github']['token']]);
                 curl_setopt($ch, CURLOPT_POST, 1);
                 curl_setopt($ch, CURLOPT_POSTFIELDS, ['payload' => json_encode(['channel' => $yaml['slack']['channel'], 'pretext' => $launched, 'fallback' => $launched, 'color' => '#B8CB82', 'fields' => [['title' => $title, 'value' => 'Last commit: ' . $lastCommit, 'short' => false]]])]);
                 $data = curl_exec($ch);
                 curl_close($ch);
             }
         }
     }
     return null;
 }
Example #9
0
    echo '</td>';
    echo '<td style="' . $style . '">' . '<input type="checkbox" name="monitored[' . $server['id'] . ']" ' . ($server['is_monitored'] == 1 ? 'checked="checked"' : '') . '" />' . '</td>';
    echo '<td style="' . $style . '">' . $server['client'] . '</td>';
    echo '<td style="' . $style . '">' . $server['environment'] . '</td>';
    echo '<td style="' . $style . '"><a href="' . LINK . 'server/listing/id/' . $server['id'] . '">' . str_replace('_', '-', $server['name']) . '</a></td>';
    echo '<td style="' . $style . '">' . $server['ip'] . '</td>';
    echo '<td style="' . $style . '">' . $server['port'] . '</td>';
    echo '<td style="' . $style . '">' . $server['login'] . '</td>';
    Crypt::$key = CRYPT_KEY;
    //$passwd = Crypt::decrypt($server['passwd']);
    //echo '<td style="' . $style . '">' . $passwd . '</td>';
    echo '<td style="' . $style . '">' . '***' . '</td>';
    //echo '<td style="'.$style.'">'.$server['hostname'].'</td>';
    echo '<td style="' . $style . '">' . $server['version'] . '</td>';
    echo '<td style="' . $style . '">' . $server['date_refresh'] . '</td>';
    echo '<td style="max-width:600px;' . $style . '" class="">';
    if (strstr($server['error'], '[0m') || strstr($server['error'], 'Call Stack:')) {
        $converter = new AnsiToHtmlConverter();
        $html = $converter->convert($server['error']);
        echo '<pre style="background-color: black; overflow: auto; height:500px; padding: 10px 15px; font-family: monospace;">' . $html . '</pre>';
        //$server['error'];
    } else {
        echo str_replace("\n", '<br>', trim($server['error']));
    }
    echo '</td>';
    echo '</tr>';
}
echo '</table>';
echo '<input type="hidden" name="is_monitored" value="1" />';
echo '<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Update</button>';
echo '</form>';
 public function connect(Application $app)
 {
     $controller = new ControllerCollection(new Route());
     $controller->get('/media/{instance}', function ($instance) use($app) {
         if (!preg_match('/^[a-z]+$/', $instance)) {
             die('Wrong instance name. Should be [a-z]+');
         }
         if (!isset($app['config']['type']['database'][$instance])) {
             die('No config for such instance.');
         }
         if (!$this->compareIp($_SERVER['REMOTE_ADDR'], $app['config']['type']['media'][$instance]['instance']['accessIp'])) {
             die('Access denied.');
         }
         /** @var \Knp\Console\Application $application */
         $application = $app['console'];
         $application->setAutoExit(false);
         $input = new ArrayInput(array('command' => 'media:push', 'instance' => $instance));
         $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true);
         $application->run($input, $output);
         $converter = new AnsiToHtmlConverter();
         $content = $output->fetch();
         return $app['twig']->render('console.twig', array('response' => $converter->convert($content)));
     });
     $controller->get('/database/{instance}', function ($instance, Request $request) use($app) {
         if (!preg_match('/^[a-z]+$/', $instance)) {
             die('Wrong instance name. Should be [a-z]+');
         }
         if (!isset($app['config']['type']['database'][$instance])) {
             die('No config for such instance.');
         }
         if (!$this->compareIp($_SERVER['REMOTE_ADDR'], $app['config']['type']['database'][$instance]['instance']['accessIp'])) {
             die('Access denied.');
         }
         $iv = $request->get('iv');
         if (!preg_match('/^[0-9]+$/', $iv)) {
             die('Wrong $iv. Should be [0-9]+');
         }
         if ($request->get('outputFile') && $request->get('iv') && $request->get('copyPath') && $request->get('hash')) {
             $secret = $app['config']['secret'];
             $parameters['iv'] = array('value' => null, 'decrypt' => false, 'base64Decode' => false);
             $parameters['code'] = array('value' => null, 'decrypt' => true, 'base64Decode' => true);
             $parameters['outputFile'] = array('value' => null, 'decrypt' => true, 'base64Decode' => true);
             $parameters['copyPath'] = array('value' => null, 'decrypt' => true, 'base64Decode' => true);
             $parameters['hash'] = array('value' => null, 'decrypt' => true, 'base64Decode' => true);
             foreach ($parameters as $parameterKey => $parameter) {
                 $passedValue = $request->get($parameterKey);
                 if ($parameter['base64Decode']) {
                     $passedValue = base64_decode(strtr($passedValue, '-_,', '+/='));
                 }
                 if ($parameter['decrypt']) {
                     $passedValue = $this->decryptData($passedValue, $secret, $iv);
                 }
                 $parameters[$parameterKey]['value'] = trim($passedValue);
             }
             // check security hash for external parameters
             $hashToCheck = $parameters['hash']['value'];
             unset($parameters['hash']);
             $hashParts = array();
             foreach ($parameters as $parameterKey => $parameter) {
                 $hashParts[] = $parameter['value'];
             }
             if ($hashToCheck != md5(implode('-', $hashParts))) {
                 die('Security hash invalid!');
             }
             /** @var \Knp\Console\Application $application */
             $application = $app['console'];
             $application->setAutoExit(false);
             $input = new ArrayInput(array('command' => 'database:push', 'databaseCode' => $parameters['code']['value'], '--outputFile' => $parameters['outputFile']['value'], '--iv' => $iv, '--copyPath' => $parameters['copyPath']['value']));
             $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true);
             $application->run($input, $output);
             $converter = new AnsiToHtmlConverter();
             $content = $output->fetch();
             return $app['twig']->render('console.twig', array('response' => $converter->convert($content)));
         } else {
             return false;
         }
     });
     return $controller;
 }
Example #11
0
 /**
  * Convert output ansi chars to html.
  *
  * @param $log
  * @return mixed|string
  */
 private function ansi2Html($log)
 {
     $converter = new AnsiToHtmlConverter();
     $log = $converter->convert($log);
     $log = str_replace(chr(13) . chr(10), '<br>', $log);
     $log = str_replace(chr(10), '<br>', $log);
     $log = str_replace(chr(13), '<br>', $log);
     return $log;
 }
Example #12
0
<?php

use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
Route::get('/artisan', function () {
    return View::make('artisan-web::artisan');
});
Route::get('/artisan/execute', function () {
    $env = Input::get('env');
    $cmd = Input::get('cmd');
    $cmd = base_path() . '/artisan --ansi -n ' . escapeshellcmd($cmd) . ' 2>&1';
    exec($cmd, $lines);
    $output = implode(PHP_EOL, $lines);
    $converter = new AnsiToHtmlConverter();
    return $converter->convert($output);
});
Example #13
0
 public function getBuffer()
 {
     if ($this->type == self::TYPE_HTML) {
         $formatter = new OutputFormatter(true);
         $convertor = new AnsiToHtmlConverter();
         return nl2br($convertor->convert($formatter->format($this->buffer)));
     }
     return $this->buffer;
 }