-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRTMMail.php
executable file
·221 lines (164 loc) · 5.37 KB
/
RTMMail.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
<?php
include_once('ressources/class.templates.inc');
include_once('ressources/class.ldap.inc');
include_once('ressources/class.users.menus.inc');
include_once('ressources/class.mysql.inc');
include_once('ressources/class.rtmm.tools.inc');
if(isset($_GET["popup-index"])){index();exit;}
if(isset($_GET["showevents"])){showevents();exit;}
if(isset($_GET["SendQuery"])){SendQuery();exit;}
js();
function js(){
$page=CurrentPageName();
$prefix=str_replace(".","_",$page);
$tpl=new templates();
$title=$tpl->_ENGINE_parse_body('{RTMMail}',"RTMMailConfig.php");
$users=new usersMenus();
if(!$users->AsPostfixAdministrator){
if(!$users->AsOrgAdmin){
$error=$tpl->_ENGINE_parse_body("{ERROR_NO_PRIVS}");
echo "alert('$error')";
die();
}
}
$html="
var {$prefix}timerID = null;
var {$prefix}tant=0;
var {$prefix}reste=0;
var stopm='$stop_monitor';
var startm='$start_monitor';
function {$prefix}demarre(){
{$prefix}tant = {$prefix}tant+1;
{$prefix}reste=20-{$prefix}tant;
if(!RTMMailOpen()){return false;}
if ({$prefix}tant < 10 ) {
{$prefix}timerID =setTimeout(\"{$prefix}demarre()\",2000);
} else {
{$prefix}tant = 0;
{$prefix}ChargeLogs();
{$prefix}demarre();
}
}
function {$prefix}Loadpage(){
RTMMail('750','$page?popup-index=yes','$title');
setTimeout(\"{$prefix}STartALL()\",900);
}
function {$prefix}STartALL(){
{$prefix}demarre();
{$prefix}ChargeLogs();
}
var x_{$prefix}ChargeLogs= function (obj) {
var results=obj.responseText;
document.getElementById('RTMMail_events').innerHTML=results;
}
function {$prefix}ChargeLogs(){
var query=document.getElementById('query').value;
if(query.length>0){return;}
var XHR = new XHRConnection();
XHR.appendData('showevents','yes');
XHR.sendAndLoad('$page', 'GET', x_{$prefix}ChargeLogs);
}
function RTMMQuery(e){
if(checkEnter(e)){
RTMMQuerySend();
}
}
var X_RTMMQuerySend= function (obj) {
var results=obj.responseText;
document.getElementById('RTMMail_events').innerHTML=results;
}
function RTMMQuerySend(){
var XHR = new XHRConnection();
var query=document.getElementById('query').value;
XHR.appendData('SendQuery',query);
document.getElementById('RTMMail_events').innerHTML='<center><img src=img/wait_verybig.gif></center>';
XHR.sendAndLoad('$page', 'GET', X_RTMMQuerySend);
}
function RefreshCache(){
LoadAjax('RTMMail_events','$page?showevents=yes&kill-cache=yes');
}
{$prefix}Loadpage();
";
echo $html;
}
function index(){
$html="
<H1>{RTMMail}</H1>
<table style='width:100%' class=table_form>
<tr>
<td valign='top' class=legend>{find}:</td>
<td valign='top'>". Field_text('query',null,'width:100%',null,null,null,false,"RTMMQuery(event);")."</td>
<td valign='top' width=1%>" . imgtootltip('20-refresh.png',"{refresh} cache","RefreshCache()")."</td>
</tr>
</table>
<br>
".RoundedLightWhite("
<div id='RTMMail_events' style='with:100%;height:350px;overflow:auto'><center><img src=img/wait_verybig.gif></center></div>");
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html,"RTMMailConfig.php");
}
function showevents(){
if(!isset($_GET["kill-cache"])){unset($_SESSION["RTTM"]["M"]);}
$users=new usersMenus();
if($users->AsPostfixAdministrator==false){
if($users->AsOrgAdmin){
ShoweventsORG();
}
return;
}
$html=file_get_contents("ressources/logs/last-100-mails.html");
$tpl=new templates();
$html="<table style='width:100%'>$html</table>";
echo $tpl->_ENGINE_parse_body($html);
}
function SendQuery(){
$users=new usersMenus();
if($users->AsPostfixAdministrator==false){
if($users->AsOrgAdmin){
ShoweventsORG();
}
return;
}
$pattern=$_GET["SendQuery"];
$pattern=str_replace('*','%',$pattern);
if(strpos(" $pattern",'%')==0){$pattern=$pattern."%";}
if($_SESSION["RTTM"]["M"][md5($pattern)]<>null){echo $_SESSION["RTTM"]["M"][md5($pattern)];return ;}
$q=new mysql();
$sql="SELECT * FROM smtp_logs WHERE (delivery_user LIKE '$pattern') OR (sender_user LIKE '$pattern') ORDER BY time_stamp DESC limit 0,100";
$results=$q->QUERY_SQL($sql,"artica_events");
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
$count=$count+1;
$tr=$tr.format_line($ligne);
}
$tpl=new templates();
$html=$tpl->_parse_body("<table style='width:99%'>$tr</table>");
$_SESSION["RTTM"]["M"][md5($pattern)]=$html;
echo $html;
}
function ShoweventsORG(){
$ldap=new clladp();
$pattern=$_GET["SendQuery"];
$pattern=str_replace('*','%',$pattern);
if(strpos(" $pattern",'%')==0){$pattern=$pattern."%";}
if($_SESSION["RTTM"]["M"][md5($pattern)]<>null){echo $_SESSION["RTTM"]["M"][md5($pattern)];return ;}
$hash=$ldap->hash_get_domains_ou($_SESSION["ou"]);
if(!is_array($hash)){return null;}
while (list ($num, $ligne) = each ($hash) ){
$sender_domain[]="(sender_domain='$num')";
$sender_domain[]="(delivery_domain='$num')";
}
$or=implode(" OR ",$sender_domain);
$first="((delivery_user LIKE '$pattern') OR (sender_user LIKE '$pattern'))";
$sql="SELECT * FROM smtp_logs WHERE $first AND ($or) ORDER BY time_stamp DESC limit 0,100";
$q=new mysql();
$results=$q->QUERY_SQL($sql,'artica_events');
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
$count=$count+1;
$tr=$tr.format_line($ligne);
}
$tpl=new templates();
$html=$tpl->_parse_body("<table style='width:99%'>$tr</table>");
$_SESSION["RTTM"]["M"][md5($pattern)]=$html;
echo $html;
}
?>