ScreenshotController: allow for documentation...

...images to work in the doc module and in foreign Git repositories
with the same relative link
This commit is contained in:
Thomas Gelf 2016-03-23 19:35:09 +01:00
parent e8cfeb74cc
commit 67f0502cde
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,38 @@
<?php
namespace Icinga\Module\Director\Controllers;
use Icinga\Exception\NotFoundError;
use Icinga\Web\Controller;
class ScreenshotController extends Controller
{
public function indexAction()
{
$subdir = $this->getParam('subdir');
$file = $this->getParam('file');
$valid = '[A-z0-9][A-z0-9_-]*';
if (!preg_match('/^' . $valid . '$/', $subdir)
|| !preg_match('/^' . $valid . '\.png$/', $file)
) {
throw new NotFoundError('Not found');
}
$filename = sprintf(
'%s/doc/screenshot/director/%s/%s',
$this->Module()->getBaseDir(),
$subdir,
$file
);
if (file_exists($filename)) {
$this->getResponse()->setHeader('Content-Type', 'image/png', true);
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$fh = fopen($filename, 'r');
fpassthru($fh);
} else {
throw new NotFoundError('Not found: ' . $filename);
}
}
}

16
run.php
View File

@ -1,5 +1,7 @@
<?php
use Icinga\Application\Icinga;
$prefix = '\\Icinga\\Module\\Director\\';
$this->provideHook('monitoring/HostActions');
@ -29,3 +31,17 @@ $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\Pro
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierExtractFromDN');
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierFromAdSid');
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierFromLatin1');
if (Icinga::app()->isCli()) {
return;
}
$screenshotRoute = new Zend_Controller_Router_Route(
'screenshot/director/:subdir/:file',
array(
'module' => 'director',
'controller' => 'screenshot',
)
);
$this->addRoute('screenshot/director', $screenshotRoute);