r2122 - remove last reference to getObjectAddresses()
authorDenis Ovsienko <infrastation@yandex.ru>
Sat, 9 Aug 2008 20:53:35 +0000 (20:53 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Sat, 9 Aug 2008 20:53:35 +0000 (20:53 +0000)
 - fix bug in niftyString()
 - rework NATv4 rendering (yet some bugs left to fix)

inc/database.php
inc/interface.php

index 9690b36c8302a50395f9042e1807dd1fb93539ef..02ed917b2e39e7002f8dd5d8801424190103ff6c 100644 (file)
@@ -894,6 +894,9 @@ function unlinkPort ($port)
        return '';
 }
 
+// Return all IPv4 addresses allocated to the objects. Attach detailed
+// info about address to each alocation records. Index result by dotted-quad
+// address.
 function getObjectIPv4Allocations ($object_id = 0)
 {
        $ret = array();
@@ -910,73 +913,6 @@ function getObjectIPv4Allocations ($object_id = 0)
        return $ret;
 }
 
-// Return a list of IPv4 allocations for the object. Each address will list
-// all other objects, to which it is allocated (except the current object).
-function getObjectAddresses ($object_id = 0)
-{
-       if ($object_id == 0)
-       {
-               showError ('Invalid object_id', __FUNCTION__);
-               return;
-       }
-       $query =
-               "select ".
-               "IPAddress.name as IPAddress_name, ".
-               "IPAddress.reserved as IPAddress_reserved, ".
-               "IPBonds.name as IPBonds_name, ".
-               "INET_NTOA(IPBonds.ip) as IPBonds_ip, ".
-               "IPBonds.type as IPBonds_type, ".
-               "RemoteBonds.name as RemoteBonds_name, ".
-               "RemoteBonds.type as RemoteBonds_type, ".
-               "RemoteBonds.object_id as RemoteBonds_object_id ".
-               "from IPBonds " .
-               "left join IPBonds as RemoteBonds on IPBonds.ip=RemoteBonds.ip " .
-                       "and IPBonds.object_id!=RemoteBonds.object_id " .
-               "left join IPAddress on IPBonds.ip=IPAddress.ip " .
-               "where ".
-               "IPBonds.object_id = ${object_id} ".
-               "order by IPBonds.ip, RemoteBonds.object_id";
-       $result = useSelectBlade ($query, __FUNCTION__);
-       $ret=array();
-       $count=0;
-       $refcount=0;
-       $prev_ip = 0;
-       // Free the DB connection to enable subqueries.
-       $rows = $result->fetchAll (PDO::FETCH_ASSOC);
-       $result->closeCursor();
-       foreach ($rows as $row)
-       {
-               if ($prev_ip != $row['IPBonds_ip'])
-               {
-                       $count++;
-                       $refcount=0;
-                       $prev_ip = $row['IPBonds_ip'];
-                       $ret[$count]['address_name'] = $row['IPAddress_name'];
-                       $ret[$count]['address_reserved'] = $row['IPAddress_reserved'];
-                       $ret[$count]['ip'] = $row['IPBonds_ip'];
-                       $ret[$count]['name'] = $row['IPBonds_name'];
-                       $ret[$count]['type'] = $row['IPBonds_type'];
-                       $ret[$count]['references'] = array();
-               }
-
-               if ($row['RemoteBonds_type'])
-               {
-                       $ret[$count]['references'][$refcount]['type'] = $row['RemoteBonds_type'];
-                       $ret[$count]['references'][$refcount]['name'] = $row['RemoteBonds_name'];
-                       $ret[$count]['references'][$refcount]['object_id'] = $row['RemoteBonds_object_id'];
-                       if (empty ($row['RemoteBonds_object_id']))
-                               $ret[$count]['references'][$refcount]['object_name'] = '';
-                       else
-                       {
-                               $oi = getObjectInfo ($row['RemoteBonds_object_id']);
-                               $ret[$count]['references'][$refcount]['object_name'] = displayedName ($oi);
-                       }
-                       $refcount++;
-               }
-       }
-       return $ret;
-}
-
 // Return minimal IPv4 address, optionally with "ip" key set, if requested.
 function constructIPv4Address ($dottedquad = NULL)
 {
index 818cd53f47b157deba7ee6f462ca29ae21dc5ac2..2f86118909359bf897b40da32b878ac24009e391 100644 (file)
@@ -845,7 +845,7 @@ function renderRackObject ($object_id = 0)
                        echo "</td><td class='${secondclass} description'>$address_name</td>";
                        echo "<td class='${secondclass}'>\n";
                        $prefix = '';
-                       if ($addr['reserved'] == 'yes')
+                       if ($alloc['addrinfo']['reserved'] == 'yes')
                        {
                                echo $prefix . '<strong>RESERVED</strong>';
                                $prefix = '; ';
@@ -881,17 +881,15 @@ function renderRackObject ($object_id = 0)
 
                        foreach ($forwards['out'] as $pf)
                        {
-                               $class='trerror';
-                               $name='';
-                               foreach ($addresses as $addr)
-                                       if ($addr['ip'] == $pf['localip'])
-                                       {
-                                               $class='';
-                                               $name=$addr['name'];
-                                               break;
-                                       }
+                               $class = 'trerror';
+                               $osif = '';
+                               if (isset ($alloclist [$pf['localip']]))
+                               {
+                                       $class = $alloclist [$pf['localip']]['addrinfo']['class'];
+                                       $osif = $alloclist [$pf['localip']]['osif'] . ': ';
+                               }
                                echo "<tr class='$class'>";
-                               echo "<td>${pf['proto']}</td><td class=tdleft>${name}: <a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}</td>";
+                               echo "<td>${pf['proto']}</td><td class=tdleft>${osif}<a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}</td>";
                                echo "<td class=tdleft><a href='${root}?page=ipaddress&tab=default&ip=${pf['remoteip']}'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
                                $address = getIPv4Address ($pf['remoteip']);
                                echo "<td class='description'>";
@@ -2489,15 +2487,13 @@ function renderIPv4AddressAllocations ($dottedquad)
 
 }
 
-// FIXME: use allocation list, get rid of getObjectAddresses()
 function renderNATv4ForObject ($object_id = 0)
 {
        global $pageno, $tabno, $root;
        
        $info = getObjectInfo ($object_id);
        $forwards = getNATv4ForObject ($object_id);
-       $addresses = getObjectAddresses ($object_id);
-//     $alloclist = getObjectIPv4Allocations ($object_id);
+       $alloclist = getObjectIPv4Allocations ($object_id);
        showMessageOrError();
        echo "<center><h2>locally performed NAT</h2></center>";
 
@@ -2506,21 +2502,19 @@ function renderNATv4ForObject ($object_id = 0)
 
        foreach ($forwards['out'] as $pf)
        {
-               $class='trerror';
-               $name='';
-               foreach ($addresses as $addr)
-                       if ($addr['ip'] == $pf['localip'])
-                       {
-                               $class='';
-                               $name = $addr['name'];
-                               break;
-                       }
+               $class = 'trerror';
+               $osif = '';
+               if (isset ($alloclist [$pf['localip']]))
+               {
+                       $class = $alloclist [$pf['localip']]['addrinfo']['class'];
+                       $osif = $alloclist [$pf['localip']]['osif'] . ': ';
+               }
 
                echo "<tr class='$class'>";
                echo "<td><a href='${root}process.php?op=delNATv4Rule&localip=${pf['localip']}&localport=${pf['localport']}&remoteip=${pf['remoteip']}&remoteport=${pf['remoteport']}&proto=${pf['proto']}&object_id=$object_id&page=${pageno}&tab=${tabno}'>";
                printImageHREF ('delete', 'Delete NAT rule');
                echo "</a></td>";
-               echo "<td>${pf['proto']}/${name}: <a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}";
+               echo "<td>${pf['proto']}/${osif}<a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}";
                if (!empty ($pf['local_addr_name']))
                        echo ' (' . $pf['local_addr_name'] . ')';
                echo "</td>";
@@ -2558,9 +2552,12 @@ function renderNATv4ForObject ($object_id = 0)
        printSelect (array ('TCP' => 'TCP', 'UDP' => 'UDP'), 'proto');
        echo "<select name='localip' tabindex=1>";
 
-       foreach ($addresses as $addr)
-               echo "<option value='${addr['ip']}'>" . (empty ($addr['name']) ? '' : "${addr['name']}: ") .
-                       "${addr['ip']}" . (empty ($addr['address_name']) ? '' : " (${addr['address_name']})") . "</option>";
+       foreach ($alloclist as $dottedquad => $alloc)
+       {
+               $name = empty ($alloc['addrinfo']['name']) ? '' : (' (' . niftyString ($alloc['addrinfo']['name']) . ')');
+               $osif = empty ($alloc['osif']) ? '' : ($alloc['osif'] . ': ');
+               echo "<option value='${dottedquad}'>${osif}${dottedquad}${name}</option>";
+       }
 
        echo "</select>:<input type='text' name='localport' size='4' tabindex=2></td>";
        echo "<td><input type='text' name='remoteip' id='remoteip' size='10' tabindex=3>";
@@ -5061,6 +5058,7 @@ function niftyString ($string, $maxlen = 20)
                return '&nbsp;';
        if (strlen ($string) > $maxlen)
                return substr ($string, 0, $maxlen - 3) . $cutind;
+       return $string;
 }
 
 ?>