Telnet WILL negotiaion

@param    char   $cmd    Binary representation of command char

@throws   SocketClientException   On socket communication error
@return   int                     Bytes written
556617
private function _negotiateWill($cmd) {
        switch ($cmd) {
            case TEL_GA:
                break;
            case TEL_ECHO:
                break;
            default:
                return $this->send(TEL_IAC.TEL_WONT.$cmd, false);
        }
    }
379997
static public function UnpackCommand($cmd)
    {
        # check Message type
        $message_type = $cmd >> 4;
        $dup = ($cmd & 0x08) >> 3;
        $qos = ($cmd & 0x06) >> 1;
        $retain = ($cmd & 0x01);

        return array(
            'message_type'  =>  $message_type,
            'dup'           =>  $dup,
            'qos'           =>  $qos,
            'retain'        =>  $retain,
        );
    }
391049
private Command processCommand(Socket clientSocket) {
        BufferedReader in = null;
        BufferedWriter out = null;
        try{
            in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
            String s;
            while ((s = in.readLine()) != null) {
                if("exit".equalsIgnoreCase(s.trim())) {
                    respond(out, "ok");

                    return Command.EXIT;
                }else {
                    respond(out, String.format("Unknown command '%s'", s));
                }
            }
        }catch (IOException e) {
            log.warn(String.format("Failed to accept user command at port %d: %s", clientSocket.getPort(), e.getMessage()), e);
        }finally {
            try{
                Closeables.close(in, true);
                Closeables.close(out, true);
            } catch(IOException ignored) {

            }

        }

        return null;
    }
1167373
protected function executeCommand($cmd)
    {
        // Shell-escape all arguments except the command.
        $args = func_get_args();
        foreach ($args as $index => $arg) {
            if ($index !== 0) {
                $args[$index] = escapeshellarg($arg);
            }
        }

        // And replace the arguments.
        $command = call_user_func_array('sprintf', $args);
        $output = '';
        if ($this->io->isVerbose()) {
            $this->io->write('<comment>' . $command . '</comment>');
            $io = $this->io;
            $output = function ($type, $data) use ($io) {
                if ($type === Process::ERR) {
                    $io->write('<error>' . $data . '</error>');
                } else {
                    $io->write('<comment>' . $data . '</comment>');
                }
            };
        }
        return ($this->executor->execute($command, $output) === 0);
    }
287114
private void handleCommand(byte b) throws IOException {
        if (b == SE) {
            telnetCommand += (char) b;
            handleNegotiation();
            reset();
        } else if (isWill || isDo) {
            if (isWill && b == TERMINAL_TYPE) {
                socketChannel
                    .write(ByteBuffer.wrap(new byte[] { IAC, SB, TERMINAL_TYPE, ECHO, IAC, SE }));
            } else if (b != ECHO && b != GA && b != NAWS) {
                telnetCommand += (char) b;
                socketChannel.write(ByteBuffer.wrap(telnetCommand.getBytes()));
            }
            reset();
        } else if (isWont || isDont) {
            telnetCommand += (char) b;
            socketChannel.write(ByteBuffer.wrap(telnetCommand.getBytes()));
            reset();
        } else if (isSb) {
            telnetCommand += (char) b;
        }
    }
1343464
public function execute($cmd, $data)
    {
        // Use pipes for STDIN, STDOUT, and STDERR
        $descr = array(
          0 => array(
            'pipe',
            'r'
          ) ,
          1 => array(
            'pipe',
            'w'
          ) ,
          2 => array(
            'pipe',
            'w'
          )
        );
        $pipes = [];

        // Start process, telling it to use STDIN for input and STDOUT for output.
        $cmd = escapeshellcmd($cmd);
        $process = proc_open($cmd, $descr, $pipes);

        // Get the data into pipe only if data is resource
        if (gettype($data) == "resource") {
            // Stream input to STDIN
            while (!feof($data)) {
                fwrite($pipes[0], fread($data, 1024));
            }

            // Close STDIN and the source data.
            fclose($pipes[0]);
            fclose($data);
        }

        // Wait for process to finish while reading STDOUT to a temp stream.
        // Otherwise the process can block indefinitely if STODUT gets bigger
        // than 4kb.
        $this->output = fopen("php://temp", 'w+');
        $exit_code = null;
        while ($exit_code === null) {
            $status = proc_get_status($process);
            if ($status['running'] === false) {
                $exit_code = $status['exitcode'];
            }

            $chunk = stream_get_contents($pipes[1]);
            if ($chunk !== false) {
                fwrite($this->output, $chunk);
            }
        }

        // Close STDOUT
        fclose($pipes[1]);

        // On error, extract message from STDERR and throw an exception.
        if ($exit_code != 0) {
            $msg = stream_get_contents($pipes[2]);
            $this->cleanup($pipes, $this->output, $process);
            if ($this->log) {
                $this->log->error('Process exited with non-zero code.', [
                  'exit_code' => $exit_code,
                  'stderr' => $msg,
                ]);
            }
            throw new \RuntimeException($msg, 500);
        }

        // Return a function that streams the output.
        return function () use ($pipes, $process) {
            rewind($this->output);
            while (!feof($this->output)) {
                echo fread($this->output, 1024);
                ob_flush();
                flush();
            }
            $this->cleanup($pipes, $this->output, $process);
        };
    }
904310
function cmd_STOR($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $ftpsock = $this->getUserSock($user);
        $file = $this->fillDirName($user, $cmd[1]);
        $this->debug("PUT: $file");
        $fp = fopen($file, "w");
        if (!$fp)
        {
            $this->send($fd, "553 Can't open that file: Permission denied");
        }
        else
        {
            $this->send($fd, "150 Connecting to client");
            while (!feof($ftpsock))
            {
                $cont = fread($ftpsock, 8192);
                if (!$cont) break;
                if (!fwrite($fp, $cont)) break;
            }
            if (fclose($fp) and $this->closeUserSock($user))
            {
                $this->send($fd, "226 File successfully transferred");
            }
            else
            {
                $this->send($fd, "550 Error during file-transfer");
            }
        }
    }
128752
function cmd_PORT($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $port = explode(",", $cmd[1]);
        if (count($port) != 6)
        {
            $this->send($fd, "501 Syntax error in IP address");
        }
        else
        {
            if (!$this->isIPAddress($port))
            {
                $this->send($fd, "501 Syntax error in IP address");
                return;
            }
            $ip = $port[0] . "." . $port[1] . "." . $port[2] . "." . $port[3];
            $port = hexdec(dechex($port[4]) . dechex($port[5]));
            if ($port < 1024)
            {
                $this->send($fd, "501 Sorry, but I won't connect to ports < 1024");
            }
            elseif ($port > 65000)
            {
                $this->send($fd, "501 Sorry, but I won't connect to ports > 65000");
            }
            else
            {
                $ftpsock = fsockopen($ip, $port);
                if ($ftpsock)
                {
                    $this->users[$user]['sock'] = $ftpsock;
                    $this->users[$user]['pasv'] = false;
                    $this->send($fd, "200 PORT command successful");
                }
                else
                {
                    $this->send($fd, "501 Connection failed");
                }
            }
        }
    }
432791
private function doRequest($cmd, $args = array())
    {
        clearstatcache();
        $args['domain'] = $this->domain;
        $params = http_build_query($args);

        $this->connect();

        fwrite($this->socket, "{$cmd} {$params}\n");
        $line = fgets($this->socket);

        $words = explode(' ', $line);

        if ($words[0] == 'OK') {
            parse_str(trim($words[1]), $result);
        } else {
            $errorName = empty($words[1]) ? null : $words[1];

            switch ($errorName) {
                case 'unknown_key':
                    $errorCode = static::ERR_UNKNOWN_KEY;
                    break;
                case 'empty_file':
                    $errorCode = static::ERR_EMPTY_FILE;
                    break;
                case 'none_match':
                    $errorCode = static::ERR_NONE_MATCH;
                    break;
                case 'key_exists':
                    $errorCode = static::ERR_KEY_EXISTS;
                    break;
                default:
                    $errorCode = static::ERR_OTHER;
            }

            throw new \RuntimeException(
                sprintf('Error response: %s', $line),
                $errorCode
            );
        }

        return $result;
    }
12748
public function sendCommand(string $command) : string
    {
        try {
            $this->socket->send(json_encode([
                'action' => 'command',
                'command' => [
                    'name' => $command,
                ]
            ]));
            $result = $this->socket->recv();
            return $result;
        } catch (\ZMQException $e) {
            throw new ClientException($e->getMessage());
        }
    }
1017736
protected function dialog($cmd=NULL,$log=TRUE) {
		$socket=&$this->socket;
		if (!is_null($cmd))
			fputs($socket,$cmd."\r\n");
		$reply='';
		while (!feof($socket) && ($info=stream_get_meta_data($socket)) &&
			!$info['timed_out'] && $str=fgets($socket,4096)) {
			$reply.=$str;
			if (preg_match('/(?:^|\n)\d{3} .+?\r\n/s',$reply))
				break;
		}
		if ($log) {
			$this->log.=$cmd."\n";
			$this->log.=str_replace("\r",'',$reply);
		}
		return $reply;
	}
587981
public function request($cmd, $throw = TRUE)
  {
    if($this->getId() != $this->getParent()->serverSelectedId())
    {
      $this->getParent()->serverSelect($this->getId());
    }

    return $this->getParent()->request($cmd, $throw);
  }
857313
public static function detectCmdLocationInPath(string $cmd, string $path) : string
    {
        $command = $path . DIRECTORY_SEPARATOR . $cmd;
        $bin     = self::getExecutable($command);
        if (empty($bin)) {
            throw new RuntimeException(sprintf('wrong path specified for \'%s\': %s', $cmd, $path));
        }
        return $bin;
    }
1158858
static function execute($cmd)
    {
        $result = '';
        echo 'Executing ' . $cmd . PHP_EOL;
        $result = shell_exec($cmd);
        echo($result);
        return $result;
    }
563797
private function run(string $cmd, string $cwd = null): bool
    {
        $process = new Process($cmd, $cwd);

        $process->setTimeout(300);

        if ($process->isTty()) {
            $process->setTty(true);
        }

        try {
            $output = $this->app->make(OutputInterface::class);
        } catch (Throwable $e) {
            $output = null;
        }

        if ($output) {
            $output->write("\n");
            $process->run(
                function ($type, $line) use ($output) {
                    $output->write($line);
                }
            );
        } else {
            $process->run();
        }

        return $process->isSuccessful();
    }
951529
public function command_args_case(CommandInterface $cmd)
    {
        $buf = new Buffer;
        $buf->appendLine('case $state in');

        foreach ($cmd->getArguments() as $a) {
            $buf->appendLine("({$a->name})");

            if ($a->validValues || $a->suggestions) {
                $buf->appendLine('_values ' . $this->render_argument_completion_values($a) . ' && ret=0');
            } elseif (in_array($a->isa, ['file', 'path', 'dir'], true)) {
                $buf->appendLine($this->render_argument_completion_handler($a) . ' && ret=0');
            }
            $buf->appendLine(';;');
        }
        $buf->appendLine('esac');

        return $buf->__toString();
    }
153978
private function buildCommand($cmd, $args = array()) {
    while(list($name, $data) = each($args)) {
    $safeData = false;
      $filterType = mb_substr($name, 0, 1);
      switch($filterType) {
        case '%':
          $safeData = escapeshellarg($data);
          break;
        case '!':
          $safeData = escapeshellcmd($data);
          break;
        default:
          throw new \phpSec\Exception\InvalidArgumentException('Unknown variable type');
          break;
      }
      if($safeData !== false) {
        $cmd = str_replace($name, $safeData, $cmd);
      }
    }
    return $cmd;
  }