From 323d5eef7170445e5dabfd9724983cbab7267b9a Mon Sep 17 00:00:00 2001 From: Gary Date: Tue, 24 Feb 2026 07:42:15 +0000 Subject: [PATCH 1/4] Additional plugin to manage Identity Name from ISPConfig --- .../config/config.inc.php.dist | 5 ++ ispconfig3_identity/ispconfig3_identity.php | 77 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 ispconfig3_identity/config/config.inc.php.dist create mode 100644 ispconfig3_identity/ispconfig3_identity.php diff --git a/ispconfig3_identity/config/config.inc.php.dist b/ispconfig3_identity/config/config.inc.php.dist new file mode 100644 index 0000000..4daec12 --- /dev/null +++ b/ispconfig3_identity/config/config.inc.php.dist @@ -0,0 +1,5 @@ +rcmail = rcmail::get_instance(); + $this->rc = rcube::get_instance(); + + $this->require_plugin('ispconfig3_account'); + + $this->load_config('config/config.inc.php.dist'); + if (file_exists($this->home . '/config/config.inc.php')) { + $this->load_config('config/config.inc.php'); + } + + $this->soap = new SoapClient(null, [ + 'location' => $this->rcmail->config->get('soap_url') . 'index.php', + 'uri' => $this->rcmail->config->get('soap_url'), + $this->rcmail->config->get('soap_validate_cert') ?: + 'stream_context' => stream_context_create(['ssl' => [ + 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true + ]]) + ]); + +$this->add_hook('login_after', [$this, 'set_identity']); + } + + private function remoteGetUser() + { + try { + $session_id = $this->soap->login($this->rcmail->config->get('remote_soap_user'), $this->rcmail->config->get('remote_soap_pass')); + // Search by the login + $this->mail_user = $this->soap->mail_user_get($session_id, ['login' => $this->rcmail->user->data['username']]); + // Alternatively also search the email field, this can differ from the login field for legacy reasons + if (empty($this->mail_user)) { + $this->mail_user = $this->soap->mail_user_get($session_id, ['email' => $this->rcmail->user->data['username']]); + } + + $this->soap->logout($session_id); + } + catch (SoapFault $e) { + $error = $this->rc->text_exists($e->getMessage(), $this->ID) ? $this->gettext($e->getMessage()) : $e->getMessage(); + $this->rcmail->output->command('display_message', 'Soap Error: ' . $error, 'error'); + } + } + + /* + // Funciton to set the identitiy that matches the e-mail address + */ + function set_identity() + { + $this->remoteGetUser(); + + $identities = $this->rc->user->list_identities(); + // Loop through identities to find the one corrisponding to the mailbox email + foreach ($identities as $identity) { + // Identitiy found + if ($identity['email'] == $this->rcmail->user->data['username'] && $this->mail_user[0]['email'] === $this->rcmail->user->data['username']) { + // The below by default will set once at initial login, this allows users to then change later + // If setting force_name_update to true will update to match ISPConfig every login + if ($identity['name'] == "" || ($this->rcmail->config->get('force_name_update') && $identity['name'] != $this->mail_user[0]['name'])) { + $update = ["name" => $this->mail_user[0]['name']]; + $this->rc->user->update_identity($identity['identity_id'],$update); + } + } + } + } +} From 0f21e711fb859e6c1db39bc1e6576f12abd8e8dc Mon Sep 17 00:00:00 2001 From: Gary Date: Sun, 1 Mar 2026 22:58:03 +0000 Subject: [PATCH 2/4] Fix Indentation --- ispconfig3_identity/ispconfig3_identity.php | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ispconfig3_identity/ispconfig3_identity.php b/ispconfig3_identity/ispconfig3_identity.php index f970ba2..1543e36 100644 --- a/ispconfig3_identity/ispconfig3_identity.php +++ b/ispconfig3_identity/ispconfig3_identity.php @@ -31,7 +31,7 @@ function init() ]]) ]); -$this->add_hook('login_after', [$this, 'set_identity']); + $this->add_hook('login_after', [$this, 'set_identity']); } private function remoteGetUser() @@ -44,7 +44,7 @@ private function remoteGetUser() if (empty($this->mail_user)) { $this->mail_user = $this->soap->mail_user_get($session_id, ['email' => $this->rcmail->user->data['username']]); } - + $this->soap->logout($session_id); } catch (SoapFault $e) { @@ -54,21 +54,21 @@ private function remoteGetUser() } /* - // Funciton to set the identitiy that matches the e-mail address + * Funciton to set the identitiy that matches the e-mail address */ function set_identity() { $this->remoteGetUser(); - $identities = $this->rc->user->list_identities(); - // Loop through identities to find the one corrisponding to the mailbox email - foreach ($identities as $identity) { - // Identitiy found - if ($identity['email'] == $this->rcmail->user->data['username'] && $this->mail_user[0]['email'] === $this->rcmail->user->data['username']) { - // The below by default will set once at initial login, this allows users to then change later - // If setting force_name_update to true will update to match ISPConfig every login - if ($identity['name'] == "" || ($this->rcmail->config->get('force_name_update') && $identity['name'] != $this->mail_user[0]['name'])) { - $update = ["name" => $this->mail_user[0]['name']]; + $identities = $this->rc->user->list_identities(); + // Loop through identities to find the one corrisponding to the mailbox email + foreach ($identities as $identity) { + // Identitiy found + if ($identity['email'] == $this->rcmail->user->data['username'] && $this->mail_user[0]['email'] === $this->rcmail->user->data['username']) { + // The below by default will set once at initial login, this allows users to then change later + // If setting force_name_update to true will update to match ISPConfig every login + if ($identity['name'] == "" || ($this->rcmail->config->get('force_name_update') && $identity['name'] != $this->mail_user[0]['name'])) { + $update = ["name" => $this->mail_user[0]['name']]; $this->rc->user->update_identity($identity['identity_id'],$update); } } From d1472fb45862760eab40eef8fcad5adfc9a279d7 Mon Sep 17 00:00:00 2001 From: Gary Date: Sun, 1 Mar 2026 22:58:23 +0000 Subject: [PATCH 3/4] Add logic for no mail_user --- ispconfig3_identity/ispconfig3_identity.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ispconfig3_identity/ispconfig3_identity.php b/ispconfig3_identity/ispconfig3_identity.php index 1543e36..9013d1f 100644 --- a/ispconfig3_identity/ispconfig3_identity.php +++ b/ispconfig3_identity/ispconfig3_identity.php @@ -46,6 +46,8 @@ private function remoteGetUser() } $this->soap->logout($session_id); + // Still not set a user, return false + (empty($this->mail_user)) ? return false : return true; } catch (SoapFault $e) { $error = $this->rc->text_exists($e->getMessage(), $this->ID) ? $this->gettext($e->getMessage()) : $e->getMessage(); @@ -58,8 +60,7 @@ private function remoteGetUser() */ function set_identity() { - $this->remoteGetUser(); - + if ($this->remoteGetUser()) { $identities = $this->rc->user->list_identities(); // Loop through identities to find the one corrisponding to the mailbox email foreach ($identities as $identity) { @@ -69,7 +70,8 @@ function set_identity() // If setting force_name_update to true will update to match ISPConfig every login if ($identity['name'] == "" || ($this->rcmail->config->get('force_name_update') && $identity['name'] != $this->mail_user[0]['name'])) { $update = ["name" => $this->mail_user[0]['name']]; - $this->rc->user->update_identity($identity['identity_id'],$update); + $this->rc->user->update_identity($identity['identity_id'], $update); + } } } } From 2816e7e6f13f7d55aa4bede46cb19429db98887b Mon Sep 17 00:00:00 2001 From: Gary Date: Thu, 12 Mar 2026 07:37:30 +0000 Subject: [PATCH 4/4] Fix return clause --- ispconfig3_identity/ispconfig3_identity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ispconfig3_identity/ispconfig3_identity.php b/ispconfig3_identity/ispconfig3_identity.php index 9013d1f..b721fd7 100644 --- a/ispconfig3_identity/ispconfig3_identity.php +++ b/ispconfig3_identity/ispconfig3_identity.php @@ -47,7 +47,7 @@ private function remoteGetUser() $this->soap->logout($session_id); // Still not set a user, return false - (empty($this->mail_user)) ? return false : return true; + return (empty($this->mail_user)) ? false : true; } catch (SoapFault $e) { $error = $this->rc->text_exists($e->getMessage(), $this->ID) ? $this->gettext($e->getMessage()) : $e->getMessage();