0.16.2
bugfix: IP address picker was broken
bugfix: more message processing fixes
+ new feature: "router" addresses allocations
+ new feature: router configuration exporter
0.16.1 2008-07-30
new feature: pre-assigned tags for new VS and RS pools records
new feature: cache RackCode parse tree for better performance
--- /dev/null
+#!/bin/sh
+
+# This is a RackTables gateway for router configuration export. The configuration
+# is fed in arbitrary format and should only be somehow sent to the remote host
+# for further processing. This is a quick hack and should be replaced with a
+# generic file sender gateway in future.
+#
+# The only supported command is:
+#
+# * submit <username> <endpoint> <filename>: send the file
+#
+
+user=
+endpoint=
+cfgfile=
+MYDIR=`dirname $0`
+
+do_submit()
+{
+ user=`echo $args | cut -s -d' ' -f1`
+ endpoint=`echo $args | cut -s -d' ' -f2`
+ cfgfile=`echo $args | cut -s -d' ' -f3`
+ # sanity checks
+ if [ -z "$user" -o -z "$endpoint" -o -z "$cfgfile" ]; then
+ echo 'ERR!invalid arguments'
+ return
+ fi
+ if [ ! -s "$cfgfile" ]; then
+ echo "ERR!File $cfgfile is either missing or empty."
+ return
+ fi
+ if [ ! -x "$MYDIR/install" ]; then
+ echo "ERR!Cannot execute $MYDIR/install"
+ return
+ fi
+ "$MYDIR/install" $user $endpoint $cfgfile
+ ret=$?
+ if [ $ret = 0 ]; then
+ echo "OK!File sent successfully"
+ else
+ echo "ERR!File installer returned code $ret"
+ fi
+}
+
+# main loop
+while read cmd args; do
+ case $cmd in
+ submit)
+ do_submit $args
+ ;;
+ *)
+ echo "ERR!unknown command $cmd"
+ esac
+done
+
+exit 0
return $newconfig;
}
+function buildRouterConfig ($object_id = 0)
+{
+ if ($object_id <= 0)
+ {
+ showError ('Invalid argument', __FUNCTION__);
+ return;
+ }
+ $newconfig = 'dummy text';
+ return $newconfig;
+}
+
// Indicate occupation state of each IP address: none, ordinary or problematic.
function markupIPv4AddrList (&$addrlist)
{
return $log;
}
+// FIXME: copied and pasted too
+function activateRouterConfig ($object_id = 0, $configtext = '')
+{
+ global $remote_username;
+ if ($object_id <= 0 or empty ($configtext))
+ return oneLiner (160); // invalid arguments
+ $objectInfo = getObjectInfo ($object_id);
+ $endpoints = findAllEndpoints ($object_id, $objectInfo['name']);
+ if (count ($endpoints) == 0)
+ return oneLiner (161); // endpoint not found
+ if (count ($endpoints) > 1)
+ return oneLiner (162); // can't pick an address
+ $hwtype = $swtype = 'unknown';
+ $endpoint = str_replace (' ', '+', $endpoints[0]);
+ $tmpfilename = tempnam ('', 'RackTables-rtrconfig-');
+ $tmpfile = fopen ($tmpfilename, 'wb');
+ fwrite ($tmpfile, str_replace ("\r", '', $configtext));
+ fclose ($tmpfile);
+ $data = queryGateway
+ (
+ 'rtrconfig',
+ array ("submit ${endpoint} ${remote_username} ${tmpfilename}")
+ );
+ unlink ($tmpfilename);
+ if ($data == NULL)
+ return oneLiner (163); // unknown gateway failure
+ if (strpos ($data[0], 'OK!') !== 0)
+ return oneLiner (164, array ($data[0])); // gateway failure
+ if (count ($data) != 2)
+ return oneLiner (165); // protocol violation
+ // Finally we can parse the response into message array.
+ $log = array ('v' => 2);
+ $codemap['ERR'] = 166; // generic gateway error
+ $codemap['OK'] = 62; // generic gateway success
+ list ($code, $text) = split ('!', $data[1]);
+ $log['m'][] = array ('c' => $codemap[$code], 'a' => array ($text));
+ return $log;
+}
+
?>
161 => array ('code' => 'error', 'format' => 'Endpoint not found. Please either set FQDN attribute or assign an IP address to the object.'),
162 => array ('code' => 'error', 'format' => 'More than one IP address is assigned to this object, please configure FQDN attribute.'),
163 => array ('code' => 'error', 'format' => 'Failed to get any response from queryGateway() or the gateway died'),
- 164 => array ('code' => 'error', 'format' => 'Gateway failure: returned code %u.'),
+ 164 => array ('code' => 'error', 'format' => 'Gateway failure: %s.'),
165 => array ('code' => 'error', 'format' => 'Gateway failure: malformed reply.'),
166 => array ('code' => 'error', 'format' => 'gw: %s'),
167 => array ('code' => 'error', 'format' => 'Could not find port %s'),
echo '</pre>';
}
+function renderRouterConfig ($object_id = 0)
+{
+ showMessageOrError();
+ global $root, $pageno, $tabno;
+ if ($object_id <= 0)
+ {
+ showError ('Invalid argument', __FUNCTION__);
+ return;
+ }
+ echo '<br>';
+ echo "<form method=post action='${root}process.php?page=${pageno}&tab=${tabno}&op=submitRouterConfig'>";
+ echo "<input type=hidden name=object_id value=${object_id}>";
+ echo "<center><input type=submit value='Submit for activation'></center>";
+ echo "</form>";
+ echo '<pre>';
+ echo buildRouterConfig ($object_id);
+ echo '</pre>';
+}
+
function renderVirtualService ($vsid)
{
global $root, $nextorder;
$tab['object']['livevlans'] = 'Live VLANs';
$tab['object']['snmpportfinder'] = 'SNMP port finder';
$tab['object']['editrspvs'] = 'RS pools';
-$tab['object']['lvsconfig'] = 'LVS configuration';
+$tab['object']['lvsconfig'] = 'LVS config';
$tab['object']['autoports'] = 'AutoPorts';
$tab['object']['tags'] = 'Tags';
+$tab['object']['rtrconfig'] = 'Router config';
$tabhandler['object']['default'] = 'renderRackObject';
$tabhandler['object']['edit'] = 'renderEditObjectForm';
$tabhandler['object']['rackspace'] = 'renderRackSpaceForObject';
$tabhandler['object']['autoports'] = 'renderAutoPortsForm';
$tabhandler['object']['tags'] = 'renderObjectTags';
$tabhandler['object']['editrspvs'] = 'renderObjectSLB';
+$tabhandler['object']['rtrconfig'] = 'renderRouterConfig';
$tabextraclass['object']['snmpportfinder'] = 'attn';
$tabextraclass['object']['autoports'] = 'attn';
$trigger['object']['ipv4'] = 'trigger_ipv4';
$trigger['object']['editrspvs'] = 'trigger_natv4';
$trigger['object']['lvsconfig'] = 'trigger_lvsconfig';
$trigger['object']['autoports'] = 'trigger_autoports';
+$trigger['object']['rtrconfig'] = 'trigger_rtrconfig';
$trigger['object']['tags'] = 'trigger_tags';
$ophandler['object']['ports']['addPort'] = 'addPortForObject';
$ophandler['object']['ports']['delPort'] = 'delPortFromObject';
$ophandler['object']['editrspvs']['delLB'] = 'deleteLoadBalancer';
$ophandler['object']['editrspvs']['updLB'] = 'updateLoadBalancer';
$ophandler['object']['lvsconfig']['submitSLBConfig'] = 'submitSLBConfig';
+$ophandler['object']['rtrconfig']['submitRouterConfig'] = 'submitRouterConfig';
$delayauth['object']['livevlans']['setPortVLAN'] = TRUE;
$msgcode['object']['nat4']['addNATv4Rule']['OK'] = 2;
$msgcode['object']['nat4']['addNATv4Rule']['ERR'] = 100;
return buildWideRedirectURL ($msglog);
}
+function submitRouterConfig ()
+{
+ assertUIntArg ('object_id', __FUNCTION__);
+ $msglog = activateRouterConfig ($_REQUEST['object_id'], buildRouterConfig ($_REQUEST['object_id']));
+ return buildWideRedirectURL ($msglog);
+}
+
?>
return getConfigVar ('USER_AUTH_SRC') == 'database';
}
+// There's a sense to export router configuration,
+function trigger_rtrconfig ()
+{
+ assertUIntArg ('object_id', __FUNCTION__);
+ $alloclist = getObjectAddresses ($_REQUEST['object_id']);
+ $gwcount = 0;
+ foreach ($alloclist as $alloc)
+ if ($alloc['type'] == 'router')
+ $gwcount++;
+ return $gwcount > 0;
+}
+
?>