filesender: init at 2.48

This commit is contained in:
nhnn 2024-05-21 18:58:55 +03:00
parent d36cb226a5
commit b56286db09
No known key found for this signature in database
2 changed files with 161 additions and 0 deletions

@ -0,0 +1,39 @@
{
stdenv,
fetchFromGitHub,
lib,
nixosTests,
}:
stdenv.mkDerivation rec {
pname = "filesender";
version = "2.48";
src = fetchFromGitHub {
owner = "filesender";
repo = "filesender";
rev = "filesender-${version}";
hash = "sha256-lXA9XZ5gbfut2EQ5bF2w8rhAEM++8rQseWviKwfRWGk=";
};
patches = [
# /nix/store is read-only, but filesender searches config and logs inside of installation directory.
# This patch changes search directories to FILESENDER_CONFIG_DIR and FILESENDER_LOG_DIR environment variables.
./separate_mutable_paths.patch
];
installPhase = ''
mkdir -p $out/
cp -R . $out/
'';
passthru.tests = {
inherit (nixosTests) filesender;
};
meta = {
description = "Web application for sending large files to other users";
homepage = "https://filesender.org/";
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [ nhnn ];
};
}

@ -0,0 +1,122 @@
diff --git a/classes/utils/Config.class.php b/classes/utils/Config.class.php
index a4d819bc..3c2ed287 100644
--- a/classes/utils/Config.class.php
+++ b/classes/utils/Config.class.php
@@ -30,7 +30,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-if (!defined('FILESENDER_BASE')) { // Require environment (fatal)
+if (!defined('FILESENDER_BASE') || !defined("FILESENDER_CONFIG_DIR")) { // Require environment (fatal)
die('Missing environment');
}
@@ -116,7 +116,7 @@ class Config
}
// Check if main config exists
- $main_config_file = FILESENDER_BASE.'/config/config.php';
+ $main_config_file = FILESENDER_CONFIG_DIR.'/config/config.php';
if (!file_exists($main_config_file)) {
throw new ConfigFileMissingException($main_config_file);
}
@@ -136,7 +136,7 @@ class Config
// load password file if it is there
- $pass_config_file = FILESENDER_BASE.'/config/config-passwords.php';
+ $pass_config_file = FILESENDER_CONFIG_DIR.'/config/config-passwords.php';
if (file_exists($pass_config_file)) {
$config = array();
include_once($pass_config_file);
@@ -153,7 +153,7 @@ class Config
throw new ConfigBadParameterException('virtualhost');
}
- $config_file = FILESENDER_BASE.'/config/'.$virtualhost.'/config.php';
+ $config_file = FILESENDER_CONFIG_DIR.'/config/'.$virtualhost.'/config.php';
if (!file_exists($config_file)) {
throw new ConfigFileMissingException($config_file);
} // Should exist even if empty
@@ -175,7 +175,7 @@ class Config
}
foreach ($regex_and_configs as $regex => $extra_config_name) {
if (preg_match('`'.$regex.'`', $auth_attrs[$attr])) {
- $extra_config_file = FILESENDER_BASE.'/config/config-' . $extra_config_name . '.php';
+ $extra_config_file = FILESENDER_CONFIG_DIR.'/config/config-' . $extra_config_name . '.php';
if (file_exists($extra_config_file)) {
$config = array();
include_once($extra_config_file);
@@ -204,7 +204,7 @@ class Config
// Load config overrides if any
$overrides_cfg = self::get('config_overrides');
if ($overrides_cfg) {
- $overrides_file = FILESENDER_BASE.'/config/'.($virtualhost ? $virtualhost.'/' : '').'config_overrides.json';
+ $overrides_file = FILESENDER_CONFIG_DIR.'/config/'.($virtualhost ? $virtualhost.'/' : '').'config_overrides.json';
$overrides = file_exists($overrides_file) ? json_decode(trim(file_get_contents($overrides_file))) : new StdClass();
@@ -431,7 +431,7 @@ class Config
public static function getVirtualhosts()
{
$virtualhosts = array();
- foreach (scandir(FILESENDER_BASE.'/config') as $item) {
+ foreach (scandir(FILESENDER_CONFIG_DIR.'/config') as $item) {
if (!preg_match('`^(.+)\.conf\.php$`', $item, $match)) {
continue;
}
diff --git a/config/csrf-protector-config.php b/config/csrf-protector-config.php
index 83759ca4..ea4a3173 100755
--- a/config/csrf-protector-config.php
+++ b/config/csrf-protector-config.php
@@ -40,7 +40,7 @@ return array(
// The following should be set correctly from your config.php
// information
"jsUrl" => $config['site_url'] . "/js/csrfprotector.js",
- "logDirectory" => FILESENDER_BASE.'/log/',
+ "logDirectory" => FILESENDER_LOG_DIR,
// I found that leaving this with the _ as default
// caused the implicit token to be stripped
diff --git a/includes/ConfigDefaults.php b/includes/ConfigDefaults.php
index 733550e7..8d99b5f0 100644
--- a/includes/ConfigDefaults.php
+++ b/includes/ConfigDefaults.php
@@ -224,7 +224,7 @@ $default = array(
'log_facilities' => array(
array(
'type' => 'file',
- 'path' => FILESENDER_BASE.'/log/',
+ 'path' => FILESENDER_LOG_DIR,
'rotate' => 'hourly'
)
),
diff --git a/includes/ConfigValidation.php b/includes/ConfigValidation.php
index 5c1e7f61..b1fb57e4 100644
--- a/includes/ConfigValidation.php
+++ b/includes/ConfigValidation.php
@@ -31,9 +31,9 @@
*/
// Require environment (fatal)
-if(!defined('FILESENDER_BASE')) die('Missing environment');
+if(!defined('FILESENDER_BASE') || !defined("FILESENDER_CONFIG_DIR")) die('Missing environment');
-if(!file_exists(FILESENDER_BASE.'/config/config.php'))
++if(!file_exists(FILESENDER_CONFIG_DIR.'/config.php'))
die('Configuration file not found');
ConfigValidator::addCheck('site_url', 'string');
diff --git a/includes/init.php b/includes/init.php
index ba7fa82f..31812c54 100644
--- a/includes/init.php
+++ b/includes/init.php
@@ -35,6 +35,8 @@ if(PHP_INT_SIZE !== 8) {
}
define('FILESENDER_BASE', dirname( __DIR__ ));
+define('FILESENDER_CONFIG_DIR', getenv('FILESENDER_CONFIG_DIR', true) ?: (FILESENDER_BASE.'/config'));
+define('FILESENDER_LOG_DIR', getenv('FILESENDER_LOG_DIR', true) ?: (FILESENDER_BASE.'/log'));
// Include classes autoloader
require_once(FILESENDER_BASE.'/classes/autoload.php');