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.

166 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. session_start();
  37. /**
  38. * @param string $username
  39. * @param string $password
  40. * @return boolean true on success, else false.
  41. */
  42. function login($username, $password) {
  43. if(UserHandler::login($username, $password)) {
  44. session_regenerate_id();
  45. $_SESSION['authenticated'] = true;
  46. $_SESSION['username'] = $username;
  47. return true;
  48. }
  49. return false;
  50. }
  51. if(!isset($_SESSION['authenticated'])) {
  52. $server->addFunction('login', 'login');
  53. }
  54. else {
  55. $server->setClass('UserProxy', 'user');
  56. $server->setClass('VacationProxy', 'vacation');
  57. $server->setClass('AliasProxy', 'alias');
  58. }
  59. echo $server->handle();
  60. class UserProxy {
  61. /**
  62. * @param string $old_password
  63. * @param string $new_password
  64. * @return boolean true on success
  65. */
  66. public function changePassword($old_password, $new_password) {
  67. $uh = new UserHandler($_SESSION['username']);
  68. return $uh->change_pass($old_password, $new_password);
  69. }
  70. /**
  71. * @param string $username
  72. * @param string $password
  73. * @return boolean true if successful.
  74. */
  75. public function login($username, $password) {
  76. $uh = new UserHandler($_SESSION['username']);
  77. return $uh->login($username, $password);
  78. }
  79. }
  80. class VacationProxy {
  81. /**
  82. * @return boolean true if the vacation is removed successfully. Else false.
  83. */
  84. public function remove() {
  85. $vh = new VacationHandler($_SESSION['username']);
  86. return $vh->remove();
  87. }
  88. /**
  89. * @return boolean true if vacation stuff is enabled in this instance of postfixadmin
  90. * and the user has the ability to make changes to it.
  91. */
  92. public function isVacationSupported() {
  93. $vh = new VacationHandler($_SESSION['username']);
  94. return $vh->vacation_supported();
  95. }
  96. /**
  97. * @return boolean true if the user has an active vacation record etc.
  98. */
  99. public function checkVacation() {
  100. $vh = new VacationHandler($_SESSION['username']);
  101. return $vh->check_vacation();
  102. }
  103. /**
  104. * @return struct|boolean - either array of vacation details or boolean false if the user has none.
  105. */
  106. public function getDetails() {
  107. $vh = new VacationHandler($_SESSION['username']);
  108. return $vh->get_details();
  109. }
  110. /**
  111. * @param string $subject
  112. * @param string $body
  113. * @return boolean true on success.
  114. */
  115. public function setAway($subject, $body) {
  116. $vh = new VacationHandler($_SESSION['username']);
  117. return $vh->set_away($subject, $body);
  118. }
  119. }
  120. class AliasProxy {
  121. /**
  122. * @return array - array of aliases this user has. Array may be empty.
  123. */
  124. public function get() {
  125. $ah = new AliasHandler($_SESSION['username']);
  126. /* I see no point in returning special addresses to the user. */
  127. return $ah->get(false);
  128. }
  129. /**
  130. * @param array of email addresses (Strings)
  131. * @param string flag to set ('forward_and_store' or 'remote_only')
  132. * @return boolean true
  133. */
  134. public function update($addresses, $flags) {
  135. $ah = new AliasHandler($_SESSION['username']);
  136. /**
  137. * if the user is on vacation, they should use VacationProxy stuff to remove it
  138. * and we'll never return the vacation address from here anyway
  139. */
  140. return $ah->update($addresses, $flags, true);
  141. }
  142. /**
  143. * @return boolean true if the user has 'store_and_forward' set.
  144. * (i.e. their email address is also in the alias table). IF it returns false, then it's 'remote_only'
  145. */
  146. public function hasStoreAndForward() {
  147. $ah = new AliasHandler($_SESSION['username']);
  148. return $ah->hasStoreAndForward();
  149. }
  150. }