mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
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:
parent
e8cfeb74cc
commit
67f0502cde
38
application/controllers/ScreenshotController.php
Normal file
38
application/controllers/ScreenshotController.php
Normal 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
16
run.php
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user