2
0

mailbox.js 92 KB

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