1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2014 Robin Appelman <[email protected]> |
4
|
|
|
* This file is licensed under the Licensed under the MIT license: |
5
|
|
|
* http://opensource.org/licenses/MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Icewind\SMB\Wrapped; |
9
|
|
|
|
10
|
|
|
use Icewind\SMB\AbstractServer; |
11
|
|
|
use Icewind\SMB\System; |
12
|
|
|
|
13
|
|
|
class Server extends AbstractServer { |
14
|
|
|
/** |
15
|
|
|
* Check if the smbclient php extension is available |
16
|
|
|
* |
17
|
|
|
* @return bool |
18
|
|
|
*/ |
19
|
|
|
public static function available(System $system) { |
20
|
|
|
return $system->getSmbclientPath(); |
21
|
|
|
} |
22
|
|
|
|
23
|
5 |
|
private function getAuthFileArgument() { |
24
|
5 |
|
if ($this->getAuth()->getUsername()) { |
|
|
|
|
25
|
5 |
|
return '--authentication-file=' . System::getFD(3); |
26
|
|
|
} else { |
27
|
|
|
return ''; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return \Icewind\SMB\IShare[] |
33
|
|
|
* |
34
|
|
|
* @throws \Icewind\SMB\Exception\AuthenticationException |
35
|
|
|
* @throws \Icewind\SMB\Exception\InvalidHostException |
36
|
|
|
*/ |
37
|
5 |
|
public function listShares() { |
38
|
5 |
|
$command = sprintf('%s %s %s -L %s', |
39
|
5 |
|
$this->system->getSmbclientPath(), |
40
|
5 |
|
$this->getAuthFileArgument(), |
41
|
5 |
|
$this->getAuth()->getExtraCommandLineArguments(), |
42
|
5 |
|
escapeshellarg('//' . $this->getHost()) |
43
|
5 |
|
); |
44
|
5 |
|
$connection = new RawConnection($command); |
45
|
5 |
|
$connection->writeAuthentication($this->getAuth()->getUsername(), $this->getAuth()->getPassword()); |
46
|
5 |
|
$connection->connect(); |
47
|
5 |
|
$output = $connection->readAll(); |
48
|
5 |
|
$parser = new Parser($this->timezoneProvider); |
49
|
|
|
|
50
|
5 |
|
if (isset($output[0])) { |
51
|
3 |
|
$parser->checkConnectionError($output[0]); |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
$shareNames = $parser->parseListShares($output); |
55
|
|
|
|
56
|
2 |
|
$shares = array(); |
57
|
2 |
|
foreach ($shareNames as $name => $description) { |
58
|
|
|
$shares[] = $this->getShare($name); |
59
|
2 |
|
} |
60
|
2 |
|
return $shares; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $name |
65
|
|
|
* @return \Icewind\SMB\IShare |
66
|
|
|
*/ |
67
|
255 |
|
public function getShare($name) { |
68
|
255 |
|
return new Share($this, $name, $this->system); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: