admin.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. if (localStorage.getItem("current_page") === null) {
  66. var current_page = {};
  67. } else {
  68. var current_page = JSON.parse(localStorage.getItem('current_page'));
  69. }
  70. function table_admin_ready(ft, name) {
  71. heading = ft.$el.parents('.panel').find('.panel-heading')
  72. var ft_paging = ft.use(FooTable.Paging)
  73. $(heading).children('.table-lines').text(function(){
  74. return ft_paging.totalRows;
  75. })
  76. }
  77. function draw_domain_admins() {
  78. ft_domainadmins = FooTable.init('#domainadminstable', {
  79. "columns": [
  80. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  81. {"sorted": true,"name":"username","title":lang.username,"style":{"width":"250px"}},
  82. {"name":"selected_domains","title":lang.admin_domains,"breakpoints":"xs sm"},
  83. {"name":"tfa_active","title":"TFA", "filterable": false,"style":{"maxWidth":"80px","width":"80px"}},
  84. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  85. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  86. ],
  87. "rows": $.ajax({
  88. dataType: 'json',
  89. url: '/api/v1/get/domain-admin/all',
  90. jsonp: false,
  91. error: function () {
  92. console.log('Cannot draw domain admin table');
  93. },
  94. success: function (data) {
  95. return process_table_data(data, 'domainadminstable');
  96. }
  97. }),
  98. "empty": lang.empty,
  99. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  100. "state": {"enabled": true},
  101. "filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
  102. "sorting": {"enabled": true},
  103. "toggleSelector": "table tbody span.footable-toggle"
  104. });
  105. }
  106. function draw_oauth2_clients() {
  107. ft_oauth2clientstable = FooTable.init('#oauth2clientstable', {
  108. "columns": [
  109. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  110. {"name":"id","type":"text","title":"ID","style":{"width":"50px"}},
  111. {"name":"client_id","type":"text","title":lang.oauth2_client_id,"style":{"width":"200px"}},
  112. {"name":"client_secret","title":lang.oauth2_client_secret,"breakpoints":"xs sm md","style":{"width":"200px"}},
  113. {"name":"redirect_uri","title":lang.oauth2_redirect_uri, "type": "text"},
  114. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  115. ],
  116. "rows": $.ajax({
  117. dataType: 'json',
  118. url: '/api/v1/get/oauth2-client/all',
  119. jsonp: false,
  120. error: function () {
  121. console.log('Cannot draw oauth2 clients table');
  122. },
  123. success: function (data) {
  124. return process_table_data(data, 'oauth2clientstable');
  125. }
  126. }),
  127. "empty": lang.empty,
  128. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  129. "sorting": {"enabled": true},
  130. "toggleSelector": "table tbody span.footable-toggle"
  131. });
  132. }
  133. function draw_admins() {
  134. ft_admins = FooTable.init('#adminstable', {
  135. "columns": [
  136. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  137. {"sorted": true,"name":"usr","title":lang.username,"style":{"width":"250px"}},
  138. {"name":"tfa_active","title":"TFA", "filterable": false,"style":{"maxWidth":"80px","width":"80px"}},
  139. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  140. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  141. ],
  142. "rows": $.ajax({
  143. dataType: 'json',
  144. url: '/api/v1/get/admin/all',
  145. jsonp: false,
  146. error: function () {
  147. console.log('Cannot draw admin table');
  148. },
  149. success: function (data) {
  150. return process_table_data(data, 'adminstable');
  151. }
  152. }),
  153. "empty": lang.empty,
  154. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  155. "filtering": {"enabled": false},
  156. "state": {"enabled": true},
  157. "sorting": {"enabled": true},
  158. "toggleSelector": "table tbody span.footable-toggle"
  159. });
  160. }
  161. function draw_fwd_hosts() {
  162. ft_forwardinghoststable = FooTable.init('#forwardinghoststable', {
  163. "columns": [
  164. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  165. {"name":"host","type":"text","title":lang.host,"style":{"width":"250px"}},
  166. {"name":"source","title":lang.source,"breakpoints":"xs sm"},
  167. {"name":"keep_spam","title":lang.spamfilter, "type": "text","style":{"maxWidth":"80px","width":"80px"}},
  168. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  169. ],
  170. "rows": $.ajax({
  171. dataType: 'json',
  172. url: '/api/v1/get/fwdhost/all',
  173. jsonp: false,
  174. error: function () {
  175. console.log('Cannot draw forwarding hosts table');
  176. },
  177. success: function (data) {
  178. return process_table_data(data, 'forwardinghoststable');
  179. }
  180. }),
  181. "empty": lang.empty,
  182. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  183. "sorting": {"enabled": true},
  184. "toggleSelector": "table tbody span.footable-toggle"
  185. });
  186. }
  187. function draw_relayhosts() {
  188. ft_relayhoststable = FooTable.init('#relayhoststable', {
  189. "columns": [
  190. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  191. {"name":"id","type":"text","title":"ID","style":{"width":"50px"}},
  192. {"name":"hostname","type":"text","title":lang.host,"style":{"width":"250px"}},
  193. {"name":"username","title":lang.username,"breakpoints":"xs sm"},
  194. {"name":"used_by_domains","title":lang.in_use_by,"style":{"width":"110px"}, "type": "text","breakpoints":"xs sm"},
  195. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  196. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"220px","width":"220px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  197. ],
  198. "rows": $.ajax({
  199. dataType: 'json',
  200. url: '/api/v1/get/relayhost/all',
  201. jsonp: false,
  202. error: function () {
  203. console.log('Cannot draw forwarding hosts table');
  204. },
  205. success: function (data) {
  206. return process_table_data(data, 'relayhoststable');
  207. }
  208. }),
  209. "empty": lang.empty,
  210. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  211. "sorting": {"enabled": true},
  212. "toggleSelector": "table tbody span.footable-toggle"
  213. });
  214. }
  215. function draw_transport_maps() {
  216. ft_relayhoststable = FooTable.init('#transportstable', {
  217. "columns": [
  218. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  219. {"name":"id","type":"text","title":"ID","style":{"width":"50px"}},
  220. {"name":"destination","type":"text","title":lang.destination,"style":{"width":"250px"}},
  221. {"name":"nexthop","type":"text","title":lang.nexthop,"style":{"width":"250px"}},
  222. {"name":"username","title":lang.username,"breakpoints":"xs sm"},
  223. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  224. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"220px","width":"220px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  225. ],
  226. "rows": $.ajax({
  227. dataType: 'json',
  228. url: '/api/v1/get/transport/all',
  229. jsonp: false,
  230. error: function () {
  231. console.log('Cannot draw transports table');
  232. },
  233. success: function (data) {
  234. return process_table_data(data, 'transportstable');
  235. }
  236. }),
  237. "empty": lang.empty,
  238. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  239. "sorting": {"enabled": true},
  240. "toggleSelector": "table tbody span.footable-toggle"
  241. });
  242. }
  243. function draw_queue() {
  244. ft_queuetable = FooTable.init('#queuetable', {
  245. "columns": [
  246. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  247. {"name":"queue_id","type":"text","title":"QID","style":{"width":"50px"}},
  248. {"name":"queue_name","type":"text","title":"Queue","style":{"width":"120px"}},
  249. {"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"}},
  250. {"name":"message_size","style":{"whiteSpace":"nowrap"},"title":lang.message_size,"formatter": function(value){
  251. return humanFileSize(value);
  252. }},
  253. {"name":"sender","title":lang.sender, "type": "text","breakpoints":"xs sm"},
  254. {"name":"recipients","title":lang.recipients, "type": "text","style":{"word-break":"break-all","min-width":"300px"},"breakpoints":"xs sm md"},
  255. ],
  256. "rows": $.ajax({
  257. dataType: 'json',
  258. url: '/api/v1/get/mailq/all',
  259. jsonp: false,
  260. error: function () {
  261. console.log('Cannot draw forwarding hosts table');
  262. },
  263. success: function (data) {
  264. return process_table_data(data, 'queuetable');
  265. }
  266. }),
  267. "empty": lang.empty,
  268. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  269. "sorting": {"enabled": true},
  270. "toggleSelector": "table tbody span.footable-toggle",
  271. "on": {
  272. "ready.ft.table": function(e, ft){
  273. table_admin_ready(ft, 'queuetable');
  274. }
  275. }
  276. });
  277. }
  278. function process_table_data(data, table) {
  279. if (table == 'relayhoststable') {
  280. $.each(data, function (i, item) {
  281. item.action = '<div class="btn-group">' +
  282. '<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>' +
  283. '<a href="/edit/relayhost/' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  284. '<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>' +
  285. '</div>';
  286. item.chkbox = '<input type="checkbox" data-id="rlyhosts" name="multi_select" value="' + item.id + '" />';
  287. });
  288. } else if (table == 'transportstable') {
  289. $.each(data, function (i, item) {
  290. if (item.username) {
  291. item.username = '<span style="border-left:3px solid #' + intToRGB(hashCode(item.nexthop)) + ';padding-left:5px;">' + item.username + '</span>';
  292. }
  293. item.action = '<div class="btn-group">' +
  294. '<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>' +
  295. '<a href="/edit/transport/' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  296. '<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>' +
  297. '</div>';
  298. item.chkbox = '<input type="checkbox" data-id="transports" name="multi_select" value="' + item.id + '" />';
  299. });
  300. } else if (table == 'queuetable') {
  301. $.each(data, function (i, item) {
  302. item.chkbox = '<input type="checkbox" data-id="mailqitems" name="multi_select" value="' + item.queue_id + '" />';
  303. rcpts = $.map(item.recipients, function(i) {
  304. return escapeHtml(i);
  305. });
  306. item.recipients = rcpts.join('<hr style="margin:1px!important">');
  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. // Relayhost
  367. $('#testRelayhostModal').on('show.bs.modal', function (e) {
  368. $('#test_relayhost_result').text("-");
  369. button = $(e.relatedTarget)
  370. if (button != null) {
  371. $('#relayhost_id').val(button.data('relayhost-id'));
  372. }
  373. })
  374. $('#test_relayhost').on('click', function (e) {
  375. e.preventDefault();
  376. prev = $('#test_relayhost').text();
  377. $(this).prop("disabled",true);
  378. $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
  379. $.ajax({
  380. type: 'GET',
  381. url: 'inc/ajax/relay_check.php',
  382. dataType: 'text',
  383. data: $('#test_relayhost_form').serialize(),
  384. complete: function (data) {
  385. $('#test_relayhost_result').html(data.responseText);
  386. $('#test_relayhost').prop("disabled",false);
  387. $('#test_relayhost').text(prev);
  388. }
  389. });
  390. })
  391. // Transport
  392. $('#testTransportModal').on('show.bs.modal', function (e) {
  393. $('#test_transport_result').text("-");
  394. button = $(e.relatedTarget)
  395. if (button != null) {
  396. $('#transport_id').val(button.data('transport-id'));
  397. $('#transport_type').val(button.data('transport-type'));
  398. }
  399. })
  400. $('#test_transport').on('click', function (e) {
  401. e.preventDefault();
  402. prev = $('#test_transport').text();
  403. $(this).prop("disabled",true);
  404. $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
  405. $.ajax({
  406. type: 'GET',
  407. url: 'inc/ajax/transport_check.php',
  408. dataType: 'text',
  409. data: $('#test_transport_form').serialize(),
  410. complete: function (data) {
  411. $('#test_transport_result').html(data.responseText);
  412. $('#test_transport').prop("disabled",false);
  413. $('#test_transport').text(prev);
  414. }
  415. });
  416. })
  417. // DKIM private key modal
  418. $('#showDKIMprivKey').on('show.bs.modal', function (e) {
  419. $('#priv_key_pre').text("-");
  420. p_related = $(e.relatedTarget)
  421. if (p_related != null) {
  422. var decoded_key = Base64.decode((p_related.data('priv-key')));
  423. $('#priv_key_pre').text(decoded_key);
  424. }
  425. })
  426. // App links
  427. function add_table_row(table_id) {
  428. var row = $('<tr />');
  429. cols = '<td><input class="input-sm form-control" data-id="app_links" type="text" name="app" required></td>';
  430. cols += '<td><input class="input-sm form-control" data-id="app_links" type="text" name="href" required></td>';
  431. cols += '<td><a href="#" role="button" class="btn btn-xs btn-default" type="button">Remove row</a></td>';
  432. row.append(cols);
  433. table_id.append(row);
  434. }
  435. $('#app_link_table').on('click', 'tr a', function (e) {
  436. e.preventDefault();
  437. $(this).parents('tr').remove();
  438. });
  439. $('#add_app_link_row').click(function() {
  440. add_table_row($('#app_link_table'));
  441. });
  442. });
  443. $(window).load(function(){
  444. initial_width_config = $("#sidebar-admin-config").width();
  445. initial_width_maps = $("#sidebar-admin-maps").width();
  446. $("#scrollbox-config").css("width", initial_width_config);
  447. $("#scrollbox-maps").css("width", initial_width_maps);
  448. if (sessionStorage.scrollTop > 70) {
  449. $('#scrollbox-config').addClass('scrollboxFixed');
  450. $('#scrollbox-maps').addClass('scrollboxFixed');
  451. }
  452. $(window).bind('scroll', function() {
  453. if ($(window).scrollTop() > 70) {
  454. $('#scrollbox-config').addClass('scrollboxFixed');
  455. $('#scrollbox-maps').addClass('scrollboxFixed');
  456. } else {
  457. $('#scrollbox-config').removeClass('scrollboxFixed');
  458. $('#scrollbox-maps').removeClass('scrollboxFixed');
  459. }
  460. });
  461. });
  462. function resizeScrollbox() {
  463. on_resize_width_config = $("#sidebar-admin-config").width();
  464. on_resize_width_maps = $("#sidebar-admin-maps").width();
  465. $("#scrollbox-config").removeAttr("style");
  466. $("#scrollbox-config").css("width", on_resize_width_config);
  467. $("#scrollbox-maps").removeAttr("style");
  468. $("#scrollbox-maps").css("width", on_resize_width_maps);
  469. }
  470. $(window).on('resize', resizeScrollbox);
  471. $('a[data-toggle="tab"]').on('shown.bs.tab', resizeScrollbox);