Add ImgAction to StaticController
This commit is contained in:
parent
be3193a0d7
commit
2c6f8a8441
|
@ -1,60 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
// @codingStandardsIgnoreStart
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
/**
|
|
||||||
* Icinga 2 Web - Head for multiple monitoring frontends
|
|
||||||
* Copyright (C) 2013 Icinga Development Team
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
||||||
* @author Icinga Development Team <info@icinga.org>
|
|
||||||
*/
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
# namespace Icinga\Web\Form;
|
|
||||||
|
|
||||||
use Icinga\Web\ActionController;
|
use Icinga\Web\ActionController;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga,
|
||||||
use Zend_Controller_Action_Exception as ActionException;
|
Zend_Controller_Action_Exception as ActionException;
|
||||||
|
|
||||||
use Icinga\Application\Benchmark;
|
|
||||||
/**
|
|
||||||
* Class StaticController
|
|
||||||
* @package Icinga\Web\Form
|
|
||||||
*/
|
|
||||||
class StaticController extends ActionController
|
class StaticController extends ActionController
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $handlesAuthentication = true;
|
protected $handlesAuthentication = true;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->_helper->viewRenderer->setNoRender(true);
|
$this->_helper->viewRenderer->setNoRender(true);
|
||||||
$this->_helper->layout()->disableLayout();
|
$this->_helper->layout()->disableLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getModuleList()
|
private function getModuleList()
|
||||||
{
|
{
|
||||||
$modules = Icinga::app()->moduleManager()->getLoadedModules();
|
$modules = Icinga::app()->moduleManager()->getLoadedModules();
|
||||||
|
@ -73,9 +33,6 @@ class StaticController extends ActionController
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function modulelistAction()
|
public function modulelistAction()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -86,12 +43,44 @@ class StaticController extends ActionController
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function imgAction()
|
||||||
* @throws \Zend_Controller_Action_Exception
|
{
|
||||||
*/
|
$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()
|
public function javascriptAction()
|
||||||
{
|
{
|
||||||
$module = $this->_getParam('module_name');
|
$module = $this->_getParam('moduleName');
|
||||||
$file = $this->_getParam('file');
|
$file = $this->_getParam('file');
|
||||||
$basedir = Icinga::app()->getModule($module)->getBaseDir();
|
$basedir = Icinga::app()->getModule($module)->getBaseDir();
|
||||||
|
|
||||||
|
@ -126,8 +115,7 @@ class StaticController extends ActionController
|
||||||
} else {
|
} else {
|
||||||
readfile($filePath);
|
readfile($filePath);
|
||||||
}
|
}
|
||||||
return;
|
$this->_viewRenderer->setNoRender();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @codingStandardsIgnoreEnd
|
}
|
||||||
|
|
Loading…
Reference in New Issue