2010-06-16 18:21:58 +00:00
|
|
|
<?php
|
|
|
|
/* Required libraries */
|
|
|
|
$TOPDIR = '..';
|
|
|
|
require_once "$TOPDIR/lib/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.
|
|
|
|
*
|
|
|
|
* @param $cmd The xCAT command
|
2011-04-15 20:46:23 +00:00
|
|
|
* @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
|
2010-06-16 18:21:58 +00:00
|
|
|
* @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"];
|
2011-04-12 19:46:01 +00:00
|
|
|
|
2012-04-20 03:50:58 +00:00
|
|
|
// File contents in case of file write
|
|
|
|
if (isset($_GET["cont"])) {
|
|
|
|
$cont = $_GET["cont"];
|
|
|
|
}
|
|
|
|
|
2010-06-16 18:21:58 +00:00
|
|
|
// Special messages put here
|
|
|
|
// This gets sent back to the AJAX request as is.
|
|
|
|
$msg = $_GET["msg"];
|
|
|
|
|
|
|
|
// If no $tgt is given, set $tgt to NULL
|
|
|
|
if (!$tgt) {
|
|
|
|
$tgt = NULL;
|
|
|
|
}
|
2011-01-13 23:06:31 +00:00
|
|
|
|
2010-06-16 18:21:58 +00:00
|
|
|
// If no $msg is given, set $msg to NULL
|
|
|
|
if (!$msg) {
|
|
|
|
$msg = NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-12 19:46:01 +00:00
|
|
|
// If no $args are given, set $args_array to NULL
|
|
|
|
$args_array = array();
|
|
|
|
if ($args) {
|
2011-01-13 23:06:31 +00:00
|
|
|
// If $args contains multiple arguments, split it into an array
|
|
|
|
if (strpos($args,";")) {
|
|
|
|
// Split the arguments into an array
|
2011-04-12 19:46:01 +00:00
|
|
|
$args_array = array();
|
|
|
|
$args_array = explode(";", $args);
|
|
|
|
} else {
|
|
|
|
$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);
|
2011-01-13 23:06:31 +00:00
|
|
|
} else {
|
2011-04-12 19:46:01 +00:00
|
|
|
$opts_array = array($opts);
|
2011-01-13 23:06:31 +00:00
|
|
|
}
|
2010-06-16 18:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Submit request and get response
|
2011-04-12 19:46:01 +00:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2010-06-16 18:21:58 +00:00
|
|
|
$rsp = array();
|
|
|
|
|
2010-11-05 22:53:47 +00:00
|
|
|
// webrun pping and gangliastatus output needs special handling
|
2010-11-09 05:05:10 +00:00
|
|
|
if(strncasecmp($cmd, "webrun", 6) == 0 && (stristr($args, "pping") || stristr($args, "gangliastatus") || stristr($args, "chtab"))) {
|
2010-06-16 18:21:58 +00:00
|
|
|
$rsp = extractWebrun($xml);
|
|
|
|
}
|
|
|
|
// nodels output needs special handling
|
|
|
|
else if(strncasecmp($cmd, "nodels", 6) == 0) {
|
|
|
|
// Handle the output the same way as webrun
|
2010-10-27 02:59:50 +00:00
|
|
|
$rsp = extractNodels($xml);
|
2010-06-16 18:21:58 +00:00
|
|
|
}
|
|
|
|
// extnoderange output needs special handling
|
|
|
|
// This command gets the nodes and groups
|
|
|
|
else if(strncasecmp($cmd, "extnoderange", 12) == 0) {
|
|
|
|
$rsp = extractExtnoderange($xml);
|
2012-04-20 03:50:58 +00:00
|
|
|
}
|
|
|
|
// Write contents to file
|
|
|
|
else if(strncasecmp($cmd, "write", 4) == 0) {
|
|
|
|
// Directory should be /var/opt/xcat/profiles
|
|
|
|
// You can write anything to that directory
|
|
|
|
$file = "$tgt";
|
|
|
|
$handle = fopen($file, 'w') or die("Cannot open $file");
|
|
|
|
fwrite($handle, $cont);
|
|
|
|
fclose($handle);
|
|
|
|
|
|
|
|
$rsp = "Directory entry written to $file";
|
2010-06-16 18:21:58 +00:00
|
|
|
}
|
|
|
|
// Handle the typical output
|
|
|
|
else {
|
|
|
|
foreach ($xml->children() as $child) {
|
2010-07-22 21:26:17 +00:00
|
|
|
foreach ($child->children() as $data) {
|
|
|
|
if($data->name) {
|
2012-02-03 18:22:33 +00:00
|
|
|
$node = $data->name;
|
2010-08-03 12:45:51 +00:00
|
|
|
|
2011-08-23 03:53:52 +00:00
|
|
|
if ($data->data->contents) {
|
2010-08-03 12:45:51 +00:00
|
|
|
$cont = $data->data->contents;
|
2011-08-23 03:53:52 +00:00
|
|
|
} else {
|
2010-08-03 12:45:51 +00:00
|
|
|
$cont = $data->data;
|
|
|
|
}
|
|
|
|
|
2011-08-23 03:53:52 +00:00
|
|
|
if ($data->data->desc) {
|
|
|
|
$cont = $data->data->desc . ": " . $cont;
|
|
|
|
}
|
|
|
|
|
2010-07-29 20:22:09 +00:00
|
|
|
$cont = str_replace(":|:", "\n", $cont);
|
2010-07-22 21:26:17 +00:00
|
|
|
array_push($rsp, "$node: $cont");
|
|
|
|
} else if(strlen("$data") > 2) {
|
2010-07-29 20:22:09 +00:00
|
|
|
$data = str_replace(":|:", "\n", $data);
|
2010-07-22 21:26:17 +00:00
|
|
|
array_push($rsp, "$data");
|
2010-07-22 19:56:09 +00:00
|
|
|
}
|
2010-06-16 18:21:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reply in the form of JSON
|
|
|
|
$rtn = array("rsp" => $rsp, "msg" => $msg);
|
|
|
|
echo json_encode($rtn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the output for a webrun command
|
|
|
|
*
|
|
|
|
* @param $xml The XML output from docmd()
|
|
|
|
* @return An array containing the output
|
|
|
|
*/
|
|
|
|
function extractWebrun($xml) {
|
|
|
|
$rsp = array();
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
// Extract data returned
|
|
|
|
foreach($xml->children() as $nodes){
|
|
|
|
foreach($nodes->children() as $node){
|
|
|
|
// Get the node name
|
|
|
|
$name = $node->name;
|
2010-11-05 22:53:47 +00:00
|
|
|
|
2010-06-16 18:21:58 +00:00
|
|
|
// Get the content
|
2010-11-05 22:53:47 +00:00
|
|
|
$status = $node->data;
|
2010-07-29 20:22:09 +00:00
|
|
|
$status = str_replace(":|:", "\n", $status);
|
2010-06-16 18:21:58 +00:00
|
|
|
|
|
|
|
// Add to return array
|
|
|
|
$rsp[$i] = array("$name", "$status");
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rsp;
|
|
|
|
}
|
|
|
|
|
2010-10-27 02:59:50 +00:00
|
|
|
/**
|
|
|
|
* Extract the output for a nodels command
|
|
|
|
*
|
|
|
|
* @param $xml The XML output from docmd()
|
|
|
|
* @return An array containing the output
|
|
|
|
*/
|
|
|
|
function extractNodels($xml) {
|
|
|
|
$rsp = array();
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
// Extract data returned
|
|
|
|
foreach($xml->children() as $nodes){
|
|
|
|
foreach($nodes->children() as $node){
|
|
|
|
// Get the node name
|
|
|
|
$name = $node->name;
|
|
|
|
// Get the content
|
|
|
|
$status = $node->data->contents;
|
|
|
|
$status = str_replace(":|:", "\n", $status);
|
|
|
|
|
|
|
|
$description = $node->data->desc;
|
|
|
|
// Add to return array
|
|
|
|
$rsp[$i] = array("$name", "$status", "$description");
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rsp;
|
|
|
|
}
|
|
|
|
|
2010-06-16 18:21:58 +00:00
|
|
|
/**
|
|
|
|
* Extract the output for a extnoderange command
|
|
|
|
*
|
|
|
|
* @param $xml The XML output from docmd()
|
|
|
|
* @return The nodes and groups
|
|
|
|
*/
|
|
|
|
function extractExtnoderange($xml) {
|
|
|
|
$rsp = array();
|
|
|
|
|
|
|
|
// Extract data returned
|
|
|
|
foreach ($xml->xcatresponse->intersectinggroups as $group) {
|
|
|
|
array_push($rsp, "$group");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rsp;
|
|
|
|
}
|
|
|
|
?>
|