-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
164 lines (142 loc) · 3.43 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
$LICENSE = <<<EOF
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar
14 rue de Plaisance, 75014 Paris, France
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
- - - - - - - - - - - - - - - - - - - - - - - - - -
The source code of this application is available at:
git://github.com/cluenet/ldapsearch.git
http://github.com/cluenet/ldapsearch
EOF;
error_reporting(E_ALL);
ini_set('display_errors', 1);
date_default_timezone_set("UTC");
@include "config.inc";
$Errors = array();
$SysErrors = array();
# Display full information? (false for 'info' view)
$Moar = false;
# Display module to show in single result view
switch (!empty($_GET["view"]) ? $_GET["view"] : "simple") {
case "raw":
case "ldif":
$View = "ldif";
break;
case "sshkey":
case "sshkeys":
$View = "sshkeys";
break;
case "access":
case "account":
case "person":
case "contact":
$View = $_GET["view"];
break;
case "server":
case "servers":
case "serveraccess":
$View = "servaccess";
break;
# 'info' displays basic information from all other modules
case "simple":
$View = "info";
break;
default:
$View = $_GET["view"];
}
$Stylesheets = array(
# zeroth entry is the default
'simple',
'pretty',
);
@include "functions.inc";
$Style = $Stylesheets[0];
if (isset($_GET["style"])) {
if (in_array($_GET["style"], $Stylesheets)) {
$Style = $_GET["style"];
setcookie("style", $Style, strtotime("+1 year"));
}
else {
setcookie("style", null, 0);
}
header("Location: "
.parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH)
."?".mangle_query(null, array("style")));
}
elseif (isset($_COOKIE["style"])) {
if (in_array($_COOKIE["style"], $Stylesheets)) {
$Style = $_COOKIE["style"];
}
else {
setcookie("style", null, 0);
}
}
// Construct LDAP filter from query...
if (isset($_GET["q"])) {
$Query = trim($_GET["q"]);
// user entered LDAP filter
if (!empty($Query) and $Query[0] == "(") {
$Filter = $Query;
}
// googley 'key:value' query
elseif (strpos($Query, ':') !== false) {
list ($prefix, $q) = explode(':', $Query, 2);
switch (strtolower($prefix)) {
case 'irc':
$Filter = "(clueIrcNick={$q})"; break;
case 'pgp':
case 'pgpkey':
case 'gpg':
case 'gpgkey':
$Filter = "(pgpKeyId={$q})"; break;
default:
$Filter = "({$prefix}=${q})"; break;
}
}
// username
else {
$Filter = "(|(uid={$Query})(clueIrcNick={$Query}))";
}
}
// ...or show the welcome page.
else {
$Query = false;
}
if (strlen(@$Filter))
$Filter = "(&{$Filter}(objectClass=cluenetUser))";
if ($Query) {
$NumResults = -1;
$ldapConn = ldap_connect_and_do_things();
if ($ldapConn) {
$lsearch = @ldap_list($ldapConn, "ou=people,dc=cluenet,dc=org", $Filter, Array(), null, 0);
if ($lsearch === false) {
$SysErrors[] = "LDAP query failed.";
$NumResults = 0;
} else {
$NumResults = ldap_count_entries($ldapConn, $lsearch);
}
}
} else {
$NumResults = -1;
}
switch ($NumResults) {
case -1:
require "welcome.inc";
break;
case 0:
require "results-none.inc";
break;
case 1:
require "results-single.inc";
break;
default:
require "results-list.inc";
break;
}