2013-06-14 13:51:44 +02:00
|
|
|
<?php
|
2013-08-06 11:24:16 +02:00
|
|
|
// @codingStandardsIgnoreStart
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
/**
|
2013-10-23 15:10:33 +02:00
|
|
|
* This file is part of Icinga Web 2.
|
2013-08-06 11:24:16 +02:00
|
|
|
*
|
2013-10-23 15:10:33 +02:00
|
|
|
* Icinga Web 2 - Head for multiple monitoring backends.
|
2013-08-06 11:24:16 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2013-10-23 15:10:33 +02:00
|
|
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*
|
2013-08-06 11:24:16 +02:00
|
|
|
*/
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-14 13:51:44 +02:00
|
|
|
|
2013-08-16 14:56:23 +02:00
|
|
|
use \Zend_Controller_Action_Exception as ActionException;
|
2014-02-26 11:19:52 +01:00
|
|
|
use Icinga\Web\Controller\ActionController;
|
|
|
|
use Icinga\Application\Icinga;
|
|
|
|
use Icinga\Logger\Logger;
|
2013-07-12 13:45:11 +02:00
|
|
|
|
2013-09-24 12:48:30 +02:00
|
|
|
/**
|
|
|
|
* Delivery static content to clients
|
|
|
|
*/
|
2013-06-14 13:51:44 +02:00
|
|
|
class StaticController extends ActionController
|
|
|
|
{
|
2013-08-16 14:56:23 +02:00
|
|
|
/**
|
2013-08-30 15:50:49 +02:00
|
|
|
* Static routes don't require authentication
|
|
|
|
*
|
|
|
|
* @var bool
|
2013-08-16 14:56:23 +02:00
|
|
|
*/
|
2013-08-30 15:50:49 +02:00
|
|
|
protected $requiresAuthentication = false;
|
2013-06-14 13:51:44 +02:00
|
|
|
|
2013-08-30 15:50:49 +02:00
|
|
|
/**
|
|
|
|
* Disable layout rendering as this controller doesn't provide any html layouts
|
|
|
|
*/
|
2013-06-14 13:51:44 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->_helper->viewRenderer->setNoRender(true);
|
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
}
|
|
|
|
|
2014-02-21 11:46:10 +01:00
|
|
|
public function gravatarAction()
|
|
|
|
{
|
|
|
|
$img = file_get_contents('http://www.gravatar.com/avatar/' . md5(strtolower(trim($this->_request->getParam('email')))) . '?s=200&d=mm');
|
|
|
|
header('image/jpeg');
|
|
|
|
echo $img;
|
|
|
|
}
|
|
|
|
|
2013-08-30 15:50:49 +02:00
|
|
|
/**
|
|
|
|
* Return an image from the application's or the module's public folder
|
|
|
|
*/
|
2013-07-12 13:45:11 +02:00
|
|
|
public function imgAction()
|
|
|
|
{
|
2013-08-06 11:53:42 +02:00
|
|
|
$module = $this->_getParam('module_name');
|
2014-02-14 15:08:23 +01:00
|
|
|
// TODO: This is more than dangerous, must be fixed!!
|
2013-07-12 13:45:11 +02:00
|
|
|
$file = $this->_getParam('file');
|
2013-08-16 14:56:23 +02:00
|
|
|
|
2013-08-06 11:24:16 +02:00
|
|
|
$basedir = Icinga::app()->getModuleManager()->getModule($module)->getBaseDir();
|
2013-07-12 13:45:11 +02:00
|
|
|
|
|
|
|
$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';
|
|
|
|
}
|
2013-09-03 18:43:17 +02:00
|
|
|
|
2013-07-12 13:45:11 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-08-30 15:50:49 +02:00
|
|
|
/**
|
|
|
|
* Return a javascript file from the application's or the module's public folder
|
|
|
|
*/
|
2013-06-14 13:51:44 +02:00
|
|
|
public function javascriptAction()
|
|
|
|
{
|
2013-08-06 11:24:16 +02:00
|
|
|
$module = $this->_getParam('module_name');
|
2013-07-12 13:45:11 +02:00
|
|
|
$file = $this->_getParam('file');
|
2013-08-06 11:24:16 +02:00
|
|
|
|
2013-08-20 12:00:41 +02:00
|
|
|
if ($module == 'app') {
|
|
|
|
$basedir = Icinga::app()->getApplicationDir('../public/js/icinga/components/');
|
|
|
|
$filePath = $basedir . $file;
|
|
|
|
} else {
|
|
|
|
if (!Icinga::app()->getModuleManager()->hasEnabled($module)) {
|
2013-08-20 19:47:04 +02:00
|
|
|
Logger::error(
|
|
|
|
'Non-existing frontend component "' . $module . '/' . $file
|
2014-02-26 11:19:52 +01:00
|
|
|
. '" was requested. The module "' . $module . '" does not exist or is not active.'
|
|
|
|
);
|
2013-08-20 12:00:41 +02:00
|
|
|
echo "/** Module not enabled **/";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$basedir = Icinga::app()->getModuleManager()->getModule($module)->getBaseDir();
|
|
|
|
$filePath = $basedir . '/public/js/' . $file;
|
2013-08-06 11:53:42 +02:00
|
|
|
}
|
2013-06-14 13:51:44 +02:00
|
|
|
|
|
|
|
if (!file_exists($filePath)) {
|
2013-08-20 19:31:29 +02:00
|
|
|
Logger::error(
|
|
|
|
'Non-existing frontend component "' . $module . '/' . $file
|
2014-02-26 11:19:52 +01:00
|
|
|
. '" was requested, which would resolve to the the path: ' . $filePath
|
|
|
|
);
|
2013-08-16 14:56:23 +02:00
|
|
|
echo '/** Module has no js files **/';
|
2013-08-06 11:53:42 +02:00
|
|
|
return;
|
2013-06-14 13:51:44 +02:00
|
|
|
}
|
|
|
|
$response = $this->getResponse();
|
2013-09-03 18:43:17 +02:00
|
|
|
$response->setHeader('Content-Type', 'text/javascript');
|
2013-09-11 17:07:33 +02:00
|
|
|
$this->setCacheHeader(3600);
|
2013-09-03 18:43:17 +02:00
|
|
|
|
2013-06-14 13:51:44 +02:00
|
|
|
$response->setHeader(
|
|
|
|
'Last-Modified',
|
|
|
|
gmdate(
|
|
|
|
'D, d M Y H:i:s',
|
|
|
|
filemtime($filePath)
|
|
|
|
) . ' GMT'
|
|
|
|
);
|
|
|
|
|
2013-09-03 18:43:17 +02:00
|
|
|
readfile($filePath);
|
2013-06-14 13:51:44 +02:00
|
|
|
}
|
2013-09-03 18:43:17 +02:00
|
|
|
|
|
|
|
/**
|
2013-09-24 12:48:30 +02:00
|
|
|
* Set cache header for this response
|
2013-09-03 18:43:17 +02:00
|
|
|
*
|
2013-09-04 17:12:44 +02:00
|
|
|
* @param integer $maxAge The maximum age to set
|
2013-09-03 18:43:17 +02:00
|
|
|
*/
|
|
|
|
private function setCacheHeader($maxAge)
|
|
|
|
{
|
2013-10-16 12:00:09 +02:00
|
|
|
$this->_response->setHeader('Cache-Control', 'max-age=3600', true);
|
|
|
|
$this->_response->setHeader('Pragma', 'cache', true);
|
|
|
|
$this->_response->setHeader(
|
2013-09-03 18:43:17 +02:00
|
|
|
'Expires',
|
|
|
|
gmdate(
|
|
|
|
'D, d M Y H:i:s',
|
|
|
|
time()+3600
|
|
|
|
) . ' GMT',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
2013-10-16 12:00:09 +02:00
|
|
|
|
|
|
|
public function stylesheetAction()
|
|
|
|
{
|
|
|
|
$lessCompiler = new \Icinga\Web\LessCompiler();
|
|
|
|
$moduleManager = Icinga::app()->getModuleManager();
|
|
|
|
|
|
|
|
$publicDir = realpath(dirname($_SERVER['SCRIPT_FILENAME']));
|
|
|
|
|
|
|
|
$lessCompiler->addItem($publicDir . '/css/vendor');
|
|
|
|
$lessCompiler->addItem($publicDir . '/css/icinga');
|
|
|
|
|
|
|
|
foreach ($moduleManager->getLoadedModules() as $moduleName) {
|
|
|
|
$cssDir = $moduleName->getCssDir();
|
2013-10-16 14:48:22 +02:00
|
|
|
|
2013-10-16 12:00:09 +02:00
|
|
|
if (is_dir($cssDir)) {
|
|
|
|
$lessCompiler->addItem($cssDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_response->setHeader('Content-Type', 'text/css');
|
|
|
|
$this->setCacheHeader(3600);
|
|
|
|
|
|
|
|
$lessCompiler->printStack();
|
|
|
|
}
|
2013-07-12 13:45:11 +02:00
|
|
|
}
|
2013-08-07 10:27:50 +02:00
|
|
|
// @codingStandardsIgnoreEnd
|