Skip to content

Commit 43c5c5e

Browse files
committed
MODULES-1789 add initial mod_geoip support
1 parent 7dde9fc commit 43c5c5e

5 files changed

Lines changed: 91 additions & 0 deletions

File tree

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [Classes: apache::mod::*](#classes-apachemodname)
1717
* [Class: apache::mod::alias](#class-apachemodalias)
1818
* [Class: apache::mod::event](#class-apachemodevent)
19+
* [Class: apache::mod::geoip](#class-apachemodgeoip)
1920
* [Class: apache::mod::info](#class-apachemodinfo)
2021
* [Class: apache::mod::pagespeed](#class-apachemodpagespeed)
2122
* [Class: apache::mod::php](#class-apachemodphp)
@@ -624,6 +625,25 @@ Installs and manages mod_auth_cas. The parameters `cas_login_url` and `cas_valid
624625

625626
Full documentation on mod_auth_cas is available from [JASIG](https://github.com/Jasig/mod_auth_cas).
626627

628+
####Class: `apache::mod::geoip`
629+
630+
Installs and manages mod_geoip.
631+
632+
Full documentation on mod_geoip is available from [MaxMind](http://dev.maxmind.com/geoip/legacy/mod_geoip2/).
633+
634+
These are the default settings:
635+
636+
```puppet
637+
class {'apache::mod::geoip':
638+
$enable => 'Off',
639+
$dbfile => '/usr/share/GeoIP/GeoIP.dat',
640+
$flag => 'Standard',
641+
$output => 'All',
642+
}
643+
```
644+
645+
The parameter `dbfile` can be a single directory or a hash of directories.
646+
627647
####Class: `apache::mod::info`
628648

629649
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
18291849
}
18301850
```
18311851

1852+
######`geoip_enable`
1853+
1854+
Sets the [GeoIPEnable](http://dev.maxmind.com/geoip/legacy/mod_geoip2/#Configuration) directive.
1855+
Note that you must declare `class {'apache::mod::geoip': }` before using this directive.
1856+
1857+
```puppet
1858+
apache::vhost { 'first.example.com':
1859+
docroot => '/var/www/first',
1860+
directories => [
1861+
{ path => '/var/www/first',
1862+
geoip_enable => 'On',
1863+
},
1864+
],
1865+
}
1866+
```
1867+
18321868
######`headers`
18331869

18341870
Adds lines for [Header](http://httpd.apache.org/docs/current/mod/mod_headers.html#header) directives.

manifests/mod/geoip.pp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class apache::mod::geoip (
2+
$enable = 'Off',
3+
$dbfile = '/usr/share/GeoIP/GeoIP.dat',
4+
$flag = 'Standard',
5+
$output = 'All',
6+
$enableutf8 = undef,
7+
$scanproxyheaders = undef,
8+
$uselastxforwarededforip = undef,
9+
) {
10+
::apache::mod { 'geoip': }
11+
12+
# Template uses:
13+
# - enable
14+
# - dbfile
15+
# - flag
16+
# - output
17+
# - enableutf8
18+
# - scanproxyheaders
19+
# - uselastxforwarededforip
20+
file { 'geoip.conf':
21+
ensure => file,
22+
path => "${::apache::mod_dir}/geoip.conf",
23+
content => template('apache/mod/geoip.conf.erb'),
24+
require => Exec["mkdir ${::apache::mod_dir}"],
25+
before => File[$::apache::mod_dir],
26+
notify => Class['apache::service'],
27+
}
28+
29+
}

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
},
7878
'fastcgi' => 'mod_fastcgi',
7979
'fcgid' => 'mod_fcgid',
80+
'geoip' => 'mod_geoip',
8081
'ldap' => $::apache::version::distrelease ? {
8182
'7' => 'mod_ldap',
8283
default => undef,

templates/mod/geoip.conf.erb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
GeoIPEnable <%= @enable %>
2+
3+
<%- if @dbfile and ! [ false, 'false', '' ].include?(@dbfile) -%>
4+
<%- if @dbfile.kind_of?(Array) -%>
5+
<%- Array(@dbfile).each do |file| -%>
6+
GeoIPDBFile <%= file %> <%= @flag %>
7+
<%- end -%>
8+
<%- else -%>
9+
GeoIPDBFile <%= @dbfile %> <%= @flag %>
10+
<%- end -%>
11+
<%- end -%>
12+
GeoIPOutput <%= @output %>
13+
<% if @enableutf8 -%>
14+
GeoIPEnableUTF8 <%= @enableutf8 %>
15+
<% end -%>
16+
<% if @scanproxyheaders -%>
17+
GeoIPScanProxyHeaders <%= @scanproxyheaders %>
18+
<% end -%>
19+
<% if @uselastxforwarededforip -%>
20+
GeoIPUseLastXForwardedForIP <%= @uselastxforwarededforip %>
21+
<% end -%>
22+

templates/vhost/_directories.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
Header <%= header %>
3535
<%- end -%>
3636
<%- end -%>
37+
<%- if directory['geoip_enable'] and directory['geoip_enable'] != '' -%>
38+
GeoIPEnable <%= directory['geoip_enable'] %>
39+
<%- end -%>
3740
<%- if directory['options'] -%>
3841
Options <%= Array(directory['options']).join(' ') %>
3942
<%- end -%>

0 commit comments

Comments
 (0)