Skip to content

Commit

Permalink
Fixed core files marked as broken in a Windows server
Browse files Browse the repository at this point in the history
  • Loading branch information
cixtor committed Jun 7, 2016
1 parent 6636817 commit 5ca9a6c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
2 changes: 0 additions & 2 deletions inc/tpl/settings-scanner.html.tpl
Expand Up @@ -142,6 +142,4 @@
%%%SUCURI.Settings.SiteCheckCache%%%

%%%SUCURI.Settings.SiteCheckTimeout%%%

%%%SUCURI.Settings.DataStorage%%%
</div>
47 changes: 34 additions & 13 deletions sucuri.php
Expand Up @@ -538,6 +538,24 @@ public static function human_filesize($bytes = 0, $decimals = 2)
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[ $factor ];
}

/**
* Fix the deliminar of a resource path.
*
* In Windows based system the directory separator is a back slash which
* differs from what other file systems use. To keep consistency during the
* unit-tests we have decided to replace any non forward slash with it.
*
* @return string Fixed file path.
*/
public static function fixPath($path = '')
{
$delimiter = '/' /* Forward slash */;
$path = str_replace(DIRECTORY_SEPARATOR, $delimiter, $path);
$path = rtrim($path, $delimiter);

return $path;
}

/**
* Returns the system filepath to the relevant user uploads directory for this
* site. This is a multisite capable function.
Expand All @@ -548,6 +566,7 @@ public static function human_filesize($bytes = 0, $decimals = 2)
public static function datastore_folder_path($path = '')
{
$default_dir = 'sucuri';
$abspath = self::fixPath(ABSPATH);

if (defined('SUCURI_DATA_STORAGE')
&& file_exists(SUCURI_DATA_STORAGE)
Expand Down Expand Up @@ -575,15 +594,20 @@ public static function datastore_folder_path($path = '')
if (defined('WP_CONTENT_DIR')) {
$uploads_path = implode(DIRECTORY_SEPARATOR, array(WP_CONTENT_DIR, 'uploads'));
} else {
$uploads_path = implode(DIRECTORY_SEPARATOR, array(ABSPATH, 'wp-content', 'uploads'));
$uploads_path = implode(DIRECTORY_SEPARATOR, array($abspath, 'wp-content', 'uploads'));
}
}

$datastore = $uploads_path . DIRECTORY_SEPARATOR . $default_dir;
$datastore = self::fixPath($datastore);
SucuriScanOption::update_option(':datastore_path', $datastore);
}

return $datastore . DIRECTORY_SEPARATOR . $path;
// Keep consistency with the directory separator.
$final = $datastore . DIRECTORY_SEPARATOR . $path;
$final = self::fixPath($final);

return $final;
}

/**
Expand Down Expand Up @@ -1705,7 +1729,7 @@ public function __construct()
public function get_directory_tree_md5($directory = '', $as_array = false)
{
$project_signatures = '';
$abs_path = rtrim(ABSPATH, DIRECTORY_SEPARATOR);
$abspath = self::fixPath(ABSPATH);
$files = $this->get_directory_tree($directory);

if ($as_array) {
Expand All @@ -1720,7 +1744,7 @@ public function get_directory_tree_md5($directory = '', $as_array = false)
$filesize = @filesize($filepath);

if ($as_array) {
$basename = str_replace($abs_path . DIRECTORY_SEPARATOR, '', $filepath);
$basename = str_replace($abspath . '/', '', $filepath);
$project_signatures[ $basename ] = array(
'filepath' => $filepath,
'checksum' => $file_checksum,
Expand All @@ -1729,7 +1753,7 @@ public function get_directory_tree_md5($directory = '', $as_array = false)
'modified_at' => @filemtime($filepath),
);
} else {
$filepath = str_replace($abs_path, $abs_path . DIRECTORY_SEPARATOR, $filepath);
$filepath = str_replace($abspath, $abspath . '/', $filepath);
$project_signatures .= sprintf(
"%s%s%s%s\n",
$file_checksum,
Expand Down Expand Up @@ -1787,7 +1811,9 @@ public function get_directory_tree($directory = '')
break;
}

return $tree;
if (is_array($tree) && !empty($tree)) {
return array_map(array('SucuriScan', 'fixPath'), $tree);
}
}

return false;
Expand Down Expand Up @@ -2984,10 +3010,7 @@ public static function get_default_options($settings = '')
*/
public static function optionsFilePath()
{
$folder = implode(
DIRECTORY_SEPARATOR,
array(WP_CONTENT_DIR, 'uploads', 'sucuri')
);
$folder = WP_CONTENT_DIR . '/uploads/sucuri';

if (defined('SUCURI_DATA_STORAGE')
&& file_exists(SUCURI_DATA_STORAGE)
Expand All @@ -2996,7 +3019,7 @@ public static function optionsFilePath()
$folder = SUCURI_DATA_STORAGE;
}

return sprintf('%s/sucuri-settings.php', $folder);
return $folder . '/sucuri-settings.php';
}

/**
Expand Down Expand Up @@ -10578,8 +10601,6 @@ function sucuriscan_integrity_form_submissions()
*/
function sucuriscan_get_integrity_tree($dir = './', $recursive = false)
{
$abs_path = rtrim(ABSPATH, '/');

$file_info = new SucuriScanFileInfo();
$file_info->ignore_files = false;
$file_info->ignore_directories = false;
Expand Down

0 comments on commit 5ca9a6c

Please sign in to comment.