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 aliases = Array(params[:aliases])
24 urls = Array(params[:urls])
25 directory = params[:directory] || "/srv/#{name}"
26 version = params[:version] || Chef::Wordpress.current_version
27 database_name = params[:database_name]
28 database_user = params[:database_user]
29 database_password = params[:database_password]
30 database_prefix = params[:database_prefix] || "wp_"
32 node.set_unless[:wordpress][:sites][name] = {}
34 node.set[:wordpress][:sites][name][:directory] = directory
36 node.set_unless[:wordpress][:sites][name][:auth_key] = random_password(64)
37 node.set_unless[:wordpress][:sites][name][:secure_auth_key] = random_password(64)
38 node.set_unless[:wordpress][:sites][name][:logged_in_key] = random_password(64)
39 node.set_unless[:wordpress][:sites][name][:nonce_key] = random_password(64)
40 node.set_unless[:wordpress][:sites][name][:auth_salt] = random_password(64)
41 node.set_unless[:wordpress][:sites][name][:secure_auth_salt] = random_password(64)
42 node.set_unless[:wordpress][:sites][name][:logged_in_salt] = random_password(64)
43 node.set_unless[:wordpress][:sites][name][:nonce_salt] = random_password(64)
45 mysql_user "#{database_user}@localhost" do
46 password database_password
49 mysql_database database_name do
50 permissions "#{database_user}@localhost" => :all
53 directory directory do
54 owner node[:wordpress][:user]
55 group node[:wordpress][:group]
59 subversion directory do
61 repository "http://core.svn.wordpress.org/tags/#{version}"
62 user node[:wordpress][:user]
63 group node[:wordpress][:group]
65 notifies :reload, "service[apache2]"
68 wp_config = edit_file "#{directory}/wp-config-sample.php" do |line|
69 line.gsub!(/database_name_here/, database_name)
70 line.gsub!(/username_here/, database_user)
71 line.gsub!(/password_here/, database_password)
72 line.gsub!(/wp_/, database_prefix)
74 line.gsub!(/('AUTH_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:auth_key]}'")
75 line.gsub!(/('SECURE_AUTH_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:secure_auth_key]}'")
76 line.gsub!(/('LOGGED_IN_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:logged_in_key]}'")
77 line.gsub!(/('NONCE_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:nonce_key]}'")
78 line.gsub!(/('AUTH_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:auth_salt]}'")
79 line.gsub!(/('SECURE_AUTH_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:secure_auth_salt]}'")
80 line.gsub!(/('LOGGED_IN_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:logged_in_salt]}'")
81 line.gsub!(/('NONCE_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:nonce_salt]}'")
83 if line =~ /define\('WP_DEBUG'/
86 line += " * Don't allow file editing.\n"
88 line += "define('DISALLOW_FILE_EDIT', true);\n"
90 line += "define('FORCE_SSL_LOGIN', true);\n"
91 line += "define('FORCE_SSL_ADMIN', true);\n"
98 file "#{directory}/wp-config.php" do
99 owner node[:wordpress][:user]
100 group node[:wordpress][:group]
103 notifies :reload, "service[apache2]"
106 directory "#{directory}/wp-content/uploads" do
112 file "#{directory}/sitemap.xml" do
116 file "#{directory}/sitemap.xml.gz" do
120 cookbook_file "#{directory}/googlefac54c35e800caab.html" do
122 owner node[:wordpress][:user]
123 group node[:wordpress][:group]
130 template "apache.erb"
132 variables :aliases => aliases, :urls => urls, :ssl_enabled => ssl_enabled
133 notifies :reload, "service[apache2]"
136 http_request "http://#{name}/wp-admin/upgrade.php" do
138 url "http://#{name}/wp-admin/upgrade.php?step=1"
139 subscribes :get, "subversion[#{directory}]"
142 wordpress_plugin "wp-fail2ban" do
146 script "#{directory}/wp-content/plugins/wp-fail2ban" do
153 @include "wp-config.php";
154 @include_once "wp-includes/functions.php";
155 @include_once "wp-admin/includes/plugin.php";
156 activate_plugin("wp-fail2ban/wp-fail2ban.php", '', false, false);
159 subscribes :run, "subversion[#{directory}/wp-content/plugins/wp-fail2ban]"