Beispiel #1
0
 /**
  * Creates an Virtual CLI (job) object to submit commands to the native vcli service.
  *
  * @param null $id A unique ID to identify the command line interface session.
  * @param int $timeout The amount of time allocated for any given command to execute before a timeout occurs.
  * @param string $shell The initial shell to use for the CLI. Defaults to native environment shell.
  * @param null $wait Optional initial substring to wait for when the CLI is initialized.
  * @param string $concat_char Optional override for the command concatenation character.
  */
 public function __construct($id = null, $timeout = 60, $shell = null, $wait = null, $concat_char = null)
 {
     // Windows default usually c:\windows\System32\cmd.exe from ComSpec and /bin/bash from SHELL on *nix
     if ($shell === null) {
         if (VCLIManager::$platform === 'win32') {
             $shell = getenv("ComSpec");
         } else {
             $shell = getenv("SHELL");
         }
     }
     // Windows default is "Microsoft Windows" and "bash" for *nix
     if ($wait === null) {
         if (VCLIManager::$platform === 'win32') {
             $wait = "Microsoft Windows";
         } else {
             $wait = "bash";
         }
     }
     // Allow customization of the command concatenation character
     if ($concat_char === null) {
         if (VCLIManager::$platform === 'win32') {
             $concat_char = "&";
         } else {
             $concat_char = ";";
         }
     }
     $this->concat_char = $concat_char;
     // Create new instance and unique id if none supplied
     if ($id === null) {
         $id = uniqid() . dechex(rand(0, 32000));
         // Immediately create the native shell instance
         $args = array('console_id' => $id, 'timeout' => $timeout, 'wait_for' => $wait, 'action' => 'create', 'command' => $shell);
         VCLIManager::send($args);
         // Check for existing instance by name and create it if nec
     } else {
         if (!VCLIManager::has_cli($id)) {
             $args = array('console_id' => $id, 'timeout' => $timeout, 'wait_for' => $wait, 'action' => 'create', 'command' => $shell);
             VCLIManager::send($args);
         }
     }
     $this->id = $id;
 }
Beispiel #2
0
 /**
  * Used to retrieve an existing virtual command line interface object by the given id. The object can be used to
  * add commands, get results, and query the status.
  *
  * @param $id The identifier used to create the initial instance of the VirtualCLI object.
  *
  * @return VirtualCLI The VirtualCLI object as referenced by the given id or false.
  */
 static function get_cli($id)
 {
     if (VCLIManager::has_cli($id)) {
         return new VirtualCLI($id);
     } else {
         return false;
     }
 }