" " $matches = []; if (preg_match_all('/\\(\\(([a-z0-9-_]+)\\)\\)/i', $value, $matches) > 0) { foreach ($matches[1] as $match) { $attributes[] = strtolower($match); } } // %attr% -> value $matches = []; if (preg_match_all('/%([a-z0-9-_]+)%/i', $value, $matches) > 0) { foreach ($matches[1] as $match) { $attributes[] = strtolower($match); } } // @attr@ -> v $matches = []; if (preg_match_all('/@([a-z0-9-_]+)@/i', $value, $matches) > 0) { foreach ($matches[1] as $match) { $attributes[] = strtolower($match); } } // ??attr?? -> value $matches = []; if (preg_match_all('/\\?\\?([a-z0-9-_]+)\\?\\?/i', $value, $matches) > 0) { foreach ($matches[1] as $match) { $attributes[] = strtolower($match); } } // !!attr!! -> VALUE $matches = []; if (preg_match_all('/!!([a-z0-9-_]+)!!/i', $value, $matches) > 0) { foreach ($matches[1] as $match) { $attributes[] = strtolower($match); } } // ?attr? -> v $matches = []; if (preg_match_all('/\\?([a-z0-9-_]+)\\?/i', $value, $matches) > 0) { foreach ($matches[1] as $match) { $attributes[] = strtolower($match); } } // !attr! -> V $matches = []; if (preg_match_all('/!([a-z0-9-_]+)!/i', $value, $matches) > 0) { foreach ($matches[1] as $match) { $attributes[] = strtolower($match); } } // §attr|;§ -> "val1;val2" $matches = []; if (preg_match_all('/§([a-z0-9-_]+)\\|([^§]+)§/i', $value, $matches) > 0) { foreach ($matches[1] as $match) { $attributes[] = strtolower($match); } } return array_values(array_unique($attributes)); } /** * Replaces wildcards in the user entered value. * * @param string $value user entered value * @param array $entry LDAP entry * @return string result */ function replaceWildcards(string $value, array $entry): string { $attrsLower = array_change_key_case($entry, CASE_LOWER); $replacement = $value; $attrsLower['dn'] = [$attrsLower['dn']]; // ((attr)) -> " " $matches = []; if (preg_match_all('/\\(\\(([a-z0-9-_]+)\\)\\)/i', $replacement, $matches) > 0) { foreach ($matches[1] as $match) { $attributeName = strtolower($match); if (!empty($attrsLower[$attributeName][0])) { $replacement = str_replace('((' . $match . '))', ' ', $replacement); } else { $replacement = str_replace('((' . $match . '))', '', $replacement); } } } // %attr% -> value $matches = []; if (preg_match_all('/%([a-z0-9-_]+)%/i', $replacement, $matches) > 0) { foreach ($matches[1] as $match) { $attributeName = strtolower($match); if (!empty($attrsLower[$attributeName][0])) { $replacement = str_replace('%' . $match . '%', $attrsLower[$attributeName][0], $replacement); } else { $replacement = str_replace('%' . $match . '%', '', $replacement); } } } // @attr@ -> v $matches = []; if (preg_match_all('/@([a-z0-9-_]+)@/i', $replacement, $matches) > 0) { foreach ($matches[1] as $match) { $attributeName = strtolower($match); if (!empty($attrsLower[$attributeName][0])) { $replacement = str_replace('@' . $match . '@', substr($attrsLower[$attributeName][0], 0, 1), $replacement); } else { $replacement = str_replace('@' . $match . '@', '', $replacement); } } } // ??attr?? -> value $matches = []; if (preg_match_all('/\\?\\?([a-z0-9-_]+)\\?\\?/i', $replacement, $matches) > 0) { foreach ($matches[1] as $match) { $attributeName = strtolower($match); if (!empty($attrsLower[$attributeName][0])) { $replacement = str_replace('??' . $match . '??', strtolower($attrsLower[$attributeName][0]), $replacement); } else { $replacement = str_replace('??' . $match . '??', '', $replacement); } } } // !!attr!! -> VALUE $matches = []; if (preg_match_all('/!!([a-z0-9-_]+)!!/i', $replacement, $matches) > 0) { foreach ($matches[1] as $match) { $attributeName = strtolower($match); if (!empty($attrsLower[$attributeName][0])) { $replacement = str_replace('!!' . $match . '!!', strtoupper($attrsLower[$attributeName][0]), $replacement); } else { $replacement = str_replace('!!' . $match . '!!', '', $replacement); } } } // ?attr? -> v $matches = []; if (preg_match_all('/\\?([a-z0-9-_]+)\\?/i', $replacement, $matches) > 0) { foreach ($matches[1] as $match) { $attributeName = strtolower($match); if (!empty($attrsLower[$attributeName][0])) { $replacement = str_replace('?' . $match . '?', strtolower(substr($attrsLower[$attributeName][0], 0, 1)), $replacement); } else { $replacement = str_replace('?' . $match . '?', '', $replacement); } } } // !attr! -> V $matches = []; if (preg_match_all('/!([a-z0-9-_]+)!/i', $replacement, $matches) > 0) { foreach ($matches[1] as $match) { $attributeName = strtolower($match); if (!empty($attrsLower[$attributeName][0])) { $replacement = str_replace('!' . $match . '!', strtoupper(substr($attrsLower[$attributeName][0], 0, 1)), $replacement); } else { $replacement = str_replace('!' . $match . '!', '', $replacement); } } } // §attr|;§ -> "val1;val2" $matches = []; if (preg_match_all('/§([a-z0-9-_]+)\\|([^§]+)§/i', $replacement, $matches) > 0) { for ($i = 0; $i < count($matches[1]); $i++) { $attributeName = strtolower($matches[1][$i]); $separator = $matches[2][$i]; $match = $matches[0][$i]; if (!empty($attrsLower[$attributeName][0])) { $replacement = str_replace($match, implode($separator, $attrsLower[$attributeName]), $replacement); } else { $replacement = str_replace($match, '', $replacement); } } } return $replacement; }