Skip to content

Commit 06b26aa

Browse files
author
Marius Burkard
committed
- patches for jailkit update feature, contributed by Timme Hosting
1 parent 818d002 commit 06b26aa

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

interface/web/sites/lib/lang/de_web_vhost_domain.lng

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,5 @@ $wb['error_server_change_not_possible'] = 'Der Server kann nicht geändert werde
155155
$wb['enable_pagespeed_txt'] = 'Enable PageSpeed';
156156
$wb['log_retention_txt'] = 'Log-Dateien Aufbewahrungszeit';
157157
$wb['log_retention_error_regex'] = 'Aufbewahrungszeit in Tagen (Erlaubte Werte: min. 0 - max. 9999)';
158-
$wb['jailkit_jkupdate_cron_txt'] = 'Automatisches jkupdate';
158+
$wb['jailkit_jkupdate_cron_txt'] = 'Automatisches Jailkit-Update';
159+
$wb['ttip_jailkit_jkupdate_cron_txt'] = 'Wenn diese Website mind. einen Jailkit-SSH-Benutzer hat, wird das Jailkit durch einen täglichen Cron Job aktuell gehalten.';

interface/web/sites/lib/lang/en_web_vhost_domain.lng

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,5 @@ $wb['error_domain_change_forbidden'] = 'The domain name cannot be changed. Pleas
161161
$wb['error_server_change_not_possible'] = 'The server cannot be changed.';
162162
$wb['log_retention_txt'] = 'Logfiles retention time';
163163
$wb['log_retention_error_regex'] = 'Retention time in days (allowed values: min. 0 - max. 9999)';
164-
$wb['jailkit_jkupdate_cron_txt'] = 'Automate jkupdate';
164+
$wb['jailkit_jkupdate_cron_txt'] = 'Automatic Jailkit update';
165+
$wb['ttip_jailkit_jkupdate_cron_txt'] = 'If this site has at least one Jailkit SSH user, the jailkit will be kept up to date through a daily cron job.';

interface/web/sites/templates/web_vhost_domain_advanced.htm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ <h1><tmpl_var name="list_head_txt"></h1>
101101
<b>{tmpl_var name="available_php_directive_snippets_txt"}</b><br><br>&nbsp;{tmpl_var name="php_directive_snippets_txt"}
102102
</div>
103103
</div>
104-
<div class="form-group nginx">
105-
<label for="jailkit_jkupdate_cron" class="col-sm-3 control-label">{tmpl_var name='jailkit_jkupdate_cron_txt'}</label>
104+
<div class="form-group">
105+
<label for="jailkit_jkupdate_cron" class="col-sm-3 control-label">{tmpl_var name='jailkit_jkupdate_cron_txt'}{tmpl_if name="ttip_jailkit_jkupdate_cron_txt"}<div class="ttip" title="{tmpl_var name='ttip_jailkit_jkupdate_cron_txt'}" ></div>{/tmpl_if}</label>
106106
<div class="col-sm-9">
107107
{tmpl_var name='jailkit_jkupdate_cron'}
108108
</div>

server/lib/classes/cron.d/500-jkupdate.inc.php

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,72 @@ public function onRunJob() {
5353

5454
$app->uses('getconf');
5555
$jailkit_conf = $app->getconf->get_server_config($conf['server_id'], 'jailkit');
56-
$jailkit_programs = explode(' ', $jailkit_conf['jailkit_chroot_app_programs']);
56+
//$jailkit_programs = explode(' ', $jailkit_conf['jailkit_chroot_app_programs']);
57+
$jailkit_programs = preg_split("/[\s,]+/", $jailkit_conf['jailkit_chroot_app_programs']);
58+
$jailkit_sections = trim($jailkit_conf['jailkit_chroot_app_sections']);
5759

58-
$sites = $app->db->queryAllRecords('SELECT domain_id, document_root FROM web_domain WHERE jailkit_jkupdate_cron = \'y\'');
60+
$sites = $app->db->queryAllRecords("SELECT domain_id, document_root, fastcgi_php_version FROM web_domain WHERE jailkit_jkupdate_cron = 'y' AND type = 'vhost' AND parent_domain_id = 0 AND document_root != '' ORDER BY domain_id");
5961

6062
foreach($sites as $site) {
61-
$users = $app->db->queryOneRecord('SELECT COUNT(*) AS user_count FROM shell_user WHERE parent_domain_id = ? AND active=\'y\' AND chroot=\'jailkit\'', $site['domain_id']);
62-
$crons = $app->db->queryOneRecord('SELECT COUNT(*) AS cron_count FROM cron WHERE parent_domain_id = ? AND active=\'y\' AND type=\'chrooted\'', $site['domain_id']);
63+
$set_php_symlink = false;
64+
65+
$users = $app->db->queryOneRecord("SELECT COUNT(*) AS user_count FROM shell_user WHERE parent_domain_id = ? AND active='y' AND chroot='jailkit'", intval($site['domain_id']));
66+
$crons = $app->db->queryOneRecord("SELECT COUNT(*) AS cron_count FROM cron WHERE parent_domain_id = ? AND active='y' AND type='chrooted'", $site['domain_id']);
6367
if ($users['user_count'] > 0 || $crons['cron_count'] > 0) {
68+
6469
if (!is_dir($site['document_root'])) {
6570
return;
6671
}
72+
73+
//$app->log('Running jailkit init for '.$site['document_root']);
74+
//if($jailkit_sections != '') $this->run_jk_init($site['document_root'], $jailkit_sections);
6775

6876
$app->log('Running jailkit updates for '.$site['document_root']);
6977

7078
$this->run_jk_update($site['document_root']);
71-
$this->run_jk_cp($site['document_root'], $jailkit_programs);
79+
if(preg_match('@(\d\d?\.\d\d?\.\d\d?)@', $site['fastcgi_php_version'], $matches)){
80+
if(!in_array('/opt/php-'.$matches[1].'/bin/php', $jailkit_programs)) $jailkit_programs[] = '/opt/php-'.$matches[1].'/bin/php';
81+
if(!in_array('/opt/php-'.$matches[1].'/include', $jailkit_programs)) $jailkit_programs[] = '/opt/php-'.$matches[1].'/include';
82+
if(!in_array('/opt/php-'.$matches[1].'/lib', $jailkit_programs)) $jailkit_programs[] = '/opt/php-'.$matches[1].'/lib';
83+
if(!in_array('/opt/th-php-libs', $jailkit_programs)) $jailkit_programs[] = '/opt/th-php-libs';
84+
85+
$set_php_symlink = true;
86+
87+
}
88+
if(is_array($jailkit_programs) && !empty($jailkit_programs)) $this->run_jk_cp($site['document_root'], $jailkit_programs);
89+
90+
if($set_php_symlink){
91+
// create symlink from /usr/bin/php to current PHP version
92+
if(preg_match('@(\d\d?\.\d\d?\.\d\d?)@', $site['fastcgi_php_version'], $matches) && (!file_exists($site['document_root'].'/usr/bin/php') || is_link($site['document_root'].'/usr/bin/php'))){
93+
@unlink($site['document_root'].'/usr/bin/php');
94+
@symlink('/opt/php-'.$matches[1].'/bin/php', $site['document_root'].'/usr/bin/php');
95+
}
96+
}
7297
}
7398
}
99+
100+
if(file_exists('/dev/tty')){
101+
chmod('/dev/tty', 0666);
102+
}
74103

75104
parent::onRunJob();
76105
}
106+
107+
private function run_jk_init($document_root, $sections){
108+
global $app;
109+
110+
$return_var = $this->exec_log('/usr/sbin/jk_init -f -k -c /etc/jailkit/jk_init.ini -j '.escapeshellarg($document_root).' '.$sections);
111+
112+
if ($return_var > 0) {
113+
$app->log('jk_init failed with -j, trying again without -j', LOGLEVEL_DEBUG);
114+
115+
$return_var = $this->exec_log('/usr/sbin/jk_init -f -k -c /etc/jailkit/jk_init.ini '.escapeshellarg($document_root).' '.$sections);
116+
117+
if ($return_var > 0) {
118+
$app->log('jk_init failed (with and without -j parameter)', LOGLEVEL_WARN);
119+
}
120+
}
121+
}
77122

78123
private function run_jk_update($document_root) {
79124
global $app;
@@ -94,10 +139,14 @@ private function run_jk_cp($document_root, $programs) {
94139
global $app;
95140

96141
foreach($programs as $program) {
142+
$program = trim($program);
143+
if($program == ''){
144+
continue;
145+
}
97146
if (!file_exists($program)) {
98147
continue;
99148
}
100-
149+
101150
$return_var = $this->exec_log('/usr/sbin/jk_cp '.escapeshellarg($document_root).' '.escapeshellarg($program));
102151

103152
if ($return_var > 0) {
@@ -109,6 +158,10 @@ private function run_jk_cp($document_root, $programs) {
109158
}
110159
}
111160
}
161+
162+
if(file_exists($document_root.'/dev/tty')){
163+
chmod($document_root.'/dev/tty', 0666);
164+
}
112165
}
113166

114167
private function exec_log($cmd) {
@@ -134,4 +187,4 @@ public function onAfterRun() {
134187

135188
}
136189

137-
?>
190+
?>

0 commit comments

Comments
 (0)