/**
	 * Get file permissions from the requested directory.
	 *
	 * If the directory permissions cannot be read, a default value of 0644 will be returned.
	 *
	 * @since 1.15.0
	 *
	 * @param string $dir Full path to the file to retrieve permissions from.
	 * @return int|WP_Error The permissions as an int or a WP_Error object if an error occurs.
	 */
	public static function get_permissions( $dir ) {
		if ( ! self::is_dir( $dir ) ) {
			return new WP_Error( 'itsec-lib-dir-get-permissions-missing-dir', sprintf( __( 'Permissions for the directory %s could not be read as the directory could not be found.', 'it-l10n-ithemes-security-pro' ), $dir ) );
		}
		
		if ( ! ITSEC_Lib_Utility::is_callable_function( 'fileperms' ) ) {
			return new WP_Error( 'itsec-lib-directory-get-permissions-fileperms-is-disabled', sprintf( __( 'Permissions for the directory %s could not be read as the fileperms() function is disabled. This is a system configuration issue.', 'it-l10n-ithemes-security-pro' ), $dir ) );
		}
		
		
		$dir = rtrim( $dir, '/' );
		@clearstatcache( true, $dir );
		
		return fileperms( $dir ) & 0777;
	}
Пример #2
0
 /**
  * Get file permissions from the requested file.
  *
  * @since 1.15.0
  *
  * @param string $file Full path to the file to retrieve permissions from.
  * @return int|WP_Error The permissions as an int or a WP_Error object if an error occurs.
  */
 public static function get_permissions($file)
 {
     if (!self::is_file($file)) {
         return new WP_Error('itsec-lib-file-get-permissions-missing-file', sprintf(__('Permissions for the file %s could not be read as the file could not be found.', 'it-l10n-better-wp-security'), $file));
     }
     if (!ITSEC_Lib_Utility::is_callable_function('fileperms')) {
         return new WP_Error('itsec-lib-file-get-permissions-fileperms-is-disabled', sprintf(__('Permissions for the file %s could not be read as the fileperms() function is disabled. This is a system configuration issue.', 'it-l10n-better-wp-security'), $file));
     }
     @clearstatcache(true, $file);
     return fileperms($file) & 0777;
 }
 /**
  * Internal class function to remove comments from a string containing PHP code.
  *
  * @since 1.15.0
  * @access protected
  *
  * @param string $contents String containing the code to strip of comments.
  * @return string|WP_Error Returns a string containing the stripped source or a WP_Error object on an error.
  */
 protected static function strip_php_comments($contents)
 {
     if (!ITSEC_Lib_Utility::is_callable_function('token_get_all')) {
         return new WP_Error('itsec-lib-config-file-strip-php-comments-token-get-all-is-disabled', __('Unable to strip comments from the source code as the token_get_all() function is disabled. This is a system configuration issue.', 'it-l10n-better-wp-security'));
     }
     $tokens = token_get_all($contents);
     if (!is_array($tokens)) {
         return new WP_Error('itsec-lib-config-file-strip-php-comments-token-get-all-invalid-response', sprintf(__('Unable to strip comments from the source code as the token_get_all() function returned an unrecognized value (type: %s)', 'it-l10n-better-wp-security'), gettype($tokens)));
     }
     if (!defined('T_ML_COMMENT')) {
         define('T_ML_COMMENT', T_COMMENT);
     }
     if (!defined('T_DOC_COMMENT')) {
         define('T_DOC_COMMENT', T_ML_COMMENT);
     }
     $contents = '';
     foreach ($tokens as $token) {
         if (is_string($token)) {
             $contents .= $token;
         } else {
             list($id, $text) = $token;
             switch ($id) {
                 case T_COMMENT:
                 case T_ML_COMMENT:
                 case T_DOC_COMMENT:
                     break;
                 default:
                     $contents .= $text;
                     break;
             }
         }
     }
     return $contents;
 }