Skip to content

Commit

Permalink
call verify_php_ini from server_php_{insert,update} events
Browse files Browse the repository at this point in the history
  • Loading branch information
jnorell committed Aug 18, 2021
1 parent 0f7af6d commit 7faccfc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
9 changes: 9 additions & 0 deletions server/mods-available/web_module.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class web_module {
'web_backup_insert',
'web_backup_update',
'web_backup_delete',
'server_php_insert',
'server_php_update',
'server_php_delete',
'aps_instance_insert',
'aps_instance_update',
'aps_instance_delete',
Expand Down Expand Up @@ -112,6 +115,7 @@ class that contains the function functionname.
$app->modules->registerTableHook('web_folder', 'web_module', 'process');
$app->modules->registerTableHook('web_folder_user', 'web_module', 'process');
$app->modules->registerTableHook('web_backup', 'web_module', 'process');
$app->modules->registerTableHook('server_php', 'web_module', 'process');
$app->modules->registerTableHook('aps_instances', 'web_module', 'process');
$app->modules->registerTableHook('aps_instances_settings', 'web_module', 'process');
$app->modules->registerTableHook('aps_packages', 'web_module', 'process');
Expand Down Expand Up @@ -167,6 +171,11 @@ function process($tablename, $action, $data) {
if($action == 'u') $app->plugins->raiseEvent('web_backup_update', $data);
if($action == 'd') $app->plugins->raiseEvent('web_backup_delete', $data);
break;
case 'server_php':
if($action == 'i') $app->plugins->raiseEvent('server_php_insert', $data);
if($action == 'u') $app->plugins->raiseEvent('server_php_update', $data);
if($action == 'd') $app->plugins->raiseEvent('server_php_delete', $data);
break;
case 'aps_instances':
if($action == 'i') $app->plugins->raiseEvent('aps_instance_insert', $data);
if($action == 'u') $app->plugins->raiseEvent('aps_instance_update', $data);
Expand Down
61 changes: 60 additions & 1 deletion server/plugins-available/webserver_plugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public function onLoad() {
global $app;

$app->plugins->registerAction('server_plugins_loaded', $this->plugin_name, 'check_phpini_changes');

$app->plugins->registerEvent('server_update', $this->plugin_name, 'server_update');

$app->plugins->registerEvent('server_php_insert', $this->plugin_name, 'server_php_update');
$app->plugins->registerEvent('server_php_update', $this->plugin_name, 'server_php_update');
}

/**
Expand Down Expand Up @@ -184,6 +188,36 @@ public function check_phpini_changes() {
unset($processed);
}

/**
* The method runs each php.ini file through verify_php_ini()
*/
function server_php_update($event_name, $data) {
global $app, $conf;

if(isset($data['new']['php_fastcgi_ini_dir'])) {
$php_ini = $data['new']['php_fastcgi_ini_dir'] . '/php.ini';
if(file_exists($php_ini)) {
$this->verify_php_ini(array('file' => $php_ini,
'mode' => 'fast-cgi',
'php_version' => $data['new']['server_php_id'])
);
} else {
$app->log("Cannot verify php.ini, file not found: $php_ini", LOGLEVEL_WARN);
}
}
if(isset($data['new']['php_fpm_ini_dir'])) {
$php_ini = $data['new']['php_fpm_ini_dir'] . '/php.ini';
if(file_exists($php_ini)) {
$this->verify_php_ini(array('file' => $php_ini,
'mode' => 'php-fpm',
'php_version' => $data['new']['server_php_id'])
);
} else {
$app->log("Cannot verify php.ini, file not found: $php_ini", LOGLEVEL_WARN);
}
}
}

/**
* The method checks/sets needed php.ini settings
*/
Expand Down Expand Up @@ -281,7 +315,32 @@ function server_update($event_name, $data) {
}
}
}

$check_files = array();
if ($old['php_ini_path_apache'] != $new['php_ini_path_apache']) {
$check_files[] = array('file' => $new['php_ini_path_apache'],
'mode' => 'mod',
'php_version' => 0);
}

if ($old['fastcgi_phpini_path'] != $new['fastcgi_phpini_path']) {
$check_files[] = array('file' => $new['fastcgi_phpini_path'],
'mode' => 'fast-cgi',
'php_version' => 0);
}
if ($old['php_ini_path_cgi'] != $new['php_ini_path_cgi']) {
$check_files[] = array('file' => $new['php_ini_path_cgi'],
'mode' => 'fast-cgi',
'php_version' => 0);
}
if ($old['php_fpm_ini_path'] != $new['php_fpm_ini_path']) {
$check_files[] = array('file' => $web_config['php_fpm_ini_path'],
'mode' => 'php-fpm',
'php_version' => 0);
}
foreach ($check_files as $file) {
$this->verify_php_ini($file);
}
}
}

?>

0 comments on commit 7faccfc

Please sign in to comment.