diff --git a/library/Icinga/Pdf/File.php b/library/Icinga/File/Pdf.php similarity index 85% rename from library/Icinga/Pdf/File.php rename to library/Icinga/File/Pdf.php index 37093600c..0c8aebed1 100644 --- a/library/Icinga/Pdf/File.php +++ b/library/Icinga/File/Pdf.php @@ -1,14 +1,18 @@ getApplicationDir() . '/../public'; define('K_TCPDF_EXTERNAL_CONFIG', true); //define('K_PATH_URL', 'http://net-test-icinga-vm1.adm.netways.de/develop/'); // ??? // define('K_PATH_URL', '/var/www/net-test-icinga-vm1.adm.netways.de/develop/public'); // ??? -define('K_PATH_URL', '/develop'); // ??? +define('K_PATH_URL', (string) Url::create('/') === '/' ? '' : (string) Url::create('/')); // ???'/')); define('K_PATH_MAIN', dirname(ICINGA_LIBDIR) . '/public'); define('K_PATH_FONTS', ICINGA_LIBDIR . '/vendor/tcpdf/fonts/'); define('K_PATH_CACHE', ICINGA_LIBDIR . '/vendor/tcpdf/cache/'); @@ -19,13 +23,13 @@ define('K_BLANK_IMAGE', K_PATH_IMAGES.'_blank.png'); // COULD be anything? // define('K_CELL_HEIGHT_RATIO', 1.25); define('K_SMALL_RATIO', 2/3); -define('K_TCPDF_CALLS_IN_HTML', true); // SECURITY: is false better? +define('K_TCPDF_CALLS_IN_HTML', false); // SECURITY: is false better? define('K_TCPDF_THROW_EXCEPTION_ERROR', true); - +define('K_THAI_TOPCHARS', false); require_once 'vendor/tcpdf/tcpdf.php'; -class File extends TCPDF +class Pdf extends TCPDF { protected $cell_height_ratio = 1.25; public function __construct( diff --git a/library/Icinga/Web/ActionController.php b/library/Icinga/Web/ActionController.php index ebefc8acf..e4dcb2c4e 100755 --- a/library/Icinga/Web/ActionController.php +++ b/library/Icinga/Web/ActionController.php @@ -1,35 +1,13 @@ - * @author Icinga Development Team - */ // {{{ICINGA_LICENSE_HEADER}}} namespace Icinga\Web; -use Icinga\Authentication\Manager; +use Icinga\Authentication\Manager as AuthManager; use Icinga\Application\Benchmark; use Icinga\Exception; use Icinga\Application\Config; -use Icinga\Pdf\File; use Icinga\Web\Notification; use Zend_Layout as ZfLayout; use Zend_Controller_Action as ZfController; @@ -37,6 +15,11 @@ use Zend_Controller_Request_Abstract as ZfRequest; use Zend_Controller_Response_Abstract as ZfResponse; use Zend_Controller_Action_HelperBroker as ZfActionHelper; +/* + * @TODO(el): There was a note from tg that the following line is temporary. Ask him why. + */ +use Icinga\File\Pdf; + /** * Base class for all core action controllers * @@ -45,21 +28,16 @@ use Zend_Controller_Action_HelperBroker as ZfActionHelper; * @copyright Copyright (c) 2013 Icinga-Web Team * @author Icinga-Web Team * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License - * @package Icinga\Web */ class ActionController extends ZfController { /** * The Icinga Config object is available in all controllers. This is the * modules config for module action controllers. - * * @var Config */ protected $config; - /** - * @var bool - */ protected $replaceLayout = false; /** @@ -84,20 +62,12 @@ class ActionController extends ZfController */ protected $action_name; - /** - * @var bool - */ + // @TODO(el): Should be true, is/was disabled for testing purpose protected $handlesAuthentication = false; - /** - * @var bool - */ protected $modifiesSession = false; - /** - * @var bool - */ - protected $allowAccess = false; + private $allowAccess = false; /** * The constructor starts benchmarking, loads the configuration and sets @@ -113,30 +83,22 @@ class ActionController extends ZfController array $invokeArgs = array() ) { Benchmark::measure('Action::__construct()'); - $this->module_name = $request->getModuleName(); + + $this->module_name = $request->getModuleName(); $this->controller_name = $request->getControllerName(); - $this->action_name = $request->getActionName(); + $this->action_name = $request->getActionName(); $this->loadConfig(); $this->setRequest($request) - ->setResponse($response) - ->_setInvokeArgs($invokeArgs); + ->setResponse($response) + ->_setInvokeArgs($invokeArgs); $this->_helper = new ZfActionHelper($this); - /* - * -------------------------------------------- - * Authentication is disabled to test bootstrap - * -------------------------------------------- - * - * @todo remove this! - */ - - if ($this->handlesAuthentication() || - Manager::getInstance( + AuthManager::getInstance( null, array( - "writeSession" => $this->modifiesSession + 'writeSession' => $this->modifiesSession ) )->isAuthenticated() ) { @@ -171,7 +133,7 @@ class ActionController extends ZfController * Helper function creating a new widget * * @param string $name The widget name - * @param array|string $properties Optional widget properties + * @param string $properties Optional widget properties * * @return Widget\AbstractWidget */ @@ -185,9 +147,8 @@ class ActionController extends ZfController * * TODO: This has not been implemented yet * - * @param $uri * @param string $permission Permission name - * @internal param string $object No idea what this should have been :-) + * @param string $object No idea what this should have been :-) * * @return bool */ @@ -204,18 +165,31 @@ class ActionController extends ZfController * @param string $permission Permission name * @param string $object No idea what this should have been :-) * - * @throws \Exception * @return self */ final protected function assertPermission($permission, $object = null) { - if (!$this->hasPermission($permission, $object)) { + if (! $this->hasPermission($permission, $object)) { // TODO: Log violation, create dedicated Exception class throw new \Exception('Permission denied'); } return $this; } + protected function preserve($key, $value = null) + { + if ($value === null) { + $value = $this->_getParam($key); + } + if ($value !== null) { + if (! isset($this->view->preserve)) { + $this->view->preserve = array(); + } + $this->view->preserve[$key] = $value; + } + return $this; + } + /** * Our benchmark wants to know when we started our dispatch loop * @@ -224,8 +198,7 @@ class ActionController extends ZfController public function preDispatch() { Benchmark::measure('Action::preDispatch()'); - - if (!$this->allowAccess) { + if (! $this->allowAccess) { $this->_request->setModuleName('default') ->setControllerName('authentication') ->setActionName('login') @@ -237,21 +210,27 @@ class ActionController extends ZfController $this->view->controller_name = $this->controller_name; $this->view->module_name = $this->module_name; + // TODO(el): What is this, why do we need that here? + $this->view->compact = $this->_request->getParam('view') === 'compact'; + + Benchmark::measure(sprintf( + 'Action::preDispatched(): %s / %s / %s', + $this->module_name, + $this->controller_name, + $this->action_name + )); + //$this->quickRedirect('/authentication/login?a=e'); } - /** - * @param $url - * @param array $params - */ public function redirectNow($url, array $params = array()) { + if ($url instanceof Url) { + $url = $url->getRelative(); + } $this->_helper->Redirector->gotoUrlAndExit($url); } - /** - * @return bool - */ public function handlesAuthentication() { return $this->handlesAuthentication; @@ -265,8 +244,8 @@ class ActionController extends ZfController protected function renderBenchmark() { return '
'
-        . Benchmark::renderToHtml()
-        . '
'; + . Benchmark::renderToHtml() + . ''; } /** @@ -284,7 +263,6 @@ class ActionController extends ZfController { Benchmark::measure('Action::postDispatch()'); - // TODO: Move this elsewhere, this is just an ugly test: if ($this->_request->getParam('filetype') === 'pdf') { @@ -293,40 +271,56 @@ class ActionController extends ZfController require_once 'vendor/lessphp/lessc.inc.php'; $less = new \lessc; $cssdir = dirname(ICINGA_LIBDIR) . '/public/css'; - // TODO: We need a way to retrieve public dir, even if located elsewhere + // TODO: We need a way to retrieve public dir, even if located elsewhere $css = $less->compileFile($cssdir . '/pdfprint.less'); - /* - foreach ($app->moduleManager()->getLoadedModules() as $name => $module) { - if ($module->hasCss()) { - $css .= $less->compile( - '.icinga-module.module-' - . $name - . " {\n" - . file_get_contents($module->getCssFilename()) - . "}\n\n" - ); - } - } - */ +/* + foreach (\Icinga\Application\Icinga::app()->moduleManager()->getLoadedModules() as $name => $module) { + if ($module->hasCss()) { + $css .= $less->compile( + '.icinga-module.module-' + . $name + . " {\n" + . file_get_contents($module->getCssFilename()) + . "}\n\n" + ); + } + } +*/ // END of CSS test - $this->render( + $this->render( null, $this->_helper->viewRenderer->getResponseSegment(), $this->_helper->viewRenderer->getNoController() ); - $html = '' . (string)$this->getResponse(); + $html = (string) $this->getResponse(); + if ($this->module_name !== null) { + $html = '
' + . "\n" + . $html + . '
'; + } - $pdf = new File(); + $html = '' . $html; + + //$html .= $this->view->action('services', 'list', 'monitoring', array('limit' => 10)); +// $html = preg_replace('~icinga-module.module-bpapp~', 'csstest', $html); +// echo $html; exit; + $pdf = new Pdf(); $pdf->AddPage(); - $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); + $pdf->setFontSubsetting(false); + $pdf->writeHTML($html); //0, 0, '', '', $html, 0, 1, 0, true, '', true); + $pdf->Output('docs.pdf', 'I'); exit; } // END of PDF test + if ($this->_request->isXmlHttpRequest()) { if ($this->replaceLayout || $this->_getParam('_render') === 'body') { $this->_helper->layout()->setLayout('just-the-body'); @@ -335,24 +329,23 @@ class ActionController extends ZfController $this->_helper->layout()->setLayout('inline'); } } - $notification = Notification::getInstance(); if ($notification->hasMessages()) { $nhtml = '
    '; foreach ($notification->getMessages() as $msg) { $nhtml .= '
  • [' - . $msg->type - . '] ' - . htmlspecialchars($msg->message); + . $msg->type + . '] ' + . htmlspecialchars($msg->message); } $nhtml .= '
'; $this->getResponse()->append('notification', $nhtml); } - /*if (Session::getInstance()->show_benchmark) { + if (AuthManager::getInstance()->getSession()->get('show_benchmark')) { Benchmark::measure('Response ready'); - $this->getResponse()->append('benchmark', $this->renderBenchmark()); - }*/ + $this->_helper->layout()->benchmark = $this->renderBenchmark(); + } } }