File and directory rights

- Sets the file and directory permissions from the FP main directory and its subdirectories when executing the setup.
- See #307
This commit is contained in:
Frank Hochmuth 2024-02-02 23:39:53 +01:00 committed by GitHub
commit 94780adfdf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 23 deletions

View File

@ -18,10 +18,11 @@
define('DUMB_MODE_ENABLED', false);
// default file permissions
// change file to 776 and dir to 776 if your webserver "complains"
// https://binary-butterfly.de/artikel/dateirechte-wie-stelle-ich-das-bei-meinem-hoster-ein/
// change file to 666 and dir to 777 if your webserver "complains"
// Note: Lowering the directory and file permissions may result in FlatPress or some additional plugins not working correctly.
define('FILE_PERMISSIONS', 0776);
define('DIR_PERMISSIONS', 0776);
define('FILE_PERMISSIONS', 0666);
define('DIR_PERMISSIONS', 0777);
// first some webserver setup...
@ -34,6 +35,9 @@ define('SESSION_PATH', '');
define('ABS_PATH', dirname(__FILE__) . '/');
// here was blog root in earlier versions. This has been moved to config_load()
// Is required so that the file and directory permissions can be set when executing the setup
define('BASE_DIR', dirname(__FILE__));
// here are default config files
define('FP_DEFAULTS', 'fp-defaults/');

View File

@ -1,37 +1,37 @@
<?php
error_reporting($_SERVER ["SERVER_NAME"] == "localhost" ? E_ALL : 0);
@error_reporting($_SERVER ["SERVER_NAME"] == "localhost" ? E_ALL : 0);
// Changing file/directory permissions recursively
$start_dir = FP_CONTENT; // Starting directory
$start_dir = BASE_DIR; // Starting directory
$perms ['file'] = FILE_PERMISSIONS; // chmod value for files
$perms ['folder'] = DIR_PERMISSIONS; // chmod value for folders
function chmod_file_folder($dir) {
function chmod_r($dir) {
global $perms;
$dh = @opendir($dir);
$dp = @opendir($dir);
while($file = readdir($dp)) {
if (($file == ".") || ($file == ".."))
continue;
if ($dh) {
$fullPath = $dir . '/' . $file;
while (false !== ($file = readdir($dh))) {
if ($file != "." && $file != "..") {
$fullpath = $dir . '/' . $file;
if (!is_dir($fullpath)) {
chmod($fullpath, $perms ['file']);
} else {
chmod($fullpath, $perms ['folder']);
chmod_file_folder($fullpath);
}
}
if(is_dir($fullPath)) {
// echo('DIR:' . $fullPath . "\n");
@chmod($fullPath, $perms ['folder']);
chmod_r($fullPath, $perms ['folder'], $perms ['file']);
} else {
// echo('FILE:' . $fullPath . "\n");
@chmod($fullPath, $perms ['file']);
}
closedir($dh);
}
closedir($dp);
}
$language = @$_POST ['language'] ?$_POST ['language'] : $browserLang;
chmod_r($start_dir, $perms ['folder'], $perms ['file']);
// Sets the local language based on the browser
$language = @$_POST ['language'] ? $_POST ['language'] : $browserLang;
$lf = "lang.$language.php";
if (!preg_match('|^lang\.[a-z]{2}-[a-z]{2}\.php$|', $lf))