mailbox.js 91 KB

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