#
# The only supported command is:
#
-# * submit <username> <endpoint> <handler name> <data file name>: send the file
+# * submit <username> <endpoint> <handler name> [filename1] [filename2] [...]
#
# Handler name can be any string used to distinguish different file processors.
# The temporary file will be passed to a script in current directory, if it exists.
user=$1
endpoint=$2
handler=$3
- cfgfile=$4
+ # 0 or more files
+ files=$4
# sanity checks
- if [ -z "$user" -o -z "$endpoint" -o -z "$handler" -o -z "$cfgfile" ]; then
+ if [ -z "$user" -o -z "$endpoint" -o -z "$handler" ]; then
echo 'ERR!invalid arguments'
return
fi
- if [ ! -f "$cfgfile" ]; then
- echo "ERR!File $cfgfile is missing."
- return
- fi
+ for cfgfile in $files; do
+ if [ ! -f "$cfgfile" ]; then
+ echo "ERR!File $cfgfile is missing."
+ return
+ fi
+ done
if [ ! -x "$MYDIR/$handler.install" ]; then
echo "ERR!Cannot execute $MYDIR/$handler.install"
return
fi
- "$MYDIR/$handler.install" "$user" "$endpoint" "$cfgfile"
+ "$MYDIR/$handler.install" "$user" "$endpoint" $files
ret=$?
if [ $ret = 0 ]; then
echo "OK!"
// Drop a file off RackTables platform. The gateway will catch the file and pass it to the given
// installer script.
-// Return a
-function gwSendFile ($endpoint, $handlername, $filetext = '')
+function gwSendFile ($endpoint, $handlername, $filetext = array())
{
global $remote_username;
- $tmpfilename = tempnam ('', 'RackTables-sendfile-');
- $tmpfile = fopen ($tmpfilename, 'wb');
- fwrite ($tmpfile, $filetext);
- fclose ($tmpfile);
+ $tmpnames = array();
$endpoint = str_replace (' ', '\ ', $endpoint); // the gateway dispatcher uses read (1) to assign arguments
+ $command = "submit ${remote_username} ${endpoint} ${handlername}";
+ foreach ($filetext as $text)
+ {
+ $name = tempnam ('', 'RackTables-sendfile-');
+ $tmpnames[] = $name;
+ $tmpfile = fopen ($name, 'wb');
+ fwrite ($tmpfile, $text);
+ fclose ($tmpfile);
+ $command .= " ${name}";
+ }
$outputlines = queryGateway
(
'sendfile',
- array ("submit ${remote_username} ${endpoint} ${handlername} ${tmpfilename}")
+ array ($command)
);
- unlink ($tmpfilename);
+ foreach ($tmpnames as $name)
+ unlink ($name);
if ($outputlines == NULL)
return oneLiner (163); // unknown gateway failure
if (count ($outputlines) != 1)
if (count ($endpoints) > 1)
return oneLiner (162); // can't pick an address
$endpoint = str_replace (' ', '+', $endpoints[0]);
- return gwSendFile ($endpoint, $handlername, $filetext);
+ return gwSendFile ($endpoint, $handlername, array ($filetext));
}
function gwRecvFileFromObject ($object_id = 0, $handlername, &$output)
{
assertUIntArg ('object_id', __FUNCTION__);
$newconfig = buildLVSConfig ($_REQUEST['object_id']);
- $msglog = gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8'));
+ $msglog = gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', array (html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8')));
return buildWideRedirectURL ($msglog);
}