_dir)) { $this->_dir = $galleryStub->getConfig('data.gallery.base'); if (empty($this->_dir)) { $this->_dir = $_SESSION['configPath'] . DIRECTORY_SEPARATOR . 'g2data'; } } /* * An example for a slightly obfuscated g2data folder name such that the location * of the storage folder can't be guessed too easily. */ $templateData['suggested_obfuscated_g2data_name'] = 'g2data_' . substr(md5(rand()),0 , 10); $templateData['isMultisite'] = $galleryStub->getConfig('isMultisite'); if (!empty($_POST['action']) && $_POST['action'] == 'save') { if (empty($_POST['dir'])) { $templateData['error']['missing_value'] = 1; } else { $dir = rtrim($this->sanitize($_POST['dir'])); /* Normalize the path, add a traling slash if necessary */ if (substr($dir, -1) != DIRECTORY_SEPARATOR) { $dir .= DIRECTORY_SEPARATOR; } $originalDir = $dir; /* * Make the path absolute since relative to the install/ folder isn't the same as * relative to the main.php entry file. And also check if it exists. */ $realPath = @realpath($dir); if (empty($realPath)) { /* * The folder does not exist yet. If we have already write permission on the * parent folder, create the storage folder. */ $parentDir = realpath(dirname($dir)); if (!empty($parentDir) && is_dir($parentDir) && is_readable($parentDir) && is_writeable($parentDir)) { $dir = $parentDir . DIRECTORY_SEPARATOR . basename($dir) . DIRECTORY_SEPARATOR; /* Create the storage folder with restrictive permissions */ if (@mkdir($dir)) { chmod($dir, 0700); } } } /* Ensure that it is an absolute filesystem path */ $dir = @realpath($dir); if (!empty($dir) && substr($dir, -1) != DIRECTORY_SEPARATOR) { $dir .= DIRECTORY_SEPARATOR; } /* Check if the (newly created) dir exists, is writeable etc. */ if (!is_dir($dir)) { $templateData['error']['missing_dir'] = 1; } else if (substr($dir, 0, -1) === $_SESSION['configPath'] || ($galleryStub->getConfig('isMultisite') && substr($dir, 0, -1) === dirname(dirname(dirname(__FILE__))))) { $templateData['error']['in_gallery_dir'] = 1; } else if (!is_readable($dir)) { $templateData['error']['inaccessible_dir'] = 1; } else if (!is_writeable($dir)) { $templateData['error']['readonly_dir'] = 1; } else { /* * Security check: * If the user ticks the checkbox and thereby acknowledges that the storage * folder might be accessible from the web, we proceed with the installation. */ list ($checkExecuted, $webAccessible) = $this->_isStoragePathWebAccessible($dir); if (empty($_POST['i_acknowledge_the_risk']) && (!$checkExecuted || $webAccessible)) { if (!$checkExecuted) { /* Show a warning suggesting an obfuscated path. */ $templateData['error']['possibly_web_accessible_dir'] = 1; } else if ($webAccessible) { $templateData['error']['web_accessible_dir'] = 1; } } else { /* * Populate the dir. */ if (!populateDataDirectory($dir)) { $templateData['error']['creation_error'] = 1; } else { $this->_dir = $dir; $this->setComplete(true); } } } } $templateData['dir'] = isset($originalDir) ? $originalDir : $this->_dir; } else { $templateData['dir'] = $this->_dir; } if ($this->isComplete()) { $galleryStub->setConfig('data.gallery.base', $this->_dir); $templateData['bodyFile'] = 'StorageSetupSuccess.html'; } else { $templateData['bodyFile'] = 'StorageSetupRequest.html'; } if (!strncasecmp(PHP_OS, 'win', 3)) { $templateData['OS'] = 'winnt'; } else { $templateData['OS'] = 'unix'; } } function processRequest() { if (!empty($_GET['doAutoComplete'])) { processAutoCompleteRequest(); return false; } return true; } function isRedoable() { return true; } /** * Try to protect the given folder with a .htaccess file from direct web-access. * And then check if the given folder is web-accessible either way. * Precondition: gallery and g2data folders exist. * * @return array(boolean false if check procedure failed due to platform issues, * boolean true if the folder is accessible from the web (=insecure)) */ function _isStoragePathWebAccessible($dir) { /* Check if we can use fsockopen. Else we can't test it at all. */ if (!function_exists('fsockopen') || in_array('fsockopen', preg_split('/,\s*/', ini_get('disable_functions')))) { return array(false, false); } /* Add a .htaccess file. */ if (!secureStorageFolder($dir)) { return array(false, false); } /* Add a probe file. */ $probeFileName = 'probe_' . substr(md5(uniqid(rand())), 0, 10) . '.html'; $probeFilePath = $dir . $probeFileName; $checkString = md5(rand()); $fh = @fopen($probeFilePath, 'w'); if ($fh) { $contents = "