Ejemplo n.º 1
0
 /**
  * Calculate the path to the site "home" directory.
  *
  * The home directory is the path equivalent to the home_url. That is,
  * the path to the true root of the website. In situations where WordPress is
  * installed in a subdirectory the home path is different to ABSPATH
  *
  * @param string $site_path The site_path to use when calculating the home path, defaults to ABSPATH
  */
 public static function get_home_path($site_path = ABSPATH)
 {
     if (defined('HMBKP_ROOT') && HMBKP_ROOT) {
         return wp_normalize_path(HMBKP_ROOT);
     }
     $home_path = $site_path;
     if (path_in_php_open_basedir(dirname($site_path))) {
         // Handle wordpress installed in a subdirectory
         // 1. index.php and wp-config.php found in parent dir
         // 2. index.php in parent dir, wp-config.php in $site_path ( wp-config.php can be in both locations )
         if ((file_exists(dirname($site_path) . '/wp-config.php') || file_exists($site_path . '/wp-config.php')) && file_exists(dirname($site_path) . '/index.php')) {
             $home_path = dirname($site_path);
         }
         // Handle wp-config.php being above site_path
         if (file_exists(dirname($site_path) . '/wp-config.php') && !file_exists($site_path . '/wp-config.php') && !file_exists(dirname($site_path) . '/index.php')) {
             $home_path = $site_path;
         }
     }
     return wp_normalize_path(untrailingslashit($home_path));
 }
Ejemplo n.º 2
0
 /**
  * Calculate the path to the site "home" directory.
  *
  * The home directory is the path equivalent to the home_url. That is,
  * the path to the true root of the website. In situations where WordPress is
  * installed in a subdirectory the home path is different to ABSPATH
  *
  * @param string $site_path The site_path to use when calculating the home path, defaults to ABSPATH
  */
 public static function get_home_path($site_path = ABSPATH)
 {
     if (defined('HMBKP_ROOT') && HMBKP_ROOT) {
         return wp_normalize_path(HMBKP_ROOT);
     }
     $home_path = wp_normalize_path($site_path);
     if (path_in_php_open_basedir(dirname($site_path))) {
         $home = set_url_scheme(get_option('home'), 'http');
         $siteurl = set_url_scheme(get_option('siteurl'), 'http');
         if (!empty($home) && 0 !== strcasecmp($home, $siteurl)) {
             $wp_path_rel_to_home = str_ireplace($home, '', $siteurl);
             /* $siteurl - $home */
             $pos = strripos(wp_normalize_path($_SERVER['SCRIPT_FILENAME']), trailingslashit($wp_path_rel_to_home));
             $home_path = substr(wp_normalize_path($_SERVER['SCRIPT_FILENAME']), 0, $pos);
             $home_path = trailingslashit($home_path);
         }
         if (is_multisite()) {
             $slashed_home = trailingslashit(get_option('home'));
             $base = parse_url($slashed_home, PHP_URL_PATH);
             $document_root_fix = wp_normalize_path(realpath($_SERVER['DOCUMENT_ROOT']));
             $abspath_fix = wp_normalize_path(ABSPATH);
             $home_path = strpos($abspath_fix, $document_root_fix) === 0 ? $document_root_fix . $base : $home_path;
         }
     }
     return wp_normalize_path(untrailingslashit($home_path));
 }
Ejemplo n.º 3
0
function set_server_config_notices()
{
    $notices = Notices::get_instance();
    $messages = array();
    if (!is_dir(Path::get_path())) {
        $messages[] = sprintf(__('The backups directory can\'t be created because your %s directory isn\'t writable. Please create the folder manually.', 'backupwordpress'), '<code>' . esc_html(dirname(Path::get_path())) . '</code>');
    }
    if (is_dir(Path::get_path()) && !wp_is_writable(Path::get_path())) {
        $messages[] = __('The backups directory isn\'t writable. Please fix the permissions.', 'backupwordpress');
    }
    if (Backup_Utilities::is_safe_mode_on()) {
        $messages[] = sprintf(__('%1$s is running in %2$s, please contact your host and ask them to disable it. BackUpWordPress may not work correctly whilst %3$s is on.', 'backupwordpress'), '<code>PHP</code>', sprintf('<a href="%1$s">%2$s</a>', __('http://php.net/manual/en/features.safe-mode.php', 'backupwordpress'), __('Safe Mode', 'backupwordpress')), '<code>' . __('Safe Mode', 'backupwordpress') . '</code>');
    }
    if (defined('HMBKP_PATH') && HMBKP_PATH) {
        // Suppress open_basedir warning https://bugs.php.net/bug.php?id=53041
        if (!path_in_php_open_basedir(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your server has an %1$s restriction in effect and your custom backups directory (%2$s) is not within the allowed path(s): (%3$s).', 'backupwordpress'), '<code>open_basedir</code>', '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(@ini_get('open_basedir')) . '</code>');
        } elseif (!file_exists(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your custom path does not exist', 'backupwordpress'));
        } else {
            if (!is_dir(HMBKP_PATH)) {
                $messages[] = sprintf(__('Your custom backups directory %1$s doesn\'t exist and can\'t be created, your backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(Path::get_path()) . '</code>');
            }
            if (is_dir(HMBKP_PATH) && !wp_is_writable(HMBKP_PATH)) {
                $messages[] = sprintf(__('Your custom backups directory %1$s isn\'t writable, new backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(Path::get_path()) . '</code>');
            }
        }
    }
    if (!is_readable(Path::get_root())) {
        $messages[] = sprintf(__('Your site root path %s isn\'t readable.', 'backupwordpress'), '<code>' . Path::get_root() . '</code>');
    }
    if (!Requirement_Mysqldump_Command_Path::test() && !Requirement_PDO::test()) {
        $messages[] = sprintf(__('Your database cannot be backed up because your server doesn\'t support %1$s or %2$s. Please contact your host and ask them to enable them.', 'backupwordpress'), '<code>mysqldump</code>', '<code>PDO</code>');
    }
    if (count($messages) > 0) {
        $notices->set_notices('server_config', $messages, false);
    }
}
 public function test_preceding_basedir()
 {
     $this->basedir = 'foobarbaz' . dirname(__DIR__);
     $this->assertFalse(path_in_php_open_basedir(__DIR__, array($this, 'ini_get_mock')));
 }