Skip to content

Commit 32e546f

Browse files
committed
Merge remote-tracking branch 'helmo/6501-php-ssh-cron' into 6501-php-ssh-cron
2 parents e7cab97 + bf791d4 commit 32e546f

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function onRunJob() {
4242
$jailkit_config = $app->getconf->get_server_config($conf['server_id'], 'jailkit');
4343
if (isset($this->jailkit_config) && isset($this->jailkit_config['jailkit_hardlinks'])) {
4444
if ($this->jailkit_config['jailkit_hardlinks'] == 'yes') {
45-
$options = array('hardlink');
45+
$global_options = array('hardlink');
4646
} elseif ($this->jailkit_config['jailkit_hardlinks'] == 'no') {
47-
$options = array();
47+
$global_options = array();
4848
}
4949
} else {
50-
$options = array('allow_hardlink');
50+
$global_options = array('allow_hardlink');
5151
}
5252

5353
// force all jails to update every 2 weeks
@@ -65,7 +65,12 @@ public function onRunJob() {
6565
// limit the number of jails we update at one time according to time of day
6666
$num_jails_to_update = (date('H') < 6) ? 25 : 3;
6767

68-
$sql = "SELECT domain_id, domain, document_root, system_user, system_group, php_fpm_chroot, jailkit_chroot_app_sections, jailkit_chroot_app_programs, delete_unused_jailkit, last_jailkit_hash FROM web_domain WHERE type = 'vhost' AND (last_jailkit_update IS NULL OR last_jailkit_update < (NOW() - INTERVAL 24 HOUR)) AND server_id = ? ORDER by last_jailkit_update LIMIT ?";
68+
$sql = "SELECT domain_id, domain, document_root, system_user, system_group, php_fpm_chroot, jailkit_chroot_app_sections, jailkit_chroot_app_programs, delete_unused_jailkit, last_jailkit_hash, `php_cli_binary`
69+
FROM web_domain
70+
LEFT JOIN server_php ON web_domain.server_php_id = server_php.server_php_id
71+
WHERE type = 'vhost' AND (last_jailkit_update IS NULL OR last_jailkit_update < (NOW() - INTERVAL 24 HOUR)) AND web_domain.server_id = ? and domain_id=57
72+
ORDER by last_jailkit_update
73+
LIMIT ?";
6974
$records = $app->db->queryAllRecords($sql, $conf['server_id'], $num_jails_to_update);
7075

7176
foreach($records as $rec) {
@@ -74,6 +79,9 @@ public function onRunJob() {
7479
continue;
7580
}
7681

82+
$options = $global_options;
83+
$options['php_cli_binary'] = $rec['php_cli_binary'];
84+
7785
//$app->log('Beginning jailkit maintenance for domain '.$rec['domain'].' at '.$rec['document_root'], LOGLEVEL_DEBUG);
7886
print 'Beginning jailkit maintenance for domain '.$rec['domain'].' at '.$rec['document_root']."\n";
7987

server/lib/classes/system.inc.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,11 +2829,27 @@ public function update_jailkit_chroot($home_dir, $sections = array(), $programs
28292829
$this->chmod($home_dir . '/var/tmp', 0770, true);
28302830
}
28312831

2832-
// TODO: Set /usr/bin/php symlink to php version of the website.
2833-
//
2834-
// Currently server_php does not have a field for the cli path;
2835-
// we can guess/determing according to OS-specific conventions or add that field.
2836-
// Then symlink /usr/bin/php (or correct OS-specific path) to that location.
2832+
if (!empty($options['php_cli_binary'])) {
2833+
if(!file_exists($home_dir . '/' . $options['php_cli_binary'])) {
2834+
$app->log("The PHP cli binary " . $options['php_cli_binary'] . " is not available in the jail of the web " . $this->web['domain'] . " / SSH/SFTP user: " . $this->username . ". Check your Jailkit setup!", LOGLEVEL_DEBUG);
2835+
$tpl->setVar('use_php_path', false);
2836+
$tpl->setVar('use_php_alias', false);
2837+
if(is_link($home_dir . '/etc/alternatives/php'))
2838+
{
2839+
unlink($home_dir . '/etc/alternatives/php');
2840+
}
2841+
} else {
2842+
if($app->system->get_os_type() == "debian" || $app->system->get_os_type() == "ubuntu") {
2843+
$app->log("update_jailkit_chroot: setting alternatives/php to " . $options['php_cli_binary'], LOGLEVEL_DEBUG);
2844+
if(is_link($home_dir . '/etc/alternatives/php') || is_file($home_dir . '/etc/alternatives/php'))
2845+
{
2846+
unlink($home_dir . '/etc/alternatives/php');
2847+
}
2848+
symlink($options['php_cli_binary'], $home_dir . '/etc/alternatives/php');
2849+
}
2850+
2851+
}
2852+
}
28372853

28382854
// search for any hardlinked files which are now missing
28392855
if (!(in_array('hardlink', $opts) || in_array('allow_hardlink', $options))) {

server/plugins-available/shelluser_jailkit_plugin.inc.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ function _setup_jailkit_chroot()
344344
$options = array('allow_hardlink');
345345
}
346346

347-
$web = $app->db->queryOneRecord("SELECT domain, last_jailkit_hash FROM web_domain WHERE domain_id = ?", $this->data['new']["parent_domain_id"]);
347+
$web = $app->db->queryOneRecord("SELECT `domain`, `last_jailkit_hash`, `php_cli_binary` FROM web_domain
348+
LEFT JOIN server_php ON web_domain.server_php_id = server_php.server_php_id
349+
WHERE `domain_id` = ?", $data["new"]["parent_domain_id"]);
350+
348351

349352
$last_updated = preg_split('/[\s,]+/', $this->jailkit_config['jailkit_chroot_app_sections']
350353
.' '.$this->jailkit_config['jailkit_chroot_app_programs']
@@ -389,6 +392,7 @@ function _setup_jailkit_chroot()
389392
foreach ($records as $record) {
390393
$options[] = 'skip='.$record['web_folder'];
391394
}
395+
$options['php_cli_binary'] = $web['php_cli_binary'];
392396

393397
$app->system->update_jailkit_chroot($this->data['new']['dir'], $sections, $programs, $options);
394398

@@ -725,21 +729,6 @@ function _setup_php_jailkit() {
725729
$app->log("The PHP cli binary " . $this->web['php_cli_binary'] . " is not available in the jail of the web " . $this->web['domain'] . " / SSH/SFTP user: " . $this->username . ". Check your Jailkit setup!", LOGLEVEL_DEBUG);
726730
$tpl->setVar('use_php_path', false);
727731
$tpl->setVar('use_php_alias', false);
728-
if(is_link($this->web['document_root'] . '/etc/alternatives/php'))
729-
{
730-
unlink($this->web['document_root'] . '/etc/alternatives/php');
731-
}
732-
} else {
733-
if($app->system->get_os_type() == "debian" || $app->system->get_os_type() == "ubuntu") {
734-
if(is_link($this->web['document_root'] . '/etc/alternatives/php') || is_file($this->web['document_root'] . '/etc/alternatives/php'))
735-
{
736-
unlink($this->web['document_root'] . '/etc/alternatives/php');
737-
symlink($this->web['php_cli_binary'], $this->web['document_root'] . '/etc/alternatives/php');
738-
} else {
739-
symlink($this->web['php_cli_binary'], $this->web['document_root'] . '/etc/alternatives/php');
740-
}
741-
}
742-
743732
}
744733
}
745734

0 commit comments

Comments
 (0)