1 | <?php |
||
13 | class Server { |
||
14 | const LOCALE = 'en_US.UTF-8'; |
||
15 | |||
16 | /** |
||
17 | * @var string $host |
||
18 | */ |
||
19 | protected $host; |
||
20 | |||
21 | /** |
||
22 | * @var string $user |
||
23 | */ |
||
24 | protected $user; |
||
25 | |||
26 | /** |
||
27 | * @var string $password |
||
28 | */ |
||
29 | protected $password; |
||
30 | |||
31 | /** |
||
32 | * @var string $workgroup |
||
33 | */ |
||
34 | protected $workgroup; |
||
35 | |||
36 | /** |
||
37 | * @var \Icewind\SMB\System |
||
38 | */ |
||
39 | private $system; |
||
40 | |||
41 | /** |
||
42 | * @var TimeZoneProvider |
||
43 | */ |
||
44 | private $timezoneProvider; |
||
45 | |||
46 | /** |
||
47 | * Check if the smbclient php extension is available |
||
48 | * |
||
49 | * @return bool |
||
50 | */ |
||
51 | public static function NativeAvailable() { |
||
52 | return function_exists('smbclient_state_new'); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param string $host |
||
57 | * @param string $user |
||
58 | * @param string $password |
||
59 | */ |
||
60 | 1020 | public function __construct($host, $user, $password) { |
|
69 | |||
70 | /** |
||
71 | * Split workgroup from username |
||
72 | * |
||
73 | * @param $user |
||
74 | * @return string[] [$workgroup, $user] |
||
75 | */ |
||
76 | 1020 | public function splitUser($user) { |
|
85 | |||
86 | /** |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getAuthString() { |
||
92 | |||
93 | /** |
||
94 | * @return string |
||
95 | */ |
||
96 | 1020 | public function getUser() { |
|
99 | |||
100 | /** |
||
101 | * @return string |
||
102 | */ |
||
103 | 1020 | public function getPassword() { |
|
106 | |||
107 | /** |
||
108 | * return string |
||
109 | */ |
||
110 | 1020 | public function getHost() { |
|
113 | |||
114 | /** |
||
115 | * @return string |
||
116 | */ |
||
117 | 1020 | public function getWorkgroup() { |
|
120 | |||
121 | /** |
||
122 | * @return \Icewind\SMB\IShare[] |
||
123 | * |
||
124 | * @throws \Icewind\SMB\Exception\AuthenticationException |
||
125 | * @throws \Icewind\SMB\Exception\InvalidHostException |
||
126 | */ |
||
127 | public function listShares() { |
||
128 | $workgroupArgument = ($this->workgroup) ? ' -W ' . escapeshellarg($this->workgroup) : ''; |
||
129 | $command = sprintf('%s %s --authentication-file=%s -gL %s', |
||
130 | $this->system->getSmbclientPath(), |
||
131 | $workgroupArgument, |
||
132 | System::getFD(3), |
||
133 | escapeshellarg($this->getHost()) |
||
134 | ); |
||
135 | $connection = new RawConnection($command); |
||
136 | $connection->writeAuthentication($this->getUser(), $this->getPassword()); |
||
137 | $connection->connect(); |
||
138 | $output = $connection->readAll(); |
||
139 | $parser = new Parser($this->timezoneProvider); |
||
140 | |||
141 | $parser->checkConnectionError($output[0]); |
||
142 | |||
143 | $shareNames = $parser->parseListShares($output); |
||
144 | |||
145 | $shares = array(); |
||
146 | foreach ($shareNames as $name => $description) { |
||
147 | $shares[] = $this->getShare($name); |
||
148 | } |
||
149 | return $shares; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @param string $name |
||
154 | * @return \Icewind\SMB\IShare |
||
155 | */ |
||
156 | public function getShare($name) { |
||
157 | return new Share($this, $name, $this->system); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getTimeZone() { |
||
166 | } |
||
167 |