Skip to content

Commit 4664a29

Browse files
committed
- 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.
1 parent fc7f1b1 commit 4664a29

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

server/plugins-available/shelluser_base_plugin.inc.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ function update($event_name, $data) {
239239
function delete($event_name, $data) {
240240
global $app, $conf;
241241

242-
$app->uses('system,getconf');
242+
$app->uses('system,getconf,services');
243243

244244
$security_config = $app->getconf->get_security_config('permissions');
245245
if($security_config['allow_shell_user'] != 'yes') {
@@ -251,12 +251,12 @@ function delete($event_name, $data) {
251251
// Get the UID of the user
252252
$userid = intval($app->system->getuid($data['old']['username']));
253253
if($userid > $this->min_uid) {
254+
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($data['old']['parent_domain_id']));
255+
254256
// check if we have to delete the dir
255257
$check = $app->db->queryOneRecord('SELECT shell_user_id FROM `shell_user` WHERE `dir` = \'' . $app->db->quote($data['old']['dir']) . '\'');
256258
if(!$check && is_dir($data['old']['dir'])) {
257259

258-
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($data['old']['parent_domain_id']));
259-
260260
$app->system->web_folder_protection($web['document_root'], false);
261261

262262
// delete dir
@@ -292,10 +292,33 @@ function delete($event_name, $data) {
292292

293293
// We delete only non jailkit users, jailkit users will be deleted by the jailkit plugin.
294294
if ($data['old']['chroot'] != "jailkit") {
295+
// if this web uses PHP-FPM, that PPH-FPM service must be stopped before we can delete this user
296+
if($web['php'] == 'php-fpm'){
297+
if(trim($web['fastcgi_php_version']) != ''){
298+
$default_php_fpm = false;
299+
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']));
300+
} else {
301+
$default_php_fpm = true;
302+
}
303+
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
304+
if(!$default_php_fpm){
305+
$app->services->restartService('php-fpm', 'stop:'.$custom_php_fpm_init_script);
306+
} else {
307+
$app->services->restartService('php-fpm', 'stop:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']);
308+
}
309+
}
295310
$command = 'killall -u '.escapeshellcmd($data['old']['username']).' ; userdel -f';
296311
$command .= ' '.escapeshellcmd($data['old']['username']).' &> /dev/null';
297312
exec($command);
298313
$app->log("Deleted shelluser: ".$data['old']['username'], LOGLEVEL_DEBUG);
314+
// start PHP-FPM again
315+
if($web['php'] == 'php-fpm'){
316+
if(!$default_php_fpm){
317+
$app->services->restartService('php-fpm', 'start:'.$custom_php_fpm_init_script);
318+
} else {
319+
$app->services->restartService('php-fpm', 'start:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']);
320+
}
321+
}
299322
}
300323

301324
} else {

0 commit comments

Comments
 (0)