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.

xmail.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * XMail Password Driver
  4. *
  5. * Driver for XMail password
  6. *
  7. * @version 2.0
  8. * @author Helio Cavichiolo Jr <helio@hcsistemas.com.br>
  9. *
  10. * Setup xmail_host, xmail_user, xmail_pass and xmail_port into
  11. * config.inc.php of password plugin as follows:
  12. *
  13. * $config['xmail_host'] = 'localhost';
  14. * $config['xmail_user'] = 'YourXmailControlUser';
  15. * $config['xmail_pass'] = 'YourXmailControlPass';
  16. * $config['xmail_port'] = 6017;
  17. *
  18. * Copyright (C) 2005-2013, The Roundcube Dev Team
  19. *
  20. * This program is free software: you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation, either version 3 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program. If not, see http://www.gnu.org/licenses/.
  32. */
  33. class rcube_xmail_password
  34. {
  35. function save($currpass, $newpass)
  36. {
  37. $rcmail = rcmail::get_instance();
  38. list($user,$domain) = explode('@', $_SESSION['username']);
  39. $xmail = new XMail;
  40. $xmail->hostname = $rcmail->config->get('xmail_host');
  41. $xmail->username = $rcmail->config->get('xmail_user');
  42. $xmail->password = $rcmail->config->get('xmail_pass');
  43. $xmail->port = $rcmail->config->get('xmail_port');
  44. if (!$xmail->connect()) {
  45. rcube::raise_error(array(
  46. 'code' => 600,
  47. 'type' => 'php',
  48. 'file' => __FILE__, 'line' => __LINE__,
  49. 'message' => "Password plugin: Unable to connect to mail server"
  50. ), true, false);
  51. return PASSWORD_CONNECT_ERROR;
  52. }
  53. else if (!$xmail->send("userpasswd\t".$domain."\t".$user."\t".$newpass."\n")) {
  54. $xmail->close();
  55. rcube::raise_error(array(
  56. 'code' => 600,
  57. 'type' => 'php',
  58. 'file' => __FILE__, 'line' => __LINE__,
  59. 'message' => "Password plugin: Unable to change password"
  60. ), true, false);
  61. return PASSWORD_ERROR;
  62. }
  63. else {
  64. $xmail->close();
  65. return PASSWORD_SUCCESS;
  66. }
  67. }
  68. }
  69. class XMail {
  70. var $socket;
  71. var $hostname = 'localhost';
  72. var $username = 'xmail';
  73. var $password = '';
  74. var $port = 6017;
  75. function send($msg)
  76. {
  77. socket_write($this->socket,$msg);
  78. if (substr(socket_read($this->socket, 512, PHP_BINARY_READ),0,1) != "+") {
  79. return false;
  80. }
  81. return true;
  82. }
  83. function connect()
  84. {
  85. $this->socket = socket_create(AF_INET, SOCK_STREAM, 0);
  86. if ($this->socket < 0)
  87. return false;
  88. $result = socket_connect($this->socket, $this->hostname, $this->port);
  89. if ($result < 0) {
  90. socket_close($this->socket);
  91. return false;
  92. }
  93. if (substr(socket_read($this->socket, 512, PHP_BINARY_READ),0,1) != "+") {
  94. socket_close($this->socket);
  95. return false;
  96. }
  97. if (!$this->send("$this->username\t$this->password\n")) {
  98. socket_close($this->socket);
  99. return false;
  100. }
  101. return true;
  102. }
  103. function close()
  104. {
  105. $this->send("quit\n");
  106. socket_close($this->socket);
  107. }
  108. }