Skip to content

Commit e0d7bcf

Browse files
committed
exclude web_folder of subdomain/aliasdomain in jailkit cleanup
1 parent 35aa8f8 commit e0d7bcf

File tree

6 files changed

+106
-27
lines changed

6 files changed

+106
-27
lines changed

server/lib/classes/cron.d/600-jailkit_maintenance.inc.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public function onRunJob() {
5858
$jailkit_config = $app->getconf->get_server_config($conf['server_id'], 'jailkit');
5959
if (isset($this->jailkit_config) && isset($this->jailkit_config['jailkit_hardlinks'])) {
6060
if ($this->jailkit_config['jailkit_hardlinks'] == 'yes') {
61-
$update_options = array('hardlink');
61+
$options = array('hardlink');
6262
} elseif ($this->jailkit_config['jailkit_hardlinks'] == 'no') {
63-
$update_options = array();
63+
$options = array();
6464
}
6565
} else {
66-
$update_options = array('allow_hardlink');
66+
$options = array('allow_hardlink');
6767
}
6868

6969
// limit the number of jails we update at one time according to time of day
@@ -86,6 +86,14 @@ public function onRunJob() {
8686
// check for any cron job using this jail
8787
$cron_inuse = $app->db->queryOneRecord('SELECT id FROM `cron` WHERE `parent_domain_id` = ? AND `type` = ? AND `server_id` = ?', $rec['domain_id'], 'chrooted', $conf['server_id']);
8888

89+
$records2 = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $rec['domain_id'], $rec['document_root'], $conf['server_id']);
90+
foreach ($records2 as $record2) {
91+
if ($record2['web_folder'] == NULL || $record2['web_folder'] == '') {
92+
continue;
93+
}
94+
$options[] = 'skip='.$record2['web_folder'];
95+
}
96+
8997
if ($shell_user_inuse || $cron_inuse || $rec['php_fpm_chroot'] == 'y' || $rec['delete_unused_jailkit'] != 'y') {
9098
$sections = $jailkit_config['jailkit_chroot_app_sections'];
9199
if (isset($rec['jailkit_chroot_app_sections']) && $rec['jailkit_chroot_app_sections'] != '') {
@@ -104,7 +112,7 @@ public function onRunJob() {
104112

105113
if ($update_hash != $rec['last_jailkit_hash']) {
106114
$app->system->web_folder_protection($rec['document_root'], false);
107-
$app->system->update_jailkit_chroot($rec['document_root'], $sections, $programs, $update_options);
115+
$app->system->update_jailkit_chroot($rec['document_root'], $sections, $programs, $options);
108116
$app->system->web_folder_protection($rec['document_root'], true);
109117
$app->db->query("UPDATE `web_domain` SET `last_jailkit_update` = NOW(), `last_jailkit_hash` = ? WHERE `document_root` = ?", $update_hash, $rec['document_root']);
110118
} else {
@@ -114,7 +122,7 @@ public function onRunJob() {
114122
//$app->log('Removing unused jail: '.$rec['document_root'], LOGLEVEL_DEBUG);
115123
print 'Removing unused jail: '.$rec['document_root']."\n";
116124
$app->system->web_folder_protection($rec['document_root'], false);
117-
$app->system->delete_jailkit_chroot($rec['document_root']);
125+
$app->system->delete_jailkit_chroot($rec['document_root'], $options);
118126
$app->system->web_folder_protection($rec['document_root'], true);
119127

120128
$app->db->query("UPDATE `web_domain` SET `last_jailkit_update` = NOW(), `last_jailkit_hash` = NULL WHERE `document_root` = ?", $rec['document_root']);

server/lib/classes/system.inc.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,9 +2485,23 @@ public function update_jailkit_chroot($home_dir, $sections = array(), $programs
24852485
return false;
24862486
}
24872487

2488+
$jailkit_directories = array(
2489+
'bin',
2490+
'dev',
2491+
'etc',
2492+
'lib',
2493+
'lib32',
2494+
'lib64',
2495+
'opt',
2496+
'sys',
2497+
'usr',
2498+
'var',
2499+
);
2500+
24882501
$opts = array();
24892502
$jk_update_args = '';
24902503
$jk_cp_args = '';
2504+
$skips = '';
24912505
foreach ($options as $opt) {
24922506
switch ($opt) {
24932507
case '-k':
@@ -2501,27 +2515,19 @@ public function update_jailkit_chroot($home_dir, $sections = array(), $programs
25012515
$opts[] = 'force';
25022516
$jk_cp_args .= ' -f';
25032517
break;
2518+
default:
2519+
if (preg_match('@^skip[ =]/?(.+)$@', $opt, $matches) ) {
2520+
$jailkit_directories = $app->functions->array_unset_by_value($jailkit_directories, $matches[1]);
2521+
$skips .= ' --skip=/'.escapeshellarg($matches[1]);
2522+
}
2523+
break;
25042524
}
25052525
}
25062526

25072527
// Change ownership of the chroot directory to root
25082528
$this->chown($home_dir, 'root');
25092529
$this->chgrp($home_dir, 'root');
25102530

2511-
$jailkit_directories = array(
2512-
'bin',
2513-
'dev',
2514-
'etc',
2515-
'lib',
2516-
'lib32',
2517-
'lib64',
2518-
'opt',
2519-
'sys',
2520-
'usr',
2521-
'var',
2522-
);
2523-
2524-
$skips = '';
25252531
$multiple_links = array();
25262532
foreach ($jailkit_directories as $dir) {
25272533
$root_dir = '/'.$dir;
@@ -2693,9 +2699,10 @@ public function update_jailkit_chroot($home_dir, $sections = array(), $programs
26932699
return true;
26942700
}
26952701

2696-
public function delete_jailkit_chroot($home_dir) {
2702+
public function delete_jailkit_chroot($home_dir, $options = array()) {
26972703
global $app;
26982704

2705+
$app->log("delete_jailkit_chroot called for $home_dir with options ".print_r($options, true), LOGLEVEL_DEBUG);
26992706
$app->uses('ini_parser');
27002707

27012708
// Disallow operating on root directory
@@ -2723,6 +2730,16 @@ public function delete_jailkit_chroot($home_dir) {
27232730
'run', # not used by jailkit, but added for cleanup
27242731
);
27252732

2733+
foreach ($options as $opt) {
2734+
switch ($opt) {
2735+
default:
2736+
if (preg_match('@^skip[ =]/?(.+)$@', $opt, $matches) ) {
2737+
$jailkit_directories = $app->functions->array_unset_by_value($jailkit_directories, $matches[1]);
2738+
}
2739+
break;
2740+
}
2741+
}
2742+
27262743
$removed = '';
27272744
foreach ($jailkit_directories as $dir) {
27282745
$jail_dir = rtrim($home_dir, '/') . '/'.$dir;

server/plugins-available/apache2_plugin.inc.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,11 @@ function update($event_name, $data) {
831831
$programs = $jailkit_config['jailkit_chroot_app_programs'] . ' '
832832
. $jailkit_config['jailkit_chroot_cron_programs'];
833833

834+
$records = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $data['new']['domain_id'], $data['new']['document_root'], $conf['server_id']);
835+
foreach ($records as $record) {
836+
$options[] = 'skip='.$record['web_folder'];
837+
}
838+
834839
// don't update if last_jailkit_hash is the same
835840
$tmp = $app->db->queryOneRecord('SELECT `last_jailkit_hash` FROM web_domain WHERE domain_id = ?', $data['new']['parent_domain_id']);
836841
if ($update_hash != $tmp['last_jailkit_hash']) {
@@ -3683,7 +3688,7 @@ private function get_seo_redirects($web, $prefix = ''){
36833688

36843689
function _setup_jailkit_chroot()
36853690
{
3686-
global $app;
3691+
global $app, $conf;
36873692

36883693
$app->uses('system');
36893694

@@ -3746,6 +3751,11 @@ function _setup_jailkit_chroot()
37463751
return;
37473752
}
37483753

3754+
$records = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $this->website['domain_id'], $this->website['document_root'], $conf['server_id']);
3755+
foreach ($records as $record) {
3756+
$options[] = 'skip='.$record['web_folder'];
3757+
}
3758+
37493759
$app->system->update_jailkit_chroot($this->website['document_root'], $sections, $programs, $options);
37503760
}
37513761

@@ -3824,7 +3834,13 @@ private function _delete_jailkit_if_unused($parent_domain_id) {
38243834
return;
38253835
}
38263836

3827-
$app->system->delete_jailkit_chroot($parent_domain['document_root']);
3837+
$options = array();
3838+
$records = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $parent_domain_id, $parent_domain['document_root'], $conf['server_id']);
3839+
foreach ($records as $record) {
3840+
$options[] = 'skip='.$record['web_folder'];
3841+
}
3842+
3843+
$app->system->delete_jailkit_chroot($parent_domain['document_root'], $options);
38283844

38293845
// this gets last_jailkit_update out of sync with master db, but that is ok,
38303846
// as it is only used as a timestamp to moderate the frequency of updating on the slaves

server/plugins-available/cron_jailkit_plugin.inc.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ function _setup_jailkit_chroot()
296296
return;
297297
}
298298

299+
$records = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $this->parent_domain['domain_id'], $this->parent_domain['document_root'], $conf['server_id']);
300+
foreach ($records as $record) {
301+
$options[] = 'skip='.$record['web_folder'];
302+
}
303+
299304
$app->system->update_jailkit_chroot($this->parent_domain['document_root'], $sections, $programs, $options);
300305
}
301306

@@ -392,7 +397,13 @@ private function _delete_jailkit_if_unused($parent_domain_id) {
392397
return;
393398
}
394399

395-
$app->system->delete_jailkit_chroot($parent_domain['document_root']);
400+
$options = array();
401+
$records = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $parent_domain_id, $parent_domain['document_root'], $conf['server_id']);
402+
foreach ($records as $record) {
403+
$options[] = 'skip='.$record['web_folder'];
404+
}
405+
406+
$app->system->delete_jailkit_chroot($parent_domain['document_root'], $options);
396407

397408
// this gets last_jailkit_update out of sync with master db, but that is ok,
398409
// as it is only used as a timestamp to moderate the frequency of updating on the slaves

server/plugins-available/nginx_plugin.inc.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,11 @@ function update($event_name, $data) {
669669
$programs = $jailkit_config['jailkit_chroot_app_programs'] . ' '
670670
. $jailkit_config['jailkit_chroot_cron_programs'];
671671

672+
$records = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $data['new']['domain_id'], $data['new']['document_root'], $conf['server_id']);
673+
foreach ($records as $record) {
674+
$options[] = 'skip='.$record['web_folder'];
675+
}
676+
672677
// don't update if last_jailkit_hash is the same
673678
$tmp = $app->db->queryOneRecord('SELECT `last_jailkit_hash` FROM web_domain WHERE domain_id = ?', $data['new']['parent_domain_id']);
674679
if ($update_hash != $tmp['last_jailkit_hash']) {
@@ -3450,7 +3455,7 @@ private function get_seo_redirects($web, $prefix = '', $force_subdomain = false)
34503455

34513456
function _setup_jailkit_chroot()
34523457
{
3453-
global $app;
3458+
global $app, $conf;
34543459

34553460
$app->uses('system');
34563461

@@ -3513,6 +3518,11 @@ function _setup_jailkit_chroot()
35133518
return;
35143519
}
35153520

3521+
$records = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $this->website['domain_id'], $this->website['document_root'], $conf['server_id']);
3522+
foreach ($records as $record) {
3523+
$options[] = 'skip='.$record['web_folder'];
3524+
}
3525+
35163526
$app->system->update_jailkit_chroot($this->website['document_root'], $sections, $programs, $options);
35173527
}
35183528

@@ -3590,7 +3600,13 @@ private function _delete_jailkit_if_unused($parent_domain_id) {
35903600
return;
35913601
}
35923602

3593-
$app->system->delete_jailkit_chroot($parent_domain['document_root']);
3603+
$options = array();
3604+
$records = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $parent_domain_id, $parent_domain['document_root'], $conf['server_id']);
3605+
foreach ($records as $record) {
3606+
$options[] = 'skip='.$record['web_folder'];
3607+
}
3608+
3609+
$app->system->delete_jailkit_chroot($parent_domain['document_root'], $options);
35943610

35953611
// this gets last_jailkit_update out of sync with master db, but that is ok,
35963612
// as it is only used as a timestamp to moderate the frequency of updating on the slaves

server/plugins-available/shelluser_jailkit_plugin.inc.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function delete($event_name, $data) {
286286

287287
function _setup_jailkit_chroot()
288288
{
289-
global $app;
289+
global $app, $conf;
290290

291291
if (isset($this->jailkit_config) && isset($this->jailkit_config['jailkit_hardlinks'])) {
292292
if ($this->jailkit_config['jailkit_hardlinks'] == 'yes') {
@@ -356,6 +356,11 @@ function _setup_jailkit_chroot()
356356
return;
357357
}
358358

359+
$records = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $this->data['new']['parent_domain_id'], $this->data['new']['dir'], $conf['server_id']);
360+
foreach ($records as $record) {
361+
$options[] = 'skip='.$record['web_folder'];
362+
}
363+
359364
$app->system->update_jailkit_chroot($this->data['new']['dir'], $sections, $programs, $options);
360365
}
361366

@@ -621,7 +626,13 @@ private function _delete_jailkit_if_unused($parent_domain_id) {
621626
return;
622627
}
623628

624-
$app->system->delete_jailkit_chroot($parent_domain['document_root']);
629+
$options = array();
630+
$records = $app->db->queryAllRecords('SELECT web_folder FROM `web_domain` WHERE `parent_domain_id` = ? AND `document_root` = ? AND web_folder != \'\' AND web_folder IS NOT NULL AND `server_id` = ?', $parent_domain_id, $parent_domain['document_root'], $conf['server_id']);
631+
foreach ($records as $record) {
632+
$options[] = 'skip='.$record['web_folder'];
633+
}
634+
635+
$app->system->delete_jailkit_chroot($parent_domain['document_root'], $options);
625636

626637
// this gets last_jailkit_update out of sync with master db, but that is ok,
627638
// as it is only used as a timestamp to moderate the frequency of updating on the slaves

0 commit comments

Comments
 (0)