Skip to content

Commit a7e4ec0

Browse files
author
Till Brehm
committed
Added new directory delete procedure in jailkit plugin.
1 parent a13af29 commit a7e4ec0

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

server/plugins-available/shelluser_base_plugin.inc.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ function delete($event_name, $data) {
254254
// check if we have to delete the dir
255255
$check = $app->db->queryOneRecord('SELECT shell_user_id FROM `shell_user` WHERE `dir` = \'' . $app->db->quote($data['old']['dir']) . '\'');
256256
if(!$check && is_dir($data['old']['dir'])) {
257+
258+
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($data['old']['parent_domain_id']));
259+
260+
$app->system->web_folder_protection($web['document_root'], false);
261+
257262
// delete dir
258263
$homedir = $data['old']['dir'];
259264
if(substr($homedir, -1) !== '/') $homedir .= '/';
@@ -281,6 +286,8 @@ function delete($event_name, $data) {
281286
}
282287
unset($files);
283288
unset($dirs);
289+
290+
$app->system->web_folder_protection($web['document_root'], true);
284291
}
285292

286293
// We delete only non jailkit users, jailkit users will be deleted by the jailkit plugin.

server/plugins-available/shelluser_jailkit_plugin.inc.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,13 @@ function delete($event_name, $data) {
247247
$app->system->web_folder_protection($web['document_root'], false);
248248

249249
if(@is_dir($data['old']['dir'].$jailkit_chroot_userhome)) {
250+
$userid = intval($app->system->getuid($data['old']['username']));
250251
$command = 'killall -u '.escapeshellcmd($data['old']['username']).' ; userdel -f';
251252
$command .= ' '.escapeshellcmd($data['old']['username']).' &> /dev/null';
252253
exec($command);
254+
255+
$this->_delete_homedir($data['old']['dir'].$jailkit_chroot_userhome,$userid,$data['old']['parent_domain_id']);
256+
253257
$app->log("Jailkit Plugin -> delete chroot home:".$data['old']['dir'].$jailkit_chroot_userhome, LOGLEVEL_DEBUG);
254258
}
255259

@@ -523,6 +527,48 @@ private function _setup_ssh_rsa() {
523527
exec("chmod 600 '$sshkeys'");
524528

525529
}
530+
531+
private function _delete_homedir($homedir,$userid,$parent_domain_id) {
532+
global $app, $conf;
533+
534+
// check if we have to delete the dir
535+
$check = $app->db->queryOneRecord('SELECT shell_user_id FROM `shell_user` WHERE `dir` = \'' . $app->db->quote($homedir) . '\'');
536+
537+
if(!$check && is_dir($homedir)) {
538+
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($parent_domain_id));
539+
$app->system->web_folder_protection($web['document_root'], false);
540+
541+
// delete dir
542+
if(substr($homedir, -1) !== '/') $homedir .= '/';
543+
$files = array('.bash_logout', '.bash_history', '.bashrc', '.profile');
544+
$dirs = array('.ssh');
545+
foreach($files as $delfile) {
546+
if(is_file($homedir . $delfile) && fileowner($homedir . $delfile) == $userid) unlink($homedir . $delfile);
547+
}
548+
foreach($dirs as $deldir) {
549+
if(is_dir($homedir . $deldir) && fileowner($homedir . $deldir) == $userid) exec('rm -rf ' . escapeshellarg($homedir . $deldir));
550+
}
551+
$empty = true;
552+
$dirres = opendir($homedir);
553+
if($dirres) {
554+
while(($entry = readdir($dirres)) !== false) {
555+
if($entry != '.' && $entry != '..') {
556+
$empty = false;
557+
break;
558+
}
559+
}
560+
closedir($dirres);
561+
}
562+
if($empty == true) {
563+
rmdir($homedir);
564+
}
565+
unset($files);
566+
unset($dirs);
567+
568+
$app->system->web_folder_protection($web['document_root'], true);
569+
}
570+
571+
}
526572

527573
} // end class
528574

0 commit comments

Comments
 (0)