2007-10-26 22:44:33 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2007-12-04 18:17:21 +00:00
|
|
|
* Action file for running xdsh/psh and output the results to the screen
|
2007-10-26 22:44:33 +00:00
|
|
|
*/
|
|
|
|
|
2007-12-04 18:17:21 +00:00
|
|
|
$TOPDIR = '..';
|
|
|
|
require_once "$TOPDIR/lib/functions.php";
|
|
|
|
|
|
|
|
|
2007-12-11 19:44:21 +00:00
|
|
|
// HTTP Headers to tell the browser to always update, never cache this page
|
|
|
|
// so the History combo box always update the new commands added whenever the page is reloaded
|
2007-10-26 22:44:33 +00:00
|
|
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // date in the past
|
|
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
|
|
|
|
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
|
|
|
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
|
|
|
header("Pragma: no-cache"); // HTTP/1.0
|
|
|
|
|
2007-12-11 19:44:21 +00:00
|
|
|
// Store command into history cookie, if it is not already there
|
2007-10-26 22:44:33 +00:00
|
|
|
$expire_time = gmmktime(0, 0, 0, 1, 1, 2038);
|
2007-12-18 15:30:44 +00:00
|
|
|
//echo "<p>{$_REQUEST['command']},"; foreach ($_COOKIE['history'] as $h) { echo "$h,"; }; echo "</p>\n";
|
|
|
|
//echo "<p>" . isset($_COOKIE['history']) . ',' . array_search($_REQUEST['command'], $_COOKIE['history']) . "</p>\n";
|
|
|
|
if (isset($_COOKIE['history']) && array_search($_REQUEST['command'], $_COOKIE['history'])!==FALSE) {
|
2007-12-11 19:44:21 +00:00
|
|
|
// this command is already in the history, so do not need to add it
|
|
|
|
} else {
|
|
|
|
$i = isset($_COOKIE['history']) ? count($_COOKIE['history']) : 0;
|
|
|
|
setcookie("history[$i]", $_REQUEST['command'], $expire_time);
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2007-12-11 19:44:21 +00:00
|
|
|
//print_r($_COOKIE);
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
//get the command and the options
|
|
|
|
$cmd = @$_REQUEST["command"];
|
|
|
|
$copy = @$_REQUEST["copy"];
|
|
|
|
$node = @$_REQUEST["node"];
|
|
|
|
$group = @$_REQUEST["nodegrps"];
|
|
|
|
$psh = @$_REQUEST["psh"];
|
|
|
|
|
|
|
|
$serial = @$_REQUEST["serial"];
|
|
|
|
$verify = @$_REQUEST["verify"];
|
|
|
|
$collapse = @$_REQUEST["collapse"];
|
|
|
|
$fanout = @$_REQUEST["fanout"];
|
|
|
|
$userID = @$_REQUEST["userID"];
|
|
|
|
$rshell = @$_REQUEST["rshell"];
|
|
|
|
$shell_opt = @$_REQUEST["shell_opt"];
|
|
|
|
$monitor = @$_REQUEST["monitor"];
|
|
|
|
$ret_code = @$_REQUEST["ret_code"];
|
|
|
|
|
|
|
|
|
2007-12-11 19:44:21 +00:00
|
|
|
//if ($group == "") $nodegrps = "blade7"; // For now, use blade7 as test node
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
if ($psh == "off"){ //using dsh
|
2007-12-04 18:17:21 +00:00
|
|
|
$command = "xdsh ";
|
|
|
|
$copy_cmd = "xdcp ";
|
2008-01-17 20:33:12 +00:00
|
|
|
if ($group == "") $node_group = /* "-n " . */ $node;
|
|
|
|
else $node_group = /* "-N " . */ $group;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
}else{
|
2007-12-04 18:17:21 +00:00
|
|
|
$command = "psh ";
|
2008-01-17 20:33:12 +00:00
|
|
|
$copy_cmd = "pscp ";
|
2007-12-11 19:44:21 +00:00
|
|
|
if ($group == "") $node_group = $node;
|
2007-10-26 22:44:33 +00:00
|
|
|
else $node_group = $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($serial == "on") $options = "-s "; //serial mode/streaming mode
|
|
|
|
if ($fanout == "") $options .= "-f 64 "; else $options .= "-f " . $fanout;
|
|
|
|
if ($userID != "") $options .= "-l " . $userID;
|
|
|
|
if ($verify == "on") $options .= "-v ";
|
|
|
|
if ($monitor == "on") $options .= "-m ";
|
|
|
|
|
2007-12-04 18:17:21 +00:00
|
|
|
//echo "<p>Command: ". $cmd ."</p>";
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2007-12-04 18:17:21 +00:00
|
|
|
//$exp_cmd = "export DSH_CONTEXT=XCAT XCATROOT=/opt/xcat; ";
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
if ($copy == "on"){ //using dcp/prcp
|
|
|
|
|
|
|
|
//extract the script name from the command
|
|
|
|
$script = strtok($cmd,' ');
|
|
|
|
|
|
|
|
//copy the command to the remote node
|
|
|
|
$source = "/opt/xcat/bin/" . $script; //copy from
|
|
|
|
$target = "/tmp"; //copy to
|
|
|
|
if ($psh == "off"){
|
2007-12-04 18:17:21 +00:00
|
|
|
$copy_cmd = $exp_cmd . $copy_cmd . $node_group . " " . $source . " " . $target;
|
2007-10-26 22:44:33 +00:00
|
|
|
}else{
|
2007-12-04 18:17:21 +00:00
|
|
|
$copy_cmd = $copy_cmd . $source . " " . $node_group . ":" . $target;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
runcmd($copy_cmd,1, $outp);
|
|
|
|
|
|
|
|
if ($psh != "on"){
|
2007-12-04 18:17:21 +00:00
|
|
|
$command_string = $exp_cmd . $command. $node_group . " /tmp/" . $cmd;
|
2007-10-26 22:44:33 +00:00
|
|
|
}else{
|
2007-12-04 18:17:21 +00:00
|
|
|
$command_string = $command . $node_group . " /tmp/" . $cmd;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if ($psh != "on"){
|
2007-12-04 18:17:21 +00:00
|
|
|
$command_string = $exp_cmd . $command. $node_group . " " . $cmd;
|
2007-10-26 22:44:33 +00:00
|
|
|
}else{
|
2007-12-04 18:17:21 +00:00
|
|
|
$command_string = $command . $node_group . " " . $cmd;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-04 18:17:21 +00:00
|
|
|
if ($collapse == "on") $command_string .= " | dshbak -c";
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2007-12-04 18:17:21 +00:00
|
|
|
echo "<p><b>Command: $command_string</b></p>";
|
|
|
|
//echo "<p><b>Command Ouput:</b></br></p>"; //output will be returned from the runcmd function call
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
//run the script
|
2007-12-04 18:17:21 +00:00
|
|
|
$output = array();
|
2007-10-26 22:44:33 +00:00
|
|
|
if ($ret_code == "on"){
|
2007-12-04 18:17:21 +00:00
|
|
|
$rc = runcmd($command_string, 0, $output); //mode 0
|
2007-10-26 22:44:33 +00:00
|
|
|
if ($rc == 0){
|
2007-12-11 19:44:21 +00:00
|
|
|
foreach ($output as $line){ echo "$line<br>"; }
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
2007-12-04 18:17:21 +00:00
|
|
|
//$rc = runcmd($command_string,1, $outp); //streaming mode - DOES NOT WORK YET
|
|
|
|
$rc = runcmd($command_string, 0, $output); //mode 0
|
2007-10-26 22:44:33 +00:00
|
|
|
if ($rc == 0){
|
2007-12-04 18:17:21 +00:00
|
|
|
foreach ($output as $line){ echo "$line<br>"; }
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************************
|
|
|
|
* TEST PART
|
|
|
|
* for now just use system command on the server, not using psh to run cmds on the nodes
|
|
|
|
***************************************************************************************/
|
|
|
|
|
|
|
|
//test case 1: mode 1 (or -1)
|
|
|
|
/*$rc = runcmd($cmd,1, $outp);
|
|
|
|
echo "</br> RC to caller: " . $rc . "</br>";*/
|
|
|
|
//passed
|
|
|
|
|
|
|
|
//test case 2: mode 3
|
|
|
|
/*$rc = runcmd($cmd,3, $outp, array('NoRedirectStdErr' => TRUE));
|
|
|
|
echo "RC to caller: " . $rc . "</br>";
|
|
|
|
echo "Ouput file handle: " . $outp . "</br>";
|
|
|
|
echo "Results: " . "</br>";
|
|
|
|
if ($outp){
|
|
|
|
while (!feof($outp)){
|
|
|
|
$read = fgets($outp);
|
|
|
|
echo $read;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
//passed
|
|
|
|
|
|
|
|
//testcase 3: mode 0
|
|
|
|
/*$rc = runcmd($cmd,0, $outp, array('NoRedirectStdErr' => TRUE));
|
|
|
|
if ($rc == 0) echo "Results: ";
|
|
|
|
foreach ($outp as $key => $val){
|
|
|
|
echo $val. ";";
|
|
|
|
}*/
|
|
|
|
//passed
|
|
|
|
|
|
|
|
//testcase 4: mode 2
|
|
|
|
/*$rc = runcmd($cmd,2, $outp, array('NoRedirectStdErr' => TRUE));
|
|
|
|
echo "Results: " . $outp;*/
|
|
|
|
//passed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
//history cookie
|
|
|
|
if ($rc == 0){ // no error
|
|
|
|
if (isset($_COOKIE["history"])){ //append to the old cookie
|
|
|
|
//avoid repetitive entries when user hit "Refresh" button
|
|
|
|
if (strstr($_COOKIE["history"], ';') == FALSE){ //just have one entry in the history cookie
|
|
|
|
if (strcmp($_COOKIE["history"],$cmd_text) <> 0){
|
|
|
|
$cmd_history = $_COOKIE["history"] . ";" . $cmd_text;
|
|
|
|
setcookie("history",$cmd_history,$expire_time);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$string = $_COOKIE["history"];
|
|
|
|
$token = strtok($string, ';');
|
|
|
|
$is_repetitive = 0;
|
|
|
|
if (strcmp($token,$cmd_text) <> 0) $is_repetitive = 1;
|
|
|
|
while (FALSE !== ($token = strtok(';'))) {
|
|
|
|
if (strcmp($token,$cmd_text) <> 0) $is_repetitive = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($is_repetitive == 0){ //the new command is not repetitive
|
|
|
|
$cmd_history = $_COOKIE["history"] . ";" . $cmd_text;
|
|
|
|
setcookie("history",$cmd_history,$expire_time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{ //first time, write new
|
|
|
|
$cmd_history = $cmd_text;
|
|
|
|
setcookie("history",$cmd_history,$expire_time); //cookie lasts 30 days
|
|
|
|
}
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
2007-12-11 19:44:21 +00:00
|
|
|
?>
|