- split gwSendFile() into gwSendFile() and gwSendFileToObject() for convenience
- import grayscale version of tango-edit-clear icon and display it on empty lists
- justify layouts on ipaddress-properties and *-tags tabs
- sendfile: treat spaces in arguments better
- set tabindex in renderChapterEditor()
- split printSelect() code into printSelect(), printNiftySelect() and cookOptgroups()
- add VENDOR_SIEVE config option and implement relevant feature
do_submit()
{
- user=`echo $args | cut -s -d' ' -f1`
- endpoint=`echo $args | cut -s -d' ' -f2`
- handler=`echo $args | cut -s -d' ' -f3`
- cfgfile=`echo $args | cut -s -d' ' -f4`
+ user=$1
+ endpoint=$2
+ handler=$3
+ cfgfile=$4
# sanity checks
if [ -z "$user" -o -z "$endpoint" -o -z "$handler" -o -z "$cfgfile" ]; then
echo 'ERR!invalid arguments'
echo "ERR!Cannot execute $MYDIR/$handler.install"
return
fi
- "$MYDIR/$handler.install" $user $endpoint $cfgfile
+ "$MYDIR/$handler.install" "$user" "$endpoint" "$cfgfile"
ret=$?
if [ $ret = 0 ]; then
echo "OK!"
else
- echo "ERR!File handler returned code $ret"
+ echo "ERR!File handler '$handler' returned code $ret"
fi
}
# main loop
-while read cmd args; do
+while read cmd arg1 arg2 arg3 arg4; do
case $cmd in
submit)
- do_submit $args
+ do_submit "$arg1" "$arg2" "$arg3" "$arg4"
;;
*)
echo "ERR!unknown command $cmd"
return $ret;
}
+// Process the given list of records to build data suitable for printNiftySelect()
+// (like it was formerly executed by printSelect()). Screen out vendors according
+// to VENDOR_SIEVE, if object type ID is provided. However, the OPTGROUP with already
+// selected OPTION is protected from being screened.
+function cookOptgroups ($recordList, $object_type_id = 0, $existing_value = 0)
+{
+ $ret = array();
+ // Always keep "other" OPTGROUP at the SELECT bottom.
+ $therest = array();
+ foreach ($recordList as $dict_key => $dict_value)
+ if (strpos ($dict_value, '%GSKIP%') !== FALSE)
+ {
+ $tmp = explode ('%GSKIP%', $dict_value, 2);
+ $ret[$tmp[0]][$dict_key] = $tmp[1];
+ }
+ elseif (strpos ($dict_value, '%GPASS%') !== FALSE)
+ {
+ $tmp = explode ('%GPASS%', $dict_value, 2);
+ $ret[$tmp[0]][$dict_key] = $tmp[1];
+ }
+ else
+ $therest[$dict_key] = $dict_value;
+ if ($object_type_id != 0)
+ {
+ $screenlist = array();
+ foreach (explode (';', getConfigVar ('VENDOR_SIEVE')) as $sieve)
+ if (FALSE !== mb_ereg ("^([^@]+)(@${object_type_id})?\$", trim ($sieve), $regs))
+ $screenlist[] = $regs[1];
+ foreach (array_keys ($ret) as $vendor)
+ if (in_array ($vendor, $screenlist))
+ {
+ $ok_to_screen = TRUE;
+ if ($existing_value)
+ foreach (array_keys ($ret[$vendor]) as $recordkey)
+ if ($recordkey == $existing_value)
+ {
+ $ok_to_screen = FALSE;
+ break;
+ }
+ if ($ok_to_screen)
+ unset ($ret[$vendor]);
+ }
+ }
+ $ret['other'] = $therest;
+ return $ret;
+}
+
?>
// Drop a file off RackTables platform. The gateway will catch the file and pass it to the given
// installer script.
-function gwSendFile ($object_id = 0, $handlername, $filetext = '')
+// Return a
+function gwSendFile ($endpoint, $handlername, $filetext = '')
{
global $remote_username;
- if ($object_id <= 0 or empty ($handlername))
- 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
- $endpoint = str_replace (' ', '+', $endpoints[0]);
$tmpfilename = tempnam ('', 'RackTables-sendfile-');
$tmpfile = fopen ($tmpfilename, 'wb');
fwrite ($tmpfile, $filetext);
fclose ($tmpfile);
+ $endpoint = str_replace (' ', '\ ', $endpoint); // the gateway dispatcher uses read (1) to assign arguments
$outputlines = queryGateway
(
'sendfile',
if (strpos ($outputlines[0], 'OK!') !== 0)
return oneLiner (164, array ($outputlines[0])); // gateway failure
// Being here means having 'OK!' in the response.
- return oneLiner (66, array ($handlername)); // ignore provided "Ok" text, generate our own one
-
-
+ return oneLiner (66, array ($handlername)); // ignore provided "Ok" text
+}
- // Finally we can parse the response into message array.
- $log = array ('v' => 2);
- $codemap['OK'] = 66; // sendfile done
- list ($code, $text) = split ('!', $outputlines[0]);
- $log['m'][] = array ('c' => $codemap[$code], 'a' => array ($text));
- return $log;
+function gwSendFileToObject ($object_id = 0, $handlername, $filetext = '')
+{
+ global $remote_username;
+ if ($object_id <= 0 or empty ($handlername))
+ 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
+ $endpoint = str_replace (' ', '+', $endpoints[0]);
+ return gwSendFile ($endpoint, $handlername, $filetext);
}
?>
exit (1);
}
-// Escape any globals before we ever try to use them.
+// Escape any globals before we ever try to use them, but keep a copy of originals.
+$sic = $_REQUEST;
foreach ($_REQUEST as $key => $value)
if (gettype ($value) == 'string')
$_REQUEST[$key] = escapeString ($value);
$image['CLEAR']['path'] = 'pix/tango-edit-clear-big.png';
$image['CLEAR']['width'] = 32;
$image['CLEAR']['height'] = 32;
+$image['CLEAR gray']['path'] = 'pix/tango-edit-clear-gray-32x32.png';
+$image['CLEAR gray']['width'] = 32;
+$image['CLEAR gray']['height'] = 32;
$image['save']['path'] = 'pix/tango-document-save.png';
$image['save']['width'] = 16;
$image['save']['height'] = 16;
case 'dict':
$chapter = readChapter ($record['chapter_name']);
$chapter[0] = '-- NOT SET --';
- printSelect ($chapter, "${i}_value", $record['key']);
+ $chapter = cookOptgroups ($chapter, $object['objtype_id'], $record['key']);
+ printNiftySelect ($chapter, "${i}_value", $record['key']);
break;
}
echo "</td></tr>\n";
}
// This is a helper for creators and editors.
-function printSelect ($rowList, $select_name, $selected_id = NULL, $tabindex = NULL)
+// Input array keys are OPTION VALUEs and input array values are OPTION text.
+function printSelect ($optionList, $select_name, $selected_id = NULL, $tabindex = NULL)
{
- // First collect all data for OPTGROUPs, then ouput it and dump
- // the rest of records as is.
- $optgroup = array();
- $other = array();
- foreach ($rowList as $dict_key => $dict_value)
+ echo "<select name=${select_name}" . ($tabindex ? " tabindex=${tabindex}" : '') . '>';
+ foreach ($optionList as $dict_key => $dict_value)
+ echo "<option value=${dict_key}" . ($dict_key == $selected_id ? ' selected' : '') . ">${dict_value}</option>";
+ echo "</select>";
+}
+
+// Input is a cooked list of OPTGROUPs, each with own sub-list of OPTIONs in the same
+// format as printSelect() expects.
+function printNiftySelect ($groupList, $select_name, $selected_id = NULL, $tabindex = NULL)
+{
+ // special treatment for ungrouped data
+ if (count ($groupList) == 1 and isset ($groupList['other']))
{
- if (strpos ($dict_value, '%GSKIP%') !== FALSE)
- {
- $tmp = explode ('%GSKIP%', $dict_value, 2);
- $optgroup[$tmp[0]][$dict_key] = $tmp[1];
- }
- elseif (strpos ($dict_value, '%GPASS%') !== FALSE)
- {
- $tmp = explode ('%GPASS%', $dict_value, 2);
- $optgroup[$tmp[0]][$dict_key] = $tmp[1];
- }
- else
- $other[$dict_key] = $dict_value;
+ printSelect ($groupList['other'], $select_name, $selected_id, $tabindex);
+ return;
}
echo "<select name=${select_name}" . ($tabindex ? " tabindex=${tabindex}" : '') . '>';
- if (!count ($optgroup))
+ foreach ($groupList as $groupname => $groupdata)
{
- foreach ($other as $dict_key => $dict_value)
- {
- echo "<option value=${dict_key}";
- if ($dict_key == $selected_id)
- echo ' selected';
- echo ">${dict_value}</option>";
- }
- }
- else
- {
- foreach ($optgroup as $groupname => $groupdata)
- {
- echo "<optgroup label='${groupname}'>";
- foreach ($groupdata as $dict_key => $dict_value)
- {
- echo "<option value=${dict_key}";
- if ($dict_key == $selected_id)
- echo ' selected';
- echo ">${dict_value}</option>";
- }
- echo "</optgroup>\n";
- }
- if (count ($other))
- {
- echo "<optgroup label='other'>\n";
- foreach ($other as $dict_key => $dict_value)
- {
- echo "<option value=${dict_key}";
- if ($dict_key == $selected_id)
- echo ' selected';
- echo ">${dict_value}</option>";
- }
- echo "</optgroup>\n";
- }
+ echo "<optgroup label='${groupname}'>";
+ foreach ($groupdata as $dict_key => $dict_value)
+ echo "<option value=${dict_key}" . ($dict_key == $selected_id ? ' selected' : '') . ">${dict_value}</option>";
+ echo "</optgroup>\n";
}
echo "</select>";
}
echo "<tr><td class='tdright'>Name:</td><td class='tdleft'><input type=text name=name size=20 value='${address['name']}'></tr>";
echo "<td class='tdright'>Reserved:</td><td class='tdleft'><input type=checkbox name=reserved size=20 ";
echo ($address['reserved']=='yes') ? 'checked' : '';
- echo "></tr><tr><td colspan=2 class='tdcenter'>";
+ echo "></tr><tr><td class=tdleft>";
printImageHREF ('SAVE', 'Save changes', TRUE);
- echo "</td></form></tr></table>\n";
- finishPortlet();
+ echo "</td></form><td class=tdright>";
if (empty ($address['name']) and $address['reserved'] == 'no')
- return;
-
- startPortlet ('release');
- printOpFormIntro ('editAddress', array ('name' => '', 'reserved' => ''));
- echo "<input type=submit value='release'></form>";
+ printImageHREF ('CLEAR gray');
+ else
+ {
+ printOpFormIntro ('editAddress', array ('name' => '', 'reserved' => ''));
+ printImageHREF ('CLEAR', 'Release', TRUE);
+ echo "</form>";
+ }
+ echo "</td></tr></table>\n";
finishPortlet();
}
echo '<tr><td> </td><td>';
printImageHREF ('add', 'Add new', TRUE);
echo "</td>";
- echo "<td class=tdleft><input type=text name=dict_value size=32></td><td>";
- printImageHREF ('add', 'Add new', TRUE);
+ echo "<td class=tdleft><input type=text name=dict_value size=32 tabindex=100></td><td>";
+ printImageHREF ('add', 'Add new', TRUE, 101);
echo '</td></tr></form>';
}
$dict = getDict();
function renderEntityTags ($entity_id = 0)
{
- global $tagtree, $target_given_tags, $pageno, $page, $etype_by_pageno;
+ global $tagtree, $target_given_tags, $pageno, $page, $etype_by_pageno, $target_given_tags;
if ($entity_id <= 0)
{
showError ('Invalid or missing arguments', __FUNCTION__);
echo '<tr><td class=tdleft>';
printImageHREF ('SAVE', 'Save changes', TRUE);
echo "</form></td><td class=tdright>";
- printOpFormIntro ('saveTags', array ($bypass_name => $entity_id, 'taglist[]' => ''));
- printImageHREF ('CLEAR', 'Reset all tags', TRUE);
+ if (!count ($target_given_tags))
+ printImageHREF ('CLEAR gray');
+ else
+ {
+ printOpFormIntro ('saveTags', array ($bypass_name => $entity_id, 'taglist[]' => ''));
+ printImageHREF ('CLEAR', 'Reset all tags', TRUE);
+ }
echo '</form></td></tr></table>';
finishPortlet();
}
setConfigVar ('PREVIEW_TEXT_ROWS', '25');
setConfigVar ('PREVIEW_TEXT_COLS', '80');
setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320');
+ setConfigVar ('VENDOR_SIEVE', '');
return buildRedirectURL (__FUNCTION__, 'OK');
}
{
assertUIntArg ('object_id', __FUNCTION__);
$newconfig = buildLVSConfig ($_REQUEST['object_id']);
- $msglog = gwSendFile ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8'));
+ $msglog = gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8'));
return buildWideRedirectURL ($msglog);
}
assertStringArg ('file_name', __FUNCTION__);
assertStringArg ('file_type', __FUNCTION__);
assertStringArg ('file_comment', __FUNCTION__, TRUE);
- $error = commitUpdateFile ($_REQUEST['file_id'], $_REQUEST['file_name'], $_REQUEST['file_type'], $_REQUEST['file_comment']);
+ // prepared statement params below
+ global $sic;
+ $error = commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment']);
if ($error != '')
return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_ROWS','25','uint','yes','no','Rows for text file preview');
INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_COLS','80','uint','yes','no','Columns for text file preview');
INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_IMAGE_MAXPXS','320','uint','yes','no','Max pixels per axis for image file preview');
+INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('VENDOR_SIEVE','','string','yes','no','Vendor sieve configuration');
INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('DB_VERSION','0.17.0','string','no','yes','Database version.');
INSERT INTO `Script` VALUES ('RackCode','allow {$userid_1}');
$query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_ROWS','25','uint','yes','no','Rows for text file preview')";
$query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_COLS','80','uint','yes','no','Columns for text file preview')";
$query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_IMAGE_MAXPXS','320','uint','yes','no','Max pixels per axis for image file preview')";
+ $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('VENDOR_SIEVE','','string','yes','no','Vendor sieve configuration')";
$query[] = "alter table TagTree add column valid_realm set('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user') not null default 'file,ipv4net,ipv4vs,ipv4rspool,object,rack,user' after parent_id";
$result = $dbxlink->query ("select user_id, user_name, user_realname from UserAccount where user_enabled = 'no'");
while ($row = $result->fetch (PDO::FETCH_ASSOC))