@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * Constructor. |
28 | 28 | * |
29 | - * @param object $configuration Configuration class object |
|
30 | - * @param object $authentication Authentication class object |
|
31 | - * @return void |
|
29 | + * @param Configuration $configuration Configuration class object |
|
30 | + * @param Authentication $authentication Authentication class object |
|
31 | + * @return string |
|
32 | 32 | */ |
33 | 33 | public function __construct(Configuration $configuration, Authentication $authentication) |
34 | 34 | { |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * Returns SSH interactive shell. |
52 | 52 | * |
53 | - * @return resouce SSH interactive shell |
|
53 | + * @return Shell SSH interactive shell |
|
54 | 54 | */ |
55 | 55 | final public function shell() |
56 | 56 | { |
@@ -88,8 +88,7 @@ discard block |
||
88 | 88 | * Execute remote command via SSH (shell). |
89 | 89 | * |
90 | 90 | * @param string $command command being executed |
91 | - * @param instance $terminal Terminal instance |
|
92 | - * @return object |
|
91 | + * @return Shell |
|
93 | 92 | */ |
94 | 93 | final public function write($command, $returncode = false) |
95 | 94 | { |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | class Shell extends Connection |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * SSH interactive shell resource. |
|
20 | - * |
|
21 | - * @var resource |
|
22 | - */ |
|
23 | - private $stream; |
|
24 | - private $command; |
|
18 | + /** |
|
19 | + * SSH interactive shell resource. |
|
20 | + * |
|
21 | + * @var resource |
|
22 | + */ |
|
23 | + private $stream; |
|
24 | + private $command; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Constructor. |
@@ -34,57 +34,57 @@ discard block |
||
34 | 34 | { |
35 | 35 | parent::__construct($configuration, $authentication); |
36 | 36 | |
37 | - $this->shell(); |
|
37 | + $this->shell(); |
|
38 | 38 | } |
39 | 39 | |
40 | - /** |
|
41 | - * Destructor. |
|
42 | - * |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function __destruct() |
|
46 | - { |
|
47 | - fclose($this->stream); |
|
48 | - } |
|
40 | + /** |
|
41 | + * Destructor. |
|
42 | + * |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function __destruct() |
|
46 | + { |
|
47 | + fclose($this->stream); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
50 | + /** |
|
51 | 51 | * Returns SSH interactive shell. |
52 | 52 | * |
53 | 53 | * @return resouce SSH interactive shell |
54 | 54 | */ |
55 | - final public function shell() |
|
56 | - { |
|
57 | - if (($this->stream = @ssh2_shell($this->connection)) === false) |
|
55 | + final public function shell() |
|
56 | + { |
|
57 | + if (($this->stream = @ssh2_shell($this->connection)) === false) |
|
58 | 58 | { |
59 | 59 | throw new \RuntimeException($this->get_error_message()); |
60 | 60 | } |
61 | - sleep(1); |
|
62 | - return $this; |
|
63 | - } |
|
61 | + sleep(1); |
|
62 | + return $this; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
65 | + /** |
|
66 | 66 | * Retrieves shell command output. |
67 | 67 | * |
68 | 68 | * @return void |
69 | 69 | */ |
70 | - final public function output() |
|
71 | - { |
|
72 | - $stdout = []; |
|
73 | - while (!preg_match('/RETURN_CODE:\[([0-9]+)\]/', implode(PHP_EOL, $stdout), $retval)) |
|
74 | - { |
|
75 | - $buffer = fgets($this->stream); |
|
76 | - if (!empty($buffer)) |
|
77 | - { |
|
78 | - $stdout[] = trim($buffer); |
|
79 | - //print $buffer; |
|
80 | - } |
|
81 | - } |
|
82 | - $stdout = preg_replace('/RETURN_CODE:\[([0-9]+)\]/', '', $stdout); |
|
83 | - $this->set_output(implode(PHP_EOL, $stdout)); |
|
70 | + final public function output() |
|
71 | + { |
|
72 | + $stdout = []; |
|
73 | + while (!preg_match('/RETURN_CODE:\[([0-9]+)\]/', implode(PHP_EOL, $stdout), $retval)) |
|
74 | + { |
|
75 | + $buffer = fgets($this->stream); |
|
76 | + if (!empty($buffer)) |
|
77 | + { |
|
78 | + $stdout[] = trim($buffer); |
|
79 | + //print $buffer; |
|
80 | + } |
|
81 | + } |
|
82 | + $stdout = preg_replace('/RETURN_CODE:\[([0-9]+)\]/', '', $stdout); |
|
83 | + $this->set_output(implode(PHP_EOL, $stdout)); |
|
84 | 84 | $this->set_exitstatus($retval[1]); |
85 | - } |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
87 | + /** |
|
88 | 88 | * Execute remote command via SSH (shell). |
89 | 89 | * |
90 | 90 | * @param string $command command being executed |
@@ -93,20 +93,20 @@ discard block |
||
93 | 93 | */ |
94 | 94 | final public function write($command, $returncode = false) |
95 | 95 | { |
96 | - $command = ($returncode == false) ? $command : $command . '; echo "RETURN_CODE:[$?]";'; |
|
97 | - $write_count = 0; |
|
98 | - $string_len = strlen($command . PHP_EOL); |
|
99 | - while ($write_count < $string_len) |
|
100 | - { |
|
101 | - $fwrite_count = fwrite($this->stream, substr($command . PHP_EOL, $write_count), 1024); |
|
102 | - if ($fwrite_count === false) |
|
103 | - { |
|
104 | - throw new \RuntimeException('failed to write command to stream'); |
|
105 | - } |
|
106 | - $write_count += $fwrite_count; |
|
107 | - } |
|
108 | - sleep(1); |
|
109 | - return $this; |
|
110 | - } |
|
96 | + $command = ($returncode == false) ? $command : $command . '; echo "RETURN_CODE:[$?]";'; |
|
97 | + $write_count = 0; |
|
98 | + $string_len = strlen($command . PHP_EOL); |
|
99 | + while ($write_count < $string_len) |
|
100 | + { |
|
101 | + $fwrite_count = fwrite($this->stream, substr($command . PHP_EOL, $write_count), 1024); |
|
102 | + if ($fwrite_count === false) |
|
103 | + { |
|
104 | + throw new \RuntimeException('failed to write command to stream'); |
|
105 | + } |
|
106 | + $write_count += $fwrite_count; |
|
107 | + } |
|
108 | + sleep(1); |
|
109 | + return $this; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | final public function shell() |
56 | 56 | { |
57 | - if (($this->stream = @ssh2_shell($this->connection)) === false) |
|
57 | + if (($this->stream = @ssh2_shell($this->connection)) === FALSE) |
|
58 | 58 | { |
59 | 59 | throw new \RuntimeException($this->get_error_message()); |
60 | 60 | } |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | * @param instance $terminal Terminal instance |
92 | 92 | * @return object |
93 | 93 | */ |
94 | - final public function write($command, $returncode = false) |
|
94 | + final public function write($command, $returncode = FALSE) |
|
95 | 95 | { |
96 | - $command = ($returncode == false) ? $command : $command . '; echo "RETURN_CODE:[$?]";'; |
|
96 | + $command = ($returncode == FALSE) ? $command : $command . '; echo "RETURN_CODE:[$?]";'; |
|
97 | 97 | $write_count = 0; |
98 | 98 | $string_len = strlen($command . PHP_EOL); |
99 | 99 | while ($write_count < $string_len) |
100 | 100 | { |
101 | 101 | $fwrite_count = fwrite($this->stream, substr($command . PHP_EOL, $write_count), 1024); |
102 | - if ($fwrite_count === false) |
|
102 | + if ($fwrite_count === FALSE) |
|
103 | 103 | { |
104 | 104 | throw new \RuntimeException('failed to write command to stream'); |
105 | 105 | } |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * Constructor. |
56 | 56 | * |
57 | - * @param instance $configuration Configuration instance |
|
58 | - * @param instance $authentication Authentication instance |
|
59 | - * @return void |
|
57 | + * @param Configuration $configuration Configuration instance |
|
58 | + * @param Authentication $authentication Authentication instance |
|
59 | + * @return string |
|
60 | 60 | */ |
61 | 61 | public function __construct(Configuration $configuration, Authentication $authentication) |
62 | 62 | { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | /** |
67 | 67 | * Set execution mode. |
68 | 68 | * |
69 | - * @return object |
|
69 | + * @return SSH |
|
70 | 70 | */ |
71 | 71 | final public function set_mode($mode = self::WAIT) |
72 | 72 | { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * Set filename path. |
79 | 79 | * |
80 | - * @return object |
|
80 | + * @return SSH |
|
81 | 81 | */ |
82 | 82 | final public function set_filename($filename) |
83 | 83 | { |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * Execute remote command via SSH. |
110 | 110 | * |
111 | 111 | * @param string $command command being executed |
112 | - * @param instance $terminal Terminal instance |
|
112 | + * @param Terminal $terminal Terminal instance |
|
113 | 113 | * @return void |
114 | 114 | */ |
115 | 115 | final public function exec($command, Terminal $terminal = null) |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | * Create channel stream. |
148 | 148 | * |
149 | 149 | * @param string $command command being executed |
150 | - * @param instance $terminal Terminal instance |
|
151 | - * @return stream SSH connection resource stream |
|
150 | + * @param Terminal $terminal Terminal instance |
|
151 | + * @return resource SSH connection resource stream |
|
152 | 152 | */ |
153 | 153 | final private function get_stream($command, Terminal $terminal) |
154 | 154 | { |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * Executes a command on a remote server. |
180 | 180 | * |
181 | 181 | * @param resource $stream SSH resource stream |
182 | - * @return void |
|
182 | + * @return integer|null |
|
183 | 183 | */ |
184 | 184 | final private function exec_wait($stream) |
185 | 185 | { |
@@ -122,19 +122,19 @@ discard block |
||
122 | 122 | switch ($this->get_mode()) |
123 | 123 | { |
124 | 124 | case 'execute.wait': |
125 | - $stream = $this->get_stream($command, $terminal); |
|
125 | + $stream = $this->get_stream($command, $terminal); |
|
126 | 126 | $this->exec_wait($stream); |
127 | 127 | break; |
128 | 128 | |
129 | 129 | case 'execute.realtime': |
130 | - $command .= ' 2>&1'; |
|
131 | - $stream = $this->get_stream($command, $terminal); |
|
130 | + $command .= ' 2>&1'; |
|
131 | + $stream = $this->get_stream($command, $terminal); |
|
132 | 132 | $this->exec_realtime($stream); |
133 | 133 | break; |
134 | 134 | |
135 | 135 | case 'execute.file': |
136 | - $command .= ' 2>&1'; |
|
137 | - $stream = $this->get_stream($command, $terminal); |
|
136 | + $command .= ' 2>&1'; |
|
137 | + $stream = $this->get_stream($command, $terminal); |
|
138 | 138 | $this->exec_file($stream); |
139 | 139 | break; |
140 | 140 | |
@@ -159,19 +159,19 @@ discard block |
||
159 | 159 | |
160 | 160 | $command .= '; echo "RETURN_CODE:[$?]"'; |
161 | 161 | $stream = @ssh2_exec( |
162 | - $this->connection, |
|
163 | - $command, |
|
164 | - $terminal->get_pty(), |
|
165 | - $terminal->get_env(), |
|
166 | - $terminal->get_width(), |
|
167 | - $terminal->get_height() |
|
168 | - ); |
|
162 | + $this->connection, |
|
163 | + $command, |
|
164 | + $terminal->get_pty(), |
|
165 | + $terminal->get_env(), |
|
166 | + $terminal->get_width(), |
|
167 | + $terminal->get_height() |
|
168 | + ); |
|
169 | 169 | |
170 | - if ($stream === false) |
|
170 | + if ($stream === false) |
|
171 | 171 | { |
172 | 172 | throw new \RuntimeException($this->get_error_message()); |
173 | 173 | } |
174 | - stream_set_blocking($stream, true); |
|
174 | + stream_set_blocking($stream, true); |
|
175 | 175 | return $stream; |
176 | 176 | } |
177 | 177 | |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | */ |
218 | 218 | final private function exec_realtime($stream) |
219 | 219 | { |
220 | - while ($buffer = fgets($stream)) |
|
220 | + while ($buffer = fgets($stream)) |
|
221 | 221 | { |
222 | 222 | if (!preg_match('/RETURN_CODE:\[([0-9]+)\]/', $buffer, $retval)) |
223 | 223 | { |
224 | - print $buffer; |
|
224 | + print $buffer; |
|
225 | 225 | } |
226 | - flush(); |
|
226 | + flush(); |
|
227 | 227 | } |
228 | 228 | fclose($stream); |
229 | 229 | $this->set_exitstatus($retval[1]); |
@@ -218,7 +218,7 @@ |
||
218 | 218 | final private function exec_realtime($stream) |
219 | 219 | { |
220 | 220 | while ($buffer = fgets($stream)) |
221 | - { |
|
221 | + { |
|
222 | 222 | if (!preg_match('/RETURN_CODE:\[([0-9]+)\]/', $buffer, $retval)) |
223 | 223 | { |
224 | 224 | print $buffer; |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @var string |
44 | 44 | */ |
45 | - public $mode = null; |
|
45 | + public $mode = NULL; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Filename path. |
49 | 49 | * |
50 | 50 | * @var string |
51 | 51 | */ |
52 | - public $filename = null; |
|
52 | + public $filename = NULL; |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Constructor. |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | final public function get_mode() |
94 | 94 | { |
95 | - return ($this->mode === null) ? self::WAIT : $this->mode; |
|
95 | + return ($this->mode === NULL) ? self::WAIT : $this->mode; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param instance $terminal Terminal instance |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - final public function exec($command, Terminal $terminal = null) |
|
115 | + final public function exec($command, Terminal $terminal = NULL) |
|
116 | 116 | { |
117 | 117 | if (!$terminal instanceof Terminal) |
118 | 118 | { |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | $terminal->get_height() |
168 | 168 | ); |
169 | 169 | |
170 | - if ($stream === false) |
|
170 | + if ($stream === FALSE) |
|
171 | 171 | { |
172 | 172 | throw new \RuntimeException($this->get_error_message()); |
173 | 173 | } |
174 | - stream_set_blocking($stream, true); |
|
174 | + stream_set_blocking($stream, TRUE); |
|
175 | 175 | return $stream; |
176 | 176 | } |
177 | 177 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | do |
192 | 192 | { |
193 | 193 | sleep(1); |
194 | - if ($out === false || $err === false) |
|
194 | + if ($out === FALSE || $err === FALSE) |
|
195 | 195 | { |
196 | 196 | $stderr .= 'STDOUT and/or STDERR stream(s) closed unexpectedly.'; |
197 | 197 | return 1; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | */ |
238 | 238 | final private function exec_file($stream) |
239 | 239 | { |
240 | - if ($this->get_filename() === null) |
|
240 | + if ($this->get_filename() === NULL) |
|
241 | 241 | { |
242 | 242 | throw new \RuntimeException('A valid filename path must be provided.'); |
243 | 243 | } |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * Set STDOUT output stream. |
58 | 58 | * |
59 | - * @param mixed $stdout standard output |
|
59 | + * @param mixed $stdout standard output |
|
60 | 60 | * @return object |
61 | 61 | */ |
62 | 62 | final public function set_output($stdout) |
63 | 63 | { |
64 | - $this->stdout = $stdout; |
|
64 | + $this->stdout = $stdout; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * Set STDERR output stream. |
69 | 69 | * |
70 | - * @param string $stderr standard error |
|
70 | + * @param string $stderr standard error |
|
71 | 71 | * @return object |
72 | 72 | */ |
73 | 73 | final public function set_error($stderr) |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | /** |
79 | 79 | * Set exit status code. |
80 | 80 | * |
81 | - * @param int $exitstatus exit status code |
|
81 | + * @param int $exitstatus exit status code |
|
82 | 82 | * @return object |
83 | 83 | */ |
84 | 84 | final public function set_exitstatus($exitstatus) |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | final public function get_output() |
95 | 95 | { |
96 | - return $this->stdout; |
|
96 | + return $this->stdout; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | final public function get_error() |
105 | 105 | { |
106 | - return $this->stderr; |
|
106 | + return $this->stderr; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | final public function get_exitstatus() |
115 | 115 | { |
116 | - return $this->exitstatus; |
|
116 | + return $this->exitstatus; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -37,21 +37,21 @@ |
||
37 | 37 | * |
38 | 38 | * @var string |
39 | 39 | */ |
40 | - protected $error_message = null; |
|
40 | + protected $error_message = NULL; |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Last known error line number. |
44 | 44 | * |
45 | 45 | * @var int |
46 | 46 | */ |
47 | - protected $error_line_no = null; |
|
47 | + protected $error_line_no = NULL; |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * Last known error filename. |
51 | 51 | * |
52 | 52 | * @var string |
53 | 53 | */ |
54 | - protected $error_file = null; |
|
54 | + protected $error_file = NULL; |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Set STDOUT output stream. |
@@ -16,7 +16,7 @@ |
||
16 | 16 | * |
17 | 17 | * @var string |
18 | 18 | */ |
19 | - private $pty = null; |
|
19 | + private $pty = NULL; |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Environmental variables (associative array). |