Skip to content

Commit

Permalink
Merge branch 'master' into feature/navigation-unhandled-badges-7114
Browse files Browse the repository at this point in the history
Conflicts:
	library/Icinga/Web/Menu.php
  • Loading branch information
majentsch committed Sep 5, 2014
2 parents 19eca5f + 3fbf172 commit 51d14af
Show file tree
Hide file tree
Showing 31 changed files with 747 additions and 65 deletions.
26 changes: 14 additions & 12 deletions application/controllers/ListController.php
Expand Up @@ -9,6 +9,7 @@
use Icinga\Logger\Logger;
use Icinga\Logger\Writer\FileWriter;
use Icinga\Protocol\File\FileReader;
use \Zend_Controller_Action_Exception as ActionError;

/**
* Class ListController
Expand Down Expand Up @@ -38,20 +39,21 @@ protected function addTitleTab($action)
*/
public function applicationlogAction()
{
if (! Logger::writesToFile()) {
throw new ActionError('Site not found', 404);
}

$this->addTitleTab('application log');
$pattern = '/^(?<datetime>[0-9]{4}(-[0-9]{2}){2}' // date
. 'T[0-9]{2}(:[0-9]{2}){2}([\\+\\-][0-9]{2}:[0-9]{2})?)' // time
. ' - (?<loglevel>[A-Za-z]+)' // loglevel
. ' - (?<message>.*)$/'; // message

$loggerWriter = Logger::getInstance()->getWriter();
if ($loggerWriter instanceof FileWriter) {
$resource = new FileReader(new Zend_Config(array(
'filename' => $loggerWriter->getPath(),
'fields' => '/^(?<datetime>[0-9]{4}(-[0-9]{2}){2}' // date
. 'T[0-9]{2}(:[0-9]{2}){2}([\\+\\-][0-9]{2}:[0-9]{2})?)' // time
. ' - (?<loglevel>[A-Za-z]+)' // loglevel
. ' - (?<message>.*)$/' // message
)));
$this->view->logData = $resource->select()->order('DESC')->paginate();
} else {
$this->view->logData = null;
}
$resource = new FileReader(new Zend_Config(array(
'filename' => $loggerWriter->getPath(),
'fields' => $pattern
)));
$this->view->logData = $resource->select()->order('DESC')->paginate();
}
}
2 changes: 1 addition & 1 deletion application/controllers/StaticController.php
Expand Up @@ -47,7 +47,7 @@ public function gravatarAction()
$cache->send($cacheFile);
return;
}
$img = file_get_contents('http://www.gravatar.com/avatar/' . $filename . '?s=200&d=mm');
$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;
Expand Down
17 changes: 15 additions & 2 deletions application/forms/Preference/GeneralForm.php
Expand Up @@ -5,6 +5,7 @@
namespace Icinga\Form\Preference;

use DateTimeZone;
use Icinga\Util\TimezoneDetect;
use Zend_Config;
use Zend_Form_Element_Text;
use Zend_Form_Element_Select;
Expand Down Expand Up @@ -69,13 +70,22 @@ private function addLanguageSelection(Zend_Config $cfg)
*/
private function addTimezoneSelection(Zend_Config $cfg)
{
$prefs = $this->getUserPreferences();
$useGlobalTimezone = $this->getRequest()->getParam('default_timezone', !$prefs->has('app.timezone'));
$detect = new TimezoneDetect();

$tzList = array();
foreach (DateTimeZone::listIdentifiers() as $tz) {
$tzList[$tz] = $tz;
}

$helptext = 'Use the following timezone for dates and times';
$prefs = $this->getUserPreferences();
$useGlobalTimezone = $this->getRequest()->getParam('default_timezone', !$prefs->has('app.timezone'));

if ($useGlobalTimezone && $detect->success() === true) {
$helptext .= '<br />' . t('Currently your time was detected to be')
. ': '
. '<strong>' . $detect->getTimezoneName() . '</strong>';
}

$selectTimezone = new Zend_Form_Element_Select(
array(
Expand All @@ -87,6 +97,7 @@ private function addTimezoneSelection(Zend_Config $cfg)
'value' => $prefs->get('app.timezone', $cfg->get('timezone', date_default_timezone_get()))
)
);

$this->addElement(
'checkbox',
'default_timezone',
Expand All @@ -99,7 +110,9 @@ private function addTimezoneSelection(Zend_Config $cfg)
if ($useGlobalTimezone) {
$selectTimezone->setAttrib('disabled', 1);
}

$this->addElement($selectTimezone);

$this->enableAutoSubmit(array('default_timezone'));
}

Expand Down
8 changes: 4 additions & 4 deletions application/layouts/scripts/layout.phtml
Expand Up @@ -29,17 +29,17 @@ $iframeClass = $isIframe ? ' iframe' : '';
<title><?= $this->title ? $this->escape($this->title) : 'Icinga Web' ?></title>
<!-- TODO: viewport and scale settings make no sense for us, fix this -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="<?= $this->href($cssfile) ?>" media="screen" type="text/css" />
<? if ($isIframe): ?>
<? if ($isIframe): ?>
<base target="_parent"/>
<?php else: ?>
<?php else: ?>
<script type="text/javascript">
(function() {
var html = document.getElementsByTagName('html')[0];
html.className = html.className.replace(/no-js/, 'js');
}());
</script>
<?php endif ?>
<?php endif ?>
<link rel="stylesheet" href="<?= $this->href($cssfile) ?>" media="screen" type="text/css" />
<!-- Respond.js IE8 support of media queries -->
<!--[if lt IE 9]>
<script src="<?= $this->baseUrl('js/vendor/respond.min.js');?>"></script>
Expand Down
2 changes: 1 addition & 1 deletion application/views/helpers/FormDateTime.php
Expand Up @@ -2,7 +2,7 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

use Zend_View_Helper_FormElement;
use \Zend_View_Helper_FormElement;

/**
* Helper to generate a "datetime" element
Expand Down
2 changes: 1 addition & 1 deletion application/views/helpers/FormTriStateCheckbox.php
Expand Up @@ -2,7 +2,7 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

use Zend_View_Helper_FormElement;
use \Zend_View_Helper_FormElement;

/**
* Helper to generate a "datetime" element
Expand Down
8 changes: 5 additions & 3 deletions library/Icinga/Application/Web.php
Expand Up @@ -10,6 +10,7 @@
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\NotReadableError;
use Icinga\Logger\Logger;
use Icinga\Util\TimezoneDetect;
use Icinga\Web\Request;
use Icinga\Web\Response;
use Icinga\Web\View;
Expand Down Expand Up @@ -273,10 +274,11 @@ private function setupPagination()
*/
protected function setupTimezone()
{
$userTimezone = null;

if ($this->user !== null && $this->user->getPreferences() !== null) {
$userTimezone = $this->user->getPreferences()->get('app.timezone');
} else {
$userTimezone = null;
$detect = new TimezoneDetect();
$userTimezone = $this->user->getPreferences()->get('app.timezone', $detect->getTimezoneName());
}

try {
Expand Down
18 changes: 18 additions & 0 deletions library/Icinga/Logger/Logger.php
Expand Up @@ -27,6 +27,13 @@ class Logger
*/
protected $writer;

/**
* The configured type
*
* @string Type (syslog, file)
*/
protected $type = 'none';

/**
* The maximum severity to emit
*
Expand Down Expand Up @@ -83,6 +90,7 @@ protected function createWriter(Zend_Config $config)
$config->type
);
}
$this->type = $config->type;

return new $class($config);
}
Expand Down Expand Up @@ -204,6 +212,16 @@ public function getWriter()
return $this->writer;
}

public static function writesToSyslog()
{
return static::$instance && static::$instance->type === 'syslog';
}

public static function writesToFile()
{
return static::$instance && static::$instance->type === 'file';
}

/**
* Get this' instance
*
Expand Down
9 changes: 5 additions & 4 deletions library/Icinga/Protocol/File/FileReader.php
Expand Up @@ -6,6 +6,7 @@

use Icinga\Data\Selectable;
use Countable;
use Icinga\Util\Enumerate;
use Zend_Config;

/**
Expand Down Expand Up @@ -52,7 +53,9 @@ public function __construct(Zend_Config $config)
*/
public function iterate()
{
return new FileIterator($this->filename, $this->fields);
return new Enumerate(
new FileIterator($this->filename, $this->fields)
);
}

/**
Expand Down Expand Up @@ -117,15 +120,13 @@ public function fetchPairs(FileQuery $query)
$skip = $count - ($skip + $read);
}
}
$index = 0;
foreach ($this->iterate() as $line) {
foreach ($this->iterate() as $index => $line) {
if ($index >= $skip) {
if ($index >= $skip + $read) {
break;
}
$lines[] = $line;
}
++$index;
}
if ($query->sortDesc()) {
$lines = array_reverse($lines);
Expand Down
62 changes: 62 additions & 0 deletions library/Icinga/Util/Enumerate.php
@@ -0,0 +1,62 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Util;

use Iterator;

/**
* Class Enumerate
*
* @see https://docs.python.org/2/library/functions.html#enumerate
*
* @package Icinga\Util
*/
class Enumerate implements Iterator
{
/**
* @var Iterator
*/
protected $iterator;

/**
* @var int
*/
protected $key;

/**
* @param Iterator $iterator
*/
public function __construct(Iterator $iterator)
{
$this->iterator = $iterator;
}

public function rewind()
{
$this->iterator->rewind();
$this->key = 0;
}

public function next()
{
$this->iterator->next();
++$this->key;
}

public function valid()
{
return $this->iterator->valid();
}

public function current()
{
return $this->iterator->current();
}

public function key()
{
return $this->key;
}
}

0 comments on commit 51d14af

Please sign in to comment.