NAMEesmith::template - Utilities for e-smith server and gateway development
VERSIONThis file documents
SYNOPSIS
use esmith::template;
processTemplate(...);
DESCRIPTIONThis is the interface to the E-Smith templating system. For an overview of how the system works, see section ``3.4 Templated Configuration System'' of the Dev Guide. esmith::template exports a single function, processTemplate, which, as you might guess, processes sets of templates into a single output file.
Template VariablesThe following variables are available to all templates.
In addition, each record in the default esmith configuration database (configuration) is available as a hash if it has multiple properties (where each key/value is a property of the record) or if it has a single property (type) then it given as a scalar. So you can say:
{ $DomainName } # $configdb->get('DomainName')->value;
{ $sshd{status} } # $configdb->get('sshd')->prop('status')
Finally, variables from additional databases are usually gotten via the esmith::DB->as_hash feature.
{ require esmith::HostsDB;
my %Hosts = esmith::HostsDB->as_hash;
...
}
Functions
For example we have a template /etc/e-smith/templates/etc/hosts that we want to expand to /etc/hosts using the normal configuration.
# Records from esmith::ConfigDB->open will be available by default
processTemplate({
TEMPLATE_PATH => '/etc/hosts',
});
Example 2: we have a template /etc/e-smith/templates-user/qmail that we want to expand to /home/e-smith/files/users/$username/.qmail Solution:
processTemplate({
TEMPLATE_PATH => '/qmail',
TEMPLATE_EXPAND_QUEUE => [
'/etc/e-smith/templates-user-custom',
'/etc/e-smith/templates-user',
],
OUTPUT_PREFIX => '/home/e-smith/files/users/$username',
OUTPUT_FILENAME => '.qmail',
FILTER => sub { $_[0] =~ /^\s*$/ ? '' : $_[0] },
UID => $username,
GID => $username,
PERMS => 0644,
});
Example 3: we have a template fragment /etc/e-smith/templates/etc/httpd/conf/httpd.conf/80VirtualHosts that needs to iterate through the given list of VirtualHosts, process each template and return the results in a string until all the VirtualHosts have been completed. The results will be expanded into the /etc/httpd/conf/httpd.conf file. Solution: In the 80VirtualHosts fragment, we use the OUTPUT_TYPE='string' option to return the output of processTemplate for each VirtualHost as a string, and then we add the results to the $OUT variable for inclusion in the httpd.conf template expansion. We store the VirtualHosts template in /etc/httpd/conf/httpd.conf/VirtualHosts for clarity and namespace separation.
foreach my $ipAddress (keys %ipAddresses)
{
# the $OUT variable stores the output of this template fragment
use esmith::templates;
$OUT .= processTemplate (
{
MORE_DATA => { ipAddress => $ipAddress, port => $port,
virtualHosts => \@virtualHosts,
virtualHostContent => \%virtualHostContent },
TEMPLATE_PATH => "/etc/httpd/conf/httpd.conf/VirtualHosts",
OUTPUT_TYPE => 'string',
});
}
FiltersFilters are an experimental feature which allow you to filter the output of a template in various ways. Filtering functions take a single line at a time and return the filtered version.
SEE ALSOSection 3.4 ``Templated Configuration System'' of the E-Smith Dev Guide
AUTHORMitel Networks Corporation For more information, see http://www.e-smith.org/ |
|
smeserver.fr Site consacré à la distribution Linux SME Server Site sous licence Creative Commons (by, nc, sa) |