Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fixed some url construction problems.
Browse files Browse the repository at this point in the history
Add ENCFS_UID as a plugin option because it was hardcoded and set to 33.
  • Loading branch information
thomasCresson committed Jul 30, 2013
1 parent 0f0f6e6 commit 0f9500e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
55 changes: 30 additions & 25 deletions core/src/plugins/cypher.encfs/class.EncfsMounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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]);
}
Expand All @@ -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]);
}
Expand All @@ -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]);
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/plugins/cypher.encfs/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<global_param description="CONF_MESSAGE[Password used when generating the encfs6.xml file]"
label="CONF_MESSAGE[Encfs Password]" name="ENCFS_XML_PASSWORD"
type="string" mandatory="true" />
<global_param description="CONF_MESSAGE[User ID for the web accessing user (apache, www-data,...).]"
label="CONF_MESSAGE[UID]" name="ENCFS_UID"
type="integer" mandatory="true" default="33"/>
</server_settings>
<class_definition classname="EncfsMounter" filename="plugins/cypher.encfs/class.EncfsMounter.php"/>
<registry_contributions>
Expand Down

0 comments on commit 0f9500e

Please sign in to comment.