-
Notifications
You must be signed in to change notification settings - Fork 66
Additional plugin to manage Identity Name from ISPConfig #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
packet-nomad-gary
wants to merge
4
commits into
w2c:master
Choose a base branch
from
packet-nomad-gary:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <?php | ||
| // Set the below to true to update on first login | ||
| // Setting $config['identities_level'] = 4 in your overall | ||
| // roundcube config will prohibt users updating this | ||
| $config['force_name_update'] = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
|
|
||
| class ispconfig3_identity extends rcube_plugin | ||
| { | ||
| public $task = 'login'; | ||
| private $rcmail; | ||
| private $rc; | ||
| private $mail_user; | ||
|
|
||
| private $soap; | ||
|
|
||
|
|
||
| function init() | ||
| { | ||
| $this->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); | ||
| // Still not set a user, return false | ||
| 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(); | ||
| $this->rcmail->output->command('display_message', 'Soap Error: ' . $error, 'error'); | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * Funciton to set the identitiy that matches the e-mail address | ||
| */ | ||
| function set_identity() | ||
| { | ||
| 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) { | ||
| // 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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.