mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
Merge branch 'feature/installation-and-configuration-cleanup-5638'
Conflicts: config/config.ini.in library/Icinga/Application/ApplicationBootstrap.php library/Icinga/Application/Cli.php library/Icinga/Application/EmbeddedWeb.php library/Icinga/Application/Logger.php library/Icinga/Application/Modules/Manager.php library/Icinga/Application/Web.php library/Icinga/Authentication/Backend/DbUserBackend.php library/Icinga/Authentication/Manager.php library/Icinga/User/Preferences/IniStore.php test/php/library/Icinga/Application/LoggerTest.php
This commit is contained in:
commit
07d04628cf
.vagrant-puppet
files
etc
var/www/html/icingaweb
manifests
application
controllers
AuthenticationController.phpConfigController.phpDashboardController.phpErrorController.phpPreferenceController.php
layouts/scripts
views
bin
config
configure.acetc
library
Icinga
Application
Authentication
AdmissionLoader.phpAuthChain.php
Backend
Credential.phpGroupBackend.phpManager.phpMembership.phpUserBackend.phpData
Exception
Protocol
Livestatus
Statusdat
Test
User
Preferences.php
Preferences
Util
Web
vendor
Parsedown
dompdf
htmlpurifier-4.5.0-lite/library/HTMLPurifier/DefinitionCache/Serializer
modules/monitoring/library/Monitoring/Backend/Statusdat/Query
public/css/pdf
9
.vagrant-puppet/files/etc/icingaweb/authentication.ini
Normal file
9
.vagrant-puppet/files/etc/icingaweb/authentication.ini
Normal file
@ -0,0 +1,9 @@
|
||||
[internal_ldap_authentication]
|
||||
backend = ldap
|
||||
resource = internal_ldap
|
||||
user_class = inetOrgPerson
|
||||
user_name_attribute = uid
|
||||
|
||||
[internal_db_authentication]
|
||||
backend = db
|
||||
resource = internal_db
|
21
.vagrant-puppet/files/etc/icingaweb/dashboard/dashboard.ini
Normal file
21
.vagrant-puppet/files/etc/icingaweb/dashboard/dashboard.ini
Normal file
@ -0,0 +1,21 @@
|
||||
[Landing]
|
||||
title = "Landing page"
|
||||
[Landing.Hostgroups]
|
||||
url = "monitoring/chart/hostgroup?height=400&width=500"
|
||||
height = "280"
|
||||
width = "500"
|
||||
height = ""
|
||||
width = ""
|
||||
|
||||
[Landing.Servicegroups]
|
||||
url = "monitoring/chart/servicegroup?height=360&width=450"
|
||||
height = "280"
|
||||
width = "500"
|
||||
height = ""
|
||||
width = ""
|
||||
|
||||
[Landing.Unhandled Problem Services]
|
||||
url = "monitoring/list/services?service_handled=0&service_problem=1"
|
||||
|
||||
[Landing.Unhandled Problem Hosts]
|
||||
url = "monitoring/list/hosts?host_handled=0&host_problem=1"
|
@ -0,0 +1,19 @@
|
||||
[localdb]
|
||||
|
||||
type = ido
|
||||
resource = "ido"
|
||||
|
||||
[locallive]
|
||||
disabled = "1"
|
||||
type = livestatus
|
||||
resource = livestatus
|
||||
|
||||
[localfile]
|
||||
disabled = "1"
|
||||
type = statusdat
|
||||
resource = statusdat
|
||||
|
||||
;[localfailsafe]
|
||||
;enabled=false
|
||||
;type = combo
|
||||
;backends = localdb, locallive, localfile
|
@ -0,0 +1,2 @@
|
||||
[icinga]
|
||||
path = "/usr/local/icinga-mysql/var/rw/icinga.cmd"
|
@ -0,0 +1,76 @@
|
||||
|
||||
[Problems]
|
||||
priority = 20
|
||||
icon = "img/icons/error.png"
|
||||
|
||||
[Problems.Unhandled Hosts]
|
||||
icon = "img/icons/host.png"
|
||||
priority = 50
|
||||
url = "monitoring/list/hosts?host_problem=1&host_handled=0"
|
||||
|
||||
[Problems.Unhandled Services]
|
||||
icon = "img/icons/service.png"
|
||||
priority = 50
|
||||
url = "monitoring/list/services?service_problem=1&service_handled=0"
|
||||
|
||||
[Problems.Current Downtimes]
|
||||
url = "monitoring/list/downtimes?downtime_is_in_effect=1"
|
||||
icon = "img/icons/down.png"
|
||||
|
||||
[Overview]
|
||||
priority = 30
|
||||
icon = "img/icons/hostgroup.png"
|
||||
|
||||
[Overview.Hosts]
|
||||
title = "Hosts"
|
||||
url = "monitoring/list/hosts"
|
||||
icon = "img/icons/host.png"
|
||||
priority = 50
|
||||
|
||||
[Overview.Services]
|
||||
title = "Services"
|
||||
url = "monitoring/list/services"
|
||||
icon = "img/icons/service.png"
|
||||
priority = 50
|
||||
|
||||
[Overview.Servicegroups]
|
||||
title = "Servicegroups"
|
||||
url = "monitoring/list/servicegroups"
|
||||
icon = "img/icons/servicegroup.png"
|
||||
priority = 60
|
||||
|
||||
[Overview.Hostgroups]
|
||||
title = "Hostgroups"
|
||||
url = "monitoring/list/hostgroups"
|
||||
icon = "img/icons/hostgroup.png"
|
||||
priority = 60
|
||||
|
||||
[Overview.Downtimes]
|
||||
title = "Downtimes"
|
||||
url = "monitoring/list/downtimes"
|
||||
icon = "img/icons/down.png"
|
||||
priority = 70
|
||||
|
||||
[Overview.Comments]
|
||||
title = "Comments"
|
||||
url = "monitoring/list/comments"
|
||||
icon = "img/icons/comment.png"
|
||||
priority = 70
|
||||
|
||||
[History]
|
||||
icon = "img/icons/history.png"
|
||||
|
||||
[History.Notifications]
|
||||
title = "Notifications"
|
||||
url = "monitoring/list/notifications"
|
||||
icon = "img/icons/notification.png"
|
||||
|
||||
[History.Events]
|
||||
title = "All Events"
|
||||
url = "monitoring/list/eventhistory"
|
||||
icon = "img/icons/history.png"
|
||||
|
||||
[System.Performance]
|
||||
title = "Performance"
|
||||
url = "monitoring/process/performance"
|
||||
|
34
.vagrant-puppet/files/etc/icingaweb/resources.ini
Normal file
34
.vagrant-puppet/files/etc/icingaweb/resources.ini
Normal file
@ -0,0 +1,34 @@
|
||||
[internal_db]
|
||||
type = db
|
||||
db = mysql
|
||||
host = localhost
|
||||
port = 3306
|
||||
password = icingaweb
|
||||
username = icingaweb
|
||||
dbname = icingaweb
|
||||
|
||||
[ido]
|
||||
type = db
|
||||
db = mysql
|
||||
host = localhost
|
||||
port = 3306
|
||||
password = icinga
|
||||
username = icinga
|
||||
dbname = icinga
|
||||
|
||||
[statusdat]
|
||||
type = statusdat
|
||||
status_file = /usr/local/icinga-mysql/var/status.dat
|
||||
object_file = /usr/local/icinga-mysql/var/objects.cache
|
||||
|
||||
[livestatus]
|
||||
type = livestatus
|
||||
socket = /usr/local/icinga-mysql/var/rw/live
|
||||
|
||||
[internal_ldap]
|
||||
type = ldap
|
||||
hostname = localhost
|
||||
port = 389
|
||||
root_dn = "ou=people, dc=icinga, dc=org"
|
||||
bind_dn = "cn=admin,cn=config"
|
||||
bind_pw = admin
|
@ -25,7 +25,7 @@ ICINGA_MYSQL_CMD=${ICINGA_MYSQL_CMD:-"/usr/local/icinga-mysql/var/rw/icinga.cmd"
|
||||
ICINGA_PGSQL_CMD=${ICINGA_PGSQL_CMD:-"/usr/local/icinga-pgsql/var/rw/icinga.cmd"}
|
||||
|
||||
LOCKFILE=${LOCKFILE:-/var/lock/subsys/$PROG}
|
||||
PIDFILE=${PIDFILE:-/var/lock/subsys/$PROG/$PROD.pid}
|
||||
PIDFILE=${PIDFILE:-/var/lock/subsys/$PROG/$PROG.pid}
|
||||
|
||||
RETVAL=0
|
||||
|
||||
|
@ -1,17 +1,16 @@
|
||||
______ ___
|
||||
/\__ _\ __ /'___`\
|
||||
\/_/\ \/ ___ /\_\ ___ __ __ /\_\ /\ \
|
||||
\ \ \ /'___\/\ \ /' _ `\ /'_ `\ /'__`\ \/_/// /__
|
||||
______ ___
|
||||
/\__ _\ __ /'___`\
|
||||
\/_/\ \/ ___ /\_\ ___ __ __ /\_\ /\ \
|
||||
\ \ \ /'___\/\ \ /' _ `\ /'_ `\ /'__`\ \/_/// /__
|
||||
\_\ \__/\ \__/\ \ \/\ \/\ \/\ \L\ \/\ \L\.\_ // /_\ \
|
||||
/\_____\ \____\\ \_\ \_\ \_\ \____ \ \__/.\_\ /\______/
|
||||
\/_____/\/____/ \/_/\/_/\/_/\/___L\ \/__/\/_/ \/_____/
|
||||
/\____/
|
||||
\_/__/
|
||||
__ __ __
|
||||
/\ \ __/\ \ /\ \
|
||||
\ \ \/\ \ \ \ __\ \ \____
|
||||
\ \ \ \ \ \ \ /'__`\ \ '__`\
|
||||
\/_____/\/____/ \/_/\/_/\/_/\/___L\ \/__/\/_/ \/_____/
|
||||
/\____/
|
||||
\_/__/
|
||||
__ __ __
|
||||
/\ \ __/\ \ /\ \
|
||||
\ \ \/\ \ \ \ __\ \ \____
|
||||
\ \ \ \ \ \ \ /'__`\ \ '__`\
|
||||
\ \ \_/ \_\ \/\ __/\ \ \L\ \
|
||||
\ `\___x___/\ \____\\ \_,__/
|
||||
'\/__//__/ \/____/ \/___/
|
||||
|
||||
'\/__//__/ \/____/ \/___/
|
||||
|
12
.vagrant-puppet/files/var/www/html/icingaweb/.htaccess
Normal file
12
.vagrant-puppet/files/var/www/html/icingaweb/.htaccess
Normal file
@ -0,0 +1,12 @@
|
||||
RewriteEngine on
|
||||
RewriteBase /icingaweb
|
||||
RewriteRule ^css/icinga.css css.php
|
||||
RewriteCond %{REQUEST_FILENAME} -s [OR]
|
||||
RewriteCond %{REQUEST_FILENAME} -l [OR]
|
||||
RewriteCond %{REQUEST_FILENAME} -d
|
||||
RewriteRule ^.*$ - [NC,L]
|
||||
RewriteRule ^.*$ index.php [NC,L]
|
||||
|
||||
php_flag short_open_tag on
|
||||
|
||||
php_value xdebug.idekey PHPSTORM
|
4
.vagrant-puppet/files/var/www/html/icingaweb/index.php
Normal file
4
.vagrant-puppet/files/var/www/html/icingaweb/index.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
require_once '/vagrant/library/Icinga/Application/Web.php';
|
||||
use Icinga\Application\Web;
|
||||
Web::start('/etc/icingaweb')->dispatch();
|
@ -338,31 +338,25 @@ package { ['cmake', 'boost-devel', 'bison', 'flex']:
|
||||
# make_timeout => 900
|
||||
#}
|
||||
|
||||
configure { 'icingaweb':
|
||||
path => '/vagrant',
|
||||
flags => '--prefix=/vagrant \
|
||||
--with-icinga-commandpipe="/usr/local/icinga-mysql/var/rw/icinga.cmd" \
|
||||
--with-statusdat-file="/usr/local/icinga-mysql/var/status.dat" \
|
||||
--with-objects-cache-file=/usr/local/icinga-mysql/var/objects.cache \
|
||||
--with-icinga-backend=ido \
|
||||
--with-httpd-config-path="/etc/httpd/conf.d" \
|
||||
--with-ldap-authentication \
|
||||
--with-internal-authentication \
|
||||
--with-livestatus-socket="/usr/local/icinga-mysql/var/rw/live"',
|
||||
require => Exec['install php-ZendFramework']
|
||||
}
|
||||
#configure { 'icingaweb':
|
||||
# path => '/vagrant',
|
||||
# flags => '--prefix=/vagrant \
|
||||
# --with-icinga-commandpipe="/usr/local/icinga-mysql/var/rw/icinga.cmd" \
|
||||
# --with-statusdat-file="/usr/local/icinga-mysql/var/status.dat" \
|
||||
# --with-objects-cache-file=/usr/local/icinga-mysql/var/objects.cache \
|
||||
# --with-icinga-backend=ido \
|
||||
# --with-httpd-config-path="/etc/httpd/conf.d" \
|
||||
# --with-ldap-authentication \
|
||||
# --with-internal-authentication \
|
||||
# --with-livestatus-socket="/usr/local/icinga-mysql/var/rw/live"',
|
||||
# require => Exec['install php-ZendFramework']
|
||||
#}
|
||||
|
||||
file { 'icingaweb-public':
|
||||
ensure => '/vagrant/public',
|
||||
path => '/var/www/html/icingaweb',
|
||||
require => Class['apache']
|
||||
}
|
||||
|
||||
file { '/etc/httpd/conf.d/icingaweb.conf':
|
||||
source => 'puppet:////vagrant/.vagrant-puppet/files/etc/httpd/conf.d/icingaweb.conf',
|
||||
require => Package['apache'],
|
||||
notify => Service['apache']
|
||||
}
|
||||
#file { 'icingaweb-public':
|
||||
# ensure => '/vagrant/public',
|
||||
# path => '/var/www/html/icingaweb',
|
||||
# require => Class['apache']
|
||||
#}
|
||||
|
||||
exec { 'install php-ZendFramework-Db-Adapter-Pdo-Mysql':
|
||||
command => 'yum -d 0 -e 0 -y --enablerepo=epel install php-ZendFramework-Db-Adapter-Pdo-Mysql',
|
||||
@ -570,3 +564,132 @@ exec { 'populate-icinga_web-mysql-db':
|
||||
command => 'mysql -uicinga_web -picinga_web icinga_web < /usr/local/src/icinga-web/icinga-web-1.10.0-beta/etc/schema/mysql.sql',
|
||||
require => [ Exec['create-mysql-icinga_web-db'], Cmmi['icinga-web'] ]
|
||||
}
|
||||
|
||||
#
|
||||
# Development environment (Feature #5554)
|
||||
#
|
||||
file { '/var/www/html/icingaweb':
|
||||
ensure => 'directory',
|
||||
owner => 'apache',
|
||||
group => 'apache'
|
||||
}
|
||||
|
||||
file { '/var/www/html/icingaweb/css':
|
||||
ensure => 'link',
|
||||
target => '/vagrant/public/css',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/var/www/html/icingaweb']
|
||||
}
|
||||
|
||||
file { '/var/www/html/icingaweb/img':
|
||||
ensure => 'link',
|
||||
target => '/vagrant/public/img',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/var/www/html/icingaweb']
|
||||
}
|
||||
|
||||
file { '/var/www/html/icingaweb/js':
|
||||
ensure => 'link',
|
||||
target => '/vagrant/public/js',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/var/www/html/icingaweb']
|
||||
}
|
||||
|
||||
file { '/var/www/html/icingaweb/index.php':
|
||||
source => 'puppet:////vagrant/.vagrant-puppet/files/var/www/html/icingaweb/index.php',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/var/www/html/icingaweb']
|
||||
}
|
||||
|
||||
file { '/var/www/html/icingaweb/.htaccess':
|
||||
source => 'puppet:////vagrant/.vagrant-puppet/files/var/www/html/icingaweb/.htaccess',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/var/www/html/icingaweb']
|
||||
}
|
||||
|
||||
file { '/etc/httpd/conf.d/icingaweb.conf':
|
||||
source => 'puppet:////vagrant/.vagrant-puppet/files/etc/httpd/conf.d/icingaweb.conf',
|
||||
require => Package['apache'],
|
||||
notify => Service['apache']
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb':
|
||||
ensure => 'directory',
|
||||
owner => 'apache',
|
||||
group => 'apache'
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb/authentication.ini':
|
||||
source => 'puppet:////vagrant/.vagrant-puppet/files/etc/icingaweb/authentication.ini',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/etc/icingaweb']
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb/resources.ini':
|
||||
source => 'puppet:////vagrant/.vagrant-puppet/files/etc/icingaweb/resources.ini',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/etc/icingaweb']
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb/enabledModules':
|
||||
ensure => 'directory',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/etc/icingaweb']
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb/modules':
|
||||
ensure => 'directory',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/etc/icingaweb']
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb/modules/monitoring':
|
||||
ensure => 'directory',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/etc/icingaweb/modules']
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb/modules/monitoring/backends.ini':
|
||||
source => 'puppet:////vagrant/.vagrant-puppet/files/etc/icingaweb/modules/monitoring/backends.ini',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/etc/icingaweb/modules/monitoring']
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb/modules/monitoring/instances.ini':
|
||||
source => 'puppet:////vagrant/.vagrant-puppet/files/etc/icingaweb/modules/monitoring/instances.ini',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/etc/icingaweb/modules/monitoring']
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb/modules/monitoring/menu.ini':
|
||||
source => 'puppet:////vagrant/.vagrant-puppet/files/etc/icingaweb/modules/monitoring/menu.ini',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/etc/icingaweb/modules/monitoring']
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb/dashboard':
|
||||
ensure => 'directory',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/etc/icingaweb']
|
||||
}
|
||||
|
||||
file { '/etc/icingaweb/dashboard/dashboard.ini':
|
||||
source => 'puppet:////vagrant/.vagrant-puppet/files/etc/icingaweb/dashboard/dashboard.ini',
|
||||
owner => 'apache',
|
||||
group => 'apache',
|
||||
require => File['/etc/icingaweb/dashboard']
|
||||
}
|
||||
|
0
aclocal.m4
vendored
Executable file → Normal file
0
aclocal.m4
vendored
Executable file → Normal file
@ -30,11 +30,14 @@
|
||||
|
||||
# namespace Icinga\Application\Controllers;
|
||||
|
||||
use \Exception;
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Authentication\Credential;
|
||||
use Icinga\Authentication\Manager as AuthManager;
|
||||
use Icinga\Form\Authentication\LoginForm;
|
||||
use Icinga\Authentication\AuthChain;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\User;
|
||||
|
||||
/**
|
||||
* Application wide controller for authentication
|
||||
@ -64,16 +67,52 @@ class AuthenticationController extends ActionController
|
||||
$this->redirectNow($redirectUrl);
|
||||
}
|
||||
if ($this->view->form->isSubmittedAndValid()) {
|
||||
$credentials = new Credential(
|
||||
$this->view->form->getValue('username'),
|
||||
$this->view->form->getValue('password')
|
||||
$user = new User(
|
||||
$this->view->form->getValue('username')
|
||||
);
|
||||
if (!$auth->authenticate($credentials)) {
|
||||
$this->view->form->getElement('password')
|
||||
->addError(t('Please provide a valid username and password'));
|
||||
} else {
|
||||
$this->redirectNow($redirectUrl);
|
||||
try {
|
||||
$config = Config::app('authentication');
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error(
|
||||
new Exception('Cannot load authentication configuration. An exception was thrown:', 0, $e)
|
||||
);
|
||||
throw new ConfigurationError(
|
||||
'No authentication methods available. It seems that none authentication method has been set'
|
||||
. ' up. Please contact your Icinga Web administrator'
|
||||
);
|
||||
}
|
||||
$backendsWithError = 0;
|
||||
// TODO(el): Currently the user is only notified about authentication backend problems when all backends
|
||||
// have errors. It may be the case that the authentication backend which provides the user has errors
|
||||
// but other authentication backends work. In that scenario the user is presented an error message
|
||||
// saying "Incorrect username or password". We must inform the user that not all authentication methods
|
||||
// are available.
|
||||
$backendsTried = 0;
|
||||
$chain = new AuthChain($config);
|
||||
foreach ($chain as $backend) {
|
||||
++$backendsTried;
|
||||
try {
|
||||
if ($backend->authenticate($user, $this->view->form->getValue('password'))) {
|
||||
$auth->setAuthenticated($user);
|
||||
$this->redirectNow($redirectUrl);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Logger::error(
|
||||
new Exception(
|
||||
'Cannot authenticate against backend "' . $backend->getName() . '".'
|
||||
. ' An exception was thrown:', 0, $e
|
||||
)
|
||||
);
|
||||
++$backendsWithError;
|
||||
}
|
||||
}
|
||||
if ($backendsWithError === $backendsTried) {
|
||||
throw new ConfigurationError(
|
||||
'No authentication methods available. It seems that all set up authentication methods have'
|
||||
. ' errors. Please contact your Icinga Web administrator'
|
||||
);
|
||||
}
|
||||
$this->view->form->getElement('password')->addError(t('Incorrect username or password'));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->view->errorInfo = $e->getMessage();
|
||||
|
@ -113,7 +113,7 @@ class ConfigController extends BaseConfigController
|
||||
{
|
||||
$this->view->messageBox = new AlertMessageBox(true);
|
||||
$form = new GeneralForm();
|
||||
$form->setConfiguration(IcingaConfig::app());
|
||||
//$form->setConfiguration(IcingaConfig::app());
|
||||
$form->setRequest($this->_request);
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
if (!$this->writeConfigFile($form->getConfig(), 'config')) {
|
||||
@ -465,11 +465,11 @@ class ConfigController extends BaseConfigController
|
||||
$form = new ConfirmRemovalForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setRemoveTarget('resource', $name);
|
||||
|
||||
|
||||
// Check if selected resource is currently used for authentication
|
||||
$authConfig = IcingaConfig::app('authentication', true)->toArray();
|
||||
foreach ($authConfig as $backendName => $config) {
|
||||
if (array_key_exists('resource', $config) && $config['resource'] === $name) {
|
||||
if (array_key_exists('resource', $config) && $config['resource'] === $name) {
|
||||
$this->addErrorMessage(
|
||||
'Warning: The resource "' . $name . '" is currently used for user authentication by "' . $backendName . '". ' .
|
||||
' Deleting it could eventally make login impossible.'
|
||||
|
@ -28,13 +28,14 @@
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
use \Icinga\Web\Controller\ActionController;
|
||||
use \Icinga\Web\Url;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Web\Widget\Dashboard;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Form\Dashboard\AddUrlForm;
|
||||
use \Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Dashboard;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Form\Dashboard\AddUrlForm;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Logger\Logger;
|
||||
|
||||
/**
|
||||
* Handle creation, removal and displaying of dashboards, panes and components
|
||||
@ -53,7 +54,12 @@ class DashboardController extends ActionController
|
||||
private function getDashboard($config = 'dashboard/dashboard')
|
||||
{
|
||||
$dashboard = new Dashboard();
|
||||
$dashboard->readConfig(IcingaConfig::app($config));
|
||||
try {
|
||||
$dashboardConfig = IcingaConfig::app($config);
|
||||
$dashboard->readConfig($dashboardConfig);
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error(new Exception('Cannot load dashboard configuration. An exception was thrown:', 0, $e));
|
||||
}
|
||||
return $dashboard;
|
||||
}
|
||||
|
||||
|
2
application/controllers/ErrorController.php
Executable file → Normal file
2
application/controllers/ErrorController.php
Executable file → Normal file
@ -37,6 +37,8 @@ use \Icinga\Web\Controller\ActionController;
|
||||
*/
|
||||
class ErrorController extends ActionController
|
||||
{
|
||||
protected $requiresAuthentication = false;
|
||||
|
||||
/**
|
||||
* Display exception
|
||||
*/
|
||||
|
@ -28,18 +28,17 @@
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
use \Icinga\Web\Controller\BasePreferenceController;
|
||||
use \Icinga\Web\Widget\Tab;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Web\Url;
|
||||
use \Icinga\Form\Preference\GeneralForm;
|
||||
use Icinga\Web\Controller\BasePreferenceController;
|
||||
use Icinga\Web\Widget\Tab;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Form\Preference\GeneralForm;
|
||||
|
||||
/**
|
||||
* Application wide preference controller for user preferences
|
||||
*/
|
||||
class PreferenceController extends BasePreferenceController
|
||||
{
|
||||
|
||||
/**
|
||||
* Create tabs for this preference controller
|
||||
*
|
||||
@ -66,34 +65,21 @@ class PreferenceController extends BasePreferenceController
|
||||
public function indexAction()
|
||||
{
|
||||
$form = new GeneralForm();
|
||||
$form->setConfiguration(IcingaConfig::app());
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setConfiguration(IcingaConfig::app())
|
||||
->setRequest($this->getRequest());
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
$preferences = $form->getPreferences();
|
||||
$userPreferences = $this->getRequest()->getUser()->getPreferences();
|
||||
|
||||
$userPreferences->startTransaction();
|
||||
foreach ($preferences as $key => $value) {
|
||||
if (!$value) {
|
||||
$userPreferences->remove($key);
|
||||
} else {
|
||||
$userPreferences->set($key, $value);
|
||||
}
|
||||
}
|
||||
try {
|
||||
$userPreferences->commit();
|
||||
$this->view->successMessage = "Preferences Updated Successfully";
|
||||
|
||||
// recreate form to show new values
|
||||
$this->savePreferences($form->getPreferences());
|
||||
$this->view->successMessage = 'Preferences Updated Successfully';
|
||||
// Recreate form to show new values
|
||||
// TODO(el): It must sufficient to call $form->populate(...)
|
||||
$form = new GeneralForm();
|
||||
$form->setConfiguration(IcingaConfig::app());
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->view->exceptionMessage = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
}
|
||||
}
|
||||
|
0
application/layouts/scripts/body.phtml
Executable file → Normal file
0
application/layouts/scripts/body.phtml
Executable file → Normal file
0
application/layouts/scripts/layout.phtml
Executable file → Normal file
0
application/layouts/scripts/layout.phtml
Executable file → Normal file
0
application/layouts/scripts/login.phtml
Executable file → Normal file
0
application/layouts/scripts/login.phtml
Executable file → Normal file
0
application/layouts/scripts/parts/navigation.phtml
Executable file → Normal file
0
application/layouts/scripts/parts/navigation.phtml
Executable file → Normal file
0
application/layouts/scripts/parts/topbar.phtml
Executable file → Normal file
0
application/layouts/scripts/parts/topbar.phtml
Executable file → Normal file
0
application/views/helpers/Auth.php
Executable file → Normal file
0
application/views/helpers/Auth.php
Executable file → Normal file
0
application/views/scripts/error/error.phtml
Executable file → Normal file
0
application/views/scripts/error/error.phtml
Executable file → Normal file
0
application/views/scripts/mixedPagination.phtml
Executable file → Normal file
0
application/views/scripts/mixedPagination.phtml
Executable file → Normal file
@ -11,6 +11,5 @@ set_include_path(
|
||||
);
|
||||
|
||||
require_once 'Icinga/Application/Cli.php';
|
||||
date_default_timezone_set('UTC');
|
||||
$app = Cli::start(dirname(__FILE__) . '/../config/')->dispatch();
|
||||
|
||||
|
19
config/authentication.ini.in
Executable file → Normal file
19
config/authentication.ini.in
Executable file → Normal file
@ -1,29 +1,20 @@
|
||||
; authentication.ini
|
||||
;
|
||||
; Each section listed in this configuration represents a single backend
|
||||
; that can be used to authenticate users or groups. Each databse backend must refer
|
||||
; to a resource defined in resources.ini,
|
||||
; Each section listed in this configuration represents a backend used to authenticate users. The backend configurations
|
||||
: must define a resource referring to a configured database or LDAP connection in the INI file resources.ini.
|
||||
;
|
||||
; The order of entries in this configuration is used to determine the fallback
|
||||
; priority in case of an error. If the resource referenced in the first
|
||||
; entry is not reachable, the next lower entry will be used for authentication.
|
||||
; Please be aware that this behaviour is not valid for the authentication itself.
|
||||
; The authentication will only be done against the one available resource with the highest
|
||||
; priority.
|
||||
; The backends will be processed from top to bottom using the first backend for authentication which reports that
|
||||
; the user trying to log in is available.
|
||||
|
||||
|
||||
[internal_ldap_authentication]
|
||||
@ldap_auth_disabled@
|
||||
backend = ldap
|
||||
target = user
|
||||
resource = internal_ldap
|
||||
; Object class of the user
|
||||
user_class = @ldap_user_objectclass@
|
||||
; ; Attribute name for username
|
||||
user_name_attribute = @ldap_attribute_username@
|
||||
|
||||
[internal_db_authentication]
|
||||
@internal_auth_disabled@
|
||||
backend = db
|
||||
target = "user"
|
||||
resource = "internal_db"
|
||||
resource = internal_db
|
||||
|
21
config/config.ini.in
Executable file → Normal file
21
config/config.ini.in
Executable file → Normal file
@ -6,12 +6,9 @@ indexController = "dashboard"
|
||||
dateFormat = "d/m/Y"
|
||||
timeFormat = "g:i A"
|
||||
|
||||
; The directory that contains the symlinks to all enabled directories.
|
||||
moduleFolder = "@icingaweb_config_path@/enabledModules"
|
||||
|
||||
; Contains the directories that will be searched for available modules. Modules that
|
||||
; don't exist in these directories can still be symlinked in the module folder, but
|
||||
; won't show up in the list of disabled modules.
|
||||
; won't show up in the list of disabled modules
|
||||
; modulePath = "/vagrant/modules:/usr/share/icingaweb/modules"
|
||||
|
||||
; The used authentication-mode can be either "internal" to handle the authentication in IcingaWeb
|
||||
@ -19,7 +16,7 @@ moduleFolder = "@icingaweb_config_path@/enabledModules"
|
||||
authenticationMode = "internal"
|
||||
|
||||
[logging]
|
||||
enable = true
|
||||
;enable = false
|
||||
; Writing to a Stream
|
||||
type = "stream"
|
||||
; Write data to the following file
|
||||
@ -44,13 +41,13 @@ level = 1
|
||||
; INFO = 2 - Informational: informational messages
|
||||
; DEBUG = 3 - Debug: debug messages
|
||||
|
||||
; Use ini store to store preferences on local disk
|
||||
[preferences]
|
||||
; Use INI file storage to save preferences to a local disk
|
||||
type = "ini"
|
||||
|
||||
; Use database to store preference into mysql or postgres
|
||||
;[preferences]
|
||||
;type=db
|
||||
;resource=icingaweb-mysql
|
||||
|
||||
configPath = "@icingaweb_config_path@/preferences"
|
||||
|
||||
; Use database storage to save preferences in either a MySQL or PostgreSQL database
|
||||
;type = db
|
||||
;resource = icingaweb-mysql
|
||||
|
||||
|
||||
|
0
config/menu.ini
Executable file → Normal file
0
config/menu.ini
Executable file → Normal file
0
config/modules/monitoring/menu.ini
Executable file → Normal file
0
config/modules/monitoring/menu.ini
Executable file → Normal file
0
config/resources.ini.in
Executable file → Normal file
0
config/resources.ini.in
Executable file → Normal file
0
configure.ac
Executable file → Normal file
0
configure.ac
Executable file → Normal file
0
etc/apache/icingaweb.conf.in
Executable file → Normal file
0
etc/apache/icingaweb.conf.in
Executable file → Normal file
0
etc/module_skeleton/config/menu.ini
Executable file → Normal file
0
etc/module_skeleton/config/menu.ini
Executable file → Normal file
124
library/Icinga/Application/ApplicationBootstrap.php
Executable file → Normal file
124
library/Icinga/Application/ApplicationBootstrap.php
Executable file → Normal file
@ -29,17 +29,17 @@
|
||||
|
||||
namespace Icinga\Application;
|
||||
|
||||
use \Exception;
|
||||
use \DateTimeZone;
|
||||
use \Zend_Config;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Modules\Manager as ModuleManager;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Util\Translator;
|
||||
use Icinga\Logger\Logger;
|
||||
|
||||
use Icinga\Data\ResourceFactory;
|
||||
|
||||
/**
|
||||
* This class bootstraps a thin Icinga application layer
|
||||
@ -82,9 +82,9 @@ abstract class ApplicationBootstrap
|
||||
/**
|
||||
* Config object
|
||||
*
|
||||
* @var Config
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $config;
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Configuration directory
|
||||
@ -126,7 +126,7 @@ abstract class ApplicationBootstrap
|
||||
*/
|
||||
protected function __construct($configDir)
|
||||
{
|
||||
$this->libDir = realpath(__DIR__. '/../..');
|
||||
$this->libDir = realpath(__DIR__ . '/../..');
|
||||
|
||||
if (!defined('ICINGA_LIBDIR')) {
|
||||
define('ICINGA_LIBDIR', $this->libDir);
|
||||
@ -259,40 +259,11 @@ abstract class ApplicationBootstrap
|
||||
*/
|
||||
public static function start($configDir)
|
||||
{
|
||||
$class = get_called_class();
|
||||
/** @var ApplicationBootstrap $obj */
|
||||
$application = new $class($configDir);
|
||||
$application = new static($configDir);
|
||||
$application->bootstrap();
|
||||
|
||||
return $application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop application and show information about errors
|
||||
*
|
||||
* @param array $errors
|
||||
*/
|
||||
public function stopApplication(array $errors = array())
|
||||
{
|
||||
$msg = "Application could not be started!\n\n";
|
||||
|
||||
if (count($errors)) {
|
||||
foreach ($errors as $error) {
|
||||
$msg .= $error[0]. "\n";
|
||||
}
|
||||
} else {
|
||||
$msg .= "Further information about the error may have been written to the application's log file.\n"
|
||||
. 'Please check it in order to analyse the problem.';
|
||||
}
|
||||
|
||||
if ($this->isWeb()) {
|
||||
$msg = nl2br($msg);
|
||||
}
|
||||
|
||||
echo $msg;
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup Icinga auto loader
|
||||
*
|
||||
@ -300,7 +271,7 @@ abstract class ApplicationBootstrap
|
||||
*/
|
||||
public function setupAutoloader()
|
||||
{
|
||||
require $this->libDir. '/Icinga/Application/Loader.php';
|
||||
require $this->libDir . '/Icinga/Application/Loader.php';
|
||||
|
||||
$this->loader = new Loader();
|
||||
$this->loader->registerNamespace('Icinga', $this->libDir. '/Icinga');
|
||||
@ -342,7 +313,12 @@ abstract class ApplicationBootstrap
|
||||
$this->moduleManager = new ModuleManager(
|
||||
$this,
|
||||
$this->configDir . '/enabledModules',
|
||||
explode(':', $this->config->global->get('modulePath', ICINGA_APPDIR . '/../modules'))
|
||||
explode(
|
||||
':',
|
||||
$this->config->global !== null
|
||||
? $this->config->global->get('modulePath', ICINGA_APPDIR . '/../modules')
|
||||
: ICINGA_APPDIR . '/../modules'
|
||||
)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
@ -356,8 +332,8 @@ abstract class ApplicationBootstrap
|
||||
{
|
||||
try {
|
||||
$this->moduleManager->loadEnabledModules();
|
||||
} catch (Exception $e) {
|
||||
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error(new Exception('Cannot load enabled modules. An exception was thrown:', 0, $e));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
@ -380,7 +356,6 @@ abstract class ApplicationBootstrap
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -389,10 +364,15 @@ abstract class ApplicationBootstrap
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function setupConfig()
|
||||
protected function loadConfig()
|
||||
{
|
||||
Config::$configDir = $this->configDir;
|
||||
$this->config = Config::app();
|
||||
try {
|
||||
$this->config = Config::app();
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error(new Exception('Cannot load application configuration. An exception was thrown:', 0, $e));
|
||||
$this->config = new Zend_Config(array());
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -403,30 +383,45 @@ abstract class ApplicationBootstrap
|
||||
*/
|
||||
protected function setupErrorHandling()
|
||||
{
|
||||
if ($this->config->get('global', 'environment') == 'development') {
|
||||
error_reporting(E_ALL | E_NOTICE);
|
||||
ini_set('display_startup_errors', 1);
|
||||
ini_set('display_errors', 1);
|
||||
}
|
||||
|
||||
try {
|
||||
Logger::create($this->config->logging);
|
||||
} catch (ConfigurationError $e) {
|
||||
Logger::error($e);
|
||||
}
|
||||
|
||||
error_reporting(E_ALL | E_NOTICE);
|
||||
ini_set('display_startup_errors', 1);
|
||||
ini_set('display_errors', 1);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup factories that provide access to the resources
|
||||
* Set up logger
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function setupLogger()
|
||||
{
|
||||
if ($this->config->logging !== null) {
|
||||
try {
|
||||
Logger::create($this->config->logging);
|
||||
} catch (ConfigurationError $e) {
|
||||
Logger::error($e);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the resource factory
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function setupResourceFactory()
|
||||
{
|
||||
$config = Config::app('resources');
|
||||
ResourceFactory::setConfig($config);
|
||||
try {
|
||||
$config = Config::app('resources');
|
||||
ResourceFactory::setConfig($config);
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error(
|
||||
new Exception('Cannot load resource configuration. An exception was thrown:', 0, $e)
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -438,7 +433,7 @@ abstract class ApplicationBootstrap
|
||||
*/
|
||||
protected function setupTimezone()
|
||||
{
|
||||
$timeZoneString = $this->config->global->get('timezone', 'UTC');
|
||||
$timeZoneString = $this->config->global !== null ? $this->config->global->get('timezone', 'UTC') : 'UTC';
|
||||
try {
|
||||
$tz = new DateTimeZone($timeZoneString);
|
||||
} catch (Exception $e) {
|
||||
@ -459,7 +454,10 @@ abstract class ApplicationBootstrap
|
||||
protected function setupInternationalization()
|
||||
{
|
||||
try {
|
||||
Translator::setupLocale($this->config->global->get('language', Translator::DEFAULT_LOCALE));
|
||||
Translator::setupLocale(
|
||||
$this->config->global !== null ? $this->config->global->get('language', Translator::DEFAULT_LOCALE)
|
||||
: Translator::DEFAULT_LOCALE
|
||||
);
|
||||
} catch (Exception $error) {
|
||||
Logger::error($error);
|
||||
}
|
||||
|
0
library/Icinga/Application/Benchmark.php
Executable file → Normal file
0
library/Icinga/Application/Benchmark.php
Executable file → Normal file
@ -62,11 +62,13 @@ class Cli extends ApplicationBootstrap
|
||||
{
|
||||
$this->assertRunningOnCli();
|
||||
$this->setupLogging()
|
||||
->setupConfig()
|
||||
->fixLoggingConfig()
|
||||
->setupErrorHandling()
|
||||
->loadConfig()
|
||||
->setupTimezone()
|
||||
->setupInternationalization()
|
||||
->parseBasicParams()
|
||||
->fixLoggingConfig()
|
||||
->setupLogger()
|
||||
->setupResourceFactory()
|
||||
->setupModuleManager();
|
||||
}
|
||||
|
@ -29,8 +29,9 @@
|
||||
|
||||
namespace Icinga\Application;
|
||||
|
||||
use \Icinga\Exception\ProgrammingError;
|
||||
use \Zend_Config_Ini;
|
||||
use Zend_Config_Ini;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
||||
/**
|
||||
* Global registry of application and module configuration.
|
||||
@ -68,22 +69,25 @@ class Config extends Zend_Config_Ini
|
||||
/**
|
||||
* Load configuration from the config file $filename
|
||||
*
|
||||
* @param string $filename The filename to parse
|
||||
* @param string $filename The filename to parse
|
||||
|
||||
* @see Zend_Config_Ini::__construct
|
||||
* @throws Exception When the file can't be read
|
||||
* @throws NotReadableError When the file does not exist or cannot be read
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
if (!@is_readable($filename)) {
|
||||
throw new \Exception('Cannot read config file: ' . $filename);
|
||||
$canonical = realpath($filename);
|
||||
if ($canonical === false) {
|
||||
throw new NotReadableError('Cannot read config file "' . $filename . '". Config file does not exist');
|
||||
}
|
||||
if (!is_readable($canonical)) {
|
||||
throw new NotReadableError('Cannot read config file "' . $filename . '". Permission denied');
|
||||
};
|
||||
$this->configFile = $filename;
|
||||
$this->configFile = $canonical;
|
||||
$section = null;
|
||||
$options = array(
|
||||
'allowModifications' => true
|
||||
);
|
||||
parent::__construct($filename, $section, $options);
|
||||
parent::__construct($canonical, $section, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,7 +103,7 @@ class Config extends Zend_Config_Ini
|
||||
{
|
||||
if (!isset(self::$app[$configname]) || $fromDisk) {
|
||||
$filename = self::$configDir . '/' . $configname . '.ini';
|
||||
self::$app[$configname] = new Config(realpath($filename));
|
||||
self::$app[$configname] = new Config($filename);
|
||||
}
|
||||
return self::$app[$configname];
|
||||
}
|
||||
|
0
library/Icinga/Application/Loader.php
Executable file → Normal file
0
library/Icinga/Application/Loader.php
Executable file → Normal file
@ -37,6 +37,7 @@ use Icinga\Data\DataArray\Query as ArrayQuery;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\SystemPermissionException;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
|
||||
/**
|
||||
* Module manager that handles detecting, enabling and disabling of modules
|
||||
@ -99,22 +100,10 @@ class Manager
|
||||
* the given path
|
||||
* @param array $availableDirs Installed modules location
|
||||
**/
|
||||
public function __construct($app, $enabledDir = null, array $availableDirs = array())
|
||||
public function __construct($app, $enabledDir, array $availableDirs)
|
||||
{
|
||||
$this->app = $app;
|
||||
if (empty($availableDirs)) {
|
||||
$availableDirs = array(realpath(ICINGA_APPDIR . '/../modules'));
|
||||
} else {
|
||||
foreach ($availableDirs as $key => $dir) {
|
||||
$dir[$key] = realpath($dir);
|
||||
}
|
||||
}
|
||||
$this->modulePaths = $availableDirs;
|
||||
if ($enabledDir === null) {
|
||||
$enabledDir = $this->app->getConfigDir() . '/enabledModules';
|
||||
}
|
||||
$enabledDir = realpath($enabledDir);
|
||||
|
||||
$this->enableDir = $enabledDir;
|
||||
}
|
||||
|
||||
@ -134,54 +123,59 @@ class Manager
|
||||
*
|
||||
* Update the internal $enabledDirs property with the enabled modules.
|
||||
*
|
||||
* @throws ConfigurationError If module dir is not a directory or not readable
|
||||
* @throws ConfigurationError If module dir does not exist, is not a directory or not readable
|
||||
*/
|
||||
private function detectEnabledModules()
|
||||
{
|
||||
$canonical = $this->enableDir;
|
||||
if ($canonical === false) {
|
||||
throw new NotReadableError(
|
||||
'Cannot read enabled modules. Module directory "' . $this->enableDir . '" does not exist'
|
||||
);
|
||||
}
|
||||
if (!is_dir($this->enableDir)) {
|
||||
throw new ConfigurationError(
|
||||
'Could not read enabled modules: Module directory is not a directory: ' . $this->enableDir
|
||||
throw new NotReadableError(
|
||||
'Cannot read enabled modules. Module directory "' . $this->enableDir . '" is not a directory'
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_readable($this->enableDir)) {
|
||||
throw new ConfigurationError(
|
||||
'Could not read enabled modules: Module directory is not readable: ' . $this->enableDir
|
||||
throw new NotReadableError(
|
||||
'Cannot read enabled modules. Module directory "' . $this->enableDir . '" is not readable'
|
||||
);
|
||||
}
|
||||
if (($dh = opendir($canonical)) !== false) {
|
||||
$this->enabledDirs = array();
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
|
||||
$fh = opendir($this->enableDir);
|
||||
if ($file[0] === '.' || $file === 'README') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->enabledDirs = array();
|
||||
while (false !== ($file = readdir($fh))) {
|
||||
$link = $this->enableDir . '/' . $file;
|
||||
if (! is_link($link)) {
|
||||
Logger::warn(
|
||||
'Found invalid module in enabledModule directory "%s": "%s" is not a symlink',
|
||||
$this->enableDir,
|
||||
$link
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file[0] === '.' || $file === 'README') {
|
||||
continue;
|
||||
$dir = realpath($link);
|
||||
if (!file_exists($dir) || !is_dir($dir)) {
|
||||
Logger::warn(
|
||||
'Found invalid module in enabledModule directory "%s": "%s" points to non existing path "%s"',
|
||||
$this->enableDir,
|
||||
$link,
|
||||
$dir
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->enabledDirs[$file] = $dir;
|
||||
ksort($this->enabledDirs);
|
||||
}
|
||||
|
||||
$link = $this->enableDir . '/' . $file;
|
||||
if (! is_link($link)) {
|
||||
Logger::warning(
|
||||
'Found invalid module in enabledModule directory "%s": "%s" is not a symlink',
|
||||
$this->enableDir,
|
||||
$link
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
$dir = realpath($link);
|
||||
if (!file_exists($dir) || !is_dir($dir)) {
|
||||
Logger::warning(
|
||||
'Found invalid module in enabledModule directory "%s": "%s" points to non existing path "%s"',
|
||||
$this->enableDir,
|
||||
$link,
|
||||
$dir
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->enabledDirs[$file] = $dir;
|
||||
ksort($this->enabledDirs);
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,6 +268,7 @@ class Manager
|
||||
$this->enabledDirs[$name] = $link;
|
||||
|
||||
$this->loadModule($name);
|
||||
$this->getModule($name)->launchRegisterScript();
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -516,29 +511,37 @@ class Manager
|
||||
public function detectInstalledModules()
|
||||
{
|
||||
foreach ($this->modulePaths as $basedir) {
|
||||
if (!file_exists($basedir)) {
|
||||
Logger::warning('Module path "%s" does not exist.', $basedir);
|
||||
$canonical = realpath($basedir);
|
||||
if ($canonical === false) {
|
||||
Logger::warn('Module path "%s" does not exist', $basedir);
|
||||
continue;
|
||||
}
|
||||
$fh = opendir($basedir);
|
||||
if ($fh === false) {
|
||||
return $this;
|
||||
if (!is_dir($canonical)) {
|
||||
Logger::err('Module path "%s" is not a directory', $canonical);
|
||||
continue;
|
||||
}
|
||||
while ($name = readdir($fh)) {
|
||||
if ($name[0] === '.') {
|
||||
continue;
|
||||
}
|
||||
if (is_dir($basedir . '/' . $name)) {
|
||||
if (! array_key_exists($name, $this->installedBaseDirs)) {
|
||||
$this->installedBaseDirs[$name] = $basedir . '/' . $name;
|
||||
} else {
|
||||
Logger::warning(
|
||||
'Module "%s" already exists in installation path "%s" and is ignored.',
|
||||
$basedir . '/' . $name,
|
||||
$this->installedBaseDirs[$name]
|
||||
);
|
||||
if (!is_readable($canonical)) {
|
||||
Logger::err('Module path "%s" is not readable', $canonical);
|
||||
continue;
|
||||
}
|
||||
if (($dh = opendir($canonical)) !== false) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file[0] === '.') {
|
||||
continue;
|
||||
}
|
||||
if (is_dir($canonical . '/' . $file)) {
|
||||
if (! array_key_exists($file, $this->installedBaseDirs)) {
|
||||
$this->installedBaseDirs[$file] = $canonical . '/' . $file;
|
||||
} else {
|
||||
Logger::warn(
|
||||
'Module "%s" already exists in installation path "%s" and is ignored.',
|
||||
$canonical . '/' . $file,
|
||||
$this->installedBaseDirs[$file]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
ksort($this->installedBaseDirs);
|
||||
|
@ -568,25 +568,7 @@ class Module
|
||||
}
|
||||
|
||||
$this->registerLocales()
|
||||
->registerRoutes()
|
||||
->registerMenuEntries();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register menu entries
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function registerMenuEntries()
|
||||
{
|
||||
$cfg = $this->app
|
||||
->getConfig()
|
||||
->module($this->name, 'menu');
|
||||
$view = $this->app->getViewRenderer();
|
||||
if ($cfg) {
|
||||
$view->view->navigation = $cfg->merge($view->view->navigation);
|
||||
}
|
||||
->registerRoutes();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,10 @@
|
||||
|
||||
namespace Icinga\Application;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once dirname(__FILE__) . '/ApplicationBootstrap.php';
|
||||
// @codingStandardsIgnoreStop
|
||||
|
||||
use \DateTimeZone;
|
||||
use \Exception;
|
||||
use \Zend_Layout;
|
||||
@ -40,20 +44,16 @@ use \Zend_Controller_Front;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Authentication\Manager as AuthenticationManager;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\User\Preferences\LoadInterface;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\User;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Web\View;
|
||||
use Icinga\User\Preferences\StoreFactory;
|
||||
use Icinga\User\Preferences\SessionStore;
|
||||
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Session\Session as BaseSession;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\Util\Translator;
|
||||
|
||||
require_once __DIR__ . '/ApplicationBootstrap.php';
|
||||
|
||||
/**
|
||||
* Use this if you want to make use of Icinga functionality in other web projects
|
||||
*
|
||||
@ -114,14 +114,16 @@ class Web extends ApplicationBootstrap
|
||||
*/
|
||||
protected function bootstrap()
|
||||
{
|
||||
return $this->setupLogging()
|
||||
->setupConfig()
|
||||
return $this
|
||||
->setupLogging()
|
||||
->setupErrorHandling()
|
||||
->loadConfig()
|
||||
->setupResourceFactory()
|
||||
->setupSession()
|
||||
->setupUser()
|
||||
->setupInternationalization()
|
||||
->setupTimezone()
|
||||
->setupLogger()
|
||||
->setupInternationalization()
|
||||
->setupRequest()
|
||||
->setupZendMvc()
|
||||
->setupModuleManager()
|
||||
@ -137,7 +139,6 @@ class Web extends ApplicationBootstrap
|
||||
*/
|
||||
private function setupRoute()
|
||||
{
|
||||
|
||||
$this->frontController->getRouter()->addRoute(
|
||||
'module_javascript',
|
||||
new Zend_Controller_Router_Route(
|
||||
@ -201,25 +202,6 @@ class Web extends ApplicationBootstrap
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a NullStore as the preference provider
|
||||
*
|
||||
* @param Preferences $preferences The preference registry to attach the NullStore to
|
||||
* @param User $user The user, required for API compliance
|
||||
*
|
||||
* @see NullStore
|
||||
*/
|
||||
private function registerFallbackPreferenceProvider($preferences, $user)
|
||||
{
|
||||
$this->getConfig()->preferences->type = 'null';
|
||||
$preferenceStore = StoreFactory::create(
|
||||
$this->getConfig()->preferences,
|
||||
$user
|
||||
);
|
||||
|
||||
$preferences->attach($preferenceStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user object and inject preference interface
|
||||
*
|
||||
@ -228,98 +210,21 @@ class Web extends ApplicationBootstrap
|
||||
*/
|
||||
private function setupUser()
|
||||
{
|
||||
$authenticationManager = AuthenticationManager::getInstance();
|
||||
|
||||
|
||||
if ($this->getConfig()->get('global')->get('authenticationMode', 'internal') === 'external') {
|
||||
try {
|
||||
$config = Config::app('authentication');
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error(
|
||||
new Exception('Cannot load authentication configuration. An exception was thrown:', 0, $e)
|
||||
);
|
||||
$config = null;
|
||||
}
|
||||
$authenticationManager = AuthenticationManager::getInstance($config);
|
||||
if ($config !== null && $config->global !== null && $config->global->get('authenticationMode', 'internal') === 'external') {
|
||||
$authenticationManager->authenticateFromRemoteUser();
|
||||
}
|
||||
|
||||
if ($authenticationManager->isAuthenticated() === true) {
|
||||
$user = $authenticationManager->getUser();
|
||||
|
||||
// Needed to update values in user session
|
||||
$sessionStore = new SessionStore($this->session);
|
||||
|
||||
// Performance: Do not ask provider if we've preferences
|
||||
// stored in session
|
||||
$initialPreferences = array();
|
||||
$preferencesLoaded = false;
|
||||
if (count($sessionStore->load())) {
|
||||
$initialPreferences = $sessionStore->load();
|
||||
$preferencesLoaded = true;
|
||||
}
|
||||
|
||||
$preferences = new Preferences($initialPreferences);
|
||||
|
||||
$preferences->attach($sessionStore);
|
||||
|
||||
if ($this->getConfig()->preferences !== null) {
|
||||
if (!$this->getConfig()->preferences->type) {
|
||||
Logger::info(
|
||||
'Preferences provider configuration error. No type was omitted. For convenience we enable '
|
||||
. 'file based ini provider for you.'
|
||||
);
|
||||
|
||||
$this->getConfig()->preferences->type = 'ini';
|
||||
}
|
||||
|
||||
$path = Config::resolvePath($this->getConfig()->preferences->configPath);
|
||||
if (is_dir($path) === false) {
|
||||
Logger::warning(
|
||||
'Path for preferences not found (IniStore, "%s"). Using default one: "%s"',
|
||||
$this->getConfig()->preferences->configPath,
|
||||
$this->getConfigDir('preferences')
|
||||
);
|
||||
|
||||
$this->getConfig()->preferences->configPath = $this->getConfigDir('preferences');
|
||||
}
|
||||
|
||||
$preferenceStore = null;
|
||||
|
||||
try {
|
||||
$preferenceStore = StoreFactory::create(
|
||||
$this->getConfig()->preferences,
|
||||
$user
|
||||
);
|
||||
$preferences->attach($preferenceStore);
|
||||
} catch (Exception $e) {
|
||||
Logger::warning(
|
||||
'Could not create create preferences provider, preferences will be discarded: '
|
||||
. '"%s"',
|
||||
$e->getMessage()
|
||||
);
|
||||
$this->registerFallbackPreferenceProvider($preferences, $user);
|
||||
}
|
||||
|
||||
if ($preferencesLoaded === false && $preferenceStore instanceof LoadInterface) {
|
||||
try {
|
||||
$initialPreferences = $preferenceStore->load();
|
||||
} catch (Exception $e) {
|
||||
Logger::warning(
|
||||
'%s::%s: Could not load preferences from provider. '
|
||||
. 'An exception during bootstrap was thrown: %s',
|
||||
__CLASS__,
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
);
|
||||
$this->registerFallbackPreferenceProvider($preferences, $user);
|
||||
}
|
||||
|
||||
$sessionStore->writeAll($initialPreferences);
|
||||
}
|
||||
} else {
|
||||
Logger::error(
|
||||
'Preferences are not configured. Refer to the documentation to setup a valid provider. '
|
||||
. 'We will use session store only. Preferences are not persisted after logout'
|
||||
);
|
||||
}
|
||||
|
||||
$user->setPreferences($preferences);
|
||||
|
||||
$this->user = $user;
|
||||
$this->user = $authenticationManager->getUser();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -387,11 +292,10 @@ class Web extends ApplicationBootstrap
|
||||
|
||||
$view->view->setEncoding('UTF-8');
|
||||
$view->view->headTitle()->prepend(
|
||||
$this->getConfig()->{'global'}->get('project', 'Icinga')
|
||||
$this->config->global !== null ? $this->config->global->get('project', 'Icinga') : 'Icinga'
|
||||
);
|
||||
|
||||
$view->view->headTitle()->setSeparator(' :: ');
|
||||
$view->view->navigation = $this->getConfig()->app('menu');
|
||||
|
||||
$this->viewRenderer = $view;
|
||||
|
||||
@ -427,15 +331,19 @@ class Web extends ApplicationBootstrap
|
||||
*/
|
||||
protected function setupTimezone()
|
||||
{
|
||||
$userTimeZone = $this->user === null ? null : $this->user->getPreferences()->get('app.timezone');
|
||||
if ($this->user !== null && $this->user->getPreferences() !== null) {
|
||||
$userTimezone = $this->user->getPreferences()->get('app.timezone');
|
||||
} else {
|
||||
$userTimezone = null;
|
||||
}
|
||||
|
||||
try {
|
||||
$tz = new DateTimeZone($userTimeZone);
|
||||
$tz = new DateTimeZone($userTimezone);
|
||||
} catch (Exception $e) {
|
||||
return parent::setupTimezone();
|
||||
}
|
||||
|
||||
date_default_timezone_set($userTimeZone);
|
||||
date_default_timezone_set($userTimezone);
|
||||
DateTimeFactory::setConfig(array('timezone' => $tz));
|
||||
return $this;
|
||||
}
|
||||
@ -450,19 +358,18 @@ class Web extends ApplicationBootstrap
|
||||
protected function setupInternationalization()
|
||||
{
|
||||
parent::setupInternationalization();
|
||||
$userLocale = $this->user === null ? null : $this->user->getPreferences()->get('app.language');
|
||||
|
||||
if ($userLocale) {
|
||||
if ($this->user !== null && $this->user->getPreferences() !== null
|
||||
&& ($locale = $this->user->getPreferences()->get('app.language') !== null)
|
||||
) {
|
||||
try {
|
||||
Translator::setupLocale($userLocale);
|
||||
Translator::setupLocale($locale);
|
||||
} catch (Exception $error) {
|
||||
Logger::info(
|
||||
'Cannot set locale "' . $userLocale . '" configured in ' .
|
||||
'Cannot set locale "' . $locale . '" configured in ' .
|
||||
'preferences of user "' . $this->user->getUsername() . '"'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
0
library/Icinga/Application/functions.php
Executable file → Normal file
0
library/Icinga/Application/functions.php
Executable file → Normal file
@ -30,6 +30,7 @@
|
||||
namespace Icinga\Authentication;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Util\String;
|
||||
|
||||
/**
|
||||
@ -70,7 +71,12 @@ class AdmissionLoader
|
||||
public function getPermissions($username, array $groups)
|
||||
{
|
||||
$permissions = array();
|
||||
foreach (Config::app('permissions') as $section) {
|
||||
try {
|
||||
$config = Config::app('permissions');
|
||||
} catch (NotReadableError $e) {
|
||||
return $permissions;
|
||||
}
|
||||
foreach ($config as $section) {
|
||||
if ($this->match($section, $username, $groups)) {
|
||||
foreach ($section as $key => $value) {
|
||||
if (strpos($key, 'permission') === 0) {
|
||||
@ -79,7 +85,6 @@ class AdmissionLoader
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
@ -94,15 +99,19 @@ class AdmissionLoader
|
||||
public function getRestrictions($username, array $groups)
|
||||
{
|
||||
$restrictions = array();
|
||||
foreach (Config::app('restrictions') as $section) {
|
||||
try {
|
||||
$config = Config::app('restrictions');
|
||||
} catch (NotReadableError $e) {
|
||||
return $restrictions;
|
||||
}
|
||||
foreach ($config as $section) {
|
||||
if ($this->match($section, $username, $groups)) {
|
||||
if (array_key_exists($section->name, $restrictions) === false) {
|
||||
if (!array_key_exists($section->name, $restrictions)) {
|
||||
$restrictions[$section->name] = array();
|
||||
}
|
||||
$restrictions[$section->name][] = $section->restriction;
|
||||
}
|
||||
}
|
||||
|
||||
return $restrictions;
|
||||
}
|
||||
}
|
||||
|
66
library/Icinga/Authentication/AuthChain.php
Normal file
66
library/Icinga/Authentication/AuthChain.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Authentication;
|
||||
|
||||
use Iterator;
|
||||
use Zend_Config;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
||||
class AuthChain implements Iterator
|
||||
{
|
||||
private $config;
|
||||
|
||||
private $currentBackend;
|
||||
|
||||
public function __construct(Zend_Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
$this->config->rewind();
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return $this->currentBackend;
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return $this->config->key();
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
$this->config->next();
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
if (!$this->config->valid()) {
|
||||
return false;
|
||||
}
|
||||
$backendConfig = $this->config->current();
|
||||
if ((bool) $backendConfig->get('disabled', false) === true) {
|
||||
$this->next();
|
||||
return $this->valid();
|
||||
}
|
||||
try {
|
||||
$name = $this->key();
|
||||
$backend = UserBackend::create($name, $backendConfig);
|
||||
} catch (ConfigurationError $e) {
|
||||
Logger::error(
|
||||
new ConfigurationError(
|
||||
'Cannot create authentication backend "' . $name . '". An exception was thrown:', 0, $e
|
||||
)
|
||||
);
|
||||
$this->next();
|
||||
return $this->valid();
|
||||
}
|
||||
$this->currentBackend = $backend;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -29,337 +29,98 @@
|
||||
|
||||
namespace Icinga\Authentication\Backend;
|
||||
|
||||
use \Exception;
|
||||
use \stdClass;
|
||||
use \Zend_Config;
|
||||
use \Zend_Db;
|
||||
use \Zend_Db_Adapter_Abstract;
|
||||
use \Icinga\Data\ResourceFactory;
|
||||
use \Icinga\User;
|
||||
use \Icinga\Authentication\UserBackend;
|
||||
use \Icinga\Authentication\Credential;
|
||||
use \Icinga\Authentication;
|
||||
use \Icinga\Logger\Logger;
|
||||
use \Icinga\Exception\ProgrammingError;
|
||||
use \Icinga\Exception\ConfigurationError;
|
||||
use Exception;
|
||||
use Zend_Db_Expr;
|
||||
use Icinga\Authentication\UserBackend;
|
||||
use Icinga\Data\Db\Connection;
|
||||
use Icinga\User;
|
||||
|
||||
/**
|
||||
* User authentication backend (@see Icinga\Authentication\UserBackend) for
|
||||
* authentication of users via an SQL database. The credentials needed to access
|
||||
* the database are configurable via the application.ini
|
||||
*
|
||||
* See the UserBackend class (@see Icinga\Authentication\UserBackend) for
|
||||
* usage information
|
||||
*/
|
||||
class DbUserBackend implements UserBackend
|
||||
class DbUserBackend extends UserBackend
|
||||
{
|
||||
/**
|
||||
* The database connection that will be used for fetching users
|
||||
* Connection to the database
|
||||
*
|
||||
* @var Zend_Db
|
||||
* @var Connection
|
||||
*/
|
||||
private $db;
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* The name of the user table
|
||||
*
|
||||
* @var String
|
||||
*/
|
||||
private $userTable = 'account';
|
||||
|
||||
/**
|
||||
* Column name to identify active users
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $activeColumnName = 'active';
|
||||
|
||||
/**
|
||||
* Column name to fetch the password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $passwordColumnName = 'password';
|
||||
|
||||
/**
|
||||
* Column name for password salt
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $saltColumnName = 'salt';
|
||||
|
||||
/**
|
||||
* Column name for user name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $userColumnName = 'username';
|
||||
|
||||
/**
|
||||
* Column name of email
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $emailColumnName = null;
|
||||
|
||||
/**
|
||||
* Name of the backend
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Create a new DbUserBackend
|
||||
*
|
||||
* @param Zend_Config $config The configuration for this authentication backend.
|
||||
* 'resource' => The name of the resource to use, or an actual
|
||||
* instance of Zend_Db_Adapter_Abstract
|
||||
* 'name' => The name of this authentication backend
|
||||
*
|
||||
* @throws ConfigurationError When the given resource does not exist.
|
||||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
if (!isset($config->resource)) {
|
||||
throw new ConfigurationError('An authentication backend must provide a resource.');
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given user exists
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasUser(User $user)
|
||||
{
|
||||
$row = $this->conn->select()->from('account', array(new Zend_Db_Expr(1)))
|
||||
->where('username = ?', $user->getUsername())
|
||||
->fetch();
|
||||
return $row !== false ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $password
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authenticate(User $user, $password)
|
||||
{
|
||||
$salt = $this->getSalt($user->getUsername());
|
||||
if ($salt === null) {
|
||||
return false;
|
||||
}
|
||||
$this->name = $config->name;
|
||||
if ($config->resource instanceof Zend_Db_Adapter_Abstract) {
|
||||
$this->db = $config->resource;
|
||||
} else {
|
||||
$resource = ResourceFactory::createResource(ResourceFactory::getResourceConfig($config->resource));
|
||||
$this->db = $resource->getConnection();
|
||||
if ($salt === '') {
|
||||
throw new Exception();
|
||||
}
|
||||
$row = $this->conn->select()->from('account', array(new Zend_Db_Expr(1)))
|
||||
->where('username = ?', $user->getUsername())
|
||||
->where('active = ?', true)
|
||||
->where('password = ?', $this->hashPassword($password, $salt))
|
||||
->fetchRow();
|
||||
return $row !== false ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for password column
|
||||
* Get salt by username
|
||||
*
|
||||
* @param string $passwordColumnName
|
||||
* @param string $username
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function setPasswordColumnName($passwordColumnName)
|
||||
private function getSalt($username)
|
||||
{
|
||||
$this->passwordColumnName = $passwordColumnName;
|
||||
$row = $this->conn->select()->from('account', array('salt'))->where('username = ?', $username)->fetchRow();
|
||||
return $row !== false ? $row->salt : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for password salt column
|
||||
*
|
||||
* @param string $saltColumnName
|
||||
*/
|
||||
public function setSaltColumnName($saltColumnName)
|
||||
{
|
||||
$this->saltColumnName = $saltColumnName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for usernamea column
|
||||
*
|
||||
* @param string $userColumnName
|
||||
*/
|
||||
public function setUserColumnName($userColumnName)
|
||||
{
|
||||
$this->userColumnName = $userColumnName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for database table
|
||||
*
|
||||
* @param String $userTable
|
||||
*/
|
||||
public function setUserTable($userTable)
|
||||
{
|
||||
$this->userTable = $userTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for column identifying an active user
|
||||
*
|
||||
* Set this to null if no active column exists.
|
||||
*
|
||||
* @param string $activeColumnName
|
||||
*/
|
||||
public function setActiveColumnName($activeColumnName)
|
||||
{
|
||||
$this->activeColumnName = $activeColumnName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for email column
|
||||
*
|
||||
* Set to null if not needed
|
||||
*
|
||||
* @param string $emailColumnName
|
||||
*/
|
||||
public function setEmailColumnName($emailColumnName)
|
||||
{
|
||||
$this->emailColumnName = $emailColumnName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the backend
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user identified by the given credentials is available
|
||||
*
|
||||
* @param Credential $credential Credential to find a user in the database
|
||||
*
|
||||
* @return boolean True when the username is known and currently active.
|
||||
*/
|
||||
public function hasUsername(Credential $credential)
|
||||
{
|
||||
$user = $this->getUserByName($credential->getUsername());
|
||||
return isset($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate a user with the given credentials
|
||||
*
|
||||
* @param Credential $credential Credential to authenticate
|
||||
*
|
||||
* @return User|null The authenticated user or Null.
|
||||
*/
|
||||
public function authenticate(Credential $credential)
|
||||
{
|
||||
try {
|
||||
$salt = $this->getUserSalt($credential->getUsername());
|
||||
} catch (Exception $e) {
|
||||
Logger::error(
|
||||
'Could not fetch salt from database for user %s. Exception was thrown: %s',
|
||||
$credential->getUsername(),
|
||||
$e->getMessage()
|
||||
);
|
||||
return null;
|
||||
}
|
||||
$sth = $this->db
|
||||
->select()->from($this->userTable)
|
||||
->where($this->userColumnName . ' = ?', $credential->getUsername())
|
||||
->where(
|
||||
$this->passwordColumnName . ' = ?',
|
||||
$this->createPasswordHash($credential->getPassword(), $salt)
|
||||
);
|
||||
|
||||
if ($this->activeColumnName !== null) {
|
||||
$sth->where($this->activeColumnName . ' = ?', true);
|
||||
}
|
||||
|
||||
$res = $sth->query()->fetch();
|
||||
|
||||
if ($res !== false) {
|
||||
return $this->createUserFromResult($res);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the users salt from the database
|
||||
*
|
||||
* @param string$username The user whose salt should be fetched
|
||||
*
|
||||
* @return string|null Return the salt-string or null, when the user does not exist
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
private function getUserSalt($username)
|
||||
{
|
||||
$res = $this->db->select()
|
||||
->from($this->userTable, $this->saltColumnName)
|
||||
->where($this->userColumnName . ' = ?', $username)
|
||||
->query()->fetch();
|
||||
if ($res !== false) {
|
||||
return $res->{$this->saltColumnName};
|
||||
} else {
|
||||
throw new ProgrammingError('No Salt found for user "' . $username . '"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create password hash at this place
|
||||
* Hash a password
|
||||
*
|
||||
* @param string $password
|
||||
* @param string $salt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function createPasswordHash($password, $salt)
|
||||
{
|
||||
private function hashPassword($password, $salt) {
|
||||
return hash_hmac('sha256', $password, $salt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the user information from the database
|
||||
* Get the number of users available
|
||||
*
|
||||
* @param string $username The name of the user
|
||||
*
|
||||
* @return User|null Returns the user object, or null when the user does not exist
|
||||
* @return int
|
||||
*/
|
||||
private function getUserByName($username)
|
||||
public function count()
|
||||
{
|
||||
$this->db->getConnection();
|
||||
$sth = $this->db->select()
|
||||
->from($this->userTable)
|
||||
->where($this->userColumnName .' = ?', $username);
|
||||
|
||||
if ($this->activeColumnName !== null) {
|
||||
$sth->where($this->activeColumnName .' = ?', true);
|
||||
}
|
||||
|
||||
$res = $sth->query()->fetch();
|
||||
|
||||
if ($res !== false) {
|
||||
return $this->createUserFromResult($res);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of User from a query result
|
||||
*
|
||||
* @param stdClass $resultRow Result object from database
|
||||
*
|
||||
* @return User The created instance of User.
|
||||
*/
|
||||
protected function createUserFromResult(stdClass $resultRow)
|
||||
{
|
||||
$usr = new User(
|
||||
$resultRow->{$this->userColumnName},
|
||||
null,
|
||||
null,
|
||||
(isset($resultRow->{$this->emailColumnName})) ? $resultRow->{$this->emailColumnName} : null
|
||||
);
|
||||
return $usr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of users in this database connection
|
||||
*
|
||||
* This class is mainly used for determining whether the authentication backend is valid or not
|
||||
*
|
||||
* @return int The number of users set in this backend
|
||||
* @see UserBackend::getUserCount
|
||||
*/
|
||||
public function getUserCount()
|
||||
{
|
||||
$query = $this->db->select()->from($this->userTable, 'COUNT(*) as count')->query();
|
||||
return $query->fetch()->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to connect to the underlying database.
|
||||
*
|
||||
* @throws ConfigurationError When the backend is not reachable with the given configuration.
|
||||
*/
|
||||
public function connect()
|
||||
{
|
||||
$this->db->getConnection();
|
||||
return $this->conn->select()->from('account', array('count' => 'COUNT(*)'))->fetch()->count();
|
||||
}
|
||||
}
|
||||
|
@ -29,170 +29,98 @@
|
||||
|
||||
namespace Icinga\Authentication\Backend;
|
||||
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use \stdClass;
|
||||
use \Zend_Config;
|
||||
use \Icinga\User;
|
||||
use \Icinga\Authentication\UserBackend;
|
||||
use \Icinga\Authentication\Credential;
|
||||
use \Icinga\Protocol\Ldap;
|
||||
use \Icinga\Protocol\Ldap\Connection as LdapConnection;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Exception\ConfigurationError;
|
||||
use Icinga\User;
|
||||
use Icinga\Authentication\UserBackend;
|
||||
use Icinga\Protocol\Ldap\Connection;
|
||||
|
||||
/**
|
||||
* User authentication backend
|
||||
*/
|
||||
class LdapUserBackend implements UserBackend
|
||||
class LdapUserBackend extends UserBackend
|
||||
{
|
||||
/**
|
||||
* Ldap resource
|
||||
* Connection to the LDAP server
|
||||
*
|
||||
* @var Connection
|
||||
**/
|
||||
protected $connection;
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* The ldap connection information
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $config;
|
||||
protected $userClass;
|
||||
|
||||
/**
|
||||
* Name of the backend
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
protected $userNameAttribute;
|
||||
|
||||
/**
|
||||
* Create a new LdapUserBackend
|
||||
*
|
||||
* @param Zend_Config $config The configuration for this authentication backend.
|
||||
* 'resource' => The name of the resource to use, or an actual
|
||||
* instance of \Icinga\Protocol\Ldap\Connection.
|
||||
* 'name' => The name of this authentication backend.
|
||||
*
|
||||
* @throws ConfigurationError When the given resource does not exist.
|
||||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
public function __construct(Connection $conn, $userClass, $userNameAttribute)
|
||||
{
|
||||
if (!isset($config->resource)) {
|
||||
throw new ConfigurationError('An authentication backend must provide a resource.');
|
||||
}
|
||||
$this->config = $config;
|
||||
$this->name = $config->name;
|
||||
if ($config->resource instanceof LdapConnection) {
|
||||
$this->connection = $config->resource;
|
||||
} else {
|
||||
$this->connection = ResourceFactory::createResource(
|
||||
ResourceFactory::getResourceConfig($config->resource)
|
||||
$this->conn = $conn;
|
||||
$this->userClass = $userClass;
|
||||
$this->userNameAttribute = $userNameAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create query
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
* @return \Icinga\Protocol\Ldap\Query
|
||||
**/
|
||||
protected function createQuery($username)
|
||||
{
|
||||
return $this->conn->select()
|
||||
->from(
|
||||
$this->userClass,
|
||||
array($this->userNameAttribute)
|
||||
)
|
||||
->where(
|
||||
$this->userNameAttribute,
|
||||
str_replace('*', '', $username)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the backend
|
||||
* Test whether the given user exists
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the username exists
|
||||
*
|
||||
* @param Credential $credential Credential to find user in database
|
||||
* @param User $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasUsername(Credential $credential)
|
||||
public function hasUser(User $user)
|
||||
{
|
||||
return $this->connection->fetchOne(
|
||||
$this->selectUsername($credential->getUsername())
|
||||
) === $credential->getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the '*' character from $string
|
||||
*
|
||||
* @param string $string Input string
|
||||
*
|
||||
* @return string
|
||||
**/
|
||||
protected function stripAsterisks($string)
|
||||
{
|
||||
return str_replace('*', '', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to fetch the username
|
||||
*
|
||||
* @param string $username The username to select
|
||||
*
|
||||
* @return stdClass $result
|
||||
**/
|
||||
protected function selectUsername($username)
|
||||
{
|
||||
return $this->connection->select()
|
||||
->from(
|
||||
$this->config->user_class,
|
||||
array(
|
||||
$this->config->user_name_attribute
|
||||
)
|
||||
)
|
||||
->where(
|
||||
$this->config->user_name_attribute,
|
||||
$this->stripAsterisks($username)
|
||||
);
|
||||
$username = $user->getUsername();
|
||||
return $this->conn->fetchOne($this->createQuery($username)) === $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate
|
||||
*
|
||||
* @param Credential $credentials Credential to authenticate
|
||||
* @param User $user
|
||||
* @param string $password
|
||||
*
|
||||
* @return User
|
||||
* @return bool
|
||||
*/
|
||||
public function authenticate(Credential $credentials)
|
||||
public function authenticate(User $user, $password)
|
||||
{
|
||||
if ($this->connection->testCredentials(
|
||||
$this->connection->fetchDN($this->selectUsername($credentials->getUsername())),
|
||||
$credentials->getPassword()
|
||||
)) {
|
||||
return new User($credentials->getUsername());
|
||||
if ($this->conn->testCredentials(
|
||||
$this->conn->fetchDN($this->createQuery($user->getUsername())),
|
||||
$password
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return number of users in this backend
|
||||
* Get the number of users available
|
||||
*
|
||||
* @return int The number of users set in this backend
|
||||
* @see UserBackend::getUserCount
|
||||
* @return int
|
||||
*/
|
||||
public function getUserCount()
|
||||
public function count()
|
||||
{
|
||||
return $this->connection->count(
|
||||
$this->connection->select()->from(
|
||||
$this->config->user_class,
|
||||
return $this->conn->count(
|
||||
$this->conn->select()->from(
|
||||
$this->userClass,
|
||||
array(
|
||||
$this->config->user_name_attribute
|
||||
$this->userNameAttribute
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Establish the connection to this authentication backend
|
||||
*
|
||||
* @throws \Exception When the connection to the resource is not possible.
|
||||
*/
|
||||
public function connect()
|
||||
{
|
||||
$this->connection->connect();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,135 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Authentication;
|
||||
|
||||
/**
|
||||
* Data holder object for authentication information
|
||||
*
|
||||
* This object should be used instead of passing names and
|
||||
* passwords as primitives in order to allow additional information
|
||||
* to be provided (like the domain) when needed.
|
||||
*/
|
||||
class Credential
|
||||
{
|
||||
/**
|
||||
* Username
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $username;
|
||||
|
||||
/**
|
||||
* Password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* Domain
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $domain;
|
||||
|
||||
/**
|
||||
* Create a new credential object
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param string $domain
|
||||
*/
|
||||
public function __construct($username = '', $password = null, $domain = null)
|
||||
{
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->domain = $domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for username
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for username
|
||||
*
|
||||
* @param string $username
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for password
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for password
|
||||
*
|
||||
* @param string $password
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for domain
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDomain()
|
||||
{
|
||||
return $this->domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for domain
|
||||
*
|
||||
* @param string $domain
|
||||
*/
|
||||
public function setDomain($domain)
|
||||
{
|
||||
$this->domain = $domain;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}}
|
||||
|
||||
namespace Icinga\Authentication;
|
||||
|
||||
/**
|
||||
* Api behaviour for a group backend
|
||||
*
|
||||
* @TODO(mh): Groups not implemented at present, re-implement if needed (#4624)
|
||||
*/
|
||||
interface GroupBackend
|
||||
{
|
||||
/**
|
||||
* Name of the backend
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
}
|
@ -29,30 +29,18 @@
|
||||
|
||||
namespace Icinga\Authentication;
|
||||
|
||||
use \Exception;
|
||||
use \Zend_Config;
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\User;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Authentication\Backend\DbUserBackend;
|
||||
use Icinga\Authentication\Backend\LdapUserBackend;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\User\Preferences\PreferencesStore;
|
||||
|
||||
/**
|
||||
* The authentication manager allows to identify users and
|
||||
* to persist authentication information in a session.
|
||||
*
|
||||
* Direct instantiation is not permitted, the AuthenticationManager
|
||||
* must be created using the getInstance method. Subsequent getInstance
|
||||
* calls return the same object and ignore any additional configuration.
|
||||
*
|
||||
* @TODO(mh): Group support is not implemented yet (#4624)
|
||||
**/
|
||||
class Manager
|
||||
{
|
||||
|
||||
/**
|
||||
* Singleton instance
|
||||
*
|
||||
@ -61,323 +49,82 @@ class Manager
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* If the user was authenticated from the REMOTE_USER server variable
|
||||
*
|
||||
* @var Boolean
|
||||
*/
|
||||
private $fromRemoteUser = false;
|
||||
|
||||
/**
|
||||
* Instance of authenticated user
|
||||
* Authenticated user
|
||||
*
|
||||
* @var User
|
||||
**/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Array of user backends
|
||||
*
|
||||
* @var array
|
||||
**/
|
||||
private $userBackends = array();
|
||||
|
||||
/**
|
||||
* Array of group backends
|
||||
*
|
||||
* @var array
|
||||
**/
|
||||
private $groupBackends = array();
|
||||
|
||||
/**
|
||||
* The configuration
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $config = null;
|
||||
|
||||
/**
|
||||
* If the backends are already created.
|
||||
* If the user was authenticated from the REMOTE_USER server variable
|
||||
*
|
||||
* @var Boolean
|
||||
*/
|
||||
private $initialized = false;
|
||||
private $fromRemoteUser = false;
|
||||
|
||||
/**
|
||||
* Creates a new authentication manager using the provided config (or the
|
||||
* configuration provided in the authentication.ini if no config is given)
|
||||
* and with the given options.
|
||||
*
|
||||
* @param Zend_Config $config The configuration to use for authentication
|
||||
* instead of the authentication.ini
|
||||
* @param array $options Additional options that affect the managers behaviour.
|
||||
* Supported values:
|
||||
* * noDefaultConfig: Disable default configuration from authentication.ini
|
||||
**/
|
||||
private function __construct(Zend_Config $config = null, array $options = array())
|
||||
private function __construct()
|
||||
{
|
||||
if ($config === null && !(isset($options['noDefaultConfig']) && $options['noDefaultConfig'] == true)) {
|
||||
$config = IcingaConfig::app('authentication');
|
||||
}
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a singleton instance of our self
|
||||
* Get the authentication manager
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param array $options
|
||||
*
|
||||
* @return self
|
||||
* @see Manager:__construct
|
||||
* @return self
|
||||
*/
|
||||
public static function getInstance(Zend_Config $config = null, array $options = array())
|
||||
public static function getInstance()
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new Manager($config, $options);
|
||||
self::$instance = new static();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize multiple backends from Zend Config
|
||||
*/
|
||||
private function setupBackends(Zend_Config $config)
|
||||
public function setAuthenticated(User $user, $persist = true)
|
||||
{
|
||||
foreach ($config as $name => $backendConfig) {
|
||||
// We won't initialize disabled backends
|
||||
if ($backendConfig->get('disabled') == '1') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($backendConfig->name === null) {
|
||||
$backendConfig->name = $name;
|
||||
}
|
||||
$backend = $this->createBackend($backendConfig);
|
||||
if ($backend instanceof UserBackend) {
|
||||
$backend->connect();
|
||||
$this->userBackends[$backend->getName()] = $backend;
|
||||
} elseif ($backend instanceof GroupBackend) {
|
||||
$backend->connect();
|
||||
$this->groupBackends[$backend->getName()] = $backend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a single backend from the given Zend_Config
|
||||
*
|
||||
* @param Zend_Config $backendConfig
|
||||
*
|
||||
* @return null|UserBackend
|
||||
*/
|
||||
private function createBackend(Zend_Config $backendConfig)
|
||||
{
|
||||
$target = ucwords(strtolower($backendConfig->target));
|
||||
$name = $backendConfig->name;
|
||||
// TODO: implement support for groups (#4624) and remove OR-Clause
|
||||
if ((!$target || strtolower($target) != "user") && !$backendConfig->class) {
|
||||
Logger::warning('AuthManager: Backend "%s" has no target configuration. (e.g. target=user|group)', $name);
|
||||
return null;
|
||||
}
|
||||
$username = $user->getUsername();
|
||||
try {
|
||||
if (isset($backendConfig->class)) {
|
||||
// use a custom backend class, this is probably only useful for testing
|
||||
if (!class_exists($backendConfig->class)) {
|
||||
Logger::error('AuthManager: Class not found (%s) for backend %s', $backendConfig->class, $name);
|
||||
return null;
|
||||
}
|
||||
$class = $backendConfig->class;
|
||||
return new $class($backendConfig);
|
||||
}
|
||||
|
||||
switch (ResourceFactory::getResourceConfig($backendConfig->resource)->type) {
|
||||
case 'db':
|
||||
return new DbUserBackend($backendConfig);
|
||||
case 'ldap':
|
||||
return new LdapUserBackend($backendConfig);
|
||||
default:
|
||||
Logger::warning('AuthManager: Resource type ' . $backendConfig->type . ' not available.');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Logger::warning('AuthManager: Not able to create backend. Exception was thrown: %s', $e->getMessage());
|
||||
$config = IcingaConfig::app();
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error(
|
||||
new Exception('Cannot load preferences for user "' . $username . '". An exception was thrown', 0, $e)
|
||||
);
|
||||
$config = new Zend_Config(array());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a user backend to the stack
|
||||
*
|
||||
* @param UserBackend $userBackend
|
||||
*/
|
||||
public function addUserBackend(UserBackend $userBackend)
|
||||
{
|
||||
$this->userBackends[$userBackend->getName()] = $userBackend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user backend by name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return UserBackend|null
|
||||
*/
|
||||
public function getUserBackend($name)
|
||||
{
|
||||
$this->initBackends();
|
||||
return (isset($this->userBackends[$name])) ? $this->userBackends[$name] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a group backend to the stack
|
||||
*
|
||||
* @param GroupBackend $groupBackend
|
||||
*/
|
||||
public function addGroupBackend(GroupBackend $groupBackend)
|
||||
{
|
||||
$this->groupBackends[$groupBackend->getName()] = $groupBackend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a group backend by name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return GroupBackend|null
|
||||
*/
|
||||
public function getGroupBackend($name)
|
||||
{
|
||||
$this->initBackends();
|
||||
return (isset($this->groupBackends[$name])) ? $this->groupBackends[$name] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a backend for the given credentials
|
||||
*
|
||||
* @param Credential $credentials
|
||||
*
|
||||
* @return UserBackend|null
|
||||
* @throws ConfigurationError
|
||||
*/
|
||||
private function getBackendForCredential(Credential $credentials)
|
||||
{
|
||||
$this->initBackends();
|
||||
|
||||
$authErrors = 0;
|
||||
foreach ($this->userBackends as $userBackend) {
|
||||
|
||||
$flag = false;
|
||||
|
||||
if (($preferencesConfig = $config->preferences) !== null) {
|
||||
try {
|
||||
Logger::debug(
|
||||
'AuthManager: Try backend %s for user %s',
|
||||
$userBackend->getName(),
|
||||
$credentials->getUsername()
|
||||
$preferencesStore = PreferencesStore::create(
|
||||
$preferencesConfig,
|
||||
$user
|
||||
);
|
||||
$flag = $userBackend->hasUsername($credentials);
|
||||
} catch (Exception $e) {
|
||||
$preferences = new Preferences($preferencesStore->load());
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error(
|
||||
'AuthManager: Backend "%s" has errors. Exception was thrown: %s',
|
||||
$userBackend->getName(),
|
||||
$e->getMessage()
|
||||
new Exception(
|
||||
'Cannot load preferences for user "' . $username . '". An exception was thrown', 0, $e
|
||||
)
|
||||
);
|
||||
|
||||
$authErrors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($flag === true) {
|
||||
Logger::debug(
|
||||
'AuthManager: Backend %s has user %s',
|
||||
$userBackend->getName(),
|
||||
$credentials->getUsername()
|
||||
);
|
||||
return $userBackend;
|
||||
$preferences = new Preferences();
|
||||
}
|
||||
} else {
|
||||
$preferences = new Preferences();
|
||||
}
|
||||
|
||||
if ($authErrors >= count($this->userBackends)) {
|
||||
throw new ConfigurationError(
|
||||
'No working backend found. Unable to authenticate any user.' .
|
||||
"\nPlease examine the logs for more information."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that all backends are initialized
|
||||
*/
|
||||
private function initBackends()
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->setupBackends($this->config);
|
||||
$this->initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to authenticate a user with the given credentials
|
||||
*
|
||||
* @param Credential $credentials The credentials to use for authentication
|
||||
* @param Boolean $persist Whether to persist the authentication result in the current session
|
||||
*
|
||||
* @return Boolean Whether the authentication was successful or not
|
||||
* @throws ConfigurationError
|
||||
*/
|
||||
public function authenticate(Credential $credentials, $persist = true)
|
||||
{
|
||||
$this->initBackends();
|
||||
if (count($this->userBackends) === 0) {
|
||||
Logger::error('AuthManager: No authentication backend provided, your users will never be able to login.');
|
||||
throw new ConfigurationError(
|
||||
'No authentication backend set - login will never succeed as icinga-web ' .
|
||||
'doesn\'t know how to determine your user. ' . "\n" .
|
||||
'To fix this error, setup your authentication.ini with at least one valid authentication backend.'
|
||||
);
|
||||
}
|
||||
|
||||
$userBackend = $this->getBackendForCredential($credentials);
|
||||
|
||||
if ($userBackend === null) {
|
||||
Logger::info('AuthManager: Unknown user %s tried to log in', $credentials->getUsername());
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->user = $userBackend->authenticate($credentials);
|
||||
|
||||
if ($this->user === null) {
|
||||
Logger::info('AuthManager: Invalid credentials for user %s provided', $credentials->getUsername());
|
||||
return false;
|
||||
}
|
||||
|
||||
$username = $credentials->getUsername();
|
||||
|
||||
$user->setPreferences($preferences);
|
||||
$membership = new Membership();
|
||||
|
||||
$groups = $membership->getGroupsByUsername($username);
|
||||
$this->user->setGroups($groups);
|
||||
|
||||
$user->setGroups($groups);
|
||||
$admissionLoader = new AdmissionLoader();
|
||||
|
||||
$this->user->setPermissions(
|
||||
$user->setPermissions(
|
||||
$admissionLoader->getPermissions($username, $groups)
|
||||
);
|
||||
|
||||
$this->user->setRestrictions(
|
||||
$user->setRestrictions(
|
||||
$admissionLoader->getRestrictions($username, $groups)
|
||||
);
|
||||
|
||||
$this->user = $user;
|
||||
if ($persist == true) {
|
||||
// Refresh the used session ID on each login, to offer protection against session fixation
|
||||
$session = Session::getSession();
|
||||
$session->refreshId();
|
||||
$this->persistCurrentUser();
|
||||
}
|
||||
|
||||
Logger::info('AuthManager: User successfully logged in: %s', $credentials->getUsername());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -398,27 +145,6 @@ class Manager
|
||||
$this->user = Session::getSession()->get('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to authenticate the user from the session, and then from the REMOTE_USER superglobal, that can be set by
|
||||
* an external authentication provider.
|
||||
*/
|
||||
public function authenticateFromRemoteUser()
|
||||
{
|
||||
$this->fromRemoteUser = true;
|
||||
$this->authenticateFromSession();
|
||||
if ($this->user !== null) {
|
||||
if (array_key_exists('REMOTE_USER', $_SERVER) && $this->user->getUsername() !== $_SERVER["REMOTE_USER"]) {
|
||||
// Remote user has changed, clear all sessions
|
||||
$this->removeAuthorization();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (array_key_exists('REMOTE_USER', $_SERVER) && $_SERVER["REMOTE_USER"]) {
|
||||
$this->user = new User($_SERVER["REMOTE_USER"]);
|
||||
$this->persistCurrentUser();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the user is currently authenticated
|
||||
*
|
||||
@ -505,6 +231,27 @@ class Manager
|
||||
return $this->user->getGroups();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to authenticate the user from the session, and then from the REMOTE_USER superglobal, that can be set by
|
||||
* an external authentication provider.
|
||||
*/
|
||||
public function authenticateFromRemoteUser()
|
||||
{
|
||||
$this->fromRemoteUser = true;
|
||||
$this->authenticateFromSession();
|
||||
if ($this->user !== null) {
|
||||
if (array_key_exists('REMOTE_USER', $_SERVER) && $this->user->getUsername() !== $_SERVER["REMOTE_USER"]) {
|
||||
// Remote user has changed, clear all sessions
|
||||
$this->removeAuthorization();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (array_key_exists('REMOTE_USER', $_SERVER) && $_SERVER["REMOTE_USER"]) {
|
||||
$this->user = new User($_SERVER["REMOTE_USER"]);
|
||||
$this->persistCurrentUser();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the session was established from the REMOTE_USER server variable.
|
||||
*/
|
||||
|
@ -30,6 +30,7 @@
|
||||
namespace Icinga\Authentication;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Util\String;
|
||||
|
||||
/**
|
||||
@ -47,10 +48,14 @@ class Membership
|
||||
public function getGroupsByUsername($username)
|
||||
{
|
||||
$groups = array();
|
||||
foreach (Config::app('membership') as $section) {
|
||||
try {
|
||||
$config = Config::app('memberships');
|
||||
} catch (NotReadableError $e) {
|
||||
return $groups;
|
||||
}
|
||||
foreach ($config as $section) {
|
||||
$users = String::trimSplit($section->users);
|
||||
|
||||
if (in_array($username, $users) === true) {
|
||||
if (in_array($username, $users)) {
|
||||
$groups = array_merge($groups, String::trimSplit($section->groups));
|
||||
}
|
||||
}
|
||||
|
@ -29,51 +29,133 @@
|
||||
|
||||
namespace Icinga\Authentication;
|
||||
|
||||
use \Zend_Config;
|
||||
use \Icinga\User;
|
||||
use Icinga\Authentication\Credential;
|
||||
use Countable;
|
||||
use Zend_Config;
|
||||
use Icinga\Authentication\Backend\DbUserBackend;
|
||||
use Icinga\Authentication\Backend\LdapUserBackend;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\User;
|
||||
|
||||
/**
|
||||
* Public api for an user backend object
|
||||
*/
|
||||
interface UserBackend
|
||||
abstract class UserBackend implements Countable
|
||||
{
|
||||
/**
|
||||
* Test if the username exists
|
||||
* Name of the backend
|
||||
*
|
||||
* @param Credential $credentials
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Setter for the backend's name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the backend's name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public static function create($name, Zend_Config $backendConfig)
|
||||
{
|
||||
if ($backendConfig->name !== null) {
|
||||
$name = $backendConfig->name;
|
||||
}
|
||||
if (isset($backendConfig->class)) {
|
||||
// Use a custom backend class, this is only useful for testing
|
||||
if (!class_exists($backendConfig->class)) {
|
||||
throw new ConfigurationError(
|
||||
'Authentication configuration for backend "' . $name . '" defines an invalid backend'
|
||||
. ' class. Backend class "' . $backendConfig->class. '" not found'
|
||||
);
|
||||
}
|
||||
return new $backendConfig->class($backendConfig);
|
||||
}
|
||||
if ($backendConfig->resource === null) {
|
||||
throw new ConfigurationError(
|
||||
'Authentication configuration for backend "' . $name
|
||||
. '" is missing the resource directive'
|
||||
);
|
||||
}
|
||||
if (($backendType = $backendConfig->backend) === null) {
|
||||
throw new ConfigurationError(
|
||||
'Authentication configuration for backend "' . $name
|
||||
. '" is missing the backend directive'
|
||||
);
|
||||
}
|
||||
try {
|
||||
$resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource);
|
||||
} catch (ProgrammingError $e) {
|
||||
throw new ConfigurationError(
|
||||
'Resources not set up. Please contact your Icinga Web administrator'
|
||||
);
|
||||
}
|
||||
$resource = ResourceFactory::createResource($resourceConfig);
|
||||
switch (strtolower($backendType)) {
|
||||
case 'db':
|
||||
$backend = new DbUserBackend($resource);
|
||||
break;
|
||||
case 'msldap':
|
||||
$backend = new LdapUserBackend(
|
||||
$resource,
|
||||
$backendConfig->get('user_class', 'user'),
|
||||
$backendConfig->get('user_name_attribute', 'sAMAccountName')
|
||||
);
|
||||
break;
|
||||
case 'ldap':
|
||||
if (($userClass = $backendConfig->user_class) === null) {
|
||||
throw new ConfigurationError(
|
||||
'Authentication configuration for backend "' . $name
|
||||
. '" is missing the user_class directive'
|
||||
);
|
||||
}
|
||||
if (($userNameAttribute = $backendConfig->user_name_attribute) === null) {
|
||||
throw new ConfigurationError(
|
||||
'Authentication configuration for backend "' . $name
|
||||
. '" is missing the user_name_attribute directive'
|
||||
);
|
||||
}
|
||||
$backend = new LdapUserBackend($resource, $userClass, $userNameAttribute);
|
||||
break;
|
||||
default:
|
||||
throw new ConfigurationError(
|
||||
'Authentication configuration for backend "' . $name. '" defines an invalid backend'
|
||||
. ' type. Backend type "' . $backendType . '" is not supported'
|
||||
);
|
||||
}
|
||||
$backend->setName($name);
|
||||
return $backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given user exists
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasUsername(Credential $credentials);
|
||||
abstract public function hasUser(User $user);
|
||||
|
||||
/**
|
||||
* Authenticate
|
||||
*
|
||||
* @param Credential $credentials
|
||||
* @param User $user
|
||||
* @param string $password
|
||||
*
|
||||
* @return User
|
||||
* @return bool
|
||||
*/
|
||||
public function authenticate(Credential $credentials);
|
||||
|
||||
/**
|
||||
* Name of the backend
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Get the number of users available through this backend
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getUserCount();
|
||||
|
||||
/**
|
||||
* Establish the connection to this authentication backend
|
||||
*
|
||||
* @throws ConfigurationError When the backend is not reachable with the given configuration.
|
||||
*/
|
||||
public function connect();
|
||||
abstract public function authenticate(User $user, $password);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class ResourceFactory implements ConfigAwareFactory
|
||||
/**
|
||||
* Get the configuration for a specific resource
|
||||
*
|
||||
* @param $resourceName String The resources name
|
||||
* @param $resourceName String The resource's name
|
||||
*
|
||||
* @return Zend_Config The configuration of the resource
|
||||
* @throws \Icinga\Exception\ConfigurationError
|
||||
@ -62,7 +62,9 @@ class ResourceFactory implements ConfigAwareFactory
|
||||
{
|
||||
self::assertResourcesExist();
|
||||
if (($resourceConfig = self::$resources->get($resourceName)) === null) {
|
||||
throw new ConfigurationError('Resource "' . $resourceName . '" couldn\'t be retrieved');
|
||||
throw new ConfigurationError(
|
||||
'Cannot load resource config "' . $resourceName . '". Resource does not exist'
|
||||
);
|
||||
}
|
||||
return $resourceConfig;
|
||||
}
|
||||
|
11
library/Icinga/Exception/NotReadableError.php
Normal file
11
library/Icinga/Exception/NotReadableError.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class NotReadableError extends RuntimeException
|
||||
{
|
||||
}
|
11
library/Icinga/Exception/NotWritableError.php
Normal file
11
library/Icinga/Exception/NotWritableError.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class NotWritableError extends RuntimeException
|
||||
{
|
||||
}
|
0
library/Icinga/Protocol/Livestatus/Connection.php
Executable file → Normal file
0
library/Icinga/Protocol/Livestatus/Connection.php
Executable file → Normal file
0
library/Icinga/Protocol/Livestatus/Query.php
Executable file → Normal file
0
library/Icinga/Protocol/Livestatus/Query.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Exception/ParsingException.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Exception/ParsingException.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/IReader.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/IReader.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Parser.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Parser.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Query.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Query.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Query/Expression.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Query/Expression.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Query/Group.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Query/Group.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Query/IQueryPart.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Query/IQueryPart.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Reader.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/Reader.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/RuntimeStateContainer.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/RuntimeStateContainer.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/View/MonitoringObjectList.php
Executable file → Normal file
0
library/Icinga/Protocol/Statusdat/View/MonitoringObjectList.php
Executable file → Normal file
@ -371,7 +371,6 @@ namespace Icinga\Test {
|
||||
require_once self::$libDir . '/Web/Form.php';
|
||||
|
||||
require_once self::$libDir . '/User/Preferences.php';
|
||||
require_once self::$libDir . '/User/Preferences/ChangeSet.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,99 +29,53 @@
|
||||
|
||||
namespace Icinga\User;
|
||||
|
||||
use \SplObjectStorage;
|
||||
use \SplObserver;
|
||||
use \SplSubject;
|
||||
use Icinga\User\Preferences\ChangeSet;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Countable;
|
||||
|
||||
/**
|
||||
* Handling retrieve and persist of user preferences
|
||||
* User preferences container
|
||||
*
|
||||
* Usage example:
|
||||
* <code>
|
||||
* <?php
|
||||
*
|
||||
* use Icinga\User\Preferences;
|
||||
*
|
||||
* $preferences = new Preferences(); // Start with empty preferences
|
||||
*
|
||||
* $preferences = new Preferences(array('aPreference' => 'value')); // Start with initial preferences
|
||||
*
|
||||
* $prefrences = $user->getPreferences(); // Retrieve preferences from a \Icinga\User instance
|
||||
*
|
||||
* $preferences->aNewPreference = 'value'; // Set a preference
|
||||
*
|
||||
* unset($preferences->aPreference); // Unset a preference
|
||||
*
|
||||
* // Retrieve a preference and return a default value if the preference does not exist
|
||||
* $anotherPreference = $preferences->get('anotherPreference', 'defaultValue');
|
||||
*/
|
||||
class Preferences implements SplSubject, \Countable
|
||||
class Preferences implements Countable
|
||||
{
|
||||
/**
|
||||
* Container for all preferences
|
||||
* Preferences key-value array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $preferences = array();
|
||||
|
||||
/**
|
||||
* All observers for changes
|
||||
* Constructor
|
||||
*
|
||||
* @var SplObserver[]
|
||||
* @param array $preferences Preferences key-value array
|
||||
*/
|
||||
private $observer = array();
|
||||
|
||||
/**
|
||||
* Current change set
|
||||
*
|
||||
* @var ChangeSet
|
||||
*/
|
||||
private $changeSet;
|
||||
|
||||
/**
|
||||
* Flag how commits are handled
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $autoCommit = true;
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
* @param array $initialPreferences
|
||||
*/
|
||||
public function __construct(array $initialPreferences)
|
||||
public function __construct(array $preferences = array())
|
||||
{
|
||||
$this->preferences = $initialPreferences;
|
||||
$this->changeSet = new ChangeSet();
|
||||
$this->preferences = $preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach an SplObserver
|
||||
* Count all preferences
|
||||
*
|
||||
* @link http://php.net/manual/en/splsubject.attach.php
|
||||
* @param SplObserver $observer
|
||||
*/
|
||||
public function attach(SplObserver $observer)
|
||||
{
|
||||
$this->observer[] = $observer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach an observer
|
||||
*
|
||||
* @link http://php.net/manual/en/splsubject.detach.php
|
||||
* @param SplObserver $observer
|
||||
*/
|
||||
public function detach(SplObserver $observer)
|
||||
{
|
||||
$key = array_search($observer, $this->observer, true);
|
||||
if ($key !== false) {
|
||||
unset($this->observer[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify an observer
|
||||
*
|
||||
* @link http://php.net/manual/en/splsubject.notify.php
|
||||
*/
|
||||
public function notify()
|
||||
{
|
||||
/** @var SplObserver $observer */
|
||||
$observer = null;
|
||||
foreach ($this->observer as $observer) {
|
||||
$observer->update($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count elements of an object
|
||||
*
|
||||
* @link http://php.net/manual/en/countable.count.php
|
||||
* @return int The custom count as an integer
|
||||
* @return int The number of preferences
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
@ -129,93 +83,94 @@ class Preferences implements SplSubject, \Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for change set
|
||||
* @return ChangeSet
|
||||
* Determine whether a preference exists
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getChangeSet()
|
||||
public function has($name)
|
||||
{
|
||||
return $this->changeSet;
|
||||
return array_key_exists($name, $this->preferences);
|
||||
}
|
||||
|
||||
public function has($key)
|
||||
/**
|
||||
* Write data to a preference
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
return array_key_exists($key, $this->preferences);
|
||||
$this->preferences[$name] = $value;
|
||||
}
|
||||
|
||||
public function set($key, $value)
|
||||
/**
|
||||
* Retrieve a preference and return $default if the preference is not set
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
$oldValue = $this->get($key);
|
||||
|
||||
// Do not notify useless writes
|
||||
if ($oldValue !== $value) {
|
||||
$this->changeSet->appendUpdate($key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->changeSet->appendCreate($key, $value);
|
||||
if (array_key_exists($name, $this->preferences)) {
|
||||
return $this->preferences[$name];
|
||||
}
|
||||
|
||||
$this->processCommit();
|
||||
}
|
||||
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
return $this->preferences[$key];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function remove($key)
|
||||
/**
|
||||
* Magic method so that $obj->value will work.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
$this->changeSet->appendDelete($key);
|
||||
$this->processCommit();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->get($name);
|
||||
}
|
||||
|
||||
public function startTransaction()
|
||||
/**
|
||||
* Remove a given preference
|
||||
*
|
||||
* @param string $name Preference name
|
||||
*/
|
||||
public function remove($name)
|
||||
{
|
||||
$this->autoCommit = false;
|
||||
unset($this->preferences[$name]);
|
||||
}
|
||||
|
||||
public function commit()
|
||||
/**
|
||||
* Determine if a preference is set and is not NULL
|
||||
*
|
||||
* @param string $name Preference name
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name)
|
||||
{
|
||||
$changeSet = $this->changeSet;
|
||||
|
||||
if ($this->autoCommit === false) {
|
||||
$this->autoCommit = true;
|
||||
}
|
||||
|
||||
if ($changeSet->hasChanges() === true) {
|
||||
foreach ($changeSet->getCreate() as $key => $value) {
|
||||
$this->preferences[$key] = $value;
|
||||
}
|
||||
|
||||
foreach ($changeSet->getUpdate() as $key => $value) {
|
||||
$this->preferences[$key] = $value;
|
||||
}
|
||||
|
||||
foreach ($changeSet->getDelete() as $key) {
|
||||
unset($this->preferences[$key]);
|
||||
}
|
||||
|
||||
$this->notify();
|
||||
|
||||
$this->changeSet->clear();
|
||||
} else {
|
||||
throw new ProgrammingError('Nothing to commit');
|
||||
}
|
||||
return isset($this->preferences[$name]);
|
||||
}
|
||||
|
||||
private function processCommit()
|
||||
/**
|
||||
* Unset a given preference
|
||||
*
|
||||
* @param string $name Preference name
|
||||
*/
|
||||
public function __unset($name)
|
||||
{
|
||||
if ($this->autoCommit === true) {
|
||||
$this->commit();
|
||||
}
|
||||
$this->remove($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get preferences as array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return $this->preferences;
|
||||
}
|
||||
}
|
||||
|
@ -1,139 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
/**
|
||||
* Voyager object to transport changes between consumers
|
||||
*/
|
||||
class ChangeSet
|
||||
{
|
||||
/**
|
||||
* Stack of pending updates
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $update = array();
|
||||
|
||||
/**
|
||||
* Stack of pending delete operations
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $delete = array();
|
||||
|
||||
/**
|
||||
* Stack of pending create operations
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $create = array();
|
||||
|
||||
/**
|
||||
* Push an update to stack
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function appendUpdate($key, $value)
|
||||
{
|
||||
$this->update[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for pending updates
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUpdate()
|
||||
{
|
||||
return $this->update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push delete operation to stack
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function appendDelete($key)
|
||||
{
|
||||
$this->delete[] = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pending delete operations
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDelete()
|
||||
{
|
||||
return $this->delete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push create operation to stack
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function appendCreate($key, $value)
|
||||
{
|
||||
$this->create[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pending create operations
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCreate()
|
||||
{
|
||||
return $this->create;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all changes
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->update = array();
|
||||
$this->delete = array();
|
||||
$this->create = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for registered changes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChanges()
|
||||
{
|
||||
return (count($this->update) > 0) || (count($this->delete) > 0) || (count($this->create));
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
use Icinga\User;
|
||||
use \SplObserver;
|
||||
|
||||
/**
|
||||
* Handle preference updates
|
||||
*/
|
||||
interface FlushObserverInterface extends SplObserver
|
||||
{
|
||||
/**
|
||||
* Setter for user
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user);
|
||||
}
|
@ -1,204 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Protocol\Ldap\Exception;
|
||||
use \SplSubject;
|
||||
use \Icinga\User;
|
||||
use \Icinga\User\Preferences;
|
||||
use \Icinga\Exception\ConfigurationError;
|
||||
use \Icinga\Exception\ProgrammingError;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Zend_Config_Writer_Ini;
|
||||
|
||||
/**
|
||||
* Handle preferences in ini files
|
||||
*
|
||||
* Load and write values from user preferences to ini files
|
||||
*/
|
||||
class IniStore implements LoadInterface, FlushObserverInterface
|
||||
{
|
||||
/**
|
||||
* Path to ini configuration
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $configPath;
|
||||
|
||||
/**
|
||||
* Specific user file for preferences
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $preferencesFile;
|
||||
|
||||
/**
|
||||
* Config container
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $iniConfig;
|
||||
|
||||
/**
|
||||
* Ini writer
|
||||
*
|
||||
* @var Zend_Config_Writer_Ini
|
||||
*/
|
||||
private $iniWriter;
|
||||
|
||||
/**
|
||||
* Current user
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Create a new object
|
||||
*
|
||||
* @param string|null $configPath
|
||||
*/
|
||||
public function __construct($configPath = null)
|
||||
{
|
||||
if ($configPath !== null) {
|
||||
$this->setConfigPath($configPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for config directory
|
||||
*
|
||||
* @param string $configPath
|
||||
* @throws \Icinga\Exception\ConfigurationError
|
||||
*/
|
||||
public function setConfigPath($configPath)
|
||||
{
|
||||
$configPath = IcingaConfig::resolvePath($configPath);
|
||||
if (!is_dir($configPath)) {
|
||||
throw new ConfigurationError('Config dir dos not exist: '. $configPath);
|
||||
}
|
||||
|
||||
$this->configPath = $configPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for user
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
$this->preferencesFile = sprintf(
|
||||
'%s/%s.ini',
|
||||
$this->configPath,
|
||||
$this->user->getUsername()
|
||||
);
|
||||
|
||||
if (file_exists($this->preferencesFile) === false) {
|
||||
$this->createDefaultIniFile();
|
||||
}
|
||||
try {
|
||||
$this->iniConfig = new Zend_Config(
|
||||
parse_ini_file($this->preferencesFile),
|
||||
true
|
||||
);
|
||||
|
||||
$this->iniWriter = new Zend_Config_Writer_Ini(
|
||||
array(
|
||||
'config' => $this->iniConfig,
|
||||
'filename' => $this->preferencesFile
|
||||
)
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
Logger::error('Could not create IniStore backend: %s', $e->getMessage());
|
||||
throw new \RuntimeException("Creating user preference backend failed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to create blank ini file
|
||||
*/
|
||||
private function createDefaultIniFile()
|
||||
{
|
||||
// TODO: We should be able to work without preferences. Also we shouldn't store any
|
||||
// prefs as long as we didn't change some.
|
||||
if (! is_writable($this->configPath) || touch($this->preferencesFile) === false) {
|
||||
throw new ConfigurationError(
|
||||
sprintf('Unable to store "%s"', $this->preferencesFile)
|
||||
);
|
||||
}
|
||||
chmod($this->preferencesFile, 0664);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load preferences from source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
return $this->iniConfig->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive update from subject
|
||||
*
|
||||
* @link http://php.net/manual/en/splobserver.update.php
|
||||
* @param SplSubject $subject
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
public function update(SplSubject $subject)
|
||||
{
|
||||
if (!$subject instanceof Preferences) {
|
||||
throw new ProgrammingError('Not compatible with '. get_class($subject));
|
||||
}
|
||||
|
||||
$changeSet = $subject->getChangeSet();
|
||||
|
||||
foreach ($changeSet->getCreate() as $key => $value) {
|
||||
$this->iniConfig->{$key} = $value;
|
||||
}
|
||||
|
||||
foreach ($changeSet->getUpdate() as $key => $value) {
|
||||
$this->iniConfig->{$key} = $value;
|
||||
}
|
||||
|
||||
foreach ($changeSet->getDelete() as $key) {
|
||||
unset($this->iniConfig->{$key});
|
||||
}
|
||||
|
||||
// Persist changes to disk
|
||||
$this->iniWriter->write();
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
/**
|
||||
* Describe how to load preferences from data sources
|
||||
*/
|
||||
interface LoadInterface
|
||||
{
|
||||
/**
|
||||
* Load preferences from source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load();
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
use Icinga\User;
|
||||
use SplSubject;
|
||||
|
||||
/**
|
||||
* Preference store that simply discards any settings made
|
||||
*
|
||||
* Mainly used as a fallback provider if no preferences can be created
|
||||
*/
|
||||
class NullStore implements LoadInterface, FlushObserverInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Setter for user, does nothing
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Load preferences from source, return an empty array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Receive update from subject
|
||||
*
|
||||
* @link http://php.net/manual/en/splobserver.update.php
|
||||
* @param SplSubject $subject <p>
|
||||
* The <b>SplSubject</b> notifying the observer of an update.
|
||||
* </p>
|
||||
* @return void
|
||||
*/
|
||||
public function update(SplSubject $subject)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
176
library/Icinga/User/Preferences/PreferencesStore.php
Normal file
176
library/Icinga/User/Preferences/PreferencesStore.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
use Zend_Config;
|
||||
use Icinga\User;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\User\Preferences;
|
||||
|
||||
/**
|
||||
* Preferences store factory
|
||||
*
|
||||
* Usage example:
|
||||
* <code>
|
||||
* <?php
|
||||
*
|
||||
* use Zend_Config;
|
||||
* use Icinga\User\Preferences;
|
||||
* use Icinga\User\Preferences\PreferencesStore;
|
||||
*
|
||||
* // Create a INI store
|
||||
* $store = new PreferencesStore(
|
||||
* new Zend_Config(
|
||||
* 'type' => 'ini',
|
||||
* 'configPath' => '/path/to/preferences'
|
||||
* ),
|
||||
* $user // Instance of \Icinga\User
|
||||
* );
|
||||
*
|
||||
* $preferences = new Preferences($store->load());
|
||||
* $preferences->aPreference = 'value';
|
||||
* $store->save($preferences);
|
||||
*/
|
||||
abstract class PreferencesStore
|
||||
{
|
||||
/**
|
||||
* Store config
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Given user
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Create a new store
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(Zend_Config $config, User $user)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->user = $user;
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the sore
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the store config
|
||||
*
|
||||
* @return Zend_Config
|
||||
*/
|
||||
final public function getStoreConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the user
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
final public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load preferences from source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function load();
|
||||
|
||||
/**
|
||||
* Save the given preferences
|
||||
*
|
||||
* @param Preferences $preferences
|
||||
*/
|
||||
public function save(Preferences $preferences)
|
||||
{
|
||||
$storedPreferences = $this->load();
|
||||
$preferences = $preferences->toArray();
|
||||
$newPreferences = array_diff_key($preferences, $storedPreferences);
|
||||
$updatedPreferences = array_diff_assoc($preferences, $storedPreferences);
|
||||
$deletedPreferences = array_keys(array_diff_key($storedPreferences, $preferences));
|
||||
if (count($newPreferences) || count($updatedPreferences) || count($deletedPreferences)) {
|
||||
$this->cud($newPreferences, $updatedPreferences, $deletedPreferences);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create, update and delete the given preferences
|
||||
*
|
||||
* @param array $newPreferences Key-value array of preferences to create
|
||||
* @param array $updatedPreferences Key-value array of preferences to update
|
||||
* @param array $deletedPreferences An array of preference names to delete
|
||||
*/
|
||||
abstract public function cud($newPreferences, $updatedPreferences, $deletedPreferences);
|
||||
|
||||
/**
|
||||
* Create preferences storage adapter from config
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param User $user
|
||||
*
|
||||
* @return self
|
||||
* @throws ConfigurationError When the configuration defines an invalid storage type
|
||||
*/
|
||||
public static function create(Zend_Config $config, User $user)
|
||||
{
|
||||
if (($type = $config->type) === null) {
|
||||
throw new ConfigurationError(
|
||||
'Preferences configuration is missing the type directive'
|
||||
);
|
||||
}
|
||||
$type = ucfirst(strtolower($type));
|
||||
$storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store';
|
||||
if (!class_exists($storeClass)) {
|
||||
throw new ConfigurationError(
|
||||
'Preferences configuration defines an invalid storage type. Storage type ' . $type . ' not found'
|
||||
);
|
||||
}
|
||||
return new $storeClass($config, $user);
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
use Icinga\Session\Session;
|
||||
use \SplObserver;
|
||||
use \SplSubject;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
||||
/**
|
||||
* Modify preferences into session
|
||||
*/
|
||||
class SessionStore implements SplObserver, LoadInterface
|
||||
{
|
||||
/**
|
||||
* Name of session var for preferences
|
||||
*/
|
||||
const DEFAULT_SESSION_NAMESPACE = 'preferences';
|
||||
|
||||
/**
|
||||
* Session data
|
||||
*
|
||||
* @var Session
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* Create a new object
|
||||
*
|
||||
* @param Session $session
|
||||
*/
|
||||
public function __construct(Session $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive update from subject
|
||||
*
|
||||
* @link http://php.net/manual/en/splobserver.update.php
|
||||
* @param SplSubject $subject
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
public function update(SplSubject $subject)
|
||||
{
|
||||
if (!$subject instanceof Preferences) {
|
||||
throw new ProgrammingError('Not compatible with '. get_class($subject));
|
||||
}
|
||||
|
||||
$changeSet = $subject->getChangeSet();
|
||||
|
||||
$data = $this->session->get(self::DEFAULT_SESSION_NAMESPACE, array());
|
||||
|
||||
foreach ($changeSet->getCreate() as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
foreach ($changeSet->getUpdate() as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
foreach ($changeSet->getDelete() as $key) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
$this->session->set(self::DEFAULT_SESSION_NAMESPACE, $data);
|
||||
|
||||
$this->session->write();
|
||||
}
|
||||
|
||||
/**
|
||||
* Public interface to copy all preferences into session
|
||||
*
|
||||
* @param array $preferences
|
||||
*/
|
||||
public function writeAll(array $preferences)
|
||||
{
|
||||
$this->session->set(self::DEFAULT_SESSION_NAMESPACE, $preferences);
|
||||
$this->session->write();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load preferences from source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
return $this->session->get(self::DEFAULT_SESSION_NAMESPACE, array());
|
||||
}
|
||||
}
|
@ -31,9 +31,9 @@ namespace Icinga\User\Preferences;
|
||||
|
||||
use Icinga\User;
|
||||
use SplSubject;
|
||||
use Zend_Db_Adapter_Abstract;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
|
||||
/**
|
||||
* Store user preferences in database
|
||||
@ -84,6 +84,9 @@ class DbStore implements LoadInterface, FlushObserverInterface
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
ResourceFactory::createResource(
|
||||
ResourceFactory::getResourceConfig($config->resource)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,7 +94,7 @@ class DbStore implements LoadInterface, FlushObserverInterface
|
||||
*
|
||||
* @param Zend_Db_Adapter_Abstract $db
|
||||
*/
|
||||
public function setDbAdapter(Zend_Db_Adapter_Abstract $db)
|
||||
public function setDbAdapter( $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
|
||||
@ -115,8 +118,7 @@ class DbStore implements LoadInterface, FlushObserverInterface
|
||||
public function load()
|
||||
{
|
||||
$res = $this->db->select()->from($this->table)
|
||||
->where('username=?', $this->user->getUsername())
|
||||
->query();
|
||||
->where('username=?', $this->user->getUsername());
|
||||
|
||||
$out = array();
|
||||
|
146
library/Icinga/User/Preferences/Store/IniStore.php
Normal file
146
library/Icinga/User/Preferences/Store/IniStore.php
Normal file
@ -0,0 +1,146 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User\Preferences\Store;
|
||||
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Config\PreservingIniWriter;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Exception\NotWritableError;
|
||||
use Icinga\User;
|
||||
use Icinga\User\Preferences\PreferencesStore;
|
||||
use Icinga\Util\File;
|
||||
|
||||
/**
|
||||
* Load and save user preferences from and to INI files
|
||||
*
|
||||
* Usage example:
|
||||
* <code>
|
||||
* <?php
|
||||
*
|
||||
* use Zend_Config;
|
||||
* use Icinga\User\Preferences;
|
||||
* use Icinga\User\Preferences\PreferencesStore;
|
||||
* use Icinga\User\Preferences\Store\IniStore;
|
||||
*
|
||||
* // Create the store from the factory (preferred approach)
|
||||
* $store = new PreferencesStore(
|
||||
* new Zend_Config(
|
||||
* 'type' => 'ini',
|
||||
* 'configPath' => '/path/to/preferences'
|
||||
* ),
|
||||
* $user // Instance of \Icinga\User
|
||||
* );
|
||||
*
|
||||
* // Create the store directly
|
||||
* $store = new IniStore(
|
||||
* new Zend_Config(
|
||||
* 'configPath' => '/path/to/preferences'
|
||||
* ),
|
||||
* $user // Instance of \Icinga\User
|
||||
* );
|
||||
*
|
||||
* $preferences = new Preferences($store->load());
|
||||
* $preferences->aPreference = 'value';
|
||||
* $store->save($preferences);
|
||||
* </code>
|
||||
*/
|
||||
class IniStore extends PreferencesStore
|
||||
{
|
||||
/**
|
||||
* Preferences file of the given user
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $preferencesFile;
|
||||
|
||||
/**
|
||||
* Stored preferences
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $preferences;
|
||||
|
||||
/**
|
||||
* Writer which stores the preferences
|
||||
*
|
||||
* @var PreservingIniWriter
|
||||
*/
|
||||
private $writer;
|
||||
|
||||
/**
|
||||
* Initialize the store
|
||||
*
|
||||
* @throws NotReadableError When the preferences INI file of the given user is not readable
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->preferencesFile = sprintf(
|
||||
'%s/%s.ini',
|
||||
IcingaConfig::resolvePath($this->getStoreConfig()->configPath),
|
||||
$this->getUser()->getUsername()
|
||||
);
|
||||
if (file_exists($this->preferencesFile)) {
|
||||
if (!is_readable($this->preferencesFile)) {
|
||||
throw new NotReadableError('Preferences INI file ' . $this->preferencesFile . ' for user '
|
||||
. $this->getUser()->getUsername() . ' is not readable');
|
||||
} else {
|
||||
$this->preferences = parse_ini_file($this->preferencesFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load preferences from source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
return $this->preferences !== null ? $this->preferences : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create, update and delete the given preferences
|
||||
*
|
||||
* @param array $newPreferences Key-value array of preferences to create
|
||||
* @param array $updatedPreferences Key-value array of preferences to update
|
||||
* @param array $deletedPreferences An array of preference names to delete
|
||||
*
|
||||
* @throws NotWritableError When either the path to the preferences INI files is not writable or the
|
||||
* preferences INI file for the given user is not writable
|
||||
*/
|
||||
public function cud($newPreferences, $updatedPreferences, $deletedPreferences)
|
||||
{
|
||||
if ($this->preferences === null) {
|
||||
// Preferences INI file does not yet exist
|
||||
if (!is_writable($this->getStoreConfig()->configPath)) {
|
||||
throw new NotWritableError('Path to the preferences INI files ' . $this->getStoreConfig()->configPath
|
||||
. ' is not writable');
|
||||
}
|
||||
File::create($this->preferencesFile);
|
||||
$this->preferences = array();
|
||||
}
|
||||
if (!is_writable($this->preferencesFile)) {
|
||||
throw new NotWritableError('Preferences INI file ' . $this->preferencesFile . ' for user '
|
||||
. $this->getUser()->getUsername() . ' is not writable');
|
||||
}
|
||||
foreach ($newPreferences as $name => $value) {
|
||||
$this->preferences[$name] = $value;
|
||||
}
|
||||
foreach ($updatedPreferences as $name => $value) {
|
||||
$this->preferences[$name] = $value;
|
||||
}
|
||||
foreach ($deletedPreferences as $name) {
|
||||
unset($this->preferences[$name]);
|
||||
}
|
||||
if ($this->writer === null) {
|
||||
$this->writer = new PreservingIniWriter(
|
||||
array('config' => new Zend_Config($this->preferences), 'filename' => $this->preferencesFile)
|
||||
);
|
||||
}
|
||||
$this->writer->write();
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
use \Zend_Config;
|
||||
use \Icinga\User;
|
||||
use \Icinga\Exception\ProgrammingError;
|
||||
use \Icinga\Data\ResourceFactory;
|
||||
|
||||
/**
|
||||
* Create preference stores from zend config
|
||||
*/
|
||||
final class StoreFactory
|
||||
{
|
||||
/**
|
||||
* Prefix for classes containing namespace
|
||||
*/
|
||||
const CLASS_PREFIX = 'Icinga\\User\\Preferences\\';
|
||||
|
||||
/**
|
||||
* Suffix for class
|
||||
*/
|
||||
const CLASS_SUFFIX = 'Store';
|
||||
|
||||
/**
|
||||
* Create storage adapter from zend configuration
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param User $user
|
||||
*
|
||||
* @return FlushObserverInterface
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
public static function create(Zend_Config $config, User $user)
|
||||
{
|
||||
$class = self::CLASS_PREFIX. ucfirst($config->get('type')). self::CLASS_SUFFIX;
|
||||
|
||||
if (class_exists($class)) {
|
||||
$store = new $class();
|
||||
|
||||
if (!$store instanceof FlushObserverInterface) {
|
||||
throw new ProgrammingError(
|
||||
'Preferences StoreFactory could not create provider (class ' . $class . '). '
|
||||
. 'Class is not instance of FlushObserverInterface.'
|
||||
);
|
||||
}
|
||||
|
||||
$items = $config->toArray();
|
||||
|
||||
if ($items['type'] == 'db') {
|
||||
$items['dbAdapter'] = ResourceFactory::createResource($items['resource']);
|
||||
}
|
||||
unset($items['type']);
|
||||
|
||||
foreach ($items as $key => $value) {
|
||||
$setter = 'set'. ucfirst($key);
|
||||
if (is_callable(array($store, $setter))) {
|
||||
$store->$setter($value);
|
||||
}
|
||||
}
|
||||
|
||||
$store->setUser($user);
|
||||
|
||||
return $store;
|
||||
}
|
||||
|
||||
throw new ProgrammingError(
|
||||
'Preferences StoreFactory could not create provider (class ' . $class . '). Class not found.'
|
||||
);
|
||||
}
|
||||
}
|
14
library/Icinga/Util/File.php
Normal file
14
library/Icinga/Util/File.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Util;
|
||||
|
||||
class File
|
||||
{
|
||||
public static function create($filename, $mode = 0664)
|
||||
{
|
||||
fclose(fopen($filename, 'a'));
|
||||
chmod($filename, $mode);
|
||||
}
|
||||
}
|
@ -44,6 +44,6 @@ class String
|
||||
*/
|
||||
public static function trimSplit($value, $delimiter = ',')
|
||||
{
|
||||
return array_map('trim', explode(',', $value));
|
||||
return array_map('trim', explode($delimiter, $value));
|
||||
}
|
||||
}
|
||||
|
4
library/Icinga/Web/Controller/ActionController.php
Executable file → Normal file
4
library/Icinga/Web/Controller/ActionController.php
Executable file → Normal file
@ -237,7 +237,9 @@ class ActionController extends Zend_Controller_Action
|
||||
$this->_helper->layout()->setLayout($target);
|
||||
}
|
||||
if ($user = $this->getRequest()->getUser()) {
|
||||
if ($user->getPreferences()->get('app.showBenchmark') === true) {
|
||||
// Cast preference app.showBenchmark to bool because preferences loaded from a preferences storage are
|
||||
// always strings
|
||||
if ((bool) $user->getPreferences()->get('app.showBenchmark', false) === true) {
|
||||
Benchmark::measure('Response ready');
|
||||
$this->_helper->layout()->benchmark = $this->renderBenchmark();
|
||||
}
|
||||
|
@ -29,6 +29,12 @@
|
||||
|
||||
namespace Icinga\Web\Controller;
|
||||
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\User\Preferences\PreferencesStore;
|
||||
|
||||
/**
|
||||
* Base class for Preference Controllers
|
||||
*
|
||||
@ -62,4 +68,24 @@ class BasePreferenceController extends ActionController
|
||||
parent::init();
|
||||
$this->view->tabs = ControllerTabCollector::collectControllerTabs('PreferenceController');
|
||||
}
|
||||
|
||||
protected function savePreferences(array $preferences)
|
||||
{
|
||||
$currentPreferences = $this->_request->getUser()->getPreferences();
|
||||
foreach ($preferences as $key => $value) {
|
||||
if ($value === null) {
|
||||
unset($currentPreferences->{$key});
|
||||
} else {
|
||||
$currentPreferences->{$key} = $value;
|
||||
}
|
||||
}
|
||||
Session::getSession()->write();
|
||||
if (($preferencesConfig = IcingaConfig::app()->preferences) === null) {
|
||||
throw new ConfigurationError(
|
||||
'Cannot save preferences changes since you\'ve not configured a preferences backend'
|
||||
);
|
||||
}
|
||||
$store = PreferencesStore::create($preferencesConfig, $this->_request->getUser());
|
||||
$store->save($currentPreferences);
|
||||
}
|
||||
}
|
||||
|
@ -242,11 +242,14 @@ class Form extends Zend_Form
|
||||
/**
|
||||
* Set the configuration to be used for this form when no preferences are set yet
|
||||
*
|
||||
* @param IcingaConfig $cfg
|
||||
* @param IcingaConfig $cfg
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setConfiguration($cfg)
|
||||
{
|
||||
$this->config = $cfg;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
0
library/Icinga/Web/Hook.php
Executable file → Normal file
0
library/Icinga/Web/Hook.php
Executable file → Normal file
@ -31,7 +31,8 @@ namespace Icinga\Web;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Web\MenuItem;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
|
||||
class Menu extends MenuItem
|
||||
{
|
||||
@ -44,12 +45,22 @@ class Menu extends MenuItem
|
||||
{
|
||||
$menu = new static('menu');
|
||||
$manager = Icinga::app()->getModuleManager();
|
||||
$menuConfigs = array(Config::app('menu'));
|
||||
foreach ($manager->listEnabledModules() as $moduleName) {
|
||||
$moduleMenuConfig = Config::module($moduleName, 'menu');
|
||||
if ($moduleMenuConfig) {
|
||||
$menuConfigs[] = $moduleMenuConfig;
|
||||
try {
|
||||
$menuConfigs = array(Config::app('menu'));
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error($e);
|
||||
$menuConfigs = array();
|
||||
}
|
||||
try {
|
||||
|
||||
foreach ($manager->listEnabledModules() as $moduleName) {
|
||||
$moduleMenuConfig = Config::module($moduleName, 'menu');
|
||||
if ($moduleMenuConfig) {
|
||||
$menuConfigs[] = $moduleMenuConfig;
|
||||
}
|
||||
}
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error($e);
|
||||
}
|
||||
return $menu->loadMenuItems($menu->flattenConfigs($menuConfigs));
|
||||
}
|
||||
|
0
library/Icinga/Web/Paginator/Adapter/QueryAdapter.php
Executable file → Normal file
0
library/Icinga/Web/Paginator/Adapter/QueryAdapter.php
Executable file → Normal file
0
library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php
Executable file → Normal file
0
library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php
Executable file → Normal file
0
library/vendor/Parsedown/Parsedown.php
vendored
Executable file → Normal file
0
library/vendor/Parsedown/Parsedown.php
vendored
Executable file → Normal file
0
library/vendor/dompdf/changelog.txt
vendored
Executable file → Normal file
0
library/vendor/dompdf/changelog.txt
vendored
Executable file → Normal file
0
library/vendor/dompdf/dompdf.php
vendored
Executable file → Normal file
0
library/vendor/dompdf/dompdf.php
vendored
Executable file → Normal file
0
library/vendor/dompdf/load_font.php
vendored
Executable file → Normal file
0
library/vendor/dompdf/load_font.php
vendored
Executable file → Normal file
0
library/vendor/dompdf/readme.html
vendored
Executable file → Normal file
0
library/vendor/dompdf/readme.html
vendored
Executable file → Normal file
0
library/vendor/htmlpurifier-4.5.0-lite/library/HTMLPurifier/DefinitionCache/Serializer/README
vendored
Executable file → Normal file
0
library/vendor/htmlpurifier-4.5.0-lite/library/HTMLPurifier/DefinitionCache/Serializer/README
vendored
Executable file → Normal file
0
modules/monitoring/library/Monitoring/Backend/Statusdat/Query/HostgroupQuery.php
Executable file → Normal file
0
modules/monitoring/library/Monitoring/Backend/Statusdat/Query/HostgroupQuery.php
Executable file → Normal file
0
modules/monitoring/library/Monitoring/Backend/Statusdat/Query/HostlistQuery.php
Executable file → Normal file
0
modules/monitoring/library/Monitoring/Backend/Statusdat/Query/HostlistQuery.php
Executable file → Normal file
0
modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ServicegroupQuery.php
Executable file → Normal file
0
modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ServicegroupQuery.php
Executable file → Normal file
0
modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ServicelistQuery.php
Executable file → Normal file
0
modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ServicelistQuery.php
Executable file → Normal file
0
public/css/pdf/pdf.css
Executable file → Normal file
0
public/css/pdf/pdf.css
Executable file → Normal file
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user