Skip to content

Commit

Permalink
Support Content-Security-Policy (#2857)
Browse files Browse the repository at this point in the history
resolves #2845
  • Loading branch information
nilmerg authored Jan 25, 2024
2 parents 6e57e6d + 28d8f0e commit 35c6086
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 212 deletions.
11 changes: 7 additions & 4 deletions application/controllers/BasketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,21 @@ public function snapshotAction()
$this->translate('modified'),
'director/basket/snapshotobject',
$linkParams,
['style' => 'color: orange; font-weight: bold']
['class' => 'basket-modified']
);
} else {
$link = Html::tag('span', ['style' => 'color: green'], $this->translate('unchanged'));
$link = Html::tag(
'span',
['class' => 'basket-unchanged'],
$this->translate('unchanged')
);
}
} else {
$link = Link::create(
$this->translate('new'),
'director/basket/snapshotobject',
$linkParams,
['style' => 'color: green; font-weight: bold']
['class' => 'basket-new']
);
}
$table->addNameValueRow($key, $link);
Expand All @@ -333,7 +337,6 @@ public function snapshotAction()
$this->content()->add(Html::tag('h2', $type));
$this->content()->add($table);
}
$this->content()->add(Html::tag('div', ['style' => 'height: 5em']));
}

/**
Expand Down
40 changes: 21 additions & 19 deletions application/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,25 +376,27 @@ public function diffAction()
}

$baseUrl = $this->url()->without(['left', 'right']);
$this->content()->add(Html::tag('form', ['action' => (string) $baseUrl, 'method' => 'GET'], [
new HtmlString($this->view->formSelect(
'left',
$leftSum,
['class' => 'autosubmit', 'style' => 'width: 37%'],
[null => $this->translate('- please choose -')] + $configs
)),
Link::create(
Icon::create('flapping'),
$baseUrl,
['left' => $rightSum, 'right' => $leftSum]
),
new HtmlString($this->view->formSelect(
'right',
$rightSum,
['class' => 'autosubmit', 'style' => 'width: 37%'],
[null => $this->translate('- please choose -')] + $configs
)),
]));
$this->content()->add(
Html::tag('form', ['action' => (string) $baseUrl, 'method' => 'GET', 'class' => 'director-form'], [
new HtmlString($this->view->formSelect(
'left',
$leftSum,
['class' => ['autosubmit', 'config-diff']],
[null => $this->translate('- please choose -')] + $configs
)),
Link::create(
Icon::create('flapping'),
$baseUrl,
['left' => $rightSum, 'right' => $leftSum]
),
new HtmlString($this->view->formSelect(
'right',
$rightSum,
['class' => ['autosubmit', 'config-diff']],
[null => $this->translate('- please choose -')] + $configs
)),
])
);

if ($rightSum === null || $leftSum === null || ! strlen($rightSum) || ! strlen($leftSum)) {
return;
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function dictionaryAction()
$subTitle = $this->translate('Add a new instance');
}

$this->content()->add(Html::tag('h2', ['style' => 'margin-top: 2em'], $subTitle));
$this->content()->add(Html::tag('h2', ['class' => 'dictionary-header'], $subTitle));
$form->handleRequest($this->getRequest());
$this->content()->add($form);
if ($form->succeeded()) {
Expand Down Expand Up @@ -326,7 +326,7 @@ protected function prepareInstancesTable(array $currentValue)
Table::row([
$this->translate('Key / Instance'),
$this->translate('Properties')
], ['style' => 'text-align: left'], 'th')
], ['class' => 'text-align-left'], 'th')
);
foreach ($currentValue as $key => $item) {
$table->add(Table::row([
Expand Down
4 changes: 1 addition & 3 deletions application/controllers/ImportsourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ public function previewAction()
'target' => '_blank',
'class' => 'icon-download',
]
))->add(Link::create('[..]', '#', null, [
'onclick' => 'javascript:$("table.raw-data-table").toggleClass("collapsed");'
]));
));
try {
(new ImportsourceHookTable())->setImportSource($source)->renderTo($this);
} catch (Exception $e) {
Expand Down
5 changes: 1 addition & 4 deletions application/controllers/SyncruleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,7 @@ protected function objectList($objects)
protected function firstNames($objects, $max = 50)
{
$names = [];
$list = new UnorderedList();
$list->addAttributes([
'style' => 'list-style-type: none; marign: 0; padding: 0',
]);
$list = new UnorderedList([], ['class' => 'unordred-list']);
$total = count($objects);
$i = 0;
PrefetchCache::forget();
Expand Down
54 changes: 21 additions & 33 deletions application/forms/AddToBasketForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

class AddToBasketForm extends DirectorForm
{
/** @var Basket */
private $basket;

private $type = '(has not been set)';

private $names = [];
Expand All @@ -30,44 +27,35 @@ public function setup()
'b' => 'basket_name',
])->order('basket_name'));

$names = [];
$basket = null;
if ($this->hasBeenSent()) {
$basketName = $this->getSentValue('basket');
if ($basketName) {
$basket = Basket::load($basketName, $this->getDb());
}
}
$count = 0;
$type = $this->type;

$names = [];
foreach ($this->names as $name) {
if (! empty($names)) {
$names[] = ', ';
}
if ($basket && $basket->hasObject($type, $name)) {
$names[] = Html::tag('span', [
'style' => 'text-decoration: line-through'
], $name);
} else {
$count++;
if (! $basket || ! $basket->hasObject($this->type, $name)) {
$names[] = $name;
}
}
$this->addHtmlHint((new HtmlDocument())->add([
'The following objects will be added: ',
$names
]));
$this->addHtmlHint(
(new HtmlDocument())
->add(sprintf('The following objects will be added: %s', implode(", ", $names)))
);
$this->addElement('select', 'basket', [
'label' => $this->translate('Basket'),
'multiOptions' => $this->optionalEnum($enum),
'required' => true,
'class' => 'autosubmit',
]);

if ($count > 0) {
if (! empty($names)) {
$this->setSubmitLabel(sprintf(
$this->translate('Add %s objects'),
$count
count($names)
));
} else {
$this->setSubmitLabel($this->translate('Add'));
Expand Down Expand Up @@ -112,18 +100,18 @@ public function onSuccess()
'Configuration objects have been added to the chosen basket "%s"'
), $basketName));
return parent::onSuccess();
} else {
$this->addHtmlHint(Hint::error(Html::sprintf($this->translate(
'Please check your Basket configuration, %s does not support'
. ' single "%s" configuration objects'
), Link::create(
$basketName,
'director/basket',
['name' => $basketName],
['data-base-target' => '_next']
), $type)));

return false;
}

$this->addHtmlHint(Hint::error(Html::sprintf($this->translate(
'Please check your Basket configuration, %s does not support'
. ' single "%s" configuration objects'
), Link::create(
$basketName,
'director/basket',
['name' => $basketName],
['data-base-target' => '_next']
), $type)));

return false;
}
}
13 changes: 1 addition & 12 deletions application/forms/IcingaHostForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,6 @@ protected function addGroupsElement()
return $this;
}

protected function strikeGroupLinks(BaseHtmlElement $links)
{
/** @var BaseHtmlElement $link */
foreach ($links->getContent() as $link) {
$link->getAttributes()->add('style', 'text-decoration: strike');
}
$links->add('aha');
}

protected function getInheritedGroups()
{
if ($this->hasObject()) {
Expand All @@ -297,9 +288,7 @@ protected function createHostgroupLinks($groups)
);
}

return Html::tag('span', [
'style' => 'line-height: 2.5em; padding-left: 0.5em'
], $links);
return Html::tag('span', ['class' => 'host-group-links'], $links);
}

protected function getAppliedGroups()
Expand Down
7 changes: 2 additions & 5 deletions application/forms/RemoveLinkForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public function __construct($label, $title, $action, $params = [])
{
// Required to detect the right instance
$this->formName = 'RemoveSet' . sha1(json_encode($params));
parent::__construct([
'style' => 'float: right',
'data-base-target' => '_self'
]);
parent::__construct(['data-base-target' => '_self']);
$this->label = $label;
$this->title = $title;
foreach ($params as $name => $value) {
Expand All @@ -38,7 +35,7 @@ public function runOnSuccess($action)

public function setup()
{
$this->setAttrib('class', 'inline');
$this->addAttribs(['class' => ['inline', 'remove-link-form']]);
$this->addHtml(Icon::create('cancel'));
$this->addSubmitButton($this->label, [
'class' => 'link-button',
Expand Down
2 changes: 1 addition & 1 deletion library/Director/Web/Controller/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function postDispatch()
// Hint -> $this->view->compact is the only way since v2.8.0
if ($this->view->compact || $this->getOriginalUrl()->getParam('view') === 'compact') {
if ($this->view->controls) {
$this->controls()->getAttributes()->add('style', 'display: none;');
$this->controls()->getAttributes()->add('class', 'compact');
}
}
} else {
Expand Down
6 changes: 2 additions & 4 deletions library/Director/Web/Table/IcingaServiceSetServiceTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,15 @@ public function prepareQuery()
protected function createFakeRemoveLinkForReadonlyView()
{
return Html::tag('span', [
'class' => 'icon-paste',
'style' => 'float: right; font-weight: normal',
'class' => ['icon-paste', 'seviceset-obj-link'],
], $this->host->getObjectName());
}

protected function linkToHost(IcingaHost $host)
{
$hostname = $host->getObjectName();
return Link::create($hostname, 'director/host/services', ['name' => $hostname], [
'class' => 'icon-paste',
'style' => 'float: right; font-weight: normal',
'class' => ['icon-paste', 'seviceset-obj-link'],
'data-base-target' => '_next',
'title' => sprintf(
$this->translate('This set has been inherited from %s'),
Expand Down
Loading

0 comments on commit 35c6086

Please sign in to comment.