1 | <?php |
||
13 | class RawConnection { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $command; |
||
18 | |||
19 | /** |
||
20 | * @var string[] |
||
21 | */ |
||
22 | private $env; |
||
23 | |||
24 | /** |
||
25 | * @var resource[] $pipes |
||
26 | * |
||
27 | * $pipes[0] holds STDIN for smbclient |
||
28 | * $pipes[1] holds STDOUT for smbclient |
||
29 | * $pipes[3] holds the authfile for smbclient |
||
30 | * $pipes[4] holds the stream for writing files |
||
31 | * $pipes[5] holds the stream for reading files |
||
32 | */ |
||
33 | private $pipes; |
||
34 | |||
35 | /** |
||
36 | * @var resource $process |
||
37 | */ |
||
38 | private $process; |
||
39 | |||
40 | /** |
||
41 | * @var resource|null $authStream |
||
42 | */ |
||
43 | private $authStream = null; |
||
44 | |||
45 | private $connected = false; |
||
46 | |||
47 | 777 | public function __construct($command, array $env = []) { |
|
51 | |||
52 | /** |
||
53 | * @throws ConnectException |
||
54 | */ |
||
55 | 777 | public function connect() { |
|
82 | |||
83 | /** |
||
84 | * check if the connection is still active |
||
85 | * |
||
86 | * @return bool |
||
87 | */ |
||
88 | 777 | public function isValid() { |
|
96 | |||
97 | /** |
||
98 | * send input to the process |
||
99 | * |
||
100 | * @param string $input |
||
101 | */ |
||
102 | 765 | public function write($input) { |
|
106 | |||
107 | /** |
||
108 | * read a line of output |
||
109 | * |
||
110 | * @return string|false |
||
111 | */ |
||
112 | 777 | public function readLine() { |
|
115 | |||
116 | /** |
||
117 | * read a line of output |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | public function readError() { |
||
122 | return trim(stream_get_line($this->getErrorStream(), 4086)); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * get all output until the process closes |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | 15 | public function readAll() { |
|
137 | |||
138 | 765 | public function getInputStream() { |
|
141 | |||
142 | 777 | public function getOutputStream() { |
|
145 | |||
146 | public function getErrorStream() { |
||
147 | return $this->pipes[2]; |
||
148 | } |
||
149 | |||
150 | 777 | public function getAuthStream() { |
|
153 | |||
154 | 48 | public function getFileInputStream() { |
|
155 | 48 | return $this->pipes[4]; |
|
156 | } |
||
157 | |||
158 | 48 | public function getFileOutputStream() { |
|
159 | 48 | return $this->pipes[5]; |
|
160 | } |
||
161 | |||
162 | 777 | public function writeAuthentication($user, $password) { |
|
170 | |||
171 | 777 | public function close($terminate = true) { |
|
192 | |||
193 | 3 | public function reconnect() { |
|
194 | 3 | $this->close(); |
|
195 | 3 | $this->connect(); |
|
196 | 3 | } |
|
197 | |||
198 | 777 | public function __destruct() { |
|
201 | } |
||
202 |