allow obfuscated settings

This commit is contained in:
Roland Gruber 2011-07-23 15:01:20 +00:00
parent e1ad25ef02
commit 825c546991
2 changed files with 69 additions and 2 deletions

View File

@ -778,4 +778,47 @@ function formatLDAPTimestamp($time) {
' ' . substr($time, 8, 2) . ':' . substr($time, 10, 2) . ':' . substr($time, 12, 2) . ' GMT';
}
/**
* Simple function to obfuscate strings.
*
* @param String $text text to obfuscate
*/
function obfuscateText($text) {
if (($text == null) || ($text == '')) {
return $text;
}
return str_rot13(base64_encode('LAM_OBFUSCATE:'.$text));
}
/**
* Simple function to deobfuscate strings.
*
* @param String $text text to deobfuscate
*/
function deobfuscateText($text) {
if (($text == null) || ($text == '')) {
return $text;
}
return str_replace('LAM_OBFUSCATE:', '', base64_decode(str_rot13($text)));
}
/**
* Checks if the given text is obfuscated.
*
* @param String $text text to check
* @return boolean obfuscated or not
*/
function isObfuscatedText($text) {
if (($text == null) || ($text == '')) {
return false;
}
$deob = base64_decode(str_rot13($text));
if (strpos($deob, 'LAM_OBFUSCATE:') === 0) {
return true;
}
else {
return false;
}
}
?>

View File

@ -349,6 +349,8 @@ class htmlInputField extends htmlElement {
private $isPassword = false;
/** enabled or disabled */
private $isEnabled = true;
/** indicates that the value should be saved in obfuscated form */
private $obfuscate = false;
/**
* Constructor
@ -357,6 +359,9 @@ class htmlInputField extends htmlElement {
* @param String $fieldValue value of input field (optional)
*/
function __construct($fieldName, $fieldValue = null, $fieldSize = null) {
if (isObfuscatedText($fieldValue)) {
$fieldValue = deobfuscateText($fieldValue);
}
$this->fieldName = htmlspecialchars($fieldName);
$this->fieldValue = htmlspecialchars($fieldValue);
if ($fieldSize != null) {
@ -377,8 +382,13 @@ class htmlInputField extends htmlElement {
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
if (isset($values[$this->fieldName])) {
if (isObfuscatedText($values[$this->fieldName][0])) {
$this->fieldValue = deobfuscateText($values[$this->fieldName][0]);
}
else {
$this->fieldValue = $values[$this->fieldName][0];
}
}
// print input field
$name = ' name="' . $this->fieldName . '"';
$value = '';
@ -401,8 +411,13 @@ class htmlInputField extends htmlElement {
$disabled = ' disabled';
}
echo '<input type="' . $inputType . '"' . $name . $value . $maxLength . $size . $fieldTabIndex . $disabled . '>';
if ($this->obfuscate) {
return array($this->fieldName => 'text_obfuscated');
}
else {
return array($this->fieldName => 'text');
}
}
/**
* Sets the maximum field length.
@ -440,6 +455,15 @@ class htmlInputField extends htmlElement {
$this->isEnabled = $isEnabled;
}
/**
* Specifies if the value should be saved in obfuscated form (e.g. self service profile).
*
* @param boolean $obfuscate obfuscate value
*/
public function setObfuscate($obfuscate) {
$this->obfuscate = $obfuscate;
}
}
/**