/** * Is the application/plugin/theme removable? * * @param string $Type self::TYPE_APPLICATION or self::TYPE_PLUGIN or self::TYPE_THEME * @param string $Name * @return boolean */ public static function isRemovable($Type, $Name) { switch ($Type) { case self::TYPE_APPLICATION: $ApplicationManager = Gdn::Factory('ApplicationManager'); if ($IsRemovable = !array_key_exists($Name, $ApplicationManager->EnabledApplications())) { $ApplicationInfo = arrayValue($Name, $ApplicationManager->AvailableApplications(), array()); $ApplicationFolder = arrayValue('Folder', $ApplicationInfo, ''); $IsRemovable = IsWritable(PATH_APPLICATIONS . DS . $ApplicationFolder); } break; case self::TYPE_PLUGIN: if ($IsRemovable = !array_key_exists($Name, Gdn::pluginManager()->EnabledPlugins())) { $PluginInfo = arrayValue($Name, Gdn::pluginManager()->AvailablePlugins(), false); $PluginFolder = arrayValue('Folder', $PluginInfo, false); $IsRemovable = IsWritable(PATH_PLUGINS . DS . $PluginFolder); } break; case self::TYPE_THEME: // TODO $IsRemovable = false; break; } return $IsRemovable; }
public static function CanUpload($UploadPath=NULL) { if (is_null($UploadPath)) $UploadPath = PATH_LOCAL_UPLOADS; if (ini_get('file_uploads') != 1) return FALSE; if (!is_dir($UploadPath)) @mkdir($UploadPath); if (!is_dir($UploadPath)) return FALSE; if (!IsWritable($UploadPath) || !is_readable($UploadPath)) return FALSE; return TRUE; }
/** * PHP's native is_writable() function fails to correctly determine write * capabilities on some systems (Windows), and in our tests it returned TRUE * despite not being able to create subfolders within the folder being * checked. Our version truly verifies permissions by performing file-write * tests. */ function IsWritable($Path) { if ($Path[strlen($Path) - 1] == DS) { // Recursively return a temporary file path return IsWritable($Path . uniqid(mt_rand()) . '.tmp'); } elseif (is_dir($Path)) { return IsWritable($Path . '/' . uniqid(mt_rand()) . '.tmp'); } // Check tmp file for read/write capabilities $KeepPath = file_exists($Path); $File = @fopen($Path, 'a'); if ($File === FALSE) { return FALSE; } fclose($File); if (!$KeepPath) { unlink($Path); } return TRUE; }
/** * Check minimum requirements for Garden. * * @since 2.0.0 * @access private * @return bool Whether platform passes requirement check. */ private function _CheckPrerequisites() { // Make sure we are running at least PHP 5.1 if (version_compare(phpversion(), ENVIRONMENT_PHP_VERSION) < 0) { $this->Form->AddError(sprintf(T('You are running PHP version %1$s. Vanilla requires PHP %2$s or greater. You must upgrade PHP before you can continue.'), phpversion(), ENVIRONMENT_PHP_VERSION)); } // Make sure PDO is available if (!class_exists('PDO')) { $this->Form->AddError(T('You must have the PDO module enabled in PHP in order for Vanilla to connect to your database.')); } if (!defined('PDO::MYSQL_ATTR_USE_BUFFERED_QUERY')) { $this->Form->AddError(T('You must have the MySQL driver for PDO enabled in order for Vanilla to connect to your database.')); } // Make sure that the correct filesystem permissions are in place $PermissionProblem = FALSE; // Make sure the appropriate folders are writeable. $ProblemDirectories = array(); if (!is_readable(PATH_LOCAL_CONF) || !IsWritable(PATH_LOCAL_CONF)) { $ProblemDirectories[] = PATH_LOCAL_CONF; } if (!is_readable(PATH_LOCAL_UPLOADS) || !IsWritable(PATH_LOCAL_UPLOADS)) { $ProblemDirectories[] = PATH_LOCAL_UPLOADS; } if (!is_readable(PATH_LOCAL_CACHE) || !IsWritable(PATH_LOCAL_CACHE)) { $ProblemDirectories[] = PATH_LOCAL_CACHE; } if (count($ProblemDirectories) > 0) { $PermissionProblem = TRUE; $PermissionError = T('Some folders don\'t have correct permissions.', '<p>Some of your folders do not have the correct permissions.</p><p>Using your ftp client, or via command line, make sure that the following permissions are set for your vanilla installation:</p>'); $PermissionHelp = '<pre>chmod -R 777 ' . implode("\nchmod -R 777 ", $ProblemDirectories) . '</pre>'; $this->Form->AddError($PermissionError . $PermissionHelp); } // Make sure the config folder is writeable if (!$PermissionProblem) { $ConfigFile = PATH_LOCAL_CONF . DS . 'config.php'; if (!file_exists($ConfigFile)) { file_put_contents($ConfigFile, ''); } // Make sure the config file is writeable if (!is_readable($ConfigFile) || !IsWritable($ConfigFile)) { $this->Form->AddError(sprintf(T('Your configuration file does not have the correct permissions. PHP needs to be able to read and write to this file: <code>%s</code>'), $ConfigFile)); $PermissionProblem = TRUE; } } // Make sure the cache folder is writeable if (!$PermissionProblem) { if (!file_exists(PATH_LOCAL_CACHE . DS . 'Smarty')) { mkdir(PATH_LOCAL_CACHE . DS . 'Smarty'); } if (!file_exists(PATH_LOCAL_CACHE . DS . 'Smarty' . DS . 'cache')) { mkdir(PATH_LOCAL_CACHE . DS . 'Smarty' . DS . 'cache'); } if (!file_exists(PATH_LOCAL_CACHE . DS . 'Smarty' . DS . 'compile')) { mkdir(PATH_LOCAL_CACHE . DS . 'Smarty' . DS . 'compile'); } } return $this->Form->ErrorCount() == 0 ? TRUE : FALSE; }
function IsWritable($pathfile) { $isDir = substr($pathfile, -1) == '/' ? true : false; if ($isDir) { if (is_dir($pathfile)) { mt_srand((double) microtime() * 1000000); $pathfile = $pathfile . 'dede_' . uniqid(mt_rand()) . '.tmp'; } elseif (@mkdir($pathfile)) { return IsWritable($pathfile); } else { return false; } } @chmod($pathfile, 0777); $fp = @fopen($pathfile, 'ab'); if ($fp === false) { return false; } fclose($fp); $isDir && @unlink($pathfile); return true; }
function CheckFilesystem() { ShowCheck('{docroot}/tmp writable', IsWritable('tmp')); ShowCheck('{docroot}/dat writable', IsWritable('dat')); ShowCheck('{docroot}/results writable', IsWritable('results')); ShowCheck('{docroot}/work/jobs writable', IsWritable('work/jobs')); ShowCheck('{docroot}/logs writable', IsWritable('logs')); if ('Linux' == PHP_OS) { ShowCheck('{docroot}/tmp on tmpfs', IsWPTTmpOnTmpfs(), false); } }
private function _CheckPrerequisites() { // Make sure we are running at least PHP 5.1 if (version_compare(phpversion(), ENVIRONMENT_PHP_VERSION) < 0) { $this->Form->AddError(sprintf(T('You are running PHP version %1$s. Vanilla requires PHP %2$s or greater. You must upgrade PHP before you can continue.'), phpversion(), ENVIRONMENT_PHP_VERSION)); } // Make sure PDO is available if (!class_exists('PDO')) { $this->Form->AddError(T('You must have the PDO module enabled in PHP in order for Vanilla to connect to your database.')); } if (!defined('PDO::MYSQL_ATTR_USE_BUFFERED_QUERY')) { $this->Form->AddError(T('You must have the MySQL driver for PDO enabled in order for Vanilla to connect to your database.')); } // Make sure that the correct filesystem permissions are in place $PermissionProblem = FALSE; $PermissionHelp = ' <p>Using your ftp client, or via command line, make sure that the following permissions are set for your vanilla installation:</p> <pre>chmod -R 777 ' . CombinePaths(array(PATH_ROOT, 'conf')) . ' chmod -R 777 ' . CombinePaths(array(PATH_ROOT, 'cache')) . ' chmod -R 777 ' . CombinePaths(array(PATH_ROOT, 'uploads')) . '</pre>'; // Make sure the config folder is writeable if (!is_readable(PATH_CONF) || !IsWritable(PATH_CONF)) { $this->Form->AddError(T('Your configuration folder does not have the correct permissions. PHP needs to be able to read and write to this folder.')); $PermissionProblem = TRUE; } else { $ConfigFile = PATH_CONF . DS . 'config.php'; if (!file_exists($ConfigFile)) { file_put_contents($ConfigFile, ''); } // Make sure the config file is writeable if (!is_readable($ConfigFile) || !IsWritable($ConfigFile)) { $this->Form->AddError(sprintf(T('Your configuration file does not have the correct permissions. PHP needs to be able to read and write to this file: <code>%s</code>'), $ConfigFile)); $PermissionProblem = TRUE; } } $UploadsFolder = PATH_ROOT . DS . 'uploads'; if (!is_readable($UploadsFolder) || !IsWritable($UploadsFolder)) { $this->Form->AddError(sprintf(T('Your uploads folder does not have the correct permissions. PHP needs to be able to read and write to this folder: <code>%s</code>'), $UploadsFolder)); $PermissionProblem = TRUE; } // Make sure the cache folder is writeable if (!is_readable(PATH_CACHE) || !IsWritable(PATH_CACHE)) { $this->Form->AddError(sprintf(T('Your cache folder does not have the correct permissions. PHP needs to be able to read and write to this folder and all the files within: <code>%s</code>'), PATH_CACHE)); $PermissionProblem = TRUE; } else { if (!file_exists(PATH_CACHE . DS . 'HtmlPurifier')) { mkdir(PATH_CACHE . DS . 'HtmlPurifier'); } if (!file_exists(PATH_CACHE . DS . 'Smarty')) { mkdir(PATH_CACHE . DS . 'Smarty'); } if (!file_exists(PATH_CACHE . DS . 'Smarty' . DS . 'cache')) { mkdir(PATH_CACHE . DS . 'Smarty' . DS . 'cache'); } if (!file_exists(PATH_CACHE . DS . 'Smarty' . DS . 'compile')) { mkdir(PATH_CACHE . DS . 'Smarty' . DS . 'compile'); } } if ($PermissionProblem) { $this->Form->AddError($PermissionHelp); } return $this->Form->ErrorCount() == 0 ? TRUE : FALSE; }
// Wenn Verzeichnisse erstellt wurden - direkt weitermachen if ($iw[0] && $iw[1] && $iw[2] && $iw[3]) { echo '<script language="javascript">'; echo 'self.location.href=\'install.php?language=' . $language . '&phase=4&connstr=' . $connstr . '\''; echo '</script>'; } echo '</table>'; break; case 10: //safe_mode FTP $config['ftp_useSSL'] = 0; clearstatcache(); $iw[0] = IsWritable("work"); $iw[1] = IsWritable("work/config"); $iw[2] = IsWritable("work/log"); $iw[3] = IsWritable("work/backup"); if (!isset($install_ftp_port) || $install_ftp_port < 1) { $install_ftp_port = 21; } echo '<h6>' . $lang['L_FTPMODE'] . '</h6>'; echo '<p align="left" style="padding-left:100px; padding-right:100px;">' . $lang['L_SAFEMODEDESC'] . '</p>'; echo '<form action="install.php?language=' . $language . '&phase=10" method="post"><input type="hidden" name="connstr" value="' . $connstr . '"> <table width="80%"><tr><td width="50%" valign="top"><table>'; echo '<tr><td class="hd2" colspan="2">' . $lang['L_IDOMANUAL'] . '</td></tr>'; echo '<tr><td colspan="2">' . $lang['L_DOFROM'] . '<br><div class="small">' . Realpfad('./') . '</div></td></tr>'; echo '<tr><td><strong>work</strong></td><td>' . ($iw[0] ? $img_ok : $img_failed) . '</td></tr>'; echo '<tr><td><strong>work/config</strong></td><td>' . ($iw[1] ? $img_ok : $img_failed) . '</td></tr>'; echo '<tr><td><strong>work/log</strong></td><td>' . ($iw[2] ? $img_ok : $img_failed) . '</td></tr>'; echo '<tr><td><strong>work/backup</strong></td><td>' . ($iw[3] ? $img_ok : $img_failed) . '</td></tr>'; echo '<tr><td colspan="3" align="right"><input type="submit" name="dir_check" value=" ' . $lang['L_CHECK_DIRS'] . ' " class="Formbutton"></td></tr>'; if ($iw[0] && $iw[1] && $iw[2] && $iw[3]) {
/** * Saves the specified file with the provided file contents. * * @param string $FileName The full path and name of the file to be saved. * @param string $FileContents The contents of the file being saved. */ public static function saveFile($FileName, $FileContents, $Flags = VANILLA_FILE_PUT_FLAGS) { // Check that the folder exists and is writable $DirName = dirname($FileName); $FileBaseName = basename($FileName); if (!is_dir($DirName)) { throw new Exception(sprintf('Requested save operation [%1$s] could not be completed because target folder [%2$s] does not exist.', $FileBaseName, $DirName)); } if (!IsWritable($DirName)) { throw new Exception(sprintf('Requested save operation [%1$s] could not be completed because target folder [%2$s] is not writable.', $FileBaseName, $DirName)); } if (file_put_contents($FileName, $FileContents, $Flags) === false) { throw new Exception(sprintf('Requested save operation [%1$s] could not be completed!', $FileBaseName)); } return true; }
/** * Saves the specified file with the provided file contents. * * @param string $FileName The full path and name of the file to be saved. * @param string $FileContents The contents of the file being saved. */ public static function SaveFile($FileName, $FileContents, $Flags = LOCK_EX) { // Check that the folder exists and is writable $DirName = dirname($FileName); $FileBaseName = basename($FileName); if (!is_dir($DirName)) { throw new Exception(sprintf('Requested save operation [%1$s] could not be completed because target folder [%2$s] does not exist.', $FileBaseName, $DirName)); } if (!IsWritable($DirName)) { throw new Exception(sprintf('Requested save operation [%1$s] could not be completed because target folder [%2$s] is not writable.', $FileBaseName, $DirName)); } file_put_contents($FileName, $FileContents, $Flags); return TRUE; }
if ($iw[0] && $iw[1] && $iw[2] && $iw[3] && $iw[4]) { echo '<script language="javascript">'; echo 'self.location.href=\'install.php?language=' . $language . '&phase=4&connstr=' . $connstr . '\''; echo '</script>'; } echo '</table>'; break; case 10: //safe_mode FTP $config['ftp_useSSL'] = 0; clearstatcache(); $iw[0] = IsWritable("work"); $iw[1] = IsWritable("work/config"); $iw[2] = IsWritable("work/log"); $iw[3] = IsWritable("work/backup"); $iw[4] = IsWritable("work/structure"); if (!isset($install_ftp_port) || $install_ftp_port < 1) { $install_ftp_port = 21; } echo '<h6>' . $lang['ftpmode'] . '</h6>'; echo '<p align="left" style="padding-left:100px; padding-right:100px;">' . $lang['safemodedesc'] . '</p>'; echo '<form action="install.php?language=' . $language . '&phase=10" method="post"><input type="hidden" name="connstr" value="' . $connstr . '"> <table width="80%"><tr><td width="50%" valign="top"><table>'; echo '<tr><td class="hd2" colspan="2">' . $lang['idomanual'] . '</td></tr>'; echo '<tr><td colspan="2">' . $lang['dofrom'] . '<br><div class="small">' . Realpfad('./') . '</div></td></tr>'; echo '<tr><td><strong>work</strong></td><td>' . ($iw[0] ? $img_ok : $img_failed) . '</td></tr>'; echo '<tr><td><strong>work/config</strong></td><td>' . ($iw[1] ? $img_ok : $img_failed) . '</td></tr>'; echo '<tr><td><strong>work/log</strong></td><td>' . ($iw[2] ? $img_ok : $img_failed) . '</td></tr>'; echo '<tr><td><strong>work/backup</strong></td><td>' . ($iw[3] ? $img_ok : $img_failed) . '</td></tr>'; echo '<tr><td><strong>work/structure</strong></td><td>' . ($iw[4] ? $img_ok : $img_failed) . '</td></tr>'; echo '<tr><td colspan="3" align="right"><input type="submit" name="dir_check" value=" ' . $lang['check'] . ' " class="Formbutton"></td></tr>';
public function SetupCron() { $CronFolder = PATH_PLUGINS . DS . 'SphinxSearchLite' . DS . 'cron'; $InstallWizard = new SphinxSearchInstallWizard(null, null); //bad practice @todo fix this $Search = array('{path_to_indexer}' => $this->Settings['Install']->IndexerPath, '{path_to_php}' => $InstallWizard->RunTypeCommand('', 'php'), '{path_to_config}' => $this->Settings['Install']->ConfPath, '{path_to_cron}' => $CronFolder, '{DS}' => DS, '{index_prefix}' => $this->Settings['Install']->Prefix); $MainTemplate = file_get_contents(PATH_PLUGINS . DS . 'SphinxSearchLite' . DS . 'assests' . DS . 'cron.reindex.main.php.tpl'); $DeltaTemplate = file_get_contents(PATH_PLUGINS . DS . 'SphinxSearchLite' . DS . 'assests' . DS . 'cron.reindex.delta.php.tpl'); $StatsTemplate = file_get_contents(PATH_PLUGINS . DS . 'SphinxSearchLite' . DS . 'assests' . DS . 'cron.reindex.stats.php.tpl'); $ReWritedMain = str_replace(array_keys($Search), $Search, $MainTemplate); $ReWritedDelta = str_replace(array_keys($Search), $Search, $DeltaTemplate); $ReWritedStats = str_replace(array_keys($Search), $Search, $StatsTemplate); //check if cron folder is good to go if (!file_exists($CronFolder)) { parent::Update(SS_FATAL_ERROR, FALSE, FALSE, "Cron folder not found at: {$CronFolder}"); } if (!IsWritable($CronFolder)) { parent::Update(SS_FATAL_ERROR, FALSE, FALSE, "This location is not writable: {$CronFolder}"); } try { if (!file_put_contents($CronFolder . DS . 'cron.reindex.main.php', $ReWritedMain)) { parent::Update(SS_FATAL_ERROR, FALSE, FALSE, "(Permissions) Error writing cron file: {$MainTemplate}"); } if (!file_put_contents($CronFolder . DS . 'cron.reindex.delta.php', $ReWritedDelta)) { parent::Update(SS_FATAL_ERROR, FALSE, FALSE, "(Permissions) Error writing cron file: {$DeltaTemplate}"); } if (!file_put_contents($CronFolder . DS . 'cron.reindex.stats.php', $ReWritedStats)) { parent::Update(SS_FATAL_ERROR, FALSE, FALSE, "(Permissions) Error writing cron file: {$StatsTemplate}"); } } catch (Exception $e) { //get just the exception error $ErrorLen = strpos($e, 'Stack trace:', 0); $Error = substr($e, 0, $ErrorLen); parent::Update(SS_FATAL_ERROR, FALSE, FALSE, $Error); } }