Skip to content

Commit 93292a9

Browse files
author
Marius Burkard
committed
Use correct php.ini master file on custom directives (Fixes #3790)
1 parent 632f156 commit 93292a9

File tree

2 files changed

+52
-79
lines changed

2 files changed

+52
-79
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,52 @@ function onLoad() {
9191
$app->plugins->registerAction('php_ini_changed', $this->plugin_name, 'php_ini_changed');
9292
}
9393

94-
// check for php.ini changes
95-
94+
private function get_master_php_ini_content($web_data) {
95+
global $app, $conf;
96+
97+
$app->uses('getconf');
98+
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
99+
$fastcgi_config = $app->getconf->get_server_config($conf['server_id'], 'fastcgi');
100+
101+
$php_ini_content = '';
102+
$master_php_ini_path = '';
103+
104+
if($web_data['php'] == 'mod') {
105+
$master_php_ini_path = $web_config['php_ini_path_apache'];
106+
} else {
107+
// check for custom php
108+
if($web_data['fastcgi_php_version'] != '') {
109+
$tmp = explode(':', $web_data['fastcgi_php_version']);
110+
if(isset($tmp[2])) {
111+
$tmppath = $tmp[2];
112+
if(substr($tmppath, -7) != 'php.ini') {
113+
if(substr($tmppath, -1) != '/') $tmppath .= '/';
114+
$tmppath .= 'php.ini';
115+
}
116+
if(file_exists($tmppath)) {
117+
$master_php_ini_path = $tmppath;
118+
}
119+
unset($tmppath);
120+
}
121+
unset($tmp);
122+
}
123+
124+
if(!$master_php_ini_path) {
125+
if($web_data['php'] == 'fast-cgi' && file_exists($fastcgi_config["fastcgi_phpini_path"])) {
126+
$master_php_ini_path = $fastcgi_config["fastcgi_phpini_path"];
127+
} elseif($web_data['php'] == 'php-fpm' && file_exists($web_config['php_fpm_ini_path'])) {
128+
$master_php_ini_path = $fastcgi_config["fastcgi_phpini_path"];
129+
} else {
130+
$master_php_ini_path = $web_config['php_ini_path_cgi'];
131+
}
132+
}
133+
}
134+
if($master_php_ini_path != '' && substr($master_php_ini_path, -7) == 'php.ini' && is_file($master_php_ini_path)) {
135+
$php_ini_content .= $app->system->file_get_contents($master_php_ini_path)."\n";
136+
}
137+
138+
return $php_ini_content;
139+
}
96140

97141
// Handle php.ini changes
98142
function php_ini_changed($event_name, $data) {
@@ -145,22 +189,10 @@ function php_ini_changed($event_name, $data) {
145189
$custom_php_ini_dir .= '_' . $web_folder;
146190
}
147191
if(!is_dir($web_config['website_basedir'].'/conf')) $app->system->mkdir($web_config['website_basedir'].'/conf');
148-
149-
192+
150193
if(!is_dir($custom_php_ini_dir)) $app->system->mkdir($custom_php_ini_dir);
151-
$php_ini_content = '';
152-
if($web_data['php'] == 'mod') {
153-
$master_php_ini_path = $web_config['php_ini_path_apache'];
154-
} else {
155-
if($web_data['php'] == 'fast-cgi' && file_exists($fastcgi_config["fastcgi_phpini_path"])) {
156-
$master_php_ini_path = $fastcgi_config["fastcgi_phpini_path"];
157-
} else {
158-
$master_php_ini_path = $web_config['php_ini_path_cgi'];
159-
}
160-
}
161-
if($master_php_ini_path != '' && substr($master_php_ini_path, -7) == 'php.ini' && is_file($master_php_ini_path)) {
162-
$php_ini_content .= $app->system->file_get_contents($master_php_ini_path)."\n";
163-
}
194+
195+
$php_ini_content = $this->get_master_php_ini_content($web_data);
164196

165197
if(intval($web_data['directive_snippets_id']) > 0){
166198
$snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'apache' AND active = 'y' AND customer_viewable = 'y'", intval($web_data['directive_snippets_id']));
@@ -1009,32 +1041,8 @@ function update($event_name, $data) {
10091041
if(trim($data['new']['custom_php_ini']) != '') {
10101042
$has_custom_php_ini = true;
10111043
if(!is_dir($custom_php_ini_dir)) $app->system->mkdirpath($custom_php_ini_dir);
1012-
$php_ini_content = '';
1013-
if($data['new']['php'] == 'mod') {
1014-
$master_php_ini_path = $web_config['php_ini_path_apache'];
1015-
} else {
1016-
if($data["new"]['php'] == 'fast-cgi') {
1017-
if(trim($data['new']['fastcgi_php_version']) != '' && file_exists($custom_fastcgi_php_ini_dir)){
1018-
$master_php_ini_path = $custom_fastcgi_php_ini_dir;
1019-
} elseif(file_exists($fastcgi_config["fastcgi_phpini_path"])){
1020-
$master_php_ini_path = $fastcgi_config["fastcgi_phpini_path"];
1021-
} else {
1022-
$master_php_ini_path = $web_config['php_ini_path_cgi'];
1023-
}
1024-
} else {
1025-
$master_php_ini_path = $web_config['php_ini_path_cgi'];
1026-
}
1027-
}
1028-
1029-
//* Add php.ini to the path in case that the master_php_ini_path is a directory
1030-
if($master_php_ini_path != '' && is_dir($master_php_ini_path) && is_file($master_php_ini_path.'/php.ini')) {
1031-
if(substr($master_php_ini_path, -1) == '/') $master_php_ini_path = substr($master_php_ini_path, 0, -1);
1032-
$master_php_ini_path .= '/php.ini';
1033-
}
1034-
1035-
if($master_php_ini_path != '' && substr($master_php_ini_path, -7) == 'php.ini' && is_file($master_php_ini_path)) {
1036-
$php_ini_content .= $app->system->file_get_contents($master_php_ini_path)."\n";
1037-
}
1044+
1045+
$php_ini_content = $this->get_master_php_ini_content($data['new']);
10381046
$php_ini_content .= str_replace("\r", '', trim($data['new']['custom_php_ini']));
10391047

10401048
if(intval($data['new']['directive_snippets_id']) > 0){

server/plugins-available/nginx_plugin.inc.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -889,42 +889,7 @@ function update($event_name, $data) {
889889
$app->system->chown('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log', 'root');
890890
$app->system->chgrp('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log', 'root');
891891
}
892-
893-
// Change the ownership of the error log to the owner of the website
894-
/*
895-
if(!@is_file($data['new']['document_root'].'/log/error.log')) exec('touch '.escapeshellcmd($data['new']['document_root']).'/log/error.log');
896-
$app->system->chown($data['new']['document_root'].'/log/error.log',$username);
897-
$app->system->chgrp($data['new']['document_root'].'/log/error.log',$groupname);
898-
*/
899-
900-
901-
/*
902-
//* Write the custom php.ini file, if custom_php_ini filed is not empty
903-
$custom_php_ini_dir = $web_config['website_basedir'].'/conf/'.$data['new']['system_user'];
904-
if(!is_dir($web_config['website_basedir'].'/conf')) mkdir($web_config['website_basedir'].'/conf');
905-
if(trim($data['new']['custom_php_ini']) != '') {
906-
$has_custom_php_ini = true;
907-
if(!is_dir($custom_php_ini_dir)) $app->system->mkdirpath($custom_php_ini_dir);
908-
$php_ini_content = '';
909-
if($data['new']['php'] == 'mod') {
910-
$master_php_ini_path = $web_config['php_ini_path_apache'];
911-
} else {
912-
if($data["new"]['php'] == 'fast-cgi' && file_exists($fastcgi_config["fastcgi_phpini_path"])) {
913-
$master_php_ini_path = $fastcgi_config["fastcgi_phpini_path"];
914-
} else {
915-
$master_php_ini_path = $web_config['php_ini_path_cgi'];
916-
}
917-
}
918-
if($master_php_ini_path != '' && substr($master_php_ini_path,-7) == 'php.ini' && is_file($master_php_ini_path)) {
919-
$php_ini_content .= $app->system->file_get_contents($master_php_ini_path)."\n";
920-
}
921-
$php_ini_content .= str_replace("\r",'',trim($data['new']['custom_php_ini']));
922-
$app->system->file_put_contents($custom_php_ini_dir.'/php.ini',$php_ini_content);
923-
} else {
924-
$has_custom_php_ini = false;
925-
if(is_file($custom_php_ini_dir.'/php.ini')) $app->system->unlink($custom_php_ini_dir.'/php.ini');
926-
}
927-
*/
892+
928893

929894
//* Create the vhost config file
930895
$app->load('tpl');

0 commit comments

Comments
 (0)