2
# $Id: query.tcl 1150 2008-08-20 00:27:11Z mikes@u.washington.edu $
3
# ========================================================================
4
# Copyright 2008 University of Washington
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# ========================================================================
16
# Purpose: CGI script to handle querying LDAP directory
26
# inherit global config
29
# Import data validate it and get session id
30
if {[catch {WPGetInputAndID sessid}]} {
35
foreach item $query_vars {
36
if {[catch {eval WPImport $item} errstr]} {
43
# return attachment list
44
puts stdout "Content-type: text/html;\n\n<html><head><script>window.parent.drawLDAPResult({"
45
if {[string length $query]} {
46
if {[catch {WPCmd PELdap query $dir $query ""} qn]} {
47
regsub -all {'} $qn {\'} qn
48
puts stdout "error:'Search failed: $qn'"
51
0 { puts stdout "error:'Search found no matching entries'" }
53
if {[catch {WPCmd PELdap results $qn} results]} {
54
regsub -all {'} $results {\'} results
55
puts stdout "error:'Problem with results: $results'"
57
puts stdout "results:\["
58
foreach result $results {
59
set res [lindex $result 1]
62
regsub -all {'} $r {\'} r
63
puts -nonewline stdout "${comma}{personal:'[lindex $r 0]',email:\["
65
foreach a [lindex $r 4] {
66
puts -nonewline stdout "$comma2'$a'"
69
puts -nonewline stdout "\]}"
80
puts stdout "error:'Empty search request'"
83
puts stdout "});</script></head><body></body></html>"