mailbox.js 90 KB

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