{
    #------------------------------------------------------------
    # get a list of our virtual hosts and make a hash table so we
    # can look up content later
    #------------------------------------------------------------

    $OUT = '';

    use esmith::DomainsDB;

    my $db = esmith::DomainsDB->open_ro;
    unless ($db)
    {
	warn "Couldn't open domains DB in VirtualHosts template fragment";
	return;
    }

    my @domains = $db->get_all_by_prop('type' => 'domain');
    #------------------------------------------------------------
    # generate VirtualHosts - primary domain first
    #------------------------------------------------------------
    foreach my $domain (
	(grep { ($_->prop('SystemPrimaryDomain') || 'no') eq 'yes' } @domains),
	(grep { ($_->prop('SystemPrimaryDomain') || 'no') ne 'yes' } @domains),
			)
    {
	my $templatePath = $domain->prop('TemplatePath') || 'VirtualHosts';
	foreach my $port (qw(80 443))
	{
	    my %virtualHost = (
		ipAddress => '0.0.0.0',
		port => $port,
		localAccess => $localAccess,
		externalSSLAccess => $externalSSLAccess,
		domain => $domain,
	    );

	    $OUT .= esmith::templates::processTemplate (
	    {
		MORE_DATA => \%virtualHost,
		TEMPLATE_PATH =>
		    "/etc/httpd/conf/httpd.conf/$templatePath",
		OUTPUT_TYPE => 'string',
	    });
	}
    }
}
