forked from dtouzeau/artica
/
obm.index.php
435 lines (345 loc) · 11 KB
/
obm.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
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
<?php
include_once('ressources/class.templates.inc');
include_once('ressources/class.ldap.inc');
include_once('ressources/class.users.menus.inc');
include_once('ressources/class.artica.inc');
include_once('ressources/class.mysql.inc');
include_once('ressources/class.ini.inc');
include_once('ressources/class.obm.inc');
$user=new usersMenus();
if($user->AsMailBoxAdministrator==false){header('location:users.index.php');exit();}
if(isset($_GET["main"])){main_switch();exit;}
if(isset($_GET["status"])){echo main_status();exit;}
if(isset($_GET["OBMEnabled"])){main_save();exit;}
if(isset($_GET["export"])){export();exit;}
main_page();
function main_page(){
$html=
"
<script language=\"JavaScript\">
var timerID = null;
var timerID1 = null;
var tant=0;
var reste=0;
function demarre(){
tant = tant+1;
reste=10-tant;
if (tant < 10 ) {
timerID = setTimeout(\"demarre()\",5000);
} else {
tant = 0;
//document.getElementById('wait').innerHTML='<img src=img/wait.gif>';
ChargeLogs();
demarre(); //la boucle demarre !
}
}
function ChargeLogs(){
LoadAjax('services_status','$page?status=yes&hostname={$_GET["hostname"]}');
}
</script>
<table style='width:100%'>
<tr>
<td width=1% valign='top'><img src='img/bg_obm.png' style='margin-right:80px'></td>
<td valign='top'><div id='services_status'>". main_status() . "</div><br><p class=caption>{about}</p></td>
</tr>
<tr>
<td colspan=2 valign='top'><br>
<div id='main_config'></div>
</td>
</tr>
</table>
<script>demarre();LoadAjax('main_config','$page?main=yes');</script>
";
$cfg["JS"][]='js/obm.js';
$tpl=new template_users('{APP_OBM}',$html,0,0,0,0,$cfg);
echo $tpl->web_page;
}
function main_tabs(){
if(!isset($_GET["main"])){$_GET["main"]="yes";};
if($_GET["hostname"]==null){$hostname=$users->hostname;$_GET["hostname"]=$hostname;}else{$hostname=$_GET["hostname"];}
$page=CurrentPageName();
$array["yes"]='{main_settings}';
$array["logs"]='{events}';
$array["syncevents"]='{syncevents}';
$array["apacheconf"]='{apacheconf}';
while (list ($num, $ligne) = each ($array) ){
if($_GET["main"]==$num){$class="id=tab_current";}else{$class=null;}
$html=$html . "<li><a href=\"javascript:LoadAjax('main_config','$page?main=$num&hostname=$hostname')\" $class>$ligne</a></li>\n";
}
return "<div id=tablist>$html</div>";
}
function main_switch(){
switch ($_GET["main"]) {
case "yes":main_config();exit;break;
case "logs":main_logs();exit;break;
case "syncevents":main_sync();exit;break;
case "conf":echo main_conf();exit;break;
case "apacheconf":echo main_httpdconf();exit;break;
default:
break;
}
}
function main_status(){
$users=new usersMenus();
if($_GET["hostname"]==null){$hostname=$users->hostname;$_GET["hostname"]=$hostname;}else{$hostname=$_GET["hostname"];}
$ini=new Bs_IniHandler();
$sock=new sockets();
$ini->loadString($sock->getfile('obmapachestatus',$_GET["hostname"]));
$status=DAEMON_STATUS_ROUND("OBM_APACHE",$ini,null);
$tpl=new templates();
return $tpl->_ENGINE_parse_body($status);
}
function main_conf(){
$sock=new sockets();
$datas=$sock->getfile('cyrus_imapconf');
$datas=htmlspecialchars($datas);
$datas=nl2br($datas);
$datas=str_replace("\n","",$datas);
$datas=str_replace("<br /><br />","<br />",$datas);
$html=main_tabs()."
<br><H5>{config}</H5>
<div style='padding:10px;margin:10px;border 1px dotted #CCCCCC'>
<code>$datas</code>
</div>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function main_export_logs(){
if(is_file(dirname(__FILE__).'/ressources/logs/obm-synchro.log')){
$datas=file_get_contents(dirname(__FILE__).'/ressources/logs/obm-synchro.log');
}
$html="<textarea style='border:0px;padding:3px;width:100%;font-size:9px' rows=30>$datas</textarea>";
echo $html;
}
function main_config(){
$page=CurrentPageName();
$entete=main_tabs()."<br>
<H5>{main_settings}</H5>
<br>
";
$obm=new obm();
if($obm->external_url==null){$obm->external_url=$_SERVER['SERVER_NAME'];}
$form="
<input type='hidden' id='warn_export_obm' value='{warn_export_obm}'>
<table style='width:100%'>
<tr>
<td width=1% valign='top'>
<table style='width:100%'>
<tr>
<td valign='top'>" . Paragraphe("waifolder-update-64.jpg","{export_artica_users}","{export_artica_users_text}","javascript:obm_export();")."</td>
</TR>
<tr>
<td valign='top'>" . Paragraphe("64-obm.png","{APP_OBM}","{obm_connect_has_admin}","javascript:s_PopUpFull('https://$obm->external_url:$obm->apache_listen',800,600,'OBM');")."</td>
</tr>
</table>
<td valign='top'>" . RoundedLightGreen("
<form name='ffm1'>
<table style='width:100%'>
<tr>
<td align='right' nowrap style='font-weight:bold'>{enable_obm}:</td>
<td>" . Field_numeric_checkbox_img('OBMEnabled',$obm->OBMEnabled,'{enable_disable}')."</td>
</tr>
<tr>
<td align='right' nowrap style='font-weight:bold'>{https_port}:</td>
<td>" . Field_text('apache_listen',$obm->apache_listen,'width:150px')."</td>
</tr>
<tr>
<td align='right' nowrap style='font-weight:bold'>{external_protocol}:</td>
<td>" . Field_text('external_protocol',$obm->external_protocol,'width:150px',null,null,'{external_url_text}')."</td>
</tr>
<tr>
<td align='right' nowrap style='font-weight:bold'>{external_url}:</td>
<td>" . Field_text('external_url',$obm->external_url,'width:150px',null,null,'{external_url_text}')."</td>
</tr>
<tr>
<td align='right' nowrap style='font-weight:bold'>{OBMSyncCron}:</td>
<td>" . Field_text('OBMSyncCron',$obm->OBMSyncCron,'width:90px',null,null,'{OBMSyncCron_text}')."</td>
</tr>
<tr>
<td colspan=2 align='right'><input type='button' OnClick=\"javascript:ParseForm('ffm1','$page',true,false,false,'main_config','$page?main=yes');\" value='{edit} »'>
</table>
</form>")."
</td>
</tr>
</table>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body("$entete$form");
}
function main_httpdconf(){
$obm=new obm();
$conf=$obm->httpd_conf;
$conf=htmlspecialchars($conf);
$conf=nl2br($conf);
$entete=main_tabs()."<br>
<H5>{apacheconf}</H5>
<br>
<div style='padding:5px;margin:10px;border:1px dotted #CCCCCC'>
<code>$conf</code>
</div>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body("$entete");
}
function main_sync(){
$sql="SELECT * FROM events WHERE event_id='5' ORDER BY ID DESC LIMIT 0,100";
$q=new mysql();
$results=$q->QUERY_SQL($sql,'artica_events');
$table="<table style='width:550px'>";
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$ligne["text"]=htmlspecialchars($ligne["text"]);
$ligne["text"]=nl2br($ligne["text"]);
$table=$table .
"
<tr><td colspan=3><hr></td></tr>
<tr>
<td valign='top' width=1%><img src='img/fw_bold.gif'></td>
<td valign='top' nowrap><strong>{$ligne["zDate"]}</strong></td>
<td valign='top'><code>{$ligne["text"]}</code></td>
</tr>
";
}$table=$table . "</table>" ;
$table=RoundedLightGrey($table);
$entete=main_tabs()."<br>
<H5>{syncevents}</H5>
<br><div style='width:550px'>$table</div>";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($entete);
}
function main_logs(){
$page=CurrentPageName();
$tpl=new templates();
$html=main_tabs() . "
<H5>{events}</H5>
<iframe src='obm.apache.events.php' style='width:100%;height:500px;border:0px'></iframe>";
echo $tpl->_ENGINE_parse_body($html);
}
function main_save(){
$obm=new obm();
$obm->OBMEnabled=$_GET["OBMEnabled"];
if($obm->OBMEnabled==1){
$bm=new obm_export_single(1);
$ldap=new clladp();
$bm->CreateManager($ldap->ldap_admin,$ldap->ldap_password);
}
$obm->apache_listen=$_GET["apache_listen"];
$obm->external_protocol=$_GET["external_protocol"];
$obm->external_url=$_GET["external_url"];
if(preg_match('#([0-9]+)(m|h|d)#',$_GET["OBMSyncCron"])){
$obm->ObmOBMSyncCron=$_GET["OBMSyncCron"];
}
$obm->SaveToLdap();
$tpl=new templates();
echo $tpl->_ENGINE_parse_body('{success}');
}
function export(){
switch ($_GET["export"]) {
case -1:
export_main();exit;break;
case 0:
$obm=new obm_export();break;
case 5:
main_export_logs();;break;
default:
break;
}
}
function export_main(){
$html="<H5>{exporting_obm}</H5>
<div id='message_0'></div>
<div id='message_1'></div>
<div id='message_2'></div>
<div id='message_3'></div>
<div id='message_4'></div>
<div id='message_5'></div>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function export_domains(){
$obm=new obm_export();
$obm->Update_Organizations();
$html="<table style='width:100%'>
<tr>
<td width=1%><img src='img/fw_bold.gif'></td>
<td style='font-size:11px'>{organizations_added}: <b>$obm->domain_added</b></td>
</tr>
</table>";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function export_update_domains(){
$obm=new obm_export();
$obm->Update_Domains();
$html="<table style='width:100%'>
<tr>
<td width=1%><img src='img/fw_bold.gif'></td>
<td style='font-size:11px'>{domains_updated}: <b>$obm->domain_uddated</b></td>
</tr>
</table>";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function export_users(){
$obm=new obm_export();
$obm->Update_users();
$html="<table style='width:100%'>
<tr>
<td width=1%><img src='img/fw_bold.gif'></td>
<td style='font-size:11px'>{user_added}: <b>$obm->user_added</b></td>
</tr>
<tr>
<td width=1%><img src='img/fw_bold.gif'></td>
<td style='font-size:11px'>{user_failed}: <b>$obm->user_failed</b></td>
</tr>
</table>";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function export_users_update(){
$obm=new obm_export();
$obm->Update_sync_users();
$html="<table style='width:100%'>
<tr>
<td width=1%><img src='img/fw_bold.gif'></td>
<td style='font-size:11px'>{user_updated}: <b>$obm->user_added</b></td>
</tr>
<tr>
<td width=1%><img src='img/fw_bold.gif'></td>
<td style='font-size:11px'>{user_failed}: <b>$obm->user_failed</b></td>
</tr>
</table>";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function export_groups(){
$obm=new obm_export();
$obm->Update_groups();
$html="<table style='width:100%'>
<tr>
<td width=1%><img src='img/fw_bold.gif'></td>
<td style='font-size:11px'>{group_updated}: <b>$obm->user_added</b></td>
</tr>
<tr>
<td width=1%><img src='img/fw_bold.gif'></td>
<td style='font-size:11px'>{group_failed}: <b>$obm->user_failed</b></td>
</tr>
</table>";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function export_admin(){
$obm=new obm_export();
if($obm->Update_admin()){$li="{success}";}else{$li='{failed}';}
$html="<table style='width:100%'>
<tr>
<td width=1%><img src='img/fw_bold.gif'></td>
<td style='font-size:11px'>{update_global_admin}: <b>$li</b></td>
</tr>
</table>
<p class=caption>{close_now}</p>";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
?>