functions.mailq.inc.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. function mailq($_action, $_data = null) {
  3. if ($_SESSION['mailcow_cc_role'] != "admin") {
  4. $_SESSION['return'][] = array(
  5. 'type' => 'danger',
  6. 'log' => array(__FUNCTION__, $_action, $_data),
  7. 'msg' => 'access_denied'
  8. );
  9. return false;
  10. }
  11. function process_mailq_output($returned_output, $_action, $_data) {
  12. if ($returned_output !== NULL) {
  13. if (isset($returned_output['type']) && $returned_output['type'] == 'danger') {
  14. $_SESSION['return'][] = array(
  15. 'type' => 'danger',
  16. 'log' => array('mailq', $_action, $_data),
  17. 'msg' => 'Error: ' . $returned_output['msg']
  18. );
  19. }
  20. if (isset($returned_output['type']) && $returned_output['type'] == 'success') {
  21. $_SESSION['return'][] = array(
  22. 'type' => 'success',
  23. 'log' => array('mailq', $_action, $_data),
  24. 'msg' => 'queue_command_success'
  25. );
  26. }
  27. }
  28. else {
  29. $_SESSION['return'][] = array(
  30. 'type' => 'danger',
  31. 'log' => array('mailq', $_action, $_data),
  32. 'msg' => 'unknown'
  33. );
  34. }
  35. }
  36. global $lang;
  37. switch ($_action) {
  38. case 'delete':
  39. if (!is_array($_data['qid'])) {
  40. $qids = array();
  41. $qids[] = $_data['qid'];
  42. }
  43. else {
  44. $qids = $_data['qid'];
  45. }
  46. $docker_return = docker('post', 'postfix-mailcow', 'exec', array('cmd' => 'mailq', 'task' => 'delete', 'items' => $qids));
  47. process_mailq_output(json_decode($docker_return, true), $_action, $_data);
  48. break;
  49. case 'edit':
  50. if (in_array($_data['action'], array('hold', 'unhold', 'deliver'))) {
  51. if (!is_array($_data['qid'])) {
  52. $qids = array();
  53. $qids[] = $_data['qid'];
  54. }
  55. else {
  56. $qids = $_data['qid'];
  57. }
  58. if (!empty($qids)) {
  59. $docker_return = docker('post', 'postfix-mailcow', 'exec', array('cmd' => 'mailq', 'task' => $_data['action'], 'items' => $qids));
  60. process_mailq_output(json_decode($docker_return, true), $_action, $_data);
  61. }
  62. }
  63. if (in_array($_data['action'], array('flush', 'super_delete'))) {
  64. $docker_return = docker('post', 'postfix-mailcow', 'exec', array('cmd' => 'mailq', 'task' => $_data['action']));
  65. process_mailq_output(json_decode($docker_return, true), $_action, $_data);
  66. }
  67. break;
  68. case 'get':
  69. // todo: move get from json_api here
  70. break;
  71. }
  72. }