mailbox.js 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418
  1. $(document).ready(function() {
  2. acl_data = JSON.parse(acl);
  3. // Set paging
  4. // Clone mailbox mass actions
  5. $("div").find("[data-actions-header='true'").each(function() {
  6. $(this).html($(this).nextAll('.mass-actions-mailbox:first').html());
  7. });
  8. // Auto-fill domain quota when adding new domain
  9. auto_fill_quota = function(domain) {
  10. $.get("/api/v1/get/domain/" + domain, function(data){
  11. var result = $.parseJSON(JSON.stringify(data));
  12. def_new_mailbox_quota = ( result.def_new_mailbox_quota / 1048576);
  13. max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
  14. if (max_new_mailbox_quota != '0') {
  15. $('.addInputQuotaExhausted').hide();
  16. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  17. $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
  18. $('#addInputQuota').val(def_new_mailbox_quota);
  19. }
  20. else {
  21. $('.addInputQuotaExhausted').show();
  22. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  23. $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
  24. $('#addInputQuota').val(max_new_mailbox_quota);
  25. }
  26. });
  27. }
  28. $('#addSelectDomain').on('change', function() {
  29. auto_fill_quota($('#addSelectDomain').val());
  30. });
  31. auto_fill_quota($('#addSelectDomain').val());
  32. $(".goto_checkbox").click(function( event ) {
  33. $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false);
  34. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  35. $('#textarea_alias_goto').prop('disabled', true);
  36. }
  37. else {
  38. $("#textarea_alias_goto").removeAttr('disabled');
  39. }
  40. });
  41. $('#addAliasModal').on('show.bs.modal', function(e) {
  42. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  43. $('#textarea_alias_goto').prop('disabled', true);
  44. }
  45. else {
  46. $("#textarea_alias_goto").removeAttr('disabled');
  47. }
  48. });
  49. // Log modal
  50. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  51. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  52. $.ajax({
  53. url: '/inc/ajax/syncjob_logs.php',
  54. data: { id: syncjob_id },
  55. dataType: 'text',
  56. success: function(data){
  57. $(e.currentTarget).find('#logText').text(data);
  58. },
  59. error: function(xhr, status, error) {
  60. $(e.currentTarget).find('#logText').text(xhr.responseText);
  61. }
  62. });
  63. });
  64. // Log modal
  65. $('#dnsInfoModal').on('show.bs.modal', function(e) {
  66. var domain = $(e.relatedTarget).data('domain');
  67. $('.dns-modal-body').html('<div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div>');
  68. $.ajax({
  69. url: '/inc/ajax/dns_diagnostics.php',
  70. data: { domain: domain },
  71. dataType: 'text',
  72. success: function(data){
  73. $('.dns-modal-body').html(data);
  74. },
  75. error: function(xhr, status, error) {
  76. $('.dns-modal-body').html(xhr.responseText);
  77. }
  78. });
  79. });
  80. // @Open Domain add modal
  81. $('#addDomainModal').on('show.bs.modal', function(e) {
  82. $.ajax({
  83. url: '/api/v1/get/domain/template/all',
  84. data: {},
  85. dataType: 'json',
  86. success: async function(data){
  87. $('#domain_templates').find('option').remove();
  88. $('#domain_templates').selectpicker('destroy');
  89. $('#domain_templates').selectpicker();
  90. for (var i = 0; i < data.length; i++){
  91. if (data[i].template === "Default"){
  92. $('#domain_templates').prepend($('<option>', {
  93. 'value': data[i].id,
  94. 'text': data[i].template,
  95. 'data-attributes': JSON.stringify(data[i].attributes),
  96. 'selected': true
  97. }));
  98. setDomainTemplateData(data[i].attributes);
  99. } else {
  100. $('#domain_templates').append($('<option>', {
  101. 'value': data[i].id,
  102. 'text': data[i].template,
  103. 'data-attributes': JSON.stringify(data[i].attributes),
  104. 'selected': false
  105. }));
  106. }
  107. };
  108. $('#domain_templates').selectpicker("refresh");
  109. // @selecting template
  110. $('#domain_templates').on('change', function(){
  111. var selected = $('#domain_templates option:selected');
  112. var attr = selected.data('attributes');
  113. setDomainTemplateData(attr);
  114. });
  115. },
  116. error: function(xhr, status, error) {
  117. console.log(error);
  118. }
  119. });
  120. });
  121. // @Open Mailbox add modal
  122. $('#addMailboxModal').on('show.bs.modal', function(e) {
  123. $.ajax({
  124. url: '/api/v1/get/mailbox/template/all',
  125. data: {},
  126. dataType: 'json',
  127. success: async function(data){
  128. $('#mailbox_templates').find('option').remove();
  129. $('#mailbox_templates').selectpicker('destroy');
  130. $('#mailbox_templates').selectpicker();
  131. for (var i = 0; i < data.length; i++){
  132. if (data[i].template === "Default"){
  133. $('#mailbox_templates').prepend($('<option>', {
  134. 'value': data[i].id,
  135. 'text': data[i].template,
  136. 'data-attributes': JSON.stringify(data[i].attributes),
  137. 'selected': true
  138. }));
  139. setMailboxTemplateData(data[i].attributes);
  140. } else {
  141. $('#mailbox_templates').append($('<option>', {
  142. value: data[i].id,
  143. text : data[i].template,
  144. 'data-attributes': JSON.stringify(data[i].attributes),
  145. 'selected': false
  146. }));
  147. }
  148. };
  149. $('#mailbox_templates').selectpicker("refresh");
  150. // @selecting template
  151. $('#mailbox_templates').on('change', function(){
  152. var selected = $('#mailbox_templates option:selected');
  153. var attr = selected.data('attributes');
  154. setMailboxTemplateData(attr);
  155. });
  156. },
  157. error: function(xhr, status, error) {
  158. console.log(error);
  159. }
  160. });
  161. });
  162. // Sieve data modal
  163. $('#sieveDataModal').on('show.bs.modal', function(e) {
  164. var sieveScript = $(e.relatedTarget).data('sieve-script');
  165. $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
  166. });
  167. // Disable submit button on script change
  168. $('.textarea-code').on('keyup', function() {
  169. // Disable all "save" buttons, could be a "related button only" function, todo
  170. $('.add_sieve_script').attr({"disabled": true});
  171. });
  172. // Validate script data
  173. $(".validate_sieve").click(function( event ) {
  174. event.preventDefault();
  175. var validation_button = $(this);
  176. // Get script_data textarea content from form the button was clicked in
  177. var script = $('textarea[name="script_data"]', $(this).parents('form:first')).val();
  178. $.ajax({
  179. dataType: 'json',
  180. url: "/inc/ajax/sieve_validation.php",
  181. type: "get",
  182. data: { script: script },
  183. complete: function(data) {
  184. var response = (data.responseText);
  185. response_obj = JSON.parse(response);
  186. if (response_obj.type == "success") {
  187. $(validation_button).next().attr({"disabled": false});
  188. }
  189. mailcow_alert_box(response_obj.msg, response_obj.type);
  190. },
  191. });
  192. });
  193. // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
  194. // $("#active-script").closest('td').css('background-color','#b0f0a0');
  195. // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
  196. // });
  197. $('#addResourceModal').on('shown.bs.modal', function() {
  198. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  199. if ($("#multiple_bookings").val() == "custom") {
  200. $("#multiple_bookings_custom_div").show();
  201. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  202. }
  203. })
  204. $("#multiple_bookings_select").change(function() {
  205. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  206. if ($("#multiple_bookings").val() == "custom") {
  207. $("#multiple_bookings_custom_div").show();
  208. }
  209. else {
  210. $("#multiple_bookings_custom_div").hide();
  211. }
  212. });
  213. $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
  214. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  215. });
  216. function setDomainTemplateData(template){
  217. $("#addDomain_max_aliases").val(template.max_num_aliases_for_domain);
  218. $("#addDomain_max_mailboxes").val(template.max_num_mboxes_for_domain);
  219. $("#addDomain_mailbox_quota_def").val(template.def_quota_for_mbox / 1048576);
  220. $("#addDomain_mailbox_quota_m").val(template.max_quota_for_mbox / 1048576);
  221. $("#addDomain_domain_quota_m").val(template.max_quota_for_domain / 1048576);
  222. if (template.gal == 1){
  223. $('#addDomain_gal').prop('checked', true);
  224. } else {
  225. $('#addDomain_gal').prop('checked', false);
  226. }
  227. if (template.active == 1){
  228. $('#addDomain_active').prop('checked', true);
  229. } else {
  230. $('#addDomain_active').prop('checked', false);
  231. }
  232. $("#addDomain_rl_value").val(template.rl_value);
  233. $('#addDomain_rl_frame').selectpicker('val', template.rl_frame);
  234. $("#dkim_selector").val(template.dkim_selector);
  235. if (!template.key_size)
  236. template.key_size = 2048;
  237. $('#key_size').selectpicker('val', template.key_size.toString());
  238. if (template.backupmx == 1){
  239. $('#addDomain_relay_domain').prop('checked', true);
  240. } else {
  241. $('#addDomain_relay_domain').prop('checked', false);
  242. }
  243. if (template.relay_all_recipients == 1){
  244. $('#addDomain_relay_all').prop('checked', true);
  245. } else {
  246. $('#addDomain_relay_all').prop('checked', false);
  247. }
  248. if (template.relay_unknown_only == 1){
  249. $('#addDomain_relay_unknown_only').prop('checked', true);
  250. } else {
  251. $('#addDomain_relay_unknown_only').prop('checked', false);
  252. }
  253. // load tags
  254. $('#addDomain_tags').val("");
  255. $($('#addDomain_tags').parent().find(".tag-values")[0]).val("");
  256. $('#addDomain_tags').parent().find(".tag-badge").remove();
  257. for (var i = 0; i < template.tags.length; i++)
  258. addTag($('#addDomain_tags'), template.tags[i]);
  259. }
  260. function setMailboxTemplateData(template){
  261. $("#addInputQuota").val(template.quota / 1048576);
  262. if (template.quarantine_notification === "never"){
  263. $('#quarantine_notification_never').prop('checked', true);
  264. $('#quarantine_notification_hourly').prop('checked', false);
  265. $('#quarantine_notification_daily').prop('checked', false);
  266. $('#quarantine_notification_weekly').prop('checked', false);
  267. } else if(template.quarantine_notification === "hourly"){
  268. $('#quarantine_notification_never').prop('checked', false);
  269. $('#quarantine_notification_hourly').prop('checked', true);
  270. $('#quarantine_notification_daily').prop('checked', false);
  271. $('#quarantine_notification_weekly').prop('checked', false);
  272. } else if(template.quarantine_notification === "daily"){
  273. $('#quarantine_notification_never').prop('checked', false);
  274. $('#quarantine_notification_hourly').prop('checked', false);
  275. $('#quarantine_notification_daily').prop('checked', true);
  276. $('#quarantine_notification_weekly').prop('checked', false);
  277. } else if(template.quarantine_notification === "weekly"){
  278. $('#quarantine_notification_never').prop('checked', false);
  279. $('#quarantine_notification_hourly').prop('checked', false);
  280. $('#quarantine_notification_daily').prop('checked', false);
  281. $('#quarantine_notification_weekly').prop('checked', true);
  282. } else {
  283. $('#quarantine_notification_never').prop('checked', false);
  284. $('#quarantine_notification_hourly').prop('checked', false);
  285. $('#quarantine_notification_daily').prop('checked', false);
  286. $('#quarantine_notification_weekly').prop('checked', false);
  287. }
  288. if (template.quarantine_category === "reject"){
  289. $('#quarantine_category_reject').prop('checked', true);
  290. $('#quarantine_category_add_header').prop('checked', false);
  291. $('#quarantine_category_all').prop('checked', false);
  292. } else if(template.quarantine_category === "add_header"){
  293. $('#quarantine_category_reject').prop('checked', false);
  294. $('#quarantine_category_add_header').prop('checked', true);
  295. $('#quarantine_category_all').prop('checked', false);
  296. } else if(template.quarantine_category === "all"){
  297. $('#quarantine_category_reject').prop('checked', false);
  298. $('#quarantine_category_add_header').prop('checked', false);
  299. $('#quarantine_category_all').prop('checked', true);
  300. }
  301. if (template.tls_enforce_in == 1){
  302. $('#tls_enforce_in').prop('checked', true);
  303. } else {
  304. $('#tls_enforce_in').prop('checked', false);
  305. }
  306. if (template.tls_enforce_out == 1){
  307. $('#tls_enforce_out').prop('checked', true);
  308. } else {
  309. $('#tls_enforce_out').prop('checked', false);
  310. }
  311. var protocol_access = [];
  312. if (template.imap_access == 1){
  313. protocol_access.push("imap");
  314. }
  315. if (template.pop3_access == 1){
  316. protocol_access.push("pop3");
  317. }
  318. if (template.smtp_access == 1){
  319. protocol_access.push("smtp");
  320. }
  321. if (template.sieve_access == 1){
  322. protocol_access.push("sieve");
  323. }
  324. $('#protocol_access').selectpicker('val', protocol_access);
  325. var acl = [];
  326. if (template.acl_spam_alias == 1){
  327. acl.push("spam_alias");
  328. }
  329. if (template.acl_tls_policy == 1){
  330. acl.push("tls_policy");
  331. }
  332. if (template.acl_spam_score == 1){
  333. acl.push("spam_score");
  334. }
  335. if (template.acl_spam_policy == 1){
  336. acl.push("spam_policy");
  337. }
  338. if (template.acl_delimiter_action == 1){
  339. acl.push("delimiter_action");
  340. }
  341. if (template.acl_syncjobs == 1){
  342. acl.push("syncjobs");
  343. }
  344. if (template.acl_eas_reset == 1){
  345. acl.push("eas_reset");
  346. }
  347. if (template.acl_sogo_profile_reset == 1){
  348. acl.push("sogo_profile_reset");
  349. }
  350. if (template.acl_pushover == 1){
  351. acl.push("pushover");
  352. }
  353. if (template.acl_quarantine == 1){
  354. acl.push("quarantine");
  355. }
  356. if (template.acl_quarantine_attachments == 1){
  357. acl.push("quarantine_attachments");
  358. }
  359. if (template.acl_quarantine_notification == 1){
  360. acl.push("quarantine_notification");
  361. }
  362. if (template.acl_quarantine_category == 1){
  363. acl.push("quarantine_category");
  364. }
  365. if (template.acl_app_passwds == 1){
  366. acl.push("app_passwds");
  367. }
  368. $('#user_acl').selectpicker('val', acl);
  369. $('#rl_value').val(template.rl_value);
  370. if (template.rl_frame){
  371. $('#rl_frame').selectpicker('val', template.rl_frame);
  372. }
  373. console.log(template.active)
  374. if (template.active){
  375. $('#mbox_active').selectpicker('val', template.active.toString());
  376. } else {
  377. $('#mbox_active').selectpicker('val', '');
  378. }
  379. if (template.force_pw_update == 1){
  380. $('#force_pw_update').prop('checked', true);
  381. } else {
  382. $('#force_pw_update').prop('checked', false);
  383. }
  384. if (template.sogo_access == 1){
  385. $('#sogo_access').prop('checked', true);
  386. } else {
  387. $('#sogo_access').prop('checked', false);
  388. }
  389. // load tags
  390. $('#addMailbox_tags').val("");
  391. $($('#addMailbox_tags').parent().find(".tag-values")[0]).val("");
  392. $('#addMailbox_tags').parent().find(".tag-badge").remove();
  393. for (var i = 0; i < template.tags.length; i++)
  394. addTag($('#addMailbox_tags'), template.tags[i]);
  395. }
  396. });
  397. jQuery(function($){
  398. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  399. 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]}
  400. function unix_time_format(i){return""==i?'<i class="bi bi-x"></i>':new Date(i?1e3*i:0).toLocaleDateString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})}
  401. $(".refresh_table").on('click', function(e) {
  402. e.preventDefault();
  403. var table_name = $(this).data('table');
  404. if ($.fn.DataTable.isDataTable('#' + table_name))
  405. $('#' + table_name).DataTable().ajax.reload();
  406. });
  407. function draw_domain_table() {
  408. // just recalc width if instance already exists
  409. if ($.fn.DataTable.isDataTable('#domain_table') ) {
  410. $('#domain_table').DataTable().columns.adjust().responsive.recalc();
  411. return;
  412. }
  413. var table = $('#domain_table').DataTable({
  414. responsive: true,
  415. processing: true,
  416. serverSide: true,
  417. stateSave: true,
  418. pageLength: pagination_size,
  419. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  420. "tr" +
  421. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  422. language: lang_datatables,
  423. initComplete: function(){
  424. hideTableExpandCollapseBtn('#tab-domains', '#domain_table');
  425. },
  426. ajax: {
  427. type: "GET",
  428. url: "/api/v1/get/domain/datatables",
  429. dataSrc: function(json){
  430. $.each(json.data, function(i, item) {
  431. item.domain_name = escapeHtml(item.domain_name);
  432. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  433. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  434. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
  435. item.stats = item.msgs_total + "/" + item.bytes_total;
  436. if (!item.rl) item.rl = '∞';
  437. else {
  438. item.rl = $.map(item.rl, function(e){
  439. return e;
  440. }).join('/1');
  441. }
  442. item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
  443. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  444. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
  445. item.action = '<div class="btn-group">';
  446. if (role == "admin") {
  447. item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  448. '<a href="#" data-action="delete_selected" data-id="single-domain" data-api-url="delete/domain" data-item="' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  449. '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
  450. }
  451. else {
  452. item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  453. '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-xs-half btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
  454. }
  455. if (Array.isArray(item.tags)){
  456. var tags = '';
  457. for (var i = 0; i < item.tags.length; i++)
  458. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
  459. item.tags = tags;
  460. } else {
  461. item.tags = '';
  462. }
  463. if (item.backupmx == 1) {
  464. if (item.relay_unknown_only == 1) {
  465. item.domain_name = '<div class="badge fs-6 bg-info">Relay Non-Local</div> ' + item.domain_name;
  466. } else if (item.relay_all_recipients == 1) {
  467. item.domain_name = '<div class="badge fs-6 bg-info">Relay All</div> ' + item.domain_name;
  468. } else {
  469. item.domain_name = '<div class="badge fs-6 bg-info">Relay</div> ' + item.domain_name;
  470. }
  471. }
  472. });
  473. return json.data;
  474. }
  475. },
  476. columns: [
  477. {
  478. // placeholder, so checkbox will not block child row toggle
  479. title: '',
  480. data: null,
  481. searchable: false,
  482. orderable: false,
  483. defaultContent: '',
  484. responsivePriority: 1
  485. },
  486. {
  487. title: '',
  488. data: 'chkbox',
  489. searchable: false,
  490. orderable: false,
  491. defaultContent: '',
  492. responsivePriority: 2
  493. },
  494. {
  495. title: lang.domain,
  496. data: 'domain_name',
  497. responsivePriority: 3,
  498. defaultContent: ''
  499. },
  500. {
  501. title: lang.aliases,
  502. data: 'aliases',
  503. searchable: false,
  504. defaultContent: ''
  505. },
  506. {
  507. title: lang.mailboxes,
  508. data: 'mailboxes',
  509. searchable: false,
  510. responsivePriority: 4,
  511. defaultContent: ''
  512. },
  513. {
  514. title: lang.domain_quota,
  515. data: 'quota',
  516. searchable: false,
  517. defaultContent: '',
  518. render: function (data, type) {
  519. data = data.split("/");
  520. return humanFileSize(data[0]) + " / " + humanFileSize(data[1]);
  521. }
  522. },
  523. {
  524. title: lang.stats,
  525. data: 'stats',
  526. searchable: false,
  527. defaultContent: '',
  528. render: function (data, type) {
  529. data = data.split("/");
  530. return '<i class="bi bi-files"></i> ' + data[0] + ' / ' + humanFileSize(data[1]);
  531. }
  532. },
  533. {
  534. title: lang.mailbox_defquota,
  535. data: 'def_quota_for_mbox',
  536. searchable: false,
  537. defaultContent: ''
  538. },
  539. {
  540. title: lang.mailbox_quota,
  541. data: 'max_quota_for_mbox',
  542. searchable: false,
  543. defaultContent: ''
  544. },
  545. {
  546. title: 'RL',
  547. data: 'rl',
  548. searchable: false,
  549. orderable: false,
  550. defaultContent: ''
  551. },
  552. {
  553. title: lang.backup_mx,
  554. data: 'backupmx',
  555. searchable: false,
  556. defaultContent: '',
  557. render: function (data, type){
  558. return 1==data ? '<i class="bi bi-check-lg"></i>' : 0==data && '<i class="bi bi-x-lg"></i>';
  559. }
  560. },
  561. {
  562. title: lang.domain_admins,
  563. data: 'domain_admins',
  564. searchable: false,
  565. orderable: false,
  566. defaultContent: '',
  567. className: 'none'
  568. },
  569. {
  570. title: lang.created_on,
  571. data: 'created',
  572. searchable: false,
  573. orderable: false,
  574. defaultContent: '',
  575. className: 'none'
  576. },
  577. {
  578. title: lang.last_modified,
  579. data: 'modified',
  580. searchable: false,
  581. orderable: false,
  582. defaultContent: '',
  583. className: 'none'
  584. },
  585. {
  586. title: 'Tags',
  587. data: 'tags',
  588. searchable: true,
  589. orderable: false,
  590. defaultContent: '',
  591. className: 'none'
  592. },
  593. {
  594. title: lang.active,
  595. data: 'active',
  596. searchable: false,
  597. defaultContent: '',
  598. responsivePriority: 6,
  599. render: function (data, type) {
  600. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
  601. }
  602. },
  603. {
  604. title: lang.action,
  605. data: 'action',
  606. searchable: false,
  607. orderable: false,
  608. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  609. responsivePriority: 5,
  610. defaultContent: ''
  611. },
  612. ]
  613. });
  614. table.on('responsive-resize', function (e, datatable, columns){
  615. hideTableExpandCollapseBtn('#tab-domains', '#domain_table');
  616. });
  617. }
  618. function draw_templates_domain_table() {
  619. // just recalc width if instance already exists
  620. if ($.fn.DataTable.isDataTable('#templates_domain_table') ) {
  621. $('#templates_domain_table').DataTable().columns.adjust().responsive.recalc();
  622. return;
  623. }
  624. var table = $('#templates_domain_table').DataTable({
  625. responsive: true,
  626. processing: true,
  627. serverSide: false,
  628. stateSave: true,
  629. pageLength: pagination_size,
  630. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  631. "tr" +
  632. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  633. language: lang_datatables,
  634. order: [[2, 'desc']],
  635. initComplete: function(){
  636. hideTableExpandCollapseBtn('#tab-templates-domains', '#templates_domain_table');
  637. },
  638. ajax: {
  639. type: "GET",
  640. url: "/api/v1/get/domain/template/all",
  641. dataSrc: function(json){
  642. $.each(json, function (i, item) {
  643. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="domain_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  644. item.attributes.def_quota_for_mbox = humanFileSize(item.attributes.def_quota_for_mbox);
  645. item.attributes.max_quota_for_mbox = humanFileSize(item.attributes.max_quota_for_mbox);
  646. item.attributes.max_quota_for_domain = humanFileSize(item.attributes.max_quota_for_domain);
  647. item.template = escapeHtml(item.template);
  648. if (item.attributes.rl_frame === "s"){
  649. item.attributes.rl_frame = lang_rl.second;
  650. } else if (item.attributes.rl_frame === "m"){
  651. item.attributes.rl_frame = lang_rl.minute;
  652. } else if (item.attributes.rl_frame === "h"){
  653. item.attributes.rl_frame = lang_rl.hour;
  654. } else if (item.attributes.rl_frame === "d"){
  655. item.attributes.rl_frame = lang_rl.day;
  656. }
  657. item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
  658. if (item.template.toLowerCase() == "default"){
  659. item.action = '<div class="btn-group">' +
  660. '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  661. '</div>';
  662. }
  663. else {
  664. item.action = '<div class="btn-group">' +
  665. '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  666. '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/domain/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  667. '</div>';
  668. }
  669. if (Array.isArray(item.attributes.tags)){
  670. var tags = '';
  671. for (var i = 0; i < item.attributes.tags.length; i++)
  672. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
  673. item.attributes.tags = tags;
  674. } else {
  675. item.attributes.tags = '';
  676. }
  677. });
  678. return json;
  679. }
  680. },
  681. columns: [
  682. {
  683. // placeholder, so checkbox will not block child row toggle
  684. title: '',
  685. data: null,
  686. searchable: false,
  687. orderable: false,
  688. defaultContent: '',
  689. responsivePriority: 1
  690. },
  691. {
  692. title: '',
  693. data: 'chkbox',
  694. searchable: false,
  695. orderable: false,
  696. defaultContent: '',
  697. responsivePriority: 1
  698. },
  699. {
  700. title: "ID",
  701. data: 'id',
  702. responsivePriority: 2,
  703. defaultContent: ''
  704. },
  705. {
  706. title: lang.template,
  707. data: 'template',
  708. responsivePriority: 3,
  709. defaultContent: ''
  710. },
  711. {
  712. title: lang.max_aliases,
  713. data: 'attributes.max_num_aliases_for_domain',
  714. defaultContent: '',
  715. },
  716. {
  717. title: lang.max_mailboxes,
  718. data: 'attributes.max_num_mboxes_for_domain',
  719. defaultContent: '',
  720. },
  721. {
  722. title: lang.mailbox_defquota,
  723. data: 'attributes.def_quota_for_mbox',
  724. defaultContent: '',
  725. },
  726. {
  727. title: lang.max_quota,
  728. data: 'attributes.max_quota_for_mbox',
  729. defaultContent: '',
  730. },
  731. {
  732. title: lang.domain_quota_total,
  733. data: 'attributes.max_quota_for_domain',
  734. defaultContent: '',
  735. },
  736. {
  737. title: lang.gal,
  738. data: 'attributes.gal',
  739. defaultContent: '',
  740. render: function (data, type) {
  741. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  742. }
  743. },
  744. {
  745. title: lang.backup_mx,
  746. data: 'attributes.backupmx',
  747. defaultContent: '',
  748. render: function (data, type) {
  749. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  750. }
  751. },
  752. {
  753. title: lang.relay_all,
  754. data: 'attributes.relay_all_recipients',
  755. defaultContent: '',
  756. render: function (data, type) {
  757. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  758. }
  759. },
  760. {
  761. title: lang.relay_unknown,
  762. data: 'attributes.relay_unknown_only',
  763. defaultContent: '',
  764. render: function (data, type) {
  765. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  766. }
  767. },
  768. {
  769. title: lang.active,
  770. data: 'attributes.active',
  771. defaultContent: '',
  772. responsivePriority: 4,
  773. render: function (data, type) {
  774. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  775. }
  776. },
  777. {
  778. title: 'rl_frame',
  779. data: 'attributes.rl_frame',
  780. defaultContent: '',
  781. class: 'none',
  782. },
  783. {
  784. title: 'rl_value',
  785. data: 'attributes.rl_value',
  786. defaultContent: '',
  787. class: 'none',
  788. },
  789. {
  790. title: lang.dkim_domains_selector,
  791. data: 'attributes.dkim_selector',
  792. defaultContent: '',
  793. class: 'none',
  794. },
  795. {
  796. title: lang.dkim_key_length,
  797. data: 'attributes.key_size',
  798. defaultContent: '',
  799. class: 'none',
  800. },
  801. {
  802. title: 'Tags',
  803. data: 'attributes.tags',
  804. defaultContent: '',
  805. className: 'none'
  806. },
  807. {
  808. title: lang.action,
  809. data: 'action',
  810. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  811. responsivePriority: 6,
  812. defaultContent: ''
  813. },
  814. ]
  815. });
  816. table.on('responsive-resize', function (e, datatable, columns){
  817. hideTableExpandCollapseBtn('#tab-templates-domains', '#templates_domain_table');
  818. });
  819. }
  820. function draw_mailbox_table() {
  821. // just recalc width if instance already exists
  822. if ($.fn.DataTable.isDataTable('#mailbox_table') ) {
  823. $('#mailbox_table').DataTable().columns.adjust().responsive.recalc();
  824. return;
  825. }
  826. var table = $('#mailbox_table').DataTable({
  827. responsive: true,
  828. processing: true,
  829. serverSide: true,
  830. stateSave: true,
  831. pageLength: pagination_size,
  832. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  833. "tr" +
  834. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  835. language: lang_datatables,
  836. initComplete: function(settings, json){
  837. hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table');
  838. },
  839. ajax: {
  840. type: "GET",
  841. url: "/api/v1/get/mailbox/datatables",
  842. dataSrc: function(json){
  843. $.each(json.data, function (i, item) {
  844. item.quota = {
  845. sortBy: item.quota_used,
  846. value: item.quota
  847. }
  848. item.quota.value = (item.quota.value == 0 ? "∞" : humanFileSize(item.quota.value));
  849. item.quota.value = humanFileSize(item.quota_used) + "/" + item.quota.value;
  850. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  851. item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login + '/' + item.last_sso_login;
  852. /*
  853. if (!item.rl) {
  854. item.rl = '∞';
  855. } else {
  856. item.rl = $.map(item.rl, function(e){
  857. return e;
  858. }).join('/1');
  859. if (item.rl_scope === 'domain') {
  860. item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
  861. }
  862. }
  863. */
  864. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  865. if (item.attributes.passwd_update != '0') {
  866. var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
  867. item.last_pw_change = last_pw_change.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
  868. } else {
  869. item.last_pw_change = '-';
  870. }
  871. item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  872. item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  873. item.pop3_access = '<i class="text-' + (item.attributes.pop3_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.pop3_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  874. item.imap_access = '<i class="text-' + (item.attributes.imap_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.imap_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  875. item.smtp_access = '<i class="text-' + (item.attributes.smtp_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.smtp_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  876. item.sieve_access = '<i class="text-' + (item.attributes.sieve_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sieve_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  877. if (item.attributes.quarantine_notification === 'never') {
  878. item.quarantine_notification = lang.never;
  879. } else if (item.attributes.quarantine_notification === 'hourly') {
  880. item.quarantine_notification = lang.hourly;
  881. } else if (item.attributes.quarantine_notification === 'daily') {
  882. item.quarantine_notification = lang.daily;
  883. } else if (item.attributes.quarantine_notification === 'weekly') {
  884. item.quarantine_notification = lang.weekly;
  885. }
  886. if (item.attributes.quarantine_category === 'reject') {
  887. item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  888. } else if (item.attributes.quarantine_category === 'add_header') {
  889. item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  890. } else if (item.attributes.quarantine_category === 'all') {
  891. item.quarantine_category = lang.q_all;
  892. }
  893. if (acl_data.login_as === 1) {
  894. item.action = '<div class="btn-group">' +
  895. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  896. '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  897. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-lg btn-xs-half btn-success"><i class="bi bi-person-fill"></i> Login</a>';
  898. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  899. item.action += '<a href="/sogo-auth.php?login=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-lg btn-xs-half btn-primary" target="_blank"><i class="bi bi-envelope-fill"></i> SOGo</a>';
  900. }
  901. item.action += '</div>';
  902. }
  903. else {
  904. item.action = '<div class="btn-group">' +
  905. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  906. '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  907. '</div>';
  908. }
  909. item.in_use = {
  910. sortBy: item.percent_in_use,
  911. value: '<div class="progress">' +
  912. '<div class="progress-bar-mailbox progress-bar progress-bar-' + item.percent_class + '" role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
  913. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>'
  914. };
  915. item.username = escapeHtml(item.username);
  916. if (Array.isArray(item.tags)){
  917. var tags = '';
  918. for (var i = 0; i < item.tags.length; i++)
  919. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
  920. item.tags = tags;
  921. } else {
  922. item.tags = '';
  923. }
  924. });
  925. return json.data;
  926. }
  927. },
  928. columns: [
  929. {
  930. // placeholder, so checkbox will not block child row toggle
  931. title: '',
  932. data: null,
  933. searchable: false,
  934. orderable: false,
  935. defaultContent: '',
  936. responsivePriority: 1
  937. },
  938. {
  939. title: '',
  940. data: 'chkbox',
  941. searchable: false,
  942. orderable: false,
  943. defaultContent: '',
  944. responsivePriority: 2
  945. },
  946. {
  947. title: lang.username,
  948. data: 'username',
  949. responsivePriority: 3,
  950. defaultContent: ''
  951. },
  952. {
  953. title: lang.domain_quota,
  954. data: 'quota.value',
  955. searchable: false,
  956. responsivePriority: 8,
  957. defaultContent: ''
  958. },
  959. {
  960. title: lang.last_mail_login,
  961. data: 'last_mail_login',
  962. searchable: false,
  963. defaultContent: '',
  964. responsivePriority: 7,
  965. render: function (data, type) {
  966. res = data.split("/");
  967. return '<div class="badge bg-info mb-2">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' +
  968. '<div class="badge bg-info mb-2">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' +
  969. '<div class="badge bg-info">SMTP @ ' + unix_time_format(Number(res[2])) + '</div><br>' +
  970. '<div class="badge bg-info">SSO @ ' + unix_time_format(Number(res[3])) + '</div>';
  971. }
  972. },
  973. {
  974. title: lang.last_pw_change,
  975. data: 'last_pw_change',
  976. searchable: false,
  977. defaultContent: ''
  978. },
  979. {
  980. title: lang.in_use,
  981. data: 'in_use.value',
  982. searchable: false,
  983. defaultContent: '',
  984. responsivePriority: 9,
  985. className: 'dt-data-w100'
  986. },
  987. {
  988. title: lang.fname,
  989. data: 'name',
  990. defaultContent: '',
  991. className: 'none'
  992. },
  993. {
  994. title: lang.domain,
  995. data: 'domain',
  996. defaultContent: '',
  997. className: 'none'
  998. },
  999. {
  1000. title: lang.tls_enforce_in,
  1001. data: 'tls_enforce_in',
  1002. defaultContent: '',
  1003. className: 'none'
  1004. },
  1005. {
  1006. title: lang.tls_enforce_out,
  1007. data: 'tls_enforce_out',
  1008. defaultContent: '',
  1009. className: 'none'
  1010. },
  1011. {
  1012. title: 'SMTP',
  1013. data: 'smtp_access',
  1014. defaultContent: '',
  1015. className: 'none'
  1016. },
  1017. {
  1018. title: 'IMAP',
  1019. data: 'imap_access',
  1020. defaultContent: '',
  1021. className: 'none'
  1022. },
  1023. {
  1024. title: 'POP3',
  1025. data: 'pop3_access',
  1026. defaultContent: '',
  1027. className: 'none'
  1028. },
  1029. {
  1030. title: 'SIEVE',
  1031. data: 'sieve_access',
  1032. defaultContent: '',
  1033. className: 'none'
  1034. },
  1035. {
  1036. title: lang.quarantine_notification,
  1037. data: 'quarantine_notification',
  1038. defaultContent: '',
  1039. className: 'none'
  1040. },
  1041. {
  1042. title: lang.quarantine_category,
  1043. data: 'quarantine_category',
  1044. defaultContent: '',
  1045. className: 'none'
  1046. },
  1047. {
  1048. title: lang.msg_num,
  1049. data: 'messages',
  1050. searchable: false,
  1051. defaultContent: '',
  1052. responsivePriority: 5
  1053. },
  1054. {
  1055. title: lang.created_on,
  1056. data: 'created',
  1057. defaultContent: '',
  1058. className: 'none'
  1059. },
  1060. {
  1061. title: lang.last_modified,
  1062. data: 'modified',
  1063. defaultContent: '',
  1064. className: 'none'
  1065. },
  1066. {
  1067. title: 'Tags',
  1068. data: 'tags',
  1069. searchable: true,
  1070. defaultContent: '',
  1071. className: 'none'
  1072. },
  1073. {
  1074. title: lang.active,
  1075. data: 'active',
  1076. searchable: false,
  1077. defaultContent: '',
  1078. responsivePriority: 4,
  1079. render: function (data, type) {
  1080. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
  1081. }
  1082. },
  1083. {
  1084. title: lang.action,
  1085. data: 'action',
  1086. searchable: false,
  1087. orderable: false,
  1088. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1089. responsivePriority: 6,
  1090. defaultContent: ''
  1091. }
  1092. ]
  1093. });
  1094. table.on('responsive-resize', function (e, datatable, columns){
  1095. hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table');
  1096. });
  1097. }
  1098. function draw_templates_mbox_table() {
  1099. // just recalc width if instance already exists
  1100. if ($.fn.DataTable.isDataTable('#templates_mbox_table') ) {
  1101. $('#templates_mbox_table').DataTable().columns.adjust().responsive.recalc();
  1102. return;
  1103. }
  1104. var table = $('#templates_mbox_table').DataTable({
  1105. responsive: true,
  1106. processing: true,
  1107. serverSide: false,
  1108. stateSave: true,
  1109. pageLength: pagination_size,
  1110. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1111. "tr" +
  1112. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1113. language: lang_datatables,
  1114. order: [[2, 'desc']],
  1115. initComplete: function(){
  1116. hideTableExpandCollapseBtn('#tab-templates-mbox', '#templates_mbox_table');
  1117. },
  1118. ajax: {
  1119. type: "GET",
  1120. url: "/api/v1/get/mailbox/template/all",
  1121. dataSrc: function(json){
  1122. $.each(json, function (i, item) {
  1123. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailbox_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  1124. item.template = escapeHtml(item.template);
  1125. if (item.attributes.rl_frame === "s"){
  1126. item.attributes.rl_frame = lang_rl.second;
  1127. } else if (item.attributes.rl_frame === "m"){
  1128. item.attributes.rl_frame = lang_rl.minute;
  1129. } else if (item.attributes.rl_frame === "h"){
  1130. item.attributes.rl_frame = lang_rl.hour;
  1131. } else if (item.attributes.rl_frame === "d"){
  1132. item.attributes.rl_frame = lang_rl.day;
  1133. }
  1134. item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
  1135. item.attributes.quota = humanFileSize(item.attributes.quota);
  1136. item.attributes.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"><span class="sorting-value">' + (item.attributes.tls_enforce_in == 1 ? '1' : '0') + '</span></i>';
  1137. item.attributes.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"><span class="sorting-value">' + (item.attributes.tls_enforce_out == 1 ? '1' : '0') + '</span></i>';
  1138. item.attributes.pop3_access = '<i class="text-' + (item.attributes.pop3_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.pop3_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.pop3_access == 1 ? '1' : '0') + '</span></i>';
  1139. item.attributes.imap_access = '<i class="text-' + (item.attributes.imap_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.imap_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.imap_access == 1 ? '1' : '0') + '</span></i>';
  1140. item.attributes.smtp_access = '<i class="text-' + (item.attributes.smtp_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.smtp_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.smtp_access == 1 ? '1' : '0') + '</span></i>';
  1141. item.attributes.sieve_access = '<i class="text-' + (item.attributes.sieve_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sieve_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.sieve_access == 1 ? '1' : '0') + '</span></i>';
  1142. item.attributes.sogo_access = '<i class="text-' + (item.attributes.sogo_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sogo_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.sogo_access == 1 ? '1' : '0') + '</span></i>';
  1143. if (item.attributes.quarantine_notification === 'never') {
  1144. item.attributes.quarantine_notification = lang.never;
  1145. } else if (item.attributes.quarantine_notification === 'hourly') {
  1146. item.attributes.quarantine_notification = lang.hourly;
  1147. } else if (item.attributes.quarantine_notification === 'daily') {
  1148. item.attributes.quarantine_notification = lang.daily;
  1149. } else if (item.attributes.quarantine_notification === 'weekly') {
  1150. item.attributes.quarantine_notification = lang.weekly;
  1151. }
  1152. if (item.attributes.quarantine_category === 'reject') {
  1153. item.attributes.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  1154. } else if (item.attributes.quarantine_category === 'add_header') {
  1155. item.attributes.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  1156. } else if (item.attributes.quarantine_category === 'all') {
  1157. item.attributes.quarantine_category = lang.q_all;
  1158. }
  1159. if (item.template.toLowerCase() == "default"){
  1160. item.action = '<div class="btn-group">' +
  1161. '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1162. '</div>';
  1163. }
  1164. else {
  1165. item.action = '<div class="btn-group">' +
  1166. '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1167. '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/mailbox/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1168. '</div>';
  1169. }
  1170. if (Array.isArray(item.attributes.tags)){
  1171. var tags = '';
  1172. for (var i = 0; i < item.attributes.tags.length; i++)
  1173. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
  1174. item.attributes.tags = tags;
  1175. } else {
  1176. item.attributes.tags = '';
  1177. }
  1178. });
  1179. return json;
  1180. }
  1181. },
  1182. columns: [
  1183. {
  1184. // placeholder, so checkbox will not block child row toggle
  1185. title: '',
  1186. data: null,
  1187. searchable: false,
  1188. orderable: false,
  1189. defaultContent: '',
  1190. responsivePriority: 1
  1191. },
  1192. {
  1193. title: '',
  1194. data: 'chkbox',
  1195. searchable: false,
  1196. orderable: false,
  1197. defaultContent: '',
  1198. responsivePriority: 1
  1199. },
  1200. {
  1201. title: "ID",
  1202. data: 'id',
  1203. responsivePriority: 2,
  1204. defaultContent: ''
  1205. },
  1206. {
  1207. title: lang.template,
  1208. data: 'template',
  1209. responsivePriority: 3,
  1210. defaultContent: ''
  1211. },
  1212. {
  1213. title: lang.domain_quota,
  1214. data: 'attributes.quota',
  1215. defaultContent: '',
  1216. },
  1217. {
  1218. title: lang.tls_enforce_in,
  1219. data: 'attributes.tls_enforce_in',
  1220. defaultContent: ''
  1221. },
  1222. {
  1223. title: lang.tls_enforce_out,
  1224. data: 'attributes.tls_enforce_out',
  1225. defaultContent: ''
  1226. },
  1227. {
  1228. title: 'SMTP',
  1229. data: 'attributes.smtp_access',
  1230. defaultContent: '',
  1231. },
  1232. {
  1233. title: 'IMAP',
  1234. data: 'attributes.imap_access',
  1235. defaultContent: '',
  1236. },
  1237. {
  1238. title: 'POP3',
  1239. data: 'attributes.pop3_access',
  1240. defaultContent: '',
  1241. },
  1242. {
  1243. title: 'SIEVE',
  1244. data: 'attributes.sieve_access',
  1245. defaultContent: '',
  1246. },
  1247. {
  1248. title: 'SOGO',
  1249. data: 'attributes.sogo_access',
  1250. defaultContent: '',
  1251. },
  1252. {
  1253. title: lang.quarantine_notification,
  1254. data: 'attributes.quarantine_notification',
  1255. defaultContent: '',
  1256. className: 'none'
  1257. },
  1258. {
  1259. title: lang.quarantine_category,
  1260. data: 'attributes.quarantine_category',
  1261. defaultContent: '',
  1262. className: 'none'
  1263. },
  1264. {
  1265. title: lang.force_pw_update,
  1266. data: 'attributes.force_pw_update',
  1267. defaultContent: '',
  1268. class: 'none',
  1269. render: function (data, type) {
  1270. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  1271. }
  1272. },
  1273. {
  1274. title: "rl_frame",
  1275. data: 'attributes.rl_frame',
  1276. defaultContent: '',
  1277. class: 'none',
  1278. },
  1279. {
  1280. title: 'rl_value',
  1281. data: 'attributes.rl_value',
  1282. defaultContent: '',
  1283. class: 'none',
  1284. },
  1285. {
  1286. title: 'Tags',
  1287. data: 'attributes.tags',
  1288. defaultContent: '',
  1289. className: 'none'
  1290. },
  1291. {
  1292. title: lang.active,
  1293. data: 'attributes.active',
  1294. defaultContent: '',
  1295. responsivePriority: 4,
  1296. render: function (data, type) {
  1297. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
  1298. }
  1299. },
  1300. {
  1301. title: lang.action,
  1302. data: 'action',
  1303. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1304. responsivePriority: 6,
  1305. defaultContent: ''
  1306. },
  1307. ]
  1308. });
  1309. table.on('responsive-resize', function (e, datatable, columns){
  1310. hideTableExpandCollapseBtn('#tab-templates-mbox', '#templates_mbox_table');
  1311. });
  1312. }
  1313. function draw_resource_table() {
  1314. // just recalc width if instance already exists
  1315. if ($.fn.DataTable.isDataTable('#resource_table') ) {
  1316. $('#resource_table').DataTable().columns.adjust().responsive.recalc();
  1317. return;
  1318. }
  1319. var table = $('#resource_table').DataTable({
  1320. responsive: true,
  1321. processing: true,
  1322. serverSide: false,
  1323. stateSave: true,
  1324. pageLength: pagination_size,
  1325. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1326. "tr" +
  1327. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1328. language: lang_datatables,
  1329. initComplete: function(settings, json){
  1330. hideTableExpandCollapseBtn('#tab-resources', '#resource_table');
  1331. filterByDomain(json, 5, table);
  1332. },
  1333. ajax: {
  1334. type: "GET",
  1335. url: "/api/v1/get/resource/all",
  1336. dataSrc: function(json){
  1337. $.each(json, function (i, item) {
  1338. if (item.multiple_bookings == '0') {
  1339. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-success">' + lang.booking_0_short + '</span>';
  1340. } else if (item.multiple_bookings == '-1') {
  1341. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-warning">' + lang.booking_lt0_short + '</span>';
  1342. } else {
  1343. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  1344. }
  1345. item.action = '<div class="btn-group">' +
  1346. '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1347. '<a href="#" data-action="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + item.name + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1348. '</div>';
  1349. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  1350. item.name = escapeHtml(item.name);
  1351. item.description = escapeHtml(item.description);
  1352. });
  1353. return json;
  1354. }
  1355. },
  1356. columns: [
  1357. {
  1358. // placeholder, so checkbox will not block child row toggle
  1359. title: '',
  1360. data: null,
  1361. searchable: false,
  1362. orderable: false,
  1363. defaultContent: '',
  1364. responsivePriority: 1
  1365. },
  1366. {
  1367. title: '',
  1368. data: 'chkbox',
  1369. searchable: false,
  1370. orderable: false,
  1371. defaultContent: '',
  1372. responsivePriority: 2
  1373. },
  1374. {
  1375. title: lang.description,
  1376. data: 'description',
  1377. responsivePriority: 3,
  1378. defaultContent: ''
  1379. },
  1380. {
  1381. title: lang.alias,
  1382. data: 'name',
  1383. defaultContent: ''
  1384. },
  1385. {
  1386. title: lang.kind,
  1387. data: 'kind',
  1388. defaultContent: ''
  1389. },
  1390. {
  1391. title: lang.domain,
  1392. data: 'domain',
  1393. responsivePriority: 4,
  1394. defaultContent: ''
  1395. },
  1396. {
  1397. title: lang.multiple_bookings,
  1398. data: 'multiple_bookings',
  1399. defaultContent: ''
  1400. },
  1401. {
  1402. title: lang.active,
  1403. data: 'active',
  1404. defaultContent: '',
  1405. render: function (data, type) {
  1406. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
  1407. }
  1408. },
  1409. {
  1410. title: lang.action,
  1411. data: 'action',
  1412. responsivePriority: 5,
  1413. defaultContent: '',
  1414. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right'
  1415. },
  1416. ]
  1417. });
  1418. table.on('responsive-resize', function (e, datatable, columns){
  1419. hideTableExpandCollapseBtn('#tab-resources', '#resource_table');
  1420. });
  1421. }
  1422. function draw_bcc_table() {
  1423. $.get("/api/v1/get/bcc-destination-options", function(data){
  1424. var optgroup = "";
  1425. // Domains
  1426. if (data.domains && data.domains.length > 0) {
  1427. optgroup = "<optgroup label='" + lang.domains + "'>";
  1428. $.each(data.domains, function(index, domain){
  1429. optgroup += "<option value='" + domain + "'>" + domain + "</option>";
  1430. });
  1431. optgroup += "</optgroup>";
  1432. $('#bcc-local-dest').append(optgroup);
  1433. }
  1434. // Alias domains
  1435. if (data.alias_domains && data.alias_domains.length > 0) {
  1436. optgroup = "<optgroup label='" + lang.domain_aliases + "'>";
  1437. $.each(data.alias_domains, function(index, alias_domain){
  1438. optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>";
  1439. });
  1440. optgroup += "</optgroup>"
  1441. $('#bcc-local-dest').append(optgroup);
  1442. }
  1443. // Mailboxes and aliases
  1444. if (data.mailboxes && Object.keys(data.mailboxes).length > 0) {
  1445. $.each(data.mailboxes, function(mailbox, aliases){
  1446. optgroup = "<optgroup label='" + mailbox + "'>";
  1447. $.each(aliases, function(index, alias){
  1448. optgroup += "<option value='" + alias + "'>" + alias + "</option>";
  1449. });
  1450. optgroup += "</optgroup>";
  1451. $('#bcc-local-dest').append(optgroup);
  1452. });
  1453. }
  1454. // Recreate picker
  1455. $('#bcc-local-dest').selectpicker('refresh');
  1456. });
  1457. // just recalc width if instance already exists
  1458. if ($.fn.DataTable.isDataTable('#bcc_table') ) {
  1459. $('#bcc_table').DataTable().columns.adjust().responsive.recalc();
  1460. return;
  1461. }
  1462. var table = $('#bcc_table').DataTable({
  1463. responsive: true,
  1464. processing: true,
  1465. serverSide: false,
  1466. stateSave: true,
  1467. pageLength: pagination_size,
  1468. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1469. "tr" +
  1470. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1471. language: lang_datatables,
  1472. order: [[2, 'desc']],
  1473. initComplete: function(settings, json){
  1474. hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table');
  1475. filterByDomain(json, 6, table);
  1476. },
  1477. ajax: {
  1478. type: "GET",
  1479. url: "/api/v1/get/bcc/all",
  1480. dataSrc: function(json){
  1481. $.each(json, function (i, item) {
  1482. item.action = '<div class="btn-group">' +
  1483. '<a href="/edit/bcc/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1484. '<a href="#" data-action="delete_selected" data-id="single-bcc" data-api-url="delete/bcc" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1485. '</div>';
  1486. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  1487. item.local_dest = escapeHtml(item.local_dest);
  1488. item.bcc_dest = escapeHtml(item.bcc_dest);
  1489. if (item.type == 'sender') {
  1490. item.type = '<span id="active-script" class="badge fs-6 bg-success">' + lang.bcc_sender_map + '</span>';
  1491. } else {
  1492. item.type = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.bcc_rcpt_map + '</span>';
  1493. }
  1494. });
  1495. return json;
  1496. }
  1497. },
  1498. columns: [
  1499. {
  1500. // placeholder, so checkbox will not block child row toggle
  1501. title: '',
  1502. data: null,
  1503. searchable: false,
  1504. orderable: false,
  1505. defaultContent: '',
  1506. responsivePriority: 1
  1507. },
  1508. {
  1509. title: '',
  1510. data: 'chkbox',
  1511. searchable: false,
  1512. orderable: false,
  1513. defaultContent: '',
  1514. responsivePriority: 2
  1515. },
  1516. {
  1517. title: 'ID',
  1518. data: 'id',
  1519. responsivePriority: 3,
  1520. defaultContent: ''
  1521. },
  1522. {
  1523. title: lang.bcc_type,
  1524. data: 'type',
  1525. defaultContent: ''
  1526. },
  1527. {
  1528. title: lang.bcc_local_dest,
  1529. data: 'local_dest',
  1530. defaultContent: ''
  1531. },
  1532. {
  1533. title: lang.bcc_destinations,
  1534. data: 'bcc_dest',
  1535. defaultContent: ''
  1536. },
  1537. {
  1538. title: lang.domain,
  1539. data: 'domain',
  1540. responsivePriority: 4,
  1541. defaultContent: ''
  1542. },
  1543. {
  1544. title: lang.active,
  1545. data: 'active',
  1546. defaultContent: '',
  1547. render: function (data, type) {
  1548. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
  1549. }
  1550. },
  1551. {
  1552. title: lang.action,
  1553. data: 'action',
  1554. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1555. responsivePriority: 5,
  1556. defaultContent: ''
  1557. },
  1558. ]
  1559. });
  1560. table.on('responsive-resize', function (e, datatable, columns){
  1561. hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table');
  1562. });
  1563. }
  1564. function draw_recipient_map_table() {
  1565. // just recalc width if instance already exists
  1566. if ($.fn.DataTable.isDataTable('#recipient_map_table') ) {
  1567. $('#recipient_map_table').DataTable().columns.adjust().responsive.recalc();
  1568. return;
  1569. }
  1570. var table = $('#recipient_map_table').DataTable({
  1571. responsive: true,
  1572. processing: true,
  1573. serverSide: false,
  1574. stateSave: true,
  1575. pageLength: pagination_size,
  1576. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1577. "tr" +
  1578. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1579. language: lang_datatables,
  1580. order: [[2, 'desc']],
  1581. initComplete: function(){
  1582. hideTableExpandCollapseBtn('#collapse-tab-bcc-filters', '#recipient_map_table');
  1583. },
  1584. ajax: {
  1585. type: "GET",
  1586. url: "/api/v1/get/recipient_map/all",
  1587. dataSrc: function(json){
  1588. if (role !== "admin") return null;
  1589. $.each(json, function (i, item) {
  1590. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  1591. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  1592. item.action = '<div class="btn-group">' +
  1593. '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1594. '<a href="#" data-action="delete_selected" data-id="single-recipient_map" data-api-url="delete/recipient_map" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1595. '</div>';
  1596. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  1597. });
  1598. return json;
  1599. }
  1600. },
  1601. columns: [
  1602. {
  1603. // placeholder, so checkbox will not block child row toggle
  1604. title: '',
  1605. data: null,
  1606. searchable: false,
  1607. orderable: false,
  1608. defaultContent: '',
  1609. responsivePriority: 1
  1610. },
  1611. {
  1612. title: '',
  1613. data: 'chkbox',
  1614. searchable: false,
  1615. orderable: false,
  1616. defaultContent: '',
  1617. responsivePriority: 2
  1618. },
  1619. {
  1620. title: 'ID',
  1621. data: 'id',
  1622. responsivePriority: 3,
  1623. defaultContent: ''
  1624. },
  1625. {
  1626. title: lang.recipient_map_old,
  1627. data: 'recipient_map_old',
  1628. defaultContent: ''
  1629. },
  1630. {
  1631. title: lang.recipient_map_new,
  1632. data: 'recipient_map_new',
  1633. defaultContent: '',
  1634. responsivePriority: 4
  1635. },
  1636. {
  1637. title: lang.active,
  1638. data: 'active',
  1639. defaultContent: '',
  1640. render: function (data, type) {
  1641. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  1642. }
  1643. },
  1644. {
  1645. title: lang.action,
  1646. data: 'action',
  1647. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1648. responsivePriority: 5,
  1649. defaultContent: ''
  1650. },
  1651. ]
  1652. });
  1653. table.on('responsive-resize', function (e, datatable, columns){
  1654. hideTableExpandCollapseBtn('#collapse-tab-bcc-filters', '#recipient_map_table');
  1655. });
  1656. }
  1657. function draw_tls_policy_table() {
  1658. // just recalc width if instance already exists
  1659. if ($.fn.DataTable.isDataTable('#tls_policy_table') ) {
  1660. $('#tls_policy_table').DataTable().columns.adjust().responsive.recalc();
  1661. return;
  1662. }
  1663. var table = $('#tls_policy_table').DataTable({
  1664. responsive: true,
  1665. processing: true,
  1666. serverSide: false,
  1667. stateSave: true,
  1668. pageLength: pagination_size,
  1669. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1670. "tr" +
  1671. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1672. language: lang_datatables,
  1673. order: [[2, 'desc']],
  1674. initComplete: function(){
  1675. hideTableExpandCollapseBtn('#tab-tls-policy', '#tls_policy_table');
  1676. },
  1677. ajax: {
  1678. type: "GET",
  1679. url: "/api/v1/get/tls-policy-map/all",
  1680. dataSrc: function(json){
  1681. if (role !== "admin") return null;
  1682. $.each(json, function (i, item) {
  1683. item.dest = escapeHtml(item.dest);
  1684. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  1685. if (item.parameters == '') {
  1686. item.parameters = '<code>-</code>';
  1687. } else {
  1688. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  1689. }
  1690. item.action = '<div class="btn-group">' +
  1691. '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1692. '<a href="#" data-action="delete_selected" data-id="single-tls-policy-map" data-api-url="delete/tls-policy-map" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1693. '</div>';
  1694. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  1695. });
  1696. return json;
  1697. }
  1698. },
  1699. columns: [
  1700. {
  1701. // placeholder, so checkbox will not block child row toggle
  1702. title: '',
  1703. data: null,
  1704. searchable: false,
  1705. orderable: false,
  1706. defaultContent: '',
  1707. responsivePriority: 1
  1708. },
  1709. {
  1710. title: '',
  1711. data: 'chkbox',
  1712. searchable: false,
  1713. orderable: false,
  1714. defaultContent: '',
  1715. responsivePriority: 2
  1716. },
  1717. {
  1718. title: 'ID',
  1719. data: 'id',
  1720. responsivePriority: 3,
  1721. defaultContent: ''
  1722. },
  1723. {
  1724. title: lang.tls_map_dest,
  1725. data: 'dest',
  1726. defaultContent: '',
  1727. responsivePriority: 4
  1728. },
  1729. {
  1730. title: lang.tls_map_policy,
  1731. data: 'policy',
  1732. defaultContent: ''
  1733. },
  1734. {
  1735. title: lang.tls_map_parameters,
  1736. data: 'parameters',
  1737. defaultContent: ''
  1738. },
  1739. {
  1740. title: lang.active,
  1741. data: 'active',
  1742. defaultContent: '',
  1743. render: function (data, type) {
  1744. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  1745. }
  1746. },
  1747. {
  1748. title: lang.action,
  1749. data: 'action',
  1750. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1751. responsivePriority: 5,
  1752. defaultContent: ''
  1753. },
  1754. ]
  1755. });
  1756. table.on('responsive-resize', function (e, datatable, columns){
  1757. hideTableExpandCollapseBtn('#tab-tls-policy', '#tls_policy_table');
  1758. });
  1759. }
  1760. function draw_alias_table() {
  1761. // just recalc width if instance already exists
  1762. if ($.fn.DataTable.isDataTable('#alias_table') ) {
  1763. $('#alias_table').DataTable().columns.adjust().responsive.recalc();
  1764. return;
  1765. }
  1766. var table = $('#alias_table').DataTable({
  1767. responsive: true,
  1768. processing: true,
  1769. serverSide: false,
  1770. stateSave: true,
  1771. pageLength: pagination_size,
  1772. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1773. "tr" +
  1774. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1775. language: lang_datatables,
  1776. order: [[2, 'desc']],
  1777. initComplete: function(settings, json){
  1778. hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table');
  1779. filterByDomain(json, 5, table);
  1780. },
  1781. ajax: {
  1782. type: "GET",
  1783. url: "/api/v1/get/alias/all",
  1784. dataSrc: function(json){
  1785. $.each(json, function (i, item) {
  1786. item.action = '<div class="btn-group">' +
  1787. '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1788. '<a href="#" data-action="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1789. '</div>';
  1790. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  1791. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  1792. if (item.public_comment !== null) {
  1793. item.public_comment = escapeHtml(item.public_comment);
  1794. }
  1795. else {
  1796. item.public_comment = '-';
  1797. }
  1798. if (item.private_comment !== null) {
  1799. item.private_comment = escapeHtml(item.private_comment);
  1800. }
  1801. else {
  1802. item.private_comment = '-';
  1803. }
  1804. if (item.is_catch_all == 1) {
  1805. item.address = '<div class="badge fs-6 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
  1806. }
  1807. else {
  1808. item.address = escapeHtml(item.address);
  1809. }
  1810. if (item.goto == "null@localhost") {
  1811. item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
  1812. }
  1813. else if (item.goto == "spam@localhost") {
  1814. item.goto = '<span class="badge fs-6 bg-danger">' + lang.goto_spam + '</span>';
  1815. }
  1816. else if (item.goto == "ham@localhost") {
  1817. item.goto = '<span class="badge fs-6 bg-success">' + lang.goto_ham + '</span>';
  1818. }
  1819. if (item.in_primary_domain !== "") {
  1820. item.domain = '<i data-domainname="' + item.domain + '" class="bi bi-info-circle-fill alias-domain-info text-info" data-bs-toggle="tooltip" title="' + lang.target_domain + ': ' + item.in_primary_domain + '"></i> ' + item.domain;
  1821. }
  1822. });
  1823. return json;
  1824. }
  1825. },
  1826. columns: [
  1827. {
  1828. // placeholder, so checkbox will not block child row toggle
  1829. title: '',
  1830. data: null,
  1831. searchable: false,
  1832. orderable: false,
  1833. defaultContent: '',
  1834. responsivePriority: 1
  1835. },
  1836. {
  1837. title: '',
  1838. data: 'chkbox',
  1839. searchable: false,
  1840. orderable: false,
  1841. defaultContent: '',
  1842. responsivePriority: 2
  1843. },
  1844. {
  1845. title: 'ID',
  1846. data: 'id',
  1847. responsivePriority: 3,
  1848. defaultContent: ''
  1849. },
  1850. {
  1851. title: lang.alias,
  1852. data: 'address',
  1853. responsivePriority: 4,
  1854. defaultContent: ''
  1855. },
  1856. {
  1857. title: lang.target_address,
  1858. data: 'goto',
  1859. defaultContent: ''
  1860. },
  1861. {
  1862. title: lang.domain,
  1863. data: 'domain',
  1864. defaultContent: '',
  1865. responsivePriority: 5,
  1866. },
  1867. {
  1868. title: lang.bcc_destinations,
  1869. data: 'bcc_dest',
  1870. defaultContent: ''
  1871. },
  1872. {
  1873. title: lang.sogo_visible,
  1874. data: 'sogo_visible',
  1875. defaultContent: '',
  1876. render: function(data, type){
  1877. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  1878. }
  1879. },
  1880. {
  1881. title: lang.public_comment,
  1882. data: 'public_comment',
  1883. defaultContent: ''
  1884. },
  1885. {
  1886. title: lang.private_comment,
  1887. data: 'private_comment',
  1888. defaultContent: ''
  1889. },
  1890. {
  1891. title: lang.active,
  1892. data: 'active',
  1893. defaultContent: '',
  1894. responsivePriority: 6,
  1895. render: function (data, type) {
  1896. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  1897. }
  1898. },
  1899. {
  1900. title: lang.action,
  1901. data: 'action',
  1902. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1903. responsivePriority: 5,
  1904. defaultContent: ''
  1905. },
  1906. ]
  1907. });
  1908. table.on('responsive-resize', function (e, datatable, columns){
  1909. hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table');
  1910. });
  1911. table.on( 'draw', function (){
  1912. $('#alias_table [data-bs-toggle="tooltip"]').tooltip();
  1913. });
  1914. }
  1915. function draw_aliasdomain_table() {
  1916. // just recalc width if instance already exists
  1917. if ($.fn.DataTable.isDataTable('#aliasdomain_table') ) {
  1918. $('#aliasdomain_table').DataTable().columns.adjust().responsive.recalc();
  1919. return;
  1920. }
  1921. var table = $('#aliasdomain_table').DataTable({
  1922. responsive: true,
  1923. processing: true,
  1924. serverSide: false,
  1925. stateSave: true,
  1926. pageLength: pagination_size,
  1927. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1928. "tr" +
  1929. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1930. language: lang_datatables,
  1931. initComplete: function(){
  1932. hideTableExpandCollapseBtn('#tab-domain-aliases', '#aliasdomain_table');
  1933. },
  1934. ajax: {
  1935. type: "GET",
  1936. url: "/api/v1/get/alias-domain/all",
  1937. dataSrc: function(json){
  1938. $.each(json, function (i, item) {
  1939. item.alias_domain = escapeHtml(item.alias_domain);
  1940. item.action = '<div class="btn-group">' +
  1941. '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-sm btn-xs-lg btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1942. '<a href="#" data-action="delete_selected" data-id="single-alias-domain" data-api-url="delete/alias-domain" data-item="' + encodeURIComponent(item.alias_domain) + '" class="btn btn-sm btn-xs-lg btn-xs-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1943. '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-xs-third btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><i class="bi bi-globe2"></i> DNS</a></div>' +
  1944. '</div>';
  1945. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  1946. if(item.parent_is_backupmx == '1') {
  1947. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a> <div class="badge fs-6 bg-warning">' + lang.alias_domain_backupmx + '</div></span>';
  1948. } else {
  1949. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  1950. }
  1951. });
  1952. return json;
  1953. }
  1954. },
  1955. columns: [
  1956. {
  1957. // placeholder, so checkbox will not block child row toggle
  1958. title: '',
  1959. data: null,
  1960. searchable: false,
  1961. orderable: false,
  1962. defaultContent: '',
  1963. responsivePriority: 1
  1964. },
  1965. {
  1966. title: '',
  1967. data: 'chkbox',
  1968. searchable: false,
  1969. orderable: false,
  1970. defaultContent: '',
  1971. responsivePriority: 2
  1972. },
  1973. {
  1974. title: lang.alias,
  1975. data: 'alias_domain',
  1976. responsivePriority: 3,
  1977. defaultContent: ''
  1978. },
  1979. {
  1980. title: lang.target_domain,
  1981. data: 'target_domain',
  1982. responsivePriority: 4,
  1983. defaultContent: ''
  1984. },
  1985. {
  1986. title: lang.active,
  1987. data: 'active',
  1988. defaultContent: '',
  1989. render: function (data, type) {
  1990. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  1991. }
  1992. },
  1993. {
  1994. title: lang.action,
  1995. data: 'action',
  1996. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1997. responsivePriority: 5,
  1998. defaultContent: ''
  1999. },
  2000. ]
  2001. });
  2002. table.on('responsive-resize', function (e, datatable, columns){
  2003. hideTableExpandCollapseBtn('#tab-domain-aliases', '#aliasdomain_table');
  2004. });
  2005. }
  2006. function draw_sync_job_table() {
  2007. // just recalc width if instance already exists
  2008. if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
  2009. $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
  2010. return;
  2011. }
  2012. var table = $('#sync_job_table').DataTable({
  2013. responsive: true,
  2014. processing: true,
  2015. serverSide: false,
  2016. stateSave: true,
  2017. pageLength: pagination_size,
  2018. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  2019. "tr" +
  2020. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  2021. language: lang_datatables,
  2022. order: [[2, 'desc']],
  2023. initComplete: function(){
  2024. hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table');
  2025. },
  2026. ajax: {
  2027. type: "GET",
  2028. url: "/api/v1/get/syncjobs/all/no_log",
  2029. dataSrc: function(json){
  2030. $.each(json, function (i, item) {
  2031. item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
  2032. item.user2 = escapeHtml(item.user2);
  2033. if (!item.exclude > 0) {
  2034. item.exclude = '-';
  2035. } else {
  2036. item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
  2037. }
  2038. item.server_w_port = escapeHtml(item.user1) + '@' + escapeHtml(item.host1) + ':' + escapeHtml(item.port1);
  2039. item.action = '<div class="btn-group">' +
  2040. '<a href="/edit/syncjob/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  2041. '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  2042. '</div>';
  2043. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  2044. if (item.is_running == 1) {
  2045. item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
  2046. } else {
  2047. item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
  2048. }
  2049. if (!item.last_run > 0) {
  2050. item.last_run = lang.waiting;
  2051. }
  2052. if (item.success == null) {
  2053. item.success = '-';
  2054. item.exit_status = '';
  2055. } else {
  2056. item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  2057. }
  2058. if (lang['syncjob_'+item.exit_status]) {
  2059. item.exit_status = lang['syncjob_'+item.exit_status];
  2060. } else if (item.success != '-') {
  2061. item.exit_status = lang.syncjob_check_log;
  2062. }
  2063. item.exit_status = item.success + ' ' + item.exit_status;
  2064. });
  2065. return json;
  2066. }
  2067. },
  2068. columns: [
  2069. {
  2070. // placeholder, so checkbox will not block child row toggle
  2071. title: '',
  2072. data: null,
  2073. searchable: false,
  2074. orderable: false,
  2075. defaultContent: '',
  2076. responsivePriority: 1
  2077. },
  2078. {
  2079. title: '',
  2080. data: 'chkbox',
  2081. searchable: false,
  2082. orderable: false,
  2083. defaultContent: '',
  2084. responsivePriority: 2
  2085. },
  2086. {
  2087. title: 'ID',
  2088. data: 'id',
  2089. responsivePriority: 3,
  2090. defaultContent: ''
  2091. },
  2092. {
  2093. title: lang.owner,
  2094. data: 'user2',
  2095. responsivePriority: 4,
  2096. defaultContent: ''
  2097. },
  2098. {
  2099. title: 'Server',
  2100. data: 'server_w_port',
  2101. defaultContent: ''
  2102. },
  2103. {
  2104. title: lang.last_run,
  2105. data: 'last_run',
  2106. defaultContent: ''
  2107. },
  2108. {
  2109. title: lang.syncjob_last_run_result,
  2110. data: 'exit_status',
  2111. defaultContent: ''
  2112. },
  2113. {
  2114. title: 'Log',
  2115. data: 'log',
  2116. defaultContent: ''
  2117. },
  2118. {
  2119. title: lang.active,
  2120. data: 'active',
  2121. defaultContent: '',
  2122. render: function (data, type) {
  2123. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  2124. }
  2125. },
  2126. {
  2127. title: lang.status,
  2128. data: 'is_running',
  2129. defaultContent: ''
  2130. },
  2131. {
  2132. title: lang.excludes,
  2133. data: 'exclude',
  2134. defaultContent: '',
  2135. className: 'none'
  2136. },
  2137. {
  2138. title: lang.mins_interval,
  2139. data: 'mins_interval',
  2140. defaultContent: '',
  2141. className: 'none'
  2142. },
  2143. {
  2144. title: lang.action,
  2145. data: 'action',
  2146. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  2147. responsivePriority: 5,
  2148. defaultContent: ''
  2149. },
  2150. ]
  2151. });
  2152. table.on('responsive-resize', function (e, datatable, columns){
  2153. hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table');
  2154. });
  2155. }
  2156. function draw_filter_table() {
  2157. // just recalc width if instance already exists
  2158. if ($.fn.DataTable.isDataTable('#filter_table') ) {
  2159. $('#filter_table').DataTable().columns.adjust().responsive.recalc();
  2160. return;
  2161. }
  2162. var table = $('#filter_table').DataTable({
  2163. responsive: true,
  2164. autoWidth: false,
  2165. processing: true,
  2166. serverSide: false,
  2167. stateSave: true,
  2168. pageLength: pagination_size,
  2169. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  2170. "tr" +
  2171. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  2172. language: lang_datatables,
  2173. order: [[2, 'desc']],
  2174. initComplete: function(){
  2175. hideTableExpandCollapseBtn('#tab-filters', '#filter_table');
  2176. },
  2177. ajax: {
  2178. type: "GET",
  2179. url: "/api/v1/get/filters/all",
  2180. dataSrc: function(json){
  2181. $.each(json, function (i, item) {
  2182. if (item.active == 1) {
  2183. item.active = '<span id="active-script" class="badge fs-6 bg-success">' + lang.active + '</span>';
  2184. } else {
  2185. item.active = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.inactive + '</span>';
  2186. }
  2187. item.script_desc = escapeHtml(item.script_desc);
  2188. item.script_data = '<pre class="text-break" style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  2189. item.filter_type = '<div class="badge fs-6 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  2190. item.action = '<div class="btn-group">' +
  2191. '<a href="/edit/filter/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  2192. '<a href="#" data-action="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  2193. '</div>';
  2194. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  2195. });
  2196. return json;
  2197. }
  2198. },
  2199. columns: [
  2200. {
  2201. // placeholder, so checkbox will not block child row toggle
  2202. title: '',
  2203. data: null,
  2204. searchable: false,
  2205. orderable: false,
  2206. defaultContent: '',
  2207. responsivePriority: 1
  2208. },
  2209. {
  2210. title: '',
  2211. data: 'chkbox',
  2212. searchable: false,
  2213. orderable: false,
  2214. defaultContent: '',
  2215. responsivePriority: 2
  2216. },
  2217. {
  2218. title: 'ID',
  2219. data: 'id',
  2220. responsivePriority: 2,
  2221. defaultContent: ''
  2222. },
  2223. {
  2224. title: lang.active,
  2225. data: 'active',
  2226. responsivePriority: 3,
  2227. defaultContent: ''
  2228. },
  2229. {
  2230. title: 'Type',
  2231. data: 'filter_type',
  2232. responsivePriority: 4,
  2233. defaultContent: ''
  2234. },
  2235. {
  2236. title: lang.owner,
  2237. data: 'username',
  2238. defaultContent: ''
  2239. },
  2240. {
  2241. title: lang.description,
  2242. data: 'script_desc',
  2243. defaultContent: ''
  2244. },
  2245. {
  2246. title: 'Script',
  2247. data: 'script_data',
  2248. defaultContent: '',
  2249. className: 'none'
  2250. },
  2251. {
  2252. title: lang.action,
  2253. data: 'action',
  2254. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  2255. responsivePriority: 5,
  2256. defaultContent: ''
  2257. },
  2258. ]
  2259. });
  2260. table.on('responsive-resize', function (e, datatable, columns){
  2261. hideTableExpandCollapseBtn('#tab-filters', '#filter_table');
  2262. });
  2263. };
  2264. function hideTableExpandCollapseBtn(tab, table){
  2265. if ($(table).hasClass('collapsed'))
  2266. $(tab).find(".table_collapse_option").show();
  2267. else
  2268. $(tab).find(".table_collapse_option").hide();
  2269. }
  2270. function filterByDomain(json, column, table){
  2271. var tableId = $(table.table().container()).attr('id');
  2272. // Create the `select` element
  2273. var select = $('<select class="btn btn-sm btn-xs-lg btn-light text-start mx-2"><option value="">'+lang.all_domains+'</option></select>')
  2274. .insertBefore(
  2275. $('#'+tableId+' .dataTables_filter > label > input')
  2276. )
  2277. .on( 'change', function(){
  2278. table.column(column)
  2279. .search($(this).val())
  2280. .draw();
  2281. });
  2282. // get all domains
  2283. var domains = [];
  2284. json.forEach(obj => {
  2285. Object.entries(obj).forEach(([key, value]) => {
  2286. if(key === 'domain') {
  2287. domains.push(value)
  2288. }
  2289. });
  2290. });
  2291. // get unique domain list
  2292. domains = domains.filter(function(value, index, array) {
  2293. return array.indexOf(value) === index;
  2294. });
  2295. // add domains to select
  2296. domains.forEach(function(domain) {
  2297. select.append($('<option>' + domain + '</option>'));
  2298. });
  2299. }
  2300. // detect element visibility changes
  2301. function onVisible(element, callback) {
  2302. $(document).ready(function() {
  2303. let element_object = document.querySelector(element);
  2304. if (element_object === null) return;
  2305. let observer = new IntersectionObserver((entries, observer) => {
  2306. entries.forEach(entry => {
  2307. if(entry.intersectionRatio > 0) {
  2308. callback(element_object);
  2309. observer.unobserve(element_object);
  2310. }
  2311. });
  2312. })
  2313. observer.observe(element_object);
  2314. });
  2315. }
  2316. // Load only if the tab is visible
  2317. onVisible("[id^=domain_table]", () => draw_domain_table());
  2318. onVisible("[id^=templates_domain_table]", () => draw_templates_domain_table());
  2319. onVisible("[id^=mailbox_table]", () => draw_mailbox_table());
  2320. onVisible("[id^=templates_mbox_table]", () => draw_templates_mbox_table());
  2321. onVisible("[id^=resource_table]", () => draw_resource_table());
  2322. onVisible("[id^=alias_table]", () => draw_alias_table());
  2323. onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table());
  2324. onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
  2325. onVisible("[id^=filter_table]", () => draw_filter_table());
  2326. onVisible("[id^=bcc_table]", () => draw_bcc_table());
  2327. onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table());
  2328. onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table());
  2329. });