HEX
Server: nginx/1.28.0
System: Linux w3c-2 6.8.0-78-generic #78-Ubuntu SMP PREEMPT_DYNAMIC Tue Aug 12 11:34:18 UTC 2025 x86_64
User: inpa_co_1 (1082)
PHP: 8.3.29
Disabled: NONE
Upload Files
File: //var/roundcube/roundcube_password_driver.php
<?php
// Place into public_html/plugins/password/drivers/enhance.php

// Constants from the password plugin – normally already defined,
// but it’s safe to re-define with the same values if needed.
if (!defined('PASSWORD_SUCCESS')) {
    define('PASSWORD_SUCCESS', 0);
}
if (!defined('PASSWORD_ERROR')) {
    define('PASSWORD_ERROR', 1);
}
if (!defined('PASSWORD_CRYPT_ERROR')) {
    define('PASSWORD_CRYPT_ERROR', 2);
}

class rcube_enhance_password
{
    public function save($curpass, $newpass, $username = null)
    {
        $rcmail   = rcmail::get_instance();
        $user     = $username ?: $rcmail->get_user_name(); 


        $payload = ["ChangePassword" => [
            'email_address'     => $user,
            'old_password' => $curpass,
            'new_password' => $newpass,
        ]];

        $decoded = appcd_request($payload);

        if (!is_array($decoded) || !$decoded['Ok']) {
            /*rcube::raise_error([
                'code'    => 600,
                'file'    => __FILE__,
                'line'    => __LINE__,
                'message' => "Password plugin: API error response ($responseBody)",
            ], true, false);
            */
            return [
                'code'    => PASSWORD_ERROR, 
                'message' => 'Backend says: ' . $decoded['Error']['msg'],
            ];
        }

        return PASSWORD_SUCCESS;
    }
}

function appcd_request(array $request, float $timeout = 30.0): ?array {
    $socketPath = '/var/run/enhance/unpriv.sock';
    $errno = 0;
    $errstr = '';

    $fp = @stream_socket_client(
        'unix://' . $socketPath,
        $errno,
        $errstr,
        $timeout
    );

    if (!$fp) {
        throw new RuntimeException("Failed to connect to appcd: $errstr ($errno)");
    }

    fwrite($fp, json_encode($request, JSON_UNESCAPED_SLASHES) . "\n");

    $responseLine = fgets($fp);
    fclose($fp);

    if ($responseLine === false) {
        return null;
    }

    $decoded = json_decode(trim($responseLine), true);
    if (!is_array($decoded)) {
        throw new RuntimeException("Invalid JSON from appcd: $responseLine");
    }

    return $decoded;
}