Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a compatibility function for is_writable for Windows

  • Loading branch information...
commit 7f5699acd380725271c9c309ba68c7be53f95abc 1 parent cb8c608
@markkevans markkevans authored haraldpdl committed
View
2  catalog/admin/administrators.php
@@ -22,7 +22,7 @@
'Require valid-user',
'##### OSCOMMERCE ADMIN PROTECTION - END #####');
- if (file_exists(DIR_FS_ADMIN . '.htpasswd_oscommerce') && is_writable(DIR_FS_ADMIN . '.htpasswd_oscommerce') && file_exists(DIR_FS_ADMIN . '.htaccess') && is_writable(DIR_FS_ADMIN . '.htaccess')) {
+ if (file_exists(DIR_FS_ADMIN . '.htpasswd_oscommerce') && tep_is_writable(DIR_FS_ADMIN . '.htpasswd_oscommerce') && file_exists(DIR_FS_ADMIN . '.htaccess') && tep_is_writable(DIR_FS_ADMIN . '.htaccess')) {
$htaccess_array = array();
$htpasswd_array = array();
View
8 catalog/admin/define_language.php
@@ -24,7 +24,7 @@ function tep_opendir($path) {
if (!in_array($filename, $exclude_array)) {
$file = array('name' => $path . $filename,
'is_dir' => is_dir($path . $filename),
- 'writable' => is_writable($path . $filename),
+ 'writable' => tep_is_writable($path . $filename),
'size' => filesize($path . $filename),
'last_modified' => strftime(DATE_TIME_FORMAT, filemtime($path . $filename)));
@@ -72,7 +72,7 @@ function tep_opendir($path) {
if (isset($HTTP_GET_VARS['lngdir']) && isset($HTTP_GET_VARS['filename'])) {
$file = DIR_FS_CATALOG_LANGUAGES . $HTTP_GET_VARS['filename'];
- if (file_exists($file) && is_writable($file)) {
+ if (file_exists($file) && tep_is_writable($file)) {
$new_file = fopen($file, 'w');
$file_contents = stripslashes($HTTP_POST_VARS['file_contents']);
fwrite($new_file, $file_contents, strlen($file_contents));
@@ -128,7 +128,7 @@ function tep_opendir($path) {
$contents = implode('', $file_array);
$file_writeable = true;
- if (!is_writable($file)) {
+ if (!tep_is_writable($file)) {
$file_writeable = false;
$messageStack->reset();
$messageStack->add(sprintf(ERROR_FILE_NOT_WRITEABLE, $file), 'error');
@@ -185,7 +185,7 @@ function tep_opendir($path) {
</tr>
<tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">
<td class="dataTableContent"><a href="<?php echo tep_href_link(FILENAME_DEFINE_LANGUAGE, 'lngdir=' . $HTTP_GET_VARS['lngdir'] . '&filename=' . $filename); ?>"><b><?php echo $filename; ?></b></a></td>
- <td class="dataTableContent" align="center"><?php echo tep_image(DIR_WS_IMAGES . 'icons/' . ((is_writable(DIR_FS_CATALOG_LANGUAGES . $filename) == true) ? 'tick.gif' : 'cross.gif')); ?></td>
+ <td class="dataTableContent" align="center"><?php echo tep_image(DIR_WS_IMAGES . 'icons/' . ((tep_is_writable(DIR_FS_CATALOG_LANGUAGES . $filename) == true) ? 'tick.gif' : 'cross.gif')); ?></td>
<td class="dataTableContent" align="right"><?php echo strftime(DATE_TIME_FORMAT, filemtime(DIR_FS_CATALOG_LANGUAGES . $filename)); ?></td>
</tr>
<?php
View
2  catalog/admin/includes/modules/security_check/config_file_catalog.php
@@ -20,7 +20,7 @@ function securityCheck_config_file_catalog() {
}
function pass() {
- return (file_exists(DIR_FS_CATALOG . 'includes/configure.php') && !is_writable(DIR_FS_CATALOG . 'includes/configure.php'));
+ return (file_exists(DIR_FS_CATALOG . 'includes/configure.php') && !tep_is_writable(DIR_FS_CATALOG . 'includes/configure.php'));
}
function getMessage() {
View
4 catalog/admin/includes/modules/security_check/session_storage.php
@@ -20,14 +20,14 @@ function securityCheck_session_storage() {
}
function pass() {
- return ((STORE_SESSIONS != '') || (is_dir(tep_session_save_path()) && is_writable(tep_session_save_path())));
+ return ((STORE_SESSIONS != '') || (is_dir(tep_session_save_path()) && tep_is_writable(tep_session_save_path())));
}
function getMessage() {
if (STORE_SESSIONS == '') {
if (!is_dir(tep_session_save_path())) {
return WARNING_SESSION_DIRECTORY_NON_EXISTENT;
- } elseif (!is_writable(tep_session_save_path())) {
+ } elseif (!tep_is_writable(tep_session_save_path())) {
return WARNING_SESSION_DIRECTORY_NOT_WRITEABLE;
}
}
View
2  catalog/admin/sec_dir_permissions.php
@@ -24,7 +24,7 @@ function tep_opendir($path) {
if (!in_array($filename, $exclude_array)) {
$file = array('name' => $path . $filename,
'is_dir' => is_dir($path . $filename),
- 'writable' => is_writable($path . $filename));
+ 'writable' => tep_is_writable($path . $filename));
$result[] = $file;
View
33 catalog/install/includes/functions/general.php
@@ -55,4 +55,35 @@ function osc_encrypt_string($plain) {
return $password;
}
-?>
+
+////
+// Wrapper function for is_writable() for Windows compatibility
+ function osc_is_writable($file) {
+ if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
+ if (file_exists($file)) {
+ $file = realpath($file);
+ if (is_dir($file)) {
+ $result = @tempnam($file, 'osc');
+ if (is_string($result) && file_exists($result)) {
+ unlink($result);
+ return (strpos($result, $file) === 0) ? true : false;
+ }
+ } else {
+ $handle = @fopen($file, 'r+');
+ if (is_resource($handle)) {
+ fclose($handle);
+ return true;
+ }
+ }
+ } else{
+ $dir = dirname($file);
+ if (file_exists($dir) && is_dir($dir) && tep_is_writable($dir)) {
+ return true;
+ }
+ }
+ return false;
+ } else {
+ return is_writable($file);
+ }
+ }
+?>
View
2  catalog/install/templates/pages/install_3.php
@@ -74,7 +74,7 @@
</tr>
<?php
- if (is_writable($dir_fs_document_root) && is_writable($dir_fs_document_root . 'admin')) {
+ if (osc_is_writable($dir_fs_document_root) && osc_is_writable($dir_fs_document_root . 'admin')) {
?>
<tr>
<td class="inputField"><?php echo 'Administration Directory Name<br />' . osc_draw_input_field('CFG_ADMIN_DIRECTORY', 'admin', 'class="text"'); ?></td>
View
8 catalog/install/templates/pages/install_4.php
@@ -101,7 +101,7 @@
}
$admin_folder = 'admin';
- if (isset($HTTP_POST_VARS['CFG_ADMIN_DIRECTORY']) && !empty($HTTP_POST_VARS['CFG_ADMIN_DIRECTORY']) && is_writable($dir_fs_document_root) && is_writable($dir_fs_document_root . 'admin')) {
+ if (isset($HTTP_POST_VARS['CFG_ADMIN_DIRECTORY']) && !empty($HTTP_POST_VARS['CFG_ADMIN_DIRECTORY']) && osc_is_writable($dir_fs_document_root) && osc_is_writable($dir_fs_document_root . 'admin')) {
$admin_folder = preg_replace('/[^a-zA-Z0-9]/', '', trim($HTTP_POST_VARS['CFG_ADMIN_DIRECTORY']));
if (empty($admin_folder)) {
@@ -219,7 +219,7 @@
<?php
}
- if (file_exists($dir_fs_document_root . 'includes/configure.php') && is_writable($dir_fs_document_root . 'includes/configure.php')) {
+ if (file_exists($dir_fs_document_root . 'includes/configure.php') && osc_is_writable($dir_fs_document_root . 'includes/configure.php')) {
?>
<li>Set the permissions on <?php echo $dir_fs_document_root . 'includes/configure.php'; ?> to 644 (or 444 if this file is still writable).</li>
@@ -227,7 +227,7 @@
<?php
}
- if (file_exists($dir_fs_document_root . $admin_folder . '/includes/configure.php') && is_writable($dir_fs_document_root . $admin_folder . '/includes/configure.php')) {
+ if (file_exists($dir_fs_document_root . $admin_folder . '/includes/configure.php') && osc_is_writable($dir_fs_document_root . $admin_folder . '/includes/configure.php')) {
?>
<li>Set the permissions on <?php echo $dir_fs_document_root . $admin_folder . '/includes/configure.php'; ?> to 644 (or 444 if this file is still writable).</li>
@@ -240,4 +240,4 @@
<li>The Administration Tool should be further protected using htaccess/htpasswd and can be set-up within the Configuration -> Administrators page.</li>
</ol>
</div>
-</div>
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.