mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
handle new share list output
This commit is contained in:
parent
5a8d9edf74
commit
89f47cfdf2
4 changed files with 27 additions and 6 deletions
|
|
@ -17,10 +17,10 @@ class System {
|
||||||
private $stdbuf;
|
private $stdbuf;
|
||||||
|
|
||||||
public static function getFD($num) {
|
public static function getFD($num) {
|
||||||
$folders = array(
|
$folders = [
|
||||||
'/proc/self/fd',
|
'/proc/self/fd',
|
||||||
'/dev/fd'
|
'/dev/fd'
|
||||||
);
|
];
|
||||||
foreach ($folders as $folder) {
|
foreach ($folders as $folder) {
|
||||||
if (file_exists($folder)) {
|
if (file_exists($folder)) {
|
||||||
return $folder . '/' . $num;
|
return $folder . '/' . $num;
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,10 @@ class Parser {
|
||||||
if (strtolower($type) === 'disk') {
|
if (strtolower($type) === 'disk') {
|
||||||
$shareNames[$name] = $description;
|
$shareNames[$name] = $description;
|
||||||
}
|
}
|
||||||
|
} else if (strpos($line, 'Disk')) {
|
||||||
|
// new output format
|
||||||
|
list($name, $description) = explode('Disk', $line);
|
||||||
|
$shareNames[trim($name)] = trim($description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $shareNames;
|
return $shareNames;
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,9 @@ class RawConnection {
|
||||||
$this->env = $env;
|
$this->env = $env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ConnectException
|
||||||
|
*/
|
||||||
public function connect() {
|
public function connect() {
|
||||||
if (is_null($this->getAuthStream())) {
|
if (is_null($this->getAuthStream())) {
|
||||||
throw new ConnectException('Authentication not set before connecting');
|
throw new ConnectException('Authentication not set before connecting');
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,18 @@
|
||||||
namespace Icewind\SMB\Wrapped;
|
namespace Icewind\SMB\Wrapped;
|
||||||
|
|
||||||
use Icewind\SMB\AbstractServer;
|
use Icewind\SMB\AbstractServer;
|
||||||
|
use Icewind\SMB\Exception\AuthenticationException;
|
||||||
|
use Icewind\SMB\Exception\ConnectException;
|
||||||
|
use Icewind\SMB\Exception\ConnectionException;
|
||||||
|
use Icewind\SMB\Exception\InvalidHostException;
|
||||||
|
use Icewind\SMB\IShare;
|
||||||
use Icewind\SMB\System;
|
use Icewind\SMB\System;
|
||||||
|
|
||||||
class Server extends AbstractServer {
|
class Server extends AbstractServer {
|
||||||
/**
|
/**
|
||||||
* Check if the smbclient php extension is available
|
* Check if the smbclient php extension is available
|
||||||
*
|
*
|
||||||
|
* @param System $system
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function available(System $system) {
|
public static function available(System $system) {
|
||||||
|
|
@ -29,10 +35,11 @@ class Server extends AbstractServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Icewind\SMB\IShare[]
|
* @return IShare[]
|
||||||
*
|
*
|
||||||
* @throws \Icewind\SMB\Exception\AuthenticationException
|
* @throws AuthenticationException
|
||||||
* @throws \Icewind\SMB\Exception\InvalidHostException
|
* @throws InvalidHostException
|
||||||
|
* @throws ConnectException
|
||||||
*/
|
*/
|
||||||
public function listShares() {
|
public function listShares() {
|
||||||
$command = sprintf('%s %s %s -L %s',
|
$command = sprintf('%s %s %s -L %s',
|
||||||
|
|
@ -44,7 +51,14 @@ class Server extends AbstractServer {
|
||||||
$connection = new RawConnection($command);
|
$connection = new RawConnection($command);
|
||||||
$connection->writeAuthentication($this->getAuth()->getUsername(), $this->getAuth()->getPassword());
|
$connection->writeAuthentication($this->getAuth()->getUsername(), $this->getAuth()->getPassword());
|
||||||
$connection->connect();
|
$connection->connect();
|
||||||
|
if (!$connection->isValid()) {
|
||||||
|
throw new ConnectionException($connection->readLine());
|
||||||
|
}
|
||||||
$output = $connection->readAll();
|
$output = $connection->readAll();
|
||||||
|
// sometimes we get an empty line first
|
||||||
|
if (count($output) === 0) {
|
||||||
|
$output = $connection->readAll();
|
||||||
|
}
|
||||||
$parser = new Parser($this->timezoneProvider);
|
$parser = new Parser($this->timezoneProvider);
|
||||||
|
|
||||||
if (isset($output[0])) {
|
if (isset($output[0])) {
|
||||||
|
|
@ -62,7 +76,7 @@ class Server extends AbstractServer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return \Icewind\SMB\IShare
|
* @return IShare
|
||||||
*/
|
*/
|
||||||
public function getShare($name) {
|
public function getShare($name) {
|
||||||
return new Share($this, $name, $this->system);
|
return new Share($this, $name, $this->system);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue