mailhost.pp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. # define: nginx::resource::mailhost
  2. #
  3. # This definition creates a virtual host
  4. #
  5. # Parameters:
  6. # [*ensure*] - Enables or disables the specified mailhost (present|absent)
  7. # [*listen_ip*] - Default IP Address for NGINX to listen with this vHost on. Defaults to all interfaces (*)
  8. # [*listen_port*] - Default IP Port for NGINX to listen with this vHost on. Defaults to TCP 80
  9. # [*listen_options*] - Extra options for listen directive like 'default' to catchall. Undef by default.
  10. # [*ipv6_enable*] - BOOL value to enable/disable IPv6 support (false|true). Module will check to see if IPv6
  11. # support exists on your system before enabling.
  12. # [*ipv6_listen_ip*] - Default IPv6 Address for NGINX to listen with this vHost on. Defaults to all interfaces (::)
  13. # [*ipv6_listen_port*] - Default IPv6 Port for NGINX to listen with this vHost on. Defaults to TCP 80
  14. # [*ipv6_listen_options*] - Extra options for listen directive like 'default' to catchall. Template will allways add ipv6only=on.
  15. # While issue jfryman/puppet-nginx#30 is discussed, default value is 'default'.
  16. # [*index_files*] - Default index files for NGINX to read when traversing a directory
  17. # [*ssl*] - Indicates whether to setup SSL bindings for this mailhost.
  18. # [*ssl_cert*] - Pre-generated SSL Certificate file to reference for SSL Support. This is not generated by this module.
  19. # [*ssl_key*] - Pre-generated SSL Key file to reference for SSL Support. This is not generated by this module.
  20. # [*ssl_port*] - Default IP Port for NGINX to listen with this SSL vHost on. Defaults to TCP 443
  21. # [*starttls*] - enable STARTTLS support: (on|off|only)
  22. # [*protocol*] - Mail protocol to use: (imap|pop3|smtp)
  23. # [*auth_http*] - With this directive you can set the URL to the external HTTP-like server for authorization.
  24. # [*xclient*] - wheter to use xclient for smtp (on|off)
  25. # [*server_name*] - List of mailhostnames for which this mailhost will respond. Default [$name].
  26. #
  27. # Actions:
  28. #
  29. # Requires:
  30. #
  31. # Sample Usage:
  32. # nginx::resource::mailhost { 'domain1.example':
  33. # ensure => present,
  34. # auth_http => 'server2.example/cgi-bin/auth',
  35. # protocol => 'smtp',
  36. # listen_port => 587,
  37. # ssl_port => 465,
  38. # starttls => 'only',
  39. # xclient => 'off',
  40. # ssl => true,
  41. # ssl_cert => '/tmp/server.crt',
  42. # ssl_key => '/tmp/server.pem',
  43. # }
  44. define nginx::resource::mailhost (
  45. $listen_port,
  46. $ensure = 'present',
  47. $listen_ip = '*',
  48. $listen_options = undef,
  49. $ipv6_enable = false,
  50. $ipv6_listen_ip = '::',
  51. $ipv6_listen_port = '80',
  52. $ipv6_listen_options = 'default ipv6only=on',
  53. $ssl = false,
  54. $ssl_cert = undef,
  55. $ssl_key = undef,
  56. $ssl_port = undef,
  57. $starttls = 'off',
  58. $protocol = undef,
  59. $auth_http = undef,
  60. $xclient = 'on',
  61. $server_name = [$name]
  62. ) {
  63. $root_group = $::nginx::config::root_group
  64. File {
  65. owner => 'root',
  66. group => $root_group,
  67. mode => '0644',
  68. }
  69. if !is_integer($listen_port) {
  70. fail('$listen_port must be an integer.')
  71. }
  72. validate_re($ensure, '^(present|absent)$',
  73. "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
  74. if !(is_array($listen_ip) or is_string($listen_ip)) {
  75. fail('$listen_ip must be a string or array.')
  76. }
  77. if ($listen_options != undef) {
  78. validate_string($listen_options)
  79. }
  80. validate_bool($ipv6_enable)
  81. if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
  82. fail('$ipv6_listen_ip must be a string or array.')
  83. }
  84. if !is_integer($ipv6_listen_port) {
  85. fail('$ipv6_listen_port must be an integer.')
  86. }
  87. validate_string($ipv6_listen_options)
  88. validate_bool($ssl)
  89. if ($ssl_cert != undef) {
  90. validate_string($ssl_cert)
  91. }
  92. if ($ssl_key != undef) {
  93. validate_string($ssl_key)
  94. }
  95. if ($ssl_port != undef) and (!is_integer($ssl_port)) {
  96. fail('$ssl_port must be an integer.')
  97. }
  98. validate_re($starttls, '^(on|only|off)$',
  99. "${starttls} is not supported for starttls. Allowed values are 'on', 'only' and 'off'.")
  100. if ($protocol != undef) {
  101. validate_string($protocol)
  102. }
  103. if ($auth_http != undef) {
  104. validate_string($auth_http)
  105. }
  106. validate_string($xclient)
  107. validate_array($server_name)
  108. $config_file = "${::nginx::config::conf_dir}/conf.mail.d/${name}.conf"
  109. # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
  110. # and support does not exist for it in the kernel.
  111. if ($ipv6_enable and !$::ipaddress6) {
  112. warning('nginx: IPv6 support is not enabled or configured properly')
  113. }
  114. # Check to see if SSL Certificates are properly defined.
  115. if ($ssl or $starttls == 'on' or $starttls == 'only') {
  116. if ($ssl_cert == undef) or ($ssl_key == undef) {
  117. fail('nginx: SSL certificate/key (ssl_cert/ssl_cert) and/or SSL Private must be defined and exist on the target system(s)')
  118. }
  119. }
  120. concat { $config_file:
  121. owner => 'root',
  122. group => $root_group,
  123. mode => '0644',
  124. notify => Class['::nginx::service'],
  125. }
  126. if ($listen_port != $ssl_port) {
  127. concat::fragment { "${name}-header":
  128. target => $config_file,
  129. content => template('nginx/mailhost/mailhost.erb'),
  130. order => '001',
  131. }
  132. }
  133. # Create SSL File Stubs if SSL is enabled
  134. if ($ssl) {
  135. concat::fragment { "${name}-ssl":
  136. target => $config_file,
  137. content => template('nginx/mailhost/mailhost_ssl.erb'),
  138. order => '700',
  139. }
  140. }
  141. }