~ubuntu-branches/debian/stretch/alpine/stretch

« back to all changes in this revision

Viewing changes to web/cgi/alpine-2.0/conduit/query.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2010-10-03 15:31:55 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101003153155-2exypc96j1e8tw0p
Tags: 2.02-1
* New upstream release, based on re-alpine project
* Updated debian/copyright to reflect this fact
* re-alpine removed the non-free from the tarball, so now
  we do not repack the upstream tarball. (Yay!)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!./tclsh
2
 
# $Id: query.tcl 1150 2008-08-20 00:27:11Z mikes@u.washington.edu $
3
 
# ========================================================================
4
 
# Copyright 2008 University of Washington
5
 
#
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
9
 
#
10
 
#     http://www.apache.org/licenses/LICENSE-2.0
11
 
#
12
 
# ========================================================================
13
 
 
14
 
#  query.tcl
15
 
#
16
 
#  Purpose:  CGI script to handle querying LDAP directory
17
 
#
18
 
#  Input: 
19
 
set query_vars {
20
 
  {dir          ""      "0"}
21
 
  {query        ""      ""}
22
 
}
23
 
 
24
 
#  Output: 
25
 
 
26
 
# inherit global config
27
 
source ../alpine.tcl
28
 
 
29
 
# Import data validate it and get session id
30
 
if {[catch {WPGetInputAndID sessid}]} {
31
 
  return
32
 
}
33
 
 
34
 
# grok parameters
35
 
foreach item $query_vars {
36
 
  if {[catch {eval WPImport $item} errstr]} {
37
 
    lappend errs $errstr
38
 
  }
39
 
}
40
 
 
41
 
set qresult ""
42
 
 
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'"
49
 
  } else {
50
 
    switch $qn {
51
 
      0 {  puts stdout "error:'Search found no matching entries'" }
52
 
      default {
53
 
        if {[catch {WPCmd PELdap results $qn} results]} {
54
 
          regsub -all {'} $results {\'} results
55
 
          puts stdout "error:'Problem with results: $results'" 
56
 
        } else {
57
 
          puts stdout "results:\["
58
 
          foreach result $results {
59
 
            set res [lindex $result 1]
60
 
            set comma ""
61
 
            foreach r $res {
62
 
              regsub -all {'} $r {\'} r
63
 
              puts -nonewline stdout "${comma}{personal:'[lindex $r 0]',email:\["
64
 
              set comma2 ""
65
 
              foreach a [lindex $r 4] {
66
 
                puts -nonewline stdout "$comma2'$a'"
67
 
                set comma2 ","
68
 
              }
69
 
              puts -nonewline stdout "\]}"
70
 
              set comma ","
71
 
            }
72
 
          }
73
 
 
74
 
          puts stdout "\]"
75
 
        }
76
 
      }
77
 
    }
78
 
  }
79
 
} else {
80
 
  puts stdout "error:'Empty search request'"
81
 
}
82
 
 
83
 
puts stdout "});</script></head><body></body></html>"