public function executeHtml(AgaviRequestDataHolder $rd) { $this->setupHtml($rd); if ($this->getContext()->getUser()->isAuthenticated() !== true) { $this->getResponse()->setHttpStatusCode('403'); } $this->setAttribute('message', false); $message = AgaviConfig::get('modules.appkit.auth.message', false); if ($rd->has('cookies', 'icinga-web-loginname') && AgaviConfig::get('modules.appkit.auth.behaviour.store_loginname', false) === true) { $this->setAttribute('username', $rd->get('cookies', 'icinga-web-loginname')); } if ($message !== false && is_array($message)) { if (isset($message['show']) && $message['show'] == true) { if (isset($message['include_file']) && file_exists($message['include_file'])) { $text = file_get_contents($message['include_file']); } else { $text = isset($message['text']) ? $message['text'] : null; } if ($text) { $text = AppKitAgaviUtil::replaceConfigVars($text); } $this->setAttribute('message', true); $this->setAttribute('message_text', $text); $this->setAttribute('message_title', $message['title']); $this->setAttribute('message_expand_first', isset($message['expand_first']) ? (bool) $message['expand_first'] : false); } } }
/** * retrieves content via model and returns it * @param AgaviRequestDataHolder $rd required by Agavi but not used here * @return string $content generated content * @author Christian Doebler <*****@*****.**> */ public function executeSimple(AgaviRequestDataHolder $rd) { if ($rd->getParameter('interface', false) == true) { return $this->executeHtml($rd); } try { try { $modules = AgaviConfig::get("org.icinga.modules", array()); $fileName = $rd->getParameter('template'); $file = null; foreach ($modules as $name => $path) { if (file_exists($path . "/config/templates/" . $fileName . '.xml')) { $file = AppKitFileUtil::getAlternateFilename($path . "/config/templates/", $fileName, '.xml'); } } if ($file === null) { $file = AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.to'), $fileName, '.xml'); } $model = $this->getContext()->getModel('System.StaticContent', 'Cronks', array('rparam' => $rd->getParameter('p', array()))); $model->setTemplateFile($file->getRealPath()); $content = $model->renderTemplate($rd->getParameter('render', 'MAIN'), $rd->getParameters()); return sprintf('<div class="%s">%s</div>', 'static-content-container', $content); } catch (AppKitFileUtilException $e) { $msg = 'Could not find template for ' . $rd->getParameter('template'); AppKitAgaviUtil::log('Could not find template for ' . $rd->getParameter('template'), AgaviLogger::ERROR); return $msg; } } catch (Exception $e) { return $e->getMessage(); } }
public function executeJson(AgaviRequestDataHolder $rd) { try { $modules = AgaviConfig::get("org.icinga.modules", array()); $fileName = $rd->getParameter('template'); $file = null; foreach ($modules as $name => $path) { if (file_exists($path . "/config/templates/" . $fileName . '.xml')) { $file = AppKitFileUtil::getAlternateFilename($path . "/config/templates/", $fileName, '.xml'); } } if ($file === null) { $file = AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.grid'), $rd->getParameter('template'), '.xml'); } $template = new CronkGridTemplateXmlParser($file->getRealPath()); $template->parseTemplate(); $user = $this->getContext()->getUser()->getNsmUser(); $data = $template->getTemplateData(); if ($user->hasTarget('IcingaCommandRestrictions')) { $template->removeRestrictedCommands(); } return json_encode(array('template' => $template->getTemplateData(), 'fields' => $template->getFields(), 'keys' => $template->getFieldKeys(), 'params' => $rd->getParameters(), 'connections' => IcingaDoctrineDatabase::$icingaConnections)); } catch (AppKitFileUtilException $e) { $msg = 'Could not find template for ' . $rd->getParameter('template'); AppKitAgaviUtil::log('Could not find template for ' . $rd->getParameter('template'), AgaviLogger::ERROR); return $msg; } }
/** * Logs exceptions to the icinga-web logs. */ public static function logException(Exception $e) { AppKitAgaviUtil::log('Uncaught %s: %s (%s:%d)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine(), self::LOG_LEVEL); // Rethrow exception, so Agavi can handle and render it. // See AgaviController#dispatch(). throw $e; }
public function exec(Api_Console_ConsoleCommandModel $cmd) { $cmdString = $cmd->getCommandString(); $this->checkFileExistence($cmd); $username = AppKitAgaviUtil::getContext()->getUser()->getNsmUser()->user_name; putenv('ICINGAWEB_USER='******'ICINGAWEB_IP=' . $_SERVER['REMOTE_ADDR']); exec($cmdString, $out, $ret); $cmd->setReturnCode($ret); $cmd->setOutput($out); }
private function getTemplateFile(AgaviRequestDataHolder $rd) { try { $modules = AgaviConfig::get("org.icinga.modules", array()); $fileName = $rd->getParameter('template'); foreach ($modules as $name => $path) { if (file_exists($path . "/config/templates/" . $fileName . '.xml')) { return AppKitFileUtil::getAlternateFilename($path . "/config/templates/", $fileName, '.xml'); } } return AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.grid'), $fileName, '.xml'); } catch (AppKitFileUtilException $e) { AppKitAgaviUtil::log('Could not find template for ' . $rd->getParameter('template'), AgaviLogger::ERROR); throw $e; } }
private function getActionClass($moduleName, $actionName) { $actionName = AgaviToolkit::canonicalName($actionName); $longActionName = str_replace('/', '_', $actionName); $class = $moduleName . '_' . $longActionName . 'Action'; if (!class_exists($class)) { if (false !== ($file = AppKitAgaviUtil::getAgaviControllerInstance()->checkActionFile($moduleName, $actionName))) { require $file; } else { throw new AgaviException('Could not find file for Action "' . $actionName . '" in module "' . $moduleName . '"'); } if (!class_exists($class, false)) { throw new AgaviException('Could not find Action "' . $longActionName . '" for module "' . $moduleName . '"'); } } return $class; }
/** * Load all needed modules */ private function initializeModules() { $list = array(); $module_dir = AgaviToolKit::literalize("%core.module_dir%"); $files = scandir($module_dir); AppKitAgaviUtil::initializeModule('AppKit'); foreach ($files as $file) { if ($file == '.' || $file == '..') { continue; } if (!is_dir($module_dir . "/" . $file) || !is_readable($module_dir . "/" . $file)) { continue; } $list[] = $file; } $available_modules = array(); foreach ($list as $mod_name) { try { if (in_array($mod_name, self::$excludeModules) === false) { AppKitAgaviUtil::initializeModule($mod_name); $available_modules[$mod_name] = $module_dir . "/" . $mod_name; } } catch (AgaviDisabledModuleException $e) { } } AgaviConfig::set("org.icinga.modules", $available_modules); AppKitAgaviUtil::initializeModule('Config'); }
/** * Shortcut method to log messages easier from action * @param mixed $arg1 * @see app/modules/AppKit/lib/AppKitAgaviUtil#log() */ protected function log($arg1) { $args = func_get_args(); return AppKitAgaviUtil::log($args); }
protected function getLogDir() { return AppKitAgaviUtil::replaceConfigVars(AgaviConfig::get('org.icinga.appkit.log_path')); }
/** * Dump files minifying content on request * @return this * * @author Eric Lippmann <*****@*****.**> * @since 1.5.0 */ protected function readFiles() { $content = null; foreach ($this->getParameter('files') as $file) { if (false !== ($fcontent = @file_get_contents($file))) { if (!$this->getParameter('comments', true)) { $fcontent = preg_replace("!^\\s*//.*\$!m", "\n", $fcontent); $fcontent = preg_replace("!^\\s*/\\*.*?\\*/!s", "", $fcontent); } if (!$this->getParameter('indent', true)) { $fcontent = implode("\n", array_map('trim', explode("\n", $fcontent))); } if (!$this->getParameter('newlines', true)) { $fcontent = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", $fcontent); } $content .= $fcontent . "\n"; } else { AppKitAgaviUtil::log(sprintf('%s: Could not get contents of file %s.', get_class($this), $file), AgaviLogger::ERROR); } } $this->setParameter('content', $content); return $this; }
/** * Starts an agavi context for testing purposes. This was bundled into the * test bootstrap method to call this only once * @param string $env Name of the context * @return AgaviContext The created context */ public function bootstrapAgavi($env = 'testing', array $modules = array()) { require IcingaWebTestTool::getRootPath() . '/lib/agavi/src/agavi.php'; AgaviConfig::set('core.testing_dir', IcingaWebTestTool::getTestPath()); AgaviConfig::set('core.app_dir', IcingaWebTestTool::getRootPath() . DIRECTORY_SEPARATOR . 'app'); AgaviConfig::set('core.root_dir', IcingaWebTestTool::getRootPath()); Agavi::bootstrap($env); AgaviConfig::set('core.default_context', $env); AppKitAgaviUtil::initializeModule('AppKit'); AppKitAgaviUtil::initializeModule('Api'); foreach ($modules as $module) { AppKitAgaviUtil::initializeModule($module); } AgaviConfig::set('core.context_implementation', 'AppKitAgaviContext'); return AgaviContext::getInstance($env); }