diff --git a/.gitignore b/.gitignore index 05ae14b2a..f3c1a22a7 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ test/php/bin/extcmd_test # misc test output test/frontend/static/public + +# Generated API documentation +doc/api diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 96d8b187f..dd9bfc7c9 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -1,60 +1,20 @@ - * @author Icinga Development Team - */ -// {{{ICINGA_LICENSE_HEADER}}} - -# namespace Icinga\Web\Form; use Icinga\Web\ActionController; -use Icinga\Application\Icinga; -use Zend_Controller_Action_Exception as ActionException; +use Icinga\Application\Icinga, + Zend_Controller_Action_Exception as ActionException; -use Icinga\Application\Benchmark; -/** - * Class StaticController - * @package Icinga\Web\Form - */ class StaticController extends ActionController { - /** - * @var bool - */ protected $handlesAuthentication = true; - /** - * - */ public function init() { $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout()->disableLayout(); } - /** - * @return array - */ private function getModuleList() { $modules = Icinga::app()->moduleManager()->getLoadedModules(); @@ -64,35 +24,64 @@ class StaticController extends ActionController foreach ($modules as $name => $module) { $hasJs = file_exists($module->getBasedir() . "/public/js/$name.js"); $result[] = array( - 'name' => $name, - 'active' => true, - 'type' => 'generic', + 'name' => $name, + 'active' => true, + 'type' => 'generic', 'behaviour' => $hasJs ); } return $result; } - /** - * - */ public function modulelistAction() { $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout()->disableLayout(); - $this->getResponse()->setHeader("Content-Type", "application/json"); - echo "define(function() { return " . json_encode($this->getModuleList(), true) . "; })"; + $this->getResponse()->setHeader("Content-Type","application/json"); + echo "define(function() { return ".json_encode($this->getModuleList(),true)."; })"; exit; } - /** - * @throws \Zend_Controller_Action_Exception - */ + public function imgAction() + { + $module = $this->_getParam('moduleName'); + $file = $this->_getParam('file'); + $basedir = Icinga::app()->getModule($module)->getBaseDir(); + + $filePath = $basedir . '/public/img/' . $file; + if (! file_exists($filePath)) { + throw new ActionException(sprintf( + '%s does not exist', + $filePath + ), 404); + } + if (preg_match('/\.([a-z]+)$/i', $file, $m)) { + $extension = $m[1]; + } else { + $extension = 'fixme'; + } + $hash = md5_file($filePath); + if ($hash === $this->getRequest()->getHeader('If-None-Match')) { + $this->getResponse()->setHttpResponseCode(304); + return; + } + header('ETag: ' . $hash); + header('Content-Type: image/' . $extension); + header('Cache-Control: max-age=3600'); + header('Last-Modified: ' . gmdate( + 'D, d M Y H:i:s', + filemtime($filePath) + ) . ' GMT'); + + readfile($filePath); + $this->_viewRenderer->setNoRender(); + } + public function javascriptAction() { - $module = $this->_getParam('module_name'); - $file = $this->_getParam('file'); + $module = $this->_getParam('moduleName'); + $file = $this->_getParam('file'); $basedir = Icinga::app()->getModule($module)->getBaseDir(); $filePath = $basedir . '/public/js/' . $file; @@ -126,8 +115,7 @@ class StaticController extends ActionController } else { readfile($filePath); } - return; + $this->_viewRenderer->setNoRender(); } -} -// @codingStandardsIgnoreEnd +} diff --git a/application/layouts/scripts/just-the-body.phtml b/application/layouts/scripts/just-the-body.phtml index ee29c44e6..75d847fbb 100755 --- a/application/layouts/scripts/just-the-body.phtml +++ b/application/layouts/scripts/just-the-body.phtml @@ -6,9 +6,7 @@