mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Improve locating file descriptors and smbclient/net commands
This commit is contained in:
parent
a07a5ad2ec
commit
b865f430d6
5 changed files with 100 additions and 18 deletions
|
|
@ -11,7 +11,6 @@ use Icewind\SMB\Exception\AuthenticationException;
|
|||
use Icewind\SMB\Exception\InvalidHostException;
|
||||
|
||||
class Server {
|
||||
const CLIENT = 'smbclient';
|
||||
const LOCALE = 'en_US.UTF-8';
|
||||
|
||||
/**
|
||||
|
|
@ -34,6 +33,16 @@ class Server {
|
|||
*/
|
||||
protected $workgroup;
|
||||
|
||||
/**
|
||||
* @var \Icewind\SMB\System
|
||||
*/
|
||||
private $system;
|
||||
|
||||
/**
|
||||
* @var TimeZoneProvider
|
||||
*/
|
||||
private $timezoneProvider;
|
||||
|
||||
/**
|
||||
* Check if the smbclient php extension is available
|
||||
*
|
||||
|
|
@ -54,6 +63,8 @@ class Server {
|
|||
$this->user = $user;
|
||||
$this->workgroup = $workgroup;
|
||||
$this->password = $password;
|
||||
$this->system = new System();
|
||||
$this->timezoneProvider = new TimeZoneProvider($host, $this->system);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,8 +126,12 @@ class Server {
|
|||
*/
|
||||
public function listShares() {
|
||||
$workgroupArgument = ($this->workgroup) ? ' -W ' . escapeshellarg($this->workgroup) : '';
|
||||
$command = Server::CLIENT . $workgroupArgument . ' --authentication-file=/proc/self/fd/3' .
|
||||
' -gL ' . escapeshellarg($this->getHost());
|
||||
$command = sprintf('%s %s --authentication-file=%s -gL %s',
|
||||
$this->system->getSmbclientPath(),
|
||||
$workgroupArgument,
|
||||
System::getFD(3),
|
||||
escapeshellarg($this->getHost())
|
||||
);
|
||||
$connection = new RawConnection($command);
|
||||
$connection->writeAuthentication($this->getUser(), $this->getPassword());
|
||||
$output = $connection->readAll();
|
||||
|
|
@ -166,7 +181,6 @@ class Server {
|
|||
* @return string
|
||||
*/
|
||||
public function getTimeZone() {
|
||||
$command = 'net time zone -S ' . escapeshellarg($this->getHost());
|
||||
return exec($command);
|
||||
return $this->timezoneProvider->get();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue