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.

165 lines
4.7 KiB

  1. <?php
  2. /**
  3. * Requires the Zend framework is installed and in the include path.
  4. *
  5. * Usage example:
  6. * require_once('Zend/XmlRpc/Client.php');
  7. * $xmlrpc = new Zend_XmlRpc_Client('http://server/xmlrpc.php');
  8. *
  9. * $http_client = $xmlrpc->getHttpClient();
  10. * $http_client->setCookieJar();
  11. *
  12. * $login_object = $xmlrpc->getProxy('login');
  13. * $success = $login_object->login($username, $password);
  14. *
  15. * if($success) {
  16. * echo "We're logged in";
  17. * }
  18. * else {
  19. * die("Auth failed");
  20. * }
  21. * $user = $xmlrpc->getProxy('user');
  22. * $alias = $xmlrpc->getProxy('alias');
  23. * $vacation = $xmlrpc->getProxy('vacation');
  24. *
  25. * if($vacation->isEnabled()) {
  26. * echo "Vacation turned on for user";
  27. * }
  28. *
  29. * Note, the requirement that your XmlRpc client provides cookies with each request.
  30. * If it does not do this, then your authentication details will not persist across requests, and
  31. * this XMLRPC interface will not work.
  32. */
  33. require_once(dirname(__FILE__) . '/common.php');
  34. require_once('Zend/XmlRpc/Server.php');
  35. $server = new Zend_XmlRpc_Server();
  36. /**
  37. * @param string $username
  38. * @param string $password
  39. * @return boolean true on success, else false.
  40. */
  41. function login($username, $password) {
  42. if(UserHandler::login($username, $password)) {
  43. session_regenerate_id();
  44. $_SESSION['authenticated'] = true;
  45. $_SESSION['username'] = $username;
  46. return true;
  47. }
  48. return false;
  49. }
  50. if(!isset($_SESSION['authenticated'])) {
  51. $server->addFunction('login', 'login');
  52. }
  53. else {
  54. $server->setClass('UserProxy', 'user');
  55. $server->setClass('VacationProxy', 'vacation');
  56. $server->setClass('AliasProxy', 'alias');
  57. }
  58. echo $server->handle();
  59. class UserProxy {
  60. /**
  61. * @param string $old_password
  62. * @param string $new_password
  63. * @return boolean true on success
  64. */
  65. public function changePassword($old_password, $new_password) {
  66. $uh = new UserHandler($_SESSION['username']);
  67. return $uh->change_pass($old_password, $new_password);
  68. }
  69. /**
  70. * @param string $username
  71. * @param string $password
  72. * @return boolean true if successful.
  73. */
  74. public function login($username, $password) {
  75. $uh = new UserHandler($_SESSION['username']);
  76. return $uh->login($username, $password);
  77. }
  78. }
  79. class VacationProxy {
  80. /**
  81. * @return boolean true if the vacation is removed successfully. Else false.
  82. */
  83. public function remove() {
  84. $vh = new VacationHandler($_SESSION['username']);
  85. return $vh->remove();
  86. }
  87. /**
  88. * @return boolean true if vacation stuff is enabled in this instance of postfixadmin
  89. * and the user has the ability to make changes to it.
  90. */
  91. public function isVacationSupported() {
  92. $vh = new VacationHandler($_SESSION['username']);
  93. return $vh->vacation_supported();
  94. }
  95. /**
  96. * @return boolean true if the user has an active vacation record etc.
  97. */
  98. public function checkVacation() {
  99. $vh = new VacationHandler($_SESSION['username']);
  100. return $vh->check_vacation();
  101. }
  102. /**
  103. * @return struct|boolean - either array of vacation details or boolean false if the user has none.
  104. */
  105. public function getDetails() {
  106. $vh = new VacationHandler($_SESSION['username']);
  107. return $vh->get_details();
  108. }
  109. /**
  110. * @param string $subject
  111. * @param string $body
  112. * @return boolean true on success.
  113. */
  114. public function setAway($subject, $body) {
  115. $vh = new VacationHandler($_SESSION['username']);
  116. return $vh->set_away($subject, $body);
  117. }
  118. }
  119. class AliasProxy {
  120. /**
  121. * @return array - array of aliases this user has. Array may be empty.
  122. */
  123. public function get() {
  124. $ah = new AliasHandler($_SESSION['username']);
  125. /* I see no point in returning special addresses to the user. */
  126. return $ah->get(false);
  127. }
  128. /**
  129. * @param array of email addresses (Strings)
  130. * @param string flag to set ('forward_and_store' or 'remote_only')
  131. * @return boolean true
  132. */
  133. public function update($addresses, $flags) {
  134. $ah = new AliasHandler($_SESSION['username']);
  135. /**
  136. * if the user is on vacation, they should use VacationProxy stuff to remove it
  137. * and we'll never return the vacation address from here anyway
  138. */
  139. return $ah->update($addresses, $flags, true);
  140. }
  141. /**
  142. * @return boolean true if the user has 'store_and_forward' set.
  143. * (i.e. their email address is also in the alias table). IF it returns false, then it's 'remote_only'
  144. */
  145. public function hasStoreAndForward() {
  146. $ah = new AliasHandler($_SESSION['username']);
  147. return $ah->hasStoreAndForward();
  148. }
  149. }