Update Module img_ route to get image subfolders

This commit is contained in:
Alexander Fuhr 2014-09-08 11:28:14 +02:00
parent 2112d45c3c
commit 7386ae5ef5
2 changed files with 15 additions and 4 deletions

View File

@ -61,10 +61,17 @@ class StaticController extends ActionController
$module = $this->_getParam('module_name');
// TODO: This is more than dangerous, must be fixed!!
$file = $this->_getParam('file');
$basedir = Icinga::app()->getModuleManager()->getModule($module)->getBaseDir();
$filePath = $basedir . '/public/img/' . $file;
$filePath = realpath($basedir . '/public/img/' . $file);
if (strpos($filePath, $basedir) === false) {
throw new ActionException(sprintf(
'%s does not exist',
$filePath
), 404);
}
if (! file_exists($filePath)) {
throw new ActionException(sprintf(
'%s does not exist',

View File

@ -8,6 +8,7 @@ use Exception;
use Zend_Config;
use Zend_Controller_Router_Route_Abstract;
use Zend_Controller_Router_Route as Route;
use Zend_Controller_Router_Route_Regex as RegexRoute;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Config;
use Icinga\Application\Icinga;
@ -821,12 +822,15 @@ class Module
);
$router->addRoute(
$this->name . '_img',
new Route(
'img/' . $this->name . '/:file',
new RegexRoute(
'img/' . $this->name . '/(.+)',
array(
'controller' => 'static',
'action' => 'img',
'module_name' => $this->name
),
array(
1 => 'file'
)
)
);