Handle window-id requests, allowing us to identify distinct windows

This commit is contained in:
Thomas Gelf 2014-03-21 13:27:44 +00:00
parent 252feba64c
commit 01f94c574d
2 changed files with 32 additions and 6 deletions

View File

@ -68,6 +68,8 @@ class ActionController extends Zend_Controller_Action
private $noXhrBody = false;
private $windowId;
// TODO: This would look better if we had a ModuleActionController
public function Config($file = null)
{
@ -111,9 +113,14 @@ class ActionController extends Zend_Controller_Action
// when noInit is set (e.g. for testing), authentication and init is skipped
if (isset($invokeArgs['noInit'])) {
// TODO: Find out whether this still makes sense?
return;
}
if ($this->_request->isXmlHttpRequest()) {
$this->windowId = $this->_request->getHeader('X-Icinga-WindowId', null);
}
if ($this->requiresLogin() === false) {
$this->view->tabs = new Tabs();
$this->init();
@ -127,6 +134,21 @@ class ActionController extends Zend_Controller_Action
}
}
protected function getWindowId()
{
if ($this->windowId === null) {
return 'undefined';
}
return $this->windowId;
}
protected function generateWindowId()
{
$letters = 'abcefghijklmnopqrstuvwxyz';
$this->windowId = substr(str_shuffle($letters), 0, 12);
return $this->windowId;
}
/**
* Return restriction information for an eventually authenticated user
*
@ -328,6 +350,10 @@ class ActionController extends Zend_Controller_Action
return;
}
if ($isXhr && $this->getWindowId() === 'undefined') {
header('X-Icinga-WindowId: ' . $this->generateWindowId());
}
if ($this->view->title) {
if (preg_match('~[\r\n]~', $this->view->title)) {
// TODO: Innocent exception and error log for hack attempts

View File

@ -416,19 +416,19 @@
},
getWindowId: function () {
var res = window.name.match(/^Icinga_([a-zA-Z0-9])$/);
if (res) {
return res[1];
if (! this.hasWindowId()) {
return undefined;
}
return null;
return window.name.match(/^Icinga_([a-zA-Z0-9]+)$/)[1];
},
hasWindowId: function () {
var res = window.name.match(/^Icinga_([a-zA-Z0-9])$/);
return typeof res === 'object';
var res = window.name.match(/^Icinga_([a-zA-Z0-9]+)$/);
return typeof res === 'object' && null !== res;
},
setWindowId: function (id) {
this.icinga.logger.debug('Setting new window id', id);
window.name = 'Icinga_' + id;
},