diff --git a/xCAT-UI/js/ui.js b/xCAT-UI/js/ui.js index b4e36963e..8578900f2 100644 --- a/xCAT-UI/js/ui.js +++ b/xCAT-UI/js/ui.js @@ -326,7 +326,16 @@ function createStatusBar(barId) { */ function createInfoBar(msg) { var infoBar = $('
'); - var msg = $('

' + msg + '

'); + var icon = $('').css({ + 'display': 'inline-block', + 'margin': '10px 5px' + }); + var msg = $('

' + msg + '

').css({ + 'display': 'inline-block', + 'width': '95%' + }); + + infoBar.append(icon); infoBar.append(msg); return infoBar; } @@ -563,3 +572,29 @@ function openDialog(type, msg) { } }); } + +/** + * Create an iframe to hold the output of an xCAT command + * + * @param src + * The URL of the document to show in the iframe + * @return Info box containing the iframe + */ +function createIFrame(src) { + // Put an iframe inside an info box + var infoBar = $('
'); + var icon = $('').css({ + 'display': 'inline-block', + 'margin': '10px 5px' + }); + var iframe = $('').attr('src', src).css({ + 'display': 'inline-block', + 'border': '0px', + 'margin': '10px 0px', + 'width': '95%' + }); + + infoBar.append(icon); + infoBar.append(iframe); + return infoBar; +} diff --git a/xCAT-UI/lib/cmd.php b/xCAT-UI/lib/cmd.php index f4e5f6679..3b5f26686 100644 --- a/xCAT-UI/lib/cmd.php +++ b/xCAT-UI/lib/cmd.php @@ -12,6 +12,7 @@ require_once "$TOPDIR/lib/jsonwrapper.php"; * @param $cmd The xCAT command * $tgt The target node or group * $args The xCAT command arguments, separated by semicolons + * $opts The xCAT command options, separated by semicolons * @return The xCAT response. Replies are in the form of JSON */ if (isset($_GET["cmd"])) { @@ -19,7 +20,7 @@ if (isset($_GET["cmd"])) { $cmd = $_GET["cmd"]; $tgt = $_GET["tgt"]; $args = $_GET["args"]; - + // Special messages put here // This gets sent back to the AJAX request as is. $msg = $_GET["msg"]; @@ -34,22 +35,41 @@ if (isset($_GET["cmd"])) { $msg = NULL; } - // If no $args is given, set $arr to NULL - if (!$args) { - $arr = array(); - } else { + // If no $args are given, set $args_array to NULL + $args_array = array(); + if ($args) { // If $args contains multiple arguments, split it into an array if (strpos($args,";")) { // Split the arguments into an array - $arr = array(); - $arr = explode(";", $args); + $args_array = array(); + $args_array = explode(";", $args); } else { - $arr = array($args); + $args_array = array($args); + } + } + + // If no $opts are given, set $opts_array to NULL + $opts_array = array(); + if (isset($_GET["opts"])) { + $opts = $_GET["opts"]; + + // If $args contains multiple arguments, split it into an array + if (strpos($opts,";")) { + // Split the arguments into an array + $opts_array = array(); + $opts_array = explode(";", $opts); + } else { + $opts_array = array($opts); } } // Submit request and get response - $xml = docmd($cmd, $tgt, $arr); + $xml = docmd($cmd, $tgt, $args_array, $opts_array); + // If the output is flushed, do not return output in JSON + if (in_array("flush", $opts_array)) { + return; + } + $rsp = array(); // webrun pping and gangliastatus output needs special handling diff --git a/xCAT-UI/lib/functions.php b/xCAT-UI/lib/functions.php index c74ffab0c..c0aa66b41 100644 --- a/xCAT-UI/lib/functions.php +++ b/xCAT-UI/lib/functions.php @@ -12,19 +12,20 @@ error_reporting(E_ALL); ini_set('display_errors', true); /** - * Description: Run a command using the xCAT client/server protocol + * Run a command using the xCAT client/server protocol * - * @param $cmd The xCAT command - * $nr Node range or group - * $args Command arguments + * @param $cmd The xCAT command + * $nr Node range or group + * $args_array Command arguments + * $opts_array Command options * @return A tree of SimpleXML objects. * See perl-xCAT/xCAT/Client.pm for the format */ -function docmd($cmd, $nr, $args){ +function docmd($cmd, $nr, $args_array, $opts_array){ // If we are not logged in, // do not try to communicate with xcatd if (!is_logged()) { - echo "

docmd: Not logged in - cannot run command

"; + echo "

You are not logged in! Failed to run command.

"; return simplexml_load_string('', 'SimpleXMLElement', LIBXML_NOCDATA); } @@ -33,8 +34,8 @@ function docmd($cmd, $nr, $args){ $request = simplexml_load_string(''); $request->addChild('command', $cmd); if(!empty($nr)) { $request->addChild('noderange', $nr); } - if (!empty($args)) { - foreach ($args as $a) { + if (!empty($args_array)) { + foreach ($args_array as $a) { $request->addChild('arg',$a); } } @@ -44,23 +45,37 @@ function docmd($cmd, $nr, $args){ $usernode->addChild('username',$_SESSION["username"]); $usernode->addChild('password',getpassword()); - $xml = submit_request($request,0); + $xml = submit_request($request, 0, $opts_array); return $xml; } /** - * Used by docmd() + * Used by docmd() to submit request to xCAT * - * @param $req Tree of SimpleXML objects + * @param $req Tree of SimpleXML objects + * @param $opts_array Request options * @return A tree of SimpleXML objects */ -function submit_request($req, $skipVerify){ +function submit_request($req, $skipVerify, $opts_array){ $xcathost = "localhost"; $port = "3001"; $rsp = FALSE; $response = ''; $cleanexit = 0; + // Determine whether to flush output or not + $flush = false; + if (in_array("flush", $opts_array)) { + $flush = true; + } + + // Determine how to handle the flush output + // You can specify a function name, in place of TBD, to handle the flush output + $flush_format = ""; + if (in_array("flush-format=TBD", $opts_array)) { + $flush_format = "TBD"; + } + // Open syslog, include the process ID and also send // the log to standard error, and use a user defined // logging mechanism @@ -84,7 +99,15 @@ function submit_request($req, $skipVerify){ $str = fread($fp, 8192); if ($str) { $response .= preg_replace('/>\n\s*<', $str); - // syslog(LOG_INFO, "($nr) Reading partial response: $response"); + + // Flush output to browser + if ($flush) { + // Strip HTML tags from output + if ($tmp = trim(strip_tags($str))) { + echo $tmp . '
'; + flush(); + } + } } // Look for serverdone response