children() as $response) foreach ($response->children() as $t) { $tabs[] = (string) $t; } return $tabs; } function docmd($cmd, $nr, $args){ // If for some reason we are not logged in yet, do not even try to communicate w/xcatd if (!is_logged()) { echo "
Docmd: not logged in yet - can not run command.
\n"; return simplexml_load_string('", htmlentities($response), "
\n"; // 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) . '", htmlentities($response), "
\n"; $rsp = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA); //echo ''; print_r($rsp); echo "
\n"; $cleanexit = 1; break; } } fclose($fp); }else{ echo "xCAT Submit request socket Error: $errno - $errstr
\n"; } if(! $cleanexit){ if (preg_match('/^\s*Error: xCAT response ended prematurely: ", htmlentities($response), "
"; $rsp = FALSE; } } return $rsp; } //----------------------------------------------------------------------------- // Use with submit_request() to get the data fields (output that is not node-oriented) function getXmlData(& $xml) { $data = array(); foreach ($xml->children() as $response) foreach ($response->children() as $k => $v) { if ($k == 'data') { $data[] = (string) $v; } } return $data; } //----------------------------------------------------------------------------- // Use with submit_request() to get any errors that might have occurred // Returns the errorcode and adds any error strings to the $error array passed in function getXmlErrors(& $xml, & $errors) { if (!isset($errors)) { $errors = array(); } if (!isset($xml) || $xml===FALSE) { $errors[]='rc = 1'; return 1; } $errorcode = 0; foreach ($xml->children() as $response) foreach ($response->children() as $k => $v) { if ($k == 'error') { $errors[] = (string) $v; } if ($k == 'errorcode') { $errorcode = (string) $v; } } if ($errorcode==0 && count($errors)) { $errorcode = -1 * count($errors); } // the plugin author forgot to set the errorcode return $errorcode; } function getTabHeaders($xml){ foreach ($xml->children() as $response) foreach ($response->children() as $line) { $line = (string) $line; if (ereg("^#", $line)) { $line = preg_replace('/^#/','', $line); $headers = explode(',', $line); return $headers; } } // If we get here, we never found the header line return NULL; } //----------------------------------------------------------------------------- // Parse the columns of 1 line of tabdump output //Todo: the only thing this doesn't handle is escaped double quotes. function splitTableFields($line){ $fields = array(); $line = ",$line"; // prepend a comma. this makes the parsing more consistent for ($rest=$line; !empty($rest); ) { $vals = array(); // either match everything in the 1st pair of quotes, or up to the next comma if (!preg_match('/^,"([^"]*)"(.*)$/', $rest, $vals)) { preg_match('/^,([^,]*)(.*)$/', $rest, $vals); } $fields[] = $vals[1]; $rest = $vals[2]; } return $fields; } //---------------------------------------------------------------------------- // SImilar to docmd(), but also takes in data that is the table contents. function doTabRestore($tab, & $data){ #$headers = getTabHeaders(docmd('tabdump', '', array($tab))); #$headers[0] = "#" . $headers[0]; #$request->addChild('data', implode(",",$headers)); $request = simplexml_load_string('addChild:$linestr.
\n"; $request->addChild('data', $linestr); } $request->addChild('table', $tab); $resp = submit_request($request,0); return $resp; } // Send the keys and values in the primary global arrays function dumpGlobals() { //trace('$_SERVER:'); //foreach ($_SERVER as $key => $val) { trace("$key=$val."); } //trace('$_ENV:'); //foreach ($_ENV as $key => $val) { trace("$key=$val."); } trace('$_GET:'); foreach ($_GET as $key => $val) { trace("$key=$val."); } trace('$_POST:'); foreach ($_POST as $key => $val) { trace("$key=$val."); } trace('$_COOKIE:'); foreach ($_COOKIE as $key => $val) { trace("$key=$val."); } if (isset($_SESSION)) { trace('$_SESSION:'); foreach ($_SESSION as $key => $val) { trace("$key=$val."); } } trace('$GLOBALS:'); foreach ($GLOBALS as $key => $val) { trace("$key=$val."); } } // Debug output ------------------------------------ define("TRACE", "1"); function trace($str) { if (TRACE) { echo "$str
\n"; } } // some jbj/bp stuff $xcatcmds = array( "rpower" => array("on","off","reset","stat","state","boot","off","cycle"), "rvitals" => array("all","temp","wattage","voltage","fanspeed","power","leds","state"), "reventlog" => array("all", "clear"), "rinv" => array("all", "model", "serial", "vpd", "mprom", "deviceid", "uuid", "guid", "firm", "bios", "diag", "mprom", "sprom", "mparom", "mac", "mtm"), "resetboot" => array("net", "hd", "cd", "def", "stat") ); // take in the function attributesOfNodes($ht,$meth) { $arr = array(); if($meth == 'rpower'){ $arr[] = 'Power Status'; $arr[] = 'More Actions'; return($arr); }elseif($meth == 'rbeacon'){ $arr[] = 'Beacon Status'; $arr[] = 'More Actions'; return($arr); } foreach($ht->xcatresponse as $v){ foreach($v->node as $va){ $val = (string) $va->data->desc; if($val == ""){ $val = (string) $va->data->contents; } $arr[] = $val; } } $arr = array_unique($arr); return($arr); } function mkNodeHash ($ht,$cmd){ $arr = array(); $name = ""; $desc = ""; $cont = ""; foreach($ht->children() as $response) foreach($response->children() as $node) { if($node->name) { $name = (string) $node->name; $desc = (string) $node->data->desc; if($cmd == 'rpower'){ $desc = 'Power Status'; }elseif($cmd == 'rbeacon'){ $desc = 'Beacon Status'; } $cont = (string) $node->data->contents; if($cont == ''){ $cont = (string) $node->error; } $arr[$name][$desc] = $cont; } // #print_r($response); // $name = (string) $node->name; // $desc = (string) $node->data->desc; // if($cmd == 'rpower'){ // $desc = 'Power Status'; // }elseif($cmd == 'rbeacon'){ // $desc = 'Beacon Status'; // } // $cont = (string) $node->data->contents; // if($cont == ''){ // $cont = (string) $node->error; // } // $arr[$name][$desc] = $cont; } // add the more fields so we can click in place. if($cmd == 'rpower'){ foreach($arr as $n => $val){ $html = "