Mercurial > hg > rc1
comparison plugins/password/drivers/xmail.php @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
| author | Charlie Root |
|---|---|
| date | Thu, 04 Jan 2018 15:50:29 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:1e000243b222 |
|---|---|
| 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 | |
| 34 class rcube_xmail_password | |
| 35 { | |
| 36 function save($currpass, $newpass) | |
| 37 { | |
| 38 $rcmail = rcmail::get_instance(); | |
| 39 list($user,$domain) = explode('@', $_SESSION['username']); | |
| 40 | |
| 41 $xmail = new XMail; | |
| 42 | |
| 43 $xmail->hostname = $rcmail->config->get('xmail_host'); | |
| 44 $xmail->username = $rcmail->config->get('xmail_user'); | |
| 45 $xmail->password = $rcmail->config->get('xmail_pass'); | |
| 46 $xmail->port = $rcmail->config->get('xmail_port'); | |
| 47 | |
| 48 if (!$xmail->connect()) { | |
| 49 rcube::raise_error(array( | |
| 50 'code' => 600, | |
| 51 'type' => 'php', | |
| 52 'file' => __FILE__, 'line' => __LINE__, | |
| 53 'message' => "Password plugin: Unable to connect to mail server" | |
| 54 ), true, false); | |
| 55 return PASSWORD_CONNECT_ERROR; | |
| 56 } | |
| 57 else if (!$xmail->send("userpasswd\t".$domain."\t".$user."\t".$newpass."\n")) { | |
| 58 $xmail->close(); | |
| 59 rcube::raise_error(array( | |
| 60 'code' => 600, | |
| 61 'type' => 'php', | |
| 62 'file' => __FILE__, 'line' => __LINE__, | |
| 63 'message' => "Password plugin: Unable to change password" | |
| 64 ), true, false); | |
| 65 return PASSWORD_ERROR; | |
| 66 } | |
| 67 else { | |
| 68 $xmail->close(); | |
| 69 return PASSWORD_SUCCESS; | |
| 70 } | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 class XMail { | |
| 75 var $socket; | |
| 76 var $hostname = 'localhost'; | |
| 77 var $username = 'xmail'; | |
| 78 var $password = ''; | |
| 79 var $port = 6017; | |
| 80 | |
| 81 function send($msg) | |
| 82 { | |
| 83 socket_write($this->socket,$msg); | |
| 84 if (substr(socket_read($this->socket, 512, PHP_BINARY_READ),0,1) != "+") { | |
| 85 return false; | |
| 86 } | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 function connect() | |
| 91 { | |
| 92 $this->socket = socket_create(AF_INET, SOCK_STREAM, 0); | |
| 93 if ($this->socket < 0) | |
| 94 return false; | |
| 95 | |
| 96 $result = socket_connect($this->socket, $this->hostname, $this->port); | |
| 97 if ($result < 0) { | |
| 98 socket_close($this->socket); | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 if (substr(socket_read($this->socket, 512, PHP_BINARY_READ),0,1) != "+") { | |
| 103 socket_close($this->socket); | |
| 104 return false; | |
| 105 } | |
| 106 | |
| 107 if (!$this->send("$this->username\t$this->password\n")) { | |
| 108 socket_close($this->socket); | |
| 109 return false; | |
| 110 } | |
| 111 return true; | |
| 112 } | |
| 113 | |
| 114 function close() | |
| 115 { | |
| 116 $this->send("quit\n"); | |
| 117 socket_close($this->socket); | |
| 118 } | |
| 119 } |
