Projet

Général

Profil

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

univnautes / etc / rc.php_ini_setup @ b107e187

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
# filter
139
PHPMODULES="$PHPMODULES filter"
140

    
141

    
142
PHP_ZEND_MODULES="ioncube_loader"
143
PHP_ZEND_MODULES_TS="ioncube_loader_ts"
144

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

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

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

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

    
199
; Extensions
200

    
201
EOF
202

    
203
# Copy php.ini file to etc/ too (cli)
204
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
205

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

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

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

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

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

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

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

    
269

    
270
if [ "$LOWMEM" != "TRUE" ]; then
271

    
272
	/bin/cat >>/usr/local/lib/php.ini <<EOF
273

    
274
; APC Settings
275
apc.enabled="1"
276
apc.enable_cli="0"
277
apc.shm_size="${APCSHMEMSIZE}"
278

    
279
EOF
280
fi
281

    
282
	/bin/cat >>/usr/local/lib/php.ini <<EOF
283

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

    
299
EOF
300

    
301

    
302
# Copy php.ini file to etc/ too (cli)
303
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
304

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

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

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

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