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.

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