예제 #1
0
파일: smb.php 프로젝트: evanjt/core
 /**
  * @return string
  */
 public function getId()
 {
     // FIXME: double slash to keep compatible with the old storage ids,
     // failure to do so will lead to creation of a new storage id and
     // loss of shares from the storage
     return 'smb::' . $this->server->getUser() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root;
 }
예제 #2
0
 public function testListShares()
 {
     $shares = $this->server->listShares();
     foreach ($shares as $share) {
         if ($share->getName() === $this->config->share) {
             return;
         }
     }
     $this->fail('Share "' . $this->config->share . '" not found');
 }
예제 #3
0
 private function buildUrl($path)
 {
     $this->verifyPath($path);
     $url = sprintf('smb://%s/%s', $this->server->getHost(), $this->name);
     if ($path) {
         $path = trim($path, '/');
         $url .= '/';
         $url .= implode('/', array_map('rawurlencode', explode('/', $path)));
     }
     return $url;
 }
예제 #4
0
 public function setUp()
 {
     if (!function_exists('smbclient_state_new')) {
         $this->markTestSkipped('libsmbclient php extension not installed');
     }
     $this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
     $this->server = new NativeServer($this->config->host, $this->config->user, $this->config->password);
     $this->share = $this->server->getShare($this->config->share);
     if ($this->config->root) {
         $this->root = '/' . $this->config->root . '/' . uniqid();
     } else {
         $this->root = '/' . uniqid();
     }
     $this->share->mkdir($this->root);
 }
예제 #5
0
 /**
  * @param bool $isPersonal
  * @return bool
  */
 public function test($isPersonal = true)
 {
     if ($isPersonal) {
         if ($this->stat('')) {
             return true;
         }
         return false;
     } else {
         $server = new Server($this->server->getHost(), '', '');
         try {
             $server->listShares();
             return true;
         } catch (AccessDeniedException $e) {
             // expected due to anonymous login
             return true;
         } catch (Exception $e) {
             return false;
         }
     }
 }
예제 #6
0
 /**
  * Open a writable stream to a remote file
  *
  * @param string $target
  * @return resource a write only stream to upload a remote file
  *
  * @throws \Icewind\SMB\Exception\NotFoundException
  * @throws \Icewind\SMB\Exception\InvalidTypeException
  */
 public function write($target)
 {
     $target = $this->escapePath($target);
     // close the single quote, open a double quote where we put the single quote...
     $target = str_replace('\'', '\'"\'"\'', $target);
     // since returned stream is closed by the caller we need to create a new instance
     // since we can't re-use the same file descriptor over multiple calls
     $command = sprintf('%s --authentication-file=/proc/self/fd/3 //%s/%s -c \'put /proc/self/fd/4 %s\'', Server::CLIENT, $this->server->getHost(), $this->name, $target);
     $connection = new RawConnection($command);
     $connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
     $fh = $connection->getFileInputStream();
     // use a close callback to ensure the upload is finished before continuing
     // this also serves as a way to keep the connection in scope
     return CallbackWrapper::wrap($fh, null, null, function () use($connection) {
         $connection->close(false);
         // dont terminate, give the upload some time
     });
 }
예제 #7
0
파일: Share.php 프로젝트: ZverAleksey/core
 /**
  * Open a writable stream to a remote file
  *
  * @param string $target
  * @return resource a write only stream to upload a remote file
  *
  * @throws \Icewind\SMB\Exception\NotFoundException
  * @throws \Icewind\SMB\Exception\InvalidTypeException
  */
 public function write($target)
 {
     $target = $this->escapePath($target);
     // since returned stream is closed by the caller we need to create a new instance
     // since we can't re-use the same file descriptor over multiple calls
     $workgroupArgument = $this->server->getWorkgroup() ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
     $command = sprintf('%s %s --authentication-file=%s %s', $this->system->getSmbclientPath(), $workgroupArgument, System::getFD(3), escapeshellarg('//' . $this->server->getHost() . '/' . $this->name));
     $connection = new Connection($command);
     $connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
     $fh = $connection->getFileInputStream();
     $connection->write('put ' . System::getFD(4) . ' ' . $target);
     $connection->write('exit');
     // use a close callback to ensure the upload is finished before continuing
     // this also serves as a way to keep the connection in scope
     return CallbackWrapper::wrap($fh, null, null, function () use($connection, $target) {
         $connection->close(false);
         // dont terminate, give the upload some time
     });
 }
예제 #8
0
파일: SMB.php 프로젝트: GitHubUser4234/core
 /**
  * check if smbclient is installed
  */
 public static function checkDependencies()
 {
     return (bool) \OC_Helper::findBinaryPath('smbclient') || Server::NativeAvailable() ? true : ['smbclient'];
 }
예제 #9
0
 /**
  * @return string
  */
 public function getId()
 {
     return 'smb::' . $this->server->getUser() . '@' . $this->server->getHost() . '/' . $this->share->getName() . '/' . $this->root;
 }
예제 #10
0
 public function execute($_options = array())
 {
     if ($this->getType() == 'info') {
         return;
     }
     try {
         $eqLogic = $this->getEqLogic();
         $sonos = sonos3::getSonos();
         $controller = sonos3::getControllerByIp($eqLogic->getLogicalId());
         if ($this->getLogicalId() == 'play') {
             if ($eqLogic->getConfiguration('model') == 'PLAYBAR') {
                 $state = $eqLogic->getCmd(null, 'state');
                 $track_title = $eqLogic->getCmd(null, 'track_title');
                 if (is_object($state) && is_object($track_title)) {
                     if ($track_title->execCmd(null, 2) == __('Aucun', __FILE__) && $state->execCmd(null, 2) == __('Lecture', __FILE__)) {
                         return $controller->unmute();
                     }
                 }
             }
             $controller->play();
         }
         if ($this->getLogicalId() == 'stop') {
             if ($eqLogic->getConfiguration('model') == 'PLAYBAR') {
                 $state = $eqLogic->getCmd(null, 'state');
                 $track_title = $eqLogic->getCmd(null, 'track_title');
                 if (is_object($state) && is_object($track_title)) {
                     if ($track_title->execCmd(null, 2) == __('Aucun', __FILE__) && $state->execCmd(null, 2) == __('Lecture', __FILE__)) {
                         return $controller->mute();
                     }
                 }
             }
             $controller->pause();
         }
         if ($this->getLogicalId() == 'pause') {
             if ($eqLogic->getConfiguration('model') == 'PLAYBAR') {
                 $state = $eqLogic->getCmd(null, 'state');
                 $track_title = $eqLogic->getCmd(null, 'track_title');
                 if (is_object($state) && is_object($track_title)) {
                     if ($cmd_track_title->execCmd(null, 2) == __('Aucun', __FILE__) && $state->execCmd(null, 2) == __('Lecture', __FILE__)) {
                         return $controller->mute();
                     }
                 }
             }
             $controller->pause();
         }
         if ($this->getLogicalId() == 'previous') {
             $controller->previous();
         }
         if ($this->getLogicalId() == 'next') {
             $controller->next();
         }
         if ($this->getLogicalId() == 'mute') {
             $controller->mute();
         }
         if ($this->getLogicalId() == 'unmute') {
             $controller->unmute();
         }
         if ($this->getLogicalId() == 'repeat') {
             $controller->setRepeat(!$controller->getRepeat());
         }
         if ($this->getLogicalId() == 'shuffle') {
             $controller->setShuffle(!$controller->getShuffle());
         }
         if ($this->getLogicalId() == 'setVolume') {
             if ($_options['slider'] < 0) {
                 $_options['slider'] = 0;
             }
             if ($_options['slider'] > 100) {
                 $_options['slider'] = 100;
             }
             $controller->setVolume($_options['slider']);
         }
         if ($this->getLogicalId() == 'play_playlist') {
             if (!$controller->isUsingQueue()) {
                 $controller->useQueue();
             }
             $queue = $controller->getQueue();
             $playlist = $sonos->getPlaylistByName(trim(trim($_options['title']), '"'));
             if ($playlist == null) {
                 foreach ($sonos->getPlaylists() as $playlist_search) {
                     if (str_replace('  ', ' ', $playlist_search->getName()) == $_options['title']) {
                         $playlist = $playlist_search;
                         break;
                     }
                 }
             }
             if ($playlist == null) {
                 throw new Exception(__('Playlist non trouvé : ', __FILE__) . trim($_options['title']));
             }
             $tracks = $playlist->getTracks();
             $queue->clear();
             if (count($tracks) > 1) {
                 if (isset($_options['message']) && $_options['message'] == 'random') {
                     shuffle($tracks);
                 }
                 $queue->addTrack($tracks[0]);
                 $controller->play();
                 unset($tracks[0]);
                 $queue->addTracks($tracks);
             } else {
                 $queue->addTracks($tracks);
                 $controller->play();
             }
         }
         if ($this->getLogicalId() == 'play_radio') {
             $radio = $sonos->getRadio();
             $stations = $radio->getFavouriteStations();
             if ($stations->getName() == $_options['title']) {
                 $controller->useStream($show)->play();
             }
         }
         if ($this->getLogicalId() == 'add_speaker') {
             $speaker = $sonos->getSpeakerByRoom($_options['title']);
             $controller->addSpeaker($speaker);
         }
         if ($this->getLogicalId() == 'remove_speaker') {
             $speaker = $sonos->getSpeakerByRoom($_options['title']);
             $controller->removeSpeaker($speaker);
         }
         if ($this->getLogicalId() == 'tts') {
             $path = explode('/', trim(config::byKey('tts_path', 'sonos3'), '/'));
             $server = new Server(config::byKey('tts_host', 'sonos3'), config::byKey('tts_username', 'sonos3'), config::byKey('tts_password', 'sonos3'));
             $share = $server->getShare($path[0]);
             $adapter = new SmbAdapter($share);
             $filesystem = new Filesystem($adapter);
             $folder = array_pop($path);
             $directory = new Directory($filesystem, config::byKey('tts_host', 'sonos3') . '/' . implode('/', $path), $folder);
             if (config::byKey('ttsProvider', 'sonos3') != 'voxygen' && strlen($_options['message']) > 100) {
                 $_options['message'] = substr($_options['message'], 0, 100);
             }
             $track = new TextToSpeech(trim($_options['message']), $directory, new GoogleProvider());
             $track->setLanguage("fr");
             $track->setProvider(new VoxygenProvider());
             $track->getProvider()->setVoice(config::byKey('ttsVoxygenVoice', 'sonos3', 'Helene'));
             if ($_options['title'] != '' && is_numeric($_options['title'])) {
                 $controller->interrupt($track, $_options['title']);
             } else {
                 $controller->interrupt($track);
             }
         } else {
             sonos3::pull($eqLogic->getId());
         }
     } catch (Exception $e) {
         log::add('sonos', 'info', $e->getMessage());
     }
 }
예제 #11
0
<?php

use Icewind\SMB\NativeServer;
use Icewind\SMB\Server;
require 'vendor/autoload.php';
if (Server::NativeAvailable()) {
    $server = new NativeServer('localhost', 'test', 'test');
} else {
    $server = new Server('localhost', 'test', 'test');
}
$share = $server->getShare('test');
$share->put(__FILE__, 'example.php');
$files = $share->dir('/');
foreach ($files as $file) {
    echo $file->getName() . "\n";
}