/** * 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 */ 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 "<p>You are not logged in! Failed to run command.</p>"; return simplexml_load_string('<xcat></xcat>', 'SimpleXMLElement', LIBXML_NOCDATA); } // Create xCAT request // Add command, node range, and arguments to request $request = simplexml_load_string('<xcatrequest></xcatrequest>'); $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["username"]); $usernode->addChild('password', getpassword()); $xml = submit_request($request, 0, $opts_array); return $xml; }
// Change quotes to " if (!empty($col) && !preg_match('/^".*"$/', $col)) { $col = '"' . $col . '"'; } } // Sort line ksort($line, SORT_NUMERIC); $keys = array_keys($line); $max = count($line) - 1; if ($keys[$max] != $max) { for ($i = 0; $i <= $keys[$max]; $i++) { if (!isset($line[$i])) { $line[$i] = ''; } } ksort($line, SORT_NUMERIC); } // Create string containing all array elements $str = implode(",", $line); // Replace " with " $str = str_replace('"', '"', $str); // Replace ' with ' $str = str_replace("'", ''', $str); $request->addChild('data', $str); } // Run command $request->addChild('table', $tab); $xml = submit_request($request, 0, NULL); // Reply in the form of JSON $rtn = array("rsp" => $xml); echo json_encode($rtn);