GenerateSignatureFromLDAP Code
Automatically generate Outlook signatures based on templates and LDAP.
Brought to you by:
brechtsanders
Project name:
GenerateSignatureFromLDAP
Short name:
gensignfromldap
Description:
Small signature generator for Microsoft Outlook, ideal for use in logon scripts.
Outlook signature files are generated based on templates that pull data from Active Directory using LDAP.
The goal is to have a small self-contained executable that is fast and as invisible as possible.
License:
This program is distributed under the GNU General Public License v3 (see the file COPYING)
This project makes use of the following other open source project:
wxWidgets (http://www.wxwidgets.org/)
Templates:
From the files in the template directory the following files are copied without changes:
".gif", ".jpg", ".jpeg", ".png"
and the following files will be parsed as template files:
".htm", ".html", ".rtf", ".txt"
Anything inside a template file starting with a percent character (%) will be parsed as follows:
%% replace with percent character (%)
%attr% replace with LDAP attribute attr
%{function}
%{function|param1}
%{function|param1|param2|...}
perform built-in function with the specified parameters
Inside built-in function parameters the following have special meaning:
% processed as described above
\t tab character
\r carriage return character
\n line feed character
\\ backslash character (\)
\| pipe character (|)
\xNN character with hexadecimal ASCII code NN
The following functions are available
listall lists all LDAP attributes found, each line has the format: %attribute% = value
ldapvar returns the value of the LDAP attibute specified in the first parameter, an optional second parameter specifies the separator to join multiple values
envvar returns the environment variable value specified in the first parameter, an optional second parameter specifies default value to return if not found
var returns the local variable value specified in the first parameter
setvar sets the local variable value specified in the first parameter to the value specified in the second parameter, returns empty
if returns the second parameter if the first parameter is not empty or not zero, else returns the third parameter (if present)
not returns 1 if the first parameter is empty or zero
and returns 1 if all parameters evaluate to non-empty and non-zero
or returns 1 if any of the parameters evaluate to non-empty and non-zero
eq returns 1 if both parameters are equal (case sensitive string comparison)
ne returns 1 if both parameters are not equal (case sensitive string comparison)
lt returns 1 if the first parameters is less than the second (case sensitive string comparison)
lte returns 1 if the first parameters is less or equal than the second (case sensitive string comparison)
gt returns 1 if the first parameters is greater than the second (case sensitive string comparison)
gte returns 1 if the first parameters is greater or equal than the second (case sensitive string comparison)
contains returns 1 if the second parameter is found in the first parameter
notcontains returns 1 if the second parameter is not found in the first parameter
upper converts parameter to upper case
lower converts parameter to lower case
rtfquote escape all special characters (\,{,}) for use in RTF
htmlquote replaces all special characters (&,",',<,>) for use in HTML
nl2br replaces all newline characters with HTML newlines (<br/>)
replace replaces all occurrences of the second parameter in the first parameter with the third parameter
substr returns a substring of the first parameter (second parameter = position, optional third parameter = length)
include call another template file (relative to template directory) and include the results
templatedir returns template directory (may be relative to the directory the program was launched from)
templatefile returns template file name
datetime returns date/time according to specified optional strftime format (default is %Y-%m-%d %H:%M:%S), note: don't forget to double each %
ldapmemberof returns 1 if user is member of group specified with first parameter (in Common Name notation)
programversion returns version information
cancel stop processing the current template and remove the destination file
cr returns carriage return character (ASCII code 13)
lf returns line feed character (ASCII code 10)
crlf returns carriage return and line feed characters (ASCII codes 13 and 10)
base64encodefile returns BASE64 encoded contents of specified file (relative to template directory)
version returns program name and version number
Example templates:
The following template will generate a list of all available LDAP attributes (useful for finding certain attributes or values):
%{listall}
The following template will generate a signature with name, function, address, phone, fax, optional mobile phone number, e-mail address and website:
%cn%
%title%
%streetAddress%
Tel: %telephoneNumber%
Fax: %facsimileTelephoneNumber%
%{if|%{ne|%mobile%|}|GSM: %mobile%
}mailto:%mail%
%wWWHomePage%
Usage:
gensignfromldap [/?] [/d] [/h host[:port]] [/u user /p password] [/l user] [/b searchbase] [/t templatedir] [/s signaturedir]
Purpose:
Generates Outlook signature files based on template files and values stored in LDAP (e.g. Active Directory)
Parameters:
/? display help about command line parameters and exit
/v display version information and exit
/d popup error messages and exit
by default the program will quitely exit with a nonzero exit code
/o show detected signature directories and exit
/h host[:port] LDAP host (and optionally port) to connect to
default is the default Active Directory LDAP server
/u user LDAP authentication user login
default is to authenticate as the currently logged on domain user
/p password LDAP authentication password
default is to authenticate as the currently logged on domain user
/b searchbase LDAP search base
default is current domain's default naming context
/l user login of user to look up
default is currently logged on domain user
/t templatedir directory containing template files
default is "templates" under the directory of the executable file
/s signaturedir directory where signatures will be stored, this parameter can be used multiple times
Microsoft Office's signature directories are determined as follows:
value of environment variable APPDATA
+
"\Microsoft\"
+
registry values of HKEY_CURRENT_USER\Software\Microsoft\Office\<all keys>\Common\General\Signatures
or HKEY_LOCAL_MACHINE\Software\Microsoft\Office\<all keys>\Common\General\Signatures
if nothing was found like this the following directory will be used if it exists:
%APPDATA%\Microsoft\Signatures
so for an English version of Microsoft Office this would typically be:
C:\Documents and Settings\<username>\Application Data\Microsoft\Signatures
If you have installed multiple installations of Microsoft Office in different language versions,
even after they were uninstalled, multiple registry keys for the translations of "Signature" will be found.
In that case all possible signature directories will be used.
/n don't overwrite already existing signatures files
/r set Send Pictures With Document = 1 in registry
Note:
If a paramater contains spaces you must enclose it in double quotes (")
Usage:
GenerateTemplatesFromSignaturesGUI
GenerateTemplatesFromSignaturesConsole [/?] [/v] [/o] [/d] [/h host[:port]] [/u user /p password] [/b searchbase] [/l user] [/t templatedir] [/s signaturedir]
Purpose:
A wizard for generating templates for use with gensignfromldap based on Outlook signature files and values stored in LDAP (e.g. Active Directory)
Parameters:
/? display help about command line parameters and exit
/v display version information and exit
/o show detected signature directories and exit
/d popup error messages (default is to quitely exit with a nonzero exit code)
/h host[:port] LDAP host (and optionally port) to connect to (default is the default Active Directory LDAP server)
/u user LDAP authentication user login (default is to authenticate as the currently logged on domain user)
/p password LDAP authentication password (default is to authenticate as the currently logged on domain user)
/b searchbase LDAP search base (default is current domain's default naming context)
/l user login of user to look up (default is currently logged on domain user)
/t templatedir directory where template files will be stored (default is templates under the program's directory)
/s signaturedir directory containing signatures (default is Office's signature directory)
Note:
GenerateTemplatesFromSignaturesGUI is the Windows GUI (graphical user interface) version.
GenerateTemplatesFromSignaturesConsole is the command line version.