r1487 + initial code for deleting/editing real servers in a pool
authorDenis Ovsienko <infrastation@yandex.ru>
Fri, 11 Jan 2008 14:53:55 +0000 (14:53 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Fri, 11 Jan 2008 14:53:55 +0000 (14:53 +0000)
inc/database.php
inc/interface.php
inc/navigation.php
inc/ophandlers.php

index c70b3dc71e892bfab9eaf1548ffe9d714ab0df7d..f037006af8b455c4e00995b0e287b9d3d050b126 100644 (file)
@@ -2133,4 +2133,37 @@ function addRStoRSPool ($pool_id = 0, $rsip = '', $rsport = 0, $rsconfig = '')
        );
 }
 
+function commitDeleteRS ($id = 0)
+{
+       if ($id <= 0)
+               return FALSE;
+       return useDeleteBlade ('IPRealServer', 'id', $id);
+}
+
+function commitUpdateRS ($rsid = 0, $rsip = '', $rsport = 0, $rsconfig = '')
+{
+       if ($rsid <= 0 or $rsport <= 0)
+       {
+               showError ('Invalid args', __FUNCTION__);
+               die;
+       }
+       if (long2ip (ip2long ($rsip)) !== $rsip)
+       {
+               showError ("Invalid IP address '${rsip}'", __FUNCTION__);
+               die;
+       }
+       global $dbxlink;
+       $query =
+               "update IPRealServer set rsip = inet_aton('${rsip}'), rsport = ${rsport}, rsconfig = " .
+               (empty ($rsconfig) ? 'NULL' : "'#{rsconfig}'") .
+               " where id = ${rsid} limit 1";
+       $result = $dbxlink->query ($query);
+       if ($result == NULL)
+       {
+               showError ("SQL query '${query}' failed", __FUNCTION__);
+               die;
+       }
+       return TRUE;
+}
+
 ?>
index 9d221a1f0fddb141d64e9f315240965d6be4ce42..5e515d89511e2d0b1d1fef1fda9b60ae5e700bb2 100644 (file)
@@ -3737,22 +3737,28 @@ function renderRSPoolServerForm ($pool_id = 0)
        echo "<td><input type=submit value='OK' tabindex=3></tr>\n";
        echo "<tr><th colspan=3>configuration</th></tr>";
        echo "<tr><td colspan=3><textarea name=rsconfig rows=10 cols=80 tabindex=4></textarea></td></tr>";
-       echo "</table>\n";
+       echo "</form></table>\n";
        finishPortlet();
 
        echo "<center><h2>Manage Existing</h2></center>\n";
        echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
-       echo "<tr><th>&nbsp;</th><th>Address</th><th>Port</th><th>configuration</th></tr>\n";
+       echo "<tr><th>&nbsp;</th><th>Address</th><th>Port</th><th>configuration</th><th>&nbsp;</th></tr>\n";
        foreach ($poolInfo['rslist'] as $rsid => $rs)
        {
-               echo "<tr><td><a href='${root}process.php?op=delRealServer&page=${pageno}&tab=${tabno}&rsid=${rsid}'>";
+               echo "<form action='${root}process.php'>";
+               echo "<input type=hidden name=page value='${pageno}'>\n";
+               echo "<input type=hidden name=tab value='${tabno}'>\n";
+               echo "<input type=hidden name=op value=updRS>";
+               echo "<input type=hidden name=id value='${rsid}'>";
+               echo "<input type=hidden name=pool_id value='${pool_id}'>";
+               echo "<tr valign=top><td><a href='${root}process.php?page=${pageno}&tab=${tabno}";
+               echo "&op=delRS&pool_id=${pool_id}&id=${rsid}'>";
                printImageHREF ('delete', 'Delete this real server');
-               echo "</td><td>${rs['rsip']}</td><td>${rs['rsport']}</td><td>";
-               if (empty ($rs['rsconfig']))
-                       echo '&nbsp;';
-               else
-                       echo "<pre>${rs['rsconfig']}</pre>";
-               echo "</td></tr>\n";
+               echo "</td><td><input type=text name=rsip value='${rs['rsip']}'></td>";
+               echo "<td><input type=text name=rsport value='${rs['rsport']}'></td>";
+               echo "<td><textarea name=rsconfig>${rs['rsconfig']}</textarea></td>";
+               echo "<td><input type=submit value='OK'></td>";
+               echo "</tr></form>\n";
        }
        echo "</table>\n";
 }
index b603fd8107bef2344c991f93a1d77fb4656bb2ef..7a5e69ce0f03b7bf42681b1609bbef026be8ac2e 100644 (file)
@@ -170,6 +170,8 @@ $tab['rspool']['editlb'] = '[Load Balancers]';
 $tabhandler['rspool']['default'] = 'renderRSPool';
 $tabhandler['rspool']['editrslist'] = 'renderRSPoolServerForm';
 $ophandler['rspool']['editrslist']['addRS'] = 'addRealServer';
+$ophandler['rspool']['editrslist']['delRS'] = 'deleteRealServer';
+$ophandler['rspool']['editrslist']['updRS'] = 'updateRealServer';
 
 $page['search']['title_handler'] = 'dynamic_title_search';
 $page['search']['handler'] = 'handler_search';
index d8f3ee8b1e64dc06f48ab51859cb94ed2f1612e0..e210ca1b56b5e49d2ae6848a872f695ee92fc60e 100644 (file)
@@ -974,7 +974,41 @@ function addRealServer ()
        if (!addRStoRSPool ($pool_id, $rsip, $rsport, $rsconfig))
                return "${root}?page=${pageno}&tab=${tabno}&id=$pool_id&error=" . urlencode ('addRStoRSPool() failed');
        else
-               return "${root}?page=${pageno}&tab=${tabno}&id=$pool_id&message=" . urlencode ("Real server successfully added");
+               return "${root}?page=${pageno}&tab=${tabno}&id=$pool_id&message=" . urlencode ("Real server was successfully added");
+}
+
+function deleteRealServer ()
+{
+       global $root, $pageno, $tabno;
+
+       assertUIntArg ('pool_id');
+       assertUIntArg ('id');
+       $rsid = $_REQUEST['id'];
+       $pool_id = $_REQUEST['pool_id'];
+       if (!commitDeleteRS ($rsid))
+               return "${root}?page=${pageno}&tab=${tabno}&id=$pool_id&error=" . urlencode ('commitDeleteRS() failed');
+       else
+               return "${root}?page=${pageno}&tab=${tabno}&id=$pool_id&message=" . urlencode ("Real server was successfully deleted");
+}
+
+function updateRealServer ()
+{
+       global $root, $pageno, $tabno;
+
+       assertUIntArg ('id');
+       assertUIntArg ('pool_id');
+       assertStringArg ('rsip');
+       assertUIntArg ('rsport');
+       assertStringArg ('rsconfig', TRUE);
+       $pool_id = $_REQUEST['pool_id'];
+       $rsid = $_REQUEST['id'];
+       $rsip = $_REQUEST['rsip'];
+       $rsport = $_REQUEST['rsport'];
+       $rsconfig = $_REQUEST['rsconfig'];
+       if (!commitUpdateRS ($rsid, $rsip, $rsport, $rsconfig))
+               return "${root}?page=${pageno}&tab=${tabno}&id=$pool_id&error=" . urlencode ('commitUpdateRS() failed');
+       else
+               return "${root}?page=${pageno}&tab=${tabno}&id=$pool_id&message=" . urlencode ("Real server was successfully updated");
 }
 
 ?>