diff --git a/core/src/plugins/cypher.encfs/class.EncfsMounter.php b/core/src/plugins/cypher.encfs/class.EncfsMounter.php index 0cb4d1aeda..6841f61944 100644 --- a/core/src/plugins/cypher.encfs/class.EncfsMounter.php +++ b/core/src/plugins/cypher.encfs/class.EncfsMounter.php @@ -88,8 +88,11 @@ public function switchAction($actionName, $httpVars, $fileVars){ if(empty($xmlTemplate) || !is_file($xmlTemplate)){ throw new Exception("It seems that you have not set the plugin 'Enfcs XML File' configuration, or the system cannot find it!"); } - $dir = $this->getWorkingPath().AJXP_Utils::decodeSecureMagic($httpVars["dir"]); - if(dirname($dir) != $this->getWorkingPath()){ + + //$repo = ConfService::getRepository(); + $dir = $this->getWorkingPath().ltrim(AJXP_Utils::decodeSecureMagic($httpVars["dir"]), "/"); + + if(dirname($dir) != rtrim($this->getWorkingPath(), "/")){ throw new Exception("Please cypher only folders at the root of your repository"); } $pass = $httpVars["pass"]; @@ -103,7 +106,8 @@ public function switchAction($actionName, $httpVars, $fileVars){ if($result){ // Mount folder mkdir($clear); - self::mountFolder($raw, $clear, $pass); + $uid = $this->getFilteredOption("ENCFS_UID"); + self::mountFolder($raw, $clear, $pass, $uid); $content = scandir($dir); foreach($content as $fileOrFolder){ if($fileOrFolder == "." || $fileOrFolder == "..") continue; @@ -117,15 +121,16 @@ public function switchAction($actionName, $httpVars, $fileVars){ // SIMPLY UNMOUNT self::umountFolder($dir); } - break; + break; case "encfs.uncypher_folder": $dir = $this->getWorkingPath().AJXP_Utils::decodeSecureMagic($httpVars["dir"]); $raw = str_replace("ENCFS_CLEAR_", "ENCFS_RAW_", $dir); $pass = $httpVars["pass"]; + $uid = $this->getFilteredOption("ENCFS_UID"); if(is_dir($raw)){ - self::mountFolder($raw, $dir, $pass); + self::mountFolder($raw, $dir, $pass, $uid); } - break; + break; } AJXP_XMLWriter::header(); AJXP_XMLWriter::reloadDataNode(); @@ -158,10 +163,10 @@ public static function initEncFolder($raw, $originalXML, $originalSecret, $secr copy($originalXML, $raw."/".basename($originalXML)); $descriptorspec = array( - 0 => array("pipe", "r"), // stdin - 1 => array("pipe", "w"), // stdout - 2 => array("pipe", "w") // stderr ?? instead of a file - ); + 0 => array("pipe", "r"), // stdin + 1 => array("pipe", "w"), // stdout + 2 => array("pipe", "w") // stderr ?? instead of a file + ); $command = 'sudo encfsctl autopasswd '.escapeshellarg($raw); $process = proc_open($command, $descriptorspec, $pipes); $text = ""; $error = ""; @@ -172,11 +177,11 @@ public static function initEncFolder($raw, $originalXML, $originalSecret, $secr fflush($pipes[0]); fclose($pipes[0]); while($s= fgets($pipes[1], 1024)) { - $text .= $s; + $text .= $s; } fclose($pipes[1]); while($s= fgets($pipes[2], 1024)) { - $error .= $s . "\n"; + $error .= $s . "\n"; } fclose($pipes[2]); } @@ -189,25 +194,25 @@ public static function initEncFolder($raw, $originalXML, $originalSecret, $secr } - public static function mountFolder($raw, $clear, $secret){ + public static function mountFolder($raw, $clear, $secret, $uid){ $descriptorspec = array( - 0 => array("pipe", "r"), // stdin - 1 => array("pipe", "w"), // stdout - 2 => array("pipe", "w") // stderr ?? instead of a file - ); - $command = 'sudo encfs -o allow_other,uid=33 -S '.escapeshellarg($raw).' '.escapeshellarg($clear); + 0 => array("pipe", "r"), // stdin + 1 => array("pipe", "w"), // stdout + 2 => array("pipe", "w") // stderr ?? instead of a file + ); + $command = 'sudo encfs -o allow_other,uid='.$uid.' -S '.escapeshellarg($raw).' '.escapeshellarg($clear); $process = proc_open($command, $descriptorspec, $pipes); $text = ""; $error = ""; if (is_resource($process)) { fwrite($pipes[0], $secret); fclose($pipes[0]); while($s= fgets($pipes[1], 1024)) { - $text .= $s; + $text .= $s; } fclose($pipes[1]); while($s= fgets($pipes[2], 1024)) { - $error .= $s . "\n"; + $error .= $s . "\n"; } fclose($pipes[2]); } @@ -225,19 +230,19 @@ public static function mountFolder($raw, $clear, $secret){ public static function umountFolder($clear){ $descriptorspec = array( - 1 => array("pipe", "w"), // stdout - 2 => array("pipe", "w") // stderr ?? instead of a file - ); + 1 => array("pipe", "w"), // stdout + 2 => array("pipe", "w") // stderr ?? instead of a file + ); $command = 'sudo umount '.escapeshellarg($clear); $process = proc_open($command, $descriptorspec, $pipes); $text = ""; $error = ""; if (is_resource($process)) { while($s= fgets($pipes[1], 1024)) { - $text .= $s; + $text .= $s; } fclose($pipes[1]); while($s= fgets($pipes[2], 1024)) { - $error .= $s . "\n"; + $error .= $s . "\n"; } fclose($pipes[2]); } diff --git a/core/src/plugins/cypher.encfs/manifest.xml b/core/src/plugins/cypher.encfs/manifest.xml index 8402d7b575..bc863c3bf1 100644 --- a/core/src/plugins/cypher.encfs/manifest.xml +++ b/core/src/plugins/cypher.encfs/manifest.xml @@ -18,6 +18,9 @@ +