コード例 #1
0
ファイル: VFSHelper.php プロジェクト: Tebro/xbmc-video-server
 /**
  * Returns the absolute URL to the specified path
  * @param string $path a path returned from an API call
  * @param boolean $omitCredentials whether to omit credentials from the URL
  * @return string the URL
  */
 private function getNonProxiedUrl($path, $omitCredentials)
 {
     $hostname = Backend::normalizeAddress($this->_backend->hostname);
     $port = $this->_backend->port;
     $url = 'http://{credentials}' . $hostname . ':' . $port . '/' . $path;
     if ($omitCredentials) {
         $url = str_replace('{credentials}', '', $url);
     } else {
         $url = str_replace('{credentials}', $this->_backend->username . ':' . $this->_backend->password . '@', $url);
     }
     return $url;
 }
コード例 #2
0
ファイル: XBMC.php プロジェクト: Tebro/xbmc-video-server
 /**
  * Initializes the component
  */
 public function init()
 {
     // Connect to the current backend
     $this->_backend = Yii::app()->backendManager->getCurrent();
     $hostname = Backend::normalizeAddress($this->_backend->hostname);
     $endpoint = 'http://' . $hostname . ':' . $this->_backend->port . '/jsonrpc';
     $clientFlags = JsonRPCClient::FLAG_ATTEMPT_UTF8_RECOVERY;
     $clientOptions = array('timeout' => Setting::getInteger('requestTimeout'));
     $this->_client = new JsonRPCClient($endpoint, $this->_backend->username, $this->_backend->password, $clientFlags, $clientOptions);
     // Initialize the VFS helper
     $this->_vfsHelper = new VFSHelper();
     parent::init();
 }
コード例 #3
0
 /**
  * @return boolean whether this backend is connectable
  * @param int $port the port to try to connect to. Defaults to null, meaning 
  * the HTTP port configured for this backend
  * @param boolean $logFailure whether unsuccessful attempts should be logged. Defaults 
  * to true.
  */
 public function isConnectable($port = null, $logFailure = true)
 {
     $errno = 0;
     $errStr = '';
     if ($port === null) {
         $port = $this->port;
     }
     if (@fsockopen(Backend::normalizeAddress($this->hostname), $port, $errno, $errStr, self::SOCKET_TIMEOUT) === false || $errno !== 0) {
         if ($logFailure) {
             Yii::log('Failed to connect to ' . $this->hostname . ':' . $this->port . '. The exact error was: ' . $errStr . ' (' . $errno . ')', CLogger::LEVEL_ERROR, 'Backend');
         }
         return false;
     }
     return true;
 }
コード例 #4
0
 /**
  * @return string the hostname:port combination
  */
 public function getHostInfo()
 {
     return Backend::normalizeAddress($this->_hostname) . ':' . $this->_port;
 }
コード例 #5
0
 /**
  * Returns the absolute URL to the specified API path
  * @param string $path a path returned from an API call
  * @param boolean $omitCredentials whether to omit the XBMC credentials in 
  * the generated URLs
  * @return string
  */
 public function getAbsoluteVfsUrl($path, $omitCredentials = false)
 {
     $backend = Yii::app()->backendManager->getCurrent();
     // Use reverse proxy for vfs:// paths (if specified)
     $proxyLocation = $backend->proxyLocation;
     if (!empty($proxyLocation) && substr($path, 0, 3) === 'vfs') {
         // Only use HTTPS if user has explicitly enabled it
         $scheme = 'http://';
         if (Setting::getBoolean('useHttpsForVfsUrls') && Yii::app()->request->isSecureConnection) {
             $scheme = 'https://';
         }
         // Remove the beginning "vfs/" from the path
         $path = substr($path, 4);
         return $scheme . $_SERVER['HTTP_HOST'] . $proxyLocation . '/' . $path;
     } else {
         $url = 'http://{credentials}' . Backend::normalizeAddress($backend->hostname) . ':' . $backend->port . '/' . $path;
         if ($omitCredentials) {
             $url = str_replace('{credentials}', '', $url);
         } else {
             $url = str_replace('{credentials}', $backend->username . ':' . $backend->password . '@', $url);
         }
         return $url;
     }
 }