mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-24 22:34:24 +02:00
Merge branch 'bugfix/preferences-and-navigation-items-stored-in-ini-files-rely-on-case-sensitive-usernames-11051'
fixes #11051
This commit is contained in:
commit
d34b0f0d51
@ -7,6 +7,7 @@ use Exception;
|
|||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Exception\NotFoundError;
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Data\DataArray\ArrayDatasource;
|
use Icinga\Data\DataArray\ArrayDatasource;
|
||||||
|
use Icinga\Data\Filter\FilterMatchCaseInsensitive;
|
||||||
use Icinga\Forms\ConfirmRemovalForm;
|
use Icinga\Forms\ConfirmRemovalForm;
|
||||||
use Icinga\Forms\Navigation\NavigationConfigForm;
|
use Icinga\Forms\Navigation\NavigationConfigForm;
|
||||||
use Icinga\Web\Controller;
|
use Icinga\Web\Controller;
|
||||||
@ -78,7 +79,7 @@ class NavigationController extends Controller
|
|||||||
$config->getConfigObject()->setKeyColumn('name');
|
$config->getConfigObject()->setKeyColumn('name');
|
||||||
$query = $config->select();
|
$query = $config->select();
|
||||||
if ($owner !== null) {
|
if ($owner !== null) {
|
||||||
$query->where('owner', $owner);
|
$query->applyFilter(new FilterMatchCaseInsensitive('owner', '=', $owner));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($query as $itemConfig) {
|
foreach ($query as $itemConfig) {
|
||||||
|
@ -472,11 +472,18 @@ class Config implements Countable, Iterator, Selectable
|
|||||||
$filename = $type . 's.ini';
|
$filename = $type . 's.ini';
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::resolvePath(
|
if ($username) {
|
||||||
($username ? 'preferences' . DIRECTORY_SEPARATOR . $username : 'navigation')
|
$path = static::resolvePath(implode(DIRECTORY_SEPARATOR, array('preferences', $username, $filename)));
|
||||||
. DIRECTORY_SEPARATOR
|
if (realpath($path) === false) {
|
||||||
. $filename
|
$path = static::resolvePath(implode(
|
||||||
);
|
DIRECTORY_SEPARATOR,
|
||||||
|
array('preferences', strtolower($username), $filename)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$path = static::resolvePath('navigation' . DIRECTORY_SEPARATOR . $filename);
|
||||||
|
}
|
||||||
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,7 +172,7 @@ class Web extends EmbeddedWeb
|
|||||||
{
|
{
|
||||||
// TODO: Provide a more sophisticated solution
|
// TODO: Provide a more sophisticated solution
|
||||||
|
|
||||||
if (isset($config['owner']) && $config['owner'] === $this->user->getUsername()) {
|
if (isset($config['owner']) && strtolower($config['owner']) === strtolower($this->user->getUsername())) {
|
||||||
unset($config['owner']);
|
unset($config['owner']);
|
||||||
unset($config['users']);
|
unset($config['users']);
|
||||||
unset($config['groups']);
|
unset($config['groups']);
|
||||||
@ -195,7 +195,7 @@ class Web extends EmbeddedWeb
|
|||||||
|
|
||||||
if (isset($config['users'])) {
|
if (isset($config['users'])) {
|
||||||
$users = array_map('trim', explode(',', strtolower($config['users'])));
|
$users = array_map('trim', explode(',', strtolower($config['users'])));
|
||||||
if (in_array('*', $users, true) || in_array($this->user->getUsername(), $users, true)) {
|
if (in_array('*', $users, true) || in_array(strtolower($this->user->getUsername()), $users, true)) {
|
||||||
unset($config['owner']);
|
unset($config['owner']);
|
||||||
unset($config['users']);
|
unset($config['users']);
|
||||||
unset($config['groups']);
|
unset($config['groups']);
|
||||||
|
@ -11,12 +11,20 @@ class FilterExpression extends Filter
|
|||||||
protected $sign;
|
protected $sign;
|
||||||
protected $expression;
|
protected $expression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this filter compare case sensitive?
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $caseSensitive;
|
||||||
|
|
||||||
public function __construct($column, $sign, $expression)
|
public function __construct($column, $sign, $expression)
|
||||||
{
|
{
|
||||||
$column = trim($column);
|
$column = trim($column);
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
$this->sign = $sign;
|
$this->sign = $sign;
|
||||||
$this->expression = $expression;
|
$this->expression = $expression;
|
||||||
|
$this->caseSensitive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isExpression()
|
public function isExpression()
|
||||||
@ -55,6 +63,16 @@ class FilterExpression extends Filter
|
|||||||
return $this->expression;
|
return $this->expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether this filter compares case sensitive
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getCaseSensitive()
|
||||||
|
{
|
||||||
|
return $this->caseSensitive;
|
||||||
|
}
|
||||||
|
|
||||||
public function setExpression($expression)
|
public function setExpression($expression)
|
||||||
{
|
{
|
||||||
$this->expression = $expression;
|
$this->expression = $expression;
|
||||||
@ -69,6 +87,19 @@ class FilterExpression extends Filter
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this filter's case sensitivity
|
||||||
|
*
|
||||||
|
* @param bool $caseSensitive
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setCaseSensitive($caseSensitive = true)
|
||||||
|
{
|
||||||
|
$this->caseSensitive = $caseSensitive;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function listFilteredColumns()
|
public function listFilteredColumns()
|
||||||
{
|
{
|
||||||
return array($this->getColumn());
|
return array($this->getColumn());
|
||||||
@ -97,6 +128,26 @@ class FilterExpression extends Filter
|
|||||||
return $this->column . $this->sign . $expression;
|
return $this->column . $this->sign . $expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If $var is a scalar, do the same as strtolower() would do.
|
||||||
|
* If $var is an array, map $this->strtolowerRecursive() to its elements.
|
||||||
|
* Otherwise, return $var unchanged.
|
||||||
|
*
|
||||||
|
* @param mixed $var
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function strtolowerRecursive($var)
|
||||||
|
{
|
||||||
|
if ($var === null || is_scalar($var)) {
|
||||||
|
return strtolower($var);
|
||||||
|
}
|
||||||
|
if (is_array($var)) {
|
||||||
|
return array_map(array($this, 'strtolowerRecursive'), $var);
|
||||||
|
}
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
public function matches($row)
|
public function matches($row)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -106,11 +157,18 @@ class FilterExpression extends Filter
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($this->expression)) {
|
if ($this->caseSensitive) {
|
||||||
return in_array($rowValue, $this->expression);
|
$expression = $this->expression;
|
||||||
|
} else {
|
||||||
|
$rowValue = $this->strtolowerRecursive($rowValue);
|
||||||
|
$expression = $this->strtolowerRecursive($this->expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
$expression = (string) $this->expression;
|
if (is_array($expression)) {
|
||||||
|
return in_array($rowValue, $expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
$expression = (string) $expression;
|
||||||
if (strpos($expression, '*') === false) {
|
if (strpos($expression, '*') === false) {
|
||||||
if (is_array($rowValue)) {
|
if (is_array($rowValue)) {
|
||||||
return in_array($expression, $rowValue);
|
return in_array($expression, $rowValue);
|
||||||
|
12
library/Icinga/Data/Filter/FilterMatchCaseInsensitive.php
Normal file
12
library/Icinga/Data/Filter/FilterMatchCaseInsensitive.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Data\Filter;
|
||||||
|
|
||||||
|
class FilterMatchCaseInsensitive extends FilterMatch
|
||||||
|
{
|
||||||
|
public function __construct($column, $sign, $expression) {
|
||||||
|
parent::__construct($column, $sign, $expression);
|
||||||
|
$this->caseSensitive = false;
|
||||||
|
}
|
||||||
|
}
|
12
library/Icinga/Data/Filter/FilterMatchNotCaseInsensitive.php
Normal file
12
library/Icinga/Data/Filter/FilterMatchNotCaseInsensitive.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Data\Filter;
|
||||||
|
|
||||||
|
class FilterMatchNotCaseInsensitive extends FilterMatchNot
|
||||||
|
{
|
||||||
|
public function __construct($column, $sign, $expression) {
|
||||||
|
parent::__construct($column, $sign, $expression);
|
||||||
|
$this->caseSensitive = false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user