-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathleft.php
More file actions
249 lines (206 loc) · 7.44 KB
/
left.php
File metadata and controls
249 lines (206 loc) · 7.44 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
// navigation bar
// $Id: left.php,v 2.130 2007-07-13 11:12:01 turbo Exp $
// {{{ Setup session etc
require("./include/pql_session.inc");
require($_SESSION["path"]."/include/pql_config.inc");
require($_SESSION["path"]."/left-head.html");
// }}}
// {{{ Server control header
$div_counter = 0;
?>
<!-- Server Control -->
<div id="el<?php echo $div_counter?>Parent" class="parent">
<a class="item" href="control.php">
<font color="black" class="heada"><b>Users</b></font>
</a>
</div>
<?php
$div_counter++;
if($_SESSION["ALLOW_BRANCH_CREATE"] and $_SESSION["ADVANCED_MODE"]) {
?>
<!-- Add domain branch link -->
<div id="el5Parent" class="parent">
<a href="domain_add_form.php?rootdn=<?php echo $_SESSION["BASE_DN"][0]?>"><?php echo pql_complete_constant($LANG->_('Add %what%'), array('what' => $LANG->_('domain branch'))); ?></a><br>
</div>
<?php
}
// }}}
// {{{ ---------------- GET THE DOMAINS/BRANCHES
if($_SESSION["ALLOW_BRANCH_CREATE"]) {
// This is a 'super-admin'. Should be able to read EVERYTHING!
$domains = pql_get_domains();
} else {
// {{{ Get ALL domains we have access to.
// I.e., all DN's with 'administrator: USER_DN'
foreach($_SESSION["BASE_DN"] as $dn) {
$dom = $_pql->get_dn($dn, pql_get_define("PQL_ATTR_ADMINISTRATOR")."=".$_SESSION["USER_DN"]);
if($dom) {
foreach($dom as $d) {
$domains[] = $d;
}
}
}
// }}}
}
// }}}
// {{{ ---------------- GET THE USERS OF THE BRANCH
if(!isset($domains) or !is_array($domains)) {
// {{{ No domain defined -> 'ordinary' user (only show this user)
$_SESSION["SINGLE_USER"] = 1;
$cn = $_pql->get_attribute($_SESSION["USER_DN"], pql_get_define("PQL_ATTR_CN"));
if(is_array($cn))
$cn = $cn[0];
// Try to get the DN of the domain
$dnparts = ldap_explode_dn($_SESSION["USER_DN"], 0);
for($i=1; $i < count($dnparts); $i++) {
// Traverse the users DN backwards
$DN = $dnparts[$i];
for($j=$i+1; $j < count($dnparts); $j++)
$DN .= "," . $dnparts[$j];
// Look in DN for attribute 'defaultdomain'.
$defaultdomain = $_pql->get_attribute($DN, pql_get_define("PQL_ATTR_DEFAULTDOMAIN"));
if($defaultdomain) {
// A hit. This is the domain under which the user is located.
$domain = $DN;
break;
}
}
if(empty($domain) and $_REQUEST["domain"])
$domain = $_REQUEST["domain"];
if(empty($rootdn) and empty($_REQUEST["rootdn"]))
$rootdn = pql_get_rootdn($_SESSION["USER_DN"], 'left.php');
$links = array($cn => "user_detail.php?rootdn=".$rootdn."&domain=$domain&user=".urlencode($_SESSION["USER_DN"]));
echo "<br>";
pql_format_tree_span($cn, $links, -1);
// }}}
} else {
// {{{ We got at least one domain - get it's users
$_SESSION["SINGLE_USER"] = 0;
?>
<!-- Domain branches -->
<?php
$domains = pql_uniq($domains);
if(file_exists($_SESSION["path"]."/.DEBUG_DOMAINS")) {
echo "<br>Domains:";
printr($domains);
}
foreach($domains as $key => $domain) {
// {{{ Get domain name part from the DN
// Three steps because pql_get_domains() and pql_get_dn()
// returns normalized DN's which isn't as pretty.
// 1. Get each part of the DN
$dnparts = explode(',', $domain);
// 2. Extract the attribute from the first RDN
$tmp = explode('=', $dnparts[0]);
$attrib = $tmp[0];
// 3. Get the attribute value from the object
$d = $_pql->get_attribute($domain, $attrib);
if(is_array($d))
// Happens if the object have '> 1' attribute values in it's reference.
// It's impossible to figure out WHICH of the values to use, so we
// take the first. Better than nothing...
$d = $d[0];
// }}}
if(!preg_match('/%3D/i', $domain))
$domain = urlencode($domain);
// Get Root DN
$rootdn = pql_get_rootdn($domain, 'left.php');
// Create a user search filter
if(pql_get_define("PQL_CONF_USER_FILTER", $rootdn))
$filter = pql_get_define("PQL_CONF_USER_FILTER", $rootdn);
else
$filter = pql_get_define("PQL_CONF_REFERENCE_USERS_WITH", $rootdn)."=*";
// Get the subbranches in this domain
$branches = pql_unit_get($domain);
if((count($branches) > 1)) {
// More than one subbranch
$links = array(pql_complete_constant($LANG->_('Add %what%'),
array('what' => $LANG->_('sub unit')))
=> "unit_add.php?rootdn=$rootdn&domain=$domain",
pql_complete_constant($LANG->_('Add %what%'),
array('what' => $LANG->_('user')))
=> "user_add.php?rootdn=$rootdn&domain=$domain");
// Just incase there's user(s) at the base of the domain branch...
$users = $_pql->get_dn($domain, $filter, 'ONELEVEL');
if(is_array($users))
// We have users in this domain
pql_left_htmlify_userlist($rootdn, $domain, $subbranch, $users, $links);
pql_format_tree($d, "domain_detail.php?rootdn=$rootdn&domain=$domain", $links, 0);
} elseif((count($branches) <= 1))
// This branch don't have any sub units (flat structure)
// -> make sure we still jump into the for loop!
$branches[0] = $domain;
// Just to make sure that the branches variable is really count()'able...
if(!@$branches[0])
$branches = array();
if(file_exists($_SESSION["path"]."/.DEBUG_DOMAINS")) {
echo "<br>Branches ($domain): ";
printr($branches);
}
for($i=0; $i < count($branches); $i++) {
$subbranch = 0;
// Zero out the variables, othervise we won't get users in
// specified domain, but also in the PREVIOUS domain shown!
unset($users); unset($links); unset($cns);
// Get all users (their DN) in this domain (sub)branch
if(file_exists($_SESSION["path"]."/.DEBUG_DOMAINS"))
echo "Retreiving users in branch '".$branches[$i]."'<br>";
$users = $_pql->get_dn($branches[$i], $filter);
// Level 2: The users
if(count($branches) > 1) {
// We're only interested in the 'People', 'Users' etc value,
// not the complete DN.
// Three steps because pql_get_domains() and pql_get_dn()
// returns normalized DN's which isn't as pretty.
$dnparts = ldap_explode_dn($branches[$i], 0);
$tmp = explode('=', $dnparts[0]);
$attrib = $tmp[0];
$subbranch = $_pql->get_attribute($branches[$i], $attrib);
$url = '';
$links = array(pql_complete_constant($LANG->_('Add %what%'),
array('what' => $LANG->_('user')))
=> "user_add.php?rootdn=$rootdn&domain=$domain&subbranch=$subbranch");
} else {
$links = array(pql_complete_constant($LANG->_('Add %what%'),
array('what' => $LANG->_('sub unit')))
=> "unit_add.php?rootdn=$rootdn&domain=$domain",
pql_complete_constant($LANG->_('Add %what%'),
array('what' => $LANG->_('user')))
=> "user_add.php?rootdn=$rootdn&domain=$domain");
}
if(is_array($users))
// We have users in this domain
pql_left_htmlify_userlist($rootdn, $domain, $subbranch, $users, $links);
// Level 1: The domain name with it's users
if((count($branches) > 1) and $subbranch)
pql_format_tree(pql_maybe_decode(urldecode($subbranch)), $url, $links, 1);
else
pql_format_tree($d, "domain_detail.php?rootdn=$rootdn&domain=$domain", $links, 0);
} // end foreach ($branches)
// This an ending for the domain tree
pql_format_tree_end();
unset($links);
} // end foreach ($domains)
// }}}
} // end if(is_array($domains))
// }}}
if(file_exists($_SESSION["path"]."/.DEBUG_PROFILING")) {
$now = pql_format_return_unixtime();
echo "Now: <b>$now</b><br>";
$time = $now - $start;
echo "Time: '$time second";
if($time > 1)
echo "s";
echo "'<br>";
}
require("./left-trailer.html");
pql_flush();
/*
* Local variables:
* mode: php
* mode: font-lock
* tab-width: 4
* End:
*/
?>