' : '' ?> +
diff --git a/library/Icinga/Authentication/Manager.php b/library/Icinga/Authentication/Manager.php index 75cf81481..efe9b5815 100644 --- a/library/Icinga/Authentication/Manager.php +++ b/library/Icinga/Authentication/Manager.php @@ -113,30 +113,32 @@ class Manager } /** - * Tries to authenticate the user with the current session + * Try to authenticate the user with the current session + * + * Authentication for externally-authenticated users will be revoked if the username changed or external + * authentication is no longer in effect */ public function authenticateFromSession() { $this->user = Session::getSession()->get('user'); - if ($this->user !== null && $this->user->isRemoteUser() === true) { list($originUsername, $field) = $this->user->getRemoteUserInformation(); - if (array_key_exists($field, $_SERVER) && $_SERVER[$field] !== $originUsername) { + if (! array_key_exists($field, $_SERVER) || $_SERVER[$field] !== $originUsername) { $this->removeAuthorization(); } } } /** - * Returns true when the user is currently authenticated + * Whether the user is authenticated * - * @param Boolean $ignoreSession Set to true to prevent authentication by session + * @param bool $ignoreSession True to prevent session authentication * * @return bool */ public function isAuthenticated($ignoreSession = false) { - if ($this->user === null && !$ignoreSession) { + if ($this->user === null && ! $ignoreSession) { $this->authenticateFromSession(); } return is_object($this->user); @@ -145,25 +147,16 @@ class Manager /** * Whether an authenticated user has a given permission * - * This is true if the user owns this permission, false if not. - * Also false if there is no authenticated user - * - * TODO: I'd like to see wildcard support, e.g. module/* - * * @param string $permission Permission name - * @return bool + * + * @return bool True if the user owns the given permission, false if not or if not authenticated */ public function hasPermission($permission) { if (! $this->isAuthenticated()) { return false; } - foreach ($this->user->getPermissions() as $p) { - if ($p === $permission) { - return true; - } - } - return false; + return $this->user->can($permission); } /** diff --git a/library/Icinga/User.php b/library/Icinga/User.php index 13f62881a..71e4b47e4 100644 --- a/library/Icinga/User.php +++ b/library/Icinga/User.php @@ -187,9 +187,9 @@ class User } /** - * Return permission information for this user + * Get the user's permissions * - * @return array + * @return array */ public function getPermissions() { @@ -197,13 +197,17 @@ class User } /** - * Setter for permissions + * Set the user's permissions * - * @param array $permissions + * @param array $permissions + * + * @return $this */ public function setPermissions(array $permissions) { - $this->permissions = $permissions; + natcasesort($permissions); + $this->permissions = array_combine($permissions, $permissions); + return $this; } /** @@ -442,6 +446,33 @@ class User */ public function isRemoteUser() { - return (count($this->remoteUserInformation)) ? true : false; + return ! empty($this->remoteUserInformation); + } + + /** + * Whether the user has a given permission + * + * @param string $permission + * + * @return bool + */ + public function can($permission) + { + if (isset($this->permissions['*']) || isset($this->permissions[$permission])) { + return true; + } + foreach ($this->permissions as $permitted) { + $wildcard = strpos($permitted, '*'); + if ($wildcard !== false) { + if (substr($permission, 0, $wildcard) === substr($permitted, 0, $wildcard)) { + return true; + } else { + if ($permission === $permitted) { + return true; + } + } + } + } + return false; } } diff --git a/library/Icinga/Web/JavaScript.php b/library/Icinga/Web/JavaScript.php index 6aa36d608..6224b5b82 100644 --- a/library/Icinga/Web/JavaScript.php +++ b/library/Icinga/Web/JavaScript.php @@ -26,7 +26,8 @@ class JavaScript 'js/icinga/behavior/tooltip.js', 'js/icinga/behavior/sparkline.js', 'js/icinga/behavior/tristate.js', - 'js/icinga/behavior/navigation.js' + 'js/icinga/behavior/navigation.js', + 'js/icinga/behavior/form.js' ); protected static $vendorFiles = array( diff --git a/library/Icinga/Web/Widget/Chart/HistoryColorGrid.php b/library/Icinga/Web/Widget/Chart/HistoryColorGrid.php index 974e02060..56de318e8 100644 --- a/library/Icinga/Web/Widget/Chart/HistoryColorGrid.php +++ b/library/Icinga/Web/Widget/Chart/HistoryColorGrid.php @@ -28,29 +28,32 @@ class HistoryColorGrid extends AbstractWidget { private $maxValue = 1; private $start = null; - private $end = null; - private $data = array(); - private $color; + public $opacity = 1.0; - public function __construct($color = '#51e551') { + public function __construct($color = '#51e551', $start = null, $end = null) { $this->setColor($color); + if (isset($start)) { + $this->start = $this->tsToDateStr($start); + } + if (isset($end)) { + $this->end = $this->tsToDateStr($end); + } } /** * Set the displayed data-set * - * @param $data array The values to display. - * properties for each entry: + * @param $events array The history events to display as an array of arrays: * value: The value to display * caption: The caption on mouse-over * url: The url to open on click. */ - public function setData(array $data) + public function setData(array $events) { - $this->data = $data; + $this->data = $events; $start = time(); $end = time(); foreach ($this->data as $entry) { @@ -68,8 +71,12 @@ class HistoryColorGrid extends AbstractWidget { $start = $time; } } - $this->start = $this->tsToDateStr($start); - $this->end = $this->tsToDateStr($end); + if (!isset($this->start)) { + $this->start = $this->tsToDateStr($start); + } + if (!isset($this->end)) { + $this->end = $this->tsToDateStr($end); + } } /** @@ -82,6 +89,16 @@ class HistoryColorGrid extends AbstractWidget { $this->color = $color; } + /** + * Set the used opacity + * + * @param $opacity + */ + public function setOpacity($opacity) + { + $this->opacity = $opacity; + } + /** * Calculate the color to display for the given value. * @@ -104,16 +121,17 @@ class HistoryColorGrid extends AbstractWidget { */ private function renderDay($day) { - if (array_key_exists($day, $this->data)) { + if (array_key_exists($day, $this->data) && $this->data[$day]['value'] > 0) { $entry = $this->data[$day]; return'calculateColor($entry['value']) . ';" ' . + 'style="background-color:' . $this->calculateColor($entry['value']) . '; ' + . ' opacity: ' . $this->opacity . ';"' . 'title="' . $entry['caption'] . '" ' . 'href="' . $entry['url'] . '"' . '> '; } else { return 'calculateColor(0) . ';" ' . + 'style="background-color:' . $this->calculateColor(0) . '; ' . ' opacity: ' . $this->opacity . ';" ' . 'title="No entries for ' . $day . '" ' . '>'; } @@ -130,13 +148,14 @@ class HistoryColorGrid extends AbstractWidget { { $weeks = $grid['weeks']; $months = $grid['months']; + $years = $grid['years']; $html = '
'; $old = -1; - foreach ($months as $month) { + foreach ($months as $week => $month) { if ($old !== $month) { $old = $month; - $txt = $this->monthName($month); + $txt = $this->monthName($month, $years[$week]); } else { $txt = ''; } @@ -157,6 +176,7 @@ class HistoryColorGrid extends AbstractWidget { */ private function renderVertical($grid) { + $years = $grid['years']; $weeks = $grid['weeks']; $months = $grid['months']; $html = ' |
---|