|
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\Native; |
|
9
|
|
|
|
|
10
|
|
|
use Icewind\SMB\AbstractServer; |
|
11
|
|
|
use Icewind\SMB\IAuth; |
|
12
|
|
|
use Icewind\SMB\System; |
|
13
|
|
|
use Icewind\SMB\TimeZoneProvider; |
|
14
|
|
|
|
|
15
|
|
|
class NativeServer extends AbstractServer { |
|
16
|
|
|
/** |
|
17
|
|
|
* @var NativeState |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $state; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param string $host |
|
23
|
|
|
* @param IAuth $auth |
|
24
|
|
|
* @param System $system |
|
25
|
|
|
* @param TimeZoneProvider $timeZoneProvider |
|
26
|
|
|
*/ |
|
27
|
255 |
|
public function __construct($host, IAuth $auth, System $system, TimeZoneProvider $timeZoneProvider) { |
|
28
|
255 |
|
parent::__construct($host, $auth, $system, $timeZoneProvider); |
|
29
|
255 |
|
$this->state = new NativeState(); |
|
30
|
255 |
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
protected function connect() { |
|
33
|
1 |
|
$this->state->init($this->getAuth()); |
|
34
|
1 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return \Icewind\SMB\IShare[] |
|
38
|
|
|
* @throws \Icewind\SMB\Exception\AuthenticationException |
|
39
|
|
|
* @throws \Icewind\SMB\Exception\InvalidHostException |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function listShares() { |
|
42
|
1 |
|
$this->connect(); |
|
43
|
1 |
|
$shares = array(); |
|
44
|
1 |
|
$dh = $this->state->opendir('smb://' . $this->getHost()); |
|
45
|
1 |
|
while ($share = $this->state->readdir($dh)) { |
|
46
|
1 |
|
if ($share['type'] === 'file share') { |
|
47
|
1 |
|
$shares[] = $this->getShare($share['name']); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
1 |
|
$this->state->closedir($dh); |
|
51
|
1 |
|
return $shares; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $name |
|
56
|
|
|
* @return \Icewind\SMB\IShare |
|
57
|
|
|
*/ |
|
58
|
255 |
|
public function getShare($name) { |
|
59
|
255 |
|
return new NativeShare($this, $name); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Check if the smbclient php extension is available |
|
64
|
|
|
* |
|
65
|
|
|
* @param System $system |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function available(System $system) { |
|
69
|
|
|
return function_exists('smbclient_state_new'); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|