mailbox.js 90 KB

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