} } if ($save) { // try and fix it @chmod($htfile, 0777); if (is_writeable($htfile)) { if (@file_put_contents($htfile, $ht)) { $err = ''; } clearstatcache(); } @chmod($htfile, 0444); } $good = checkMark($base, $b, $err, gettext("Setup was not able to write to the file change RewriteBase match the install folder.") . "<br />" . sprintf(gettext("Either make the file writeable or set <code>RewriteBase</code> in your <code>.htaccess</code> file to <code>%s</code>."), $d)) && $good; if ($siteupdate) { $good = checkMark($save, gettext('Rewrite rules updated'), gettext('Rewrite rules updated [not updated]'), gettext("Setup was not able to write to the file change the rewrite rules for site upgrades.")) && $good; } } //robots.txt file $robots = file_get_contents(dirname(dirname(__FILE__)) . '/example_robots.txt'); if ($robots === false) { checkmark(-1, gettext('<em>robots.txt</em> file'), gettext('<em>robots.txt</em> file [Not created]'), gettext('Setup could not find the <em>example_robots.txt</em> file.')); } else { if (file_exists($serverpath . '/robots.txt')) { checkmark(-2, gettext('<em>robots.txt</em> file'), gettext('<em>robots.txt</em> file [Not created]'), gettext('Setup did not create a <em>robots.txt</em> file because one already exists.')); } else { $text = explode('# Place it in the root folder of your web pages.', $robots); $d = dirname(dirname(dirname($_SERVER['SCRIPT_NAME']))); if ($d == '/') { $d = ''; }
/** * * checks presence and permissions of folders * @param $which * @param $path * @param $class * @param $relaxation * @param $subfolders */ function folderCheck($which, $path, $class, $relaxation = true, $subfolders = NULL) { global $const_webpath, $serverpath, $chmod, $permission_names; $path = str_replace('\\', '/', $path); if (!is_dir($path) && $class == 'std') { mkdir_recursive($path, $chmod); } $serverpath = str_replace('\\', '/', dirname(dirname(dirname(__FILE__)))); switch ($class) { case 'std': $append = str_replace($serverpath, '', $path); if (substr($append, -1, 1) == '/') { $append = substr($append, 0, -1); } if (substr($append, 0, 1) == '/') { $append = substr($append, 1); } if ($append != $which) { $f = " (<em>{$append}</em>)"; } else { $f = ''; } if (!is_null($subfolders)) { $subfolderfailed = ''; foreach ($subfolders as $subfolder) { if (!mkdir_recursive($path . $subfolder, $chmod)) { $subfolderfailed .= ', <code>' . $subfolder . '</code>'; } } if (!empty($subfolderfailed)) { return checkMark(-1, '', sprintf(gettext('<em>%1$s</em> folder%2$s [subfolder creation failure]'), $which, $f), sprintf(gettext('Setup could not create the following subfolders:<br />%s'), substr($subfolderfailed, 2))); } } $perms = fileperms($path) & 0777; if (zp_loggedin(ADMIN_RIGHTS) && ($chmod < $perms || $relaxation && $chmod != $perms)) { @chmod($path, $chmod); clearstatcache(); if (($perms = fileperms($path) & 0777) != $chmod) { if (array_key_exists($perms, $permission_names)) { $perms_class = $permission_names[$perms]; } else { $perms_class = gettext('unknown'); } if (array_key_exists($chmod, $permission_names)) { $chmod_class = $permission_names[$chmod]; } else { $chmod_class = gettext('unknown'); } return checkMark(-1, '', sprintf(gettext('<em>%1$s</em> folder%2$s [permissions failure]'), $which, $f), sprintf(gettext('Setup could not change the folder permissions from <em>%1$s</em> (<code>0%2$o</code>) to <em>%3$s</em> (<code>0%4$o</code>). You will have to set the permissions manually. See the <a href="http://www.zenphoto.org/news/troubleshooting-zenphoto#29">Troubleshooting guide</a> for details on Zenphoto permissions requirements.'), $perms_class, $perms, $chmod_class, $chmod)); } else { ?> <script type="text/javascript"> // <!-- <![CDATA[ $.ajax({ type: 'POST', url: '<?php echo WEBPATH . '/' . ZENFOLDER; ?> /setup_permissions_changer.php', data: 'folder=<?php echo $path; ?> &key=<?php echo sha1(filemtime(CONFIGFILE) . file_get_contents(CONFIGFILE)); ?> ' }); // ]]> --> </script> <?php } } break; case 'in_webpath': if (empty($const_webpath)) { $serverroot = $serverpath; } else { $serverroot = substr($serverpath, 0, strpos($serverpath, $const_webpath)); } $append = substr($path, strlen($serverroot)); $f = " (<em>{$append}</em>)"; break; case 'external': $append = $path; $f = " (<em>{$append}</em>)"; break; } if (!is_dir($path)) { $msg = " " . sprintf(gettext('You must create the folder <em>%1$s</em><br /><code>mkdir(%2$s, 0777)</code>.'), $append, $path); if ($class != 'std') { return checkMark(false, '', sprintf(gettext('<em>%1$s</em> folder [<em>%2$s</em> does not exist]'), $which, $append), $msg); } else { return checkMark(false, '', sprintf(gettext('<em>%1$s</em> folder [<em>%2$s</em> does not exist and <strong>setup</strong> could not create it]'), $which, $append), $msg); } } else { if (!is_writable($path)) { $msg = sprintf(gettext('Change the permissions on the <code>%1$s</code> folder to be writable by the server (<code>chmod 777 %2$s</code>)'), $which, $append); return checkMark(false, '', sprintf(gettext('<em>%1$s</em> folder [<em>%2$s</em> is not writeable and <strong>setup</strong> could not make it so]'), $which, $append), $msg); } else { return checkMark(true, sprintf(gettext('<em>%1$s</em> folder%2$s'), $which, $f), '', ''); } } }
/** * * checks presence and permissions of folders * @param $which * @param $path * @param $class * @param $relaxation * @param $subfolders */ function folderCheck($which, $path, $class, $subfolders, $recurse, $chmod, $updatechmod) { global $permission_names; $path = str_replace('\\', '/', $path); if (!is_dir($path) && $class == 'std') { mkdir_recursive($path, $chmod); } switch ($class) { case 'std': $append = trim(str_replace(SERVERPATH, '', $path), '/'); if ($append != $which) { $f = " (<em>{$append}</em>)"; } else { $f = ''; } if (!is_null($subfolders)) { $subfolderfailed = ''; foreach ($subfolders as $subfolder) { if (!mkdir_recursive($path . $subfolder, $chmod)) { $subfolderfailed .= ', <code>' . $subfolder . '</code>'; } } if (!empty($subfolderfailed)) { return checkMark(-1, '', sprintf(gettext('<em>%1$s</em> folder%2$s [subfolder creation failure]'), $which, $f), sprintf(gettext('Setup could not create the following subfolders:<br />%s'), substr($subfolderfailed, 2))); } } if (isWin()) { $perms = fileperms($path) & 0700; $check = $chmod & 0700; } else { $perms = fileperms($path) & 0777; $check = $chmod; } if (setupUserAuthorized() && $updatechmod) { @chmod($path, $chmod); clearstatcache(); $perms = fileperms($path) & 0777; if (!checkPermissions($perms, $chmod)) { if (array_key_exists($perms & 0666 | 4, $permission_names)) { $perms_class = $permission_names[$perms & 0666 | 4]; } else { $perms_class = gettext('unknown'); } if (array_key_exists($chmod & 0666 | 4, $permission_names)) { $chmod_class = $permission_names[$chmod & 0666 | 4]; } else { $chmod_class = gettext('unknown'); } return checkMark(-1, '', sprintf(gettext('<em>%1$s</em> folder%2$s [permissions failure]'), $which, $f), sprintf(gettext('Setup could not change the file permissions from <em>%1$s</em> (<code>0%2$o</code>) to <em>%3$s</em> (<code>0%4$o</code>). You will have to set the permissions manually.'), $perms_class, $perms, $chmod_class, $chmod)); } else { if ($recurse) { ?> <script type="text/javascript"> // <!-- <![CDATA[ $.ajax({ type: 'POST', cache: false, url: '<?php echo WEBPATH . '/' . ZENFOLDER; ?> /setup/setup_permissions_changer.php', data: 'folder=<?php echo $path; ?> &key=<?php echo sha1(filemtime(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE) . file_get_contents(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE)); ?> ' }); // ]]> --> </script> <?php } } } break; case 'in_webpath': $webpath = $_SERVER['SCRIPT_NAME']; if (empty($webpath)) { $serverroot = SERVERPATH; } else { $i = strpos($webpath, '/' . ZENFOLDER); $webpath = substr($webpath, 0, $i); $serverroot = substr(SERVERPATH, 0, strpos(SERVERPATH, $webpath)); } $append = substr($path, strlen($serverroot) + 1); $f = " (<em>{$append}</em>)"; break; case 'external': $append = $path; $f = " (<em>{$append}</em>)"; break; } if (!is_dir($path)) { $msg = " " . sprintf(gettext('You must create the folder <em>%1$s</em><br /><code>mkdir(%2$s, 0777)</code>.'), $append, substr($path, 0, -1)); if ($class != 'std') { return checkMark(false, '', sprintf(gettext('<em>%1$s</em> folder [<em>%2$s</em> does not exist]'), $which, $append), $msg); } else { return checkMark(false, '', sprintf(gettext('<em>%1$s</em> folder [<em>%2$s</em> does not exist and <strong>setup</strong> could not create it]'), $which, $append), $msg); } } else { if (!is_writable($path)) { $msg = sprintf(gettext('Change the permissions on the <code>%1$s</code> folder to be writable by the server (<code>chmod 777 %2$s</code>)'), $which, $append); return checkMark(false, '', sprintf(gettext('<em>%1$s</em> folder [<em>%2$s</em> is not writeable and <strong>setup</strong> could not make it so]'), $which, $append), $msg); } else { return checkMark(true, sprintf(gettext('<em>%1$s</em> folder%2$s'), $which, $f), '', ''); } } }
function folderCheck($which, $path, $class) { global $const_webpath, $serverpath; if (!is_dir($path) && $class == 'std') { @mkdir($path, CHMOD_VALUE); } @chmod($path, CHMOD_VALUE); $folder = basename($path); if (empty($folder)) { $folder = basename(basename($path)); } switch ($class) { case 'std': $append = $folder; break; case 'in_webpath': $serverpath = dirname(dirname(__FILE__)); if (empty($const_webpath)) { $serverroot = $serverpath; } else { $serverroot = substr($serverpath, 0, strpos($serverpath, $const_webpath)); } $append = substr($path, strlen($serverroot)); break; case 'external': $append = $path; break; } $f = ''; if (!is_dir($path)) { $e = ''; if ($class != 'std') { $sfx = ' ' . sprintf(gettext("[<em>%s</em> does not exist]"), $append); $folder = $append; } else { $sfx = ' ' . sprintf(gettext("[<em>%s</em> does not exist and <strong>setup</strong> could not create it]"), $append); } $msg = " " . sprintf(gettext('You must create the folder <em>%1$s</em><br /><code>mkdir(%2$s, 0777)</code>.'), $folder, $path); } else { if (!is_writable($path)) { $sfx = ' ' . sprintf(gettext('[<em>%s</em> is not writeable and <strong>setup</strong> could not make it so]'), $append); $msg = sprintf(gettext('Change the permissions on the <code>%1$s</code> folder to be writable by the server (<code>chmod 777 %2$s</code>)'), $folder, $append); } else { if ($folder != $which || $class != 'std') { $f = " (<em>{$append}</em>)"; } $msg = ''; $sfx = ''; } } return checkMark(is_dir($path) && is_writable($path), sprintf(gettext(" <em>%s</em> folder"), $which) . $f, $sfx, $msg); }
// try and fix it @chmod($htfile, 0666 & $chmod); if (is_writeable($htfile)) { $ht = substr($ht, 0, $i) . "RewriteBase {$d}\n" . substr($ht, $j + 1); if ($handle = fopen($htfile, 'w')) { if (fwrite($handle, $ht)) { $base = true; $b = sprintf(gettext("<em>.htaccess</em> RewriteBase is <code>%s</code> (fixed)"), $d); $err = ''; } fclose($handle); clearstatcache(); } } } $good = checkMark($base, $b, $err, gettext("Setup was not able to write to the file change RewriteBase match the install folder.") . "<br />" . sprintf(gettext("Either make the file writeable or set <code>RewriteBase</code> in your <code>.htaccess</code> file to <code>%s</code>."), $d)) && $good; } //robots.txt file $robots = file_get_contents(dirname(__FILE__) . '/example_robots.txt'); if ($robots === false) { checkmark(-1, gettext('<em>robots.txt</em> file'), gettext('<em>robots.txt</em> file [Not created]'), gettext('Setup could not find the <em>example_robots.txt</em> file.')); } else { if (file_exists(dirname(dirname(__FILE__)) . '/robots.txt')) { checkmark(-2, gettext('<em>robots.txt</em> file'), gettext('<em>robots.txt</em> file [Not created]'), '<p>' . gettext('Setup did not create a <em>robots.txt</em> file because one already exists.') . '</p>'); } else { $text = explode('****delete all lines above and including this one *******' . "\n", $robots); $d = dirname(dirname($_SERVER['SCRIPT_NAME'])); if ($d == '/') { $d = ''; } $robots = str_replace('/zenphoto', $d, $text[1]);