summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:26:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:26:02 +0000
commitfcbf3ce37ca8f90a3e36d524a3274ffc063a40e3 (patch)
tree84c735df2e97350a721273e9dd425729d43cc8a2 /application
parentInitial commit. (diff)
downloadicingaweb2-module-pdfexport-fcbf3ce37ca8f90a3e36d524a3274ffc063a40e3.tar.xz
icingaweb2-module-pdfexport-fcbf3ce37ca8f90a3e36d524a3274ffc063a40e3.zip
Adding upstream version 0.10.2+dfsg1.upstream/0.10.2+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application')
-rw-r--r--application/controllers/ConfigController.php30
-rw-r--r--application/forms/ChromeBinaryForm.php94
-rw-r--r--application/views/scripts/config/chrome.phtml6
3 files changed, 130 insertions, 0 deletions
diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php
new file mode 100644
index 0000000..7b5130b
--- /dev/null
+++ b/application/controllers/ConfigController.php
@@ -0,0 +1,30 @@
+<?php
+
+/* Icinga PDF Export | (c) 2019 Icinga GmbH | GPLv2 */
+
+namespace Icinga\Module\Pdfexport\Controllers;
+
+use Icinga\Application\Config;
+use Icinga\Module\Pdfexport\Forms\ChromeBinaryForm;
+use Icinga\Web\Controller;
+
+class ConfigController extends Controller
+{
+ public function init()
+ {
+ $this->assertPermission('config/modules');
+
+ parent::init();
+ }
+
+ public function chromeAction()
+ {
+ $form = (new ChromeBinaryForm())
+ ->setIniConfig(Config::module('pdfexport'));
+
+ $form->handleRequest();
+
+ $this->view->tabs = $this->Module()->getConfigTabs()->activate('chrome');
+ $this->view->form = $form;
+ }
+}
diff --git a/application/forms/ChromeBinaryForm.php b/application/forms/ChromeBinaryForm.php
new file mode 100644
index 0000000..c72d933
--- /dev/null
+++ b/application/forms/ChromeBinaryForm.php
@@ -0,0 +1,94 @@
+<?php
+
+/* Icinga PDF Export | (c) 2019 Icinga GmbH | GPLv2 */
+
+namespace Icinga\Module\Pdfexport\Forms;
+
+use Exception;
+use Icinga\Forms\ConfigForm;
+use Icinga\Module\Pdfexport\HeadlessChrome;
+use Zend_Validate_Callback;
+
+class ChromeBinaryForm extends ConfigForm
+{
+ public function init()
+ {
+ $this->setName('pdfexport_binary');
+ $this->setSubmitLabel($this->translate('Save Changes'));
+ }
+
+ public function createElements(array $formData)
+ {
+ $this->addElement('text', 'chrome_binary', [
+ 'label' => $this->translate('Local Binary'),
+ 'placeholder' => '/usr/bin/google-chrome',
+ 'validators' => [new Zend_Validate_Callback(function ($value) {
+ $chrome = (new HeadlessChrome())
+ ->setBinary($value);
+
+ try {
+ $version = $chrome->getVersion();
+ } catch (Exception $e) {
+ $this->getElement('chrome_binary')->addError($e->getMessage());
+ return true;
+ }
+
+ if ($version < 59) {
+ $this->getElement('chrome_binary')->addError(sprintf(
+ $this->translate(
+ 'Chrome/Chromium supporting headless mode required'
+ . ' which is provided since version 59. Version detected: %s'
+ ),
+ $version
+ ));
+ }
+
+ return true;
+ })]
+ ]);
+
+ $this->addElement('checkbox', 'chrome_force_temp_storage', [
+ 'label' => $this->translate('Force local temp storage')
+ ]);
+
+ $this->addElement('text', 'chrome_host', [
+ 'label' => $this->translate('Remote Host'),
+ 'validators' => [new Zend_Validate_Callback(function ($value) {
+ if ($value === null) {
+ return true;
+ }
+
+ $port = $this->getValue('chrome_port') ?: 9222;
+
+ $chrome = (new HeadlessChrome())
+ ->setRemote($value, $port);
+
+ try {
+ $version = $chrome->getVersion();
+ } catch (Exception $e) {
+ $this->getElement('chrome_host')->addError($e->getMessage());
+ return true;
+ }
+
+ if ($version < 59) {
+ $this->getElement('chrome_host')->addError(sprintf(
+ $this->translate(
+ 'Chrome/Chromium supporting headless mode required'
+ . ' which is provided since version 59. Version detected: %s'
+ ),
+ $version
+ ));
+ }
+
+ return true;
+ })]
+ ]);
+
+ $this->addElement('number', 'chrome_port', [
+ 'label' => $this->translate('Remote Port'),
+ 'placeholder' => 9222,
+ 'min' => 1,
+ 'max' => 65535
+ ]);
+ }
+}
diff --git a/application/views/scripts/config/chrome.phtml b/application/views/scripts/config/chrome.phtml
new file mode 100644
index 0000000..46daf07
--- /dev/null
+++ b/application/views/scripts/config/chrome.phtml
@@ -0,0 +1,6 @@
+<div class="controls">
+ <?= /** @var \Icinga\Web\Widget\Tabs $tabs */ $tabs ?>
+</div>
+<div class="content">
+ <?= /** @var \Icinga\Module\Pdfexport\Forms\ChromeBinaryForm $form */ $form ?>
+</div>