mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
Added a methode to list printers
This commit is contained in:
parent
25a76128d5
commit
8d6286e6b4
1 changed files with 32 additions and 2 deletions
|
|
@ -78,12 +78,12 @@ class Server {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \Icewind\SMB\IShare[]
|
||||
* @return array
|
||||
*
|
||||
* @throws \Icewind\SMB\Exception\AuthenticationException
|
||||
* @throws \Icewind\SMB\Exception\InvalidHostException
|
||||
*/
|
||||
public function listShares() {
|
||||
private function listSMB() {
|
||||
$command = Server::CLIENT . ' --authentication-file=/proc/self/fd/3' .
|
||||
' -gL ' . escapeshellarg($this->getHost());
|
||||
$connection = new RawConnection($command);
|
||||
|
|
@ -106,6 +106,16 @@ class Server {
|
|||
throw new InvalidHostException();
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Icewind\SMB\IShare[]
|
||||
*
|
||||
*/
|
||||
public function listShares() {
|
||||
$output = $this->listSMB();
|
||||
|
||||
$shareNames = array();
|
||||
foreach ($output as $line) {
|
||||
if (strpos($line, '|')) {
|
||||
|
|
@ -123,6 +133,26 @@ class Server {
|
|||
return $shares;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function listPrinters() {
|
||||
$output = $this->listSMB();
|
||||
|
||||
$printers = array();
|
||||
foreach ($output as $line) {
|
||||
if (strpos($line, '|')) {
|
||||
list($type, $name, $description) = explode('|', $line);
|
||||
if (strtolower($type) === 'printer') {
|
||||
$printers[$name] = $description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $printers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return \Icewind\SMB\IShare
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue