Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | // Base64 functions
|
| 2 | var 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 | jQuery(function($){
|
| 4 | // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
|
| 5 | var entityMap={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};
|
| 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();
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 56 | $("#rspamd_global_filters").removeClass("d-none");
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 57 | });
|
| 58 | $("#super_delete").click(function() { return confirm(lang.queue_ays); });
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 59 |
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 60 | $(".refresh_table").on('click', function(e) {
|
| 61 | e.preventDefault();
|
| 62 | var table_name = $(this).data('table');
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 63 | $('#' + table_name).DataTable().ajax.reload();
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 64 | });
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 65 | function draw_domain_admins() {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 66 | // just recalc width if instance already exists
|
| 67 | if ($.fn.DataTable.isDataTable('#domainadminstable') ) {
|
| 68 | $('#domainadminstable').DataTable().columns.adjust().responsive.recalc();
|
| 69 | return;
|
| 70 | }
|
| 71 |
|
| 72 | $('#domainadminstable').DataTable({
|
| 73 | processing: true,
|
| 74 | serverSide: false,
|
| 75 | language: lang_datatables,
|
| 76 | ajax: {
|
| 77 | type: "GET",
|
| 78 | url: "/api/v1/get/domain-admin/all",
|
| 79 | dataSrc: function(data){
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 80 | return process_table_data(data, 'domainadminstable');
|
| 81 | }
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 82 | },
|
| 83 | columns: [
|
| 84 | {
|
| 85 | // placeholder, so checkbox will not block child row toggle
|
| 86 | title: '',
|
| 87 | data: null,
|
| 88 | searchable: false,
|
| 89 | orderable: false,
|
| 90 | defaultContent: ''
|
| 91 | },
|
| 92 | {
|
| 93 | title: '',
|
| 94 | data: 'chkbox',
|
| 95 | searchable: false,
|
| 96 | orderable: false,
|
| 97 | defaultContent: ''
|
| 98 | },
|
| 99 | {
|
| 100 | title: lang.username,
|
| 101 | data: 'username',
|
| 102 | defaultContent: ''
|
| 103 | },
|
| 104 | {
|
| 105 | title: lang.admin_domains,
|
| 106 | data: 'selected_domains',
|
| 107 | defaultContent: '',
|
| 108 | },
|
| 109 | {
|
| 110 | title: "TFA",
|
| 111 | data: 'tfa_active',
|
| 112 | defaultContent: '',
|
| 113 | render: function (data, type) {
|
| 114 | if(data == 1) return '<i class="bi bi-check-lg"></i>';
|
| 115 | else return '<i class="bi bi-x-lg"></i>'
|
| 116 | }
|
| 117 | },
|
| 118 | {
|
| 119 | title: lang.active,
|
| 120 | data: 'active',
|
| 121 | defaultContent: '',
|
| 122 | render: function (data, type) {
|
| 123 | if(data == 1) return '<i class="bi bi-check-lg"></i>';
|
| 124 | else return '<i class="bi bi-x-lg"></i>'
|
| 125 | }
|
| 126 | },
|
| 127 | {
|
| 128 | title: lang.action,
|
| 129 | data: 'action',
|
| 130 | className: 'text-md-end dt-sm-head-hidden dt-body-right',
|
| 131 | defaultContent: ''
|
| 132 | },
|
| 133 | ],
|
| 134 | initComplete: function(settings, json){
|
| 135 | }
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 136 | });
|
| 137 | }
|
| 138 | function draw_oauth2_clients() {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 139 | // just recalc width if instance already exists
|
| 140 | if ($.fn.DataTable.isDataTable('#oauth2clientstable') ) {
|
| 141 | $('#oauth2clientstable').DataTable().columns.adjust().responsive.recalc();
|
| 142 | return;
|
| 143 | }
|
| 144 |
|
| 145 | $('#oauth2clientstable').DataTable({
|
| 146 | processing: true,
|
| 147 | serverSide: false,
|
| 148 | language: lang_datatables,
|
| 149 | ajax: {
|
| 150 | type: "GET",
|
| 151 | url: "/api/v1/get/oauth2-client/all",
|
| 152 | dataSrc: function(data){
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 153 | return process_table_data(data, 'oauth2clientstable');
|
| 154 | }
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 155 | },
|
| 156 | columns: [
|
| 157 | {
|
| 158 | // placeholder, so checkbox will not block child row toggle
|
| 159 | title: '',
|
| 160 | data: null,
|
| 161 | searchable: false,
|
| 162 | orderable: false,
|
| 163 | defaultContent: ''
|
| 164 | },
|
| 165 | {
|
| 166 | title: '',
|
| 167 | data: 'chkbox',
|
| 168 | searchable: false,
|
| 169 | orderable: false,
|
| 170 | defaultContent: ''
|
| 171 | },
|
| 172 | {
|
| 173 | title: 'ID',
|
| 174 | data: 'id',
|
| 175 | defaultContent: ''
|
| 176 | },
|
| 177 | {
|
| 178 | title: lang.oauth2_client_id,
|
| 179 | data: 'client_id',
|
| 180 | defaultContent: ''
|
| 181 | },
|
| 182 | {
|
| 183 | title: lang.oauth2_client_secret,
|
| 184 | data: 'client_secret',
|
| 185 | defaultContent: ''
|
| 186 | },
|
| 187 | {
|
| 188 | title: lang.oauth2_redirect_uri,
|
| 189 | data: 'redirect_uri',
|
| 190 | defaultContent: ''
|
| 191 | },
|
| 192 | {
|
| 193 | title: lang.action,
|
| 194 | data: 'action',
|
| 195 | className: 'text-md-end dt-sm-head-hidden dt-body-right',
|
| 196 | defaultContent: ''
|
| 197 | },
|
| 198 | ]
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 199 | });
|
| 200 | }
|
| 201 | function draw_admins() {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 202 | // just recalc width if instance already exists
|
| 203 | if ($.fn.DataTable.isDataTable('#adminstable') ) {
|
| 204 | $('#adminstable').DataTable().columns.adjust().responsive.recalc();
|
| 205 | return;
|
| 206 | }
|
| 207 |
|
| 208 | $('#adminstable').DataTable({
|
| 209 | processing: true,
|
| 210 | serverSide: false,
|
| 211 | language: lang_datatables,
|
| 212 | ajax: {
|
| 213 | type: "GET",
|
| 214 | url: "/api/v1/get/admin/all",
|
| 215 | dataSrc: function(data){
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 216 | return process_table_data(data, 'adminstable');
|
| 217 | }
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 218 | },
|
| 219 | columns: [
|
| 220 | {
|
| 221 | // placeholder, so checkbox will not block child row toggle
|
| 222 | title: '',
|
| 223 | data: null,
|
| 224 | searchable: false,
|
| 225 | orderable: false,
|
| 226 | defaultContent: ''
|
| 227 | },
|
| 228 | {
|
| 229 | title: '',
|
| 230 | data: 'chkbox',
|
| 231 | searchable: false,
|
| 232 | orderable: false,
|
| 233 | defaultContent: ''
|
| 234 | },
|
| 235 | {
|
| 236 | title: lang.username,
|
| 237 | data: 'username',
|
| 238 | defaultContent: ''
|
| 239 | },
|
| 240 | {
|
| 241 | title: "TFA",
|
| 242 | data: 'tfa_active',
|
| 243 | defaultContent: '',
|
| 244 | render: function (data, type) {
|
| 245 | if(data == 1) return '<i class="bi bi-check-lg"></i>';
|
| 246 | else return '<i class="bi bi-x-lg"></i>'
|
| 247 | }
|
| 248 | },
|
| 249 | {
|
| 250 | title: lang.active,
|
| 251 | data: 'active',
|
| 252 | defaultContent: '',
|
| 253 | render: function (data, type) {
|
| 254 | if(data == 1) return '<i class="bi bi-check-lg"></i>';
|
| 255 | else return '<i class="bi bi-x-lg"></i>'
|
| 256 | }
|
| 257 | },
|
| 258 | {
|
| 259 | title: lang.action,
|
| 260 | data: 'action',
|
| 261 | defaultContent: '',
|
| 262 | className: 'text-md-end dt-sm-head-hidden dt-body-right'
|
| 263 | },
|
| 264 | ]
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 265 | });
|
| 266 | }
|
| 267 | function draw_fwd_hosts() {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 268 | // just recalc width if instance already exists
|
| 269 | if ($.fn.DataTable.isDataTable('#forwardinghoststable') ) {
|
| 270 | $('#forwardinghoststable').DataTable().columns.adjust().responsive.recalc();
|
| 271 | return;
|
| 272 | }
|
| 273 |
|
| 274 | $('#forwardinghoststable').DataTable({
|
| 275 | processing: true,
|
| 276 | serverSide: false,
|
| 277 | language: lang_datatables,
|
| 278 | ajax: {
|
| 279 | type: "GET",
|
| 280 | url: "/api/v1/get/fwdhost/all",
|
| 281 | dataSrc: function(data){
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 282 | return process_table_data(data, 'forwardinghoststable');
|
| 283 | }
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 284 | },
|
| 285 | columns: [
|
| 286 | {
|
| 287 | // placeholder, so checkbox will not block child row toggle
|
| 288 | title: '',
|
| 289 | data: null,
|
| 290 | searchable: false,
|
| 291 | orderable: false,
|
| 292 | defaultContent: ''
|
| 293 | },
|
| 294 | {
|
| 295 | title: '',
|
| 296 | data: 'chkbox',
|
| 297 | searchable: false,
|
| 298 | orderable: false,
|
| 299 | defaultContent: ''
|
| 300 | },
|
| 301 | {
|
| 302 | title: lang.host,
|
| 303 | data: 'host',
|
| 304 | defaultContent: ''
|
| 305 | },
|
| 306 | {
|
| 307 | title: lang.source,
|
| 308 | data: 'source',
|
| 309 | defaultContent: ''
|
| 310 | },
|
| 311 | {
|
| 312 | title: lang.spamfilter,
|
| 313 | data: 'keep_spam',
|
| 314 | defaultContent: ''
|
| 315 | },
|
| 316 | {
|
| 317 | title: lang.action,
|
| 318 | data: 'action',
|
| 319 | className: 'text-md-end dt-sm-head-hidden dt-body-right',
|
| 320 | defaultContent: ''
|
| 321 | },
|
| 322 | ]
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 323 | });
|
| 324 | }
|
| 325 | function draw_relayhosts() {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 326 | // just recalc width if instance already exists
|
| 327 | if ($.fn.DataTable.isDataTable('#relayhoststable') ) {
|
| 328 | $('#relayhoststable').DataTable().columns.adjust().responsive.recalc();
|
| 329 | return;
|
| 330 | }
|
| 331 |
|
| 332 | $('#relayhoststable').DataTable({
|
| 333 | processing: true,
|
| 334 | serverSide: false,
|
| 335 | language: lang_datatables,
|
| 336 | ajax: {
|
| 337 | type: "GET",
|
| 338 | url: "/api/v1/get/relayhost/all",
|
| 339 | dataSrc: function(data){
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 340 | return process_table_data(data, 'relayhoststable');
|
| 341 | }
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 342 | },
|
| 343 | columns: [
|
| 344 | {
|
| 345 | // placeholder, so checkbox will not block child row toggle
|
| 346 | title: '',
|
| 347 | data: null,
|
| 348 | searchable: false,
|
| 349 | orderable: false,
|
| 350 | defaultContent: ''
|
| 351 | },
|
| 352 | {
|
| 353 | title: '',
|
| 354 | data: 'chkbox',
|
| 355 | searchable: false,
|
| 356 | orderable: false,
|
| 357 | defaultContent: ''
|
| 358 | },
|
| 359 | {
|
| 360 | title: 'ID',
|
| 361 | data: 'id',
|
| 362 | defaultContent: ''
|
| 363 | },
|
| 364 | {
|
| 365 | title: lang.host,
|
| 366 | data: 'hostname',
|
| 367 | defaultContent: ''
|
| 368 | },
|
| 369 | {
|
| 370 | title: lang.username,
|
| 371 | data: 'username',
|
| 372 | defaultContent: ''
|
| 373 | },
|
| 374 | {
|
| 375 | title: lang.in_use_by,
|
| 376 | data: 'in_use_by',
|
| 377 | defaultContent: ''
|
| 378 | },
|
| 379 | {
|
| 380 | title: lang.active,
|
| 381 | data: 'active',
|
| 382 | defaultContent: '',
|
| 383 | render: function (data, type) {
|
| 384 | if(data == 1) return '<i class="bi bi-check-lg"></i>';
|
| 385 | else return '<i class="bi bi-x-lg"></i>'
|
| 386 | }
|
| 387 | },
|
| 388 | {
|
| 389 | title: lang.action,
|
| 390 | data: 'action',
|
| 391 | className: 'text-md-end dt-sm-head-hidden dt-body-right',
|
| 392 | defaultContent: ''
|
| 393 | },
|
| 394 | ]
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 395 | });
|
| 396 | }
|
| 397 | function draw_transport_maps() {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 398 | // just recalc width if instance already exists
|
| 399 | if ($.fn.DataTable.isDataTable('#transportstable') ) {
|
| 400 | $('#transportstable').DataTable().columns.adjust().responsive.recalc();
|
| 401 | return;
|
| 402 | }
|
| 403 |
|
| 404 | $('#transportstable').DataTable({
|
| 405 | processing: true,
|
| 406 | serverSide: false,
|
| 407 | language: lang_datatables,
|
| 408 | ajax: {
|
| 409 | type: "GET",
|
| 410 | url: "/api/v1/get/transport/all",
|
| 411 | dataSrc: function(data){
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 412 | return process_table_data(data, 'transportstable');
|
| 413 | }
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 414 | },
|
| 415 | columns: [
|
| 416 | {
|
| 417 | // placeholder, so checkbox will not block child row toggle
|
| 418 | title: '',
|
| 419 | data: null,
|
| 420 | searchable: false,
|
| 421 | orderable: false,
|
| 422 | defaultContent: ''
|
| 423 | },
|
| 424 | {
|
| 425 | title: '',
|
| 426 | data: 'chkbox',
|
| 427 | searchable: false,
|
| 428 | orderable: false,
|
| 429 | defaultContent: ''
|
| 430 | },
|
| 431 | {
|
| 432 | title: 'ID',
|
| 433 | data: 'id',
|
| 434 | defaultContent: ''
|
| 435 | },
|
| 436 | {
|
| 437 | title: lang.destination,
|
| 438 | data: 'destination',
|
| 439 | defaultContent: ''
|
| 440 | },
|
| 441 | {
|
| 442 | title: lang.nexthop,
|
| 443 | data: 'nexthop',
|
| 444 | defaultContent: ''
|
| 445 | },
|
| 446 | {
|
| 447 | title: lang.username,
|
| 448 | data: 'username',
|
| 449 | defaultContent: ''
|
| 450 | },
|
| 451 | {
|
| 452 | title: lang.active,
|
| 453 | data: 'active',
|
| 454 | defaultContent: '',
|
| 455 | render: function (data, type) {
|
| 456 | if(data == 1) return '<i class="bi bi-check-lg"></i>';
|
| 457 | else return '<i class="bi bi-x-lg"></i>'
|
| 458 | }
|
| 459 | },
|
| 460 | {
|
| 461 | title: lang.action,
|
| 462 | data: 'action',
|
| 463 | className: 'text-md-end dt-sm-head-hidden dt-body-right',
|
| 464 | defaultContent: ''
|
| 465 | },
|
| 466 | ]
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 467 | });
|
| 468 | }
|
| 469 |
|
| 470 | function process_table_data(data, table) {
|
| 471 | if (table == 'relayhoststable') {
|
| 472 | $.each(data, function (i, item) {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 473 | item.action = '<div class="btn-group">' +
|
| 474 | '<a href="#" data-bs-toggle="modal" data-bs-target="#testTransportModal" data-transport-id="' + encodeURI(item.id) + '" data-transport-type="sender-dependent" class="btn btn-xs btn-xs-third btn-secondary"><i class="bi bi-caret-right-fill"></i> Test</a>' +
|
| 475 | '<a href="/edit/relayhost/' + encodeURI(item.id) + '" class="btn btn-xs btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 476 | '<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 Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 477 | '</div>';
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 478 | if (item.used_by_mailboxes == '') { item.in_use_by = item.used_by_domains; }
|
| 479 | else if (item.used_by_domains == '') { item.in_use_by = item.used_by_mailboxes; }
|
| 480 | else { item.in_use_by = item.used_by_mailboxes + '<hr style="margin:5px 0px 5px 0px;">' + item.used_by_domains; }
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 481 | item.chkbox = '<input type="checkbox" data-id="rlyhosts" name="multi_select" value="' + item.id + '" />';
|
| 482 | });
|
| 483 | } else if (table == 'transportstable') {
|
| 484 | $.each(data, function (i, item) {
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 485 | if (item.is_mx_based) {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 486 | item.destination = '<i class="bi bi-info-circle-fill text-info mx-info" data-bs-toggle="tooltip" title="' + lang.is_mx_based + '"></i> <code>' + item.destination + '</code>';
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 487 | }
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 488 | if (item.username) {
|
| 489 | item.username = '<i style="color:#' + intToRGB(hashCode(item.nexthop)) + ';" class="bi bi-square-fill"></i> ' + item.username;
|
| 490 | }
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 491 | item.action = '<div class="btn-group">' +
|
| 492 | '<a href="#" data-bs-toggle="modal" data-bs-target="#testTransportModal" data-transport-id="' + encodeURI(item.id) + '" data-transport-type="transport-map" class="btn btn-xs btn-xs-third btn-secondary"><i class="bi bi-caret-right-fill"></i> Test</a>' +
|
| 493 | '<a href="/edit/transport/' + encodeURI(item.id) + '" class="btn btn-xs btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 494 | '<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 Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 495 | '</div>';
|
| 496 | item.chkbox = '<input type="checkbox" data-id="transports" name="multi_select" value="' + item.id + '" />';
|
| 497 | });
|
| 498 | } else if (table == 'queuetable') {
|
| 499 | $.each(data, function (i, item) {
|
| 500 | item.chkbox = '<input type="checkbox" data-id="mailqitems" name="multi_select" value="' + item.queue_id + '" />';
|
| 501 | rcpts = $.map(item.recipients, function(i) {
|
| 502 | return escapeHtml(i);
|
| 503 | });
|
| 504 | item.recipients = rcpts.join('<hr style="margin:1px!important">');
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 505 | item.action = '<div class="btn-group">' +
|
| 506 | '<a href="#" data-bs-toggle="modal" data-bs-target="#showQueuedMsg" data-queue-id="' + encodeURI(item.queue_id) + '" class="btn btn-xs btn-secondary">' + lang.queue_show_message + '</a>' +
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 507 | '</div>';
|
| 508 | });
|
| 509 | } else if (table == 'forwardinghoststable') {
|
| 510 | $.each(data, function (i, item) {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 511 | item.action = '<div class="btn-group">' +
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 512 | '<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 Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 513 | '</div>';
|
| 514 | item.chkbox = '<input type="checkbox" data-id="fwdhosts" name="multi_select" value="' + item.host + '" />';
|
| 515 | });
|
| 516 | } else if (table == 'oauth2clientstable') {
|
| 517 | $.each(data, function (i, item) {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 518 | item.action = '<div class="btn-group">' +
|
| 519 | '<a href="/edit.php?oauth2client=' + encodeURI(item.id) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 520 | '<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 Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 521 | '</div>';
|
| 522 | item.scope = "profile";
|
| 523 | item.grant_types = 'refresh_token password authorization_code';
|
| 524 | item.chkbox = '<input type="checkbox" data-id="oauth2_clients" name="multi_select" value="' + item.id + '" />';
|
| 525 | });
|
| 526 | } else if (table == 'domainadminstable') {
|
| 527 | $.each(data, function (i, item) {
|
| 528 | item.selected_domains = escapeHtml(item.selected_domains);
|
| 529 | item.selected_domains = item.selected_domains.toString().replace(/,/g, "<br>");
|
| 530 | item.chkbox = '<input type="checkbox" data-id="domain_admins" name="multi_select" value="' + item.username + '" />';
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 531 | item.action = '<div class="btn-group">' +
|
| 532 | '<a href="/edit/domainadmin/' + encodeURI(item.username) + '" class="btn btn-xs btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 533 | '<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>' +
|
| 534 | '<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 Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 535 | '</div>';
|
| 536 | });
|
| 537 | } else if (table == 'adminstable') {
|
| 538 | $.each(data, function (i, item) {
|
| 539 | if (admin_username.toLowerCase() == item.username.toLowerCase()) {
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 540 | item.usr = '<i class="bi bi-person-check"></i> ' + item.username;
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 541 | } else {
|
| 542 | item.usr = item.username;
|
| 543 | }
|
| 544 | item.chkbox = '<input type="checkbox" data-id="admins" name="multi_select" value="' + item.username + '" />';
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 545 | item.action = '<div class="btn-group">' +
|
| 546 | '<a href="/edit/admin/' + encodeURI(item.username) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 547 | '<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 Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 548 | '</div>';
|
| 549 | });
|
| 550 | }
|
| 551 | return data
|
| 552 | };
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 553 |
|
| 554 | // detect element visibility changes
|
| 555 | function onVisible(element, callback) {
|
| 556 | $(document).ready(function() {
|
| 557 | element_object = document.querySelector(element);
|
| 558 | if (element_object === null) return;
|
| 559 |
|
| 560 | new IntersectionObserver((entries, observer) => {
|
| 561 | entries.forEach(entry => {
|
| 562 | if(entry.intersectionRatio > 0) {
|
| 563 | callback(element_object);
|
| 564 | }
|
| 565 | });
|
| 566 | }).observe(element_object);
|
| 567 | });
|
| 568 | }
|
| 569 | // Draw Table if tab is active
|
| 570 | onVisible("[id^=adminstable]", () => draw_admins());
|
| 571 | onVisible("[id^=domainadminstable]", () => draw_domain_admins());
|
| 572 | onVisible("[id^=oauth2clientstable]", () => draw_oauth2_clients());
|
| 573 | onVisible("[id^=forwardinghoststable]", () => draw_fwd_hosts());
|
| 574 | onVisible("[id^=relayhoststable]", () => draw_relayhosts());
|
| 575 | onVisible("[id^=transportstable]", () => draw_transport_maps());
|
| 576 |
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 577 |
|
| 578 | $('body').on('click', 'span.footable-toggle', function () {
|
| 579 | event.stopPropagation();
|
| 580 | })
|
| 581 |
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 582 | // API IP check toggle
|
| 583 | $("#skip_ip_check_ro").click(function( event ) {
|
| 584 | $("#skip_ip_check_ro").not(this).prop('checked', false);
|
| 585 | if ($("#skip_ip_check_ro:checked").length > 0) {
|
| 586 | $('#allow_from_ro').prop('disabled', true);
|
| 587 | }
|
| 588 | else {
|
| 589 | $("#allow_from_ro").removeAttr('disabled');
|
| 590 | }
|
| 591 | });
|
| 592 | $("#skip_ip_check_rw").click(function( event ) {
|
| 593 | $("#skip_ip_check_rw").not(this).prop('checked', false);
|
| 594 | if ($("#skip_ip_check_rw:checked").length > 0) {
|
| 595 | $('#allow_from_rw').prop('disabled', true);
|
| 596 | }
|
| 597 | else {
|
| 598 | $("#allow_from_rw").removeAttr('disabled');
|
| 599 | }
|
| 600 | });
|
| 601 | // Relayhost
|
| 602 | $('#testRelayhostModal').on('show.bs.modal', function (e) {
|
| 603 | $('#test_relayhost_result').text("-");
|
| 604 | button = $(e.relatedTarget)
|
| 605 | if (button != null) {
|
| 606 | $('#relayhost_id').val(button.data('relayhost-id'));
|
| 607 | }
|
| 608 | })
|
| 609 | $('#test_relayhost').on('click', function (e) {
|
| 610 | e.preventDefault();
|
| 611 | prev = $('#test_relayhost').text();
|
| 612 | $(this).prop("disabled",true);
|
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 613 | $(this).html('<i class="bi bi-arrow-repeat icon-spin"></i> ');
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 614 | $.ajax({
|
| 615 | type: 'GET',
|
| 616 | url: 'inc/ajax/relay_check.php',
|
| 617 | dataType: 'text',
|
| 618 | data: $('#test_relayhost_form').serialize(),
|
| 619 | complete: function (data) {
|
| 620 | $('#test_relayhost_result').html(data.responseText);
|
| 621 | $('#test_relayhost').prop("disabled",false);
|
| 622 | $('#test_relayhost').text(prev);
|
| 623 | }
|
| 624 | });
|
| 625 | })
|
| 626 | // Transport
|
| 627 | $('#testTransportModal').on('show.bs.modal', function (e) {
|
| 628 | $('#test_transport_result').text("-");
|
| 629 | button = $(e.relatedTarget)
|
| 630 | if (button != null) {
|
| 631 | $('#transport_id').val(button.data('transport-id'));
|
| 632 | $('#transport_type').val(button.data('transport-type'));
|
| 633 | }
|
| 634 | })
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 635 | $('#test_transport').on('click', function (e) {
|
| 636 | e.preventDefault();
|
| 637 | prev = $('#test_transport').text();
|
| 638 | $(this).prop("disabled",true);
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 639 | $(this).html('<div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div> ');
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 640 | $.ajax({
|
| 641 | type: 'GET',
|
| 642 | url: 'inc/ajax/transport_check.php',
|
| 643 | dataType: 'text',
|
| 644 | data: $('#test_transport_form').serialize(),
|
| 645 | complete: function (data) {
|
| 646 | $('#test_transport_result').html(data.responseText);
|
| 647 | $('#test_transport').prop("disabled",false);
|
| 648 | $('#test_transport').text(prev);
|
| 649 | }
|
| 650 | });
|
| 651 | })
|
| 652 | // DKIM private key modal
|
| 653 | $('#showDKIMprivKey').on('show.bs.modal', function (e) {
|
| 654 | $('#priv_key_pre').text("-");
|
| 655 | p_related = $(e.relatedTarget)
|
| 656 | if (p_related != null) {
|
| 657 | var decoded_key = Base64.decode((p_related.data('priv-key')));
|
| 658 | $('#priv_key_pre').text(decoded_key);
|
| 659 | }
|
| 660 | })
|
| 661 | // FIDO2 friendly name modal
|
| 662 | $('#fido2ChangeFn').on('show.bs.modal', function (e) {
|
| 663 | rename_link = $(e.relatedTarget)
|
| 664 | if (rename_link != null) {
|
| 665 | $('#fido2_cid').val(rename_link.data('cid'));
|
| 666 | $('#fido2_subject_desc').text(Base64.decode(rename_link.data('subject')));
|
| 667 | }
|
| 668 | })
|
| 669 | // App links
|
| 670 | function add_table_row(table_id, type) {
|
| 671 | var row = $('<tr />');
|
| 672 | if (type == "app_link") {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 673 | cols = '<td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="app" required></td>';
|
| 674 | cols += '<td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="href" required></td>';
|
| 675 | cols += '<td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100" type="button">' + lang.remove_row + '</a></td>';
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 676 | } else if (type == "f2b_regex") {
|
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 677 | cols = '<td><input style="text-align:center" class="input-sm input-xs-lg form-control" data-id="f2b_regex" type="text" value="+" disabled></td>';
|
| 678 | cols += '<td><input class="input-sm input-xs-lg form-control regex-input" data-id="f2b_regex" type="text" name="regex" required></td>';
|
| 679 | cols += '<td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100" type="button">' + lang.remove_row + '</a></td>';
|
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 680 | }
|
| 681 | row.append(cols);
|
| 682 | table_id.append(row);
|
| 683 | }
|
| 684 | $('#app_link_table').on('click', 'tr a', function (e) {
|
| 685 | e.preventDefault();
|
| 686 | $(this).parents('tr').remove();
|
| 687 | });
|
| 688 | $('#f2b_regex_table').on('click', 'tr a', function (e) {
|
| 689 | e.preventDefault();
|
| 690 | $(this).parents('tr').remove();
|
| 691 | });
|
| 692 | $('#add_app_link_row').click(function() {
|
| 693 | add_table_row($('#app_link_table'), "app_link");
|
| 694 | });
|
| 695 | $('#add_f2b_regex_row').click(function() {
|
| 696 | add_table_row($('#f2b_regex_table'), "f2b_regex");
|
| 697 | });
|
| 698 | });
|