Ejemplo n.º 1
0
 /**
  * Get the current results from the virtual commandline interface. Non-blocking. Specify an optional command_id to
  * retrieve a command's specific results or none (-1 default) to return all results of the current given session.
  *
  * @param int $command_id Optional id of a specific command to get the results for or -1 (default) to return all
  *
  * @return string The given results.
  */
 public function get_results($command_id = -1)
 {
     $args = array('wait_for' => $command_id, 'console_id' => $this->id, 'action' => 'result');
     $results = VCLIManager::send($args);
     // Filter out password and ~~~done~~~ echos if present
     $lines = explode(Chr(10), $results);
     $results = "";
     $prev = "";
     foreach ($lines as $line) {
         // Hide passwords in response to prompts
         if (substr(strtolower($prev), 0, 8) === "password") {
             $line = "********" . $this->eol;
         }
         // Hide done waiting mechanism
         if (false !== strpos($line, "~~~done~~~")) {
             $line = str_replace($this->concat_char . "echo ~~~done~~~", "", $line);
             $line = str_replace("~~~done~~~", "", $line);
         }
         // Eat echo'd command on Windows
         if (VCLIManager::$platform === 'win32') {
             if ($line === substr($prev, -strlen($line)) && strlen($prev) > strlen($line)) {
                 continue;
             }
         }
         // Eat invisible [?1034h
         if (substr($line, 0, 8) === '[?1034h') {
             $line = substr($line, 8);
         }
         $prev = $line;
         $results .= $line . Chr(10);
     }
     // Parse out the percent complete from the initial response
     $results = new GString($results);
     $this->completed = intval($results->getLeftMost("|\n"));
     return $results->delLeftMost("|\n")->__toString();
 }