mailbox.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. $(document).ready(function() {
  2. FooTable.domainFilter = FooTable.Filtering.extend({
  3. construct: function(instance){
  4. this._super(instance);
  5. var domain_list = [];
  6. $.ajax({
  7. dataType: 'json',
  8. 'async': false,
  9. url: '/api/v1/get/domain/all',
  10. jsonp: false,
  11. error: function () {
  12. domain_list.push('Cannot read domain list');
  13. },
  14. success: function (data) {
  15. $.each(data, function (i, item) {
  16. domain_list.push(item.domain_name);
  17. });
  18. }
  19. });
  20. this.domains = domain_list;
  21. this.def = 'All Domains';
  22. this.$domain = null;
  23. },
  24. $create: function(){
  25. this._super();
  26. var self = this,
  27. $form_grp = $('<div/>', {'class': 'form-group'})
  28. .append($('<label/>', {'class': 'sr-only', text: 'Domain'}))
  29. .prependTo(self.$form);
  30. self.$domain = $('<select/>', { 'class': 'form-control' })
  31. .on('change', {self: self}, self._onDomainDropdownChanged)
  32. .append($('<option/>', {text: self.def}))
  33. .appendTo($form_grp);
  34. $.each(self.domains, function(i, domain){
  35. self.$domain.append($('<option/>').text(domain));
  36. });
  37. },
  38. _onDomainDropdownChanged: function(e){
  39. var self = e.data.self,
  40. selected = $(this).val();
  41. if (selected !== self.def){
  42. self.addFilter('domain', selected, ['domain']);
  43. } else {
  44. self.removeFilter('domain');
  45. }
  46. self.filter();
  47. },
  48. draw: function(){
  49. this._super();
  50. var domain = this.find('domain');
  51. if (domain instanceof FooTable.Filter){
  52. this.$domain.val(domain.query.val());
  53. } else {
  54. this.$domain.val(this.def);
  55. }
  56. $(this.$domain).closest("select").selectpicker();
  57. }
  58. });
  59. // Auto-fill domain quota when adding new domain
  60. auto_fill_quota = function(domain) {
  61. $.get("/api/v1/get/domain/" + domain, function(data){
  62. var result = $.parseJSON(JSON.stringify(data));
  63. max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
  64. if (max_new_mailbox_quota != '0') {
  65. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  66. $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
  67. $('#addInputQuota').val(max_new_mailbox_quota);
  68. }
  69. else {
  70. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  71. $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
  72. $('#addInputQuota').val(max_new_mailbox_quota);
  73. }
  74. });
  75. }
  76. $('#addSelectDomain').on('change', function() {
  77. auto_fill_quota($('#addSelectDomain').val());
  78. });
  79. auto_fill_quota($('#addSelectDomain').val());
  80. $(".generate_password").click(function( event ) {
  81. event.preventDefault();
  82. var random_passwd = Math.random().toString(36).slice(-8)
  83. $('#password').prop('type', 'text');
  84. $('#password').val(random_passwd);
  85. $('#password2').prop('type', 'text');
  86. $('#password2').val(random_passwd);
  87. });
  88. $("#goto_null").click(function( event ) {
  89. if ($("#goto_null").is(":checked")) {
  90. $('#textarea_alias_goto').prop('disabled', true);
  91. }
  92. else {
  93. $("#textarea_alias_goto").removeAttr('disabled');
  94. }
  95. });
  96. // Log modal
  97. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  98. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  99. $.ajax({
  100. url: '/inc/ajax/syncjob_logs.php',
  101. data: { id: syncjob_id },
  102. dataType: 'text',
  103. success: function(data){
  104. $(e.currentTarget).find('#logText').text(data);
  105. },
  106. error: function(xhr, status, error) {
  107. $(e.currentTarget).find('#logText').text(xhr.responseText);
  108. }
  109. });
  110. });
  111. // Log modal
  112. $('#dnsInfoModal').on('show.bs.modal', function(e) {
  113. var domain = $(e.relatedTarget).data('domain');
  114. $('.dns-modal-body').html('<center><span style="font-size:18pt;margin:50px" class="glyphicon glyphicon-refresh glyphicon-spin"></span></center>');
  115. $.ajax({
  116. url: '/inc/ajax/dns_diagnostics.php',
  117. data: { domain: domain },
  118. dataType: 'text',
  119. success: function(data){
  120. $('.dns-modal-body').html(data);
  121. },
  122. error: function(xhr, status, error) {
  123. $('.dns-modal-body').html(xhr.responseText);
  124. }
  125. });
  126. });
  127. // Sieve data modal
  128. $('#sieveDataModal').on('show.bs.modal', function(e) {
  129. var sieveScript = $(e.relatedTarget).data('sieve-script');
  130. $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
  131. });
  132. // Set line numbers for textarea
  133. $("#script_data").numberedtextarea({allowTabChar: true});
  134. // Disable submit button on script change
  135. $('#script_data').on('keyup', function() {
  136. $('#add_filter_btns > #add_item').attr({"disabled": true});
  137. $('#validation_msg').html('-');
  138. });
  139. // Validate script data
  140. $("#validate_sieve").click(function( event ) {
  141. event.preventDefault();
  142. var script = $('#script_data').val();
  143. $.ajax({
  144. dataType: 'jsonp',
  145. url: "/inc/ajax/sieve_validation.php",
  146. type: "get",
  147. data: { script: script },
  148. complete: function(data) {
  149. var response = (data.responseText);
  150. response_obj = JSON.parse(response);
  151. if (response_obj.type == "success") {
  152. $('#add_filter_btns > #add_item').attr({"disabled": false});
  153. }
  154. mailcow_alert_box(response_obj.msg, response_obj.type);
  155. },
  156. });
  157. });
  158. // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
  159. // $("#active-script").closest('td').css('background-color','#b0f0a0');
  160. // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
  161. // });
  162. });
  163. jQuery(function($){
  164. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  165. var entityMap = {
  166. '&': '&amp;',
  167. '<': '&lt;',
  168. '>': '&gt;',
  169. '"': '&quot;',
  170. "'": '&#39;',
  171. '/': '&#x2F;',
  172. '`': '&#x60;',
  173. '=': '&#x3D;'
  174. };
  175. function escapeHtml(string) {
  176. return String(string).replace(/[&<>"'`=\/]/g, function (s) {
  177. return entityMap[s];
  178. });
  179. }
  180. if (localStorage.getItem("current_page") === null) {
  181. var current_page = {};
  182. } else {
  183. var current_page = JSON.parse(localStorage.getItem('current_page'));
  184. }
  185. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  186. function validateEmail(email) {
  187. var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  188. return re.test(email);
  189. }
  190. // Calculation human readable file sizes
  191. function humanFileSize(bytes) {
  192. if(Math.abs(bytes) < 1024) {
  193. return bytes + ' B';
  194. }
  195. var units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
  196. var u = -1;
  197. do {
  198. bytes /= 1024;
  199. ++u;
  200. } while(Math.abs(bytes) >= 1024 && u < units.length - 1);
  201. return bytes.toFixed(1)+' '+units[u];
  202. }
  203. function unix_time_format(tm) {
  204. var date = new Date(tm ? tm * 1000 : 0);
  205. return date.toLocaleString();
  206. }
  207. $(".refresh_table").on('click', function(e) {
  208. e.preventDefault();
  209. var table_name = $(this).data('table');
  210. $('#' + table_name).find("tr.footable-empty").remove();
  211. draw_table = $(this).data('draw');
  212. eval(draw_table + '()');
  213. });
  214. function table_mailbox_ready(ft, name) {
  215. heading = ft.$el.parents('.tab-pane').find('.panel-heading')
  216. var ft_paging = ft.use(FooTable.Paging)
  217. $(heading).children('.table-lines').text(function(){
  218. return ft_paging.totalRows;
  219. })
  220. if (current_page[name]) {
  221. ft_paging.goto(parseInt(current_page[name]))
  222. }
  223. }
  224. function table_mailbox_paging(ft, name) {
  225. var ft_paging = ft.use(FooTable.Paging)
  226. current_page[name] = ft_paging.current;
  227. localStorage.setItem('current_page', JSON.stringify(current_page));
  228. }
  229. function draw_domain_table() {
  230. ft_domain_table = FooTable.init('#domain_table', {
  231. "columns": [
  232. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  233. {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
  234. {"name":"aliases","title":lang.aliases,"breakpoints":"xs sm"},
  235. {"name":"mailboxes","title":lang.mailboxes},
  236. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  237. res = value.split("/");
  238. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  239. },
  240. "sortValue": function(value){
  241. res = value.split("/");
  242. return Number(res[0]);
  243. },
  244. },
  245. {"name":"max_quota_for_mbox","title":lang.mailbox_quota,"breakpoints":"xs sm","style":{"width":"125px"}},
  246. {"name":"backupmx","filterable": false,"style":{"maxWidth":"120px","width":"120px"},"title":lang.backup_mx,"breakpoints":"xs sm"},
  247. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  248. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"240px","width":"240px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  249. ],
  250. "rows": $.ajax({
  251. dataType: 'json',
  252. url: '/api/v1/get/domain/all',
  253. jsonp: false,
  254. error: function (data) {
  255. console.log('Cannot draw domain table');
  256. },
  257. success: function (data) {
  258. $.each(data, function (i, item) {
  259. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  260. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  261. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain;
  262. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  263. item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
  264. item.action = '<div class="btn-group">';
  265. if (role == "admin") {
  266. item.action += '<a href="/edit.php?domain=' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  267. '<a href="#" id="delete_selected" data-id="single-domain" data-api-url="delete/domain" data-item="' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>';
  268. }
  269. else {
  270. item.action += '<a href="/edit.php?domain=' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>';
  271. }
  272. item.action += '<a href="#dnsInfoModal" class="btn btn-xs btn-info" data-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><span class="glyphicon glyphicon-question-sign"></span> DNS</a></div>';
  273. });
  274. }
  275. }),
  276. "empty": lang.empty,
  277. "paging": {
  278. "enabled": true,
  279. "limit": 5,
  280. "size": pagination_size
  281. },
  282. "filtering": {
  283. "enabled": true,
  284. "delay": 100,
  285. "position": "left",
  286. "connectors": false,
  287. "placeholder": lang.filter_table
  288. },
  289. "sorting": {
  290. "enabled": true
  291. },
  292. "on": {
  293. "ready.ft.table": function(e, ft){
  294. table_mailbox_ready(ft, 'domain_table');
  295. },
  296. "after.ft.paging": function(e, ft){
  297. table_mailbox_paging(ft, 'domain_table');
  298. }
  299. }
  300. });
  301. }
  302. function draw_mailbox_table() {
  303. ft_mailbox_table = FooTable.init('#mailbox_table', {
  304. "columns": [
  305. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  306. {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
  307. {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm"},
  308. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  309. {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
  310. res = value.split("/");
  311. return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
  312. },
  313. "sortValue": function(value){
  314. res = value.split("/");
  315. return Number(res[0]);
  316. },
  317. },
  318. {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"xs sm md"},
  319. {"name":"in_use","filterable": false,"type":"html","title":lang.in_use,"sortValue": function(value){
  320. return Number($(value).find(".progress-bar").attr('aria-valuenow'));
  321. },
  322. },
  323. {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
  324. {"name":"active","filterable": false,"title":lang.active},
  325. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
  326. ],
  327. "empty": lang.empty,
  328. "rows": $.ajax({
  329. dataType: 'json',
  330. url: '/api/v1/get/mailbox/all',
  331. jsonp: false,
  332. error: function () {
  333. console.log('Cannot draw mailbox table');
  334. },
  335. success: function (data) {
  336. $.each(data, function (i, item) {
  337. item.quota = item.quota_used + "/" + item.quota;
  338. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  339. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  340. if (role == "admin") {
  341. item.action = '<div class="btn-group">' +
  342. '<a href="/edit.php?mailbox=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  343. '<a href="#" id="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  344. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-user"></span> Login</a>' +
  345. '</div>';
  346. }
  347. else {
  348. item.action = '<div class="btn-group">' +
  349. '<a href="/edit.php?mailbox=' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  350. '<a href="#" id="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  351. '</div>';
  352. }
  353. item.in_use = '<div class="progress">' +
  354. '<div class="progress-bar progress-bar-' + item.percent_class + ' role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  355. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  356. item.username = escapeHtml(item.username);
  357. });
  358. }
  359. }),
  360. "paging": {
  361. "enabled": true,
  362. "limit": 5,
  363. "size": pagination_size
  364. },
  365. "filtering": {
  366. "enabled": true,
  367. "delay": 100,
  368. "position": "left",
  369. "connectors": false,
  370. "placeholder": lang.filter_table
  371. },
  372. "components": {
  373. "filtering": FooTable.domainFilter
  374. },
  375. "sorting": {
  376. "enabled": true
  377. },
  378. "on": {
  379. "ready.ft.table": function(e, ft){
  380. table_mailbox_ready(ft, 'mailbox_table');
  381. },
  382. "after.ft.paging": function(e, ft){
  383. table_mailbox_paging(ft, 'mailbox_table');
  384. }
  385. }
  386. });
  387. }
  388. function draw_resource_table() {
  389. ft_resource_table = FooTable.init('#resource_table', {
  390. "columns": [
  391. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  392. {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
  393. {"name":"kind","title":lang.kind},
  394. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  395. {"name":"multiple_bookings","filterable": false,"style":{"maxWidth":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
  396. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  397. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  398. ],
  399. "empty": lang.empty,
  400. "rows": $.ajax({
  401. dataType: 'json',
  402. url: '/api/v1/get/resource/all',
  403. jsonp: false,
  404. error: function () {
  405. console.log('Cannot draw resource table');
  406. },
  407. success: function (data) {
  408. $.each(data, function (i, item) {
  409. if (item.multiple_bookings == '0') {
  410. item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
  411. } else if (item.multiple_bookings == '-1') {
  412. item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
  413. } else {
  414. item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  415. }
  416. item.action = '<div class="btn-group">' +
  417. '<a href="/edit.php?resource=' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  418. '<a href="#" id="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + item.name + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  419. '</div>';
  420. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  421. item.name = escapeHtml(item.name);
  422. });
  423. }
  424. }),
  425. "paging": {
  426. "enabled": true,
  427. "limit": 5,
  428. "size": pagination_size
  429. },
  430. "filtering": {
  431. "enabled": true,
  432. "delay": 100,
  433. "position": "left",
  434. "connectors": false,
  435. "placeholder": lang.filter_table
  436. },
  437. "components": {
  438. "filtering": FooTable.domainFilter
  439. },
  440. "sorting": {
  441. "enabled": true
  442. },
  443. "on": {
  444. "ready.ft.table": function(e, ft){
  445. table_mailbox_ready(ft, 'resource_table');
  446. },
  447. "after.ft.paging": function(e, ft){
  448. table_mailbox_paging(ft, 'resource_table');
  449. }
  450. }
  451. });
  452. }
  453. function draw_bcc_table() {
  454. ft_bcc_table = FooTable.init('#bcc_table', {
  455. "columns": [
  456. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  457. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  458. {"name":"type","title":lang.bcc_type},
  459. {"name":"local_dest","title":lang.bcc_local_dest},
  460. {"name":"bcc_dest","title":lang.bcc_destinations},
  461. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  462. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  463. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  464. ],
  465. "empty": lang.empty,
  466. "rows": $.ajax({
  467. dataType: 'json',
  468. url: '/api/v1/get/bcc/all',
  469. jsonp: false,
  470. error: function () {
  471. console.log('Cannot draw bcc table');
  472. },
  473. success: function (data) {
  474. $.each(data, function (i, item) {
  475. item.action = '<div class="btn-group">' +
  476. '<a href="/edit.php?bcc=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  477. '<a href="#" id="delete_selected" data-id="single-bcc" data-api-url="delete/bcc" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  478. '</div>';
  479. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  480. item.local_dest = escapeHtml(item.local_dest);
  481. item.bcc_dest = escapeHtml(item.bcc_dest);
  482. if (item.type == 'sender') {
  483. item.type = '<span id="active-script" class="label label-success">Sender</span>';
  484. } else {
  485. item.type = '<span id="inactive-script" class="label label-warning">Recipient</span>';
  486. }
  487. });
  488. }
  489. }),
  490. "paging": {
  491. "enabled": true,
  492. "limit": 5,
  493. "size": pagination_size
  494. },
  495. "filtering": {
  496. "enabled": true,
  497. "delay": 100,
  498. "position": "left",
  499. "connectors": false,
  500. "placeholder": lang.filter_table
  501. },
  502. "sorting": {
  503. "enabled": true
  504. },
  505. "on": {
  506. "ready.ft.table": function(e, ft){
  507. table_mailbox_ready(ft, 'bcc_table');
  508. },
  509. "after.ft.paging": function(e, ft){
  510. table_mailbox_paging(ft, 'bcc_table');
  511. }
  512. }
  513. });
  514. }
  515. function draw_recipient_map_table() {
  516. ft_recipient_map_table = FooTable.init('#recipient_map_table', {
  517. "columns": [
  518. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  519. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  520. {"name":"recipient_map_old","title":lang.recipient_map_old},
  521. {"name":"recipient_map_new","title":lang.recipient_map_new},
  522. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  523. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
  524. ],
  525. "empty": lang.empty,
  526. "rows": $.ajax({
  527. dataType: 'json',
  528. url: '/api/v1/get/recipient_map/all',
  529. jsonp: false,
  530. error: function () {
  531. console.log('Cannot draw recipient map table');
  532. },
  533. success: function (data) {
  534. if (role == "admin") {
  535. $.each(data, function (i, item) {
  536. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  537. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  538. item.action = '<div class="btn-group">' +
  539. '<a href="/edit.php?recipient_map=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  540. '<a href="#" id="delete_selected" data-id="single-recipient_map" data-api-url="delete/recipient_map" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  541. '</div>';
  542. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  543. });
  544. }
  545. }
  546. }),
  547. "paging": {
  548. "enabled": true,
  549. "limit": 5,
  550. "size": pagination_size
  551. },
  552. "filtering": {
  553. "enabled": true,
  554. "delay": 100,
  555. "position": "left",
  556. "connectors": false,
  557. "placeholder": lang.filter_table
  558. },
  559. "sorting": {
  560. "enabled": true
  561. },
  562. "on": {
  563. "ready.ft.table": function(e, ft){
  564. table_mailbox_ready(ft, 'recipient_map_table');
  565. },
  566. "after.ft.paging": function(e, ft){
  567. table_mailbox_paging(ft, 'recipient_map_table');
  568. }
  569. }
  570. });
  571. }
  572. function draw_alias_table() {
  573. ft_alias_table = FooTable.init('#alias_table', {
  574. "columns": [
  575. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  576. {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
  577. {"name":"goto","title":lang.target_address},
  578. {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
  579. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  580. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  581. ],
  582. "empty": lang.empty,
  583. "rows": $.ajax({
  584. dataType: 'json',
  585. url: '/api/v1/get/alias/all',
  586. jsonp: false,
  587. error: function () {
  588. console.log('Cannot draw alias table');
  589. },
  590. success: function (data) {
  591. $.each(data, function (i, item) {
  592. item.action = '<div class="btn-group">' +
  593. '<a href="/edit.php?alias=' + encodeURIComponent(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  594. '<a href="#" id="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURIComponent(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  595. '</div>';
  596. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.address) + '" />';
  597. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  598. if (item.is_catch_all == 1) {
  599. item.address = '<div class="label label-default">Catch-All</div> ' + escapeHtml(item.address);
  600. }
  601. else {
  602. item.address = escapeHtml(item.address);
  603. }
  604. if (item.goto == "null@localhost") {
  605. item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
  606. }
  607. if (item.in_primary_domain !== "") {
  608. item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
  609. }
  610. });
  611. }
  612. }),
  613. "paging": {
  614. "enabled": true,
  615. "limit": 5,
  616. "size": pagination_size
  617. },
  618. "filtering": {
  619. "enabled": true,
  620. "delay": 100,
  621. "position": "left",
  622. "connectors": false,
  623. "placeholder": lang.filter_table
  624. },
  625. "components": {
  626. "filtering": FooTable.domainFilter
  627. },
  628. "sorting": {
  629. "enabled": true
  630. },
  631. "on": {
  632. "ready.ft.table": function(e, ft){
  633. table_mailbox_ready(ft, 'alias_table');
  634. },
  635. "after.ft.paging": function(e, ft){
  636. table_mailbox_paging(ft, 'alias_table');
  637. }
  638. }
  639. });
  640. }
  641. function draw_aliasdomain_table() {
  642. ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
  643. "columns": [
  644. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
  645. {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
  646. {"name":"target_domain","title":lang.target_domain},
  647. {"name":"active","filterable": false,"style":{"maxWidth":"50px","width":"70px"},"title":lang.active},
  648. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  649. ],
  650. "empty": lang.empty,
  651. "rows": $.ajax({
  652. dataType: 'json',
  653. url: '/api/v1/get/alias-domain/all',
  654. jsonp: false,
  655. error: function () {
  656. console.log('Cannot draw alias domain table');
  657. },
  658. success: function (data) {
  659. $.each(data, function (i, item) {
  660. item.action = '<div class="btn-group">' +
  661. '<a href="/edit.php?aliasdomain=' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  662. '<a href="#" id="delete_selected" data-id="single-alias-domain" data-api-url="delete/alias-domain" data-item="' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  663. '<a href="#dnsInfoModal" class="btn btn-xs btn-info" data-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><span class="glyphicon glyphicon-question-sign"></span> DNS</a></div>' +
  664. '</div>';
  665. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  666. });
  667. }
  668. }),
  669. "paging": {
  670. "enabled": true,
  671. "limit": 5,
  672. "size": pagination_size
  673. },
  674. "filtering": {
  675. "enabled": true,
  676. "delay": 100,
  677. "position": "left",
  678. "connectors": false,
  679. "placeholder": lang.filter_table
  680. },
  681. "sorting": {
  682. "enabled": true
  683. },
  684. "on": {
  685. "ready.ft.table": function(e, ft){
  686. table_mailbox_ready(ft, 'aliasdomain_table');
  687. },
  688. "after.ft.paging": function(e, ft){
  689. table_mailbox_paging(ft, 'aliasdomain_table');
  690. }
  691. }
  692. });
  693. }
  694. function draw_sync_job_table() {
  695. ft_syncjob_table = FooTable.init('#sync_job_table', {
  696. "columns": [
  697. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  698. {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  699. {"name":"user2","title":lang.owner},
  700. {"name":"server_w_port","title":"Server","breakpoints":"xs"},
  701. {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
  702. {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
  703. {"name":"last_run","title":lang.last_run,"breakpoints":"all"},
  704. {"name":"log","title":"Log"},
  705. {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active},
  706. {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
  707. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  708. ],
  709. "empty": lang.empty,
  710. "rows": $.ajax({
  711. dataType: 'json',
  712. url: '/api/v1/get/syncjobs/all/no_log',
  713. jsonp: false,
  714. error: function () {
  715. console.log('Cannot draw sync job table');
  716. },
  717. success: function (data) {
  718. $.each(data, function (i, item) {
  719. item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">Open logs</a>'
  720. item.user2 = escapeHtml(item.user2);
  721. if (!item.exclude > 0) {
  722. item.exclude = '-';
  723. } else {
  724. item.exclude = '<code>' + item.exclude + '</code>';
  725. }
  726. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  727. item.action = '<div class="btn-group">' +
  728. '<a href="/edit.php?syncjob=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  729. '<a href="#" id="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  730. '</div>';
  731. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  732. if (item.is_running == 1) {
  733. item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
  734. } else {
  735. item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
  736. }
  737. if (!item.last_run > 0) {
  738. item.last_run = lang.waiting;
  739. }
  740. });
  741. }
  742. }),
  743. "paging": {
  744. "enabled": true,
  745. "limit": 5,
  746. "size": pagination_size
  747. },
  748. "filtering": {
  749. "enabled": true,
  750. "delay": 100,
  751. "position": "left",
  752. "connectors": false,
  753. "placeholder": lang.filter_table
  754. },
  755. "sorting": {
  756. "enabled": true
  757. },
  758. "on": {
  759. "ready.ft.table": function(e, ft){
  760. table_mailbox_ready(ft, 'sync_job_table');
  761. },
  762. "after.ft.paging": function(e, ft){
  763. table_mailbox_paging(ft, 'sync_job_table');
  764. }
  765. }
  766. });
  767. }
  768. function draw_filter_table() {
  769. ft_filter_table = FooTable.init('#filter_table', {
  770. "columns": [
  771. {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
  772. {"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
  773. {"name":"active","style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  774. {"name":"filter_type","style":{"maxWidth":"80px","width":"80px"},"title":"Type"},
  775. {"sorted": true,"name":"username","title":lang.owner,"style":{"maxWidth":"550px","width":"350px"}},
  776. {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
  777. {"name":"script_data","title":"Script","breakpoints":"all"},
  778. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  779. ],
  780. "empty": lang.empty,
  781. "rows": $.ajax({
  782. dataType: 'json',
  783. url: '/api/v1/get/filters/all',
  784. jsonp: false,
  785. error: function () {
  786. console.log('Cannot draw filter table');
  787. },
  788. success: function (data) {
  789. $.each(data, function (i, item) {
  790. if (item.active_int == 1) {
  791. item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
  792. } else {
  793. item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
  794. }
  795. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  796. item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  797. item.action = '<div class="btn-group">' +
  798. '<a href="/edit.php?filter=' + item.id + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  799. '<a href="#" id="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  800. '</div>';
  801. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  802. });
  803. }
  804. }),
  805. "paging": {
  806. "enabled": true,
  807. "limit": 5,
  808. "size": pagination_size
  809. },
  810. "filtering": {
  811. "enabled": true,
  812. "delay": 100,
  813. "position": "left",
  814. "connectors": false,
  815. "placeholder": lang.filter_table
  816. },
  817. "sorting": {
  818. "enabled": true
  819. },
  820. "on": {
  821. "ready.ft.table": function(e, ft){
  822. table_mailbox_ready(ft, 'filter_table');
  823. },
  824. "after.ft.paging": function(e, ft){
  825. table_mailbox_paging(ft, 'filter_table');
  826. }
  827. }
  828. });
  829. };
  830. draw_domain_table();
  831. draw_mailbox_table();
  832. draw_resource_table();
  833. draw_alias_table();
  834. draw_aliasdomain_table();
  835. draw_sync_job_table();
  836. draw_filter_table();
  837. draw_bcc_table();
  838. draw_recipient_map_table();
  839. });