Opened 2 years ago

Closed 2 years ago

#1487781 closed Feature Patches (fixed)

Enhanced Virtualmin password driver

Reported by: Hal9000 Owned by:
Priority: 5 Milestone: 0.6-beta
Component: Plugins Version: 0.5.1
Severity: normal Keywords:
Cc:

Description

Hi there!
I would like to contribute with this patch, since the Virtualmin driver of the password plugin assumes that usernaes are in email format, which is not always the case.
The patch provides a configuration option for the username format.

At the bottom of config.inc.php.dist add

// Virtualmin Driver options
// -------------------------
// Usernames format:
// 0: username@domain
// 1: username%domain
// 2: username.domain
// 3: domain.username
// 4: username-domain
// 5: domain-username
// 6: username_domain
// 7: domain_username
$rcmail_config['virtualmin_format'] = 0;

In drivers/virtualmin.php replace

$domain = substr(strrchr($username, "@"), 1);

with the following code

	$format = $rcmail->config->get('virtualmin_format', false);
	switch ($format) {
		case 1: // username%domain
			$domain = substr(strrchr($username, "%"), 1);
			break;
		case 2: // username.domain (could be bogus)
			$pieces = explode(".", $username);
			$domain = $pieces[count($pieces)-2]. "." . end($pieces);
			break;
		case 3: // domain.username (could be bogus)
			$pieces = explode(".", $username);
			$domain = $pieces[0]. "." . $pieces[1];
			break;
		case 4: // username-domain
			$domain = substr(strrchr($username, "-"), 1);
			break;
		case 5: // domain-username
			$domain = str_replace(strrchr($username, "-"), "", $username);
			break;
		case 6: // username_domain
			$domain = substr(strrchr($username, "_"), 1);
			break;
		case 7: // domain_username
			//$domain = substr(strstr($username, "_", true), 0); # only works with php 5.3
			$pieces = explode("_", $username);
			$domain = $pieces[0];
			break;
		default: // username@domain
			$domain = substr(strrchr($username, "@"), 1);
	}

Change History (3)

comment:1 Changed 2 years ago by alec

  • Milestone changed from later to 0.6-beta

comment:2 Changed 2 years ago by Hal9000

Did a little mistake: in the code for virtualmin.php, right at the start, the following line is needed:

$rcmail = rcmail::get_instance();

And at the end it would be a good idea to have this:

write_log('password', "Changing password for $username on $domain");

comment:3 Changed 2 years ago by alec

  • Resolution set to fixed
  • Status changed from new to closed

Applied in r4546/svn. Not tested, feedback welcome.

Note: See TracTickets for help on using tickets.