Added a methode to list printers

This commit is contained in:
adrian 2015-07-20 11:04:48 +02:00
commit 8d6286e6b4

View file

@ -78,12 +78,12 @@ class Server {
} }
/** /**
* @return \Icewind\SMB\IShare[] * @return array
* *
* @throws \Icewind\SMB\Exception\AuthenticationException * @throws \Icewind\SMB\Exception\AuthenticationException
* @throws \Icewind\SMB\Exception\InvalidHostException * @throws \Icewind\SMB\Exception\InvalidHostException
*/ */
public function listShares() { private function listSMB() {
$command = Server::CLIENT . ' --authentication-file=/proc/self/fd/3' . $command = Server::CLIENT . ' --authentication-file=/proc/self/fd/3' .
' -gL ' . escapeshellarg($this->getHost()); ' -gL ' . escapeshellarg($this->getHost());
$connection = new RawConnection($command); $connection = new RawConnection($command);
@ -106,6 +106,16 @@ class Server {
throw new InvalidHostException(); throw new InvalidHostException();
} }
return $output;
}
/**
* @return \Icewind\SMB\IShare[]
*
*/
public function listShares() {
$output = $this->listSMB();
$shareNames = array(); $shareNames = array();
foreach ($output as $line) { foreach ($output as $line) {
if (strpos($line, '|')) { if (strpos($line, '|')) {
@ -123,6 +133,26 @@ class Server {
return $shares; 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 * @param string $name
* @return \Icewind\SMB\IShare * @return \Icewind\SMB\IShare