blob: bdb2eaa90229e84ad0d8a6eb62432950e9bad466 [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}};
3jQuery(function($){
4 // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
5 var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};
6 function jq(myid) {return "#" + myid.replace( /(:|\.|\[|\]|,|=|@)/g, "\\$1" );}
7 function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
8 function validateRegex(e){var t=e.split("/"),n=e,r="";t.length>1&&(n=t[1],r=t[2]);try{return new RegExp(n,r),!0}catch(e){return!1}}
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]}
10 function hashCode(t){for(var n=0,r=0;r<t.length;r++)n=t.charCodeAt(r)+((n<<5)-n);return n}
11 function intToRGB(t){var n=(16777215&t).toString(16).toUpperCase();return"00000".substring(0,6-n.length)+n}
12 $("#dkim_missing_keys").on('click', function(e) {
13 e.preventDefault();
14 var domains = [];
15 $('.dkim_missing').each(function() {
16 domains.push($(this).val());
17 });
18 $('#dkim_add_domains').val(domains);
19 });
20 $(".arrow-toggle").on('click', function(e) { e.preventDefault(); $(this).find('.arrow').toggleClass("animation"); });
21 $("#mass_exclude").change(function(){ $("#mass_include").selectpicker('deselectAll'); });
22 $("#mass_include").change(function(){ $("#mass_exclude").selectpicker('deselectAll'); });
23 $("#mass_disarm").click(function() { $("#mass_send").attr("disabled", !this.checked); });
24 $(".admin-ays-dialog").click(function() { return confirm(lang.ays); });
25 $(".validate_rspamd_regex").click(function( event ) {
26 event.preventDefault();
27 var regex_map_id = $(this).data('regex-map');
28 var regex_data = $(jq(regex_map_id)).val().split(/\r?\n/);
29 var regex_valid = true;
30 for(var i = 0;i < regex_data.length;i++){
31 if(regex_data[i].startsWith('#') || !regex_data[i]){
32 continue;
33 }
34 if(!validateRegex(regex_data[i])) {
35 mailcow_alert_box('Cannot build regex from line ' + (i+1), 'danger');
36 var regex_valid = false;
37 break;
38 }
39 if(!regex_data[i].startsWith('/') || !/\/[ims]?$/.test(regex_data[i])){
40 mailcow_alert_box('Line ' + (i+1) + ' is invalid', 'danger');
41 var regex_valid = false;
42 break;
43 }
44 }
45 if (regex_valid) {
46 mailcow_alert_box('Regex OK', 'success');
47 $('button[data-id="' + regex_map_id + '"]').attr({"disabled": false});
48 }
49 });
50 $('.textarea-code').on('keyup', function() {
51 $('.submit_rspamd_regex').attr({"disabled": true});
52 });
53 $("#show_rspamd_global_filters").click(function() {
54 $.get("inc/ajax/show_rspamd_global_filters.php");
55 $("#confirm_show_rspamd_global_filters").hide();
56 $("#rspamd_global_filters").removeClass("hidden");
57 });
58 $("#super_delete").click(function() { return confirm(lang.queue_ays); });
59 $(".refresh_table").on('click', function(e) {
60 e.preventDefault();
61 var table_name = $(this).data('table');
62 $('#' + table_name).find("tr.footable-empty").remove();
63 draw_table = $(this).data('draw');
64 eval(draw_table + '()');
65 });
66 function table_admin_ready(ft, name) {
67 heading = ft.$el.parents('.panel').find('.panel-heading')
68 var ft_paging = ft.use(FooTable.Paging)
69 $(heading).children('.table-lines').text(function(){
70 return ft_paging.totalRows;
71 })
72 }
73 function draw_domain_admins() {
74 ft_domainadmins = FooTable.init('#domainadminstable', {
75 "columns": [
76 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
77 {"sorted": true,"name":"username","title":lang.username,"style":{"width":"250px"}},
78 {"name":"selected_domains","title":lang.admin_domains,"breakpoints":"xs sm"},
79 {"name":"tfa_active","title":"TFA", "filterable": false,"style":{"maxWidth":"80px","width":"80px"},"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
80 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
81 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
82 ],
83 "rows": $.ajax({
84 dataType: 'json',
85 url: '/api/v1/get/domain-admin/all',
86 jsonp: false,
87 error: function () {
88 console.log('Cannot draw domain admin table');
89 },
90 success: function (data) {
91 return process_table_data(data, 'domainadminstable');
92 }
93 }),
94 "empty": lang.empty,
95 "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
96 "state": {"enabled": true},
97 "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
98 "sorting": {"enabled": true},
99 "toggleSelector": "table tbody span.footable-toggle"
100 });
101 }
102 function draw_oauth2_clients() {
103 ft_oauth2clientstable = FooTable.init('#oauth2clientstable', {
104 "columns": [
105 {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
106 {"name":"id","type":"text","title":"ID","style":{"width":"50px"}},
107 {"name":"client_id","type":"text","title":lang.oauth2_client_id,"style":{"width":"200px"}},
108 {"name":"client_secret","title":lang.oauth2_client_secret,"breakpoints":"xs sm md","style":{"width":"200px"}},
109 {"name":"redirect_uri","title":lang.oauth2_redirect_uri, "type": "text"},
110 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
111 ],
112 "rows": $.ajax({
113 dataType: 'json',
114 url: '/api/v1/get/oauth2-client/all',
115 jsonp: false,
116 error: function () {
117 console.log('Cannot draw oauth2 clients table');
118 },
119 success: function (data) {
120 return process_table_data(data, 'oauth2clientstable');
121 }
122 }),
123 "empty": lang.empty,
124 "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
125 "sorting": {"enabled": true},
126 "toggleSelector": "table tbody span.footable-toggle"
127 });
128 }
129 function draw_admins() {
130 ft_admins = FooTable.init('#adminstable', {
131 "columns": [
132 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
133 {"sorted": true,"name":"usr","title":lang.username,"style":{"width":"250px"}},
134 {"name":"tfa_active","title":"TFA", "filterable": false,"style":{"maxWidth":"80px","width":"80px"},"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
135 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
136 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
137 ],
138 "rows": $.ajax({
139 dataType: 'json',
140 url: '/api/v1/get/admin/all',
141 jsonp: false,
142 error: function () {
143 console.log('Cannot draw admin table');
144 },
145 success: function (data) {
146 return process_table_data(data, 'adminstable');
147 }
148 }),
149 "empty": lang.empty,
150 "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
151 "filtering": {"enabled": false},
152 "state": {"enabled": true},
153 "sorting": {"enabled": true},
154 "toggleSelector": "table tbody span.footable-toggle"
155 });
156 }
157 function draw_fwd_hosts() {
158 ft_forwardinghoststable = FooTable.init('#forwardinghoststable', {
159 "columns": [
160 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
161 {"name":"host","type":"text","title":lang.host,"style":{"width":"250px"}},
162 {"name":"source","title":lang.source,"breakpoints":"xs sm"},
163 {"name":"keep_spam","title":lang.spamfilter, "type": "text","style":{"maxWidth":"80px","width":"80px"},"formatter": function(value){return 'yes'==value?'&#10005;':'no'==value&&'&#10003;';}},
164 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
165 ],
166 "rows": $.ajax({
167 dataType: 'json',
168 url: '/api/v1/get/fwdhost/all',
169 jsonp: false,
170 error: function () {
171 console.log('Cannot draw forwarding hosts table');
172 },
173 success: function (data) {
174 return process_table_data(data, 'forwardinghoststable');
175 }
176 }),
177 "empty": lang.empty,
178 "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
179 "sorting": {"enabled": true},
180 "toggleSelector": "table tbody span.footable-toggle"
181 });
182 }
183 function draw_relayhosts() {
184 ft_relayhoststable = FooTable.init('#relayhoststable', {
185 "columns": [
186 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
187 {"name":"id","type":"text","title":"ID","style":{"width":"50px"}},
188 {"name":"hostname","type":"text","title":lang.host,"style":{"width":"250px"}},
189 {"name":"username","title":lang.username,"breakpoints":"xs sm"},
190 {"name":"used_by_domains","title":lang.in_use_by,"style":{"width":"110px"}, "type": "text","breakpoints":"xs sm"},
191 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
192 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"220px","width":"220px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
193 ],
194 "rows": $.ajax({
195 dataType: 'json',
196 url: '/api/v1/get/relayhost/all',
197 jsonp: false,
198 error: function () {
199 console.log('Cannot draw forwarding hosts table');
200 },
201 success: function (data) {
202 return process_table_data(data, 'relayhoststable');
203 }
204 }),
205 "empty": lang.empty,
206 "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
207 "sorting": {"enabled": true},
208 "toggleSelector": "table tbody span.footable-toggle"
209 });
210 }
211 function draw_transport_maps() {
212 ft_relayhoststable = FooTable.init('#transportstable', {
213 "columns": [
214 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
215 {"name":"id","type":"text","title":"ID","style":{"width":"50px"}},
216 {"name":"destination","type":"text","title":lang.destination,"style":{"width":"250px"}},
217 {"name":"nexthop","type":"text","title":lang.nexthop,"style":{"width":"250px"}},
218 {"name":"username","title":lang.username,"breakpoints":"xs sm"},
219 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'&#10003;':0==value&&'&#10005;';}},
220 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"220px","width":"220px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
221 ],
222 "rows": $.ajax({
223 dataType: 'json',
224 url: '/api/v1/get/transport/all',
225 jsonp: false,
226 error: function () {
227 console.log('Cannot draw transports table');
228 },
229 success: function (data) {
230 return process_table_data(data, 'transportstable');
231 }
232 }),
233 "empty": lang.empty,
234 "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
235 "sorting": {"enabled": true},
236 "toggleSelector": "table tbody span.footable-toggle"
237 });
238 }
239 function draw_queue() {
240 ft_queuetable = FooTable.init('#queuetable', {
241 "columns": [
242 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
243 {"name":"queue_id","type":"text","title":"QID","style":{"width":"50px"}},
244 {"name":"queue_name","type":"text","title":"Queue","style":{"width":"120px"}},
245 {"name":"arrival_time","sorted": true,"direction": "DESC","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.arrival_time,"style":{"width":"170px"}},
246 {"name":"message_size","style":{"whiteSpace":"nowrap"},"title":lang.message_size,"formatter": function(value){
247 return humanFileSize(value);
248 }},
249 {"name":"sender","title":lang.sender, "type": "text","breakpoints":"xs sm"},
250 {"name":"recipients","title":lang.recipients, "type": "text","style":{"word-break":"break-all","min-width":"300px"},"breakpoints":"xs sm md"},
251 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"220px","width":"220px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
252 ],
253 "rows": $.ajax({
254 dataType: 'json',
255 url: '/api/v1/get/mailq/all',
256 jsonp: false,
257 error: function () {
258 console.log('Cannot draw forwarding hosts table');
259 },
260 success: function (data) {
261 return process_table_data(data, 'queuetable');
262 }
263 }),
264 "empty": lang.empty,
265 "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
266 "sorting": {"enabled": true},
267 "toggleSelector": "table tbody span.footable-toggle",
268 "on": {
269 "ready.ft.table": function(e, ft){
270 table_admin_ready(ft, 'queuetable');
271 }
272 }
273 });
274 }
275
276 function process_table_data(data, table) {
277 if (table == 'relayhoststable') {
278 $.each(data, function (i, item) {
279 item.action = '<div class="btn-group">' +
280 '<a href="#" data-toggle="modal" data-target="#testTransportModal" data-transport-id="' + encodeURI(item.id) + '" data-transport-type="sender-dependent" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-triangle-right"></span> Test</a>' +
281 '<a href="/edit/relayhost/' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
282 '<a href="#" data-action="delete_selected" data-id="single-rlyhost" data-api-url="delete/relayhost" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
283 '</div>';
284 item.chkbox = '<input type="checkbox" data-id="rlyhosts" name="multi_select" value="' + item.id + '" />';
285 });
286 } else if (table == 'transportstable') {
287 $.each(data, function (i, item) {
288 if (item.username) {
289 item.username = '<span style="border-left:3px solid #' + intToRGB(hashCode(item.nexthop)) + ';padding-left:5px;">' + item.username + '</span>';
290 }
291 item.action = '<div class="btn-group">' +
292 '<a href="#" data-toggle="modal" data-target="#testTransportModal" data-transport-id="' + encodeURI(item.id) + '" data-transport-type="transport-map" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-triangle-right"></span> Test</a>' +
293 '<a href="/edit/transport/' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
294 '<a href="#" data-action="delete_selected" data-id="single-transport" data-api-url="delete/transport" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
295 '</div>';
296 item.chkbox = '<input type="checkbox" data-id="transports" name="multi_select" value="' + item.id + '" />';
297 });
298 } else if (table == 'queuetable') {
299 $.each(data, function (i, item) {
300 item.chkbox = '<input type="checkbox" data-id="mailqitems" name="multi_select" value="' + item.queue_id + '" />';
301 rcpts = $.map(item.recipients, function(i) {
302 return escapeHtml(i);
303 });
304 item.recipients = rcpts.join('<hr style="margin:1px!important">');
305 item.action = '<div class="btn-group">' +
306 '<a href="#" data-toggle="modal" data-target="#showQueuedMsg" data-queue-id="' + encodeURI(item.queue_id) + '" class="btn btn-xs btn-default">' + lang.queue_show_message + '</a>' +
307 '</div>';
308 });
309 } else if (table == 'forwardinghoststable') {
310 $.each(data, function (i, item) {
311 item.action = '<div class="btn-group">' +
312 '<a href="#" data-action="delete_selected" data-id="single-fwdhost" data-api-url="delete/fwdhost" data-item="' + encodeURI(item.host) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
313 '</div>';
314 item.chkbox = '<input type="checkbox" data-id="fwdhosts" name="multi_select" value="' + item.host + '" />';
315 });
316 } else if (table == 'oauth2clientstable') {
317 $.each(data, function (i, item) {
318 item.action = '<div class="btn-group">' +
319 '<a href="/edit.php?oauth2client=' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
320 '<a href="#" data-action="delete_selected" data-id="single-oauth2-client" data-api-url="delete/oauth2-client" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
321 '</div>';
322 item.scope = "profile";
323 item.grant_types = 'refresh_token password authorization_code';
324 item.chkbox = '<input type="checkbox" data-id="oauth2_clients" name="multi_select" value="' + item.id + '" />';
325 });
326 } else if (table == 'domainadminstable') {
327 $.each(data, function (i, item) {
328 item.selected_domains = escapeHtml(item.selected_domains);
329 item.selected_domains = item.selected_domains.toString().replace(/,/g, "<br>");
330 item.chkbox = '<input type="checkbox" data-id="domain_admins" name="multi_select" value="' + item.username + '" />';
331 item.action = '<div class="btn-group">' +
332 '<a href="/edit/domainadmin/' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
333 '<a href="#" data-action="delete_selected" data-id="single-domain-admin" data-api-url="delete/domain-admin" data-item="' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
334 '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>' +
335 '</div>';
336 });
337 } else if (table == 'adminstable') {
338 $.each(data, function (i, item) {
339 if (admin_username.toLowerCase() == item.username.toLowerCase()) {
340 item.usr = '→ ' + item.username;
341 } else {
342 item.usr = item.username;
343 }
344 item.chkbox = '<input type="checkbox" data-id="admins" name="multi_select" value="' + item.username + '" />';
345 item.action = '<div class="btn-group">' +
346 '<a href="/edit/admin/' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
347 '<a href="#" data-action="delete_selected" data-id="single-admin" data-api-url="delete/admin" data-item="' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
348 '</div>';
349 });
350 }
351 return data
352 };
353 // Initial table drawings
354 draw_domain_admins();
355 draw_admins();
356 draw_fwd_hosts();
357 draw_relayhosts();
358 draw_oauth2_clients();
359 draw_transport_maps();
360 draw_queue();
361 // API IP check toggle
362 $("#skip_ip_check_ro").click(function( event ) {
363 $("#skip_ip_check_ro").not(this).prop('checked', false);
364 if ($("#skip_ip_check_ro:checked").length > 0) {
365 $('#allow_from_ro').prop('disabled', true);
366 }
367 else {
368 $("#allow_from_ro").removeAttr('disabled');
369 }
370 });
371 $("#skip_ip_check_rw").click(function( event ) {
372 $("#skip_ip_check_rw").not(this).prop('checked', false);
373 if ($("#skip_ip_check_rw:checked").length > 0) {
374 $('#allow_from_rw').prop('disabled', true);
375 }
376 else {
377 $("#allow_from_rw").removeAttr('disabled');
378 }
379 });
380 // Relayhost
381 $('#testRelayhostModal').on('show.bs.modal', function (e) {
382 $('#test_relayhost_result').text("-");
383 button = $(e.relatedTarget)
384 if (button != null) {
385 $('#relayhost_id').val(button.data('relayhost-id'));
386 }
387 })
388 $('#test_relayhost').on('click', function (e) {
389 e.preventDefault();
390 prev = $('#test_relayhost').text();
391 $(this).prop("disabled",true);
392 $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
393 $.ajax({
394 type: 'GET',
395 url: 'inc/ajax/relay_check.php',
396 dataType: 'text',
397 data: $('#test_relayhost_form').serialize(),
398 complete: function (data) {
399 $('#test_relayhost_result').html(data.responseText);
400 $('#test_relayhost').prop("disabled",false);
401 $('#test_relayhost').text(prev);
402 }
403 });
404 })
405 // Transport
406 $('#testTransportModal').on('show.bs.modal', function (e) {
407 $('#test_transport_result').text("-");
408 button = $(e.relatedTarget)
409 if (button != null) {
410 $('#transport_id').val(button.data('transport-id'));
411 $('#transport_type').val(button.data('transport-type'));
412 }
413 })
414 // Queue item
415 $('#showQueuedMsg').on('show.bs.modal', function (e) {
416 $('#queue_msg_content').text(lang.loading);
417 button = $(e.relatedTarget)
418 if (button != null) {
419 $('#queue_id').text(button.data('queue-id'));
420 }
421 $.ajax({
422 type: 'GET',
423 url: '/api/v1/get/postcat/' + button.data('queue-id'),
424 dataType: 'text',
425 complete: function (data) {
426 $('#queue_msg_content').text(data.responseText);
427 }
428 });
429 })
430 $('#test_transport').on('click', function (e) {
431 e.preventDefault();
432 prev = $('#test_transport').text();
433 $(this).prop("disabled",true);
434 $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
435 $.ajax({
436 type: 'GET',
437 url: 'inc/ajax/transport_check.php',
438 dataType: 'text',
439 data: $('#test_transport_form').serialize(),
440 complete: function (data) {
441 $('#test_transport_result').html(data.responseText);
442 $('#test_transport').prop("disabled",false);
443 $('#test_transport').text(prev);
444 }
445 });
446 })
447 // DKIM private key modal
448 $('#showDKIMprivKey').on('show.bs.modal', function (e) {
449 $('#priv_key_pre').text("-");
450 p_related = $(e.relatedTarget)
451 if (p_related != null) {
452 var decoded_key = Base64.decode((p_related.data('priv-key')));
453 $('#priv_key_pre').text(decoded_key);
454 }
455 })
456 // FIDO2 friendly name modal
457 $('#fido2ChangeFn').on('show.bs.modal', function (e) {
458 rename_link = $(e.relatedTarget)
459 if (rename_link != null) {
460 $('#fido2_cid').val(rename_link.data('cid'));
461 $('#fido2_subject_desc').text(Base64.decode(rename_link.data('subject')));
462 }
463 })
464 // App links
465 function add_table_row(table_id, type) {
466 var row = $('<tr />');
467 if (type == "app_link") {
468 cols = '<td><input class="input-sm form-control" data-id="app_links" type="text" name="app" required></td>';
469 cols += '<td><input class="input-sm form-control" data-id="app_links" type="text" name="href" required></td>';
470 cols += '<td><a href="#" role="button" class="btn btn-xs btn-default" type="button">' + lang.remove_row + '</a></td>';
471 } else if (type == "f2b_regex") {
472 cols = '<td><input style="text-align:center" class="input-sm form-control" data-id="f2b_regex" type="text" value="+" disabled></td>';
473 cols += '<td><input class="input-sm form-control regex-input" data-id="f2b_regex" type="text" name="regex" required></td>';
474 cols += '<td><a href="#" role="button" class="btn btn-xs btn-default" type="button">' + lang.remove_row + '</a></td>';
475 }
476 row.append(cols);
477 table_id.append(row);
478 }
479 $('#app_link_table').on('click', 'tr a', function (e) {
480 e.preventDefault();
481 $(this).parents('tr').remove();
482 });
483 $('#f2b_regex_table').on('click', 'tr a', function (e) {
484 e.preventDefault();
485 $(this).parents('tr').remove();
486 });
487 $('#add_app_link_row').click(function() {
488 add_table_row($('#app_link_table'), "app_link");
489 });
490 $('#add_f2b_regex_row').click(function() {
491 add_table_row($('#f2b_regex_table'), "f2b_regex");
492 });
493});
494