Module: nagvis
Branch: master
Commit: e2850c5bde8799088b6ac05d72dec6403191385a
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/commit/?id=e2850c5bde8799088b6ac05d72dec6403191385a

Author: Roman Kyrylych <[email protected]>
Date:   Tue Aug 25 11:20:01 2009 +0300

gmap: Added some validation on Link/Location objects on the server side

Signed-off-by: Roman Kyrylych <[email protected]>

---

 share/netmap/LinkService.php     |   12 ++++++++++++
 share/netmap/LocationService.php |   12 ++++++++++++
 share/netmap/Viewpoint.php       |    3 +++
 3 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/share/netmap/LinkService.php b/share/netmap/LinkService.php
index ad4d2f3..6a226c6 100644
--- a/share/netmap/LinkService.php
+++ b/share/netmap/LinkService.php
@@ -23,6 +23,12 @@
 
 class LinkService
 {
+       private function validate($link)
+       {
+               if ($link->id == '' || $link->id1 == '' || $link->id2 == '')
+                       throw new Exception('Attempt to create an invalid 
object of Link class');
+       }
+
        private function updateState(&$link)
        {
                $db = new NagiosService();
@@ -77,6 +83,8 @@ class LinkService
                {
                        $link = Link::fromXML($node);
 
+                       self::validate($link);
+
                        self::updateState($link);
 
                        if (!$problemonly || $link->state != State::OK)
@@ -92,6 +100,8 @@ class LinkService
         */
        public function add($link)
        {
+               self::validate($link);
+
                if (($xml = @simplexml_load_file('links.xml')) === FALSE)
                        throw new Exception('Could not read links.xml');
 
@@ -129,6 +139,8 @@ class LinkService
         */
        public function edit($link)
        {
+               self::validate($link);
+
                if (($xml = @simplexml_load_file('links.xml')) === FALSE)
                        throw new Exception('Could not read links.xml');
 
diff --git a/share/netmap/LocationService.php b/share/netmap/LocationService.php
index decd5a5..112d69a 100644
--- a/share/netmap/LocationService.php
+++ b/share/netmap/LocationService.php
@@ -23,6 +23,12 @@
 
 class LocationService
 {
+       private function validate($location)
+       {
+               if ($location->id == '' || $location->point == '' || 
$location->label == '')
+               throw new Exception('Attempt to create an invalid object of 
Location class');
+       }
+
        private function updateState(&$location)
        {
                $db = new NagiosService();
@@ -77,6 +83,8 @@ class LocationService
                {
                        $location = Location::fromXML($node);
 
+                       self::validate($location);
+
                        self::updateState($location);
 
                        if (!$problemonly || $location->state != State::OK)
@@ -92,6 +100,8 @@ class LocationService
         */
        public function add($location)
        {
+               self::validate($location);
+
                if (($xml = @simplexml_load_file('locations.xml')) === FALSE)
                        throw new Exception('Could not read locations.xml');
 
@@ -129,6 +139,8 @@ class LocationService
         */
        public function edit($location)
        {
+               self::validate($location);
+
                if (($xml = @simplexml_load_file('locations.xml')) === FALSE)
                        throw new Exception('Could not read locations.xml');
 
diff --git a/share/netmap/Viewpoint.php b/share/netmap/Viewpoint.php
index 78ff562..d09af25 100644
--- a/share/netmap/Viewpoint.php
+++ b/share/netmap/Viewpoint.php
@@ -29,6 +29,9 @@ class Viewpoint
 
        public function __construct($label = "", $center = "", $zoom = 0)
        {
+               if ($label == '')
+                       throw new Exception('Attempt to create an invalid 
object of Viewpoint class');
+
                $this->label = $label;
                $this->center = $center;
                $this->zoom = $zoom;


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to