Fix case sensitive interpretation of dashboard config files
fixes #10878
This commit is contained in:
parent
f876ed00f0
commit
e9bc11d340
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2016 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Legacy;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\User;
|
||||
|
||||
/**
|
||||
* Legacy dashboard config class for case insensitive interpretation of dashboard config files
|
||||
*
|
||||
* Before 2.2, the username part in dashboard config files was not lowered.
|
||||
*
|
||||
* @deprecated(el): Remove. TBD.
|
||||
*/
|
||||
class DashboardConfig extends Config
|
||||
{
|
||||
/**
|
||||
* User
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Get the user
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List all dashboard configuration files that match the given user
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function listConfigFilesForUser(User $user)
|
||||
{
|
||||
$files = [];
|
||||
$dashboards = static::resolvePath('dashboards');
|
||||
if ($handle = opendir($dashboards)) {
|
||||
while (false !== ($entry = readdir($handle))) {
|
||||
if ($entry[0] === '.' || ! is_dir($dashboards . '/' . $entry)) {
|
||||
continue;
|
||||
}
|
||||
if (strtolower($entry) === strtolower($user->getUsername())) {
|
||||
$files[] = $dashboards . '/' . $entry . '/dashboard.ini';
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function saveIni($filePath = null, $fileMode = 0660)
|
||||
{
|
||||
parent::saveIni($filePath, $fileMode);
|
||||
foreach (static::listConfigFilesForUser($this->user) as $file) {
|
||||
if ($file !== $filePath) {
|
||||
@unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,17 +3,17 @@
|
|||
|
||||
namespace Icinga\Web\Widget;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Legacy\DashboardConfig;
|
||||
use Icinga\User;
|
||||
use Icinga\Web\Navigation\DashboardPane;
|
||||
use Icinga\Web\Navigation\Navigation;
|
||||
use Icinga\Web\Widget\Dashboard\Pane;
|
||||
use Icinga\Web\Widget\Dashboard\Dashlet as DashboardDashlet;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Dashboard\Dashlet as DashboardDashlet;
|
||||
use Icinga\Web\Widget\Dashboard\Pane;
|
||||
|
||||
/**
|
||||
* Dashboards display multiple views on a single page
|
||||
|
@ -108,19 +108,34 @@ class Dashboard extends AbstractWidget
|
|||
}
|
||||
}
|
||||
|
||||
return Config::fromArray($output)->setConfigFile($this->getConfigFile());
|
||||
return DashboardConfig::fromArray($output)->setConfigFile($this->getConfigFile())->setUser($this->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* Load user dashboards from all config files that match the username
|
||||
*/
|
||||
private function loadUserDashboards()
|
||||
protected function loadUserDashboards()
|
||||
{
|
||||
foreach (DashboardConfig::listConfigFilesForUser($this->user) as $file) {
|
||||
$this->loadUserDashboardsFromFile($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load user dashboards from the given config file
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function loadUserDashboardsFromFile($file)
|
||||
{
|
||||
try {
|
||||
$config = Config::fromIni($this->getConfigFile());
|
||||
$config = Config::fromIni($file);
|
||||
} catch (NotReadableError $e) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! count($config)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -439,6 +454,6 @@ class Dashboard extends AbstractWidget
|
|||
if ($this->user === null) {
|
||||
throw new ProgrammingError('Can\'t load dashboards. User is not set');
|
||||
}
|
||||
return Config::resolvePath('dashboards/' . $this->user->getUsername() . '/dashboard.ini');
|
||||
return Config::resolvePath('dashboards/' . strtolower($this->user->getUsername()) . '/dashboard.ini');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue