From 43c5c5e7fcd444a790f4d38d4103422042e0346d Mon Sep 17 00:00:00 2001 From: Roman Mueller Date: Sun, 22 Mar 2015 17:43:41 +0100 Subject: [PATCH] MODULES-1789 add initial mod_geoip support --- README.md | 36 ++++++++++++++++++++++++++++++++ manifests/mod/geoip.pp | 29 +++++++++++++++++++++++++ manifests/params.pp | 1 + templates/mod/geoip.conf.erb | 22 +++++++++++++++++++ templates/vhost/_directories.erb | 3 +++ 5 files changed, 91 insertions(+) create mode 100644 manifests/mod/geoip.pp create mode 100644 templates/mod/geoip.conf.erb diff --git a/README.md b/README.md index ee8897274..87f441288 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ * [Classes: apache::mod::*](#classes-apachemodname) * [Class: apache::mod::alias](#class-apachemodalias) * [Class: apache::mod::event](#class-apachemodevent) + * [Class: apache::mod::geoip](#class-apachemodgeoip) * [Class: apache::mod::info](#class-apachemodinfo) * [Class: apache::mod::pagespeed](#class-apachemodpagespeed) * [Class: apache::mod::php](#class-apachemodphp) @@ -624,6 +625,25 @@ Installs and manages mod_auth_cas. The parameters `cas_login_url` and `cas_valid Full documentation on mod_auth_cas is available from [JASIG](https://github.com/Jasig/mod_auth_cas). +####Class: `apache::mod::geoip` + +Installs and manages mod_geoip. + +Full documentation on mod_geoip is available from [MaxMind](http://dev.maxmind.com/geoip/legacy/mod_geoip2/). + +These are the default settings: + +```puppet + class {'apache::mod::geoip': + $enable => 'Off', + $dbfile => '/usr/share/GeoIP/GeoIP.dat', + $flag => 'Standard', + $output => 'All', + } +``` + +The parameter `dbfile` can be a single directory or a hash of directories. + ####Class: `apache::mod::info` Installs and manages mod_info which provides a comprehensive overview of the server configuration. @@ -1829,6 +1849,22 @@ An array of hashes used to override the [ErrorDocument](https://httpd.apache.org } ``` +######`geoip_enable` + +Sets the [GeoIPEnable](http://dev.maxmind.com/geoip/legacy/mod_geoip2/#Configuration) directive. +Note that you must declare `class {'apache::mod::geoip': }` before using this directive. + +```puppet + apache::vhost { 'first.example.com': + docroot => '/var/www/first', + directories => [ + { path => '/var/www/first', + geoip_enable => 'On', + }, + ], + } +``` + ######`headers` Adds lines for [Header](http://httpd.apache.org/docs/current/mod/mod_headers.html#header) directives. diff --git a/manifests/mod/geoip.pp b/manifests/mod/geoip.pp new file mode 100644 index 000000000..5f4a8ab1d --- /dev/null +++ b/manifests/mod/geoip.pp @@ -0,0 +1,29 @@ +class apache::mod::geoip ( + $enable = 'Off', + $dbfile = '/usr/share/GeoIP/GeoIP.dat', + $flag = 'Standard', + $output = 'All', + $enableutf8 = undef, + $scanproxyheaders = undef, + $uselastxforwarededforip = undef, +) { + ::apache::mod { 'geoip': } + + # Template uses: + # - enable + # - dbfile + # - flag + # - output + # - enableutf8 + # - scanproxyheaders + # - uselastxforwarededforip + file { 'geoip.conf': + ensure => file, + path => "${::apache::mod_dir}/geoip.conf", + content => template('apache/mod/geoip.conf.erb'), + require => Exec["mkdir ${::apache::mod_dir}"], + before => File[$::apache::mod_dir], + notify => Class['apache::service'], + } + +} diff --git a/manifests/params.pp b/manifests/params.pp index 54b74e64b..ce5edec12 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -77,6 +77,7 @@ }, 'fastcgi' => 'mod_fastcgi', 'fcgid' => 'mod_fcgid', + 'geoip' => 'mod_geoip', 'ldap' => $::apache::version::distrelease ? { '7' => 'mod_ldap', default => undef, diff --git a/templates/mod/geoip.conf.erb b/templates/mod/geoip.conf.erb new file mode 100644 index 000000000..92f5dd687 --- /dev/null +++ b/templates/mod/geoip.conf.erb @@ -0,0 +1,22 @@ +GeoIPEnable <%= @enable %> + +<%- if @dbfile and ! [ false, 'false', '' ].include?(@dbfile) -%> + <%- if @dbfile.kind_of?(Array) -%> + <%- Array(@dbfile).each do |file| -%> +GeoIPDBFile <%= file %> <%= @flag %> + <%- end -%> + <%- else -%> +GeoIPDBFile <%= @dbfile %> <%= @flag %> + <%- end -%> +<%- end -%> +GeoIPOutput <%= @output %> +<% if @enableutf8 -%> +GeoIPEnableUTF8 <%= @enableutf8 %> +<% end -%> +<% if @scanproxyheaders -%> +GeoIPScanProxyHeaders <%= @scanproxyheaders %> +<% end -%> +<% if @uselastxforwarededforip -%> +GeoIPUseLastXForwardedForIP <%= @uselastxforwarededforip %> +<% end -%> + diff --git a/templates/vhost/_directories.erb b/templates/vhost/_directories.erb index 4f40cace4..e31e31b0d 100644 --- a/templates/vhost/_directories.erb +++ b/templates/vhost/_directories.erb @@ -34,6 +34,9 @@ Header <%= header %> <%- end -%> <%- end -%> + <%- if directory['geoip_enable'] and directory['geoip_enable'] != '' -%> + GeoIPEnable <%= directory['geoip_enable'] %> + <%- end -%> <%- if directory['options'] -%> Options <%= Array(directory['options']).join(' ') %> <%- end -%>