Project

General

Profile

Download (6.48 KB) Statistics
| Branch: | Tag: | Revision:
1 40e46009 Scott Ullrich
#!/bin/sh
2 de96a790 Scott Ullrich
#
3
#	rc.php_ini_setup
4 3937f149 Scott Ullrich
#	Copyright (C)2008 Scott K Ullrich <sullrich@gmail.com>
5 de96a790 Scott Ullrich
#	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 40e46009 Scott Ullrich
28
# Set our operating platform
29
PLATFORM=`cat /etc/platform`
30 0804f515 Scott Ullrich
EXTENSIONSDIR="/usr/local/lib/php/20060613/"
31 c44417f8 Scott Ullrich
32 0d60f50a Seth Mos
# Grab amount of memory that is detected
33 47eee8fa Scott Ullrich
if [ -f /var/log/dmesg.boot ]; then
34 839cad07 smos
	AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
35 47eee8fa Scott Ullrich
else 
36 839cad07 smos
	AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
37 47eee8fa Scott Ullrich
fi
38 c44417f8 Scott Ullrich
39 b713d790 Scott Ullrich
if [ -z "$AVAILMEM" ]; then
40
	MEM=`sysctl hw.physmem | cut -d':' -f2`
41
	AVAILMEM=`expr $MEM / 1048576`
42
fi
43
44 2b11ff4d Scott Ullrich
# Calculate APC SHM size according 
45
# to detected memory values
46
if [ "$AVAILMEM" -lt "128" ]; then
47 f82be9e4 Scott Ullrich
	APCSHMEMSIZE="10"
48 2b11ff4d Scott Ullrich
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 40e46009 Scott Ullrich
65 31c96a14 Scott Ullrich
# Set upload directory
66 dee5d2fb Renato Botelho
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
67 800b73e6 Scott Ullrich
	UPLOADTMPDIR="/root"
68 31c96a14 Scott Ullrich
else 
69
	UPLOADTMPDIR="/tmp"
70
fi
71
72 de96a790 Scott Ullrich
# Define php modules.  Do not add .so, it will  
73
# be done automatically by the script below.
74 0997e8f3 Scott Ullrich
PHPMODULES="apc \
75 be1db1d3 Scott Ullrich
# Downloading via HTTP/FTP (pkg mgr, etc)
76 f1b64d5e Scott Ullrich
	curl \
77
	date \
78 be1db1d3 Scott Ullrich
# Internationalization 
79 f1b64d5e Scott Ullrich
	gettext \
80 be1db1d3 Scott Ullrich
# User manager
81 f1b64d5e Scott Ullrich
	ldap \
82 8a44206b Scott Ullrich
	openssl \
83 f1b64d5e Scott Ullrich
	pcntl \
84 be1db1d3 Scott Ullrich
# Regexs, PERL style!
85 f1b64d5e Scott Ullrich
	pcre \
86 be1db1d3 Scott Ullrich
# The mighty posix!
87 f1b64d5e Scott Ullrich
	posix \
88
	readline \
89 be1db1d3 Scott Ullrich
# Login sessions
90 f1b64d5e Scott Ullrich
	session \
91
	standard \
92 be1db1d3 Scott Ullrich
# Extra sanity seatbelts
93 27798303 Scott Ullrich
	suhosin \
94 b8e3b043 Ermal Lu?i
        pfSense \
95 fca48a65 Scott Ullrich
# Firewall rules edit
96
	ctype \
97 be1db1d3 Scott Ullrich
# Config read/write
98 f1b64d5e Scott Ullrich
	xml \
99 caea0c47 Ermal Lu?i
	xmlreader \
100 a669395c Ermal
	xmlwriter \
101 be1db1d3 Scott Ullrich
	libxml \
102 d4ac1b88 Scott Ullrich
# user manager
103
	mhash \
104 16058a05 Scott Ullrich
# firewall_rules_edit.php
105
	mbstring \
106 8eae944e Ermal
	shmop \
107 be1db1d3 Scott Ullrich
# Page compression
108 f1b64d5e Scott Ullrich
	zlib"
109 e83dca8c Scott Ullrich
110 80d887d1 Scott Ullrich
# Modules previously included.
111 fcdf9492 Scott Ullrich
# can be turned on by touching
112 80d887d1 Scott Ullrich
# /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 16058a05 Scott Ullrich
124 80d887d1 Scott Ullrich
#	bz2	\
125
#	json \
126
127 de96a790 Scott Ullrich
# Get a loaded module list in the stock php
128 69b27c16 Scott Ullrich
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 e83dca8c Scott Ullrich
136 2ed3203c Scott Ullrich
# 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 4b29393a Scott Ullrich
; File generated from /etc/rc.php_ini_setup
141 40e46009 Scott Ullrich
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 c720fffc Scott Ullrich
set_time_limit = 0
148 40e46009 Scott Ullrich
register_argc_argv = On
149
file_uploads = On
150 31c96a14 Scott Ullrich
upload_tmp_dir = ${UPLOADTMPDIR}
151 40e46009 Scott Ullrich
upload_max_filesize = 100M
152
post_max_size = 100M
153
html_errors = Off
154 9444761e sullrich
zlib.output_compression = Off
155 40e46009 Scott Ullrich
zlib.output_compression_level = 1
156
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
157 0804f515 Scott Ullrich
extension_dir=${EXTENSIONSDIR}
158 40e46009 Scott Ullrich
159 4b29393a Scott Ullrich
; Extensions
160 a8e61346 Ermal
161 40e46009 Scott Ullrich
EOF
162
163 7f16265a Scott Ullrich
# Ensure directory exists
164
if [ ! -d /etc/php_dynamodules ]; then
165
	mkdir /etc/php_dynamodules
166
fi
167
168
# Read in dynamodules
169 c44417f8 Scott Ullrich
if [ -d /etc/php_dynamodules ]; then
170
	DYNA_MODULES=`ls /etc/php_dynamodules/`
171
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
172
fi
173
174 e83dca8c Scott Ullrich
# 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 de96a790 Scott Ullrich
	# Check to see if module is compiled into php statically
179 e83dca8c Scott Ullrich
	for LM in $LOADED_MODULES; do
180
		if [ "$EXT" = "$LM" ]; then
181
			SHOULDADD="false"
182
		fi
183
	done
184
	if [ "$SHOULDADD" = "true" ]; then
185 de96a790 Scott Ullrich
		# Ensure extension exists before adding.
186 69b27c16 Scott Ullrich
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
187 0804f515 Scott Ullrich
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
188
		fi
189 e83dca8c Scott Ullrich
	fi
190
done
191
192 de96a790 Scott Ullrich
# Get amount of ram installed on this system
193 40e46009 Scott Ullrich
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
194
export RAM
195 2ed3203c Scott Ullrich
if [  $RAM -gt 96 ]; then
196 40e46009 Scott Ullrich
197 2ed3203c Scott Ullrich
	cat >>/usr/local/lib/php.ini <<EOF
198 e83dca8c Scott Ullrich
199 4b29393a Scott Ullrich
; APC Settings
200 40e46009 Scott Ullrich
apc.enabled="1"
201
apc.enable_cli="1"
202 de96a790 Scott Ullrich
apc.shm_size="${APCSHMEMSIZE}"
203 40e46009 Scott Ullrich
204 a8e61346 Ermal
[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 40e46009 Scott Ullrich
EOF
216
217 de96a790 Scott Ullrich
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 40e46009 Scott Ullrich
fi
223
224 de96a790 Scott Ullrich
# Copy php.ini file to etc/ too (cli)
225 40e46009 Scott Ullrich
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
226 e1fda0c0 Scott Ullrich
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