admin.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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={"&":"&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"}},
  80. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  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"}},
  135. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  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"}},
  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},
  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},
  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. function process_table_data(data, table) {
  276. if (table == 'relayhoststable') {
  277. $.each(data, function (i, item) {
  278. item.action = '<div class="btn-group">' +
  279. '<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>' +
  280. '<a href="/edit/relayhost/' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  281. '<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>' +
  282. '</div>';
  283. item.chkbox = '<input type="checkbox" data-id="rlyhosts" name="multi_select" value="' + item.id + '" />';
  284. });
  285. } else if (table == 'transportstable') {
  286. $.each(data, function (i, item) {
  287. if (item.username) {
  288. item.username = '<span style="border-left:3px solid #' + intToRGB(hashCode(item.nexthop)) + ';padding-left:5px;">' + item.username + '</span>';
  289. }
  290. item.action = '<div class="btn-group">' +
  291. '<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>' +
  292. '<a href="/edit/transport/' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  293. '<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>' +
  294. '</div>';
  295. item.chkbox = '<input type="checkbox" data-id="transports" name="multi_select" value="' + item.id + '" />';
  296. });
  297. } else if (table == 'queuetable') {
  298. $.each(data, function (i, item) {
  299. item.chkbox = '<input type="checkbox" data-id="mailqitems" name="multi_select" value="' + item.queue_id + '" />';
  300. rcpts = $.map(item.recipients, function(i) {
  301. return escapeHtml(i);
  302. });
  303. item.recipients = rcpts.join('<hr style="margin:1px!important">');
  304. item.action = '<div class="btn-group">' +
  305. '<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>' +
  306. '</div>';
  307. });
  308. } else if (table == 'forwardinghoststable') {
  309. $.each(data, function (i, item) {
  310. item.action = '<div class="btn-group">' +
  311. '<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>' +
  312. '</div>';
  313. if (item.keep_spam == "yes") {
  314. item.keep_spam = lang.no;
  315. }
  316. else {
  317. item.keep_spam = lang.yes;
  318. }
  319. item.chkbox = '<input type="checkbox" data-id="fwdhosts" name="multi_select" value="' + item.host + '" />';
  320. });
  321. } else if (table == 'oauth2clientstable') {
  322. $.each(data, function (i, item) {
  323. item.action = '<div class="btn-group">' +
  324. '<a href="/edit.php?oauth2client=' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  325. '<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>' +
  326. '</div>';
  327. item.scope = "profile";
  328. item.grant_types = 'refresh_token password authorization_code';
  329. item.chkbox = '<input type="checkbox" data-id="oauth2_clients" name="multi_select" value="' + item.id + '" />';
  330. });
  331. } else if (table == 'domainadminstable') {
  332. $.each(data, function (i, item) {
  333. item.selected_domains = escapeHtml(item.selected_domains);
  334. item.selected_domains = item.selected_domains.toString().replace(/,/g, "<br>");
  335. item.chkbox = '<input type="checkbox" data-id="domain_admins" name="multi_select" value="' + item.username + '" />';
  336. item.action = '<div class="btn-group">' +
  337. '<a href="/edit/domainadmin/' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  338. '<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>' +
  339. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>' +
  340. '</div>';
  341. });
  342. } else if (table == 'adminstable') {
  343. $.each(data, function (i, item) {
  344. if (admin_username.toLowerCase() == item.username.toLowerCase()) {
  345. item.usr = '→ ' + item.username;
  346. } else {
  347. item.usr = item.username;
  348. }
  349. item.chkbox = '<input type="checkbox" data-id="admins" name="multi_select" value="' + item.username + '" />';
  350. item.action = '<div class="btn-group">' +
  351. '<a href="/edit/admin/' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  352. '<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>' +
  353. '</div>';
  354. });
  355. }
  356. return data
  357. };
  358. // Initial table drawings
  359. draw_domain_admins();
  360. draw_admins();
  361. draw_fwd_hosts();
  362. draw_relayhosts();
  363. draw_oauth2_clients();
  364. draw_transport_maps();
  365. draw_queue();
  366. // API IP check toggle
  367. $("#skip_ip_check_ro").click(function( event ) {
  368. $("#skip_ip_check_ro").not(this).prop('checked', false);
  369. if ($("#skip_ip_check_ro:checked").length > 0) {
  370. $('#allow_from_ro').prop('disabled', true);
  371. }
  372. else {
  373. $("#allow_from_ro").removeAttr('disabled');
  374. }
  375. });
  376. $("#skip_ip_check_rw").click(function( event ) {
  377. $("#skip_ip_check_rw").not(this).prop('checked', false);
  378. if ($("#skip_ip_check_rw:checked").length > 0) {
  379. $('#allow_from_rw').prop('disabled', true);
  380. }
  381. else {
  382. $("#allow_from_rw").removeAttr('disabled');
  383. }
  384. });
  385. // Relayhost
  386. $('#testRelayhostModal').on('show.bs.modal', function (e) {
  387. $('#test_relayhost_result').text("-");
  388. button = $(e.relatedTarget)
  389. if (button != null) {
  390. $('#relayhost_id').val(button.data('relayhost-id'));
  391. }
  392. })
  393. $('#test_relayhost').on('click', function (e) {
  394. e.preventDefault();
  395. prev = $('#test_relayhost').text();
  396. $(this).prop("disabled",true);
  397. $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
  398. $.ajax({
  399. type: 'GET',
  400. url: 'inc/ajax/relay_check.php',
  401. dataType: 'text',
  402. data: $('#test_relayhost_form').serialize(),
  403. complete: function (data) {
  404. $('#test_relayhost_result').html(data.responseText);
  405. $('#test_relayhost').prop("disabled",false);
  406. $('#test_relayhost').text(prev);
  407. }
  408. });
  409. })
  410. // Transport
  411. $('#testTransportModal').on('show.bs.modal', function (e) {
  412. $('#test_transport_result').text("-");
  413. button = $(e.relatedTarget)
  414. if (button != null) {
  415. $('#transport_id').val(button.data('transport-id'));
  416. $('#transport_type').val(button.data('transport-type'));
  417. }
  418. })
  419. // Queue item
  420. $('#showQueuedMsg').on('show.bs.modal', function (e) {
  421. $('#queue_msg_content').text(lang.loading);
  422. button = $(e.relatedTarget)
  423. if (button != null) {
  424. $('#queue_id').text(button.data('queue-id'));
  425. }
  426. $.ajax({
  427. type: 'GET',
  428. url: '/api/v1/get/postcat/' + button.data('queue-id'),
  429. dataType: 'text',
  430. complete: function (data) {
  431. $('#queue_msg_content').text(data.responseText);
  432. }
  433. });
  434. })
  435. $('#test_transport').on('click', function (e) {
  436. e.preventDefault();
  437. prev = $('#test_transport').text();
  438. $(this).prop("disabled",true);
  439. $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
  440. $.ajax({
  441. type: 'GET',
  442. url: 'inc/ajax/transport_check.php',
  443. dataType: 'text',
  444. data: $('#test_transport_form').serialize(),
  445. complete: function (data) {
  446. $('#test_transport_result').html(data.responseText);
  447. $('#test_transport').prop("disabled",false);
  448. $('#test_transport').text(prev);
  449. }
  450. });
  451. })
  452. // DKIM private key modal
  453. $('#showDKIMprivKey').on('show.bs.modal', function (e) {
  454. $('#priv_key_pre').text("-");
  455. p_related = $(e.relatedTarget)
  456. if (p_related != null) {
  457. var decoded_key = Base64.decode((p_related.data('priv-key')));
  458. $('#priv_key_pre').text(decoded_key);
  459. }
  460. })
  461. // App links
  462. function add_table_row(table_id, type) {
  463. var row = $('<tr />');
  464. if (type == "app_link") {
  465. cols = '<td><input class="input-sm form-control" data-id="app_links" type="text" name="app" required></td>';
  466. cols += '<td><input class="input-sm form-control" data-id="app_links" type="text" name="href" required></td>';
  467. cols += '<td><a href="#" role="button" class="btn btn-xs btn-default" type="button">">' + lang.remove_row + '</a></td>';
  468. } else if (type == "f2b_regex") {
  469. cols = '<td><input style="text-align:center" class="input-sm form-control" data-id="f2b_regex" type="text" value="+" disabled></td>';
  470. cols += '<td><input class="input-sm form-control regex-input" data-id="f2b_regex" type="text" name="regex" required></td>';
  471. cols += '<td><a href="#" role="button" class="btn btn-xs btn-default" type="button">' + lang.remove_row + '</a></td>';
  472. }
  473. row.append(cols);
  474. table_id.append(row);
  475. }
  476. $('#app_link_table').on('click', 'tr a', function (e) {
  477. e.preventDefault();
  478. $(this).parents('tr').remove();
  479. });
  480. $('#f2b_regex_table').on('click', 'tr a', function (e) {
  481. e.preventDefault();
  482. $(this).parents('tr').remove();
  483. });
  484. $('#add_app_link_row').click(function() {
  485. add_table_row($('#app_link_table'), "app_link");
  486. });
  487. $('#add_f2b_regex_row').click(function() {
  488. add_table_row($('#f2b_regex_table'), "f2b_regex");
  489. });
  490. });