Skip to content

Commit 8d15f38

Browse files
committed
Merge branch 'develop' into absolute_paths
2 parents 59bff84 + 4027f38 commit 8d15f38

23 files changed

Lines changed: 1081 additions & 211 deletions

File tree

Vagrantfile.dist

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# https://github.com/hashicorp/vagrant/issues/9442#issuecomment-374785457
5+
unless Vagrant::DEFAULT_SERVER_URL.frozen?
6+
Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com')
7+
end
8+
9+
Vagrant.configure("2") do |config|
10+
# VM Box
11+
config.vm.box = "ubuntu/bionic64"
12+
# Automatic box update checking
13+
config.vm.box_check_update = true
14+
15+
# CodeIgniter virtual host
16+
config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
17+
# Code Coverage virtual host
18+
config.vm.network "forwarded_port", guest: 81, host: 8081, host_ip: "127.0.0.1"
19+
# User Guide virtual host
20+
config.vm.network "forwarded_port", guest: 82, host: 8082, host_ip: "127.0.0.1"
21+
# MySQL server
22+
#config.vm.network "forwarded_port", guest: 3306, host: 3307, host_ip: "127.0.0.1"
23+
# PostgreSQL server
24+
#config.vm.network "forwarded_port", guest: 5432, host: 5433, host_ip: "127.0.0.1"
25+
# Memcached server
26+
#config.vm.network "forwarded_port", guest: 11211, host: 11212, host_ip: "127.0.0.1"
27+
# Redis server
28+
#config.vm.network "forwarded_port", guest: 6379, host: 6380, host_ip: "127.0.0.1"
29+
30+
# Add "192.168.10.10 ${VIRTUALHOST}" in your host file to access by domain
31+
#config.vm.network "private_network", ip: "192.168.10.10"
32+
33+
# Same path set in the $CODEIGNITER_PATH Provision
34+
# "virtualbox" type allow auto-sync host to guest and guest to host
35+
# but chmod does not work... tests will fail.
36+
# Default rsync__args except "--copy-links", to allow phpunit correctly works by symlink
37+
config.vm.synced_folder ".", "/var/www/codeigniter", type: "rsync", rsync__args: ["--verbose", "--archive", "--delete", "-z"]
38+
39+
# Provider-specific configuration
40+
config.vm.provider "virtualbox" do |vb|
41+
# Display the VirtualBox GUI when booting the machine
42+
vb.gui = false
43+
# Customize the amount of memory on the VM:
44+
vb.memory = "1024"
45+
end
46+
47+
# Provision
48+
config.vm.provision "shell", inline: <<-SHELL
49+
MYSQL_ROOT_PASS="password"
50+
PGSQL_ROOT_PASS="password"
51+
VIRTUALHOST="localhost"
52+
CODEIGNITER_PATH="/var/www/codeigniter"
53+
PHP_VERSION=7.2
54+
PGSQL_VERSION=10
55+
#APT_PROXY="192.168.10.1:3142"
56+
57+
grep -q "127.0.0.1 ${VIRTUALHOST}" /etc/hosts || echo "127.0.0.1 ${VIRTUALHOST}" >> /etc/hosts
58+
59+
# Creates a swap file if necessary
60+
RAM=`awk '/MemTotal/ {print $2}' /proc/meminfo`
61+
if [ $RAM -lt 1000000 ] && [ ! -f /swap/swapfile ]; then
62+
echo "================================================================================"
63+
echo "Adding swap"
64+
echo "================================================================================"
65+
echo "This process may take a few minutes. Please wait..."
66+
mkdir /swap
67+
dd if=/dev/zero of=/swap/swapfile bs=1024 count=1000000
68+
chmod 600 /swap/swapfile
69+
mkswap /swap/swapfile
70+
swapon /swap/swapfile
71+
echo "/swap/swapfile swap swap defaults 0 0" >> /etc/fstab
72+
echo "Done."
73+
fi
74+
75+
# Prepare to use APT Proxy
76+
if [ ! -z $APT_PROXY ]; then
77+
if [ ! -f /etc/apt/sources.list-origin ]; then
78+
cp /etc/apt/sources.list /etc/apt/sources.list-origin
79+
fi
80+
sed -i "s/archive.ubuntu.com/${APT_PROXY}/" /etc/apt/sources.list
81+
sed -i "s/security.ubuntu.com/${APT_PROXY}/" /etc/apt/sources.list
82+
fi
83+
84+
export DEBIAN_FRONTEND=noninteractive
85+
86+
echo "================================================================================"
87+
echo "Updating and Installing Required Packages"
88+
echo "================================================================================"
89+
90+
apt-get update
91+
92+
debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_ROOT_PASS}"
93+
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASS}"
94+
95+
apt-get install -y \
96+
php$PHP_VERSION apache2 composer \
97+
php-intl php-mbstring php-xml php-zip php-xdebug \
98+
php-mysql mysql-server mysql-client \
99+
php-pgsql postgresql-$PGSQL_VERSION \
100+
php-sqlite3 sqlite3 \
101+
php-memcached memcached \
102+
php-redis redis-server \
103+
php-curl curl \
104+
php-gd php-imagick \
105+
python-pip
106+
107+
pip install sphinx sphinxcontrib-phpdomain
108+
109+
apt-get autoclean
110+
111+
echo "================================================================================"
112+
echo "Preparing User Guide"
113+
echo "================================================================================"
114+
115+
cd "${CODEIGNITER_PATH}/user_guide_src/cilexer"
116+
python setup.py install
117+
cd ..
118+
make html
119+
120+
echo "================================================================================"
121+
echo "Configuring Databases"
122+
echo "================================================================================"
123+
124+
sed -i "s/^bind-address/#bind-address/" /etc/mysql/mysql.conf.d/mysqld.cnf
125+
mysql -e "CREATE DATABASE IF NOT EXISTS codeigniter COLLATE 'utf8_general_ci';
126+
UPDATE mysql.user SET Host='%' WHERE user='root';
127+
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
128+
FLUSH PRIVILEGES;" -uroot -p$MYSQL_ROOT_PASS
129+
systemctl restart mysql
130+
131+
sed -i "s/^#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/$PGSQL_VERSION/main/postgresql.conf
132+
grep -q "host all root all md5" /etc/postgresql/$PGSQL_VERSION/main/pg_hba.conf || echo "host all root all md5" >> /etc/postgresql/$PGSQL_VERSION/main/pg_hba.conf
133+
sudo -u postgres psql -tc "SELECT 1 FROM pg_roles WHERE rolname='root'" | grep -q 1 || sudo -u postgres psql -c "CREATE ROLE root WITH SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN"
134+
sudo -u postgres psql -c "ALTER ROLE root WITH PASSWORD '${PGSQL_ROOT_PASS}'"
135+
sudo -u postgres psql -tc "SELECT 1 FROM pg_database WHERE datname='codeigniter'" | grep -q 1 ||sudo -u postgres psql -c "CREATE DATABASE codeigniter"
136+
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE codeigniter TO root"
137+
systemctl restart postgresql
138+
139+
echo "================================================================================"
140+
echo "Configuring Memcached and Redis"
141+
echo "================================================================================"
142+
143+
sed -i "s/^bind 127.0.0.1/#bind 127.0.0.1/" /etc/redis/redis.conf
144+
sed -i "s/^protected-mode yes/protected-mode no/" /etc/redis/redis.conf
145+
sed -i "s/^-l 127.0.0.1/#-l 127.0.0.1/" /etc/memcached.conf
146+
systemctl restart redis
147+
systemctl restart memcached
148+
149+
echo "================================================================================"
150+
echo "Configuring Virtual Hosts"
151+
echo "================================================================================"
152+
153+
mkdir -p "${CODEIGNITER_PATH}/build/coverage-html"
154+
mkdir -p "${CODEIGNITER_PATH}/public"
155+
mkdir -p "${CODEIGNITER_PATH}/user_guide_src/build/html"
156+
mkdir -p "${CODEIGNITER_PATH}/writable/apache"
157+
chown -R vagrant:vagrant $CODEIGNITER_PATH
158+
159+
# Creates a symlink in the user home
160+
if [ ! -d /home/vagrant/codeigniter ]; then
161+
ln -s $CODEIGNITER_PATH /home/vagrant/codeigniter
162+
fi
163+
164+
sed -i "s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars
165+
sed -i "s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars
166+
grep -q "Listen 81" /etc/apache2/ports.conf || sed -i "s/^Listen 80/Listen 80\\nListen 81\\nListen 82/" /etc/apache2/ports.conf
167+
sed -i "s/^display_errors = Off/display_errors = On/" /etc/php/7.2/apache2/php.ini
168+
sed -i "s/^display_startup_errors = Off/display_startup_errors = On/" /etc/php/7.2/apache2/php.ini
169+
170+
echo "ServerName ${VIRTUALHOST}
171+
<Directory ${CODEIGNITER_PATH}>
172+
DirectoryIndex index.html index.php
173+
Options All
174+
AllowOverride All
175+
</Directory>
176+
<VirtualHost *:80>
177+
ServerAdmin vagrant@localhost
178+
DocumentRoot ${CODEIGNITER_PATH}/public
179+
ErrorLog ${CODEIGNITER_PATH}/writable/apache/error.log
180+
CustomLog ${CODEIGNITER_PATH}/writable/apache/custom.log combined
181+
</VirtualHost>
182+
<VirtualHost *:81>
183+
DocumentRoot ${CODEIGNITER_PATH}/build/coverage-html
184+
</VirtualHost>
185+
<VirtualHost *:82>
186+
DocumentRoot ${CODEIGNITER_PATH}/user_guide_src/build/html
187+
</VirtualHost>
188+
" > /etc/apache2/sites-available/codeigniter.conf
189+
190+
a2enmod rewrite
191+
a2dissite 000-default.conf
192+
a2ensite codeigniter.conf
193+
systemctl restart apache2
194+
195+
echo "================================================================================"
196+
echo "Services Status"
197+
echo "================================================================================"
198+
service --status-all
199+
200+
SHELL
201+
end

app/Config/ContentSecurityPolicy.php

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,40 @@
99
* choose to use it. The values here will be read in and set as defaults
1010
* for the site. If needed, they can be overridden on a page-by-page basis.
1111
*
12+
* Suggested reference for explanations:
13+
* https://www.html5rocks.com/en/tutorials/security/content-security-policy/
14+
*
1215
* @package Config
1316
*/
1417
class ContentSecurityPolicy extends BaseConfig
1518
{
16-
public $reportOnly = false;
17-
18-
public $defaultSrc = 'none';
19-
20-
public $scriptSrc = 'self';
21-
22-
public $styleSrc = 'self';
23-
24-
public $imageSrc = 'self';
25-
26-
public $baseURI = 'none';
27-
28-
public $childSrc = null;
29-
30-
public $connectSrc = 'self';
31-
32-
public $fontSrc = null;
33-
34-
public $formAction = null;
35-
19+
// broadbrush CSP management
20+
21+
public $reportOnly = false; // default CSP report context
22+
public $reportURI = null; // URL to send violation reports to
23+
public $upgradeInsecureRequests = false; // toggle for forcing https
24+
25+
// sources allowed; string or array of strings
26+
// Note: once you set a policy to 'none', it cannot be further restricted
27+
28+
public $defaultSrc = null; // will default to self if not over-ridden
29+
public $scriptSrc = 'self';
30+
public $styleSrc = 'self';
31+
public $imageSrc = 'self';
32+
public $baseURI = null; // will default to self if not over-ridden
33+
public $childSrc = 'self';
34+
public $connectSrc = 'self';
35+
public $fontSrc = null;
36+
public $formAction = 'self';
3637
public $frameAncestors = null;
38+
public $mediaSrc = null;
39+
public $objectSrc = 'self';
40+
public $manifestSrc = null;
3741

38-
public $mediaSrc = null;
39-
40-
public $objectSrc = null;
41-
42-
public $manifestSrc = null;
43-
42+
// mime types allowed; string or array of strings
4443
public $pluginTypes = null;
4544

46-
public $reportURI = null;
47-
48-
public $sandbox = false;
45+
// list of actions allowed; string or array of strings
46+
public $sandbox = null;
4947

50-
public $upgradeInsecureRequests = false;
5148
}

system/ComposerScripts.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
*/
5050
class ComposerScripts
5151
{
52-
protected static $basePath = 'system/ThirdParty/';
52+
protected static $basePath = 'ThirdParty/';
5353

5454
/**
5555
* After composer install/update, this is called to move
@@ -144,7 +144,7 @@ public static function moveEscaper()
144144
{
145145
if (class_exists('\\Zend\\Escaper\\Escaper') && is_file(static::getClassFilePath('\\Zend\\Escaper\\Escaper')))
146146
{
147-
$base = static::$basePath . 'ZendEscaper';
147+
$base = basename(__DIR__) . '/' . static::$basePath . 'ZendEscaper';
148148

149149
foreach ([$base, $base . '/Exception'] as $path)
150150
{
@@ -183,7 +183,7 @@ public static function moveKint()
183183

184184
if (is_file($filename))
185185
{
186-
$base = static::$basePath . 'Kint';
186+
$base = basename(__DIR__) . '/' . static::$basePath . 'Kint';
187187

188188
// Remove the contents of the previous Kint folder, if any.
189189
if (is_dir($base))

0 commit comments

Comments
 (0)