Author: Lars Michelsen <[email protected]>
Date: Thu Jun 14 13:57:54 2012 +0200
Committer: Lars Michelsen <[email protected]>
Commit-Date: Thu Jun 14 13:57:54 2012 +0200
Bugfix: Map configs can be edited using the GUI even in case of source errors
---
ChangeLog | 1 +
share/server/core/classes/CoreExceptions.php | 2 +
share/server/core/classes/CoreModMap.php | 1 +
share/server/core/classes/GlobalMapCfg.php | 14 +++++++++-
share/server/core/classes/WuiViewMapAddModify.php | 1 +
share/server/core/sources/geomap.php | 28 ++++++++++++--------
6 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b1f30d4..1f16b0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
Core
* Bugfix: Better catching of exceptions on nested maps
* Suppressing debug messages in non debug mode
+ * Bugfix: Map configs can be edited using the GUI even in case of source
errors
Frontend
* Added rotations to sidebar
diff --git a/share/server/core/classes/CoreExceptions.php
b/share/server/core/classes/CoreExceptions.php
index 42c5548..4ce860b 100644
--- a/share/server/core/classes/CoreExceptions.php
+++ b/share/server/core/classes/CoreExceptions.php
@@ -82,6 +82,8 @@ class UserInputError extends NagVisException {}
class InputErrorRedirect extends NagVisException {}
+class MapSourceError extends NagVisException {}
+
class FieldInputError extends NagVisException {
function __construct($field, $msg) {
$this->field = $field;
diff --git a/share/server/core/classes/CoreModMap.php
b/share/server/core/classes/CoreModMap.php
index 5db5c7f..689af9a 100644
--- a/share/server/core/classes/CoreModMap.php
+++ b/share/server/core/classes/CoreModMap.php
@@ -351,6 +351,7 @@ class CoreModMap extends CoreModule {
$MAPCFG = new GlobalMapCfg($this->CORE, $map);
try {
+ $MAPCFG->skipSourceErrors();
$MAPCFG->readMapConfig();
} catch(MapCfgInvalid $e) {}
diff --git a/share/server/core/classes/GlobalMapCfg.php
b/share/server/core/classes/GlobalMapCfg.php
index 2ca6044..9adea19 100644
--- a/share/server/core/classes/GlobalMapCfg.php
+++ b/share/server/core/classes/GlobalMapCfg.php
@@ -42,6 +42,8 @@ class GlobalMapCfg {
protected $defaultsCacheFile = '';
protected $mapLockPath;
+ protected $ignoreSourceErrors = false;
+
// Array for config validation
protected static $validConfig = null;
@@ -624,6 +626,10 @@ class GlobalMapCfg {
return false;
}
+ public function skipSourceErrors($flag = true) {
+ $this->ignoreSourceErrors = $flag;
+ }
+
/**
* A source can modify the map configuration before it is used for further
processing.
* Such a source is a key which points to a "process", "params" and
"changed" function
@@ -667,7 +673,13 @@ class GlobalMapCfg {
if(!function_exists($func))
throw new NagVisException(l('Requested source "[S]" does not
exist',
array('S' =>
$source)));
- $func($this, $this->name, $this->mapConfig);
+ try {
+ $func($this, $this->name, $this->mapConfig);
+ } catch(Exception $e) {
+ if(!$this->ignoreSourceErrors) {
+ throw $e;
+ }
+ }
}
// Call process filter implicit if not already done
diff --git a/share/server/core/classes/WuiViewMapAddModify.php
b/share/server/core/classes/WuiViewMapAddModify.php
index 1ff5fab..8a2fd99 100644
--- a/share/server/core/classes/WuiViewMapAddModify.php
+++ b/share/server/core/classes/WuiViewMapAddModify.php
@@ -44,6 +44,7 @@ class WuiViewMapAddModify {
$this->MAPCFG = new GlobalMapCfg($this->CORE, $map);
try {
+ $this->MAPCFG->skipSourceErrors();
$this->MAPCFG->readMapConfig();
} catch(MapCfgInvalid $e) {}
}
diff --git a/share/server/core/sources/geomap.php
b/share/server/core/sources/geomap.php
index 9fb87a8..fdbc7d2 100644
--- a/share/server/core/sources/geomap.php
+++ b/share/server/core/sources/geomap.php
@@ -1,14 +1,16 @@
<?php
+class GeomapError extends MapSourceError {}
+
function geomap_get_locations($p) {
$locations = array();
$f = cfg('paths', 'geomap') . '/' . $p['source_file'] . '.csv';
- if($f == '')
- throw new NagVisException(l('No location source file given. Terminate
rendering geomap.'));
+ if($p['source_file'] == '')
+ throw new GeomapError(l('No location source file given. Terminate
rendering geomap.'));
if(!file_exists($f))
- throw new NagVisException(l('Location source file "[F]" does not
exist.', Array('F' => $f)));
+ throw new GeomapError(l('Location source file "[F]" does not exist.',
Array('F' => $f)));
foreach(file($f) AS $line) {
$parts = explode(';', $line);
@@ -42,7 +44,7 @@ function geomap_get_contents($url) {
return file_get_contents($url, false, $context);
} catch(Exception $e) {
- throw new NagVisException(l('Unable to fetch URL "[U]".<br/><br />The
geomap needs to be able to fetch '
+ throw new GeomapError(l('Unable to fetch URL "[U]".<br/><br />The
geomap needs to be able to fetch '
.'some data from the internet via
webservice API. Please take a look '
.'at the docs for more details.<br /><br
/><small>[E]</small>',
Array('U' => $url, 'E' => $e)));
@@ -123,6 +125,11 @@ function process_geomap($MAPCFG, $map_name, &$map_config) {
$iconset = $params['iconset'];
list($icon_w, $icon_h) = iconset_size($iconset);
+
+ // Adapt the global section
+ $map_config[0] = $saved_config[0];
+ $map_config[0]['map_image'] = $image_name;
+ $map_config[0]['iconset'] = $iconset;
// Now add the objects to the map
foreach($locations AS $loc) {
@@ -143,7 +150,7 @@ function process_geomap($MAPCFG, $map_name, &$map_config) {
// Terminate empty views
if(count($map_config) == 0)
- throw new NagVisException(l('Got empty map after filtering. Terminate
rendering geomap.'));
+ throw new GeomapError(l('Got empty map after filtering. Terminate
rendering geomap.'));
// Now detect the upper and lower bounds of the locations to display
// Left/upper and right/bottom
@@ -154,6 +161,9 @@ function process_geomap($MAPCFG, $map_name, &$map_config) {
$min_long = 180;
$max_long = -180;
foreach($map_config AS $obj) {
+ if($obj['object_id'] == 0)
+ continue;
+
if($obj['lat'] < $min_lat)
$min_lat = $obj['lat'];
if($obj['lat'] > $max_lat)
@@ -208,12 +218,12 @@ function process_geomap($MAPCFG, $map_name, &$map_config)
{
ord($contents[1]) == 80 &&
ord($contents[2]) == 78) {
// Got an png image as answer - catch this!
- throw new NagVisException(l('Got invalid response from "[U]". This
is mostly caused by an unhandled request.',
+ throw new GeomapError(l('Got invalid response from "[U]". This is
mostly caused by an unhandled request.',
array('U' => $data_url)));
}
if(!preg_match('/^-?[0-9]+\.?[0-9]*,-?[0-9]+\.?[0-9]*,-?[0-9]+\.?[0-9]*,-?[0-9]+\.?[0-9]*$/i',
$contents))
- throw new NagVisException(l('Got invalid data from "[U]": "[C]"',
array('U' => $data_url, 'C' => var_dump($contents))));
+ throw new GeomapError(l('Got invalid data from "[U]": "[C]"',
array('U' => $data_url, 'C' => var_dump($contents))));
file_put_contents($data_path, $contents);
$parts = explode(',', $contents);
@@ -231,10 +241,6 @@ function process_geomap($MAPCFG, $map_name, &$map_config) {
$long_para = $params['width'] / $long_diff;
$lat_para = $params['height'] / $lat_diff;
-
- $map_config[0] = $saved_config[0];
- $map_config[0]['map_image'] = $image_name;
- $map_config[0]['iconset'] = $iconset;
// Now add the coordinates to the map objects
foreach($map_config AS &$obj) {
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins