Skip to content

Commit 0f7af6d

Browse files
committed
enable validate_root in php.ini
1 parent 1688fa2 commit 0f7af6d

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ function update($event_name, $data) {
11781178
$app->system->chgrp('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log', 'root');
11791179
}
11801180

1181-
//* Write the custom php.ini file, if custom_php_ini fieled is not empty
1181+
//* Write the custom php.ini file, if custom_php_ini field is not empty
11821182
$custom_php_ini_dir = $web_config['website_basedir'].'/conf/'.$data['new']['system_user'];
11831183
if($data['new']['type'] == 'vhostsubdomain' || $data['new']['type'] == 'vhostalias') $custom_php_ini_dir .= '_' . $web_folder;
11841184
if(!is_dir($web_config['website_basedir'].'/conf')) $app->system->mkdir($web_config['website_basedir'].'/conf');

server/plugins-available/webserver_plugin.inc.php

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class webserver_plugin {
3737
* This function is called during ispconfig installation to determine
3838
* if a symlink shall be created for this plugin.
3939
*/
40-
41-
4240
public function onInstall() {
4341
global $conf;
4442

@@ -92,10 +90,6 @@ public function check_phpini_changes() {
9290
'mode' => 'mod',
9391
'php_version' => 0); // default;
9492

95-
$check_files[] = array('file' => $web_config['php_ini_path_cgi'],
96-
'mode' => '', // all but 'mod' and 'fast-cgi'
97-
'php_version' => 0); // default;
98-
9993
if($fastcgi_config["fastcgi_phpini_path"] && $fastcgi_config["fastcgi_phpini_path"] != $web_config['php_ini_path_cgi']) {
10094
$check_files[] = array('file' => $fastcgi_config["fastcgi_phpini_path"],
10195
'mode' => 'fast-cgi',
@@ -106,6 +100,16 @@ public function check_phpini_changes() {
106100
'php_version' => 0); // default;
107101
}
108102

103+
$check_files[] = array('file' => $web_config['php_fpm_ini_path'],
104+
'mode' => 'php-fpm',
105+
'php_version' => 0); // default;
106+
107+
if(!array_search($web_config['php_ini_path_cgi'], array_column($check_files, 'file'))) {
108+
$check_files[] = array('file' => $web_config['php_ini_path_cgi'],
109+
'mode' => '', // all but 'mod' and 'fast-cgi'
110+
'php_version' => 0); // default;
111+
}
112+
109113

110114
//** read additional php versions of this server
111115
$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']);
@@ -114,7 +118,8 @@ public function check_phpini_changes() {
114118
$check_files[] = array('file' => $php['php_fastcgi_ini_dir'] . '/php.ini',
115119
'mode' => 'fast-cgi',
116120
'php_version' => $php['server_php_id']);
117-
} elseif($php['php_fpm_ini_dir'] && $php['php_fpm_ini_dir'] . '/php.ini' != $web_config['php_ini_path_cgi']) {
121+
}
122+
if($php['php_fpm_ini_dir'] && $php['php_fpm_ini_dir'] . '/php.ini' != $web_config['php_fpm_ini_path']) {
118123
$check_files[] = array('file' => $php['php_fpm_ini_dir'] . '/php.ini',
119124
'mode' => 'php-fpm',
120125
'php_version' => $php['server_php_id']);
@@ -134,6 +139,13 @@ public function check_phpini_changes() {
134139
}
135140
if(!is_array($php_ini_md5)) $php_ini_md5 = array();
136141

142+
// verify needed php file settings if that hasn't been done since 15 minutes
143+
$now = time();
144+
$verify_php_ini=false;
145+
if(!isset($php_ini_md5['last_verify_php_ini']) || ($now - intval($php_ini_md5['last_verify_php_ini']) > 15*60)) {
146+
$verify_php_ini=true;
147+
}
148+
137149
$processed = array();
138150
foreach($check_files as $file) {
139151
$file_path = $file['file'];
@@ -145,6 +157,11 @@ public function check_phpini_changes() {
145157
if(in_array($ident, $processed) == true) continue;
146158
$processed[] = $ident;
147159

160+
//** check that needed php.ini settings/changes are made
161+
if($verify_php_ini) {
162+
$this->verify_php_ini($file);
163+
}
164+
148165
//** check if md5sum of file changed
149166
$file_md5 = md5_file($file_path);
150167
if(array_key_exists($file_path, $php_ini_md5) == false || $php_ini_md5[$file_path] != $file_md5) {
@@ -158,13 +175,32 @@ public function check_phpini_changes() {
158175
$new_php_ini_md5[$file_path] = $file_md5;
159176
}
160177

178+
$new_php_ini_md5['last_verify_php_ini'] = time();
179+
161180
//** write new md5 sums if something changed
162-
if($php_ini_changed == true) $app->system->file_put_contents(SCRIPT_PATH . '/temp/php.ini.md5sum', base64_encode(serialize($new_php_ini_md5)));
181+
if($php_ini_changed == true || $verify_php_ini == true) $app->system->file_put_contents(SCRIPT_PATH . '/temp/php.ini.md5sum', base64_encode(serialize($new_php_ini_md5)));
163182
unset($new_php_ini_md5);
164183
unset($php_ini_md5);
165184
unset($processed);
166185
}
167186

187+
/**
188+
* The method checks/sets needed php.ini settings
189+
*/
190+
public function verify_php_ini($file) {
191+
global $app;
192+
193+
if(isset($file['file']) && is_file($file['file'])) {
194+
$php_ini = $file['file'];
195+
// ensure opcache.validate_root = 1
196+
$app->system->exec_safe('grep ^opcache.validate_root ?', $php_ini);
197+
if($app->system->last_exec_retcode() != 0) {
198+
$app->log('verify_php_ini(): php.ini '.$php_ini.' is missing validate_root', LOGLEVEL_DEBUG);
199+
$sed_script='s/; *opcache\.validate_root *= *.+$/opcache.validate_root = 1/g';
200+
$app->system->exec_safe('sed -E -i ? ?', $sed_script, $php_ini);
201+
}
202+
}
203+
}
168204

169205
/*
170206
* Checks for changes to jailkit settings in server config and schedules affected jails to be updated.

0 commit comments

Comments
 (0)