commit | author | age
|
bd68aa
|
1 |
<?php |
MC |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2007-2011, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
class webserver_plugin { |
|
32 |
|
|
33 |
var $plugin_name = 'webserver_plugin'; |
|
34 |
var $class_name = 'webserver_plugin'; |
b1a6a5
|
35 |
|
bd68aa
|
36 |
/** |
MC |
37 |
* This function is called during ispconfig installation to determine |
|
38 |
* if a symlink shall be created for this plugin. |
|
39 |
*/ |
b1a6a5
|
40 |
|
MC |
41 |
|
bd68aa
|
42 |
public function onInstall() { |
MC |
43 |
global $conf; |
b1a6a5
|
44 |
|
bd68aa
|
45 |
if($conf['services']['web'] == true) { |
MC |
46 |
return true; |
|
47 |
} else { |
|
48 |
return false; |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* This function is called when the module is loaded |
|
54 |
*/ |
|
55 |
public function onLoad() { |
|
56 |
global $app; |
|
57 |
|
b1a6a5
|
58 |
$app->plugins->registerAction('server_plugins_loaded', $this->plugin_name, 'check_phpini_changes'); |
bd68aa
|
59 |
} |
MC |
60 |
|
|
61 |
/** |
|
62 |
* This function is called when a change in one of the registered tables is detected. |
|
63 |
* The function then raises the events for the plugins. |
|
64 |
*/ |
|
65 |
public function process($tablename, $action, $data) { |
|
66 |
// not needed |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* The method checks for a change of a php.ini file |
|
71 |
*/ |
|
72 |
public function check_phpini_changes() { |
|
73 |
global $app, $conf; |
b1a6a5
|
74 |
|
MC |
75 |
//** check if the main php.ini of the system changed so we need to regenerate all custom php.inis |
|
76 |
$app->uses('getconf'); |
|
77 |
|
|
78 |
//** files to check |
|
79 |
$check_files = array(); |
|
80 |
|
|
81 |
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web'); |
|
82 |
$fastcgi_config = $app->getconf->get_server_config($conf['server_id'], 'fastcgi'); |
|
83 |
|
|
84 |
if($web_config['php_ini_check_minutes'] == 0 || @date('i') % $web_config['php_ini_check_minutes'] != 0) { |
|
85 |
$app->log('Info: php.ini change checking not enabled or not in this minute: ' . $web_config['php_ini_check_minutes'], LOGLEVEL_DEBUG); |
|
86 |
return; // do not process |
|
87 |
} |
|
88 |
|
|
89 |
//** add default php.ini files to check |
|
90 |
$check_files[] = array('file' => $web_config['php_ini_path_apache'], |
|
91 |
'mode' => 'mod', |
|
92 |
'php_version' => ''); // default; |
|
93 |
|
|
94 |
$check_files[] = array('file' => $web_config['php_ini_path_cgi'], |
|
95 |
'mode' => '', // all but 'mod' and 'fast-cgi' |
|
96 |
'php_version' => ''); // default; |
|
97 |
|
|
98 |
if($fastcgi_config["fastcgi_phpini_path"] && $fastcgi_config["fastcgi_phpini_path"] != $web_config['php_ini_path_cgi']) { |
|
99 |
$check_files[] = array('file' => $fastcgi_config["fastcgi_phpini_path"], |
|
100 |
'mode' => 'fast-cgi', |
|
101 |
'php_version' => ''); // default; |
|
102 |
} else { |
|
103 |
$check_files[] = array('file' => $web_config['php_ini_path_cgi'], |
|
104 |
'mode' => 'fast-cgi', // all but 'mod' |
|
105 |
'php_version' => ''); // default; |
|
106 |
} |
|
107 |
|
|
108 |
|
|
109 |
//** read additional php versions of this server |
cc7a82
|
110 |
$php_versions = $app->db->queryAllRecords('SELECT server_php_id, php_fastcgi_ini_dir, php_fpm_ini_dir FROM server_php WHERE server_id = ?', $conf['server_id']); |
b1a6a5
|
111 |
foreach($php_versions as $php) { |
MC |
112 |
if($php['php_fastcgi_ini_dir'] && $php['php_fastcgi_ini_dir'] . '/php.ini' != $web_config['php_ini_path_cgi']) { |
|
113 |
$check_files[] = array('file' => $php['php_fastcgi_ini_dir'] . '/php.ini', |
|
114 |
'mode' => 'fast-cgi', |
|
115 |
'php_version' => $php['php_fastcgi_ini_dir']); |
|
116 |
} elseif($php['php_fpm_ini_dir'] && $php['php_fpm_ini_dir'] . '/php.ini' != $web_config['php_ini_path_cgi']) { |
|
117 |
$check_files[] = array('file' => $php['php_fpm_ini_dir'] . '/php.ini', |
|
118 |
'mode' => 'php-fpm', |
|
119 |
'php_version' => $php['php_fpm_ini_dir']); |
|
120 |
} |
|
121 |
} |
|
122 |
unset($php_versions); |
|
123 |
|
|
124 |
//** read md5sum status file |
|
125 |
$new_php_ini_md5 = array(); |
|
126 |
$php_ini_md5 = array(); |
|
127 |
$php_ini_changed = false; |
|
128 |
$rewrite_ini_files = false; |
|
129 |
|
|
130 |
if(file_exists(SCRIPT_PATH . '/temp/php.ini.md5sum')) { |
|
131 |
$rewrite_ini_files = true; |
|
132 |
$php_ini_md5 = unserialize(base64_decode(trim($app->system->file_get_contents(SCRIPT_PATH . '/temp/php.ini.md5sum')))); |
|
133 |
} |
|
134 |
if(!is_array($php_ini_md5)) $php_ini_md5 = array(); |
|
135 |
|
|
136 |
$processed = array(); |
|
137 |
foreach($check_files as $file) { |
|
138 |
$file_path = $file['file']; |
|
139 |
if(substr($file_path, -8) !== '/php.ini') $file_path .= (substr($file_path, -1) !== '/' ? '/' : '') . 'php.ini'; |
|
140 |
if(!file_exists($file_path)) continue; |
|
141 |
|
|
142 |
//** check if this php.ini file was already processed (if additional php version uses same php.ini) |
|
143 |
$ident = $file_path . '::' . $file['mode'] . '::' . $file['php_version']; |
|
144 |
if(in_array($ident, $processed) == true) continue; |
|
145 |
$processed[] = $ident; |
|
146 |
|
|
147 |
//** check if md5sum of file changed |
|
148 |
$file_md5 = md5_file($file_path); |
|
149 |
if(array_key_exists($file_path, $php_ini_md5) == false || $php_ini_md5[$file_path] != $file_md5) { |
|
150 |
$php_ini_changed = true; |
|
151 |
|
|
152 |
$app->log('Info: PHP.ini changed: ' . $file_path . ', mode ' . $file['mode'] . ' vers ' . $file['php_version'] . '.', LOGLEVEL_DEBUG); |
|
153 |
// raise action for this file |
|
154 |
if($rewrite_ini_files == true) $app->plugins->raiseAction('php_ini_changed', $file); |
|
155 |
} |
|
156 |
|
|
157 |
$new_php_ini_md5[$file_path] = $file_md5; |
|
158 |
} |
|
159 |
|
|
160 |
//** write new md5 sums if something changed |
|
161 |
if($php_ini_changed == true) $app->system->file_put_contents(SCRIPT_PATH . '/temp/php.ini.md5sum', base64_encode(serialize($new_php_ini_md5))); |
|
162 |
unset($new_php_ini_md5); |
|
163 |
unset($php_ini_md5); |
|
164 |
unset($processed); |
bd68aa
|
165 |
} |
b1a6a5
|
166 |
|
bd68aa
|
167 |
} |
MC |
168 |
|
|
169 |
?> |