mailhost.pp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_string($listen_port) {
  70. warning('DEPRECATION: String $listen_port must be converted to an integer. Integer string support will be removed in a future release.')
  71. }
  72. elsif !is_integer($listen_port) {
  73. fail('$listen_port must be an integer.')
  74. }
  75. validate_re($ensure, '^(present|absent)$',
  76. "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
  77. if !(is_array($listen_ip) or is_string($listen_ip)) {
  78. fail('$listen_ip must be a string or array.')
  79. }
  80. if ($listen_options != undef) {
  81. validate_string($listen_options)
  82. }
  83. validate_bool($ipv6_enable)
  84. if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
  85. fail('$ipv6_listen_ip must be a string or array.')
  86. }
  87. if is_string($ipv6_listen_port) {
  88. warning('DEPRECATION: String $ipv6_listen_port must be converted to an integer. Integer string support will be removed in a future release.')
  89. }
  90. elsif !is_integer($ipv6_listen_port) {
  91. fail('$ipv6_listen_port must be an integer.')
  92. }
  93. validate_string($ipv6_listen_options)
  94. validate_bool($ssl)
  95. if ($ssl_cert != undef) {
  96. validate_string($ssl_cert)
  97. }
  98. if ($ssl_key != undef) {
  99. validate_string($ssl_key)
  100. }
  101. if $ssl_port != undef {
  102. if is_string($ssl_port) {
  103. warning('DEPRECATION: String $ssl_port must be converted to an integer. Integer string support will be removed in a future release.')
  104. }
  105. elsif !is_integer($ssl_port) {
  106. fail('$ssl_port must be an integer.')
  107. }
  108. }
  109. validate_re($starttls, '^(on|only|off)$',
  110. "${starttls} is not supported for starttls. Allowed values are 'on', 'only' and 'off'.")
  111. if ($protocol != undef) {
  112. validate_string($protocol)
  113. }
  114. if ($auth_http != undef) {
  115. validate_string($auth_http)
  116. }
  117. validate_string($xclient)
  118. validate_array($server_name)
  119. $config_file = "${::nginx::config::conf_dir}/conf.mail.d/${name}.conf"
  120. # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
  121. # and support does not exist for it in the kernel.
  122. if ($ipv6_enable and !$::ipaddress6) {
  123. warning('nginx: IPv6 support is not enabled or configured properly')
  124. }
  125. # Check to see if SSL Certificates are properly defined.
  126. if ($ssl or $starttls == 'on' or $starttls == 'only') {
  127. if ($ssl_cert == undef) or ($ssl_key == undef) {
  128. fail('nginx: SSL certificate/key (ssl_cert/ssl_cert) and/or SSL Private must be defined and exist on the target system(s)')
  129. }
  130. }
  131. concat { $config_file:
  132. owner => 'root',
  133. group => $root_group,
  134. mode => '0644',
  135. notify => Class['::nginx::service'],
  136. }
  137. if (($ssl_port == undef) or ($listen_port + 0) != ($ssl_port + 0)) {
  138. concat::fragment { "${name}-header":
  139. target => $config_file,
  140. content => template('nginx/mailhost/mailhost.erb'),
  141. order => '001',
  142. }
  143. }
  144. # Create SSL File Stubs if SSL is enabled
  145. if ($ssl) {
  146. concat::fragment { "${name}-ssl":
  147. target => $config_file,
  148. content => template('nginx/mailhost/mailhost_ssl.erb'),
  149. order => '700',
  150. }
  151. }
  152. }