Skip to content

Commit 7cf894f

Browse files
committed
Update Jailkit PHP code
1 parent b590d8e commit 7cf894f

File tree

4 files changed

+35
-28
lines changed

4 files changed

+35
-28
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ public function onRunJob() {
4040
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
4141

4242
$jailkit_config = $app->getconf->get_server_config($conf['server_id'], 'jailkit');
43-
if (isset($this->jailkit_config) && isset($this->jailkit_config['jailkit_hardlinks'])) {
44-
if ($this->jailkit_config['jailkit_hardlinks'] == 'yes') {
43+
if(isset($this->jailkit_config) && isset($this->jailkit_config['jailkit_hardlinks'])) {
44+
if($this->jailkit_config['jailkit_hardlinks'] == 'yes') {
4545
$global_options = array('hardlink');
46-
} elseif ($this->jailkit_config['jailkit_hardlinks'] == 'no') {
46+
} elseif($this->jailkit_config['jailkit_hardlinks'] == 'no') {
4747
$global_options = array();
4848
}
4949
} else {
5050
$global_options = array('allow_hardlink');
5151
}
5252

5353
// force all jails to update every 2 weeks
54-
if (! is_file('/usr/local/ispconfig/server/temp/jailkit_force_update.ts')) {
54+
if(!is_file('/usr/local/ispconfig/server/temp/jailkit_force_update.ts')) {
5555
if(!@is_dir('/usr/local/ispconfig/server/temp')) {
5656
$app->system->mkdirpath('/usr/local/ispconfig/server/temp');
5757
}
5858
$app->system->touch('/usr/local/ispconfig/server/temp/jailkit_force_update.ts');
59-
} elseif ( time() - filemtime('/usr/local/ispconfig/server/temp/jailkit_force_update.ts') > 60 * 60 * 24 * 14 ) {
59+
} elseif(time() - filemtime('/usr/local/ispconfig/server/temp/jailkit_force_update.ts') > 60 * 60 * 24 * 14) {
6060
$update_hash = 'force_update'.time();
6161
$app->db->query("UPDATE web_domain SET last_jailkit_hash = ? WHERE type = 'vhost' AND server_id = ?", $update_hash, $conf['server_id']);
6262
$app->system->touch('/usr/local/ispconfig/server/temp/jailkit_force_update.ts');

server/lib/classes/system.inc.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,21 +2835,30 @@ public function update_jailkit_chroot($home_dir, $sections = array(), $programs
28352835
$this->chmod($home_dir . '/var/tmp', 0770, true);
28362836
}
28372837

2838-
if (!empty($options['php_cli_binary'])) {
2838+
2839+
if(!empty($options['php_cli_binary'])) {
2840+
$php_bin_dir = dirname($options['php_cli_binary']);
28392841
if(!file_exists($home_dir . '/' . $options['php_cli_binary'])) {
28402842
$app->log("update_jailkit_chroot: The PHP cli binary " . $options['php_cli_binary'] . " is not available in the jail of the web " . $options['domain'], LOGLEVEL_DEBUG);
2841-
if(is_link($home_dir . '/etc/alternatives/php') || is_file($home_dir . '/etc/alternatives/php'))
2842-
{
2843-
unlink($home_dir . '/etc/alternatives/php');
2843+
2844+
$fallback_php = $app->system->get_newest_php_bin($home_dir . $php_bin_dir);
2845+
$fallback_php_bin = str_replace($home_dir, '', $fallback_php);
2846+
2847+
if(!empty($fallback_php) && file_exists($fallback_php_bin)) {
2848+
if(is_link($home_dir . '/etc/alternatives/php') || is_file($home_dir . '/etc/alternatives/php')) {
2849+
unlink($home_dir . '/etc/alternatives/php');
2850+
symlink($fallback_php_bin, $home_dir . '/etc/alternatives/php');
2851+
$app->log("update_jailkit_chroot: Found " . $fallback_php_bin . " as a fallback for alternatives/php in the jail of " . $options['domain'], LOGLEVEL_DEBUG);
2852+
}
28442853
}
2854+
28452855
} else {
28462856
if($app->system->get_os_type() == "debian" || $app->system->get_os_type() == "ubuntu") {
28472857
$app->log("update_jailkit_chroot: setting alternatives/php to " . $options['php_cli_binary'], LOGLEVEL_DEBUG);
2848-
if(is_link($home_dir . '/etc/alternatives/php') || is_file($home_dir . '/etc/alternatives/php'))
2849-
{
2858+
if(is_link($home_dir . '/etc/alternatives/php') || is_file($home_dir . '/etc/alternatives/php')) {
28502859
unlink($home_dir . '/etc/alternatives/php');
2860+
symlink($options['php_cli_binary'], $home_dir . '/etc/alternatives/php');
28512861
}
2852-
symlink($options['php_cli_binary'], $home_dir . '/etc/alternatives/php');
28532862
}
28542863

28552864
}

server/plugins-available/cron_jailkit_plugin.inc.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,17 +402,16 @@ function _setup_php_jailkit() {
402402
$tpl->setVar('use_php_alias', false);
403403

404404
if(!empty($app->system->get_newest_php_bin($this->parent_domain['document_root'] . $php_bin_dir))) {
405-
if(is_link($this->parent_domain['document_root'] . '/etc/alternatives/php'))
406-
{
407-
unlink($this->parent_domain['document_root'] . '/etc/alternatives/php');
408-
}
409-
410405
$fallback_php = $app->system->get_newest_php_bin($this->parent_domain['document_root'] . $php_bin_dir);
411406
$fallback_php_bin = str_replace($this->parent_domain['document_root'], '', $fallback_php);
412407

413-
symlink($fallback_php_bin, $this->parent_domain['document_root'] . '/etc/alternatives/php');
414-
415-
$app->log("Found " . $fallback_php_bin . " as a fallback in the jail of ". $this->parent_domain['domain'], LOGLEVEL_DEBUG);
408+
if(!empty($fallback_php) && file_exists($fallback_php_bin)) {
409+
if(is_link($this->parent_domain['document_root'] . '/etc/alternatives/php') || is_file($this->parent_domain['document_root'] . '/etc/alternatives/php')) {
410+
unlink($this->parent_domain['document_root'] . '/etc/alternatives/php');
411+
symlink($fallback_php_bin, $this->parent_domain['document_root'] . '/etc/alternatives/php');
412+
$app->log("Found " . $fallback_php_bin . " as a fallback for alternatives/php in the jail of ". $this->parent_domain['domain'], LOGLEVEL_DEBUG);
413+
}
414+
}
416415
}
417416
} else {
418417
if($app->system->get_os_type() == "debian" || $app->system->get_os_type() == "ubuntu") {

server/plugins-available/shelluser_jailkit_plugin.inc.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -739,17 +739,16 @@ function _setup_php_jailkit() {
739739
$tpl->setVar('use_php_alias', false);
740740

741741
if(!empty($app->system->get_newest_php_bin($this->web['document_root'] . $php_bin_dir))) {
742-
if(is_link($this->web['document_root'] . '/etc/alternatives/php') || is_file($this->web['document_root'] . '/etc/alternatives/php'))
743-
{
744-
unlink($this->web['document_root'] . '/etc/alternatives/php');
745-
}
746-
747742
$fallback_php = $app->system->get_newest_php_bin($this->web['document_root'] . $php_bin_dir);
748743
$fallback_php_bin = str_replace($this->web['document_root'], '', $fallback_php);
749744

750-
symlink($fallback_php_bin, $this->web['document_root'] . '/etc/alternatives/php');
751-
752-
$app->log("Found " . $fallback_php_bin . " as a fallback in the jail of ". $this->web['domain'], LOGLEVEL_DEBUG);
745+
if(!empty($fallback_php) && file_exists($fallback_php_bin)) {
746+
if(is_link($this->web['document_root'] . '/etc/alternatives/php') || is_file($this->web['document_root'] . '/etc/alternatives/php')) {
747+
unlink($this->web['document_root'] . '/etc/alternatives/php');
748+
symlink($fallback_php_bin, $this->web['document_root'] . '/etc/alternatives/php');
749+
$app->log("Found " . $fallback_php_bin . " as a fallback for alternatives/php in the jail of ". $this->web['domain'], LOGLEVEL_DEBUG);
750+
}
751+
}
753752
}
754753
} else {
755754
if($app->system->get_os_type() == "debian" || $app->system->get_os_type() == "ubuntu") {

0 commit comments

Comments
 (0)