input_check() now removes non-ASCII characters when found

This commit is contained in:
Roland Gruber 2005-08-11 18:34:50 +00:00
parent 579d94d031
commit 98cc8373e7
1 changed files with 28 additions and 11 deletions

View File

@ -521,12 +521,15 @@ class baseModule {
}
}
function input_check() {
/* We have to some string checks now. Not every ldap attributes allow utf8
* strings. Therefore we do a syntax check here and change utf8 strings to ascci
* strings. Only "7bit" ascci is allowed
* We check als the max length as defined in ldap.
/**
* Checks if the attribute values follow the LDAP syntax.
* Not every LDAP attribute allows UTF-8 strings. Therefore we do a syntax check here
* and change UTF-8 strings to ASCII strings if needed.
* The maximum length of the attributes is checked, too.
*
* @return mixed 0 if no errors/warnings occured, otherwise an array of status messages.
*/
function input_check() {
// Do a check for every ldap attribute
$attributes = array_keys($this->attributes);
for ($i=0; $i<count($attributes); $i++) {
@ -543,15 +546,29 @@ class baseModule {
$_SESSION['ldap']->attributes[$attributes[$i]]['SYNTAX']=='1.3.6.1.4.1.1466.115.121.1.11') {
// found "7bit" ascii attribute
// convert utf8 in us-ascii
$convert = array ( 'ä' => 'ae', 'Ä' => 'Ae', 'ö' => 'Oe', 'ü' => 'ue', 'Ü' => 'ue',
'ß' => 'ss', 'é' => 'e', 'è' => 'e', 'ô' => 'o'
$convert = array ( 'ä' => 'ae', 'Ä' => 'Ae', 'ö' => 'Oe', 'ü' => 'ue', 'Ü' => 'Ue',
'ß' => 'ss', 'é' => 'e', 'è' => 'e', 'ô' => 'o', 'ç' => 'c'
);
$index = array_keys($convert);
for ($j=0; $j<count($this->attributes[$attributes[$i]]); $j++)
for ($j=0; $j<count($this->attributes[$attributes[$i]]); $j++) {
$replaced = false;
// replace special characters
for ($k=0; $k<count($index); $k++) {
$temp = str_replace($index[$k], $convert[$index[$k]], $this->attributes[$attributes[$i]][$j]);
if ($temp!=$this->attributes[$attributes[$i]][$j]) {
$this->attributes[$attributes[$i]][$j] = $temp;
$replaced = true;
}
}
// remove remaining UTF-8 characters
for ($c = 0; $c < strlen($this->attributes[$attributes[$i]][$j]); $c++) {
if (ord($this->attributes[$attributes[$i]][$j][$c]) > 127) {
$this->attributes[$attributes[$i]][$j] = substr($this->attributes[$attributes[$i]][$j], 0, $c) .
substr($this->attributes[$attributes[$i]][$j], $c + 2);
$replaced = true;
}
}
if ($replaced) {
$messages[$attributes[$i]][] = array('WARN', _($attributes[$i]), _('Changed value because only ASCII characters are allowed.'));
}
}