Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
André Rodier
committed
Apr 25, 2011
0 parents
commit 4e9c256
Showing
9 changed files
with
884 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,23 @@ | ||
# Put your local configuration in 'local' folder | ||
include local/*.mk | ||
|
||
### Variable settings ####################################################### | ||
# default folder for roundcube plugins. You can override in a local makefile. | ||
pluginsDir ?= /var/www/roundcube-trunk/plugins | ||
|
||
# Install all plugins in the dev folder | ||
all: identiteam | ||
|
||
# clean packages | ||
clean: | ||
@rm -f packs/*tgz | ||
|
||
# Create a tgz package for each plugin | ||
packs: | ||
@cd plugins | ||
@git archive --format tar --prefix=identiteam/ HEAD:identiteam | gzip -9 >packs/identiteam.tgz | ||
|
||
# install packages in the currently defined plugins folder | ||
identiteam-dev: packs | ||
@tar zxf packs/identiteam.tgz -C $(pluginsDir) | ||
|
Empty file.
This file contains 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,2 @@ | ||
This folder should contains your local configuration for the main Makefile. | ||
Each file should have .mk extension |
This file contains 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 @@ | ||
This folder contains packages for each roundcube extension. |
This file contains 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,25 @@ | ||
identiteam | ||
|
||
Automatically creates new users' identities on first login, using LDAP fields. | ||
|
||
Features: | ||
- Fully customizable HTML or text signatures. | ||
- Automatically detect signatures types (HTML or text) when created. | ||
- You can use custom signatures per domain. | ||
- You can use custom signatures per use. | ||
- Templates folder location is customisable, for instance '/etc/roundcube/templates' | ||
|
||
Bugs & Issues: | ||
- Send bug reports to andre.rodier@gmail.com | ||
|
||
Basic Installation: | ||
- Copy config-default.inc.php in config.inc.php, and modify the values you need. | ||
|
||
Templates customisation on a global level: | ||
- copy the 'default' folder into a folder representative of your company, for instance "SnakeOil" | ||
- Modify 'folderName' in the config, and use 'SnakeOil' instead of default. | ||
|
||
Templates customisation on per domain basis | ||
- Modify 'folderName' in the config, and use '%d' instead of default. | ||
- Create a folder for each domain name you hosts, and copy the file 'default.tmpl' into these folders | ||
- Custom each signature. |
This file contains 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,37 @@ | ||
<?php | ||
|
||
# Default configuration settings for identiteam. | ||
# Copy this file in config.inc.php, and override the values you need. | ||
|
||
# Used to create a new user identity on the first login | ||
$rcmail_config['identiteam'] = | ||
array( | ||
|
||
# LDAP parameters | ||
'ldap' => array( | ||
'server' => 'ldap.snakeoil.com', # Your LDAP server address | ||
'filter' => '(uid=%s)' , # The LDAP filter to use. This is compared with the user' login. use 'mail' if the domain is | ||
# specified in the login process. | ||
'domain' => 'dc=snakeoil,dc=com', # LDAP Domain | ||
'extraEmailField' => 'gosamailalternateaddress', # This LDAP property is used to create multiple identities with different email addresses. | ||
|
||
# Read these fields to insert them inside the signatures. | ||
'fields' => 'postaladdress,o,ou,cn,mail,sn,telephonenumber,mobile' | ||
), | ||
|
||
# Templates parameters | ||
'templates' => array( | ||
'emptyValues' => '...', # When the value is not existing inside the signature, replace by that | ||
'formatString' => '%s/%s/%s.%s', # The default format string to build signature path templates. | ||
# The four parameters are specified below | ||
'baseDir' => 'plugins/identiteam/templates/', # Base directory where the templates are stored. | ||
# The path is relative to roundcube folder, use '/' as first character to use absolute path. | ||
'folderName' => 'default', # You can use also %d for domain name, the right part of the email address | ||
'fileName' => 'default', # You can use also %u for user name left of the email address | ||
'extension' => 'tmpl' # The default filenames extensions for signature files. Do not change the value unless needed | ||
# HTML/TEXT is automatically detected from the file content. | ||
) | ||
); | ||
|
||
|
||
|
This file contains 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,206 @@ | ||
<?php | ||
/* | ||
* Identiteam: Create users' identities and signature by querying an LDAP server. | ||
* Author: André Rodier <andre.rodier@gmail.com> | ||
* Licence: GPLv3. (See copying) | ||
*/ | ||
class identiteam extends rcube_plugin | ||
{ | ||
public $task = 'login'; | ||
|
||
private $config; | ||
private $app; | ||
|
||
# LDAP parameters | ||
private $ldap ; | ||
private $server ; | ||
private $filter ; | ||
private $domain ; | ||
private $fields ; | ||
private $conn ; | ||
|
||
|
||
function init() | ||
{ | ||
# Load default config, and merge with users' settings | ||
$this->load_config('config-default.inc.php'); | ||
$this->load_config('config.inc.php'); | ||
|
||
$this->app = rcmail::get_instance(); | ||
$this->config = $this->app->config->get('identiteam'); | ||
|
||
# Load LDAP config at once | ||
$this->ldap = $this->config['ldap']; | ||
|
||
$this->server = $this->ldap['server']; | ||
$this->filter = $this->ldap['filter']; | ||
$this->domain = $this->ldap['domain']; | ||
|
||
# Get these fields | ||
$this->fields = split(",",$this->ldap['fields']); | ||
array_push($this->fields, $this->ldap['extraEmailField']); | ||
|
||
$this->conn = ldap_connect($this->server); | ||
|
||
if ( is_resource($this->conn) ) | ||
{ | ||
ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3); | ||
|
||
$bound = ldap_bind($this->conn); | ||
|
||
if ( $bound ) | ||
{ | ||
# Create signature | ||
$this->add_hook('user2email', array($this, 'user2email')); | ||
} | ||
else | ||
{ | ||
$log = sprintf("Bind to server '%s' failed. Con: (%s), Error: (%s)", | ||
$this->server, | ||
$this->conn, | ||
ldap_errno($this->conn)); | ||
write_log('identiteam', $log); | ||
} | ||
} | ||
else | ||
{ | ||
$log = sprintf("Connection to the server failed: (Error=%s)", ldap_errno($this->conn)); | ||
write_log('identiteam', $log); | ||
} | ||
} | ||
|
||
function user2email($args) | ||
{ | ||
# load ldap confg | ||
$ldap = $this->ldap; | ||
|
||
# Open the connection and start to search | ||
$login = $args['user']; | ||
|
||
$filter = sprintf($ldap['filter'], $login); | ||
$result = ldap_search($this->conn, $this->domain, $filter, $this->fields); | ||
|
||
if ( $result ) | ||
{ | ||
$info = ldap_get_entries($this->conn, $result); | ||
$nbr = ldap_count_entries($this->conn, $result); | ||
|
||
if ( $info['count'] == 1 ) | ||
{ | ||
$userInfo = $info[0]; | ||
$identities = array(); | ||
$emails = array($userInfo["mail"][0]); | ||
|
||
$extraEmailField = $ldap['extraEmailField']; | ||
$extraEmails = $userInfo[$extraEmailField]; | ||
|
||
if ( $extraEmails['count'] > 0 ) | ||
{ | ||
$count = $extraEmails['count']; | ||
|
||
for ( $e=0; $e < $count ; $e++ ) | ||
{ | ||
array_push($emails,$extraEmails[$e]); | ||
} | ||
} | ||
|
||
foreach ( $emails as $email ) | ||
{ | ||
$dict = array(); | ||
$keys = array_keys($userInfo); | ||
foreach ( $keys as $key ) | ||
{ | ||
$dict["[$key]"] = $userInfo[$key][0]; | ||
} | ||
$dict['[mail]'] = $email; | ||
|
||
# prepare the arrays to replace into the signature template | ||
$keys = array_keys($dict); | ||
$vals = array_values($dict); | ||
|
||
$tmplConfig = $this->config['templates']; | ||
$baseDir = $tmplConfig['baseDir']; | ||
$extension = $tmplConfig['extension']; | ||
$folderName = $tmplConfig['folderName']; | ||
$fileName = $tmplConfig['fileName']; | ||
$formatString = $tmplConfig['formatString']; | ||
|
||
if ( $folderName == '%d' || $fileName == '%u' ) | ||
{ | ||
list($user,$domain) = split('@', $email); | ||
|
||
if ( $folderName == '%d' ) $folderName = $domain ; | ||
if ( $fileName == '%u' ) $fileName = $user ; | ||
} | ||
|
||
$signPath = sprintf($formatString, $baseDir, $folderName, $fileName, $extension); | ||
|
||
if ( !file_exists($signPath) ) | ||
{ | ||
$log = sprintf("Signature template not found: (path=%s). Trying default in custom folder", $signPath); | ||
write_log('identiteam', $log); | ||
$signPath = sprintf("%s/default/default.%s", $baseDir, $extension); | ||
} | ||
if ( !file_exists($signPath) ) | ||
{ | ||
$log = sprintf("Signature template not found: (path=%s). Using default one", $signPath); | ||
write_log('identiteam', $log); | ||
$signPath = "plugins/identiteam/templates/default/default.tmpl"; | ||
} | ||
|
||
# Create signature | ||
if ( file_exists($signPath) ) | ||
{ | ||
$sign = file_get_contents($signPath); | ||
$sign = str_replace($keys,$vals,$sign); | ||
|
||
# remove empty fields from the signature | ||
$repl = $tmplConfig['emptyValues']; | ||
$sign = preg_replace('/\[[a-zA-Z]+\]/', $repl, $sign); | ||
|
||
# If the signature start with an HTNL tag, | ||
# it is automatically considered as an HTML signature. | ||
$isHtml = 0; | ||
if ( preg_match('/^\s*<[a-zA-Z]+/', $sign) ) | ||
$isHtml = 1; | ||
|
||
$identities[] = array( | ||
'email' => $email, | ||
'name' => $userInfo['cn'][0], | ||
'organization' => $userInfo['o'][0], | ||
'reply-to' => '', | ||
'signature' => $sign, | ||
'html_signature' => $isHtml | ||
); | ||
} | ||
else | ||
{ | ||
$log = sprintf("Warning: signature template not found: (path=%s)", $signPath); | ||
write_log('identiteam', $log); | ||
} | ||
} | ||
|
||
$args['email'] = $identities; | ||
} | ||
else | ||
{ | ||
$log = sprintf("User '%s' not found (pass 2). Filter: %s", $login, $filter); | ||
write_log('identiteam', $log); | ||
} | ||
} | ||
else | ||
{ | ||
$log = sprintf("User '%s' not found (pass 1). Filter: %s", $login, $filter); | ||
write_log('identiteam', $log); | ||
} | ||
|
||
# We may close the connection before, | ||
# unless closing connection freed ressources | ||
# we use... | ||
ldap_close($this->conn); | ||
|
||
return $args; | ||
} | ||
|
||
} | ||
?> |
This file contains 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,6 @@ | ||
<p id="signature" style="font-size:smaller;color:595959;"> | ||
<span style="font-weight:bold">[cn]</span><br /> | ||
<span>[postaladdress]</span><br /> | ||
<span>Telephone: [telephonenumber]</span><br /> | ||
<span>Mobile: [mobile]</span> | ||
</p> |