blob: eac7b21a056f4cd085dd09b8ce81e9dd8947e436 [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"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020079 {"name":"tfa_active","title":"TFA", "filterable": false,"style":{"maxWidth":"80px","width":"80px"},"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
80 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010081 {"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"}},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200134 {"name":"tfa_active","title":"TFA", "filterable": false,"style":{"maxWidth":"80px","width":"80px"},"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
135 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100136 {"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"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200163 {"name":"keep_spam","title":lang.spamfilter, "type": "text","style":{"maxWidth":"80px","width":"80px"},"formatter": function(value){return 'yes'==value?'<i class="bi bi-x-lg"></i>':'no'==value&&'<i class="bi bi-check-lg"></i>';}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100164 {"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"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200190 {"name":"in_use_by","title":lang.in_use_by,"style":{"min-width":"200px","width":"200px"}, "type": "text","breakpoints":"xs sm"},
191 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
192 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100193 ],
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() {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200212 ft_transportstable = FooTable.init('#transportstable', {
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100213 "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"}},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200216 {"name":"destination","type":"text","title":lang.destination,"style":{"min-width":"300px","width":"300px"}},
217 {"name":"nexthop","type":"text","title":lang.nexthop,"style":{"min-width":"200px","width":"200px"}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100218 {"name":"username","title":lang.username,"breakpoints":"xs sm"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200219 {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
220 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100221 ],
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},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200236 "toggleSelector": "table tbody span.footable-toggle",
237 "on": {
238 "ready.ft.table": function(e, ft){
239 $('.mx-info').tooltip();
240 }
241 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100242 });
243 }
244 function draw_queue() {
245 ft_queuetable = FooTable.init('#queuetable', {
246 "columns": [
247 {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
248 {"name":"queue_id","type":"text","title":"QID","style":{"width":"50px"}},
249 {"name":"queue_name","type":"text","title":"Queue","style":{"width":"120px"}},
250 {"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"}},
251 {"name":"message_size","style":{"whiteSpace":"nowrap"},"title":lang.message_size,"formatter": function(value){
252 return humanFileSize(value);
253 }},
254 {"name":"sender","title":lang.sender, "type": "text","breakpoints":"xs sm"},
255 {"name":"recipients","title":lang.recipients, "type": "text","style":{"word-break":"break-all","min-width":"300px"},"breakpoints":"xs sm md"},
256 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"220px","width":"220px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
257 ],
258 "rows": $.ajax({
259 dataType: 'json',
260 url: '/api/v1/get/mailq/all',
261 jsonp: false,
262 error: function () {
263 console.log('Cannot draw forwarding hosts table');
264 },
265 success: function (data) {
266 return process_table_data(data, 'queuetable');
267 }
268 }),
269 "empty": lang.empty,
270 "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
271 "sorting": {"enabled": true},
272 "toggleSelector": "table tbody span.footable-toggle",
273 "on": {
274 "ready.ft.table": function(e, ft){
275 table_admin_ready(ft, 'queuetable');
276 }
277 }
278 });
279 }
280
281 function process_table_data(data, table) {
282 if (table == 'relayhoststable') {
283 $.each(data, function (i, item) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200284 item.action = '<div class="btn-group footable-actions">' +
285 '<a href="#" data-toggle="modal" data-target="#testTransportModal" data-transport-id="' + encodeURI(item.id) + '" data-transport-type="sender-dependent" class="btn btn-xs btn-xs-third btn-default"><i class="bi bi-caret-right-fill"></i> Test</a>' +
286 '<a href="/edit/relayhost/' + encodeURI(item.id) + '" class="btn btn-xs btn-xs-third btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
287 '<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-xs-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100288 '</div>';
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200289 if (item.used_by_mailboxes == '') { item.in_use_by = item.used_by_domains; }
290 else if (item.used_by_domains == '') { item.in_use_by = item.used_by_mailboxes; }
291 else { item.in_use_by = item.used_by_mailboxes + '<hr style="margin:5px 0px 5px 0px;">' + item.used_by_domains; }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100292 item.chkbox = '<input type="checkbox" data-id="rlyhosts" name="multi_select" value="' + item.id + '" />';
293 });
294 } else if (table == 'transportstable') {
295 $.each(data, function (i, item) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200296 if (item.is_mx_based) {
297 item.destination = '<i class="bi bi-info-circle-fill text-info mx-info" data-toggle="tooltip" title="' + lang.is_mx_based + '"></i> <code>' + item.destination + '</code>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100298 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200299 if (item.username) {
300 item.username = '<i style="color:#' + intToRGB(hashCode(item.nexthop)) + ';" class="bi bi-square-fill"></i> ' + item.username;
301 }
302 item.action = '<div class="btn-group footable-actions">' +
303 '<a href="#" data-toggle="modal" data-target="#testTransportModal" data-transport-id="' + encodeURI(item.id) + '" data-transport-type="transport-map" class="btn btn-xs btn-xs-third btn-default"><i class="bi bi-caret-right-fill"></i> Test</a>' +
304 '<a href="/edit/transport/' + encodeURI(item.id) + '" class="btn btn-xs btn-xs-third btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
305 '<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-xs-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100306 '</div>';
307 item.chkbox = '<input type="checkbox" data-id="transports" name="multi_select" value="' + item.id + '" />';
308 });
309 } else if (table == 'queuetable') {
310 $.each(data, function (i, item) {
311 item.chkbox = '<input type="checkbox" data-id="mailqitems" name="multi_select" value="' + item.queue_id + '" />';
312 rcpts = $.map(item.recipients, function(i) {
313 return escapeHtml(i);
314 });
315 item.recipients = rcpts.join('<hr style="margin:1px!important">');
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200316 item.action = '<div class="btn-group footable-actions">' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100317 '<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>' +
318 '</div>';
319 });
320 } else if (table == 'forwardinghoststable') {
321 $.each(data, function (i, item) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200322 item.action = '<div class="btn-group footable-actions">' +
323 '<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"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100324 '</div>';
325 item.chkbox = '<input type="checkbox" data-id="fwdhosts" name="multi_select" value="' + item.host + '" />';
326 });
327 } else if (table == 'oauth2clientstable') {
328 $.each(data, function (i, item) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200329 item.action = '<div class="btn-group footable-actions">' +
330 '<a href="/edit.php?oauth2client=' + encodeURI(item.id) + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
331 '<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-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100332 '</div>';
333 item.scope = "profile";
334 item.grant_types = 'refresh_token password authorization_code';
335 item.chkbox = '<input type="checkbox" data-id="oauth2_clients" name="multi_select" value="' + item.id + '" />';
336 });
337 } else if (table == 'domainadminstable') {
338 $.each(data, function (i, item) {
339 item.selected_domains = escapeHtml(item.selected_domains);
340 item.selected_domains = item.selected_domains.toString().replace(/,/g, "<br>");
341 item.chkbox = '<input type="checkbox" data-id="domain_admins" name="multi_select" value="' + item.username + '" />';
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200342 item.action = '<div class="btn-group footable-actions">' +
343 '<a href="/edit/domainadmin/' + encodeURI(item.username) + '" class="btn btn-xs btn-xs-third btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
344 '<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-xs-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
345 '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-xs-third btn-success"><i class="bi bi-person-fill"></i> Login</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100346 '</div>';
347 });
348 } else if (table == 'adminstable') {
349 $.each(data, function (i, item) {
350 if (admin_username.toLowerCase() == item.username.toLowerCase()) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200351 item.usr = '<i class="bi bi-person-check"></i> ' + item.username;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100352 } else {
353 item.usr = item.username;
354 }
355 item.chkbox = '<input type="checkbox" data-id="admins" name="multi_select" value="' + item.username + '" />';
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200356 item.action = '<div class="btn-group footable-actions">' +
357 '<a href="/edit/admin/' + encodeURI(item.username) + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
358 '<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-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100359 '</div>';
360 });
361 }
362 return data
363 };
364 // Initial table drawings
365 draw_domain_admins();
366 draw_admins();
367 draw_fwd_hosts();
368 draw_relayhosts();
369 draw_oauth2_clients();
370 draw_transport_maps();
371 draw_queue();
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200372
373 $('body').on('click', 'span.footable-toggle', function () {
374 event.stopPropagation();
375 })
376
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100377 // API IP check toggle
378 $("#skip_ip_check_ro").click(function( event ) {
379 $("#skip_ip_check_ro").not(this).prop('checked', false);
380 if ($("#skip_ip_check_ro:checked").length > 0) {
381 $('#allow_from_ro').prop('disabled', true);
382 }
383 else {
384 $("#allow_from_ro").removeAttr('disabled');
385 }
386 });
387 $("#skip_ip_check_rw").click(function( event ) {
388 $("#skip_ip_check_rw").not(this).prop('checked', false);
389 if ($("#skip_ip_check_rw:checked").length > 0) {
390 $('#allow_from_rw').prop('disabled', true);
391 }
392 else {
393 $("#allow_from_rw").removeAttr('disabled');
394 }
395 });
396 // Relayhost
397 $('#testRelayhostModal').on('show.bs.modal', function (e) {
398 $('#test_relayhost_result').text("-");
399 button = $(e.relatedTarget)
400 if (button != null) {
401 $('#relayhost_id').val(button.data('relayhost-id'));
402 }
403 })
404 $('#test_relayhost').on('click', function (e) {
405 e.preventDefault();
406 prev = $('#test_relayhost').text();
407 $(this).prop("disabled",true);
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200408 $(this).html('<i class="bi bi-arrow-repeat icon-spin"></i> ');
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100409 $.ajax({
410 type: 'GET',
411 url: 'inc/ajax/relay_check.php',
412 dataType: 'text',
413 data: $('#test_relayhost_form').serialize(),
414 complete: function (data) {
415 $('#test_relayhost_result').html(data.responseText);
416 $('#test_relayhost').prop("disabled",false);
417 $('#test_relayhost').text(prev);
418 }
419 });
420 })
421 // Transport
422 $('#testTransportModal').on('show.bs.modal', function (e) {
423 $('#test_transport_result').text("-");
424 button = $(e.relatedTarget)
425 if (button != null) {
426 $('#transport_id').val(button.data('transport-id'));
427 $('#transport_type').val(button.data('transport-type'));
428 }
429 })
430 // Queue item
431 $('#showQueuedMsg').on('show.bs.modal', function (e) {
432 $('#queue_msg_content').text(lang.loading);
433 button = $(e.relatedTarget)
434 if (button != null) {
435 $('#queue_id').text(button.data('queue-id'));
436 }
437 $.ajax({
438 type: 'GET',
439 url: '/api/v1/get/postcat/' + button.data('queue-id'),
440 dataType: 'text',
441 complete: function (data) {
442 $('#queue_msg_content').text(data.responseText);
443 }
444 });
445 })
446 $('#test_transport').on('click', function (e) {
447 e.preventDefault();
448 prev = $('#test_transport').text();
449 $(this).prop("disabled",true);
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200450 $(this).html('<i class="bi bi-arrow-repeat icon-spin"></i> ');
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100451 $.ajax({
452 type: 'GET',
453 url: 'inc/ajax/transport_check.php',
454 dataType: 'text',
455 data: $('#test_transport_form').serialize(),
456 complete: function (data) {
457 $('#test_transport_result').html(data.responseText);
458 $('#test_transport').prop("disabled",false);
459 $('#test_transport').text(prev);
460 }
461 });
462 })
463 // DKIM private key modal
464 $('#showDKIMprivKey').on('show.bs.modal', function (e) {
465 $('#priv_key_pre').text("-");
466 p_related = $(e.relatedTarget)
467 if (p_related != null) {
468 var decoded_key = Base64.decode((p_related.data('priv-key')));
469 $('#priv_key_pre').text(decoded_key);
470 }
471 })
472 // FIDO2 friendly name modal
473 $('#fido2ChangeFn').on('show.bs.modal', function (e) {
474 rename_link = $(e.relatedTarget)
475 if (rename_link != null) {
476 $('#fido2_cid').val(rename_link.data('cid'));
477 $('#fido2_subject_desc').text(Base64.decode(rename_link.data('subject')));
478 }
479 })
480 // App links
481 function add_table_row(table_id, type) {
482 var row = $('<tr />');
483 if (type == "app_link") {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200484 cols = '<td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="app" required></td>';
485 cols += '<td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="href" required></td>';
486 cols += '<td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-default" type="button">' + lang.remove_row + '</a></td>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100487 } else if (type == "f2b_regex") {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200488 cols = '<td><input style="text-align:center" class="input-sm input-xs-lg form-control" data-id="f2b_regex" type="text" value="+" disabled></td>';
489 cols += '<td><input class="input-sm input-xs-lg form-control regex-input" data-id="f2b_regex" type="text" name="regex" required></td>';
490 cols += '<td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-default" type="button">' + lang.remove_row + '</a></td>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100491 }
492 row.append(cols);
493 table_id.append(row);
494 }
495 $('#app_link_table').on('click', 'tr a', function (e) {
496 e.preventDefault();
497 $(this).parents('tr').remove();
498 });
499 $('#f2b_regex_table').on('click', 'tr a', function (e) {
500 e.preventDefault();
501 $(this).parents('tr').remove();
502 });
503 $('#add_app_link_row').click(function() {
504 add_table_row($('#app_link_table'), "app_link");
505 });
506 $('#add_f2b_regex_row').click(function() {
507 add_table_row($('#f2b_regex_table'), "f2b_regex");
508 });
509});
510