children() as $child) { foreach ($child->children() as $data) { $data = str_replace(":|:", "\n", $data); array_push($rsp, "$data"); } } } // Create virtual server else if (strncasecmp($cmd, "mkvm", 4) == 0) { // Directory /var/tmp permissions = 777 // You can write anything to that directory $userEntry = "/var/tmp/$tgt.txt"; $handle = fopen($userEntry, 'w') or die("Cannot open $userEntry"); fwrite($handle, $att); fclose($handle); // CLI command: mkvm gpok3 /tmp/gpok3.txt // Create user entry array_unshift($arr, $userEntry); $xml = docmd($cmd, $tgt, $arr, NULL); foreach ($xml->children() as $child) { foreach ($child->children() as $data) { $data = str_replace(":|:", "\n", $data); array_push($rsp, "$data"); } } } // Run shell script // This is a typical command used by all platforms. It is put here because // most of the code needed are already here else if (strncasecmp($cmd, "xdsh", 4) == 0) { // Directory /var/tmp permissions = 777 // You can write anything to that directory $msgArgs = explode(";", $msg); $inst = str_replace("out=scriptStatusBar", "", $msgArgs[0]); $script = "/var/tmp/script$inst.sh"; // Write to file $handle = fopen($script, 'w') or die("Cannot open $script"); fwrite($handle, $att); fclose($handle); // Change it to executable chmod($script, 0777); // CLI command: xdsh gpok3 -e /var/tmp/gpok3.sh // Create user entry array_push($arr, $script); $xml = docmd($cmd, $tgt, $arr, NULL); foreach ($xml->children() as $child) { foreach ($child->children() as $data) { $data = str_replace(":|:", "\n", $data); array_push($rsp, "$data"); } } // Remove this file unlink($script); } // Remove any HTML that could be used for XSS attacks foreach ($rsp as $key => &$value) { $whatami = gettype($value); if ("string" != $whatami) { //echo "found a non string in rsp array \n"; foreach ($value as $key2 => $value2){ //echo "Key2:$key2 Value2 type:",gettype($value2)," value2 data: $value2 \n"; $value[$key2] = htmlentities($value2, ENT_QUOTES | ENT_HTML5, 'UTF-8'); } } else { //echo "Key:$key Value type:",gettype($value)," value data: $value \n"; $rsp[$key] = htmlentities($value, ENT_QUOTES | ENT_HTML5, 'UTF-8'); //echo "New value: $rsp[$key] \n"; } } $msg = htmlentities($msg, ENT_QUOTES | ENT_HTML5, 'UTF-8'); // Reply in the form of JSON $rtn = array("rsp" => $rsp, "msg" => $msg); echo json_encode($rtn); } ?>