Files
roundcubemail/plugins/password/drivers/ximss.php
Michael Voříšek 28c778b7a0 Modernize more CS III (#9270)
* fix "single_trait_insert_per_statement"

* fix "empty_loop_condition"

* fix "backtick_to_shell_exec"

* fix "phpdoc_to_comment"

* fix "no_empty_statement"

* fix "heredoc_to_nowdoc"

* fix "class_reference_name_casing"

* fix "align_multiline_comment"

* fix "heredoc_indentation"

* fix "constant_case"

* fix "single_line_comment_style"

* fix "no_null_property_initialization"

* fix "standardize_increment"

* fix "no_unneeded_control_parentheses"

* fix missing NL after "<?php"

* fix php in *.sh files too

* fix trailing spaces from all text files

* fix "explicit_indirect_variable"

* Revert "fix "align_multiline_comment""

This reverts commit 42e584f8e3.

* fix "align_multiline_comment" properly

* Revert "fix trailing spaces from all text files" - diff files only

* Revert "Revert "fix trailing spaces from all text files" - diff files only"

This reverts commit 2101c2a3a3.

* rm useless "setup-php" config
2023-12-18 07:46:51 +01:00

93 lines
3.1 KiB
PHP

<?php
/**
* Communigate driver for the Password Plugin for Roundcube
*
* Tested with Communigate Pro 5.1.2
*
* Configuration options:
* password_ximss_host - Host name of Communigate server
* password_ximss_port - XIMSS port on Communigate server
*
* References:
* http://www.communigate.com/WebGuide/XMLAPI.html
*
* @version 2.0
*
* @author Erik Meitner <erik wanderings.us>
*
* Copyright (C) The Roundcube Dev Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
class rcube_ximss_password
{
function save($pass, $newpass, $username)
{
$rcmail = rcmail::get_instance();
$host = $rcmail->config->get('password_ximss_host');
$port = $rcmail->config->get('password_ximss_port');
$sock = stream_socket_client("tcp://$host:$port", $errno, $errstr, 30);
if ($sock === false) {
return PASSWORD_CONNECT_ERROR;
}
// send all requests at once(pipelined)
fwrite($sock, '<login id="A001" authData="' . $username . '" password="' . $pass . '" />' . "\0");
fwrite($sock, '<passwordModify id="A002" oldPassword="' . $pass . '" newPassword="' . $newpass . '" />' . "\0");
fwrite($sock, '<bye id="A003" />' . "\0");
//example responses
// <session id="A001" urlID="4815-vN2Txjkggy7gjHRD10jw" userName="user@example.com"/>\0
// <response id="A001"/>\0
// <response id="A002"/>\0
// <response id="A003"/>\0
// or an error:
// <response id="A001" errorText="incorrect password or account name" errorNum="515"/>\0
$responseblob = '';
while (!feof($sock)) {
$responseblob .= fgets($sock, 1024);
}
fclose($sock);
foreach (explode("\0", $responseblob) as $response) {
$resp = simplexml_load_string("<xml>" . $response . "</xml>");
$id = $resp && !empty($resp->response[0]['id']) ? $resp->response[0]['id'] : null;
if ($id == 'A001') {
if (isset($resp->response[0]['errorNum'])) {
return PASSWORD_CONNECT_ERROR;
}
}
elseif ($id == 'A002') {
if (isset($resp->response[0]['errorNum'])) {
return PASSWORD_ERROR;
}
}
elseif ($id == 'A003') {
if (isset($resp->response[0]['errorNum'])) {
// There was a problem during logout (This is probably harmless)
}
}
}
return PASSWORD_SUCCESS;
}
}