/** * Create the data folder with appropriate permissions * * 1) make parent directory writable * 2) delete existing /data folder * 3) create /data folder with php's mkdir() (so it has the correct owner) * 4) restore parent directory * */ public function FTP_DataFolder() { global $dataDir, $install_ftp_connection, $langmessage; $this->root_mode = fileperms($dataDir); if (!$this->root_mode) { return false; } // (1) $modDir = ftp_site($install_ftp_connection, 'CHMOD 0777 ' . $this->ftp_root); if (!$modDir) { echo '<li><span class="failed">'; echo sprintf($langmessage['Could_Not_'], '<em>CHMOD 0777 ' . $this->ftp_root . '</em>'); echo '</span></li>'; return false; } // (2) use rename instead of trying to delete recursively $php_dir = $dataDir . '/data'; $php_del = false; if (file_exists($php_dir)) { $ftp_dir = rtrim($this->ftp_root, '/') . '/data'; $del_name = '/data-delete-' . rand(0, 10000); $ftp_del = rtrim($this->ftp_root, '/') . $del_name; $php_del = $dataDir . $del_name; $changed = ftp_rename($install_ftp_connection, $ftp_dir, $ftp_del); if (!$changed) { echo '<li><span class="failed">'; echo sprintf($langmessage['Could_Not_'], '<em>Remove ' . $this->ftp_root . '/data</em>'); echo '</span></li>'; return false; } } // (3) use rename instead of trying to delete recursively $mode = 0755; if (defined(gp_chmod_dir)) { $mode = gp_chmod_dir; } if (!mkdir($php_dir, $mode)) { echo '<li><span class="failed">'; echo sprintf($langmessage['Could_Not_'], '<em>mkdir(' . $php_dir . ')</em>'); echo '</span></li>'; return false; } // (4) will be done afterwards // make sure it's writable ? clearstatcache(); if (!gp_is_writable($php_dir)) { return false; } echo '<li><span class="passed"><b>'; echo $langmessage['Success_continue_below']; echo '</b></span></li>'; if ($php_del) { $this->CopyData($php_del, $php_dir); } return true; }
/** * Get the minimum filesystem_method for $file * @static */ static function get_filesystem_method_file($file) { if (gp_is_writable($file)) { return gp_filesystem_direct; } elseif (function_exists('ftp_connect')) { return gp_filesystem_ftp; } else { return false; } }
/** * Modified from Wordpress function win_is_writable() * Working for users without requiring trailing slashes as noted in Wordpress * * Workaround for Windows bug in is_writable() function * will work in despite of Windows ACLs bug * NOTE: use a trailing slash for folders!!! * see http://bugs.php.net/bug.php?id=27609 * see http://bugs.php.net/bug.php?id=30931 * * @param string $path * @return bool */ function gp_is_writable($path) { if (is_writable($path)) { return true; } if (strpos($_SERVER['SERVER_SOFTWARE'], 'IIS') === false) { return false; } if (is_dir($path)) { return gp_is_writable($path . '/' . uniqid(mt_rand()) . '.tmp'); } // check tmp file for read/write capabilities $should_delete_tmp_file = !file_exists($path); $f = @fopen($path, 'a'); if ($f === false) { return false; } fclose($f); if ($should_delete_tmp_file) { unlink($path); } return true; }
/** * Determine if the directory and all it's contents are writable * */ public static function writable_dir($dir) { if (!gp_is_writable($dir)) { return false; } $dh = @opendir($dir); if (!$dh) { return false; } $dir = str_replace('\\', '/', $dir); $dir = rtrim($dir, '/'); while (($file = readdir($dh)) !== false) { if ($file === '.' || $file === '..') { continue; } $full_path = $dir . '/' . $file; if (!self::writable($full_path)) { msg('not writable: ' . $full_path); return false; } } return true; }
protected function CheckFile($path, $type = 'dir') { $current = '?'; $expected = '777'; $euid = '?'; if (\gp\install\FilePermissions::HasFunctions()) { $current = @substr(decoct(@fileperms($path)), -3); if ($type == 'file') { $expected = \gp\install\FilePermissions::getExpectedPerms_file($path); } else { $expected = \gp\install\FilePermissions::getExpectedPerms($path); } if (\gp\install\FilePermissions::perm_compare($expected, $current)) { $this->passed_count++; return; } $euid = \gp\install\FilePermissions::file_uid($path); } elseif (gp_is_writable($path)) { $this->passed_count++; return; } $this->failed_count++; if ($this->failed_count > $this->show_failed_max) { return; } echo '<tr><td>'; echo substr($path, $this->check_dir_len); echo '</td><td>'; echo $current; echo '</td><td>'; echo $expected; echo '</td><td>'; echo $euid; echo '</td><td>'; echo $this->euid; echo '</td></tr>'; }
function CheckDataFolder() { global $ok, $dataDir, $langmessage; echo '<tr>'; echo '<td class="nowrap">'; $folder = $dataDir . '/data'; if (strlen($folder) > 23) { $show = '...' . substr($folder, -20); } else { $show = $folder; } echo sprintf($langmessage['Permissions_for'], $show); echo ' '; echo '</td>'; if (!is_dir($folder)) { if (!@mkdir($folder, 0777)) { echo '<td class="passed_orange">' . $langmessage['See_Below'] . ' (0)</td>'; $this->can_write_data = $ok = false; } else { echo '<td class="passed">' . $langmessage['Passed'] . '</td>'; } } elseif (gp_is_writable($folder)) { echo '<td class="passed">' . $langmessage['Passed'] . '</td>'; } else { echo '<td class="passed_orange">' . $langmessage['See_Below'] . ' (1)</td>'; $this->can_write_data = $ok = false; } //show current info $expected = '777'; if (file_exists($folder) && ($current = @substr(decoct(fileperms($folder)), -3))) { $expected = FileSystem::getExpectedPerms($folder); if (FileSystem::perm_compare($expected, $current)) { echo '<td class="passed">'; echo $current; } else { echo '<td class="passed_orange">'; echo $current; } } else { echo '<td class="passed_orange">'; echo '???'; } echo '</td>'; echo '<td>'; echo $expected; echo '</td>'; echo '</tr>'; }