Creates an interactive shell

@see self::interactiveRead()
@see self::interactiveWrite()
@return bool
@access private
337272
function _initShell()
    {
        // connect using the sample parameters in protocol-1.5.txt.
        // according to wikipedia.org's entry on text terminals, "the fundamental type of application running on a text
        // terminal is a command line interpreter or shell".  thus, opening a terminal session to run the shell.
        $data = pack('CNa*N4C', NET_SSH1_CMSG_REQUEST_PTY, strlen('vt100'), 'vt100', 24, 80, 0, 0, self::TTY_OP_END);

        if (!$this->_send_binary_packet($data)) {
            user_error('Error sending SSH_CMSG_REQUEST_PTY');
            return false;
        }

        $response = $this->_get_binary_packet();

        if ($response === true) {
            return false;
        }
        if ($response[self::RESPONSE_TYPE] != NET_SSH1_SMSG_SUCCESS) {
            user_error('Expected SSH_SMSG_SUCCESS');
            return false;
        }

        $data = pack('C', NET_SSH1_CMSG_EXEC_SHELL);

        if (!$this->_send_binary_packet($data)) {
            user_error('Error sending SSH_CMSG_EXEC_SHELL');
            return false;
        }

        $this->bitmap |= self::MASK_SHELL;

        //stream_set_blocking($this->fsock, 0);

        return true;
    }
419696
protected function exec()
    {
        $descriptors = [
           0 => ["pipe", "r"],  // stdin is a pipe that the child will read from
           1 => ["pipe", "w"],  // stdout is a pipe that the child will write to
           2 => ["pipe", "w"] // stderr is a file to write to
        ];
        
        $process = proc_open($this->getCommand(), $descriptors, $pipes, dirname($this->getJarPath()), []);

        if (is_resource($process)) {
            fclose($pipes[0]); // close stdin pipe
            $this->output = stream_get_contents($pipes[1]);
            $this->errors = stream_get_contents($pipes[2]);
            fclose($pipes[2]);
            fclose($pipes[1]);                       
            if(proc_close($process) === -1) {
                throw new RuntimeException($this->errors);
            }
        }            
    }
319094
protected function write()
    {
        if (!isset($this->pipes[0])) {
            return;
        }
        $input = $this->input;

        if ($input instanceof \Iterator) {
            if (!$input->valid()) {
                $input = null;
            } elseif (is_resource($input = $input->current())) {
                stream_set_blocking($input, 0);
            } elseif (!isset($this->inputBuffer[0])) {
                if (!is_string($input)) {
                    if (!is_scalar($input)) {
                        throw new InvalidArgumentException(sprintf('%s yielded a value of type "%s", but only scalars and stream resources are supported', get_class($this->input), gettype($input)));
                    }
                    $input = (string) $input;
                }
                $this->inputBuffer = $input;
                $this->input->next();
                $input = null;
            } else {
                $input = null;
            }
        }

        $r = $e = array();
        $w = array($this->pipes[0]);

        // let's have a look if something changed in streams
        if (false === $n = @stream_select($r, $w, $e, 0, 0)) {
            return;
        }

        foreach ($w as $stdin) {
            if (isset($this->inputBuffer[0])) {
                $written = fwrite($stdin, $this->inputBuffer);
                $this->inputBuffer = substr($this->inputBuffer, $written);
                if (isset($this->inputBuffer[0])) {
                    return array($this->pipes[0]);
                }
            }

            if ($input) {
                for (;;) {
                    $data = fread($input, self::CHUNK_SIZE);
                    if (!isset($data[0])) {
                        break;
                    }
                    $written = fwrite($stdin, $data);
                    $data = substr($data, $written);
                    if (isset($data[0])) {
                        $this->inputBuffer = $data;

                        return array($this->pipes[0]);
                    }
                }
                if (feof($input)) {
                    if ($this->input instanceof \Iterator) {
                        $this->input->next();
                    } else {
                        $this->input = null;
                    }
                }
            }
        }

        // no input to read on resource, buffer is empty
        if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) {
            $this->input = null;
            fclose($this->pipes[0]);
            unset($this->pipes[0]);
        } elseif (!$w) {
            return array($this->pipes[0]);
        }
    }
639277
public function build()
    {
        $streams = '';
        foreach ($this->data as $data) {
            // Add start and headers
            $streams .= "--{$this->getBoundary()}\r\n".
                $this->getHeaders($data['headers'])."\r\n";

            // Convert the stream to string
            /* @var $contentStream StreamInterface */
            $contentStream = $data['contents'];
            if ($contentStream->isSeekable()) {
                $streams .= $contentStream->__toString();
            } else {
                $streams .= $contentStream->getContents();
            }

            $streams .= "\r\n";
        }

        // Append end
        $streams .= "--{$this->getBoundary()}--\r\n";

        return $this->streamFactory->createStream($streams);
    }
625840
function write($cmd)
    {
        if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
            user_error('Operation disallowed prior to login()', E_USER_NOTICE);
            return false;
        }

        if (!($this->bitmap & NET_SSH2_MASK_SHELL) && !$this->_initShell()) {
            user_error('Unable to initiate an interactive shell session', E_USER_NOTICE);
            return false;
        }

        return $this->_send_channel_packet(NET_SSH2_CHANNEL_SHELL, $cmd);
    }
313029
public function interactive()
    {
        echo "welcome! please input command('quit' or 'exit' to Quit).\n ";

        while (true) {
            echo '> ';
            if ($cmd = trim(fgets(\STDIN))) {
                // echo "input command: $cmd\n";
                if ($cmd === 'quit' || $cmd === 'exit') {
                    echo "Quit. Bye\n";
                    break;
                }

                echo $this->command($cmd) . PHP_EOL;
            }

            usleep(50000);
        }

        $this->close();
    }
1207245
public function makeRelative() {
    $this->cygwin = FALSE;
    $this->wrapper = NULL;
    $this->prefix = NULL;
    return $this;
  }
13176
public function create()
	{
		// Element fields, so don´t use parent construct method
		$GLOBALS['TL_DCA']['tl_content']['palettes'][$this->element] .= ',protected';
		$GLOBALS['TL_DCA']['tl_content']['fields']['protected']['eval']['tl_class'] = 'clr'; // push to new row (clear)

		// The groups field
		if (!$this->canChangeGroups)
		{
			if(($key = array_search('protected', $GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'])) !== false) {
				unset($GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'][$key]);
			}
			
			unset($GLOBALS['TL_DCA']['tl_content']['subpalettes']['protected']);
			
			$GLOBALS['TL_DCA']['tl_content']['fields']['protected']['eval']['submitOnChange'] = false;
			
			// Overwrite the elements groups with groups from the pattern
			$db = Database::getInstance();
			$db->prepare("UPDATE tl_content SET groups=? WHERE id=?")
			   ->execute($this->groups, $this->cid);
		}
		
		// The guests field
		if ($this->canChangeGuests)
		{
			$GLOBALS['TL_DCA']['tl_content']['palettes'][$this->element] .= ',guests';
		}
	}
41438
public function init()
    {
        $this->header('Content-Type: text/plain');

        $this->proc = new \PHPDaemon\Core\ShellCommand();
        $this->proc->onReadData(function ($stream, $data) {
            echo $data;
        });
        $this->proc->onEOF(function ($stream) {
            $this->wakeup();
        });
        $this->proc->nice(256);
        $this->proc->execute('/bin/ls -l /tmp');
    }
528748
public function create() 
    {
        try {            
            $fileData['alias'] = Input::get('filename') ? Input::get('filename') : date('m.d.Y - G:i:s');
            $fileData['type'] = 'folder';
            if(Input::get('pid') > 0) {
                $fileData['parent_id'] = Input::get('pid');
            }
            
            $this->file->create($fileData);

            return response()->json([
                'status' => 'success'
            ]);
        }
        
        catch (Exception $e) {
            return $this->handleError($e);
        }
    }
107832
public function create()
	{
		// Element fields, so don´t use parent construct method
		$GLOBALS['TL_DCA']['tl_content']['palettes'][$this->element] .= ',invisible';
		$GLOBALS['TL_DCA']['tl_content']['fields']['invisible']['eval']['tl_class'] = 'clr'; // push to new row (clear)
	
		// The start field
		if ($this->canChangeStart)
		{
			$GLOBALS['TL_DCA']['tl_content']['palettes'][$this->element] .= ',start';
		}
		// The stop field
		if ($this->canChangeStop)
		{
			$GLOBALS['TL_DCA']['tl_content']['palettes'][$this->element] .= ',stop';
		}		
	}
109356
public function write()
	{
		// do we have something to write?
		if ( ! empty($this->keys) or ! empty($this->data) or ! empty($this->flash))
		{
			parent::write();

			// rotate the session id if needed
			$this->rotate(false);

			// record the last update time of the session
			$this->keys['updated'] = $this->time->get_timestamp();

			// then update the cookie
			$this->_set_cookie(array($this->keys, $this->data, $this->flash));
		}

		return $this;
	}
34432
protected function createContainer() {

		\Pressbooks\Utility\put_contents(
			$this->tmpDir . '/mimetype',
			utf8_decode( 'application/epub+zip' )
		);

		mkdir( $this->tmpDir . '/META-INF' );
		mkdir( $this->tmpDir . '/OEBPS' );
		mkdir( $this->tmpDir . '/OEBPS/assets' );

		\Pressbooks\Utility\put_contents(
			$this->tmpDir . '/META-INF/container.xml',
			$this->loadTemplate( $this->dir . '/templates/epub201/container.php' )
		);

		\Pressbooks\Utility\put_contents(
			$this->tmpDir . '/META-INF/com.apple.ibooks.display-options.xml',
			$this->loadTemplate( $this->dir . '/templates/epub201/ibooks.php' )
		);

	}
316778
function write($cmd)
    {
        if (!$this->isAuthenticated()) {
            user_error('Operation disallowed prior to login()');
            return false;
        }

        if (!($this->bitmap & self::MASK_SHELL) && !$this->_initShell()) {
            user_error('Unable to initiate an interactive shell session');
            return false;
        }

        return $this->_send_channel_packet($this->_get_interactive_channel(), $cmd);
    }
621932
function ShellCraft() {
  var self = this;

  var ArgumentsList = require('./lib/argumentslist.js');
  var Prompt = require('./lib/prompt.js');

  self._exit = false;
  self._shell = true; /* open the shell be default */
  self._scope = 'global';

  self.arguments = new ArgumentsList();
  self.arguments._add(
    'exit',
    new Command(
      function(callback) {
        self._exit = true;
        if (callback) {
          callback();
        }
      },
      {builtIn: true, scope: '*'},
      'exit the shell'
    )
  );

  self.arguments._add(
    'help',
    new Command(
      function(callback) {
        Object.keys(Object.getPrototypeOf(self.arguments)).forEach(function(
          fct
        ) {
          if (
            !self.arguments.hasOwnProperty(fct) &&
            !/^_/.test(fct) &&
            self.arguments[fct].type() === 'command' &&
            self.arguments[fct].isScoped(self._scope)
          ) {
            console.log(self.arguments[fct].help());
          }
        });

        console.log('');

        if (callback) {
          callback();
        }
      },
      {builtIn: true, scope: '*'},
      'list of commands'
    )
  );

  self.arguments._add(
    'scope',
    new Command(
      function(callback, scope) {
        self._scope = scope[0] || 'global';
        self.autocomplete.reload();
        self.prompt.setScope(self._scope !== 'global' ? scope : '');

        if (callback) {
          callback();
        }
      },
      {
        builtIn: true,
        scope: '*',
        params: {
          optional: 'scope',
        },
      },
      function() {
        var help = 'change scope';
        var scopes = [];

        /* Look for all available scopes */
        Object.keys(Object.getPrototypeOf(self.arguments)).forEach(function(
          fct
        ) {
          if (
            !self.arguments.hasOwnProperty(fct) &&
            !/^_/.test(fct) &&
            self.arguments[fct].type() === 'command'
          ) {
            var scope = self.arguments[fct].scope();
            if (scope === '*' || scope === 'global') {
              return;
            }

            if (scopes.indexOf(scope) === -1) {
              scopes.push(self.arguments[fct].scope());
            }
          }
        });

        var list = scopes.length ? ' (' + scopes.join(', ') + ')' : '';
        return help + list;
      }
    )
  );

  self.options = {
    version: '0.0.1',
  };
  self.prompt = new Prompt();
  self.extensions = {};

  /* HACK inquirer prefix */
  Object.keys(inquirer.prompt.prompts).forEach(function(prompt) {
    inquirer.prompt.prompts[prompt].prototype.getQuestion = function() {
      var msg = inquirer.prompt.prompts[
        prompt
      ].super_.prototype.getQuestion.bind(this)();
      return msg.replace(/[^ ]*\?[^ ]* /, '');
    };
  });
}
498512
public function createScript()
    {
        if ($this->script) {
            return $this->script;
        }
        $script = new Script();
        $this->setScript($script);
        return $this->script;
    }
325630
public function construct()
	{
		// Get command name from user input
		$name = null;
		if ($this->arguments->getOpt('n') || $this->arguments->getOpt('name') || $this->arguments->getOpt(4))
		{
			// Set name, according to priority of inputs
			$name = ($this->arguments->getOpt(4)) ? $this->arguments->getOpt(4) : $name;
			$name = ($this->arguments->getOpt('n')) ? $this->arguments->getOpt('n') : $name;
			$name = ($this->arguments->getOpt('name')) ? $this->arguments->getOpt('name') : $name;
			$name = strtolower($name);
		}
		else
		{
			// If name wasn't provided, and we're in interactive mode...ask for it
			if ($this->output->isInteractive())
			{
				$name = $this->output->getResponse('What do you want the command name to be?');
			}
			else
			{
				$this->output->error("Error: a command name should be provided.");
			}
		}

		// Define our install directory or get it from args
		$dest = PATH_CORE . DS . 'libraries' . DS . 'Hubzero' . DS . 'Console' . DS . 'Command' . DS . ucfirst($name) . '.php';

		// Make command
		$this->addTemplateFile("{$this->getType()}.tmpl", $dest)
			 ->addReplacement('command_name', $name)
			 ->make();
	}