');
var frameDiv = $('');
- frameDiv.append('');
+ frameDiv.append('');
//for P7-IH, all the cecs are insert into the frame from down to up, so we had to show the cecs same as the
//physical layout.
@@ -445,7 +445,7 @@ function createSystempGraphical(bpa, fsp, area){
updateSelectNodeDiv();
});
- $('.fspcheckbox').bind('click', function(){
+ $('.fspCheckbox').bind('click', function(){
var itemName = $(this).attr('name');
name = itemName.substr(6);
@@ -571,8 +571,8 @@ function createSystemxGraphical(xnodes, area){
}
xnodenum++;
var td = $('
');
- var xnodeDiv = '';
- td.append(xnodeDiv);
+ var xNodeDiv = '';
+ td.append(xNodeDiv);
row.append(td);
}
}
@@ -801,7 +801,7 @@ function createFspDiv(fspName, mtm, fsp){
}
//create return value
- var retHtml = '';
+ var retHtml = '';
retHtml += '
';
retHtml += '
' + lparStatusRow + '
';
return retHtml;
diff --git a/xCAT-UI/js/srv_xcatauth.js b/xCAT-UI/js/srv_xcatauth.js
index a22fc56ad..e9c4ef89c 100644
--- a/xCAT-UI/js/srv_xcatauth.js
+++ b/xCAT-UI/js/srv_xcatauth.js
@@ -24,8 +24,8 @@ $(document).ready(function() {
}).button();
if (document.location.protocol == 'http:') {
- $('#login_status').html('You are using an unencrypted session!');
- $('#login_status').css('color', 'red');
+ $('#login-status').html('You are using an unencrypted session!');
+ $('#login-status').css('color', 'red');
}
if (!$("#login input[name='username']").val()) {
@@ -62,7 +62,7 @@ function onlogin(data, txtStatus) {
var usrName = $("#login input[name='username']").val();
$("#login input[name='password']").val('');
if (data.authenticated == 'yes') {
- $('#login_status').text('Login successful');
+ $('#login-status').text('Login successful');
window.location = 'service.php';
// Set user name cookie
@@ -70,8 +70,8 @@ function onlogin(data, txtStatus) {
exDate.setTime(exDate.getTime() + (240 * 60 * 1000));
$.cookie('xcat_username', usrName, { expires: exDate });
} else {
- $('#login_status').text('Authentication failure');
- $('#login_status').css('color', '#FF0000');
+ $('#login-status').text('Authentication failure');
+ $('#login-status').css('color', '#FF0000');
}
}
@@ -79,8 +79,8 @@ function onlogin(data, txtStatus) {
* Authenticate user for new session
*/
function authenticate() {
- $('#login_status').css('color', '#000000');
- $('#login_status').html('Authenticating...');
+ $('#login-status').css('color', '#000000');
+ $('#login-status').html('Authenticating...');
var passwd = $("#login input[name='password']").val();
$.post('lib/srv_log.php', {
diff --git a/xCAT-UI/js/xcatauth.js b/xCAT-UI/js/xcatauth.js
index 9d615b349..22fb185fc 100644
--- a/xCAT-UI/js/xcatauth.js
+++ b/xCAT-UI/js/xcatauth.js
@@ -26,8 +26,8 @@ $(document).ready(function() {
$('#login button').button();
if (document.location.protocol == "http:") {
- $("#login_status").html("You are using an unencrypted session!");
- $("#login_status").css("color", "#ff0000");
+ $("#login-status").html("You are using an unencrypted session!");
+ $("#login-status").css("color", "#ff0000");
}
if ($("#login input[name='username']").val() == "") {
@@ -64,7 +64,7 @@ function onlogin(data, txtStatus) {
// Clear password field regardless of what happens
$("#login input[name='password']").val("");
if (data.authenticated == "yes") {
- $("#login_status").text("Login successful");
+ $("#login-status").text("Login successful");
// Not the first time to log
if ($.cookie('logonflag')){
@@ -87,7 +87,7 @@ function onlogin(data, txtStatus) {
});
} else {
- $("#login_status").text("Authentication failure").css("color", "#FF0000");
+ $("#login-status").text("Authentication failure").css("color", "#FF0000");
}
}
@@ -97,8 +97,8 @@ function onlogin(data, txtStatus) {
* @return Nothing
*/
function authenticate() {
- $("#login_status").css("color", "#000000");
- $("#login_status").html('Authenticating...');
+ $("#login-status").css("color", "#000000");
+ $("#login-status").html('Authenticating...');
var passwd = $("#login input[name='password']").val();
$.post("lib/log.php", {
username : $("#login input[name='username']").val(),
diff --git a/xCAT-UI/lib/cmd.php b/xCAT-UI/lib/cmd.php
index d040fe499..d272b9d79 100644
--- a/xCAT-UI/lib/cmd.php
+++ b/xCAT-UI/lib/cmd.php
@@ -6,26 +6,26 @@ require_once "$TOPDIR/lib/jsonwrapper.php";
/**
* Issue a xCAT command, e.g. rinv gpok123 all
- * This will handle most commands. If not, you can create your
- * own .php. Look at zCmd.php for an example.
+ * This will handle most commands. If not, you can create your own .php.
+ * Look at zCmd.php for an example.
*
- * @param $cmd The xCAT command
- * @param $tgt The target node or group
- * @param $args The xCAT command arguments, separated by semicolons
- * @param $opts The xCAT command options, separated by semicolons
- * @return The xCAT response. Replies are in the form of JSON
+ * @param $cmd The xCAT command
+ * @param $tgt The target node or group
+ * @param $args The xCAT command arguments, separated by semicolons
+ * @param $opts The xCAT command options, separated by semicolons
+ * @return The xCAT response. Replies are in the form of JSON
*/
if (isset($_GET["cmd"])) {
// HTTP GET requests
$cmd = $_GET["cmd"];
$tgt = $_GET["tgt"];
$args = $_GET["args"];
-
+
// File contents in case of file write
if (isset($_GET["cont"])) {
$cont = $_GET["cont"];
}
-
+
// Special messages put here
// This gets sent back to the AJAX request as is.
$msg = $_GET["msg"];
@@ -34,7 +34,7 @@ if (isset($_GET["cmd"])) {
if (!$tgt) {
$tgt = NULL;
}
-
+
// If no $msg is given, set $msg to NULL
if (!$msg) {
$msg = NULL;
@@ -52,12 +52,12 @@ if (isset($_GET["cmd"])) {
$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
@@ -74,7 +74,7 @@ if (isset($_GET["cmd"])) {
if (in_array("flush", $opts_array)) {
return;
}
-
+
$rsp = array();
// webrun pping and gangliastatus output needs special handling
@@ -90,7 +90,7 @@ if (isset($_GET["cmd"])) {
// This command gets the nodes and groups
else if(strncasecmp($cmd, "extnoderange", 12) == 0) {
$rsp = extractExtnoderange($xml);
- }
+ }
// Write contents to file
else if(strncasecmp($cmd, "write", 4) == 0) {
// Directory should be /var/opt/xcat/profiles
@@ -99,7 +99,7 @@ if (isset($_GET["cmd"])) {
$handle = fopen($file, 'w') or die("Cannot open $file");
fwrite($handle, $cont);
fclose($handle);
-
+
$rsp = "Directory entry written to $file";
}
// Handle the typical output
@@ -108,20 +108,20 @@ if (isset($_GET["cmd"])) {
foreach ($child->children() as $data) {
if($data->name) {
$node = $data->name;
-
+
if ($data->data->contents) {
$cont = $data->data->contents;
} else {
$cont = $data->data;
}
-
+
if ($data->data->desc) {
$cont = $data->data->desc . ": " . $cont;
}
-
+
$cont = str_replace(":|:", "\n", $cont);
array_push($rsp, "$node: $cont");
- } else if(strlen("$data") > 2) {
+ } else if (strlen("$data") > 2) {
$data = str_replace(":|:", "\n", $data);
array_push($rsp, "$data");
}
@@ -137,8 +137,8 @@ if (isset($_GET["cmd"])) {
/**
* Extract the output for a webrun command
*
- * @param $xml The XML output from docmd()
- * @return An array containing the output
+ * @param $xml The XML output from docmd()
+ * @return An array containing the output
*/
function extractWebrun($xml) {
$rsp = array();
@@ -149,7 +149,7 @@ function extractWebrun($xml) {
foreach($nodes->children() as $node){
// Get the node name
$name = $node->name;
-
+
// Get the content
$status = $node->data;
$status = str_replace(":|:", "\n", $status);
@@ -166,8 +166,8 @@ function extractWebrun($xml) {
/**
* Extract the output for a nodels command
*
- * @param $xml The XML output from docmd()
- * @return An array containing the output
+ * @param $xml The XML output from docmd()
+ * @return An array containing the output
*/
function extractNodels($xml) {
$rsp = array();
@@ -195,8 +195,8 @@ function extractNodels($xml) {
/**
* Extract the output for a extnoderange command
*
- * @param $xml The XML output from docmd()
- * @return The nodes and groups
+ * @param $xml The XML output from docmd()
+ * @return The nodes and groups
*/
function extractExtnoderange($xml) {
$rsp = array();
diff --git a/xCAT-UI/lib/functions.php b/xCAT-UI/lib/functions.php
index c1e23b5eb..52935d368 100644
--- a/xCAT-UI/lib/functions.php
+++ b/xCAT-UI/lib/functions.php
@@ -5,22 +5,21 @@
// Retain session variables across page requests
session_start();
-session_write_close(); // Do not block HTTP requests
+session_write_close(); // Do not block other HTTP requests
-// The settings below display error on the screen,
-// instead of giving blank pages.
+// The settings below display error on the screen, instead of giving blank pages.
error_reporting(E_ALL);
ini_set('display_errors', true);
/**
* Run a command using the xCAT client/server protocol
*
- * @param $cmd The xCAT command
- * @param $nr Node range or group
- * @param $args_array Command arguments
- * @param $opts_array Command options
- * @return A tree of SimpleXML objects.
- * See perl-xCAT/xCAT/Client.pm for the format
+ * @param $cmd The xCAT command
+ * @param $nr Node range or group
+ * @param $args_array Command arguments
+ * @param $opts_array Command options
+ * @return A tree of SimpleXML objects.
+ * See perl-xCAT/xCAT/Client.pm for the format
*/
function docmd($cmd, $nr, $args_array, $opts_array){
// If we are not logged in,
@@ -34,7 +33,9 @@ function docmd($cmd, $nr, $args_array, $opts_array){
// Add command, node range, and arguments to request
$request = simplexml_load_string('');
$request->addChild('command', $cmd);
- if(!empty($nr)) { $request->addChild('noderange', $nr); }
+ if (!empty($nr)) {
+ $request->addChild('noderange', $nr);
+ }
if (!empty($args_array)) {
foreach ($args_array as $a) {
$request->addChild('arg',$a);
@@ -53,9 +54,9 @@ function docmd($cmd, $nr, $args_array, $opts_array){
/**
* Used by docmd() to submit request to xCAT
*
- * @param $req Tree of SimpleXML objects
- * @param $opts_array Request options
- * @return A 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, $opts_array){
$xcathost = "localhost";
@@ -63,46 +64,46 @@ function submit_request($req, $skipVerify, $opts_array){
$rsp = FALSE;
$response = '';
$cleanexit = 0;
-
+
// Determine whether to flush output or not
$flush = false;
if ($opts_array && 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 ($opts_array && 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
+
+ // Open syslog, include the process ID and also send the log to standard error,
+ // and use a user defined logging mechanism
openlog("xCAT-UI", LOG_PID | LOG_PERROR, LOG_LOCAL0);
// Open a socket to xcatd
syslog(LOG_INFO, "Opening socket to xcatd...");
- if($fp = stream_socket_client('ssl://'.$xcathost.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT)){
+ if ($fp = stream_socket_client('ssl://'.$xcathost.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT)){
$reqXML = $req->asXML();
$nr = $req->noderange;
$cmd = $req->command;
-
+
syslog(LOG_INFO, "Sending request: $cmd $nr");
- stream_set_blocking($fp, 0); // Set as non-blocking
- fwrite($fp,$req->asXML()); // Send XML to xcatd
- set_time_limit(900); // Set 15 minutes timeout (for long running requests)
- // The default is 30 seconds which is too short for some requests
-
+ stream_set_blocking($fp, 0); // Set as non-blocking
+ fwrite($fp,$req->asXML()); // Send XML to xcatd
+ set_time_limit(900); // Set 15 minutes timeout (for long running requests)
+ // The default is 30 seconds which is too short for some requests
+
// Turn on output buffering
ob_start();
- while(!feof($fp)) { // Read until there is no more
+ while (!feof($fp)) {
+ // Read until there is no more
// Remove newlines and add it to the response
$str = fread($fp, 8192);
if ($str) {
$response .= preg_replace('/>\n\s*', '><', $str);
-
+
// Flush output to browser
if ($flush) {
// Strip HTML tags from output
@@ -117,50 +118,48 @@ function submit_request($req, $skipVerify, $opts_array){
flush();
}
}
- }
+ }
}
-
+
// Look for serverdone response
$fullpattern = '/\s*\s*<\/serverdone>\s*<\/xcatresponse>/';
$mixedpattern = '/\s*<\/serverdone>.*<\/xcatresponse>/';
$recentpattern = '/<\/xcatresponse>/';
- if(preg_match($recentpattern,$str) && preg_match($mixedpattern,$response)) {
- // Transaction is done,
- // Package up XML and return it
+ if (preg_match($recentpattern,$str) && preg_match($mixedpattern,$response)) {
+ // Transaction is done, package up XML and return it
// Remove the serverdone response and put an xcat tag around the rest
$count = 0;
- $response = preg_replace($fullpattern,'', $response, -1, $count); // 1st try to remove the long pattern
- if (!$count) { $response = preg_replace($mixedpattern,'', $response) . '/'; } // if its not there, then remove the short pattern
+ $response = preg_replace($fullpattern,'', $response, -1, $count); // 1st try to remove the long pattern
+ if (!$count) {
+ $response = preg_replace($mixedpattern,'', $response) . '/';
+ }
$response = "$response";
- //delete the \n between '>' and '<'
$response = preg_replace('/>\n\s*', '><', $response);
- //replace the '\n' by ':|:' in the data area.
$response = preg_replace('/\n/', ':|:', $response);
$rsp = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA);
$cleanexit = 1;
break;
}
} // End of while(!feof($fp))
-
+
syslog(LOG_INFO, "($cmd $nr) Sending response");
fclose($fp);
} else {
echo "
";
$rsp = FALSE;
}
@@ -170,10 +169,6 @@ function submit_request($req, $skipVerify, $opts_array){
/**
* Enable password storage to split between cookie and session variable
- *
- * @param $data
- * @param $key
- * @return
*/
function xorcrypt($data, $key) {
$datalen = strlen($data);
@@ -187,9 +182,6 @@ function xorcrypt($data, $key) {
/**
* Get password
- *
- * @param Nothing
- * @return
*/
function getpassword() {
if (isset($GLOBALS['xcatauthsecret'])) {
@@ -204,13 +196,11 @@ function getpassword() {
}
/**
- * Get the password splitting knowledge between server
- * and client side persistant storage. Caller should regenerate
- * session ID when contemplating a new user/password, to preclude
- * session fixation, though fixation is limited without the secret.
+ * Get the password splitting knowledge between server and client side persistant storage.
+ * Caller should regenerate session ID when contemplating a new user/password,
+ * to preclude session fixation, though fixation is limited without the secret.
*
- * @param $password Password
- * @return Nothing
+ * @param $password Password
*/
function setpassword($password) {
$randlen = strlen($password);
@@ -227,8 +217,8 @@ function setpassword($password) {
/**
* Get RAND characters
*
- * @param $length Length of characters
- * @return RAND characters
+ * @param $length Length of characters
+ * @return RAND characters
*/
function getrandchars($length) {
$charset = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*';
@@ -246,9 +236,7 @@ function getrandchars($length) {
/**
* Determine if a user/password session exists
*
- * @param Nothing
- * @return True If user has a session.
- * False Otherwise
+ * @return True if user has a session, false otherwise
*/
function is_logged() {
if (isset($_SESSION["username"]) and !is_bool(getpassword())) {
@@ -260,10 +248,8 @@ function is_logged() {
/**
* Determine if a user is currently logged in successfully
- *
- * @param Nothing
- * @return True If the user is currently logged in successfully
- * False Otherwise
+ *
+ * @return True if the user is currently logged in successfully, false otherwise
*/
function isAuthenticated() {
if (is_logged()) {
@@ -290,12 +276,10 @@ function isAuthenticated() {
}
/**
-* Determine if a user has root access
-*
-* @param Nothing
-* @return True If the user has root access
-* False Otherwise
-*/
+ * Determine if a user has root access
+ *
+ * @return True if the user has root access, false otherwise
+ */
function isRootAcess() {
if (is_logged() && $_SESSION["xcatpassvalid"]) {
$testacc = docmd('tabdump', '', array('policy', '-w', "name==" . $_SESSION["username"]), array());
@@ -304,7 +288,7 @@ function isRootAcess() {
$result = str_replace('"', '', $result);
$args = array();
$args = explode(",", $result);
-
+
// Get the comments which contains the privilege
$comments = $args[8];
$args = explode(";", $comments);
@@ -319,13 +303,13 @@ function isRootAcess() {
$privilege = 'root';
$_SESSION["xcatpassvalid"] = 1;
}
-
+
break;
- }
+ }
}
}
}
-
+
if (strcmp($_SESSION["username"], 'root') == 0) {
$_SESSION["xcatpassvalid"] = 1;
}
@@ -338,10 +322,7 @@ function isRootAcess() {
}
/**
- * Log out of the current user session
- *
- * @param Nothing
- * @return Nothing
+ * Log out of current user session
*/
function logout() {
// Clear the secret cookie from browser
@@ -360,12 +341,9 @@ function logout() {
/**
* Format a given string and echo it back to the browser
- *
- * @param $str String
- * @return Nothing
*/
function format_TBD($str) {
- // Format a given string however you want it
+ // Format a given string however you want it
echo $tmp . ' ';
flush();
}
diff --git a/xCAT-UI/lib/rcons.php b/xCAT-UI/lib/rcons.php
index 5ddc2825a..d27960aa2 100644
--- a/xCAT-UI/lib/rcons.php
+++ b/xCAT-UI/lib/rcons.php
@@ -77,14 +77,14 @@ function rconsSynchronise($parameter) {
if (0 == strlen($line)) {
continue;
}
-
+
if ('<' == substr($line, 0, 1)) {
$flag = true;
$return .= $line;
break;
}
}
-
+
if ($flag) {
while (!feof($fp)) {
$return .= fgets($fp, 1024);
diff --git a/xCAT-UI/lib/srv_cmd.php b/xCAT-UI/lib/srv_cmd.php
index 3798fab27..ae3b4878b 100644
--- a/xCAT-UI/lib/srv_cmd.php
+++ b/xCAT-UI/lib/srv_cmd.php
@@ -5,22 +5,21 @@ require_once "$TOPDIR/lib/srv_functions.php";
require_once "$TOPDIR/lib/jsonwrapper.php";
/**
- * Issue a xCAT command, e.g. rinv gpok123 all
- * This will handle most commands. If not, you can create your
- * own .php. Look at zCmd.php for an example.
+ * Issue a xCAT command, e.g. rinv gpok123 all. This will handle most commands.
+ * If not, you can create your own .php. Look at zCmd.php for an example.
*
- * @param $cmd The xCAT command
- * @param $tgt The target node or group
- * @param $args The xCAT command arguments, separated by semicolons
- * @param $opts The xCAT command options, separated by semicolons
- * @return The xCAT response. Replies are in the form of JSON
+ * @param $cmd The xCAT command
+ * @param $tgt The target node or group
+ * @param $args The xCAT command arguments, separated by semicolons
+ * @param $opts The xCAT command options, separated by semicolons
+ * @return The xCAT response. Replies are in the form of JSON
*/
if (isset($_GET["cmd"])) {
// HTTP GET requests
$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"];
@@ -29,7 +28,7 @@ if (isset($_GET["cmd"])) {
if (!$tgt) {
$tgt = NULL;
}
-
+
// If no $msg is given, set $msg to NULL
if (!$msg) {
$msg = NULL;
@@ -47,12 +46,12 @@ if (isset($_GET["cmd"])) {
$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
@@ -69,7 +68,7 @@ if (isset($_GET["cmd"])) {
if (in_array("flush", $opts_array)) {
return;
}
-
+
$rsp = array();
// webrun pping and gangliastatus output needs special handling
@@ -92,17 +91,16 @@ if (isset($_GET["cmd"])) {
foreach ($child->children() as $data) {
if($data->name) {
$node = $data->name;
-
+
if($data->data->contents){
$cont = $data->data->contents;
- }
- else{
+ } else {
$cont = $data->data;
}
-
+
$cont = str_replace(":|:", "\n", $cont);
array_push($rsp, "$node: $cont");
- } else if(strlen("$data") > 2) {
+ } else if (strlen("$data") > 2) {
$data = str_replace(":|:", "\n", $data);
array_push($rsp, "$data");
}
@@ -118,8 +116,8 @@ if (isset($_GET["cmd"])) {
/**
* Extract the output for a webrun command
*
- * @param $xml The XML output from docmd()
- * @return An array containing the output
+ * @param $xml The XML output from docmd()
+ * @return An array containing the output
*/
function extractWebrun($xml) {
$rsp = array();
@@ -130,7 +128,7 @@ function extractWebrun($xml) {
foreach($nodes->children() as $node){
// Get the node name
$name = $node->name;
-
+
// Get the content
$status = $node->data;
$status = str_replace(":|:", "\n", $status);
@@ -147,8 +145,8 @@ function extractWebrun($xml) {
/**
* Extract the output for a nodels command
*
- * @param $xml The XML output from docmd()
- * @return An array containing the output
+ * @param $xml The XML output from docmd()
+ * @return An array containing the output
*/
function extractNodels($xml) {
$rsp = array();
@@ -176,8 +174,8 @@ function extractNodels($xml) {
/**
* Extract the output for a extnoderange command
*
- * @param $xml The XML output from docmd()
- * @return The nodes and groups
+ * @param $xml The XML output from docmd()
+ * @return The nodes and groups
*/
function extractExtnoderange($xml) {
$rsp = array();
diff --git a/xCAT-UI/lib/srv_functions.php b/xCAT-UI/lib/srv_functions.php
index 624db7687..c18a336fb 100644
--- a/xCAT-UI/lib/srv_functions.php
+++ b/xCAT-UI/lib/srv_functions.php
@@ -5,7 +5,7 @@
// Retain session variables across page requests
session_start();
-session_write_close(); // Do not block HTTP requests
+session_write_close(); // Do not block HTTP requests
// The settings below display error on the screen,
// instead of giving blank pages.
@@ -15,310 +15,286 @@ ini_set('display_errors', true);
/**
* Run a command using the xCAT client/server protocol
*
- * @param $cmd The xCAT command
- * @param $nr Node range or group
- * @param $args_array Command arguments
- * @param $opts_array Command options
- * @return A tree of SimpleXML objects.
- * See perl-xCAT/xCAT/Client.pm for the format
+ * @param $cmd The xCAT command
+ * @param $nr Node range or group
+ * @param $args_array Command arguments
+ * @param $opts_array Command options
+ * @return A tree of SimpleXML objects. See perl-xCAT/xCAT/Client.pm for the format
*/
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 "
You are not logged in! Failed to run command.
";
- return simplexml_load_string('', 'SimpleXMLElement', LIBXML_NOCDATA);
- }
+ // If we are not logged in,
+ // do not try to communicate with xcatd
+ if (!is_logged()) {
+ echo "
You are not logged in! Failed to run command.
";
+ return simplexml_load_string('', 'SimpleXMLElement', LIBXML_NOCDATA);
+ }
- // Create xCAT request
- // Add command, node range, and arguments to request
- $request = simplexml_load_string('');
- $request->addChild('command', $cmd);
- if(!empty($nr)) { $request->addChild('noderange', $nr); }
- if (!empty($args_array)) {
- foreach ($args_array as $a) {
- $request->addChild('arg',$a);
- }
- }
+ // Create xCAT request
+ // Add command, node range, and arguments to request
+ $request = simplexml_load_string('');
+ $request->addChild('command', $cmd);
+ if (!empty($nr)) { $request->addChild('noderange', $nr); }
+ if (!empty($args_array)) {
+ foreach ($args_array as $a) {
+ $request->addChild('arg',$a);
+ }
+ }
- // Add user and password to request
- $usernode=$request->addChild('becomeuser');
- $usernode->addChild('username',$_SESSION["srv_username"]);
- $usernode->addChild('password',getpassword());
+ // Add user and password to request
+ $usernode=$request->addChild('becomeuser');
+ $usernode->addChild('username',$_SESSION["srv_username"]);
+ $usernode->addChild('password',getpassword());
- $xml = submit_request($request, 0, $opts_array);
- return $xml;
+ $xml = submit_request($request, 0, $opts_array);
+ return $xml;
}
/**
* Used by docmd() to submit request to xCAT
*
- * @param $req Tree of SimpleXML objects
- * @param $opts_array Request options
- * @return A 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, $opts_array){
- $xcathost = "localhost";
- $port = "3001";
- $rsp = FALSE;
- $response = '';
- $cleanexit = 0;
-
- // Determine whether to flush output or not
- $flush = false;
- if ($opts_array && 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 ($opts_array && 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
- openlog("xCAT-UI", LOG_PID | LOG_PERROR, LOG_LOCAL0);
+ $xcathost = "localhost";
+ $port = "3001";
+ $rsp = FALSE;
+ $response = '';
+ $cleanexit = 0;
+
+ // Determine whether to flush output or not
+ $flush = false;
+ if ($opts_array && 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 ($opts_array && 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
+ openlog("xCAT-UI", LOG_PID | LOG_PERROR, LOG_LOCAL0);
- // Open a socket to xcatd
- syslog(LOG_INFO, "Opening socket to xcatd...");
- if($fp = stream_socket_client('ssl://'.$xcathost.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT)){
- $reqXML = $req->asXML();
- $nr = $req->noderange;
- $cmd = $req->command;
-
- syslog(LOG_INFO, "Sending request: $cmd $nr");
- stream_set_blocking($fp, 0); // Set as non-blocking
- fwrite($fp,$req->asXML()); // Send XML to xcatd
- set_time_limit(900); // Set 15 minutes timeout (for long running requests)
- // The default is 30 seconds which is too short for some requests
-
- // Turn on output buffering
- ob_start();
- while(!feof($fp)) { // Read until there is no more
- // Remove newlines and add it to the response
- $str = fread($fp, 8192);
- if ($str) {
- $response .= preg_replace('/>\n\s*', '><', $str);
-
- // Flush output to browser
- if ($flush) {
- // Strip HTML tags from output
- if ($tmp = trim(strip_tags($str))) {
- // Format the output based on what was given for $flush_format
- if ($flush_format == "TDB") {
- format_TBD($tmp);
- } else {
- // Print out output by default
- echo '
' . $tmp . '
';
- ob_flush();
- flush();
- }
- }
- }
- }
-
- // Look for serverdone response
- $fullpattern = '/\s*\s*<\/serverdone>\s*<\/xcatresponse>/';
- $mixedpattern = '/\s*<\/serverdone>.*<\/xcatresponse>/';
- $recentpattern = '/<\/xcatresponse>/';
- if(preg_match($recentpattern,$str) && preg_match($mixedpattern,$response)) {
- // Transaction is done,
- // Package up XML and return it
- // Remove the serverdone response and put an xcat tag around the rest
- $count = 0;
- $response = preg_replace($fullpattern,'', $response, -1, $count); // 1st try to remove the long pattern
- if (!$count) { $response = preg_replace($mixedpattern,'', $response) . '/'; } // if its not there, then remove the short pattern
- $response = "$response";
- //delete the \n between '>' and '<'
- $response = preg_replace('/>\n\s*', '><', $response);
- //replace the '\n' by ':|:' in the data area.
- $response = preg_replace('/\n/', ':|:', $response);
- $rsp = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA);
- $cleanexit = 1;
- break;
- }
- } // End of while(!feof($fp))
-
- syslog(LOG_INFO, "($cmd $nr) Sending response");
- fclose($fp);
- } else {
- echo "
";
- }
-
- // Flush (send) the output buffer and turn off output buffering
- ob_end_flush();
+ // Open a socket to xcatd
+ syslog(LOG_INFO, "Opening socket to xcatd...");
+ if ($fp = stream_socket_client('ssl://'.$xcathost.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT)){
+ $reqXML = $req->asXML();
+ $nr = $req->noderange;
+ $cmd = $req->command;
+
+ syslog(LOG_INFO, "Sending request: $cmd $nr");
+ stream_set_blocking($fp, 0); // Set as non-blocking
+ fwrite($fp,$req->asXML()); // Send XML to xcatd
+ set_time_limit(900); // Set 15 minutes timeout (for long running requests)
+ // The default is 30 seconds which is too short for some requests
+
+ // Turn on output buffering
+ ob_start();
+ while(!feof($fp)) { // Read until there is no more
+ // Remove newlines and add it to the response
+ $str = fread($fp, 8192);
+ if ($str) {
+ $response .= preg_replace('/>\n\s*', '><', $str);
+
+ // Flush output to browser
+ if ($flush) {
+ // Strip HTML tags from output
+ if ($tmp = trim(strip_tags($str))) {
+ // Format the output based on what was given for $flush_format
+ if ($flush_format == "TDB") {
+ format_TBD($tmp);
+ } else {
+ // Print out output by default
+ echo '
' . $tmp . '
';
+ ob_flush();
+ flush();
+ }
+ }
+ }
+ }
+
+ // Look for serverdone response
+ $fullpattern = '/\s*\s*<\/serverdone>\s*<\/xcatresponse>/';
+ $mixedpattern = '/\s*<\/serverdone>.*<\/xcatresponse>/';
+ $recentpattern = '/<\/xcatresponse>/';
+ if(preg_match($recentpattern,$str) && preg_match($mixedpattern,$response)) {
+ // Transaction is done, package up XML and return it
+ // Remove the serverdone response and put an xcat tag around the rest
+ $count = 0;
+ $response = preg_replace($fullpattern,'', $response, -1, $count); // 1st try to remove the long pattern
+ if (!$count) { $response = preg_replace($mixedpattern,'', $response) . '/'; }
+ $response = "$response";
+ $response = preg_replace('/>\n\s*', '><', $response);
+ $response = preg_replace('/\n/', ':|:', $response);
+ $rsp = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA);
+ $cleanexit = 1;
+ break;
+ }
+ } // End of while(!feof($fp))
+
+ syslog(LOG_INFO, "($cmd $nr) Sending response");
+ fclose($fp);
+ } else {
+ echo "