PostfixAdmin - web based virtual user administration interface for Postfix mail servers https://postfixadmin.github.io/postfixadmin/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
1.9 KiB

6 years ago
  1. <?php
  2. # $Id$
  3. /**
  4. * class to handle 'delete' in Cli
  5. */
  6. class CliDelete extends Shell
  7. {
  8. /**
  9. * Execution method always used for tasks
  10. */
  11. public function execute()
  12. {
  13. if (empty($this->args)) {
  14. return $this->__interactive();
  15. }
  16. if (!empty($this->args[0])) {
  17. return $this->__handle($this->args[0]);
  18. }
  19. }
  20. /**
  21. * Interactive mode
  22. */
  23. protected function __interactive()
  24. {
  25. $module = preg_replace('/Handler$/', '', $this->handler_to_use);
  26. $module = strtolower($module);
  27. $question = "Which $module do you want to delete?";
  28. $address = $this->in($question);
  29. $question = "Do you really want to delete '$address'?";
  30. $create = $this->in($question, array('y','n'));
  31. if ($create == 'y') {
  32. return $this->__handle($address);
  33. }
  34. }
  35. /**
  36. * actually delete something
  37. *
  38. * @param string address to delete
  39. */
  40. protected function __handle($address)
  41. {
  42. $handler = new $this->handler_to_use($this->new);
  43. if (!$handler->init($address)) {
  44. $this->err($handler->errormsg);
  45. return 1;
  46. }
  47. if (!$handler->delete()) {
  48. $this->err($handler->errormsg);
  49. return 1;
  50. }
  51. $this->out($handler->infomsg);
  52. return 0;
  53. }
  54. /**
  55. * Display help contents
  56. *
  57. * @access public
  58. */
  59. public function help()
  60. {
  61. $module = preg_replace('/Handler$/', '', $this->handler_to_use);
  62. $module = strtolower($module);
  63. $this->out(
  64. "Usage:
  65. postfixadmin-cli $module delete
  66. Deletes $module in interactive mode.
  67. - or -
  68. postfixadmin-cli $module delete <address>
  69. Deletes $module <address> in non-interactive mode.
  70. "
  71. );
  72. $this->_stop(1);
  73. }
  74. }
  75. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */