admin.js 25 KB

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