Esempio n. 1
0
 public static function download($url, $timeout = 3000)
 {
     xapp_import('xapp.Commons.Error');
     xapp_import('xapp.Utils.Strings');
     xapp_import('xapp.Http.MiniHTTP');
     xapp_import('xapp.Directory.Utils');
     xapp_import('xapp.File.Utils');
     if (!$url) {
         return new XApp_Error('http_no_url', 'Invalid URL Provided.');
     }
     $tmpfname = XApp_Directory_Utils::tempname($url);
     if (!$tmpfname) {
         return new XApp_Error_Base('http_no_file', 'Could not create Temporary file.');
     }
     $http = new XApp_Http();
     $response = $http->request($url, array('timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname));
     /*xapp_clog($response);*/
     if (XApp_Error_Base::is_error($response)) {
         unlink($tmpfname);
         return $response;
     }
     /*
     		if ( 200 != self::remote_retrieve_response_code( $response ) ){
     			unlink( $tmpfname );
     			return self::remote_retrieve_response_message( $response );
     		}*/
     $content_md5 = self::remote_retrieve_header($response, 'content-md5');
     if ($content_md5) {
         $md5_check = XApp_File_Utils::verify_file_md5($tmpfname, $content_md5);
         if (XApp_Error::is_error($md5_check)) {
             unlink($tmpfname);
             return $md5_check;
         }
     }
     return $tmpfname;
 }
Esempio n. 2
0
 /**
  * method ls returns the directory listing, '/' means it will include the directory names
  * of all enabled and valid mounted directories.
  *
  * This is however a wrapper for Directory::Utils::getFilteredDirList.
  * You will implement this in a way that copyDirectory,moveDirectory can work with mounted
  * resources.
  */
 public function getFilteredDirList($path, $inclusionMask = array(), $exclusionMask = array(), $options = array())
 {
     if ($path == "/") {
         // Return all mounted directories
         $all_file_proxys = $this->getResourcesByType(XAPP_RESOURCE_TYPE_FILE_PROXY);
         $retlist = array();
         $clear_path = isset($options[XApp_Directory_Utils::OPTION_CLEAR_PATH]) && $options[XApp_Directory_Utils::OPTION_CLEAR_PATH];
         foreach ($all_file_proxys as $f_proxy) {
             $retlist[] = ($clear_path ? "" : "/") . $f_proxy->name;
         }
         return $retlist;
     } else {
         // Call getFilteredDirList from XApp_Directory_Utils
         $pathResolved = $this->toRealPath($path);
         if (!file_exists($pathResolved)) {
             throw new Exception('path doesn exists');
         }
         $retlist = XApp_Directory_Utils::getFilteredDirList($pathResolved, $inclusionMask, $exclusionMask, $options);
         return $retlist;
     }
 }
Esempio n. 3
0
 public function _addNode($evt)
 {
     if ($this->_vfs !== null && is_array($evt) && array_key_exists('item', $evt) && array_key_exists('userData', $evt) && array_key_exists('options', $evt['userData'])) {
         $userData = $evt['userData'];
         $options = $userData['options'];
         //no filters? return
         if (!isset($options[self::INCLUDES_FILE_EXTENSIONS]) && !isset($options[self::EXCLUDED_FILE_EXTENSION])) {
             return true;
         }
         $item = $evt['item'];
         $isDirectory = $item->{XAPP_NODE_FIELD_IS_DIRECTORY};
         //check files
         if ($isDirectory === false) {
             $allowedFileExtensions = isset($options[self::INCLUDES_FILE_EXTENSIONS]) ? $options[self::INCLUDES_FILE_EXTENSIONS] : array();
             $forbiddenFileExtensions = isset($options[self::EXCLUDED_FILE_EXTENSION]) ? $options[self::EXCLUDED_FILE_EXTENSION] : array();
             if (is_string($allowedFileExtensions)) {
                 if (strpos($allowedFileExtensions, ',') !== false) {
                     $allowedFileExtensions = explode(',', $allowedFileExtensions);
                 } else {
                     $allowedFileExtensions = array($allowedFileExtensions);
                 }
             }
             if (is_string($forbiddenFileExtensions)) {
                 if (strpos($forbiddenFileExtensions, ',') !== false) {
                     $forbiddenFileExtensions = explode(',', $forbiddenFileExtensions);
                 } else {
                     $forbiddenFileExtensions = array($forbiddenFileExtensions);
                 }
             }
             $isAllowed = XApp_Directory_Utils::isAllowed($item->{XAPP_NODE_FIELD_NAME}, $allowedFileExtensions, $forbiddenFileExtensions);
             return $isAllowed === true;
         }
     } else {
     }
     return true;
 }
Esempio n. 4
0
 public function request($url, $args = array())
 {
     xapp_import('xapp.Utils.Strings');
     xapp_import('xapp.Utils.Arrays');
     xapp_import('xapp.Commons.Error');
     xapp_import('xapp.Directory.Utils');
     $defaults = array('method' => 'GET', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'user-agent' => 'no agent', 'reject_unsafe_urls' => false, 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true, 'sslcertificates' => null, 'stream' => false, 'filename' => null, 'limit_response_size' => null);
     // Pre-parse for the HEAD checks.
     $args = XApp_Utils_Array::parse_args($args);
     // By default, Head requests do not cause redirections.
     if (isset($args['method']) && 'HEAD' == $args['method']) {
         $defaults['redirection'] = 0;
     }
     $r = XApp_Utils_Array::parse_args($args, $defaults);
     // The transports decrement this, store a copy of the original value for loop purposes.
     if (!isset($r['_redirection'])) {
         $r['_redirection'] = $r['redirection'];
     }
     $arrURL = @parse_url($url);
     if (empty($url) || empty($arrURL['scheme'])) {
         return new XApp_Error('http_request_failed', 'A valid URL was not provided.');
     }
     /*
      * Determine if this is a https call and pass that on to the transport functions
      * so that we can blacklist the transports that do not support ssl verification
      */
     $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
     // Determine if this request is to OUR install of WordPress.
     $r['local'] = 'localhost' == $arrURL['host'] || isset($homeURL['host']) && $homeURL['host'] == $arrURL['host'];
     /*
      * If we are streaming to a file but no filename was given drop it in the WP temp dir
      * and pick its name using the basename of the $url.
      */
     if ($r['stream'] && empty($r['filename'])) {
         $r['filename'] = XApp_Directory_Utils::get_temp_dir() . basename($url);
     }
     /*
      * Force some settings if we are streaming to a file and check for existence and perms
      * of destination directory.
      */
     if ($r['stream']) {
         $r['blocking'] = true;
         if (!XApp_Directory_Utils::is_writable(dirname($r['filename']))) {
             return new XApp_Error('http_request_failed', 'Destination directory for file streaming does not exist or is not writable.');
         }
     }
     if (is_null($r['headers'])) {
         $r['headers'] = array();
     }
     if (isset($r['headers']['User-Agent'])) {
         $r['user-agent'] = $r['headers']['User-Agent'];
         unset($r['headers']['User-Agent']);
     }
     if (isset($r['headers']['user-agent'])) {
         $r['user-agent'] = $r['headers']['user-agent'];
         unset($r['headers']['user-agent']);
     }
     if ('1.1' == $r['httpversion'] && !isset($r['headers']['connection'])) {
         $r['headers']['connection'] = 'close';
     }
     // Construct Cookie: header if any cookies are set.
     //XAppHttp::buildCookieHeader( $r );
     // Avoid issues where mbstring.func_overload is enabled.
     XApp_Utils_Strings::mbstring_binary_safe_encoding();
     if (!isset($r['headers']['Accept-Encoding'])) {
         //if ( $encoding = XAppHttp_Encoding::accept_encoding( $url, $r ) )
         //	$r['headers']['Accept-Encoding'] = $encoding;
     }
     if (!is_null($r['body']) && '' != $r['body'] || 'POST' == $r['method'] || 'PUT' == $r['method']) {
         if (is_array($r['body']) || is_object($r['body'])) {
             $r['body'] = http_build_query($r['body'], null, '&');
             if (!isset($r['headers']['Content-Type'])) {
                 $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset');
             }
         }
         if ('' === $r['body']) {
             $r['body'] = null;
         }
         if (!isset($r['headers']['Content-Length']) && !isset($r['headers']['content-length'])) {
             $r['headers']['Content-Length'] = strlen($r['body']);
         }
     }
     $response = $this->_dispatch_request($url, $r);
     XApp_Utils_Strings::reset_mbstring_encoding();
     return $response;
 }