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;
     }
 }
 /**
  * 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();
     }
 }
 private function clearAdditionalCache()
 {
     $cacheDir = AgaviConfig::get('core.cache_dir');
     foreach (self::$additionalCacheDirs as $sub) {
         AppKitFileUtil::rmdir($cacheDir . DIRECTORY_SEPARATOR . $sub);
         $this->log('Cleared sub cache %s from webinterface', $sub, AgaviLogger::INFO);
     }
 }
Esempio n. 4
0
 /**
  * @group Bug
  */
 public function testBug()
 {
     $ctx = IcingaWebTestTool::getContext();
     $file = AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.grid'), self::TEMPLATE, '.xml');
     $template = new CronkGridTemplateXmlParser($file->getRealPath(), $ctx);
     $template->parseTemplate();
     $worker = CronkGridTemplateWorkerFactory::createWorker($template, $ctx, self::CONNECTION);
     $this->assertGreaterThanOrEqual(0, $worker->countResults());
 }
 public function getMetaData()
 {
     $response = $this->__soap->getJasperResponseFor(JasperSoapMultipartClient::CONTENT_ID_RESPONSE);
     if (count($response) == 1) {
         $rd = $response->current();
         $struct = array('label' => $rd->getLabel(), 'crdate' => $this->context->getTranslationManager()->_d($rd->getCrdate(), 'date-tstamp'), 'has_attachment' => $this->__soap->hasAttachment(), 'has_report' => $this->__soap->hasReport());
         $struct = $rd->getResourceDescriptor()->getParameters() + $struct;
         $struct = $rd->getProperties()->getParameters() + $struct;
         if ($struct['has_attachment']) {
             $mime = AppKitFileUtil::getMimeTypeForData($this->__soap->getDataFor(JasperSoapMultipartClient::CONTENT_ID_ATTACHMENT), $this->__soap->getHeaderFor(JasperSoapMultipartClient::CONTENT_ID_ATTACHMENT, 'content-type'));
             $struct = array('content_type' => $mime, 'content_length' => $this->__soap->getContentSize(JasperSoapMultipartClient::CONTENT_ID_ATTACHMENT), 'preview_allowed' => $this->canPreview($mime), 'download_allowed' => $this->canDownload($rd->getProperties()->getParameter('PROP_RESOURCE_TYPE'))) + $struct;
         }
         return $struct;
     }
 }
 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;
     }
 }
 public function setTemplateFile($templateFile)
 {
     $modules = AgaviConfig::get("org.icinga.modules", array());
     foreach ($modules as $name => $path) {
         if (file_exists($path . "/config/templates/" . $templateFile . '.xml')) {
             $templateFile = $path . "/config/templates/" . $templateFile . '.xml';
         }
     }
     if (!file_exists($templateFile)) {
         $this->templateFile = sprintf('%s/%s.xml', AgaviConfig::get('modules.cronks.xml.path.to'), $templateFile);
     } else {
         $this->templateFile = $templateFile;
     }
     AppKitFileUtil::fileExists($this->templateFile);
     $this->dom = new DOMDocument('1.0', 'utf-8');
     $this->dom->preserveWhiteSpace = false;
     $this->dom->load($this->templateFile);
     $this->xmlData = $this->convertDom($this->dom->getElementsByTagName('template')->item(0));
 }