summaryrefslogtreecommitdiffstats
path: root/application/controllers/IndexController.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:45:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:45:13 +0000
commita4a4a84d79e95d34f80346c423b4e84f7af3f03d (patch)
tree91608c01e82676102457ffff2219f321ec474657 /application/controllers/IndexController.php
parentInitial commit. (diff)
downloadicingaweb2-module-map-a4a4a84d79e95d34f80346c423b4e84f7af3f03d.tar.xz
icingaweb2-module-map-a4a4a84d79e95d34f80346c423b4e84f7af3f03d.zip
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--application/controllers/IndexController.php93
1 files changed, 93 insertions, 0 deletions
diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php
new file mode 100644
index 0000000..6160c67
--- /dev/null
+++ b/application/controllers/IndexController.php
@@ -0,0 +1,93 @@
+<?php
+
+namespace Icinga\Module\Map\Controllers;
+
+use Icinga\Data\Filter\FilterException;
+use Icinga\Web\Controller\ModuleActionController;
+
+class IndexController extends ModuleActionController
+{
+ public function indexAction()
+ {
+ $config = $this->Config();
+ $map = null;
+ $mapConfig = null;
+
+ // try to load stored map
+ if ($this->params->has("load")) {
+ $map = $this->params->get("load");
+
+ if (!preg_match("/^[\w]+$/", $map)) {
+ throw new FilterException("Invalid character in map name. Allow characters: a-zA-Z0-9_");
+ }
+
+ $mapConfig = $this->Config("maps");
+ if (!$mapConfig->hasSection($map)) {
+ throw new FilterException("Could not find stored map with name = " . $map);
+ }
+ }
+
+ $this->view->id = uniqid();
+ $this->view->host = $this->params->get("showHost");
+ $this->view->expand = $this->params->get("expand");
+ $this->view->fullscreen = ($this->params->get("showFullscreen") == 1);
+
+ $parameterDefaults = array(
+ "default_zoom" => "4",
+ "default_long" => '13.377485',
+ "default_lat" => '52.515855',
+ "min_zoom" => "2",
+ "max_zoom" => "19",
+ "max_native_zoom" => "19",
+ "disable_cluster_at_zoom" => null, // should be by default: max_zoom - 1
+ "cluster_problem_count" => 0,
+ "tile_url" => "//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
+ );
+
+ /*
+ * 1. url
+ * 2. stored map
+ * 3. user config
+ * 4. config
+ */
+ $userPreferences = $this->Auth()->getUser()->getPreferences();
+ if ($userPreferences->has("map")) {
+ $config->getSection("map")->merge($userPreferences->get("map"));
+ }
+
+ foreach ($parameterDefaults as $parameter => $default) {
+ if ($this->params->has($parameter)) {
+ $this->view->$parameter = $this->params->get($parameter);
+ } elseif (isset($map) && $mapConfig->getSection($map)->offsetExists($parameter)) {
+ $this->view->$parameter = $mapConfig->get($map, $parameter);
+ } else {
+ $this->view->$parameter = $config->get("map", $parameter, $default);
+ }
+ }
+
+ if (!$this->view->disable_cluster_at_zoom) {
+ $this->view->disable_cluster_at_zoom = $this->view->max_zoom - 1;
+ }
+
+ $pattern = "/^([_]{0,1}(host|service))|\(|(object|state)Type/";
+ $urlParameters = $this->filterArray($this->getAllParams(), $pattern);
+
+ if (isset($map)) {
+ $mapParameters = $this->filterArray($mapConfig->getSection($map)->toArray(), $pattern);
+ $urlParameters = array_merge($mapParameters, $urlParameters);
+ }
+
+ array_walk($urlParameters, function (&$a, $b) {
+ $a = $b . "=" . $a;
+ });
+ $this->view->url_parameters = join('&', $urlParameters);
+
+ $this->view->dashletHeight = $config->get('map', 'dashlet_height', '300');
+ }
+
+ function filterArray($array, $pattern)
+ {
+ $matches = preg_grep($pattern, array_keys($array));
+ return array_intersect_key($array, array_flip($matches));
+ }
+}