18 require_once SQ_CORE_PACKAGE_PATH.
'/../include/asset.inc';
19 require_once SQ_CORE_PACKAGE_PATH.
'/data_source/data_source/data_source.inc';
20 require_once SQ_FUDGE_PATH.
'/ldap/ldap.inc';
64 $this->_ldap_dir = Array();
66 parent::__construct($assetid);
79 $query_string = isset($this->_tmp[
'search_filter_string']) ? $this->_tmp[
'search_filter_string'] : $this->
getSearchFilterString();
80 if (empty($query_string)) {
83 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this);
84 $hash = md5($query_string.$this->attr(
'attributes').
';'.$this->
attr(
'binary_attributes'));
86 if (!isset($this->_tmp[$hash])) {
90 if ($result !== FALSE) {
91 $this->_tmp[$hash] = $result;
98 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this);
99 return $this->_tmp[$hash];
114 $ldap_bridge_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_NOTICE,
'ldap_bridge', FALSE,
'ldap_bridge');
115 $ldap_bridge_assetid = isset($ldap_bridge_link[
'minorid']) ? $ldap_bridge_link[
'minorid'] : FALSE;
116 if ($ldap_bridge_assetid) {
117 $ldap_bridge_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($ldap_bridge_assetid);
120 if (!empty($ldap_bridge_info) && $ldap_bridge_info[$ldap_bridge_assetid][
'type_code'] ==
'ldap_bridge') {
121 $ldap_bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($ldap_bridge_assetid);
123 $this->_ldap_dir[
'host'] = $ldap_bridge->attr(
'host');
124 $this->_ldap_dir[
'port'] = $ldap_bridge->attr(
'port');
125 $this->_ldap_dir[
'root_dn'] = $ldap_bridge->attr(
'root_dn');
126 $this->_ldap_dir[
'bind_dn'] = $ldap_bridge->attr(
'bind_dn');
127 $this->_ldap_dir[
'password'] = $ldap_bridge->attr(
'password');
128 $this->_ldap_dir[
'ldap_options'] = $ldap_bridge->attr(
'ldap_options');
129 $this->_ldap_dir[
'aliases'] = $ldap_bridge->attr(
'aliases');
131 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($ldap_bridge_asset);
133 $this->_ldap_dir[
'host'] = $this->
attr(
'host');
134 $this->_ldap_dir[
'port'] = $this->
attr(
'port');
135 $this->_ldap_dir[
'root_dn'] = $this->
attr(
'root_dn');
136 $this->_ldap_dir[
'bind_dn'] = $this->
attr(
'bind_dn');
137 $this->_ldap_dir[
'password'] = $this->
attr(
'password');
138 $this->_ldap_dir[
'ldap_options'] = $this->
attr(
'ldap_options');
139 $this->_ldap_dir[
'aliases'] = $this->
attr(
'aliases');
155 if (empty($this->_ldap_dir[
'host']))
return NULL;
158 if (!$ldap->connect($this->_ldap_dir[
'host'], $this->_ldap_dir[
'port'])) {
163 foreach ($this->_ldap_dir[
'ldap_options'] as $option => $value) {
164 ldap_set_option($ldap->ptr, constant($option), $value);
168 ldap_set_option($ldap->ptr, LDAP_OPT_DEREF, constant($this->_ldap_dir[
'aliases']));
171 if (!empty($this->_ldap_dir[
'bind_dn'])) {
172 if (!$ldap->bind($this->_ldap_dir[
'bind_dn'], $this->_ldap_dir[
'password'])) {
192 $search_filter = trim($search_filter);
193 if (empty($search_filter)) {
200 if (!is_null($ldap)) {
201 $base_dn = $this->_ldap_dir[
'root_dn'];
202 $sort_by = trim($this->
attr(
'sort_by'));
206 $search_result = $ldap->search($base_dn, $search_filter, empty($sort_by) ? NULL : $sort_by, TRUE, TRUE, $required_attributes);
208 if (!empty($search_result)) {
209 $entries = $ldap->getEntries($search_result, $this->
parseStringValues($this->
attr(
'binary_attributes')));
211 if (!empty($entries)) {
212 unset($entries[
'count']);
213 foreach($entries as $data) {
214 unset($data[
'count']);
215 $ds_record = Array();
216 foreach($data as $ldap_key => $ldap_val) {
217 if (!is_int($ldap_key)) {
218 if (is_array($ldap_val)) {
219 unset($ldap_val[
'count']);
220 $ds_record[$ldap_key] = implode(
";", $ldap_val);
222 $ds_record[$ldap_key] = $ldap_val;
227 $result[] = $ds_record;
234 if (!is_null($ldap)) {
254 $values = explode($delimiter, $str);
255 $new_values = Array();
256 foreach ($values as $value) {
258 if (($val !=
'') && !in_array($val, $new_values)) {
259 $new_values[] = $val;
285 'LDAP_OPT_PROTOCOL_VERSION' => 3,
286 'LDAP_OPT_REFERRALS' => 0,
300 $search_filter_string = $this->
attr(
'search_filter');
301 $keyword_wrapper =
'%%';
302 $keyword_pattern =
'('.$keyword_wrapper.
'([a-zA-Z_\-0-9\.]+)'.$keyword_wrapper.
')';
305 preg_match_all (
'/'.$keyword_pattern.
'/', $search_filter_string, $matches, PREG_PATTERN_ORDER);
306 if (empty($matches[1])) {
307 $this->_tmp[
'search_filter_string'] = $search_filter_string;
308 return $this->_tmp[
'search_filter_string'];
311 $raw_keywords = $matches[1];
312 $keywords = $matches[2];
314 foreach ($keywords as $keyword) {
316 $replacements[] = str_replace(
'$',
'\$', urldecode($value));
317 $patterns[] =
'/('.$keyword_wrapper.$keyword.$keyword_wrapper.
')/';
320 $search_filter_string = preg_replace($patterns, $replacements, $search_filter_string);
321 $this->_tmp[
'search_filter_string'] = trim($search_filter_string);
323 return $this->_tmp[
'search_filter_string'];
344 $allowed_link[
'asset'][
'card'] =
'M';
345 $allowed_link[
'asset'][
'exclusive'] = FALSE;
347 $links[SQ_LINK_TYPE_1] = $allowed_link;
348 $links[SQ_LINK_TYPE_2] = $allowed_link;
349 $links[SQ_LINK_TYPE_3] = $allowed_link;
350 $links[SQ_LINK_NOTICE] = $allowed_link;