add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
# define: nginx::resource::mailhost
|
|
|
|
#
|
|
|
|
# This definition creates a virtual host
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# [*ensure*] - Enables or disables the specified mailhost (present|absent)
|
|
|
|
# [*listen_ip*] - Default IP Address for NGINX to listen with this vHost on. Defaults to all interfaces (*)
|
|
|
|
# [*listen_port*] - Default IP Port for NGINX to listen with this vHost on. Defaults to TCP 80
|
|
|
|
# [*listen_options*] - Extra options for listen directive like 'default' to catchall. Undef by default.
|
|
|
|
# [*ipv6_enable*] - BOOL value to enable/disable IPv6 support (false|true). Module will check to see if IPv6
|
|
|
|
# support exists on your system before enabling.
|
|
|
|
# [*ipv6_listen_ip*] - Default IPv6 Address for NGINX to listen with this vHost on. Defaults to all interfaces (::)
|
|
|
|
# [*ipv6_listen_port*] - Default IPv6 Port for NGINX to listen with this vHost on. Defaults to TCP 80
|
|
|
|
# [*ipv6_listen_options*] - Extra options for listen directive like 'default' to catchall. Template will allways add ipv6only=on.
|
|
|
|
# While issue jfryman/puppet-nginx#30 is discussed, default value is 'default'.
|
|
|
|
# [*index_files*] - Default index files for NGINX to read when traversing a directory
|
|
|
|
# [*ssl*] - Indicates whether to setup SSL bindings for this mailhost.
|
|
|
|
# [*ssl_cert*] - Pre-generated SSL Certificate file to reference for SSL Support. This is not generated by this module.
|
|
|
|
# [*ssl_key*] - Pre-generated SSL Key file to reference for SSL Support. This is not generated by this module.
|
|
|
|
# [*ssl_port*] - Default IP Port for NGINX to listen with this SSL vHost on. Defaults to TCP 443
|
|
|
|
# [*starttls*] - enable STARTTLS support: (on|off|only)
|
|
|
|
# [*protocol*] - Mail protocol to use: (imap|pop3|smtp)
|
|
|
|
# [*auth_http*] - With this directive you can set the URL to the external HTTP-like server for authorization.
|
|
|
|
# [*xclient*] - wheter to use xclient for smtp (on|off)
|
|
|
|
# [*server_name*] - List of mailhostnames for which this mailhost will respond. Default [$name].
|
|
|
|
#
|
|
|
|
# Actions:
|
|
|
|
#
|
|
|
|
# Requires:
|
|
|
|
#
|
|
|
|
# Sample Usage:
|
|
|
|
# nginx::resource::mailhost { 'domain1.example':
|
|
|
|
# ensure => present,
|
|
|
|
# auth_http => 'server2.example/cgi-bin/auth',
|
|
|
|
# protocol => 'smtp',
|
|
|
|
# listen_port => 587,
|
|
|
|
# ssl_port => 465,
|
|
|
|
# starttls => 'only',
|
|
|
|
# xclient => 'off',
|
2013-05-26 14:24:40 +02:00
|
|
|
# ssl => true,
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
# ssl_cert => '/tmp/server.crt',
|
|
|
|
# ssl_key => '/tmp/server.pem',
|
|
|
|
# }
|
2013-04-13 13:52:21 +02:00
|
|
|
define nginx::resource::mailhost (
|
2013-05-08 14:15:42 +02:00
|
|
|
$listen_port,
|
2014-01-06 20:20:07 +01:00
|
|
|
$ensure = 'present',
|
2013-04-13 13:52:21 +02:00
|
|
|
$listen_ip = '*',
|
|
|
|
$listen_options = undef,
|
|
|
|
$ipv6_enable = false,
|
|
|
|
$ipv6_listen_ip = '::',
|
|
|
|
$ipv6_listen_port = '80',
|
2014-01-27 16:57:38 +01:00
|
|
|
$ipv6_listen_options = 'default ipv6only=on',
|
2013-04-13 13:52:21 +02:00
|
|
|
$ssl = false,
|
|
|
|
$ssl_cert = undef,
|
|
|
|
$ssl_key = undef,
|
|
|
|
$ssl_port = undef,
|
|
|
|
$starttls = 'off',
|
|
|
|
$protocol = undef,
|
|
|
|
$auth_http = undef,
|
|
|
|
$xclient = 'on',
|
2014-07-28 20:50:06 +02:00
|
|
|
$server_name = [$name]
|
|
|
|
) {
|
|
|
|
|
2014-11-27 05:33:57 +01:00
|
|
|
$root_group = $::nginx::config::root_group
|
2014-07-12 08:14:30 +02:00
|
|
|
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
File {
|
|
|
|
owner => 'root',
|
2014-07-28 20:50:06 +02:00
|
|
|
group => $root_group,
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
mode => '0644',
|
|
|
|
}
|
2014-01-27 16:57:38 +01:00
|
|
|
|
2014-01-06 20:20:07 +01:00
|
|
|
if !is_integer($listen_port) {
|
|
|
|
fail('$listen_port must be an integer.')
|
|
|
|
}
|
|
|
|
validate_re($ensure, '^(present|absent)$',
|
|
|
|
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
|
2015-01-13 17:30:00 +01:00
|
|
|
if !(is_array($listen_ip) or is_string($listen_ip)) {
|
|
|
|
fail('$listen_ip must be a string or array.')
|
|
|
|
}
|
2014-01-06 20:20:07 +01:00
|
|
|
if ($listen_options != undef) {
|
|
|
|
validate_string($listen_options)
|
|
|
|
}
|
|
|
|
validate_bool($ipv6_enable)
|
2015-01-13 17:30:00 +01:00
|
|
|
if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
|
|
|
|
fail('$ipv6_listen_ip must be a string or array.')
|
|
|
|
}
|
2014-01-06 20:20:07 +01:00
|
|
|
if !is_integer($ipv6_listen_port) {
|
|
|
|
fail('$ipv6_listen_port must be an integer.')
|
|
|
|
}
|
|
|
|
validate_string($ipv6_listen_options)
|
|
|
|
validate_bool($ssl)
|
|
|
|
if ($ssl_cert != undef) {
|
|
|
|
validate_string($ssl_cert)
|
|
|
|
}
|
|
|
|
if ($ssl_key != undef) {
|
|
|
|
validate_string($ssl_key)
|
|
|
|
}
|
|
|
|
if ($ssl_port != undef) and (!is_integer($ssl_port)) {
|
|
|
|
fail('$ssl_port must be an integer.')
|
|
|
|
}
|
|
|
|
validate_re($starttls, '^(on|only|off)$',
|
|
|
|
"${starttls} is not supported for starttls. Allowed values are 'on', 'only' and 'off'.")
|
|
|
|
if ($protocol != undef) {
|
|
|
|
validate_string($protocol)
|
|
|
|
}
|
|
|
|
if ($auth_http != undef) {
|
|
|
|
validate_string($auth_http)
|
|
|
|
}
|
|
|
|
validate_string($xclient)
|
2013-10-20 23:58:25 +02:00
|
|
|
validate_array($server_name)
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
|
2014-11-27 05:33:57 +01:00
|
|
|
$config_file = "${::nginx::config::conf_dir}/conf.mail.d/${name}.conf"
|
2013-12-01 01:49:41 +01:00
|
|
|
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
# Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
|
|
|
|
# and support does not exist for it in the kernel.
|
2013-04-13 13:52:21 +02:00
|
|
|
if ($ipv6_enable and !$::ipaddress6) {
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
warning('nginx: IPv6 support is not enabled or configured properly')
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check to see if SSL Certificates are properly defined.
|
|
|
|
if ($ssl or $starttls == 'on' or $starttls == 'only') {
|
|
|
|
if ($ssl_cert == undef) or ($ssl_key == undef) {
|
|
|
|
fail('nginx: SSL certificate/key (ssl_cert/ssl_cert) and/or SSL Private must be defined and exist on the target system(s)')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-01 01:49:41 +01:00
|
|
|
concat { $config_file:
|
|
|
|
owner => 'root',
|
2014-07-28 20:50:06 +02:00
|
|
|
group => $root_group,
|
2013-12-01 01:49:41 +01:00
|
|
|
mode => '0644',
|
2014-11-27 05:33:57 +01:00
|
|
|
notify => Class['::nginx::service'],
|
2013-12-01 01:49:41 +01:00
|
|
|
}
|
|
|
|
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
if ($listen_port != $ssl_port) {
|
2013-12-01 01:49:41 +01:00
|
|
|
concat::fragment { "${name}-header":
|
|
|
|
target => $config_file,
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
content => template('nginx/mailhost/mailhost.erb'),
|
2013-12-01 01:49:41 +01:00
|
|
|
order => '001',
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create SSL File Stubs if SSL is enabled
|
|
|
|
if ($ssl) {
|
2013-12-01 01:49:41 +01:00
|
|
|
concat::fragment { "${name}-ssl":
|
|
|
|
target => $config_file,
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
content => template('nginx/mailhost/mailhost_ssl.erb'),
|
2013-12-01 01:49:41 +01:00
|
|
|
order => '700',
|
add support for mail module
See http://wiki.nginx.org/Modules#Mail_modules
Sample Usage:
nginx::resource::mailhost { 'domain1.example':
ensure => present,
auth_http => 'server2.example/cgi-bin/auth',
protocol => 'smtp',
listen_port => 587,
ssl_port => 465,
starttls => 'only',
xclient => 'off',
ssl => 'true',
ssl_cert => '/tmp/server.crt',
ssl_key => '/tmp/server.pem',
}
2013-03-11 14:05:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|