blob: 0fdec8f95b6f4bb0b6d30cd14288605de7e5062d [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001$(document).ready(function() {
2 $('#syncjobLogModal').on('show.bs.modal', function(e) {
3 var syncjob_id = $(e.relatedTarget).data('syncjob-id');
4 $.ajax({
5 url: '/inc/ajax/syncjob_logs.php',
6 data: { id: syncjob_id },
7 dataType: 'text',
8 success: function(data){
9 $(e.currentTarget).find('#logText').text(data);
10 },
11 error: function(xhr, status, error) {
12 $(e.currentTarget).find('#logText').text(xhr.responseText);
13 }
14 });
15 });
16 $(".arrow-toggle").on('click', function(e) { e.preventDefault(); $(this).find('.arrow').toggleClass("animation"); });
17 $("#pushover_delete").click(function() { return confirm(lang.delete_ays); });
18});
19jQuery(function($){
20 // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
21 var entityMap = {
22 '&': '&',
23 '<': '&lt;',
24 '>': '&gt;',
25 '"': '&quot;',
26 "'": '&#39;',
27 '/': '&#x2F;',
28 '`': '&#x60;',
29 '=': '&#x3D;'
30 };
31 function escapeHtml(string) {
32 return String(string).replace(/[&<>"'`=\/]/g, function (s) {
33 return entityMap[s];
34 });
35 }
36 // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
37 function validateEmail(email) {
38 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
39 return re.test(email);
40 }
41 function unix_time_format(tm) {
42 var date = new Date(tm ? tm * 1000 : 0);
43 return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
44 }
45 acl_data = JSON.parse(acl);
46 var last_login = $('.last_login_date').data('time');
47 $('.last_login_date').text(unix_time_format(last_login));
48
49 function draw_tla_table() {
50 ft_tla_table = FooTable.init('#tla_table', {
51 "columns": [
52 {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
53 {"sorted": true,"name":"address","title":lang.alias},
54 {"name":"validity","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});},"title":lang.alias_valid_until,"style":{"width":"170px"}},
55 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
56 ],
57 "empty": lang.empty,
58 "rows": $.ajax({
59 dataType: 'json',
60 url: '/api/v1/get/time_limited_aliases',
61 jsonp: false,
62 error: function () {
63 console.log('Cannot draw tla table');
64 },
65 success: function (data) {
66 $.each(data, function (i, item) {
67 if (acl_data.spam_alias === 1) {
68 item.action = '<div class="btn-group">' +
69 '<a href="#" data-action="delete_selected" data-id="single-tla" data-api-url="delete/time_limited_alias" data-item="' + encodeURIComponent(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
70 '</div>';
71 item.chkbox = '<input type="checkbox" data-id="tla" name="multi_select" value="' + encodeURIComponent(item.address) + '" />';
72 item.address = escapeHtml(item.address);
73 }
74 else {
75 item.chkbox = '<input type="checkbox" disabled />';
76 item.action = '<span>-</span>';
77 }
78 });
79 }
80 }),
81 "paging": {
82 "enabled": true,
83 "limit": 5,
84 "size": pagination_size
85 },
86 "state": {"enabled": true},
87 "sorting": {
88 "enabled": true
89 },
90 "toggleSelector": "table tbody span.footable-toggle"
91 });
92 }
93 function draw_sync_job_table() {
94 ft_syncjob_table = FooTable.init('#sync_job_table', {
95 "columns": [
96 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
97 {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
98 {"name":"server_w_port","title":"Server"},
99 {"name":"enc1","title":lang.encryption,"breakpoints":"xs sm"},
100 {"name":"user1","title":lang.username},
101 {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
102 {"name":"mins_interval","title":lang.interval + " (min)","breakpoints":"all"},
103 {"name":"last_run","title":lang.last_run,"breakpoints":"all"},
104 {"name":"log","title":"Log"},
105 {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
106 {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
107 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
108 ],
109 "empty": lang.empty,
110 "rows": $.ajax({
111 dataType: 'json',
112 url: '/api/v1/get/syncjobs/' + encodeURIComponent(mailcow_cc_username) + '/no_log',
113 jsonp: false,
114 error: function () {
115 console.log('Cannot draw sync job table');
116 },
117 success: function (data) {
118 $.each(data, function (i, item) {
119 item.user1 = escapeHtml(item.user1);
120 item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + item.id + '">Open logs</a>'
121 if (!item.exclude > 0) {
122 item.exclude = '-';
123 } else {
124 item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
125 }
126 item.server_w_port = escapeHtml(item.user1 + '@' + item.host1 + ':' + item.port1);
127 if (acl_data.syncjobs === 1) {
128 item.action = '<div class="btn-group">' +
129 '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
130 '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
131 '</div>';
132 item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
133 }
134 else {
135 item.action = '<span>-</span>';
136 item.chkbox = '<input type="checkbox" disabled />';
137 }
138 if (item.is_running == 1) {
139 item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
140 } else {
141 item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
142 }
143 if (!item.last_run > 0) {
144 item.last_run = lang.waiting;
145 }
146 });
147 }
148 }),
149 "paging": {
150 "enabled": true,
151 "limit": 5,
152 "size": pagination_size
153 },
154 "state": {"enabled": true},
155 "sorting": {
156 "enabled": true
157 },
158 "toggleSelector": "table tbody span.footable-toggle"
159 });
160 }
161 function draw_app_passwd_table() {
162 ft_apppasswd_table = FooTable.init('#app_passwd_table', {
163 "columns": [
164 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
165 {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
166 {"name":"name","title":lang.app_name},
167 {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
168 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
169 ],
170 "empty": lang.empty,
171 "rows": $.ajax({
172 dataType: 'json',
173 url: '/api/v1/get/app-passwd/all',
174 jsonp: false,
175 error: function () {
176 console.log('Cannot draw app passwd table');
177 },
178 success: function (data) {
179 $.each(data, function (i, item) {
180 if (acl_data.app_passwds === 1) {
181 item.action = '<div class="btn-group">' +
182 '<a href="/edit/app-passwd/' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
183 '<a href="#" data-action="delete_selected" data-id="single-apppasswd" data-api-url="delete/app-passwd" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
184 '</div>';
185 item.chkbox = '<input type="checkbox" data-id="apppasswd" name="multi_select" value="' + item.id + '" />';
186 }
187 else {
188 item.action = '<span>-</span>';
189 item.chkbox = '<input type="checkbox" disabled />';
190 }
191 });
192 }
193 }),
194 "paging": {
195 "enabled": true,
196 "limit": 5,
197 "size": pagination_size
198 },
199 "state": {"enabled": true},
200 "sorting": {
201 "enabled": true
202 },
203 "toggleSelector": "table tbody span.footable-toggle"
204 });
205 }
206 function draw_wl_policy_mailbox_table() {
207 ft_wl_policy_mailbox_table = FooTable.init('#wl_policy_mailbox_table', {
208 "columns": [
209 {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
210 {"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false},
211 {"sorted": true,"name":"value","title":lang.spamfilter_table_rule},
212 {"name":"object","title":"Scope"}
213 ],
214 "empty": lang.empty,
215 "rows": $.ajax({
216 dataType: 'json',
217 url: '/api/v1/get/policy_wl_mailbox',
218 jsonp: false,
219 error: function () {
220 console.log('Cannot draw mailbox policy wl table');
221 },
222 success: function (data) {
223 $.each(data, function (i, item) {
224 if (validateEmail(item.object)) {
225 item.chkbox = '<input type="checkbox" data-id="policy_wl_mailbox" name="multi_select" value="' + item.prefid + '" />';
226 }
227 else {
228 item.chkbox = '<input type="checkbox" disabled title="' + lang.spamfilter_table_domain_policy + '" />';
229 }
230 if (acl_data.spam_policy === 0) {
231 item.chkbox = '<input type="checkbox" disabled />';
232 }
233 });
234 }
235 }),
236 "state": {"enabled": true},
237 "paging": {
238 "enabled": true,
239 "limit": 5,
240 "size": pagination_size
241 },
242 "sorting": {
243 "enabled": true
244 }
245 });
246 }
247 function draw_bl_policy_mailbox_table() {
248 ft_bl_policy_mailbox_table = FooTable.init('#bl_policy_mailbox_table', {
249 "columns": [
250 {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
251 {"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false},
252 {"sorted": true,"name":"value","title":lang.spamfilter_table_rule},
253 {"name":"object","title":"Scope"}
254 ],
255 "empty": lang.empty,
256 "rows": $.ajax({
257 dataType: 'json',
258 url: '/api/v1/get/policy_bl_mailbox',
259 jsonp: false,
260 error: function () {
261 console.log('Cannot draw mailbox policy bl table');
262 },
263 success: function (data) {
264 $.each(data, function (i, item) {
265 if (validateEmail(item.object)) {
266 item.chkbox = '<input type="checkbox" data-id="policy_bl_mailbox" name="multi_select" value="' + item.prefid + '" />';
267 }
268 else {
269 item.chkbox = '<input type="checkbox" disabled tooltip="' + lang.spamfilter_table_domain_policy + '" />';
270 }
271 if (acl_data.spam_policy === 0) {
272 item.chkbox = '<input type="checkbox" disabled />';
273 }
274 });
275 }
276 }),
277 "paging": {
278 "enabled": true,
279 "limit": 5,
280 "size": pagination_size
281 },
282 "state": {"enabled": true},
283 "sorting": {
284 "enabled": true
285 }
286 });
287 }
288
289 $('body').on('click', 'span.footable-toggle', function () {
290 event.stopPropagation();
291 })
292
293 draw_sync_job_table();
294 draw_app_passwd_table();
295 draw_tla_table();
296 draw_wl_policy_mailbox_table();
297 draw_bl_policy_mailbox_table();
298
299 // FIDO2 friendly name modal
300 $('#fido2ChangeFn').on('show.bs.modal', function (e) {
301 rename_link = $(e.relatedTarget)
302 if (rename_link != null) {
303 $('#fido2_cid').val(rename_link.data('cid'));
304 $('#fido2_subject_desc').text(Base64.decode(rename_link.data('subject')));
305 }
306 })
307
308 // Sieve data modal
309 $('#userFilterModal').on('show.bs.modal', function(e) {
310 $('#user_sieve_filter').text(lang.loading);
311 $.ajax({
312 dataType: 'json',
313 url: '/api/v1/get/active-user-sieve/' + encodeURIComponent(mailcow_cc_username),
314 jsonp: false,
315 error: function () {
316 console.log('Cannot get active sieve script');
317 },
318 complete: function (data) {
319 if (data.responseText == '{}') {
320 $('#user_sieve_filter').text(lang.no_active_filter);
321 } else {
322 $('#user_sieve_filter').text(JSON.parse(data.responseText));
323 }
324 }
325 })
326 });
327 $('#userFilterModal').on('hidden.bs.modal', function () {
328 $('#user_sieve_filter').text(lang.loading);
329 });
330});