Skip to content

Commit f9bb75f

Browse files
committed
add python env and components; apache conf; server setup script
1 parent 7a3f6c1 commit f9bb75f

11 files changed

+352
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
python_env/bin
2+
python_env/build
3+
python_env/include
4+
python_env/lib
5+
!python_env/bin/ccengine.fcgi.in
16
wp-content/backup/*
27
wp-content/cache/*
38
wp-content/upgrade/*

.gitmodules

+16
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,19 @@
1616
[submodule "wp-content/themes/creativecommons.org"]
1717
path = docroot/wp-content/themes/creativecommons.org
1818
url = https://github.com/creativecommons/theme-creativecommons.org.git
19+
[submodule "python_env/src/i18n"]
20+
path = python_env/src/i18n
21+
url = https://github.com/creativecommons/i18n
22+
branch = master
23+
[submodule "python_env/src/license.rdf"]
24+
path = python_env/src/license.rdf
25+
url = https://github.com/creativecommons/license.rdf
26+
branch = master
27+
[submodule "python_env/src/cc.license"]
28+
path = python_env/src/cc.license
29+
url = https://github.com/creativecommons/cc.license
30+
branch = master
31+
[submodule "python_env/src/cc.engine"]
32+
path = python_env/src/cc.engine
33+
url = https://github.com/creativecommons/cc.engine
34+
branch = master

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
11
# CC WordPress 2013
2+
3+
<!--
4+
<VirtualHost *:8080>
5+
Use CCVHost staging.creativecommons.org http
6+
</VirtualHost>
7+
8+
<VirtualHost *:443>
9+
Use CCVHost staging.creativecommons.org https
10+
SSLEngine on
11+
SSLCertificateFile /etc/ssl/private/staging.creativecommons.org.crt
12+
SSLCertificateKeyFile /etc/ssl/private/staging.creativecommons.org.key
13+
SSLCACertificateFile /etc/ssl/certs/RapidSSL_CA_bundle.pem
14+
</VirtualHost>
15+
-->

apache.conf

+226
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
<Macro CCVHost ${host} ${proto} ${dir} ${logdir}>
2+
ServerName ${host}
3+
4+
DocumentRoot ${dir}/docroot
5+
6+
ErrorLog ${logdir}/error.log
7+
CustomLog ${logdir}/access.log combined
8+
9+
#----------
10+
# Main (general configs)
11+
#----------
12+
13+
# Display PHP errors to users of the staging site.
14+
php_value display_errors 1
15+
16+
FileETag INode MTime Size
17+
18+
Options +ExecCGI
19+
20+
SuexecUserGroup webadmin webadmin
21+
22+
<Location /licenses>
23+
DirectoryIndex deed
24+
DefaultType text/html
25+
AddDefaultCharset utf-8
26+
</Location>
27+
28+
<Location /ccengine-fcgi>
29+
DefaultType text/html
30+
AddDefaultCharset utf-8
31+
</Location>
32+
33+
<Location /cc.engine-cache>
34+
DefaultType text/html
35+
AddDefaultCharset utf-8
36+
</Location>
37+
38+
# Always serve up deeds as text/html, even when the country code
39+
# extension makes Apache think it's something else, like .pl being
40+
# a perl script instead of Poland, but not if it's a CSS file.
41+
<LocationMatch "^/licenses/.*/deed(?!3.css).*$">
42+
ForceType text/html
43+
</LocationMatch>
44+
45+
<LocationMatch "^/cc.engine-cache/.*/deed.*">
46+
ForceType text/html
47+
</LocationMatch>
48+
49+
# We only want relative URLs to point to creativecommons.org and nothing else
50+
# like www.CC.org, etc.
51+
UseCanonicalName On
52+
53+
# Let's have Apache set some caching options for most images on CC.org
54+
<Directory ${dir}/docroot/wp-content/uploads>
55+
ExpiresActive On
56+
ExpiresDefault A60480800
57+
</Directory>
58+
59+
<Directory ${dir}/docroot/images>
60+
ExpiresActive On
61+
ExpiresDefault A60480800
62+
</Directory>
63+
64+
DirectoryIndex index.php index.html
65+
66+
### ------------------------- ####
67+
## BEGIN mod_rewrite section ##
68+
### ------------------------- ####
69+
70+
RewriteEngine on
71+
72+
#----------
73+
# Logging. Uncomment these lines and adjust the log level for debugging. Make
74+
# sure to recomment them and restart Apache when done because the file will
75+
# become immense in a hurry.
76+
#----------
77+
78+
#RewriteLog /tmp/rewrite.log
79+
#RewriteLogLevel 5
80+
81+
#----------
82+
# Config
83+
#----------
84+
85+
RewriteMap uppercase int:toupper
86+
87+
#----------
88+
# License engine and legalcode
89+
#----------
90+
91+
Alias /ccengine-fcgi ${dir}/python_env/bin/ccengine.fcgi
92+
Alias /cc.engine-cache ${dir}/python_env/cache
93+
94+
# Redirect all /license to /choose before we go any deeper
95+
RewriteRule ^/choose$ ${proto}://${host}/choose/ [L,R=301]
96+
RewriteRule ^/license$ ${proto}://${host}/choose/ [L,R=301]
97+
98+
# Fixes this repercussions of this bug:
99+
# http://code.creativecommons.org/issues/issue898
100+
RewriteRule ^/licenses/CC0/1.0(.*)$ /publicdomain/zero/1.0$1 [L,R=301]
101+
102+
# Legalcode rewrites
103+
# FIXME: eval whether we should use the LHS as the actual file structure so we don't need the rewrites
104+
RewriteRule ^/legalcode ${proto}://${host}/ [L,R=301]
105+
RewriteRule .*legalcode/$ ${proto}://${host}/ [L,R=301]
106+
RewriteRule ^/licenses/(.*)sampling\+/1.0/(.*)/legalcode$ /legalcode/$1samplingplus_1.0_$2.html [L]
107+
RewriteRule ^/licenses/(.*)sampling\+/1.0/legalcode$ /legalcode/$1samplingplus_1.0.html [L]
108+
RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/(.*)/legalcode\.([A-Za-z-]+)$ /legalcode/$1_$2_$3_$4.html [L]
109+
RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/legalcode\.([a-z][a-z])$ /legalcode/$1_$2_$3.html [L]
110+
RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/(.*)/legalcode$ /legalcode/$1_$2_$3.html [L]
111+
RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/legalcode$ /legalcode/$1_$2.html [L]
112+
RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/legalcode\.txt$ /legalcode/$1_$2.txt [L]
113+
RewriteRule ^/publicdomain/(.*)/([0-9]\.[0-9])/legalcode$ /legalcode/$1_$2.html [L]
114+
RewriteRule ^/publicdomain/(.*)/([0-9]\.[0-9])/legalcode\.([a-z][a-z])$ /legalcode/$1_$2_$3.html [L]
115+
RewriteRule ^/publicdomain/(.*)/([0-9]\.[0-9])/legalcode\.txt$ /legalcode/$1_$2.txt [L]
116+
117+
# License RDF rewrites
118+
# FIXME: eval whether we should use the LHS as the actual file structure so we don't need the rewrites
119+
RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/([a-z]+)/license_rdf$ /license_rdf/creativecommons.org_licenses_$1_$2_$3_.rdf [L,T=application/rdf+xml]
120+
RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/([a-z]+)/rdf$ /license_rdf/creativecommons.org_licenses_$1_$2_$3_.rdf [L,T=application/rdf+xml]
121+
RewriteRule ^/licenses/index.rdf$ /rdf/index.rdf [L,T=application/rdf+xml]
122+
RewriteRule ^/licenses/publicdomain/license_rdf$ /license_rdf/creativecommons.org_licenses_publicdomain_.rdf [L,T=application/rdf+xml]
123+
RewriteRule ^/licenses/publicdomain/rdf$ /license_rdf/creativecommons.org_licenses_publicdomain_.rdf [L,T=application/rdf+xml]
124+
RewriteRule ^/(publicdomain|licenses)/(.*)/([0-9]\.[0-9])/license_rdf$ /license_rdf/creativecommons.org_$1_$2_$3_.rdf [L,T=application/rdf+xml]
125+
RewriteRule ^/(publicdomain|licenses)/(.*)/([0-9]\.[0-9])/rdf$ /license_rdf/creativecommons.org_$1_$2_$3_.rdf [L,T=application/rdf+xml]
126+
RewriteRule .*rdf/$ ${proto}://${host}/ [L,R=301]
127+
128+
# See if deed is cached before sending to cc.engine
129+
# FIXME: eval memcache as an alternative?
130+
RewriteCond %{REQUEST_URI} ^/licenses
131+
RewriteCond ${dir}/python_env/cache/%{REQUEST_FILENAME} -s
132+
RewriteRule ^/licenses/(.*) /cc.engine-cache/licenses/$1 [L,PT]
133+
134+
# FIXME: do we really need rewrites for other licenses like GPL, etc?
135+
RewriteRule (.*)licence(.*) ${proto}://${host}$1license$2 [L,R=301]
136+
RewriteRule ^/(license|choose|characteristic|publicdomain)$ /$1/ [L,R=301]
137+
RewriteRule ^/(license|choose|characteristic|publicdomain)/(.*) /ccengine-fcgi/$1/$2 [PT,L]
138+
RewriteRule ^/licenses$ ${proto}://${host}/licenses/ [L,R=301]
139+
RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/([a-z][a-z])$ ${proto}://${host}/licenses/$1/$2/$3/ [L,R=301]
140+
RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/([Ss]cotland)$ ${proto}://${host}/licenses/$1/$2/scotland/ [L,R=301]
141+
RewriteRule ^/licenses/(.*)([0-9])$ ${proto}://${host}/licenses/$1$2/ [L,R=301]
142+
RewriteRule ^/licenses/(.*)/2.0/ar/(.*)$ ${proto}://${host}/licenses/$1/2.5/ar/$2 [L,R=301]
143+
RewriteRule ^/licenses/BSD/legalcode http://opensource.org/licenses/bsd-license.php [L,R]
144+
RewriteRule ^/licenses/by-nc-nd/2.0/deed-music$ ${proto}://${host}/licenses/by-nc-nd/2.0/ [L,R=301]
145+
RewriteRule ^/licenses/(.*)/deed.(.*)/$ ${proto}://${host}/ [L,R=301]
146+
RewriteRule ^/licenses/eldred-pd/$ http://web.archive.org/web/20030115160926/http://www.creativecommons.org/licenses/eldred-pd [L,R=301]
147+
RewriteRule ^/licenses/GPL/2.0/rdf$ http://www.gnu.org/licenses/gpl-2.0.rdf [R=301,L]
148+
RewriteRule ^/licenses/LGPL/2.1/rdf$ http://www.gnu.org/licenses/lgpl-2.1.rdf [R=301,L]
149+
RewriteRule ^/licenses/meet-the-licenses$ ${proto}://${host}/licenses/ [L,R=301]
150+
RewriteRule ^/licenses/MIT/legalcode http://opensource.org/licenses/mit-license.php [L,R]
151+
RewriteRule ^/licenses/publicdomain/1.0(.*)$ ${proto}://${host}/licenses/publicdomain/ [L,R=301]
152+
RewriteRule ^/licenses/zero/1.0/(.*) /publicdomain/zero/1.0/$1 [L,R=301]
153+
RewriteRule ^/licesne(.*)$ ${proto}://${host}/choose$1 [L,R=301]
154+
RewriteRule ^/public_domain ${proto}://${host}/publicdomain/ [R=301,L]
155+
RewriteRule ^/licenses/(.*) /ccengine-fcgi/licenses/$1 [PT,L]
156+
157+
#----------
158+
# Redirects to CC.net
159+
#----------
160+
# FIXME: a bunch of these have moved / don't exist anymore
161+
162+
RewriteRule ^/about/affiliates.*$ https://creativecommons.net/supporters [R=301,L]
163+
RewriteRule ^/about/lessigletter.*$ https://creativecommons.net/letters [L,R=301]
164+
RewriteRule ^/about/supporters$ https://creativecommons.net/supporters [L,R=301]
165+
RewriteRule ^/donate$ https://creativecommons.net/donate [R=301,L]
166+
RewriteRule /learn/aboutus/supporters$ https://creativecommons.net/supporters [R=301,L]
167+
RewriteRule ^/store$ https://creativecommons.net/store [L,R=301]
168+
RewriteRule /support/getabutton$ https://creativecommons.net/supportcc [R=301,L]
169+
RewriteRule /support/summit$ https://creativecommons.net [R=301,L]
170+
RewriteRule ^/support/?$ https://creativecommons.net/ [L,R=301]
171+
172+
#----------
173+
# Miscellaneous
174+
#----------
175+
176+
# Map backwardly named license types to their actual location
177+
RewriteRule ^/licenses/by-nc-nd/1.0/(.*)$ ${proto}://${host}/licenses/by-nd-nc/1.0/$1 [L,R=301]
178+
RewriteRule ^/licenses/by-nd-nc/2.0/(.*)$ ${proto}://${host}/licenses/by-nc-nd/2.0/$1 [L,R=301]
179+
180+
# Map the namespace document and schema URLs
181+
# FIXME: are symlinks cleaner?
182+
RewriteRule ^/ns$ /rdf/ns.html [L]
183+
RewriteRule ^/schema.rdf$ /rdf/schema.rdf [L]
184+
185+
#----------
186+
# WordPress rules here instead of .htaccess
187+
#----------
188+
189+
# NOTE: sometimes Wordpress decides what page to display based on both the
190+
# query string AND the REQUEST_URI. mod_rewrite does not alter the
191+
# REQUEST_URI, and therefore mod_rewrite by itself is not always enough to
192+
# coerce Wordpress into doing what we want. In these case, add the query
193+
# argument '&roflcopter' to whatever RewriteRule. This will signal a special
194+
# plugin (cc_rewrite_request_uri.php) to actually alter the REQUEST_URI in the
195+
# PHP environment to be equivalent to the right side of the RewriteRule.
196+
197+
# Catch requests to certain posts and feed them to Wordpress in a way that
198+
# it knows how to handle
199+
RewriteRule ^/weblog(/archive|)/entry/(\d+)/?$ /index.php?p=$2&%{QUERY_STRING}&roflcopter [L]
200+
RewriteRule ^/press-releases/entry/(\d+)/?$ /index.php?p=$1&roflcopter [L]
201+
202+
# Catch any requests for the general /weblog/archive and also to the
203+
# archives for any particular year/month and then redirect the client
204+
# to the new-style permalink
205+
RewriteRule ^/weblog/archive(/?.*)$ http://${host}/weblog$1 [L,R=301]
206+
207+
# Catch any old permalinks that point to long, ugly post names. The
208+
# CC Permalink Mapper will get this request and redirect the user accordingly.
209+
# But don't do this if someone was trying to access some particular feed
210+
RewriteCond %{REQUEST_URI} !^/([a-z-]+)/\d{4}/\d{2}/feed
211+
RewriteRule ^/([a-z-]+)/\d{4}/\d{2}/([a-zA-Z0-9-]+)/?$ /index.php?post_name=$2&category=$1&roflcopter [L]
212+
213+
# '<some path>/rss' returns an RSS 0.92 feed, which we don't want, so make any
214+
# requests for '<some path>/rss' return an RSS 2 feed.
215+
RewriteRule ^/(.*?)rss/?$ /index.php/$1?feed=rss2 [L]
216+
217+
# Get missing upload files from the main site
218+
# FIXME - staging only
219+
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
220+
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
221+
RewriteRule ^/(wp-content/uploads/.*)$ http://creativecommons.org/$1 [L]
222+
223+
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
224+
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
225+
RewriteRule . /index.php [L]
226+
</Macro>

python_env/bin/ccengine.fcgi.in

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!@env_dir@/bin/python
2+
3+
from paste.deploy import loadapp
4+
from paste.exceptions.errormiddleware import ErrorMiddleware
5+
from flup.server.fcgi import WSGIServer
6+
7+
CCENGINE_CONFIG_PATH = '@env_dir@/config.ini'
8+
9+
def launch_ccengine_fcgi():
10+
ccengine_wsgi_app = loadapp('config:' + CCENGINE_CONFIG_PATH)
11+
WSGIServer(ccengine_wsgi_app).run()
12+
13+
if __name__ == '__main__':
14+
launch_ccengine_fcgi()

python_env/config.ini

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[app:ccengine]
2+
use = egg:cc.engine#ccengine_app
3+
#filter-with = errors cache
4+
direct_remote_paths =
5+
images /images/
6+
includes /includes/
7+
cc3 /wp-content/themes/cc3
8+
cc4 /wp-content/themes/cc4
9+
cc5 /wp-content/themes/cc5
10+
cc6 /wp-content/themes/cc6
11+
cctheme /wp-content/themes/creativecommons.org
12+
13+
[pipeline:main]
14+
## We've disabled caching on staging...
15+
#pipeline = errors cache ccengine
16+
pipeline = errors ccengine
17+
18+
[filter:errors]
19+
use= egg:Paste#error_catcher
20+
debug = true
21+
error_log = paste_errors.log
22+
# error_log should be an absolute path?
23+
24+
[filter:cache]
25+
use = egg:wsgi_cache#middleware
26+
cache_dir = ./cache
27+
cache_paths = /licenses/
28+
directory_index = index.html
29+
30+
[server:main]
31+
use = egg:Flup#fcgi
32+
# host = %(host_ip)s
33+
# port = %(port_number)s

python_env/src/cc.engine

Submodule cc.engine added at 3efd34c

python_env/src/cc.license

Submodule cc.license added at 3715b91

python_env/src/i18n

Submodule i18n added at 23cdb82

python_env/src/license.rdf

Submodule license.rdf added at 0e13c18

server_bootstrap.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
CUR=`cwd`
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
cd ${DIR}
7+
8+
git submodule init
9+
git submodule update
10+
11+
cd python_env
12+
13+
sed -e "s|@env_dir@|${DIR}/python_env|" < bin/ccengine.fcgi.in > bin/ccengine.fcgi
14+
chmod 755 bin/ccengine.fcgi
15+
16+
virtualenv .
17+
source bin/activate
18+
19+
for i in 'setuptools>=0.7' 'zope.interface>=3.8.0' Paste PasteDeploy PasteScript
20+
do
21+
pip install $i
22+
done
23+
24+
cd src
25+
26+
for i in i18n license.rdf cc.license cc.engine
27+
do
28+
cd $i
29+
python bootstrap.py -v 2.1.1
30+
bin/buildout
31+
python setup.py develop
32+
cd ..
33+
done
34+
35+
cd i18n
36+
bin/compile_mo
37+
bin/transstats
38+
cd ../.. # python_env
39+
40+
cd ${CUR}

0 commit comments

Comments
 (0)