diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index 7d30d62e5..074e2fdc2 100644 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -4,6 +4,7 @@ // namespace Icinga\Application\Controllers; +use Icinga\Logger\Logger; use Icinga\Web\Controller\ActionController; use Icinga\Application\Icinga; @@ -21,6 +22,10 @@ class ErrorController extends ActionController { $error = $this->_getParam('error_handler'); $exception = $error->exception; + + Logger::error($exception); + Logger::error('Stacktrace: %s', $exception->getTraceAsString()); + switch ($error->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index dac0cc68b..004c52148 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -4,9 +4,12 @@ use Icinga\Module\Monitoring\Controller; use Icinga\Web\Hook; -use Icinga\Application\Config as IcingaConfig; use Icinga\Web\Url; use Icinga\Data\ResourceFactory; +use Icinga\Logger\Logger; +use Icinga\Logger\Writer\FileWriter; +use Icinga\Protocol\File\FileReader; +use \Zend_Controller_Action_Exception as ActionError; /** * Class ListController @@ -36,19 +39,21 @@ class ListController extends Controller */ public function applicationlogAction() { - $this->addTitleTab('application log'); - $config_ini = IcingaConfig::app()->toArray(); - if (!in_array('logging', $config_ini) || ( - in_array('type', $config_ini['logging']) && - $config_ini['logging']['type'] === 'file' && - in_array('target', $config_ini['logging']) && - file_exists($config_ini['logging']['target']) - ) - ) { - $resource = ResourceFactory::create('logfile'); - $this->view->logData = $resource->select()->order('DESC')->paginate(); - } else { - $this->view->logData = null; + if (! Logger::writesToFile()) { + throw new ActionError('Site not found', 404); } + + $this->addTitleTab('application log'); + $pattern = '/^(?[0-9]{4}(-[0-9]{2}){2}' // date + . 'T[0-9]{2}(:[0-9]{2}){2}([\\+\\-][0-9]{2}:[0-9]{2})?)' // time + . ' - (?[A-Za-z]+)' // loglevel + . ' - (?.*)$/'; // message + + $loggerWriter = Logger::getInstance()->getWriter(); + $resource = new FileReader(new Zend_Config(array( + 'filename' => $loggerWriter->getPath(), + 'fields' => $pattern + ))); + $this->view->logData = $resource->select()->order('DESC')->paginate(); } } diff --git a/application/controllers/SearchController.php b/application/controllers/SearchController.php index f2bf1ceac..68fd5dd3d 100644 --- a/application/controllers/SearchController.php +++ b/application/controllers/SearchController.php @@ -3,9 +3,8 @@ // {{{ICINGA_LICENSE_HEADER}}} use Icinga\Web\Controller\ActionController; -use Icinga\Application\Icinga; use Icinga\Web\Widget; -use Icinga\Web\Url; +use Icinga\Web\Widget\SearchDashboard; /** * Search controller @@ -14,47 +13,13 @@ class SearchController extends ActionController { public function indexAction() { - $search = $this->_request->getParam('q'); - if (! $search) { - $this->view->tabs = Widget::create('tabs')->add( - 'search', - array( - 'title' => $this->translate('Search'), - 'url' => '/search', - ) - )->activate('search'); - $this->render('hint'); - return; - } - $dashboard = Widget::create('dashboard')->createPane($this->translate('Search')); - $pane = $dashboard->getPane($this->translate('Search')); - $suffix = strlen($search) ? ': ' . rtrim($search, '*') . '*' : ''; - $pane->addComponent( - $this->translate('Hosts') . $suffix, - Url::fromPath('monitoring/list/hosts', array( - 'host_name' => $search . '*', - 'sort' => 'host_severity', - 'limit' => 10, - ) - )); - $pane->addComponent( - $this->translate('Services') . $suffix, - Url::fromPath('monitoring/list/services', array( - 'service_description' => $search . '*', - 'sort' => 'service_severity', - 'limit' => 10, - ) - )); - $pane->addComponent('Hostgroups' . $suffix, Url::fromPath('monitoring/list/hostgroups', array( - 'hostgroup' => $search . '*', - 'limit' => 10, - ))); - $pane->addComponent('Servicegroups' . $suffix, Url::fromPath('monitoring/list/servicegroups', array( - 'servicegroup' => $search . '*', - 'limit' => 10, - ))); - $dashboard->activate($this->translate('Search')); - $this->view->dashboard = $dashboard; - $this->view->tabs = $dashboard->getTabs(); + $this->view->dashboard = SearchDashboard::search($this->params->get('q')); + + // NOTE: This renders the dashboard twice. Remove this once we can catch exceptions thrown in view scripts. + $this->view->dashboard->render(); + } + + public function hintAction() + { } } diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 51b5fdb62..fec60a624 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -2,10 +2,11 @@ // {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}} -use Zend_Controller_Action_Exception as ActionException; use Icinga\Web\Controller\ActionController; use Icinga\Application\Icinga; use Icinga\Logger\Logger; +use Icinga\Web\FileCache; +use Zend_Controller_Action_Exception as ActionException; /** * Delivery static content to clients @@ -30,8 +31,25 @@ class StaticController extends ActionController public function gravatarAction() { + $cache = FileCache::instance(); + $filename = md5(strtolower(trim($this->_request->getParam('email')))); + $cacheFile = 'gravatar-' . $filename; + header('Cache-Control: public'); + header('Pragma: cache'); + if ($etag = $cache->etagMatchesCachedFile($cacheFile)) { + header("HTTP/1.1 304 Not Modified"); + return; + } + header('Content-Type: image/jpg'); - $img = file_get_contents('http://www.gravatar.com/avatar/' . md5(strtolower(trim($this->_request->getParam('email')))) . '?s=200&d=mm'); + if ($cache->has($cacheFile)) { + header('ETag: "' . $cache->etagForCachedFile($cacheFile) . '"'); + $cache->send($cacheFile); + return; + } + $img = file_get_contents('http://www.gravatar.com/avatar/' . $filename . '?s=120&d=mm'); + $cache->store($cacheFile, $img); + header('ETag: "' . $cache->etagForCachedFile($cacheFile) . '"'); echo $img; } diff --git a/application/forms/PreferenceForm.php b/application/forms/PreferenceForm.php index c156cca12..f01f4e337 100644 --- a/application/forms/PreferenceForm.php +++ b/application/forms/PreferenceForm.php @@ -11,6 +11,7 @@ use Icinga\Web\Request; use Icinga\Web\Session; use Icinga\Web\Notification; use Icinga\Util\Translator; +use Icinga\Util\TimezoneDetect; use Icinga\User\Preferences; use Icinga\User\Preferences\PreferencesStore; @@ -189,7 +190,7 @@ class PreferenceForm extends Form 'label' => t('Your Current Timezone'), 'description' => t('Use the following timezone for dates and times'), 'multiOptions' => $tzList, - 'value' => date_default_timezone_get() + 'value' => $this->getDefaultTimezone() ) ); if ($useLocalTimezone) { @@ -208,4 +209,19 @@ class PreferenceForm extends Form return $this; } + + /** + * Return the current default timezone + * + * @return string + */ + protected function getDefaultTimezone() + { + $detect = new TimezoneDetect(); + if ($detect->success()) { + return $detect->getTimezoneName(); + } else { + return date_default_timezone_get(); + } + } } diff --git a/application/layouts/scripts/layout.phtml b/application/layouts/scripts/layout.phtml index 32c4879b4..c4354cee2 100644 --- a/application/layouts/scripts/layout.phtml +++ b/application/layouts/scripts/layout.phtml @@ -29,17 +29,17 @@ $iframeClass = $isIframe ? ' iframe' : ''; <?= $this->title ? $this->escape($this->title) : 'Icinga Web' ?> - - + - + - + +