mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
Update Server.php
Adicionado método para definir o protocolo de SMB máximo.
This commit is contained in:
parent
97ea247c5c
commit
499148909e
1 changed files with 174 additions and 151 deletions
285
src/Server.php
285
src/Server.php
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
||||||
* This file is licensed under the Licensed under the MIT license:
|
* This file is licensed under the Licensed under the MIT license:
|
||||||
|
|
@ -11,155 +12,177 @@ use Icewind\SMB\Exception\AuthenticationException;
|
||||||
use Icewind\SMB\Exception\InvalidHostException;
|
use Icewind\SMB\Exception\InvalidHostException;
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
const LOCALE = 'en_US.UTF-8';
|
|
||||||
|
|
||||||
/**
|
const LOCALE = 'en_US.UTF-8';
|
||||||
* @var string $host
|
|
||||||
*/
|
|
||||||
protected $host;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $user
|
* @var string $host
|
||||||
*/
|
*/
|
||||||
protected $user;
|
protected $host;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $password
|
* @var string $user
|
||||||
*/
|
*/
|
||||||
protected $password;
|
protected $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $workgroup
|
* @var string $password
|
||||||
*/
|
*/
|
||||||
protected $workgroup;
|
protected $password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Icewind\SMB\System
|
* @var string $workgroup
|
||||||
*/
|
*/
|
||||||
private $system;
|
protected $workgroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var TimeZoneProvider
|
* @var \Icewind\SMB\System
|
||||||
*/
|
*/
|
||||||
private $timezoneProvider;
|
private $system;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the smbclient php extension is available
|
* @var TimeZoneProvider
|
||||||
*
|
*/
|
||||||
* @return bool
|
private $timezoneProvider;
|
||||||
*/
|
|
||||||
public static function NativeAvailable() {
|
|
||||||
return function_exists('smbclient_state_new');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $host
|
*
|
||||||
* @param string $user
|
* @var string $maxProtocol
|
||||||
* @param string $password
|
*/
|
||||||
*/
|
private $maxProtocol;
|
||||||
public function __construct($host, $user, $password) {
|
|
||||||
$this->host = $host;
|
|
||||||
list($workgroup, $user) = $this->splitUser($user);
|
|
||||||
$this->user = $user;
|
|
||||||
$this->workgroup = $workgroup;
|
|
||||||
$this->password = $password;
|
|
||||||
$this->system = new System();
|
|
||||||
$this->timezoneProvider = new TimeZoneProvider($host, $this->system);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split workgroup from username
|
* Check if the smbclient php extension is available
|
||||||
*
|
*
|
||||||
* @param $user
|
* @return bool
|
||||||
* @return string[] [$workgroup, $user]
|
*/
|
||||||
*/
|
public static function NativeAvailable() {
|
||||||
public function splitUser($user) {
|
return function_exists('smbclient_state_new');
|
||||||
if (strpos($user, '/')) {
|
}
|
||||||
return explode('/', $user, 2);
|
|
||||||
} elseif (strpos($user, '\\')) {
|
|
||||||
return explode('\\', $user);
|
|
||||||
} else {
|
|
||||||
return array(null, $user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @param string $host
|
||||||
*/
|
* @param string $user
|
||||||
public function getAuthString() {
|
* @param string $password
|
||||||
return $this->user . '%' . $this->password;
|
*/
|
||||||
}
|
public function __construct($host, $user, $password) {
|
||||||
|
$this->host = $host;
|
||||||
|
list($workgroup, $user) = $this->splitUser($user);
|
||||||
|
$this->user = $user;
|
||||||
|
$this->workgroup = $workgroup;
|
||||||
|
$this->password = $password;
|
||||||
|
$this->system = new System();
|
||||||
|
$this->timezoneProvider = new TimeZoneProvider($host, $this->system);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Split workgroup from username
|
||||||
*/
|
*
|
||||||
public function getUser() {
|
* @param $user
|
||||||
return $this->user;
|
* @return string[] [$workgroup, $user]
|
||||||
}
|
*/
|
||||||
|
public function splitUser($user) {
|
||||||
|
if (strpos($user, '/')) {
|
||||||
|
return explode('/', $user, 2);
|
||||||
|
} elseif (strpos($user, '\\')) {
|
||||||
|
return explode('\\', $user);
|
||||||
|
} else {
|
||||||
|
return array(null, $user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getPassword() {
|
public function getAuthString() {
|
||||||
return $this->password;
|
return $this->user . '%' . $this->password;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getHost() {
|
public function getUser() {
|
||||||
return $this->host;
|
return $this->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getWorkgroup() {
|
public function getPassword() {
|
||||||
return $this->workgroup;
|
return $this->password;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Icewind\SMB\IShare[]
|
* return string
|
||||||
*
|
*/
|
||||||
* @throws \Icewind\SMB\Exception\AuthenticationException
|
public function getHost() {
|
||||||
* @throws \Icewind\SMB\Exception\InvalidHostException
|
return $this->host;
|
||||||
*/
|
}
|
||||||
public function listShares() {
|
|
||||||
$workgroupArgument = ($this->workgroup) ? ' -W ' . escapeshellarg($this->workgroup) : '';
|
|
||||||
$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();
|
|
||||||
$parser = new Parser($this->timezoneProvider);
|
|
||||||
|
|
||||||
$parser->checkConnectionError($output[0]);
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getWorkgroup() {
|
||||||
|
return $this->workgroup;
|
||||||
|
}
|
||||||
|
|
||||||
$shareNames = $parser->parseListShares($output);
|
/**
|
||||||
|
* @return \Icewind\SMB\IShare[]
|
||||||
|
*
|
||||||
|
* @throws \Icewind\SMB\Exception\AuthenticationException
|
||||||
|
* @throws \Icewind\SMB\Exception\InvalidHostException
|
||||||
|
*/
|
||||||
|
public function listShares() {
|
||||||
|
$workgroupArgument = ($this->workgroup) ? ' -W ' . escapeshellarg($this->workgroup) : '';
|
||||||
|
$maxProtocolArgument = ($this->maxProtocol) ? ' -m ' . escapeshellarg($this->maxProtocol) : '';
|
||||||
|
$command = sprintf('%s %s %s --authentication-file=%s -gL %s', $this->system->getSmbclientPath(), $workgroupArgument, $maxProtocolArgument,System::getFD(3), escapeshellarg($this->getHost())
|
||||||
|
);
|
||||||
|
$connection = new RawConnection($command);
|
||||||
|
$connection->writeAuthentication($this->getUser(), $this->getPassword());
|
||||||
|
$output = $connection->readAll();
|
||||||
|
$parser = new Parser($this->timezoneProvider);
|
||||||
|
|
||||||
$shares = array();
|
$parser->checkConnectionError($output[0]);
|
||||||
foreach ($shareNames as $name => $description) {
|
|
||||||
$shares[] = $this->getShare($name);
|
|
||||||
}
|
|
||||||
return $shares;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$shareNames = $parser->parseListShares($output);
|
||||||
* @param string $name
|
|
||||||
* @return \Icewind\SMB\IShare
|
|
||||||
*/
|
|
||||||
public function getShare($name) {
|
|
||||||
return new Share($this, $name, $this->system);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$shares = array();
|
||||||
* @return string
|
foreach ($shareNames as $name => $description) {
|
||||||
*/
|
$shares[] = $this->getShare($name);
|
||||||
public function getTimeZone() {
|
}
|
||||||
return $this->timezoneProvider->get();
|
return $shares;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @return \Icewind\SMB\IShare
|
||||||
|
*/
|
||||||
|
public function getShare($name) {
|
||||||
|
return new Share($this, $name, $this->system);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTimeZone() {
|
||||||
|
return $this->timezoneProvider->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
public function getMaxProtocol() {
|
||||||
|
return $this->maxProtocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param integer $maxProtocol
|
||||||
|
*/
|
||||||
|
public function setMaxProtocol($maxProtocol) {
|
||||||
|
if((ctype_digit(strval($maxProtocol)))){
|
||||||
|
$this->maxProtocol = 'SMB' . $maxProtocol;
|
||||||
|
} else {
|
||||||
|
throw new Exception\InvalidTypeException("Parameter is invalid, integer type only is accepted");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue