mailbox.js 92 KB

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