aboutsummaryrefslogtreecommitdiff
path: root/p
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <aledeg@users.noreply.github.com> 2021-02-26 12:42:10 -0500
committerGravatar GitHub <noreply@github.com> 2021-02-26 18:42:10 +0100
commit0ce798d40bd16e7fb3b9fcd7b2b2012e6226dd24 (patch)
tree01c2169b7084c63d0c543d479fa87b886e0d8a7c /p
parent9ea3e7710ad54e76ff1f84bafb208da865816f93 (diff)
Add support for extension user files (#3433)
Extension user files can be stored easily in the user folder instead of the static folder.
Diffstat (limited to 'p')
-rw-r--r--p/ext.php16
1 files changed, 13 insertions, 3 deletions
diff --git a/p/ext.php b/p/ext.php
index d283e5f8c..daa4848d6 100644
--- a/p/ext.php
+++ b/p/ext.php
@@ -32,10 +32,15 @@ function get_absolute_filename(string $file_name) {
return $third_party_extension;
}
+ $user = realpath(USERS_PATH . '/' . $file_name);
+ if (false !== $user) {
+ return $user;
+ }
+
return '';
}
-function is_valid_path_extension($path, $extensionPath) {
+function is_valid_path_extension($path, $extensionPath, $isStatic = true) {
// It must be under the extension path.
$real_ext_path = realpath($extensionPath);
@@ -48,7 +53,12 @@ function is_valid_path_extension($path, $extensionPath) {
return false;
}
- // File to serve must be under a `ext_dir/static/` directory.
+ // User files do not need further validations
+ if (!$isStatic) {
+ return true;
+ }
+
+ // Static files to serve must be under a `ext_dir/static/` directory.
$path_relative_to_ext = substr($path, strlen($real_ext_path) + 1);
list(,$static,$file) = sscanf($path_relative_to_ext, '%[^/]/%[^/]/%s');
if (null === $file || 'static' !== $static) {
@@ -69,7 +79,7 @@ function is_valid_path_extension($path, $extensionPath) {
*
*/
function is_valid_path($path) {
- return is_valid_path_extension($path, CORE_EXTENSIONS_PATH) || is_valid_path_extension($path, THIRDPARTY_EXTENSIONS_PATH);
+ return is_valid_path_extension($path, CORE_EXTENSIONS_PATH) || is_valid_path_extension($path, THIRDPARTY_EXTENSIONS_PATH) || is_valid_path_extension($path, USERS_PATH, $false);
}
function sendBadRequestResponse(string $message = null) {