2 # Cookbook Name:: wordpress
3 # Definition:: wordpress_site
5 # Copyright 2013, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 define :wordpress_site, :action => [ :create, :enable ] do
22 ssl_enabled = params[:ssl_enabled] || false
23 ssl_certificate = params[:ssl_certificate]
24 aliases = Array(params[:aliases])
25 urls = Array(params[:urls])
26 directory = params[:directory] || "/srv/#{name}"
27 version = params[:version] || Chef::Wordpress.current_version
28 database_name = params[:database_name]
29 database_user = params[:database_user]
30 database_password = params[:database_password]
31 database_prefix = params[:database_prefix] || "wp_"
33 node.set_unless[:wordpress][:sites][name] = {}
35 node.set[:wordpress][:sites][name][:directory] = directory
37 node.set_unless[:wordpress][:sites][name][:auth_key] = random_password(64)
38 node.set_unless[:wordpress][:sites][name][:secure_auth_key] = random_password(64)
39 node.set_unless[:wordpress][:sites][name][:logged_in_key] = random_password(64)
40 node.set_unless[:wordpress][:sites][name][:nonce_key] = random_password(64)
41 node.set_unless[:wordpress][:sites][name][:auth_salt] = random_password(64)
42 node.set_unless[:wordpress][:sites][name][:secure_auth_salt] = random_password(64)
43 node.set_unless[:wordpress][:sites][name][:logged_in_salt] = random_password(64)
44 node.set_unless[:wordpress][:sites][name][:nonce_salt] = random_password(64)
46 mysql_user "#{database_user}@localhost" do
47 password database_password
50 mysql_database database_name do
51 permissions "#{database_user}@localhost" => :all
54 directory directory do
55 owner node[:wordpress][:user]
56 group node[:wordpress][:group]
60 subversion directory do
62 repository "http://core.svn.wordpress.org/tags/#{version}"
63 user node[:wordpress][:user]
64 group node[:wordpress][:group]
66 notifies :reload, "service[apache2]"
69 wp_config = edit_file "#{directory}/wp-config-sample.php" do |line|
70 line.gsub!(/database_name_here/, database_name)
71 line.gsub!(/username_here/, database_user)
72 line.gsub!(/password_here/, database_password)
73 line.gsub!(/wp_/, database_prefix)
75 line.gsub!(/('AUTH_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:auth_key]}'")
76 line.gsub!(/('SECURE_AUTH_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:secure_auth_key]}'")
77 line.gsub!(/('LOGGED_IN_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:logged_in_key]}'")
78 line.gsub!(/('NONCE_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:nonce_key]}'")
79 line.gsub!(/('AUTH_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:auth_salt]}'")
80 line.gsub!(/('SECURE_AUTH_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:secure_auth_salt]}'")
81 line.gsub!(/('LOGGED_IN_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:logged_in_salt]}'")
82 line.gsub!(/('NONCE_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:nonce_salt]}'")
84 if line =~ /define\('WP_DEBUG'/
87 line += " * Don't allow file editing.\n"
89 line += "define('DISALLOW_FILE_EDIT', true);\n"
91 line += "define('FORCE_SSL_LOGIN', true);\n"
92 line += "define('FORCE_SSL_ADMIN', true);\n"
99 file "#{directory}/wp-config.php" do
100 owner node[:wordpress][:user]
101 group node[:wordpress][:group]
104 notifies :reload, "service[apache2]"
107 directory "#{directory}/wp-content/uploads" do
113 file "#{directory}/sitemap.xml" do
117 file "#{directory}/sitemap.xml.gz" do
121 cookbook_file "#{directory}/googlefac54c35e800caab.html" do
123 owner node[:wordpress][:user]
124 group node[:wordpress][:group]
131 template "apache.erb"
133 variables :aliases => aliases, :urls => urls,
134 :ssl_enabled => ssl_enabled, :ssl_certificate => ssl_certificate
135 notifies :reload, "service[apache2]"
138 http_request "http://#{name}/wp-admin/upgrade.php" do
140 url "http://#{name}/wp-admin/upgrade.php?step=1"
141 subscribes :get, "subversion[#{directory}]"
144 wordpress_plugin "wp-fail2ban" do
148 script "#{directory}/wp-content/plugins/wp-fail2ban" do
155 @include "wp-config.php";
156 @include_once "wp-includes/functions.php";
157 @include_once "wp-admin/includes/plugin.php";
158 activate_plugin("wp-fail2ban/wp-fail2ban.php", '', false, false);
161 subscribes :run, "subversion[#{directory}/wp-content/plugins/wp-fail2ban]"