1 | <?php |
||
18 | class Server extends AbstractServer { |
||
19 | /** |
||
20 | * Check if the smbclient php extension is available |
||
21 | * |
||
22 | * @param ISystem $system |
||
23 | * @return bool |
||
24 | */ |
||
25 | 8 | public static function available(ISystem $system) { |
|
26 | 8 | return $system->getSmbclientPath(); |
|
|
|||
27 | } |
||
28 | |||
29 | 20 | private function getAuthFileArgument() { |
|
36 | |||
37 | /** |
||
38 | * @return IShare[] |
||
39 | * |
||
40 | * @throws AuthenticationException |
||
41 | * @throws InvalidHostException |
||
42 | * @throws ConnectException |
||
43 | */ |
||
44 | 20 | public function listShares() { |
|
45 | 20 | $command = sprintf( |
|
46 | 20 | '%s %s %s -L %s', |
|
47 | 20 | $this->system->getSmbclientPath(), |
|
48 | 20 | $this->getAuthFileArgument(), |
|
49 | 20 | $this->getAuth()->getExtraCommandLineArguments(), |
|
50 | 20 | escapeshellarg('//' . $this->getHost()) |
|
51 | ); |
||
52 | 20 | $connection = new RawConnection($command); |
|
53 | 20 | $connection->writeAuthentication($this->getAuth()->getUsername(), $this->getAuth()->getPassword()); |
|
54 | 20 | $connection->connect(); |
|
55 | 20 | if (!$connection->isValid()) { |
|
56 | throw new ConnectionException($connection->readLine()); |
||
57 | } |
||
58 | |||
59 | 20 | $parser = new Parser($this->timezoneProvider); |
|
60 | |||
61 | 20 | $output = $connection->readAll(); |
|
62 | 20 | if (isset($output[0])) { |
|
63 | 12 | $parser->checkConnectionError($output[0]); |
|
64 | } |
||
65 | |||
66 | // sometimes we get an empty line first |
||
67 | 8 | if (count($output) < 2) { |
|
68 | 8 | $output = $connection->readAll(); |
|
69 | } |
||
70 | |||
71 | 8 | if (isset($output[0])) { |
|
72 | 8 | $parser->checkConnectionError($output[0]); |
|
73 | } |
||
74 | |||
75 | 8 | $shareNames = $parser->parseListShares($output); |
|
76 | |||
77 | 8 | $shares = []; |
|
78 | 8 | foreach ($shareNames as $name => $description) { |
|
79 | 8 | $shares[] = $this->getShare($name); |
|
80 | } |
||
81 | 8 | return $shares; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param string $name |
||
86 | * @return IShare |
||
87 | */ |
||
88 | 1028 | public function getShare($name) { |
|
91 | } |
||
92 |