Project

General

Profile

Download (5.99 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2
#
3
#	rc.php_ini_setup
4
#	Copyright (C)2008 Scott K Ullrich <sullrich@gmail.com>
5
#	All rights reserved.
6
#
7
#	Redistribution and use in source and binary forms, with or without
8
#	modification, are permitted provided that the following conditions are met:
9
#
10
#	1. Redistributions of source code must retain the above copyright notice,
11
#	   this list of conditions and the following disclaimer.
12
#
13
#	2. Redistributions in binary form must reproduce the above copyright
14
#	   notice, this list of conditions and the following disclaimer in the
15
#	   documentation and/or other materials provided with the distribution.
16
#
17
#	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
#	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
#	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
#	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
#	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
#	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
#	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
#	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
#	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
#	POSSIBILITY OF SUCH DAMAGE.
27

    
28
# Set our operating platform
29
PLATFORM=`cat /etc/platform`
30
EXTENSIONSDIR="/usr/local/lib/php/20060613/"
31

    
32
# Grab amount of memory that is detected
33
if [ -f /var/log/dmesg.boot ]; then
34
	AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { print $5 }'| sed 's/(//g'|tail -1`
35
else 
36
	AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { print $5 }'| sed 's/(//g'|tail -1`
37
fi
38

    
39
# Calculate APC SHM size according 
40
# to detected memory values
41
if [ "$AVAILMEM" -lt "128" ]; then
42
	APCSHMEMSIZE="10"
43
fi
44
if [ "$AVAILMEM" -gt "128" ]; then
45
	APCSHMEMSIZE="25"
46
fi
47
if [ "$AVAILMEM" -gt "256" ]; then
48
	APCSHMEMSIZE="45"
49
fi
50
if [ "$AVAILMEM" -gt "384" ]; then
51
	APCSHMEMSIZE="65"
52
fi
53
if [ "$AVAILMEM" -gt "512" ]; then
54
	APCSHMEMSIZE="80"
55
fi
56
if [ "$AVAILMEM" -gt "784" ]; then
57
	APCSHMEMSIZE="100"
58
fi
59

    
60
# Set upload directory
61
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
62
	UPLOADTMPDIR="/root"
63
else 
64
	UPLOADTMPDIR="/tmp"
65
fi
66

    
67
# Define php modules.  Do not add .so, it will  
68
# be done automatically by the script below.
69
PHPMODULES="apc \
70
# Downloading via HTTP/FTP (pkg mgr, etc)
71
	curl \
72
	date \
73
# Internationalization 
74
	gettext \
75
# User manager
76
	ldap \
77
	openssl \
78
	pcntl \
79
# Regexs, PERL style!
80
	pcre \
81
# The mighty posix!
82
	posix \
83
	readline \
84
# Login sessions
85
	session \
86
	standard \
87
# Extra sanity seatbelts
88
	suhosin \
89
        pfSense \
90
# Firewall rules edit
91
	ctype \
92
# Config read/write
93
	xml \
94
	xmlreader \
95
	libxml \
96
# user manager
97
	mhash \
98
# firewall_rules_edit.php
99
	mbstring \
100
# Page compression
101
	zlib"
102

    
103
# Modules previously included.
104
# can be turned on by touching
105
# /etc/php_dynamodules/$modulename
106
#	shmop \
107
#	sysvmsg \
108
#	sysvsem \
109
#	sysvshm \
110
#	bcmath \
111
#	sqlite \
112
#	tokenizer \
113
#	uploadprogress \
114
#	sockets \
115
#	Reflection \
116
#	mysql \
117

    
118
#	bz2	\
119
#	json \
120

    
121
# Get a loaded module list in the stock php
122
if [ -f /usr/local/etc/php.ini ]; then
123
	rm /usr/local/etc/php.ini
124
fi
125
if [ -f /usr/local/lib/php.ini ]; then
126
	rm /usr/local/lib/php.ini
127
fi
128
LOADED_MODULES=`php -m | grep -v "\["`
129

    
130
# Populate a dummy php.ini to avoid
131
# the file being clobbered and the firewall
132
# not being able to boot back up.
133
cat >/usr/local/lib/php.ini <<EOF
134
; File generated from /etc/rc.php_ini_setup
135
output_buffering = "0"
136
expose_php = Off
137
implicit_flush = true
138
magic_quotes_gpc = Off
139
max_execution_time = 99999999
140
max_input_time = 99999999
141
set_time_limit = 0
142
register_argc_argv = On
143
file_uploads = On
144
upload_tmp_dir = ${UPLOADTMPDIR}
145
upload_max_filesize = 100M
146
post_max_size = 100M
147
html_errors = Off
148
zlib.output_compression = Off
149
zlib.output_compression_level = 1
150
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
151
extension_dir=${EXTENSIONSDIR}
152

    
153
; Extensions
154
EOF
155

    
156
# Ensure directory exists
157
if [ ! -d /etc/php_dynamodules ]; then
158
	mkdir /etc/php_dynamodules
159
fi
160

    
161
# Read in dynamodules
162
if [ -d /etc/php_dynamodules ]; then
163
	DYNA_MODULES=`ls /etc/php_dynamodules/`
164
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
165
fi
166

    
167
# Loop through and generate modules to load.
168
# Take into account modules built into php.
169
for EXT in $PHPMODULES; do
170
	SHOULDADD="true"
171
	# Check to see if module is compiled into php statically
172
	for LM in $LOADED_MODULES; do
173
		if [ "$EXT" = "$LM" ]; then
174
			SHOULDADD="false"
175
		fi
176
	done
177
	if [ "$SHOULDADD" = "true" ]; then
178
		# Ensure extension exists before adding.
179
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
180
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
181
		fi
182
	fi
183
done
184

    
185
# Get amount of ram installed on this system
186
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
187
export RAM
188
if [  $RAM -gt 96 ]; then
189

    
190
	cat >>/usr/local/lib/php.ini <<EOF
191

    
192
; APC Settings
193
apc.enabled="1"
194
apc.enable_cli="1"
195
apc.shm_size="${APCSHMEMSIZE}"
196

    
197
EOF
198

    
199
else 
200

    
201
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC."
202
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC." | logger -p daemon.info -i -t rc.php_ini_setup
203

    
204
fi
205

    
206
# Copy php.ini file to etc/ too (cli)
207
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
208

    
209
# Remove old log file if it exists.
210
if [ -f /var/run/php_modules_load_errors.txt ]; then
211
	rm /var/run/php_modules_load_errors.txt
212
fi 
213

    
214
# Check loaded modules and remove anything that did not load correctly
215
LOADED_MODULES=`php -m 2>/dev/null | grep -v "\["`
216
for EXT in $PHPMODULES; do
217
	SHOULDREMOVE="true"
218
	for LM in $LOADED_MODULES; do
219
		if [ "$EXT" = "$LM" ]; then
220
			SHOULDREMOVE="false"
221
		fi		
222
	done
223
	if [ "$SHOULDREMOVE" = "true" ]; then
224
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
225
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
226
			cat /usr/local/lib/php.ini | grep -v $EXT > /tmp/php.ini
227
			mv /tmp/php.ini /usr/local/lib/php.ini
228
		fi
229
	fi
230
done
231

    
232
# Copy php.ini file to etc/ too (cli)
233
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
234

    
235

    
236

    
237

    
(72-72/91)