blob: 34531b0d3bd4a6cb8f5da9b9c77aac585382d787 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001// Base64 functions
2var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(r){var t,e,o,a,h,n,c,d="",C=0;for(r=Base64._utf8_encode(r);C<r.length;)a=(t=r.charCodeAt(C++))>>2,h=(3&t)<<4|(e=r.charCodeAt(C++))>>4,n=(15&e)<<2|(o=r.charCodeAt(C++))>>6,c=63&o,isNaN(e)?n=c=64:isNaN(o)&&(c=64),d=d+this._keyStr.charAt(a)+this._keyStr.charAt(h)+this._keyStr.charAt(n)+this._keyStr.charAt(c);return d},decode:function(r){var t,e,o,a,h,n,c="",d=0;for(r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");d<r.length;)t=this._keyStr.indexOf(r.charAt(d++))<<2|(a=this._keyStr.indexOf(r.charAt(d++)))>>4,e=(15&a)<<4|(h=this._keyStr.indexOf(r.charAt(d++)))>>2,o=(3&h)<<6|(n=this._keyStr.indexOf(r.charAt(d++))),c+=String.fromCharCode(t),64!=h&&(c+=String.fromCharCode(e)),64!=n&&(c+=String.fromCharCode(o));return c=Base64._utf8_decode(c)},_utf8_encode:function(r){r=r.replace(/\r\n/g,"\n");for(var t="",e=0;e<r.length;e++){var o=r.charCodeAt(e);o<128?t+=String.fromCharCode(o):o>127&&o<2048?(t+=String.fromCharCode(o>>6|192),t+=String.fromCharCode(63&o|128)):(t+=String.fromCharCode(o>>12|224),t+=String.fromCharCode(o>>6&63|128),t+=String.fromCharCode(63&o|128))}return t},_utf8_decode:function(r){for(var t="",e=0,o=c1=c2=0;e<r.length;)(o=r.charCodeAt(e))<128?(t+=String.fromCharCode(o),e++):o>191&&o<224?(c2=r.charCodeAt(e+1),t+=String.fromCharCode((31&o)<<6|63&c2),e+=2):(c2=r.charCodeAt(e+1),c3=r.charCodeAt(e+2),t+=String.fromCharCode((15&o)<<12|(63&c2)<<6|63&c3),e+=3);return t}};
3
4jQuery(function($){
5 acl_data = JSON.parse(acl);
6 // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
7 var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};
8 function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
9 function humanFileSize(i){if(Math.abs(i)<1024)return i+" B";var B=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],e=-1;do{i/=1024,++e}while(Math.abs(i)>=1024&&e<B.length-1);return i.toFixed(1)+" "+B[e]}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010010 $(".refresh_table").on('click', function(e) {
11 e.preventDefault();
12 var table_name = $(this).data('table');
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010013 $('#' + table_name).DataTable().ajax.reload();
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010014 });
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010015 function draw_quarantine_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010016 $('#quarantinetable').DataTable({
17 processing: true,
18 serverSide: false,
19 language: lang_datatables,
20 ajax: {
21 type: "GET",
22 url: "/api/v1/get/quarantine/all",
23 dataSrc: function(data){
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010024 $.each(data, function (i, item) {
25 if (item.subject === null) {
26 item.subject = '';
27 } else {
28 item.subject = escapeHtml(item.subject);
29 }
30 if (item.score === null) {
31 item.score = '-';
32 }
33 if (item.virus_flag > 0) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010034 item.virus = '<span class="badge fs-6 bg-danger">' + lang.high_danger + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010035 } else {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010036 item.virus = '<span class="badge fs-6 bg-secondary">' + lang.neutral_danger + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010037 }
38 if (item.action === "reject") {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010039 item.rspamdaction = '<span class="badge fs-6 bg-danger">' + lang.rejected + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010040 } else if (item.action === "add header") {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010041 item.rspamdaction = '<span class="badge fs-6 bg-warning">' + lang.junk_folder + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010042 } else if (item.action === "rewrite subject") {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010043 item.rspamdaction = '<span class="badge fs-6 bg-warning">' + lang.rewrite_subject + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010044 }
45 if(item.notified > 0) {
46 item.notified = '&#10004;';
47 } else {
48 item.notified = '&#10006;';
49 }
50 if (acl_data.login_as === 1) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010051 item.action = '<div class="btn-group">' +
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020052 '<a href="#" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-xs-half btn-info show_qid_info"><i class="bi bi-box-arrow-up-right"></i> ' + lang.show_item + '</a>' +
53 '<a href="#" data-action="delete_selected" data-id="del-single-qitem" data-api-url="delete/qitem" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010054 '</div>';
55 }
56 else {
57 item.action = '<div class="btn-group">' +
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020058 '<a href="#" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-info show_qid_info"><i class="bi bi-file-earmark-text"></i> ' + lang.show_item + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010059 '</div>';
60 }
61 item.chkbox = '<input type="checkbox" data-id="qitems" name="multi_select" value="' + item.id + '" />';
62 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010063
64 return data;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010065 }
66 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010067 columns: [
68 {
69 // placeholder, so checkbox will not block child row toggle
70 title: '',
71 data: null,
72 searchable: false,
73 orderable: false,
74 defaultContent: ''
75 },
76 {
77 title: '',
78 data: 'chkbox',
79 searchable: false,
80 orderable: false,
81 defaultContent: ''
82 },
83 {
84 title: 'ID',
85 data: 'id',
86 defaultContent: ''
87 },
88 {
89 title: lang.qid,
90 data: 'qid',
91 defaultContent: ''
92 },
93 {
94 title: lang.sender,
95 data: 'sender',
96 defaultContent: ''
97 },
98 {
99 title: lang.subj,
100 data: 'subject',
101 defaultContent: ''
102 },
103 {
104 title: lang.rspamd_result,
105 data: 'rspamdaction',
106 defaultContent: ''
107 },
108 {
109 title: lang.rcpt,
110 data: 'rcpt',
111 defaultContent: ''
112 },
113 {
114 title: lang.danger,
115 data: 'virus',
116 defaultContent: ''
117 },
118 {
119 title: lang.spam_score,
120 data: 'score',
121 defaultContent: ''
122 },
123 {
124 title: lang.notified,
125 data: 'notified',
126 defaultContent: ''
127 },
128 {
129 title: lang.received,
130 data: 'created',
131 defaultContent: '',
132 render: function (data,type) {
133 var date = new Date(data ? data * 1000 : 0);
134 return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
135 }
136 },
137 {
138 title: lang.action,
139 data: 'action',
140 className: 'text-md-end dt-sm-head-hidden dt-body-right',
141 defaultContent: ''
142 },
143 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100144 });
145 }
146
147 $('body').on('click', '.show_qid_info', function (e) {
148 e.preventDefault();
149 var qitem = $(this).attr('data-item');
150 var qError = $("#qid_error");
151
152 $('#qidDetailModal').modal('show');
153 qError.hide();
154
155 $.ajax({
156 url: '/inc/ajax/qitem_details.php',
157 data: { id: qitem },
158 dataType: 'json',
159 success: function(data){
160
161 $('[data-id="qitems_single"]').each(function(index) {
162 $(this).attr("data-item", qitem);
163 });
164
165 $("#quick_download_link").attr("onclick", "window.open('/inc/ajax/qitem_details.php?id=" + qitem + "&eml', '_blank')");
166 $("#quick_release_link").attr("onclick", "window.open('/inc/ajax/qitem_details.php?id=" + qitem + "&quick_release', '_blank')");
167 $("#quick_delete_link").attr("onclick", "window.open('/inc/ajax/qitem_details.php?id=" + qitem + "&quick_delete', '_blank')");
168
169 $('#qid_detail_subj').text(data.subject);
170 $('#qid_detail_hfrom').text(data.header_from);
171 $('#qid_detail_efrom').text(data.env_from);
172 $('#qid_detail_score').html('');
173 $('#qid_detail_recipients').html('');
174 $('#qid_detail_symbols').html('');
175 $('#qid_detail_fuzzy').html('');
176 if (typeof data.symbols !== 'undefined') {
177 data.symbols.sort(function (a, b) {
178 if (a.score === 0) return 1
179 if (b.score === 0) return -1
180 if (b.score < 0 && a.score < 0) {
181 return a.score - b.score
182 }
183 if (b.score > 0 && a.score > 0) {
184 return b.score - a.score
185 }
186 return b.score - a.score
187 })
188 $.each(data.symbols, function (index, value) {
189 var highlightClass = ''
190 if (value.score > 0) highlightClass = 'negative'
191 else if (value.score < 0) highlightClass = 'positive'
192 else highlightClass = 'neutral'
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100193 $('#qid_detail_symbols').append('<span data-bs-toggle="tooltip" class="rspamd-symbol ' + highlightClass + '" title="' + (value.options ? value.options.join(', ') : '') + '">' + value.name + ' (<span class="score">' + value.score + '</span>)</span>');
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100194 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100195 $('[data-bs-toggle="tooltip"]').tooltip()
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100196 }
197 if (typeof data.fuzzy_hashes === 'object' && data.fuzzy_hashes !== null && data.fuzzy_hashes.length !== 0) {
198 $.each(data.fuzzy_hashes, function (index, value) {
199 $('#qid_detail_fuzzy').append('<p style="font-family:monospace">' + value + '</p>');
200 });
201 } else {
202 $('#qid_detail_fuzzy').append('-');
203 }
204 if (typeof data.score !== 'undefined' && typeof data.action !== 'undefined') {
205 if (data.action == "add header") {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100206 $('#qid_detail_score').append('<span class="label-rspamd-action badge fs-6 bg-warning"><b>' + data.score + '</b> - ' + lang.junk_folder + '</span>');
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100207 } else if (data.action == "reject") {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100208 $('#qid_detail_score').append('<span class="label-rspamd-action badge fs-6 bg-danger"><b>' + data.score + '</b> - ' + lang.rejected + '</span>');
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100209 } else if (data.action == "rewrite subject") {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100210 $('#qid_detail_score').append('<span class="label-rspamd-action badge fs-6 bg-warning"><b>' + data.score + '</b> - ' + lang.rewrite_subject + '</span>');
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100211 }
212 }
213 if (typeof data.recipients !== 'undefined') {
214 $.each(data.recipients, function(index, value) {
215 var elem = $('<span class="mail-address-item"></span>');
216 elem.text(value.address + ' (' + value.type.toUpperCase() + ')');
217 $('#qid_detail_recipients').append(elem);
218 });
219 }
220 $('#qid_detail_text').text(data.text_plain);
221 $('#qid_detail_text_from_html').text(data.text_html);
222 var qAtts = $("#qid_detail_atts");
223 if (typeof data.attachments !== 'undefined') {
224 qAtts.text('');
225 $.each(data.attachments, function(index, value) {
226 qAtts.append(
227 '<p><a href="/inc/ajax/qitem_details.php?id=' + qitem + '&att=' + index + '" target="_blank">' + value[0] + '</a> (' + value[1] + ')' +
228 ' - <small><a href="' + value[3] + '" target="_blank">' + lang.check_hash + '</a></small></p>'
229 );
230 });
231 }
232 else {
233 qAtts.text('-');
234 }
235 },
236 error: function(data){
237 if (typeof data.error !== 'undefined') {
238 $('#qid_detail_subj').text('-');
239 $('#qid_detail_hfrom').text('-');
240 $('#qid_detail_efrom').text('-');
241 $('#qid_detail_score').html('-');
242 $('#qid_detail_recipients').html('-');
243 $('#qid_detail_symbols').html('-');
244 $('#qid_detail_fuzzy').html('-');
245 $('#qid_detail_text').text('-');
246 $('#qid_detail_text_from_html').text('-');
247 qError.text("Error loading quarantine item");
248 qError.show();
249 }
250 }
251 });
252 });
253
254 $('body').on('click', 'span.footable-toggle', function () {
255 event.stopPropagation();
256 })
257
258 // Initial table drawings
259 draw_quarantine_table();
260});