forked from dtouzeau/artica
/
fetchmail.index.php
349 lines (254 loc) · 8.53 KB
/
fetchmail.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
<?php
include_once('ressources/class.templates.inc');
include_once('ressources/class.ldap.inc');
include_once('ressources/class.users.menus.inc');
include_once('ressources/class.fetchmail.inc');
if(isset($_GET["ajax"])){echo fetch_js();exit;}
if(isset($_GET["popup"])){echo fetch_popup();exit;}
if(isset($_GET["status"])){echo FetchMailStatus();exit;}
if(isset($_GET["enable_fetchmail"])){fetch_enable_save();exit;}
if(isset($_GET["events"])){FetchLogsPop();exit;}
if(isset($_GET["getFetchlogs"])){fetch_events();exit;}
if(isset($_GET["fetch_status"])){FetchMailStatus();exit;}
if(isset($_GET["reload-fetchmail"])){reloadfetchmail();exit;}
page();
function page(){
$usersmenus=new usersMenus();
$page=CurrentPageName();
if($usersmenus->AsPostfixAdministrator==true){}else{header('location:users.index.php');exit;}
$html="<table style='width:600px' align=center>
<tr>
<td width=50% valign='top' class='caption' style='text-align:justify'>
<img src='img/bg_fetchmail.jpg'><p>
{fetchmail_about}</p></td>
<td valign='top'>
<table>";
//folder-fetchmail-64.jpg
if($usersmenus->AsPostfixAdministrator==true){
$html=$html . "<tr><td valign='top' ><div id=status></div><br>" . applysettings("fetch") . "<br></td></tr>
<tr><td valign='top' >".Paragraphe('folder-tools-64.jpg','{daemon_settings}','{daemon_settings_text}','fetchmail.daemon.settings.php') ."</td></tr>
<tr><td valign='top'> ".Paragraphe('folder-logs-64.jpeg','{events}','{events_text}','fetchmail.daemon.events.php') ."</td></tr>";
}
$html=$html . "</table>
</td>
</tr>
</table>
<script>LoadAjax('status','$page?status=yes');</script>
";
$tpl=new template_users('Fetchmail',$html);
echo $tpl->web_page;
}
function FetchMailStatus(){
$tpl=new templates();
$ini=new Bs_IniHandler();
$sock=new sockets();
$datas=implode("\n",unserialize(base64_decode($sock->getFrameWork('cmd.php?fetchmail-status=yes'))));
$ini->loadString($datas);
$status=DAEMON_STATUS_ROUND("FETCHMAIL",$ini,null);
echo $tpl->_ENGINE_parse_body($status);
}
function fetch_js(){
$usersmenus=new usersMenus();
$tpl=new templates();
$page=CurrentPageName();
if(!$usersmenus->AsPostfixAdministrator){
$title=$tpl->_ENGINE_parse_body('{not allowed}');
echo "alert('$title');";
die();
}
if(!$usersmenus->fetchmail_installed){
$title=$tpl->_ENGINE_parse_body('{ERROR_NOT_INSTALLED_REDIRECT}');
echo "
alert('$title');
Loadjs('setup.index.progress.php?product=APP_FETCHMAIL&start-install=yes');";
exit;
}
$md=md5(date('Ymdhis'));
$title=$tpl->_ENGINE_parse_body('{APP_FETCHMAIL}');
$startcmd="YahooWin0(720,'fetchmail.index.php?popup=yes&md=$md','$title');";
if(isset($_GET["in-front-ajax"])){
$startcmd="$('#BodyContent').load('fetchmail.index.php?popup=yes&md=$md');";
}
$html="
var fetch_timerID = null;
var fetch_tant=0;
var fetch_reste=0;
function fetch_demarre(){
fetch_tant = fetch_tant+1;
fetch_reste=10-fetch_tant;
if (fetch_tant < 10 ) {
fetch_timerID = setTimeout(\"fetch_demarre()\",10000);
} else {
fetch_tant = 0;
reloadStatus();
if(document.getElementById('$md')){fetch_demarre();}
}
}
function reloadStatus(){
if(document.getElementById('$md')){
LoadAjax('$md','$page?fetch_status=yes');
}
}
var x_FetchMailEnable= function (obj) {
var tempvalue=obj.responseText;
if(tempvalue.length>0){alert(tempvalue)}
LoadFetchIndex();
}
function FetchMailEnable(){
var XHR = new XHRConnection();
XHR.appendData('enable_fetchmail',document.getElementById('enable_fetchmail').value);
document.getElementById('fetchFormEnable').innerHTML='<center><img src=\"img/wait_verybig.gif\"></center>';
XHR.sendAndLoad('$page', 'GET',x_FetchMailEnable);
}
var x_ReloadFetchMail= function (obj) {
var tempvalue=obj.responseText;
if(tempvalue.length>0){alert(tempvalue)}
}
function ReloadFetchMail(){
var XHR = new XHRConnection();
XHR.appendData('reload-fetchmail',1);
XHR.sendAndLoad('$page', 'GET',x_ReloadFetchMail);
}
function LoadFetchIndex(){
$startcmd
setTimeout(\"reloadStatus()\",2000);
}
LoadFetchIndex();
fetch_demarre();
";
echo $html;
}
function fetch_popup(){
$users=new usersMenus();
$users->LoadModulesEnabled();
if($users->EnableFetchmail==0){
echo fetch_popup_enable();
exit;
}
$add_fetchmail=Paragraphe('add-fetchmail-64.png','{add_new_fetchmail_rule}','{fetchmail_explain}',"javascript:add_fetchmail_rules()",null);
$html="
<table style='width:100%'>
<tr>
<td valign='top'>
".Paragraphe('folder-tools2-64.png','{daemon_settings}','{daemon_settings_text}',"javascript:YahooWin('550','fetchmail.daemon.settings.php?ajax=yes','{fetchmail_daemon_settings}')") ."
</td>
<td valign='top'>
".Paragraphe('fetchmail-rule-64.png','{fetchmail_rules}','{fetchmail_rules_text}',"javascript:YahooWin('550','fetchmail.daemon.rules.php?ajax=yes')") ."
</td>
<td valign='top'>
$add_fetchmail
</td>
</tr>
<tr>
<td valign='top'>".
Paragraphe('64-logs.png','{events}','{events_text}',"javascript:s_PopUpScroll('fetchmail.index.php?events=true',450,400);") ."
</td>
<td valign='top'>".
Paragraphe('64-recycle.png','{update_now}','{update_fetchmail_now}',"javascript:ReloadFetchMail();") ."
</td>
<td> </td>
</tr>
</table>
<br>
<div id='{$_GET["md"]}'></div>";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html,'artica.wizard.fetchmail.php');
}
function fetch_popup_enable(){
$artica=new artica_general();
$html="
<H1 >{enable_fetchmail}</H1>
<br><br>
<table style='width:100%'>
<tr>
<td valign='top'><div id='fetchFormEnable'>
" . Paragraphe_switch_img('{enable_fetchmail}','{enable_fetchmail_text}','enable_fetchmail',$artica->EnableFetchmail)."
</div>
</td>
<td valign='top'><input type='button' value='{edit} »»' OnClick=\"javascript:FetchMailEnable();\"><hr><br>
<p class=caption>{fetchmail_about}</p>
</tr>
</table>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function fetch_enable_save(){
$artica=new artica_general();
$artica->EnableFetchmail=$_GET["enable_fetchmail"];
$artica->Save();
$fetch=new fetchmail();
$fetch->Save();
$tpl=new templates();
echo $tpl->_ENGINE_parse_body("{enable_fetchmail}: {success}\n");
}
function fetch_events(){
$sock=new sockets();
$tbl=unserialize(base64_decode($sock->getFrameWork('cmd.php?fetchmail-logs=yes')));
$tbl=array_reverse ($tbl, TRUE);
while (list ($num, $val) = each ($tbl) ){
$val=htmlentities($val);
$html=$html . "<div style='color:white;margin-bottom:3px;'><code>$val</code></div>";
}
echo RoundedBlack($html);
}
function FetchLogsPop(){
$page=CurrentPageName();
$html="
<script language=\"JavaScript\"> // une premiere fonction pour manipuler les valeurs \"dynamiques\"
function mettre(){
document.form1.source.focus();
document.form1.source.select();
}
var timerID = null;
var timerID1 = null;
var tant=0;
var reste=0;
function demarre(){
tant = tant+1;
reste=10-tant;
if (tant < 5 ) { //exemple:caler a une minute (60*1000)
timerID = setTimeout(\"demarre()\",700);
} else {
tant = 0;
//;
postlogs();
demarre(); //la boucle demarre !
}
}
var x_postlogs=function(obj){
var tempvalue=obj.responseText;
document.getElementById('fetchev').innerHTML=tempvalue;
}
function postlogs(){
var XHR = new XHRConnection();
XHR.appendData('getFetchlogs','1');
XHR.sendAndLoad('$page', 'GET',x_postlogs);
}
function demar1(){
tant = tant+1;
if (tant < 2 ) { //delai court pour le premier affichage !
timerID = setTimeout(\"demar1()\",1000);
} else {
tant = 0; //reinitialise le compteur
LoadAjax2('fetchev','$page?getFetchlogs=1');
demarre(); //on lance la fonction demarre qui relance le compteur
}
}
</script>
<div id=wait style='margin:5px;font-weight:bold;font-size:12px;text-align:right'></div>
<div id=fetchev style='width:100%'></div>
<script>postlogs();</script>
<script>demarre();</script>
";
$tpl=new template_users("{events}",$html);
$tpl->nogbPopup=1;
$tpl->_BuildPopUp($html,"{events}");
echo $tpl->web_page;
}
function reloadfetchmail(){
$sock=new sockets();
$sock->getFrameWork('cmd.php?restart-fetchmail=yes');
$tpl=new templates();
echo $tpl->javascript_parse_text("{success}");
}