forked from poppyred/1.6.x
/
domains.php
executable file
·633 lines (520 loc) · 17.4 KB
/
domains.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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
<?php
header("Pragma: no-cache");
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
include_once('ressources/class.templates.inc');
include_once('ressources/class.mailboxes.inc');
include_once('ressources/kav4mailservers.inc');
include_once('ressources/class.cyrus.inc');
include_once('ressources/class.html.pages.inc');
include_once('ressources/class.cron.inc');
$tpl=new template_users();
$_GET["PRIVS"]=$tpl->_ParsePrivieleges($_SESSION["privileges"]["ArticaGroupPrivileges"]);
writequeries();
if(isset($_GET["delete_domain_confirm"])){delete_domain_confirm();exit;}
if(isset($_GET["add_domain_entity"])){add_domain_entity();exit;}
if(isset($_GET["ListDomainByEntity"])){echo List_domains($_GET["ListDomainByEntity"]);exit;}
if(isset($_GET["add_entity"])){add_entity();exit;}
if(isset($_GET["Tree_Internet_domain_delete_transport"])){Tree_Internet_domain_delete_transport();exit;}
if(isset($_GET["Tree_group_Add_New"])){Tree_group_Add_New();exit;}
if(isset($_GET["Tree_group_edit1"])){Tree_group_edit1();exit;}
if(isset($_GET["Tree_group_delete"])){Tree_group_delete();exit;}
if(isset($_GET["Tree_ou_Add_user"])){Tree_ou_Add_user();exit;}
if(isset($_GET["taskAdd"])){taskAdd();exit;}
if(isset($_GET["TreeSendTaskAdd"])){TreeSendTaskAdd();exit;}
if(isset($_GET["TreeTaskDelete"])){TreeTaskDelete();exit;}
if(isset($_GET["TreeApplyTasks"])){TreeApplyTasks();exit;}
if(isset($_GET["artica_service_start"])){artica_service_start();exit;}
if(isset($_GET["artica_service_stop"])){artica_service_stop();exit;}
if(isset($_GET["TreeFetchmailShowServer"])){TreeFetchmailShowServer();exit();}
if(isset($_GET["AutomaticConfig"])){TreeArticaSaveConfig();exit;}
if(isset($_GET["TreeFetchMailApplyConfig"])){TreeFetchMailApplyConfig();exit;}
if(isset($_GET["fetchmail_daemon_pool"])){TreeArticaSaveConfig();exit;}
if(isset($_GET["GetKavGroups"])){GetKavGroups();exit;}
if(isset($_GET["TreeAddNewOrganisation"])){TreeAddNewOrganisation();;exit;}
if(isset($_GET["TreeDeleteOrganisation"])){TreeDeleteOrganisation();exit;}
if(isset($_GET["TreeSynchronyzeMailBoxes"])){TreeSynchronyzeMailBoxes();exit;}
if(isset($_GET["TreeOuLoadPageFindUser"])){TreeOuLoadPageFindUser();exit;}
if(isset($_GET["save_ldap_settings"])){save_ldap_settings();exit;}
if(isset($_GET["TreeKas3SaveSettings"])){TreeKas3SaveSettings();exit;}
if(isset($_GET["kas3UpdaterConfig"])){Treekas3UpdaterConfig();exit;}
$html="
<input type='hidden' id='text_add_entity' value=\"{text_add_entity}\">
<input type='hidden' id='text_add_domain_entity' value=\"{text_add_domain_entity}\">
<input type='hidden' id='text_delete' value=\"{delete}\">
<table width='700px' style='border-top:1px dotted #8e8785;'>
<tr>
<td width='295px' valign='top' style='border-right:1px dotted #8e8785;'>
<div id='LdapTree' style='margin:5px;'></div>
</td>
<td width=50% valign='top' style='padding-left:5px'>
<div id='rightInfos'></div>
</td>
</tr>
</table>
<script type=\"text/javascript\">
var keys = [{
\"key\" : 46,
\"func\" : TreeDelete}];
var LdapTreeStruct=[
{
'id' : 'Root',
'txt' : 'Server',
'img' : 'tree-server.gif',
'onopenpopulate' : myOpenPopulate,
'openlink' : 'ldapTree.php',
'canhavechildren' : true }
];
var tree = null;
var ReturnedValue=null;
" . TreeFunctions() . "
function TafelTreeInit () {
tree = new TafelTree('LdapTree', LdapTreeStruct, {
'generate' : true,
'imgBase' : 'img/',
'width' : '100%', // valeur par d�faut : 100%
'height' : '650px', // valeur par d�faut : auto
'openAtLoad' : false,
'cookies' : false,
'onEdit' : TreeEditGroup,
'onClick' : TreeClick,
'onDropAjax':[MyTreeDrop, \"tree.functions.php\"]
});
TafelTreeManager.setKeys(keys);
}
function myOpenPopulate (branch, response) {
return true;
}
function TreeDelete (tree, code, modifiers, ev) {
var dltext=document.getElementById('text_delete').value;
if(confirm(dltext+'?')){
var XHR = new XHRConnection();
var b = tree.getSelectedBranches();
var branchId = b[0].getId();
var previous = b[0].getParent();
if (previous) {
XHR.appendData('PreviousBranch', previous.getId());
}
XHR.appendData('DeleteBranch', branchId);
XHR.sendAndLoad('tree.functions.php', 'GET',x_TreeEditGroup);
if(ReturnedValue.length>0){ReloadBranch(ReturnedValue);return true;}
alert('{failed}');
return false;
}
}
function MyTreeDrop(branchMoved,newParent,response,dropFinished){
if(response=='ok'){return true;}else{alert(response);return false;}
}
function ReloadBranch(id){
var branch = tree.getBranchById(id);
if(branch.removeChildren){
branch.removeChildren();
branch._openPopulate();
}else{alert(id);}
}
function ReloadTree(){
if (TafelTreeInit) {
document.getElementById('LdapTree').innerHTML='';
TafelTreeInit();
}
var selected = tree.getSelectedBranches();
if (selected.length > 0) {
for (var i = 0; i < selected.length; i++) {
var branch = tree.getBranchById(selected[i].getId());
branch.refreshChildren();
}
}
}
</script>
";
$tpl=new templates();
$html=$tpl->_ENGINE_parse_body($html);
$tpl=new template_users('{TITLE_DOMAINS}',$html);
echo $tpl->web_page;
function TreeFunctions(){
$html="
var x_TreeEditGroup= function (obj) {
ReturnedValue=obj.responseText;
}
function TreeEditGroup(branch, newValue, oldValue) {
var str = branch.getId() + \" : \" + newValue;
var XHR = new XHRConnection();
XHR.appendData('EditBranch', branch.getId());
XHR.appendData('EditBranchValue', newValue);
XHR.sendAndLoad('tree.functions.php', 'GET',x_TreeEditGroup);
return ReturnedValue;
}
function TreeClick(branch) {
var str = branch.getId();
var XHR = new XHRConnection();
XHR.appendData('SelectBranch', branch.getId());
XHR.setRefreshArea('rightInfos');
XHR.sendAndLoad('tree.functions.php', 'GET');
return ReturnedValue;
}
function myBeforeOpen(branch, opened){
var str = branch.getId();
var XHR = new XHRConnection();
XHR.appendData('SelectBranch', branch.getId());
XHR.setRefreshArea('rightInfos');
XHR.sendAndLoad('tree.functions.php', 'GET');
return true;
}
";
return $html;
}
function List_domains($ou=null){
if($ou==null){return null;}
$ldap=new clladp();
$hash=$ldap->hash_get_domains_ou($ou);
$kav4mailservers=new kav4mailservers();
if(!is_array($hash)){return null;}
$html="
<fieldset>
<legend>{ARRAY_TITLE}</legend>
<table style='width:95%' align='center'>
<tr class=rowT>
<td colspan=2> </TD>
<td nowrap>{ARRAY_TITLE_TRANSPORT}</TD>
<td nowrap>{ARRAY_TITLE_USERS}</TD>
<td nowrap>{ARRAY_TITLE_AV}</TD>
<td> </TD>
</TR>
";
while (list ($num, $ligne) = each ($hash) ){
if($class='rowA'){$class='rowB';}else{$class="rowA";}
$users_numbers=0;
$users_numbers=$ldap->HashGetUsersAccounts($ou,$ligne);
$redirect=$ldap->GetTransportTable($ligne);
if($redirect==null){$redirect="local/dns";}
if($kav4mailservers->IsDomainLicenced($ligne)==true){
$kav="<img src='img/status_ok.jpg'>";
}else{$kav="<img src='img/status_permission.gif'>";}
$html=$html . "<tr class=$class>
<td align='center' valign='top' width=1%>
<img src='img/upload.gif'>
</td>
<td valign='top' style='font-size:13px;letter-spacing:3px'>
<a href='domains.edit.php?domain=$ligne&ou=$ou' style='font-size:13px;' onMouseOver=\"javascript:AffBulle('{js_expand_domain}');\" OnMouseOut=\"javascript:HideBulle();\" >$ligne</a>
</td>
<td width=1% align='center'>$redirect</td>
<td width=1% align='center'>" . count($users_numbers) ."</td>
<td width=1% align='center'>$kav</td>
<td width=1% valign='top'><a href=\"javascript:DelDomain('{$ligne["domain"]}','');\"><img src='img/deluser.gif' onMouseOver=\"javascript:AffBulle('{js_del_domain}');\" OnMouseOut=\"javascript:HideBulle();\"></a></td>
</tr>";
}
$tpl=new Templates();
$html=$tpl->_parse_body($html);
return $html . "</table></fieldset>";
}
function delete_domain_confirm(){
writelogs("Receive " . $_GET["delete_domain_confirm"],__FUNCTION__,__FILE__);
$domain=$_GET["delete_domain_confirm"];
$mailb=new MailBoxes();
$mailb->Delete_entire_domain($domain);
echo List_domains();
}
function List_entities($echo=0){
$ldap=new clladp();
$hash=$ldap->hash_get_ou();
if(!is_array($hash)){return null;}
$html="<center'>
<fieldset><legend>{entities}</legend><table>
<tr class=rowT>
<td> </td>
<td>{entities}</td>
<td>{nb_domains}</td>
<td> </td>
</tr>
";
while (list ($num, $val) = each ($hash) ){
if($class=='rowB'){$class='rowB';}else{$class='rowB';}
$count_domains=0;
$count_domains=count($ldap->hash_get_domains_ou($val));
$html=$html .
"<tr class='$class'>
<td width=1%><img src='img/ou.png'></td>
<td ><a href=\"javascript:ListDomainByEntity('$val');\" style='font-size:13px;letter-spacing:3px'>$val</td>
<td ><span style='font-size:13px;letter-spacing:3px'>$count_domains</td>
<td><input type='button' OnClick=\"javascript:AddDomainByEntity('$val');\" value='{js_add_domain} »'></td>
</tr>";
}
$html= $html . "</table></fieldset>";
if($echo==1){
$tpl=new templates();
$html=$tpl->_parse_body($html);
echo $html;exit;}
return $html;
}
function add_entity(){
$entity=$_GET["add_entity"];
$ldap=new clladp();
$ldap->AddGroup($entity);
echo List_entities(1);
}
function add_domain_entity(){
$domain=$_GET["add_domain_entity"];
$ou=$_GET["entity_name"];
$ldap=new clladp();
$ldap->AddDomainEntity($ou,$domain);
echo List_entities(1);
}
function Tree_Internet_domain_delete_transport(){
$domain=$_GET["Tree_Internet_domain_delete_transport"];
$ou=$_GET["ou"];
$ldap=new clladp();
$pages=new HtmlPages();
$dn="cn=$domain,ou=$ou,dc=organizations,$ldap->suffix";
$ldap->ldap_delete($dn,True);
echo $pages->PageTransport($domain,$ou);
}
function Tree_group_Add_New(){
$group=$_GET["Tree_group_Add_New"];
$group=replace_accents($group);
$ou=$_GET["ou"];
$ldap=new clladp();
$dn="cn=$group,ou=$ou,dc=organizations,$ldap->suffix";
$update_array["cn"][0]="$group";
$update_array["gidNumber"][0]=$ldap->_GenerateGUID();
$update_array["description"][0]="New posix group";
$update_array["objectClass"][]='posixGroup';
$update_array["objectClass"][]='ArticaSettings';
$update_array["objectClass"][]='top';
if($ldap->ldap_add($dn,$update_array)==false){
echo nl2br(
"Error: Adding {$update_array["gidNumber"][0]} gid
cn=New Group\n".
$ldap->ldap_last_error);
}
$pages=new HtmlPages();
echo $pages->PageOu($dn);
}
function Tree_group_edit1(){
$gid=$_GET["Tree_group_edit1"];
$_GET["group_name"]=replace_accents($_GET["group_name"]);
$ldap=new clladp();
$hash=$ldap->GroupDatas($gid);
$dn=$hash["dn"];
if($hash["cn"]<>$_GET["group_name"]){
$ldap->ldap_group_rename($dn,"cn={$_GET["group_name"]}");
$hash=$ldap->GroupDatas($gid);
$dn=$hash["dn"];}
$update_array["description"][0]=$_GET["description"];
$ldap->Ldap_modify($dn,$update_array);
$pages=new HtmlPages();
echo $pages->PageGroup($gid);
}
function Tree_group_delete(){
$gid=$_GET["Tree_group_delete"];
$ldap=new clladp();
$hash=$ldap->GroupDatas($gid);
$ldap->ldap_delete($hash["dn"]);
$pages=new HtmlPages();
echo $pages->PageOu($hash["dn_ou"]);
}
function Tree_ou_Add_user(){
$user=$_GET["Tree_ou_Add_user"];
$user=replace_accents($user);
$ldap=new clladp();
$ou=$_GET["ou"];
$uid=str_replace(' ','.',$user);
if(stripos($user,'@')>0){
$mail=$user;
$tbl=explode('@',$user);
$domainName=$tbl[1];
$user=$tbl[0];
$uid=str_replace(' ','.',$user);
if(preg_match('#([a-z0-9]+)([\.\-_])([a-z0-9_\-\.]+)#',$user,$reg)){
$firstname=$reg[1];
$lastname=$reg[3];
}
elseif (preg_match('#(.+)\s+(.+)#',$user,$reg)){
$firstname=$reg[1];
$lastname=$reg[2];
}
elseif (preg_match('#(.+)#',$user,$reg)){
$lastname=$reg[1];
$firstname=$lastname;
}
}
else{
if(preg_match('#([a-z0-9_\-]+)\s+([a-z0-9_\-]+)#',$user,$reg)){
$lastname=$reg[2];
$firstname=$reg[1];
$domainName='none';
}else{
$lastname=$user;
$firstname=$user;
$domainName='none';
}
}
$dn="cn=$user,ou=users,ou=$ou,dc=organizations,$ldap->suffix";
$update_array["cn"][]=$user;
$update_array["uid"][]=$uid;
$update_array["sn"][]=$lastname;
$update_array["domainName"][]=$domainName;
$update_array["homeDirectory"][]="/home/$firstname.$lastname";
$update_array["accountGroup"][]="0";
$update_array["accountActive"][]='TRUE';
$update_array["mailDir"]='cyrus';
$update_array["objectClass"][]="userAccount";
$update_array["objectClass"][]="top";
$ldap->ldap_add($dn,$update_array);
if($ldap->ldap_last_error<>null){
echo nl2br($ldap->ldap_last_error);
exit();
}
$update_array=null;
$update_array["givenName"][]=$firstname;
$update_array["mail"][]=$mail;
$update_array["DisplayName"][]="$firstname " . $lastname;
$update_array["MailBoxActive"][]="FALSE";
$update_array["objectclass"][]="ArticaSettings";
$ldap->Ldap_add_mod($dn,$update_array);
$pages=new HtmlPages();
echo $pages->PageOu("ou=$ou,dc=organizations,$ldap->suffix");
}
function taskAdd(){
$taskname=$_GET["taskAdd"];
$pages=new HtmlPages();
echo $pages->PageTaskAdd($taskname);
}
function TreeSendTaskAdd(){
$taskname=$_GET["TreeSendTaskAdd"];
$taskID=$_GET["taskID"];
$cron=new cron();
$cron->ldap_AddTask($taskID,$taskname);
$pages=new HtmlPages();
echo $pages->PageTasks();
}
function TreeTaskDelete(){
$id=$_GET["TreeTaskDelete"];
$cron=new cron();
$cron->Cron_delete($id);
$pages=new HtmlPages();
echo $pages->PageTasks();
}
function TreeApplyTasks(){
$cron=new cron();
$html=$cron->SockApplyCrons();
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function artica_service_start(){
$sock=new sockets();
$sock->getfile('start_service:' . $_GET["artica_service_start"]);
}
function artica_service_stop(){
$sock=new sockets();
$sock->getfile('stop_service:' . $_GET["artica_service_stop"]);
}
function TreeFetchmailShowServer(){
$pages=new HtmlPages();
echo $pages->PageFetchMailShowServerInfos($_GET["TreeFetchmailShowServer"]);
}
function TreeArticaSaveConfig(){
$usr=new usersMenus();
$tpl=new templates();
if($usr->AsArticaAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
include_once('ressources/class.artica.inc');
$artica=new artica();
while (list ($num, $val) = each ($_GET) ){
$artica->array_config["ARTICA"][$num]=$val;
}
$artica->save();
echo "ok";
}
function save_ldap_settings(){
$usr=new usersMenus();
$tpl=new templates();
if($usr->AsArticaAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
include_once('ressources/class.artica.inc');
$artica=new artica();
while (list ($num, $val) = each ($_GET) ){
$artica->array_ldap_config["LDAP"][$num]=$val;
}
$artica->saveLDapSettings();
echo "ok";
}
function TreeFetchMailApplyConfig(){
$usr=new usersMenus();
$tpl=new templates();
if($usr->AsMailBoxAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
include_once('ressources/class.fetchmail.inc');
$fecth=new fetchmail();
echo $fecth->Save();
}
function GetKavGroups(){
$kas=new kav4mailservers(1);
}
function TreeAddNewOrganisation(){
$usr=new usersMenus();
$tpl=new templates();
if($usr->AsArticaAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
$ou=$_GET["TreeAddNewOrganisation"];
if($ou=="_Global"){echo "Reserved!";exit;}
$ldap=new clladp();
$ldap->AddOrganization($ou);
if($ldap->ldap_last_error<>null){
if($ldap->ldap_last_error_num<>68){
echo "\n****************************************\nAdding Organization \"{$ou}\"\n********************\n";
echo $ldap->ldap_last_error;
exit;
}
}
$ldap->ldap_close();
REMOVE_CACHED("domains.index.php");
$sock=new sockets();
$sock->getFrameWork("status.php?force-front-end=yes");
}
function TreeDeleteOrganisation(){
$usr=new usersMenus();
$tpl=new templates();
$ou=$_GET["TreeDeleteOrganisation"];
if($usr->AsArticaAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
$ldap=new clladp();
$ldap->ldap_delete("ou=$ou,dc=organizations,$ldap->suffix",true);
if($ldap->ldap_last_error<>null){echo $ldap->ldap_last_error;exit;}
echo $tpl->_ENGINE_parse_body( "$ou {deleted}");
}
function TreeSynchronyzeMailBoxes(){
$usr=new usersMenus();
$tpl=new templates();
if($usr->AsMailBoxAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
include_once("ressources/class.cyrus.inc");
$cyrus=new cyrus();
echo $tpl->_ENGINE_parse_body($cyrus->SynchronizeMailBoxes());
}
function TreeOuLoadPageFindUser(){
$pages=new HtmlPages();
echo $pages->PageOuFindUser($_GET["TreeOuLoadPageFindUser"],$_GET["TreeOuFindUser"]);
}
function TreeKas3SaveSettings(){
include_once('ressources/class.kas-filter.inc');
unset($_GET["TreeKas3SaveSettings"]);
$kas=new kas_filter();
if($kas->error==true){$html="{error_no_socks}" ;}
else{
while (list ($num, $val) = each ($_GET) ){$kas->array_datas[$num]=$val;}
if($kas->SaveFile()){$html="{success}";}else{$html="{failed}";}
}
unset($_GET);
$tpl=new templates();
echo html_entity_decode($tpl->_ENGINE_parse_body($html));
}
function Treekas3UpdaterConfig(){
include_once('ressources/class.kas-filter.inc');
unset($_GET["kas3UpdaterConfig"]);
unset($_GET["PRIVS"]);
$kas=new kasUpdater();
if($kas->error==true){$html="{error_no_socks}" ;}
else{
while (list ($num, $val) = each ($_GET) ){$kas->array_updater_data["updater.options"][$num]=$val;}
if($kas->SaveFile()){$html="{success}";}else{$html="{failed}";}
}
unset($_GET);
$tpl=new templates();
echo html_entity_decode($tpl->_ENGINE_parse_body($html));
}
?>