Adding the ability to set the permissions used when creating files

previously this was hardcoded, meaning that if you wanted to configure
to permit group access (for exammple) this wasn't possible
This commit is contained in:
Rob Emery 2025-01-11 21:15:17 +00:00
parent 8bf4727555
commit a8ef3aa18a
2 changed files with 4 additions and 2 deletions

View file

@ -235,6 +235,8 @@ Warning: only enable when server does not do this, else double compression error
'admin_login' => array('admin', 'Login and password for web admin panel'), 'admin_login' => array('admin', 'Login and password for web admin panel'),
'admin_password' => array(''), 'admin_password' => array(''),
'admin_totp' => array(''), 'admin_totp' => array(''),
'file_permissions' => array('0600', 'permissions to chmod cache files to when creating'),
'dir_permissions' => array('0700', 'permissions to chmod cache directories to when creating'),
'insecure_cryptkey' => array(false, 'Use email address instead of login password for encrypting sensitive data (like account passwords)'), 'insecure_cryptkey' => array(false, 'Use email address instead of login password for encrypting sensitive data (like account passwords)'),
'force_https' => array(false), 'force_https' => array(false),

View file

@ -156,14 +156,14 @@ class Utils
public static function saveFile(string $filename, string $data) : void public static function saveFile(string $filename, string $data) : void
{ {
$dir = \dirname($filename); $dir = \dirname($filename);
if (!\is_dir($dir) && !\mkdir($dir, 0700, true)) { if (!\is_dir($dir) && !\mkdir($dir, intval($oConfig->Get('security', 'dir_permissions)), true)) {
throw new \RuntimeException('Failed to create directory "'.$dir.'"'); throw new \RuntimeException('Failed to create directory "'.$dir.'"');
} }
if (false === \file_put_contents($filename, $data)) { if (false === \file_put_contents($filename, $data)) {
throw new \RuntimeException('Failed to save file "'.$filename.'"'); throw new \RuntimeException('Failed to save file "'.$filename.'"');
} }
\clearstatcache(); \clearstatcache();
\chmod($filename, 0600); \chmod($filename, intval($oConfig->Get('security', 'file_permissions')));
/* /*
try { try {
} catch (\Throwable $oException) { } catch (\Throwable $oException) {