From 736045c67da248745925d047eef235da38b18f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 9 Mar 2021 21:37:14 +0100 Subject: [PATCH 1/3] Code changes for #10020: Added ability to set chmod (default: 0640) for "proxified" files (downloaded to /proxy/ directory). This allows customization, e.g. if people want 0600 instead without changing the code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- src/Module/Proxy.php | 8 ++++++-- static/defaults.config.php | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index f20b13bcef..c7f7673b8a 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -131,7 +131,9 @@ class Proxy extends BaseModule // Store original image if ($direct_cache) { // direct cache , store under ./proxy/ - file_put_contents($basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true), $image->asString()); + $filename = $basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true) + file_put_contents($filename, $image->asString()); + chmod($filename, DI::config()->get('system', 'proxy_file_chmod', 0640)); } elseif($cachefile !== '') { // cache file file_put_contents($cachefile, $image->asString()); @@ -149,7 +151,9 @@ class Proxy extends BaseModule // Store scaled image if ($direct_cache && $request['sizetype'] != '') { - file_put_contents($basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true) . $request['sizetype'], $image->asString()); + $filename = $basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true) . $request['sizetype']; + file_put_contents($filename, $image->asString()); + chmod($filename, DI::config()->get('system', 'proxy_file_chmod', 0640)); } self::responseImageHttpCache($image); diff --git a/static/defaults.config.php b/static/defaults.config.php index 7578e3c550..b075db36a0 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -570,6 +570,10 @@ return [ // xrd_timeout (Integer) // Timeout in seconds for fetching the XRD links. 'xrd_timeout' => 20, + + // proxy_file_chmod (Integer) + // Access rights for downloaded files in /proxy/ directory + 'proxy_file_chmod' => 0640, ], 'experimental' => [ // exp_themes (Boolean) From 15fd6822e4959e27525e52e9ec4e03d01370b5a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 11 Mar 2021 12:40:31 +0100 Subject: [PATCH 2/3] Ops, missing ";" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- src/Module/Proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index c7f7673b8a..787b68e110 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -131,7 +131,7 @@ class Proxy extends BaseModule // Store original image if ($direct_cache) { // direct cache , store under ./proxy/ - $filename = $basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true) + $filename = $basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true); file_put_contents($filename, $image->asString()); chmod($filename, DI::config()->get('system', 'proxy_file_chmod', 0640)); } elseif($cachefile !== '') { From 5de0008b48b7eac58a8e80028dec97ee128379f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 11 Mar 2021 12:45:43 +0100 Subject: [PATCH 3/3] Removed default values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- src/Module/Proxy.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index 787b68e110..10ddd56334 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -133,7 +133,7 @@ class Proxy extends BaseModule // direct cache , store under ./proxy/ $filename = $basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true); file_put_contents($filename, $image->asString()); - chmod($filename, DI::config()->get('system', 'proxy_file_chmod', 0640)); + chmod($filename, DI::config()->get('system', 'proxy_file_chmod')); } elseif($cachefile !== '') { // cache file file_put_contents($cachefile, $image->asString()); @@ -153,7 +153,7 @@ class Proxy extends BaseModule if ($direct_cache && $request['sizetype'] != '') { $filename = $basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true) . $request['sizetype']; file_put_contents($filename, $image->asString()); - chmod($filename, DI::config()->get('system', 'proxy_file_chmod', 0640)); + chmod($filename, DI::config()->get('system', 'proxy_file_chmod')); } self::responseImageHttpCache($image);