| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * XMail Password Driver |
|---|
| 4 | * |
|---|
| 5 | * Driver for XMail password |
|---|
| 6 | * |
|---|
| 7 | * @version 1.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 | * $rcmail_config['xmail_host'] = 'localhost'; |
|---|
| 14 | * $rcmail_config['xmail_user'] = 'YourXmailControlUser'; |
|---|
| 15 | * $rcmail_config['xmail_pass'] = 'YourXmailControlPass'; |
|---|
| 16 | * $rcmail_config['xmail_port'] = 6017; |
|---|
| 17 | * |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | function password_save($currpass, $newpass) |
|---|
| 21 | { |
|---|
| 22 | $rcmail = rcmail::get_instance(); |
|---|
| 23 | list($user,$domain) = explode('@', $_SESSION['username']); |
|---|
| 24 | |
|---|
| 25 | $xmail = new XMail; |
|---|
| 26 | |
|---|
| 27 | $xmail->hostname = $rcmail->config->get('xmail_host'); |
|---|
| 28 | $xmail->username = $rcmail->config->get('xmail_user'); |
|---|
| 29 | $xmail->password = $rcmail->config->get('xmail_pass'); |
|---|
| 30 | $xmail->port = $rcmail->config->get('xmail_port'); |
|---|
| 31 | |
|---|
| 32 | if (!$xmail->connect()) { |
|---|
| 33 | raise_error(array( |
|---|
| 34 | 'code' => 600, |
|---|
| 35 | 'type' => 'php', |
|---|
| 36 | 'file' => __FILE__, 'line' => __LINE__, |
|---|
| 37 | 'message' => "Password plugin: Unable to connect to mail server" |
|---|
| 38 | ), true, false); |
|---|
| 39 | return PASSWORD_CONNECT_ERROR; |
|---|
| 40 | } else if (!$xmail->send("userpasswd\t".$domain."\t".$user."\t".$newpass."\n")) { |
|---|
| 41 | $xmail->close(); |
|---|
| 42 | raise_error(array( |
|---|
| 43 | 'code' => 600, |
|---|
| 44 | 'type' => 'php', |
|---|
| 45 | 'file' => __FILE__, 'line' => __LINE__, |
|---|
| 46 | 'message' => "Password plugin: Unable to change password" |
|---|
| 47 | ), true, false); |
|---|
| 48 | return PASSWORD_ERROR; |
|---|
| 49 | } else { |
|---|
| 50 | $xmail->close(); |
|---|
| 51 | return PASSWORD_SUCCESS; |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | class XMail { |
|---|
| 56 | var $socket; |
|---|
| 57 | var $hostname = 'localhost'; |
|---|
| 58 | var $username = 'xmail'; |
|---|
| 59 | var $password = ''; |
|---|
| 60 | var $port = 6017; |
|---|
| 61 | |
|---|
| 62 | function send($msg) |
|---|
| 63 | { |
|---|
| 64 | socket_write($this->socket,$msg); |
|---|
| 65 | if (substr($in = socket_read($this->socket, 512, PHP_BINARY_READ),0,1) != "+") { |
|---|
| 66 | return false; |
|---|
| 67 | } |
|---|
| 68 | return true; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | function connect() |
|---|
| 72 | { |
|---|
| 73 | $this->socket = socket_create(AF_INET, SOCK_STREAM, 0); |
|---|
| 74 | if ($this->socket < 0) |
|---|
| 75 | return false; |
|---|
| 76 | |
|---|
| 77 | $result = socket_connect($this->socket, $this->hostname, $this->port); |
|---|
| 78 | if ($result < 0) { |
|---|
| 79 | socket_close($this->socket); |
|---|
| 80 | return false; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | if (substr($in = socket_read($this->socket, 512, PHP_BINARY_READ),0,1) != "+") { |
|---|
| 84 | socket_close($this->socket); |
|---|
| 85 | return false; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | if (!$this->send("$this->username\t$this->password\n")) { |
|---|
| 89 | socket_close($this->socket); |
|---|
| 90 | return false; |
|---|
| 91 | } |
|---|
| 92 | return true; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | function close() |
|---|
| 96 | { |
|---|
| 97 | $this->send("quit\n"); |
|---|
| 98 | socket_close($this->socket); |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|