1 | <?php |
||
12 | class RawConnection { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $command; |
||
17 | |||
18 | /** |
||
19 | * @var string[] |
||
20 | */ |
||
21 | private $env; |
||
22 | |||
23 | /** |
||
24 | * @var resource[] $pipes |
||
25 | * |
||
26 | * $pipes[0] holds STDIN for smbclient |
||
27 | * $pipes[1] holds STDOUT for smbclient |
||
28 | */ |
||
29 | private $pipes; |
||
30 | |||
31 | /** |
||
32 | * @var resource $process |
||
33 | */ |
||
34 | private $process; |
||
35 | |||
36 | 777 | public function __construct($command, $env = array()) { |
|
41 | |||
42 | 777 | private function connect() { |
|
43 | $descriptorSpec = array( |
||
44 | 777 | 0 => array('pipe', 'r'), // child reads from stdin |
|
45 | 777 | 1 => array('pipe', 'w'), // child writes to stdout |
|
46 | 777 | 2 => array('pipe', 'w'), // child writes to stderr |
|
47 | 777 | 3 => array('pipe', 'r'), // child reads from fd#3 |
|
48 | 777 | 4 => array('pipe', 'r'), // child reads from fd#4 |
|
49 | 777 | 5 => array('pipe', 'w') // child writes to fd#5 |
|
50 | 777 | ); |
|
51 | 777 | setlocale(LC_ALL, Server::LOCALE); |
|
52 | 777 | $env = array_merge($this->env, array( |
|
53 | 777 | 'CLI_FORCE_INTERACTIVE' => 'y', // Needed or the prompt isn't displayed!! |
|
54 | 777 | 'LC_ALL' => Server::LOCALE, |
|
55 | 777 | 'LANG' => Server::LOCALE, |
|
56 | 'COLUMNS' => 8192 // prevent smbclient from line-wrapping it's output |
||
57 | 777 | )); |
|
58 | 777 | $this->process = proc_open($this->command, $descriptorSpec, $this->pipes, '/', $env); |
|
59 | 777 | if (!$this->isValid()) { |
|
60 | throw new ConnectionException(); |
||
61 | } |
||
62 | 777 | } |
|
63 | |||
64 | /** |
||
65 | * check if the connection is still active |
||
66 | * |
||
67 | * @return bool |
||
68 | */ |
||
69 | 777 | public function isValid() { |
|
77 | |||
78 | /** |
||
79 | * send input to the process |
||
80 | * |
||
81 | * @param string $input |
||
82 | */ |
||
83 | 765 | public function write($input) { |
|
87 | |||
88 | /** |
||
89 | * read a line of output |
||
90 | * |
||
91 | * @return string|false |
||
92 | */ |
||
93 | 774 | public function readLine() { |
|
96 | |||
97 | /** |
||
98 | * read a line of output |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | public function readError() { |
||
105 | |||
106 | /** |
||
107 | * get all output until the process closes |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | 15 | public function readAll() { |
|
118 | |||
119 | 765 | public function getInputStream() { |
|
122 | |||
123 | 774 | public function getOutputStream() { |
|
126 | |||
127 | public function getErrorStream() { |
||
130 | |||
131 | 777 | public function getAuthStream() { |
|
134 | |||
135 | 48 | public function getFileInputStream() { |
|
138 | |||
139 | 48 | public function getFileOutputStream() { |
|
142 | |||
143 | 777 | public function writeAuthentication($user, $password) { |
|
155 | |||
156 | 777 | public function close($terminate = true) { |
|
177 | |||
178 | 3 | public function reconnect() { |
|
182 | |||
183 | 777 | public function __destruct() { |
|
186 | } |
||
187 |