-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathleft-control.php
470 lines (421 loc) · 14.7 KB
/
left-control.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
<?php
// navigation bar - controls information
// $Id: left-control.php,v 2.43 2008-03-19 12:10:47 turbo Exp $
//
// {{{ Setup session etc
require("./include/pql_session.inc");
require($_SESSION["path"]."/include/pql_config.inc");
require($_SESSION["path"]."/include/pql_control.inc");
require($_SESSION["path"]."/include/pql_control_plugins.inc");
require($_SESSION["path"]."/include/pql_websrv.inc");
require("./left-head.html");
// }}}
if($_SESSION["ALLOW_CONTROL_CREATE"] and
(pql_get_define("PQL_CONF_CONTROL_USE") or
pql_get_define("PQL_CONF_WEBSRV_USE") or
pql_get_define("PQL_CONF_HOSTACL_USE") or
pql_get_define("PQL_CONF_SUDO_USE") or
pql_get_define("PQL_CONF_AUTOMOUNT_USE") or
pql_get_define("PQL_CONF_RADIUS_USE")))
{
// We're administrating QmailLDAP/Controls, Host ACLs, Sudoers or Webserver and
// the user is allowed to administrate.
$div_counter = 1;
// {{{ Retreive all physical hosts
$filter = '(&('.pql_get_define("PQL_ATTR_CN").'=*)(|('.pql_get_define("PQL_ATTR_OBJECTCLASS").'=ipHost)('.pql_get_define("PQL_ATTR_OBJECTCLASS").'=device)))';
if(is_array($_SESSION["USER_SEARCH_DN_CTR"])) {
foreach($_SESSION["USER_SEARCH_DN_CTR"] as $dn) {
$tmp = $_pql->get_dn($dn, $filter);
if(@is_array($hosts))
pql_add2array($hosts, $tmp);
else
$hosts = $tmp;
}
} else
$hosts = $_pql->get_dn($_SESSION["USER_SEARCH_DN_CTR"], $filter);
sort($hosts, SORT_STRING);
// }}}
// {{{ Check if user is controls admin in any of the root DN's
$controls_admin = 0;
foreach($_pql->ldap_basedn as $dn) {
$dn = pql_format_normalize_dn($dn);
if(pql_validate_administrator($dn, pql_get_define("PQL_ATTR_ADMINISTRATOR_CONTROLS"), $_SESSION["USER_DN"]))
$controls_admin = 1;
}
// }}}
// {{{ Add a 'Global' branch as first branch
if($_SESSION["ALLOW_BRANCH_CREATE"] or $controls_admin) {
// Only do this if:
// 1. User is super admin
// 2. User is global controls administrator
$hosts = array_merge(array("Global"), $hosts);
}
// }}}
// {{{ For each physical host, find web containers and their virtual hosts
$DATA = array();
foreach($hosts as $host_dn) {
$tmp = pql_websrv_get_data($host_dn);
if(is_array($tmp)) {
foreach($tmp as $host => $data)
$DATA[$host] = $data;
} else {
// This host does not have any web containers, but we still want it
// in the list - add it 'empty'
$host = $_pql->get_attribute($host_dn, pql_get_define("PQL_ATTR_CN"));
$DATA[$host_dn] = array();
}
}
// }}}
// {{{ Server control header
?>
<!-- Server Control -->
<div id="el<?php echo $div_counter?>Parent" class="parent">
<a class="item" href="control.php">
<font color="black" class="heada"><b>Computers</b></font>
</a>
</div>
<?php
$div_counter++;
// }}}
// {{{ 'Add physical server/host' link
if($_SESSION["ADVANCED_MODE"] and $_SESSION["ALLOW_BRANCH_CREATE"]) {
// Only do this if:
// 1. Running in a advanced mode
// 2. User is super admin
$host = explode(';', $_SESSION["USER_HOST"]);
// If it's an LDAP URI, replace "%2f" with "/" -> URLdecode
$host[0] = urldecode($host[0]);
?>
<!-- Add physical server link -->
<div id="el<?php echo $div_counter?>Parent" class="parent">
<a href="host_add.php"><?php echo $LANG->_('Add physical server/host')?></a>
</div>
<?php
$div_counter++;
}
// }}}
if(!is_array($DATA)) {
// {{{ No physical hosts
?>
<?php if($_SESSION["opera"]) { ?>
<div id="el<?php echo $div_counter?>Parent" class="parent" onclick="showhide(el<?php echo $div_counter?>Spn, el<?php echo $div_counter?>Img)">
<img name="imEx" src="images/minus.png" border="0" alt="-" width="9" height="9" id="el<?php echo $div_counter?>Img">
<font color="black" class="heada">no server hosts defined</font>
</div>
<?php } else { ?>
<div id="el<?php echo $div_counter?>Parent" class="parent">
<img src="images/navarrow.png" width="9" height="9" border="0">
<font color="black" class="heada">no server hosts defined</font>
</div>
<?php }
echo "\n";
// }}}
} else {
foreach($DATA as $physical_dn => $physical_data) {
// {{{ Get physical hostname for display
?>
<!-- Physical server: <?php echo $physical_dn?> -->
<?php
if($physical_dn == 'Global')
$host = 'Global';
else
$host = $_pql->get_attribute($physical_dn, pql_get_define("PQL_ATTR_CN"));
if(is_array($host)) {
$tmp = $host[0]." (";
for($i=1; $host[$i]; $i++) {
$tmp .= $host[$i];
if($host[$i+1])
$tmp .= ", ";
}
$tmp .= ")";
$host = $tmp;
}
// }}}
// {{{ Root of host tree
if($physical_dn == 'Global') {
pql_format_tree($host, "host_detail.php?host=".urlencode($physical_dn)."&ref=global");
} else {
$links = array();
// Check if user is controls/webserver admin in any of the root DN's
$controls_admin = 0; $websrv_admin = 0;
foreach($_pql->ldap_basedn as $dn) {
$dn = pql_format_normalize_dn($dn);
if(pql_validate_administrator($dn, pql_get_define("PQL_ATTR_ADMINISTRATOR_CONTROLS"), $_SESSION["USER_DN"]))
$controls_admin = 1;
if(pql_validate_administrator($dn, pql_get_define("PQL_ATTR_ADMINISTRATOR_WEBSRV"), $_SESSION["USER_DN"]))
$websrv_admin = 1;
}
if(pql_get_define("PQL_CONF_CONTROL_USE") and ($controls_admin or $_SESSION["ALLOW_BRANCH_CREATE"])) {
// Only do this if:
// 1. Mail server administration is on
// 2. User is global mailserver administrator
// 3. User is super admin
$new = array($LANG->_('Add mail server') => "control_add_server.php?host=".urlencode($physical_dn));
$links = $links + $new;
}
if(pql_get_define("PQL_CONF_WEBSRV_USE") and ($websrv_admin or $_SESSION["ALLOW_BRANCH_CREATE"])) {
// Only do this if:
// 1. Mail server administration is on
// 2. User is global webserver administrator OR
// 3. User is super admin
$new = array($LANG->_('Add web server') => "websrv_add.php?view=websrv&host=".urlencode($physical_dn));
$links = $links + $new;
}
if($_SESSION["ALLOW_BRANCH_CREATE"] or $websrv_admin or $controls_admin) {
// Only do this if:
// 1. User is super admin
// 2. User is global webserver administrator
// 3. User is global mailserver administrator
// 4. User have access to virtual hosts in any of the containers of this host <- TODO
pql_format_tree($host, "host_detail.php?host=".urlencode($physical_dn)."&ref=physical&view=physical", $links, 0);
} else
// MUST show the physical host, even if there's no links.
pql_format_tree($host, '', '', 0);
}
// }}}
// {{{ For each host - get QmailLDAP/Control hosts - if enabled
if(pql_get_define("PQL_CONF_CONTROL_USE") and ($controls_admin or $_SESSION["ALLOW_BRANCH_CREATE"])) {
// Only do this if:
// 1. Mail server administration is on
// 2. User is controls administrator OR
// 3. User is super admin
if($physical_dn != 'Global')
$qlcs = $_pql->get_dn($physical_dn, '(&(cn=*)(objectclass=qmailControl))', 'ONELEVEL');
if(is_array($qlcs) or ($physical_dn == 'Global')) {
// {{{ Got QLC Object(s)
if($physical_dn == 'Global')
$qlcs = array('Global'); // Fake this so that the foreach() won't complain.
foreach($qlcs as $qlc_dn) {
// {{{ Get server name for display
if($qlc_dn == 'Global')
$qlc = 'Global';
else
$qlc = $_pql->get_attribute($qlc_dn, pql_get_define("PQL_ATTR_CN"));
$qlc = pql_complete_constant($LANG->_('Mailserver - %host%'), array('host' => $qlc));
// }}}
// Get QLC categories for this QLC object
$cats = pql_plugin_get_cats();
if(!is_array($cats)) {
// {{{ No QLC plugins
if($_SESSION["opera"]) {
?>
<span id="el<?php echo $div_counter?>Spn" style="display:''">
<?php } else { ?>
<div id="el<?php echo $div_counter?>Child" class="child">
<?php } ?>
<nobr>
<img src="images/navarrow.png" width="9" height="9" border="0">
<font color="black" class="heada">no plugins defined</font>
</nobr>
<?php if($_SESSION["opera"]) { ?>
</span>
<?php } else { ?>
</div>
<?php }
// }}}
} else {
// Got QLC plugins
asort($cats);
// {{{ Setup and show the branch
$links = array();
foreach($cats as $cat) {
$new = array($cat => "control_cat.php?mxhost=".urlencode($qlc_dn)."&cat=".urlencode($cat));
$links = $links + $new;
}
pql_format_tree($qlc, "control_detail.php?mxhost=".urlencode($qlc_dn), $links, 1);
// }}}
} // end if is_array($cats)
} // end foreach($qlcs)
// }}}
} else {
// {{{ No QLC Object(s)
if(pql_get_define("PQL_CONF_CONTROL_USE")) {
if($_SESSION["opera"]) {
?>
<span id="el<?php echo $div_counter?>Spn" style="display:''">
<?php } else { ?>
<div id="el<?php echo $div_counter?>Parent" class="parent">
<?php } ?>
<nobr>
<img src="images/navarrow.png" width="9" height="9" border="0">
<font color="black" class="heada">no mailserver defined</font>
</nobr>
<br>
<?php if($_SESSION["opera"]) { ?>
</span>
<?php } else { ?>
</div>
<?php }
}
// }}}
} // end if(is_array(qlcs)
}
// }}}
// {{{ For each host - get Webserver container object(s) - if enabled
if(pql_get_define("PQL_CONF_WEBSRV_USE") and
(is_array($physical_data) or ($physical_dn == 'Global')))
{
// {{{ Got Web container object(s)
foreach($physical_data as $container_dn => $virt_hosts) {
$links = array();
// {{{ Get container name for display
if($physical_dn == 'Global')
$container = 'Global';
else
$container = $_pql->get_attribute($container_dn, pql_get_define("PQL_ATTR_CN"));
// }}}
// {{{ Extract the port number
if(preg_match('/:/', $container))
$port = ' - ' . $LANG->_('port') . ' ' . preg_replace('/.*:/', '', $container);
elseif($physical_dn == 'Global')
$port = ' - Global';
else
$port = "";
$container = pql_complete_constant($LANG->_('Webserver%port%'), array('port' => $port));
// }}}
if($container_dn != 'Global') {
if(is_array($virt_hosts)) {
// {{{ Go through the Virtual host(s)
asort($virt_hosts);
// {{{ Add a 'Add virtual server' link
if($_SESSION["ALLOW_BRANCH_CREATE"] or
pql_validate_administrator($container_dn, pql_get_define("PQL_ATTR_UNIQUE_GROUP"), $_SESSION["USER_DN"]))
{
// Only if:
// 1. Super admin
// 2. User is allowed to administrate this container (is in uniqueMember)
// 3. User is web admin of a domain which have a virtual host in this container
$new = array('<i>=> Add virtual server</i>' => "websrv_add.php?view=websrv&ref=ctrl&host=".urlencode($physical_dn)."&server=".urlencode($container_dn));
$links = $links + $new;
}
// }}}
foreach($virt_hosts as $virthost_dn => $virthost_name) {
// {{{ Setup the branch
$new = array($virthost_name => "host_detail.php?host=".urlencode($physical_dn)."&server=".urlencode($container_dn)."&virthost=".urlencode($virthost_name)."&view=websrv&ref=virtual");
$links = $links + $new;
// }}}
} // end foreach virt_hosts
// }}}
} else {
// {{{ No virtual hosts
$new = array('no virtual hosts' => '');
$links = $links + $new;
// Add a 'Add virtual server' link
if($_SESSION["ALLOW_BRANCH_CREATE"] or
pql_validate_administrator($container_dn, pql_get_define("PQL_ATTR_UNIQUE_GROUP"), $_SESSION["USER_DN"]))
{
// Only if:
// 1. Super admin
// 2. User is allowed to administrate this container (is in uniqueMember)
// 3. User is web admin of a domain which have a virtual host in this container
$new = array('<i>=> Add virtual server</i>' => "websrv_add.php?view=websrv&ref=ctrl&host=".urlencode($physical_dn)."&server=".urlencode($container_dn));
$links = $links + $new;
}
// }}}
}
} else {
// {{{ Fake virtual host for the Global branch
$links = array('no virtual hosts' => '');
// }}}
} // end if(container != Global)
// --------------------------------------------
pql_format_tree($container, "host_detail.php?host=".urlencode($physical_dn)."&server=".urlencode($container_dn)."&view=websrv&ref=container", $links, 1);
} // end foreach($web_containers)
// }}}
} else {
// {{{ No Web container object(s)
if(pql_get_define("PQL_CONF_WEBSRV_USE")) {
if($_SESSION["opera"]) {
?>
<span id="el<?php echo $div_counter?>Spn" style="display:''">
<?php } else { ?>
<div id="el<?php echo $div_counter?>Child" class="child">
<?php } ?>
<nobr>
<img src="images/navarrow.png" width="9" height="9" border="0">
<font color="black" class="heada">no webserver defined</font>
</nobr>
<?php if($_SESSION["opera"]) { ?>
</span>
<?php } else { ?>
</div>
<?php }
}
// }}}
} // endif(is_array(web_containers)
// }}}
// {{{ Get all DNS domains in the system
if(pql_get_define("PQL_CONF_BIND9_USE") and ($physical_dn == 'Global')) {
// {{{ ---------------- 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;
}
}
}
// }}}
}
// }}}
if(is_array($domains)) {
// {{{ Retreive all DNS zones
require($_SESSION["path"]."/include/pql_bind9.inc");
$zones = array();
foreach($domains as $domain) {
$zone = pql_bind9_get_zone($domain);
if(is_array($zone)) {
foreach($zone as $key => $data) {
$data["@"]["domain_branch_dn"] = $domain;
$zones[$key] = $data;
}
}
}
// }}}
if(is_array($zones)) {
ksort($zones);
// {{{ Setup and show the branch
$links = array('<i>'.$LANG->_('Replace IP address globally').'</i>' =>
'bind9_edit_attributes.php?host=Global&type=a&action=modify');
foreach($zones as $zone) {
$rootdn = pql_get_rootdn($zone["@"]["domain_branch_dn"], "left-control.php");
$dn = "host_detail.php?rootdn=$rootdn&domain=".$zone["@"]["domain_branch_dn"];
$dn .= "&view=dns&dns_domain_name=".$zone["@"]["ZONE"]."&host=Global&ref=zone";
$new = array($zone["@"]["ZONE"] => $dn);
$links = $links + $new;
}
pql_format_tree("DNS Zones - Global", "host_detail.php?view=dns&host=Global", $links, 1);
// }}}
}
}
}
// }}}
// {{{ End of the span/div - host
if($_SESSION["opera"]) {
?>
</span>
<?php } else { ?>
</div>
<?php }
echo "\n";
// }}}
} // end foreach($hosts)
} // end if(is_array(hosts)
} // end if PQL_CONF_{CONTROL,WEBSRV,HOSTACL,SUDO}_USE
echo "\n";
require("./left-trailer.html");
pql_flush();
/*
* Local variables:
* mode: php
* mode: font-lock
* tab-width: 4
* End:
*/
?>