Skip to content

Commit

Permalink
A.F....... [ZBXNEXT-6945] implemented configuration for geographival …
Browse files Browse the repository at this point in the history
…maps
  • Loading branch information
Miks Kronkalns committed Oct 8, 2021
1 parent 6e07904 commit 7e6a911
Show file tree
Hide file tree
Showing 16 changed files with 521 additions and 8 deletions.
4 changes: 2 additions & 2 deletions create/src/data.tmpl
Expand Up @@ -879,8 +879,8 @@ ROW |7 |5 |23 |0 |2 | |
ROW |8 |6 |23 |0 |4 | |

TABLE |config
FIELDS|configid|work_period |alert_usrgrpid|discovery_groupid|
ROW |1 |1-5,09:00-18:00|7 |5 |
FIELDS|configid|work_period |alert_usrgrpid|discovery_groupid|geomaps_tile_provider|
ROW |1 |1-5,09:00-18:00|7 |5 |OpenStreetMap.Mapnik |

TABLE |graph_theme
FIELDS|graphthemeid|theme |backgroundcolor|graphcolor|gridcolor|maingridcolor|gridbordercolor|textcolor|highlightcolor|leftpercentilecolor|rightpercentilecolor|nonworktimecolor|colorpalette |
Expand Down
6 changes: 5 additions & 1 deletion create/src/schema.tmpl
Expand Up @@ -587,6 +587,10 @@ FIELD |hk_events_service|t_varchar(32)|'1d' |NOT NULL |ZBX_NODATA
FIELD |passwd_min_length |t_integer |'8' |NOT NULL |ZBX_NODATA
FIELD |passwd_check_rules |t_integer |'8' |NOT NULL |ZBX_NODATA
FIELD |auditlog_enabled |t_integer |'1' |NOT NULL |ZBX_NODATA
FIELD |geomaps_tile_provider|t_varchar(255) |'' |NOT NULL |ZBX_NODATA
FIELD |geomaps_tile_url |t_varchar(1024)|'' |NOT NULL |ZBX_NODATA
FIELD |geomaps_max_zoom |t_integer |'0' |NOT NULL |ZBX_NODATA
FIELD |geomaps_attribution|t_varchar(1024)|'' |NOT NULL |ZBX_NODATA
INDEX |1 |alert_usrgrpid
INDEX |2 |discovery_groupid

Expand Down Expand Up @@ -1891,4 +1895,4 @@ INDEX |1 |serviceid
TABLE|dbversion||
FIELD |mandatory |t_integer |'0' |NOT NULL |
FIELD |optional |t_integer |'0' |NOT NULL |
ROW |5050072 |5050072
ROW |5050077 |5050077
44 changes: 44 additions & 0 deletions src/libs/zbxdbupgrade/dbupgrade_5050.c
Expand Up @@ -816,6 +816,45 @@ static int DBpatch_5050072(void)
return DBmodify_field_type("media_type_message", &field, &old_field);
}

static int DBpatch_5050073(void)
{
const ZBX_FIELD field = {"geomaps_tile_provider", "", NULL, NULL, 255, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};

return DBadd_field("config", &field);
}

static int DBpatch_5050074(void)
{
const ZBX_FIELD field = {"geomaps_tile_url", "", NULL, NULL, 1024, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};

return DBadd_field("config", &field);
}

static int DBpatch_5050075(void)
{
const ZBX_FIELD field = {"geomaps_max_zoom", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};

return DBadd_field("config", &field);
}

static int DBpatch_5050076(void)
{
const ZBX_FIELD field = {"geomaps_attribution", "", NULL, NULL, 1024, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};

return DBadd_field("config", &field);
}

static int DBpatch_5050077(void)
{
if (0 == (program_type & ZBX_PROGRAM_TYPE_SERVER))
return SUCCEED;

if (ZBX_DB_OK > DBexecute("update config set geomaps_tile_provider='OpenStreetMap.Mapnik'"))
return FAIL;

return SUCCEED;
}

#endif

DBPATCH_START(5050)
Expand Down Expand Up @@ -889,5 +928,10 @@ DBPATCH_ADD(5050069, 0, 1)
DBPATCH_ADD(5050070, 0, 1)
DBPATCH_ADD(5050071, 0, 1)
DBPATCH_ADD(5050072, 0, 1)
DBPATCH_ADD(5050073, 0, 1)
DBPATCH_ADD(5050074, 0, 1)
DBPATCH_ADD(5050075, 0, 1)
DBPATCH_ADD(5050076, 0, 1)
DBPATCH_ADD(5050077, 0, 1)

DBPATCH_END()
78 changes: 78 additions & 0 deletions ui/app/controllers/CControllerGeomapsEdit.php
@@ -0,0 +1,78 @@
<?php declare(strict_types = 1);
/*
** Zabbix
** Copyright (C) 2001-2021 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/


/**
* Edit view controller for "Geographical maps" administration screen.
*/
class CControllerGeomapsEdit extends CController {

protected function init(): void {
$this->disableSIDValidation();
}

protected function checkInput(): bool {
$fields = [
'geomaps_tile_provider' => 'db config.geomaps_tile_provider',
'geomaps_tile_url' => 'db config.geomaps_tile_url',
'geomaps_max_zoom' => 'db config.geomaps_max_zoom',
'geomaps_attribution' => 'db config.geomaps_attribution'
];

$ret = $this->validateInput($fields);

if (!$ret) {
$this->setResponse(new CControllerResponseFatal());
}

return $ret;
}

protected function checkPermissions(): bool {
return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL);
}

protected function doAction(): void {
$data = [
'geomaps_tile_provider' => $this->getInput('geomaps_tile_provider', CSettingsHelper::get(
CSettingsHelper::GEOMAPS_TILE_PROVIDER
)),
'tile_providers' => getTileProviders()
];

$data += (array_key_exists($data['geomaps_tile_provider'], $data['tile_providers']))
? $data['tile_providers'][$data['geomaps_tile_provider']]
: [
'geomaps_tile_url' => $this->getInput('geomaps_tile_url', CSettingsHelper::get(
CSettingsHelper::GEOMAPS_TILE_URL
)),
'geomaps_max_zoom' => $this->getInput('geomaps_max_zoom', CSettingsHelper::get(
CSettingsHelper::GEOMAPS_MAX_ZOOM
)),
'geomaps_attribution' => $this->getInput('geomaps_attribution', CSettingsHelper::get(
CSettingsHelper::GEOMAPS_ATTRIBUTION
))
];

$response = new CControllerResponseData($data);
$response->setTitle(_('Geographical maps'));
$this->setResponse($response);
}
}
98 changes: 98 additions & 0 deletions ui/app/controllers/CControllerGeomapsUpdate.php
@@ -0,0 +1,98 @@
<?php declare(strict_types = 1);
/*
** Zabbix
** Copyright (C) 2001-2021 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/


/**
* Update controller for "Geographical maps" administration screen.
*/
class CControllerGeomapsUpdate extends CController {

protected function init(): void {
$this->disableSIDValidation();
}

protected function checkInput(): bool {
$fields = [
'geomaps_tile_provider' => 'required|db config.geomaps_tile_provider',
'geomaps_tile_url' => 'required|db config.geomaps_tile_url|not_empty',
'geomaps_max_zoom' => 'required|db config.geomaps_max_zoom',
'geomaps_attribution' => 'db config.geomaps_attribution'
];

$ret = $this->validateInput($fields);

if (!$ret) {
switch ($this->GetValidationError()) {
case self::VALIDATION_ERROR:
$response = new CControllerResponseRedirect(
(new CUrl('zabbix.php'))
->setArgument('action', 'geomaps.edit')
->getUrl()
);

$response->setFormData(array_filter($this->getInputAll()) + [
'geomaps_tile_provider' => '',
'geomaps_tile_url' => '',
'geomaps_max_zoom' => 0
]);
CMessageHelper::setErrorTitle(_('Cannot update configuration'));
$this->setResponse($response);
break;

case self::VALIDATION_FATAL_ERROR:
$this->setResponse(new CControllerResponseFatal());
break;
}
}

return $ret;
}

protected function checkPermissions(): bool {
return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL);
}

protected function doAction(): void {
$settings = [
CSettingsHelper::GEOMAPS_TILE_PROVIDER => $this->getInput('geomaps_tile_provider'),
CSettingsHelper::GEOMAPS_TILE_URL => $this->getInput('geomaps_tile_url'),
CSettingsHelper::GEOMAPS_MAX_ZOOM => $this->getInput('geomaps_max_zoom'),
CSettingsHelper::GEOMAPS_ATTRIBUTION => $this->getInput('geomaps_attribution', '')
];

$result = API::Settings()->update($settings);

$response = new CControllerResponseRedirect(
(new CUrl('zabbix.php'))
->setArgument('action', 'geomaps.edit')
->getUrl()
);

if ($result) {
CMessageHelper::setSuccessTitle(_('Configuration updated'));
}
else {
$response->setFormData($this->getInputAll());
CMessageHelper::setErrorTitle(_('Cannot update configuration'));
}

$this->setResponse($response);
}
}
2 changes: 1 addition & 1 deletion ui/app/controllers/CControllerGuiUpdate.php
Expand Up @@ -68,7 +68,7 @@ protected function checkPermissions() {
}

protected function doAction() {
$settings = [
$settings = [
CSettingsHelper::DEFAULT_THEME => $this->getInput('default_theme'),
CSettingsHelper::DEFAULT_TIMEZONE => $this->getInput('default_timezone'),
CSettingsHelper::SEARCH_LIMIT => $this->getInput('search_limit'),
Expand Down

0 comments on commit 7e6a911

Please sign in to comment.