Project

General

Profile

Download (6.48 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/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
35
else 
36
	AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
37
fi
38

    
39
if [ -z "$AVAILMEM" ]; then
40
	MEM=`sysctl hw.physmem | cut -d':' -f2`
41
	AVAILMEM=`expr $MEM / 1048576`
42
fi
43

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

    
65
# Set upload directory
66
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
67
	UPLOADTMPDIR="/root"
68
else 
69
	UPLOADTMPDIR="/tmp"
70
fi
71

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

    
110
# Modules previously included.
111
# can be turned on by touching
112
# /etc/php_dynamodules/$modulename
113
#	sysvmsg \
114
#	sysvsem \
115
#	sysvshm \
116
#	bcmath \
117
#	sqlite \
118
#	tokenizer \
119
#	uploadprogress \
120
#	sockets \
121
#	Reflection \
122
#	mysql \
123

    
124
#	bz2	\
125
#	json \
126

    
127
# Get a loaded module list in the stock php
128
if [ -f /usr/local/etc/php.ini ]; then
129
	rm /usr/local/etc/php.ini
130
fi
131
if [ -f /usr/local/lib/php.ini ]; then
132
	rm /usr/local/lib/php.ini
133
fi
134
LOADED_MODULES=`php -m | grep -v "\["`
135

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

    
159
; Extensions
160

    
161
EOF
162

    
163
# Ensure directory exists
164
if [ ! -d /etc/php_dynamodules ]; then
165
	mkdir /etc/php_dynamodules
166
fi
167

    
168
# Read in dynamodules
169
if [ -d /etc/php_dynamodules ]; then
170
	DYNA_MODULES=`ls /etc/php_dynamodules/`
171
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
172
fi
173

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

    
192
# Get amount of ram installed on this system
193
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
194
export RAM
195
if [  $RAM -gt 96 ]; then
196

    
197
	cat >>/usr/local/lib/php.ini <<EOF
198

    
199
; APC Settings
200
apc.enabled="1"
201
apc.enable_cli="1"
202
apc.shm_size="${APCSHMEMSIZE}"
203

    
204
[suhosin]
205
suhosin.get.max_array_depth = 5000
206
suhosin.get.max_array_index_length = 256
207
suhosin.get.max_vars = 5000
208
suhosin.post.max_array_depth = 5000
209
suhosin.post.max_array_index_length = 256
210
suhosin.post.max_vars = 5000
211
suhosin.request.max_array_depth = 5000
212
suhosin.request.max_array_index_length = 256
213
suhosin.request.max_vars = 5000
214

    
215
EOF
216

    
217
else 
218

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

    
222
fi
223

    
224
# Copy php.ini file to etc/ too (cli)
225
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
226

    
227
# Remove old log file if it exists.
228
if [ -f /var/run/php_modules_load_errors.txt ]; then
229
	rm /var/run/php_modules_load_errors.txt
230
fi 
231

    
232
# Check loaded modules and remove anything that did not load correctly
233
LOADED_MODULES=`php -m 2>/dev/null | grep -v "\["`
234
for EXT in $PHPMODULES; do
235
	SHOULDREMOVE="true"
236
	for LM in $LOADED_MODULES; do
237
		if [ "$EXT" = "$LM" ]; then
238
			SHOULDREMOVE="false"
239
		fi		
240
	done
241
	if [ "$SHOULDREMOVE" = "true" ]; then
242
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
243
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
244
			cat /usr/local/lib/php.ini | grep -v $EXT > /tmp/php.ini
245
			mv /tmp/php.ini /usr/local/lib/php.ini
246
		fi
247
	fi
248
done
249

    
250
# Copy php.ini file to etc/ too (cli)
251
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
252

    
253

    
254

    
255

    
(71-71/93)