r4035 Ability to search for IP networks by vlan id
authorAlexey Andriyanov <alan@al-an.info>
Tue, 30 Nov 2010 16:27:32 +0000 (16:27 +0000)
committerAlexey Andriyanov <alan@al-an.info>
Tue, 30 Nov 2010 16:27:32 +0000 (16:27 +0000)
inc/interface.php:
 renderSearchResults: special template for vlan searching only, not by descriptions of all realms

inc/database.php:
 getVLANSearchResult: vlans are searched by description only if query does not look like VID

ChangeLog
inc/database.php
inc/interface.php

index a4addbc..72b4e8a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,7 @@
        update: enhance rackspace click helpers (by Jeroen Benda)
        bugfix: the feature of remembering last opened tab of realm page is now working
        update: UI: ports/IPs/nets highlighting enhancements
+       update: ability to search for IP networks by vlan id
 0.18.7
        bugfix: adjust 802.1Q command generation
        bugfix: fixed telnet session hanging in NX-OS4 connector
index 4743aa8..62e5f1f 100644 (file)
@@ -1704,7 +1704,7 @@ function getVLANSearchResult ($terms)
 {
        $ret = array();
        $matches = array();
-       if (preg_match ('/^vlan([[:digit:]]+)$/i', $terms, $matches))
+       if (preg_match ('/^vlan\s*(\d+)$/i', $terms, $matches))
        {
                $byID = getSearchResultByField
                (
@@ -1718,18 +1718,21 @@ function getVLANSearchResult ($terms)
                foreach ($byID as $row)
                        $ret[] = $row['domain_id'] . '-' . $row['vlan_id'];
        }
-       $byDescr = getSearchResultByField
-       (
-               'VLANDescription',
-               array ('domain_id', 'vlan_id'),
-               'vlan_descr',
-               $terms
-       );
-       foreach ($byDescr as $row)
+       else
        {
-               $vlan_ck = $row['domain_id'] . '-' . $row['vlan_id'];
-               if (!in_array ($vlan_ck, $ret))
-                       $ret[] = $vlan_ck;
+               $byDescr = getSearchResultByField
+               (
+                       'VLANDescription',
+                       array ('domain_id', 'vlan_id'),
+                       'vlan_descr',
+                       $terms
+               );
+               foreach ($byDescr as $row)
+               {
+                       $vlan_ck = $row['domain_id'] . '-' . $row['vlan_id'];
+                       if (!in_array ($vlan_ck, $ret))
+                               $ret[] = $vlan_ck;
+               }
        }
        return $ret;
 }
index 99f6357..2d778e0 100644 (file)
@@ -3672,6 +3672,31 @@ function renderSearchResults ()
                        $summary['ipv6network'][] = spotEntity ('ipv6net', $tmp);
                }
        }
+       elseif (preg_match ('@^vlan\s*(\d+)$@', $terms, $matches))
+       {
+               $tmp = getVLANSearchResult ($terms);
+               if (count ($tmp))
+               {
+                       $nhits += count ($tmp);
+                       $lasthit = 'vlan';
+                       $summary['vlan'] = $tmp;
+       
+                       // find IP networks connected to vlan
+                       foreach ($tmp as $vlan_ck)
+                       {
+                               $vlan_info = getVLANInfo ($vlan_ck);
+                               foreach (array (4, 6) as $ipv)
+                                       foreach ($vlan_info["ipv${ipv}nets"] as $net_id)
+                                       {
+                                               ++$nhits;
+                                               $lasthit = "ipv${ipv}network";
+                                               if (! isset ($summary["ipv${ipv}network"]))
+                                                       $summary["ipv${ipv}network"] = array();
+                                               $summary["ipv${ipv}network"][] = spotEntity ("ipv${ipv}net", $net_id);
+                                       }
+                       }
+               }
+       }
        else
        // Search for objects, addresses, networks, virtual services and RS pools by their description.
        {