Skip to content

Commit

Permalink
Merge branch '5.19.4-cividesk' of https://github.com/cividesk/civicrm…
Browse files Browse the repository at this point in the history
…-core into 5.19.4-cividesk
  • Loading branch information
yashodha committed Aug 24, 2020
2 parents 109fa9c + 6f4b225 commit cd2a0e6
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
30 changes: 30 additions & 0 deletions patches/kcfinder_auth_standalone.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--- a/packages/kcfinder/integration/civicrm.php
+++ b/packages/kcfinder/integration/civicrm.php
@@ -69,6 +69,9 @@
case 'Drupal8':
$auth_function = 'authenticate_drupal8';
break;
+ case 'Standalone':
+ $auth_function = 'authenticate_standalone';
+ break;
}
if(!$auth_function($config)) {
CRM_Core_Error::fatal(ts("You must be logged in with proper permissions to edit, add, or delete uploaded images."));
@@ -205,6 +208,17 @@
return true;
}

+function authenticate_standalone($config) {
+ session_start();
+ // make sure user has access to civicrm
+ CRM_Utils_System::loadBootStrap();
+ require_once "CRM/Core/Permission.php";
+ if (CRM_Core_Permission::check('access CiviCRM')) {
+ return true;
+ }
+ return false;
+}
+
checkAuthentication( );

//spl_autoload_register('__autoload');
73 changes: 73 additions & 0 deletions patches/kcfinder_uploadDir_symlink.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
--- a/packages/kcfinder/core/class/uploader.php
+++ b/packages/kcfinder/core/class/uploader.php
@@ -227,18 +227,18 @@
list($unused, $protocol, $domain, $unused, $port, $path) = $patt;
$path = path::normalize($path);
$this->config['uploadURL'] = "$protocol://$domain" . (strlen($port) ? ":$port" : "") . "/$path";
- $this->config['uploadDir'] = strlen($this->config['uploadDir'])
+ $this->config['uploadDir'] = $this->realpath(strlen($this->config['uploadDir'])
? path::normalize($this->config['uploadDir'])
- : path::url2fullPath("/$path");
- $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
+ : path::url2fullPath("/$path"));
+ $this->typeDir = $this->realpath("{$this->config['uploadDir']}/{$this->type}");
$this->typeURL = "{$this->config['uploadURL']}/{$this->type}";

// SITE ROOT
} elseif ($this->config['uploadURL'] == "/") {
- $this->config['uploadDir'] = strlen($this->config['uploadDir'])
+ $this->config['uploadDir'] = $this->realpath(strlen($this->config['uploadDir'])
? path::normalize($this->config['uploadDir'])
- : path::normalize($_SERVER['DOCUMENT_ROOT']);
- $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
+ : path::normalize(realpath($_SERVER['DOCUMENT_ROOT'])));
+ $this->typeDir = $this->realpath("{$this->config['uploadDir']}/{$this->type}");
$this->typeURL = "/{$this->type}";

// ABSOLUTE & RELATIVE
@@ -246,10 +246,10 @@
$this->config['uploadURL'] = (substr($this->config['uploadURL'], 0, 1) === "/")
? path::normalize($this->config['uploadURL'])
: path::rel2abs_url($this->config['uploadURL']);
- $this->config['uploadDir'] = strlen($this->config['uploadDir'])
+ $this->config['uploadDir'] = $this->realpath(strlen($this->config['uploadDir'])
? path::normalize($this->config['uploadDir'])
- : path::url2fullPath($this->config['uploadURL']);
- $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
+ : path::url2fullPath($this->config['uploadURL']));
+ $this->typeDir = $this->realpath("{$this->config['uploadDir']}/{$this->type}");
$this->typeURL = "{$this->config['uploadURL']}/{$this->type}";
}

@@ -324,6 +324,20 @@
}
}

+ protected function realpath($path) {
+ // PHP's realpath() does not work on files that don't exist, but
+ // there might be a symlink somewhere in the path so we need to
+ // check it.
+ $existing_path = $path;
+ while (!file_exists($existing_path)) {
+ $existing_path = dirname($existing_path);
+ }
+ $rPath = realpath($existing_path) . substr($path, strlen($existing_path));
+ if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN")
+ $rPath = str_replace("\\", "/", $rPath);
+ return $rPath;
+ }
+
public function upload() {
$config = &$this->config;
$file = &$this->file;
@@ -418,9 +432,7 @@
}

protected function checkFilePath($file) {
- $rPath = realpath($file);
- if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN")
- $rPath = str_replace("\\", "/", $rPath);
+ $rPath = $this->realpath($file);
return (substr($rPath, 0, strlen($this->typeDir)) === $this->typeDir);
}

0 comments on commit cd2a0e6

Please sign in to comment.