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

Commit f8d767f

Browse files
committed
Prefix cyphered passwords inside role parameters with a specific string. listParameters() removes prefix by default, can either keep it ($preserveCypheredPasswords) or blur passwords ($blurCypheredPasswords) by replacing with __AJXP_VALUE_SET__ value.
1 parent 3b7d464 commit f8d767f

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

core/src/core/classes/class.AJXP_Role.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class AJXP_Role implements AjxpGroupPathProvider
4141
protected $actions = array();
4242
protected $autoApplies = array();
4343

44+
static $cypheredPassPrefix = '$pydio_password$';
45+
4446
public function __construct($id)
4547
{
4648
$this->roleId = $id;
@@ -146,12 +148,12 @@ public function clearAcls()
146148
* Send all role informations as an associative array
147149
* @return array
148150
*/
149-
public function getDataArray()
151+
public function getDataArray($blurPasswords = false)
150152
{
151153
$roleData = array();
152154
$roleData["ACL"] = $this->listAcls();
153155
$roleData["ACTIONS"] = $this->listActionsStates();
154-
$roleData["PARAMETERS"] = $this->listParameters();
156+
$roleData["PARAMETERS"] = $this->listParameters(false, $blurPasswords);
155157
$roleData["APPLIES"] = $this->listAutoApplies();
156158
return $roleData;
157159
}
@@ -204,28 +206,54 @@ public function filterParameterValue($pluginId, $parameterName, $repositoryId, $
204206
if (isSet($this->parameters[AJXP_REPO_SCOPE_ALL][$pluginId][$parameterName])) {
205207
$v = $this->parameters[AJXP_REPO_SCOPE_ALL][$pluginId][$parameterName];
206208
if($v === AJXP_VALUE_CLEAR) return "";
207-
else return $v;
209+
else return $this->filterCypheredPasswordValue($v);
208210
}
209211
if (isSet($this->parameters[$repositoryId][$pluginId][$parameterName])) {
210212
$v = $this->parameters[$repositoryId][$pluginId][$parameterName];
211213
if($v === AJXP_VALUE_CLEAR) return "";
212-
else return $v;
214+
else return $this->filterCypheredPasswordValue($v);
213215
}
214216
return $parameterValue;
215217
}
218+
216219
/**
220+
* @param bool $preserveCypheredPasswords
221+
* @param bool $blurCypheredPasswords
217222
* @return array Associative array of parameters : array[REPO_ID][PLUGIN_ID][PARAMETER_NAME] = PARAMETER_VALUE
218223
*/
219-
public function listParameters()
224+
public function listParameters($preserveCypheredPasswords = false, $blurCypheredPasswords = false)
220225
{
221-
return $this->parameters;
226+
if($preserveCypheredPasswords) return $this->parameters;
227+
228+
$copy = $this->parameters;
229+
foreach($copy as $repo => &$plugs){
230+
foreach($plugs as $plugName => &$plugData){
231+
foreach($plugData as $paramName => &$paramValue){
232+
$testValue = $this->filterCypheredPasswordValue($paramValue);
233+
if($testValue != $paramValue){
234+
if($blurCypheredPasswords) $paramValue = "__AJXP_VALUE_SET__";
235+
else $paramValue = $testValue;
236+
}
237+
}
238+
}
239+
}
240+
return $copy;
222241
}
223242

224243
public function listAutoApplies()
225244
{
226245
return $this->autoApplies;
227246
}
228247

248+
/**
249+
* @param String $value
250+
* @return String
251+
*/
252+
private function filterCypheredPasswordValue($value){
253+
if(is_string($value) && strpos($value, self::$cypheredPassPrefix) === 0) return str_replace(self::$cypheredPassPrefix, "", $value);
254+
return $value;
255+
}
256+
229257
/**
230258
* @param string $pluginId
231259
* @param string $actionName
@@ -302,7 +330,7 @@ public function override(AJXP_Role $role)
302330
$newRole->setAcl($repoId, $rightString);
303331
}
304332

305-
$newParams = $this->array_merge_recursive2($role->listParameters(), $this->listParameters());
333+
$newParams = $this->array_merge_recursive2($role->listParameters(true), $this->listParameters(true));
306334
foreach ($newParams as $repoId => $data) {
307335
foreach ($data as $pluginId => $param) {
308336
foreach ($param as $parameterName => $parameterValue) {

0 commit comments

Comments
 (0)