Projet

Général

Profil

Télécharger (9,72 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / rc.php_ini_setup @ e792ac36

1
#!/bin/sh
2
#
3
#	rc.php_ini_setup
4
#	Copyright (C) 2010 Scott 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=`/bin/cat /etc/platform`
30
MIN_REALMEM_FOR_APC=512
31

    
32
if [ -d /usr/local/lib/php/20090626 ]; then
33
	EXTENSIONSDIR="/usr/local/lib/php/20090626/"
34
else
35
	EXTENSIONSDIR="/usr/local/lib/php/20060613/"
36
fi
37

    
38
# Grab amount of memory that is detected
39
if [ -f /var/log/dmesg.boot ]; then
40
	AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
41
else 
42
	AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
43
fi
44

    
45
if [ -z "$AVAILMEM" ]; then
46
	MEM=`/sbin/sysctl hw.physmem | cut -d':' -f2`
47
	AVAILMEM=`/bin/expr $MEM / 1048576`
48
fi
49

    
50

    
51
# Get amount of ram installed on this system
52
REALMEM=`/sbin/sysctl hw.realmem | /usr/bin/awk '{print $2/1048576}' | /usr/bin/awk -F '.' '{print $1}'`
53
export REALMEM
54
export LOWMEM
55

    
56
if [  "$REALMEM" -lt "$MIN_REALMEM_FOR_APC" ]; then
57
	LOWMEM="TRUE"
58
	echo ">>> Under $MIN_REALMEM_FOR_APC megabytes of ram detected.  Not enabling APC."
59
	echo ">>> Under $MIN_REALMEM_FOR_APC megabytes of ram detected.  Not enabling APC." | /usr/bin/logger -p daemon.info -i -t rc.php_ini_setup
60
else
61

    
62
	# Calculate APC SHM size according 
63
	# to detected memory values
64
	if [ "$AVAILMEM" -gt "135" ]; then
65
		APCSHMEMSIZE="10M"
66
	fi
67
	if [ "$AVAILMEM" -gt "256" ]; then
68
		APCSHMEMSIZE="20M"
69
	fi
70
	if [ "$AVAILMEM" -gt "384" ]; then
71
		APCSHMEMSIZE="25M"
72
	fi
73
	if [ "$AVAILMEM" -gt "512" ]; then
74
		APCSHMEMSIZE="30M"
75
	fi
76
	if [ "$AVAILMEM" -gt "784" ]; then
77
		APCSHMEMSIZE="50M"
78
	fi
79
fi
80

    
81
# Set upload directory
82
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
83
	UPLOADTMPDIR=`/usr/bin/grep upload_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
84
else 
85
	UPLOADTMPDIR="/tmp"
86
fi
87

    
88
# Define php modules.  Do not add .so, it will  
89
# be done automatically by the script below.
90
PHPMODULES="standard"
91
if [ "$LOWMEM" != "TRUE" ]; then
92
	PHPMODULES="$PHPMODULES apc"
93
fi
94
# Config read/write
95
PHPMODULES="$PHPMODULES xml libxml dom"
96
PHPMODULES="$PHPMODULES simplexml xmlreader xmlwriter"
97
# Downloading via HTTP/FTP (pkg mgr, etc)
98
PHPMODULES="$PHPMODULES curl date"
99
# Internationalization 
100
PHPMODULES="$PHPMODULES gettext"
101
# User manager
102
PHPMODULES="$PHPMODULES ldap openssl pcntl"
103
PHPMODULES="$PHPMODULES hash"
104
PHPMODULES="$PHPMODULES mcrypt"
105
# Regexs, PERL style!
106
PHPMODULES="$PHPMODULES pcre"
107
# The mighty posix!
108
PHPMODULES="$PHPMODULES posix"
109
PHPMODULES="$PHPMODULES readline"
110
# Login sessions
111
PHPMODULES="$PHPMODULES session"
112
# Extra sanity seatbelts
113
PHPMODULES="$PHPMODULES suhosin"
114
# Firewall rules edit
115
PHPMODULES="$PHPMODULES ctype"
116
# firewall_rules_edit.php
117
PHPMODULES="$PHPMODULES mbstring"
118
# Synchronization primitives
119
PHPMODULES="$PHPMODULES shmop"
120
# Page compression
121
PHPMODULES="$PHPMODULES zlib"
122
# SQLlite & Database
123
PHPMODULES="$PHPMODULES spl"
124
PHPMODULES="$PHPMODULES pdo"
125
PHPMODULES="$PHPMODULES sqlite"
126
# RADIUS
127
PHPMODULES="$PHPMODULES radius"
128
# ZeroMQ
129
PHPMODULES="$PHPMODULES zmq"
130
# SSH2
131
PHPMODULES="$PHPMODULES ssh2"
132
# pfSense extensions
133
PHPMODULES="$PHPMODULES pfSense"
134
# json
135
PHPMODULES="$PHPMODULES json"
136
# bcmath
137
PHPMODULES="$PHPMODULES bcmath"
138

    
139
PHP_ZEND_MODULES="ioncube_loader"
140
PHP_ZEND_MODULES_TS="ioncube_loader_ts"
141

    
142
# Modules previously included.
143
# can be turned on by touching
144
# /etc/php_dynamodules/$modulename
145
#	sysvmsg \
146
#	sysvsem \
147
#	sysvshm \
148
#	bcmath \
149
#	tokenizer \
150
#	uploadprogress \
151
#	sockets \
152
#	Reflection \
153
#	mysql \
154
#	bz2	\
155

    
156
# Clear the .ini file to make sure we are clean
157
if [ -f /usr/local/etc/php.ini ]; then
158
	/bin/rm /usr/local/etc/php.ini
159
fi
160
if [ -f /usr/local/lib/php.ini ]; then
161
	/bin/rm /usr/local/lib/php.ini
162
fi
163
LOADED_MODULES=`/usr/local/bin/php -m | /usr/bin/grep -v "\["`
164

    
165
# Fetch the timezone from the XML and set it here. We set it later too in the running scripts
166
TIMEZONE=`cat /conf/config.xml | egrep -E '<timezone>(.*?)</timezone>' | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
167

    
168
# Get a loaded module list in the stock php
169
# Populate a dummy php.ini to avoid
170
# the file being clobbered and the firewall
171
# not being able to boot back up.
172
/bin/cat >/usr/local/lib/php.ini <<EOF
173
; File generated from /etc/rc.php_ini_setup
174
output_buffering = "0"
175
expose_php = Off
176
implicit_flush = true
177
magic_quotes_gpc = Off
178
max_execution_time = 900
179
max_input_time = 1800
180
register_argc_argv = On
181
file_uploads = On
182
upload_tmp_dir = ${UPLOADTMPDIR}
183
upload_max_filesize = 200M
184
post_max_size = 200M
185
html_errors = Off
186
zlib.output_compression = Off
187
zlib.output_compression_level = 1
188
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
189
display_startup_errors=on
190
display_errors=on
191
log_errors=on
192
error_log=/tmp/PHP_errors.log
193
extension_dir=${EXTENSIONSDIR}
194
date.timezone="${TIMEZONE}"
195

    
196
; Extensions
197

    
198
EOF
199

    
200
# Copy php.ini file to etc/ too (cli)
201
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
202

    
203
# Ensure directory exists
204
if [ ! -d /etc/php_dynamodules ]; then
205
	/bin/mkdir /etc/php_dynamodules
206
fi
207
if [ ! -d /etc/php_dynamodules_zend ]; then
208
	/bin/mkdir /etc/php_dynamodules_zend
209
fi
210
if [ ! -d /etc/php_dynamodules_zend_ts ]; then
211
	/bin/mkdir /etc/php_dynamodules_zend_ts
212
fi
213

    
214
# Read in dynamodules
215
if [ -d /etc/php_dynamodules ]; then
216
	DYNA_MODULES=`/bin/ls -Utr /etc/php_dynamodules/`
217
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
218
fi
219

    
220
# Read in zend modules
221
if [ -d /etc/php_dynamodules_zend ]; then
222
	DYNA_MODULES=`/bin/ls /etc/php_dynamodules_zend/`
223
	PHP_ZEND_MODULES="$PHP_ZEND_MODULES $DYNA_MODULES"
224
fi
225

    
226
# Read in zend threaded modules
227
if [ -d /etc/php_dynamodules_zend_ts ]; then
228
	DYNA_MODULES=`/bin/ls /etc/php_dynamodules_zend_ts/`
229
	PHP_ZEND_MODULES_TS="$PHP_ZEND_MODULES_TS $DYNA_MODULES"
230
fi
231

    
232
# Loop through and generate modules to load.
233
# Take into account modules built into php.
234
for EXT in $PHPMODULES; do
235
	SHOULDADD="true"
236
	# Check to see if module is compiled into php statically
237
	for LM in $LOADED_MODULES; do
238
		if [ "$EXT" = "$LM" ]; then
239
			SHOULDADD="false"
240
		fi
241
	done
242
	if [ "$SHOULDADD" = "true" ]; then
243
		# Ensure extension exists before adding.
244
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
245
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
246
		fi
247
	fi
248
done
249

    
250
# Zend modules
251
for EXT in $PHP_ZEND_MODULES; do
252
	# Ensure extension exists before adding.
253
	if [ -f "${EXTENSIONSDIR}/ioncube/${EXT}.so" ]; then
254
		echo "zend_extension=${EXTENSIONSDIR}/ioncube/${EXT}.so" >> /usr/local/lib/php.ini
255
	fi
256
done
257

    
258
# Zend threaded modules
259
for EXT in $PHP_ZEND_MODULES_TS; do
260
	# Ensure extension exists before adding.
261
	if [ -f "${EXTENSIONSDIR}/ioncube/${EXT}.so" ]; then
262
		echo "zend_extension_ts=${EXTENSIONSDIR}/ioncube/${EXT}.so" >> /usr/local/lib/php.ini
263
	fi
264
done
265

    
266

    
267
if [ "$LOWMEM" != "TRUE" ]; then
268

    
269
	/bin/cat >>/usr/local/lib/php.ini <<EOF
270

    
271
; APC Settings
272
apc.enabled="1"
273
apc.enable_cli="0"
274
apc.shm_size="${APCSHMEMSIZE}"
275

    
276
EOF
277
fi
278

    
279
	/bin/cat >>/usr/local/lib/php.ini <<EOF
280

    
281
[suhosin]
282
suhosin.get.max_array_depth = 5000
283
suhosin.get.max_array_index_length = 256
284
suhosin.get.max_vars = 5000
285
suhosin.get.max_value_length = 500000
286
suhosin.post.max_array_depth = 5000
287
suhosin.post.max_array_index_length = 256
288
suhosin.post.max_vars = 5000
289
suhosin.post.max_value_length = 500000
290
suhosin.request.max_array_depth = 5000
291
suhosin.request.max_array_index_length = 256
292
suhosin.request.max_vars = 5000
293
suhosin.request.max_value_length = 500000
294
suhosin.memory_limit = 512435456
295

    
296
EOF
297

    
298

    
299
# Copy php.ini file to etc/ too (cli)
300
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
301

    
302
# Remove old log file if it exists.
303
if [ -f /var/run/php_modules_load_errors.txt ]; then
304
	/bin/rm /var/run/php_modules_load_errors.txt
305
fi 
306

    
307
for EXT in $PHPMODULES; do
308
	PHPMODULESLC="$PHPMODULESLC `echo "$EXT" | /usr/bin/tr '[:upper:]' '[:lower:]'`"
309
done
310

    
311
# Check loaded modules and remove anything that did not load correctly
312
LOADED_MODULES=`/usr/local/bin/php -m | /usr/bin/tr '[:upper:]' '[:lower:]' 2>/dev/null | /usr/bin/grep -v "\["`
313
for EXT in $PHPMODULESLC; do
314
	SHOULDREMOVE="true"
315
	for LM in $LOADED_MODULES; do
316
		if [ "$EXT" = "$LM" ]; then
317
			SHOULDREMOVE="false"
318
		fi		
319
	done
320
	# Handle low memory situations
321
	if [ "$LOWMEM" = "TRUE" ]; then
322
		if [ "$EXT" = "apc" ]; then
323
			SHOULDREMOVE="true"
324
		fi
325
		if [ "$EXT" = "xcache" ]; then
326
			SHOULDREMOVE="true"
327
		fi
328
	fi
329
	if [ "$SHOULDREMOVE" = "true" ]; then
330
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
331
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
332
			/bin/cat /usr/local/lib/php.ini | /usr/bin/grep -v $EXT > /tmp/php.ini
333
			/bin/rm -f /usr/local/lib/php.ini
334
			/bin/mv /tmp/php.ini /usr/local/lib/php.ini
335
		fi
336
	fi
337
done
338

    
339
# Copy php.ini file to etc/ too (cli)
340
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
(85-85/110)