Commit 4664a295 authored by Falko Timme's avatar Falko Timme

- SSH users cannot be deleted if the web site uses PHP-FPM ("userdel: user...

- SSH users cannot be deleted if the web site uses PHP-FPM ("userdel: user ssh_test is currently used by process 2890"). Fixed this by stopping PHP-FPM before user deletion and starting it again afterwards.
parent fc7f1b1f
......@@ -239,7 +239,7 @@ class shelluser_base_plugin {
function delete($event_name, $data) {
global $app, $conf;
$app->uses('system,getconf');
$app->uses('system,getconf,services');
$security_config = $app->getconf->get_security_config('permissions');
if($security_config['allow_shell_user'] != 'yes') {
......@@ -251,12 +251,12 @@ class shelluser_base_plugin {
// Get the UID of the user
$userid = intval($app->system->getuid($data['old']['username']));
if($userid > $this->min_uid) {
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($data['old']['parent_domain_id']));
// check if we have to delete the dir
$check = $app->db->queryOneRecord('SELECT shell_user_id FROM `shell_user` WHERE `dir` = \'' . $app->db->quote($data['old']['dir']) . '\'');
if(!$check && is_dir($data['old']['dir'])) {
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($data['old']['parent_domain_id']));
$app->system->web_folder_protection($web['document_root'], false);
// delete dir
......@@ -292,10 +292,33 @@ class shelluser_base_plugin {
// We delete only non jailkit users, jailkit users will be deleted by the jailkit plugin.
if ($data['old']['chroot'] != "jailkit") {
// if this web uses PHP-FPM, that PPH-FPM service must be stopped before we can delete this user
if($web['php'] == 'php-fpm'){
if(trim($web['fastcgi_php_version']) != ''){
$default_php_fpm = false;
list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($web['fastcgi_php_version']));
} else {
$default_php_fpm = true;
}
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
if(!$default_php_fpm){
$app->services->restartService('php-fpm', 'stop:'.$custom_php_fpm_init_script);
} else {
$app->services->restartService('php-fpm', 'stop:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']);
}
}
$command = 'killall -u '.escapeshellcmd($data['old']['username']).' ; userdel -f';
$command .= ' '.escapeshellcmd($data['old']['username']).' &> /dev/null';
exec($command);
$app->log("Deleted shelluser: ".$data['old']['username'], LOGLEVEL_DEBUG);
// start PHP-FPM again
if($web['php'] == 'php-fpm'){
if(!$default_php_fpm){
$app->services->restartService('php-fpm', 'start:'.$custom_php_fpm_init_script);
} else {
$app->services->restartService('php-fpm', 'start:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']);
}
}
}
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment