Skip to content

Commit 0316d01

Browse files
author
Marius Burkard
committed
- added automatic jailkit update, contributed by Timme Hosting
1 parent acf3c47 commit 0316d01

File tree

8 files changed

+155
-3
lines changed

8 files changed

+155
-3
lines changed

install/sql/incremental/upd_0086.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ ALTER TABLE `web_domain` ADD COLUMN `ssl_letsencrypt_exclude` enum('n','y') NOT
22
ALTER TABLE `remote_user` ADD `remote_access` ENUM('y','n') NOT NULL DEFAULT 'y' AFTER `remote_password`;
33
ALTER TABLE `remote_user` ADD `remote_ips` TEXT AFTER `remote_access`;
44
ALTER TABLE `server_php` ADD `active` enum('y','n') NOT NULL DEFAULT 'y' AFTER `php_fpm_pool_dir`;
5-
ALTER TABLE `web_domain` CHANGE `log_retention` `log_retention` INT(11) NOT NULL DEFAULT '10';
5+
ALTER TABLE `web_domain` CHANGE `log_retention` `log_retention` INT(11) NOT NULL DEFAULT '10';

install/sql/incremental/upd_dev_collection.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,5 @@ CREATE TABLE IF NOT EXISTS `sys_mailqueue` (
160160
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
161161
PRIMARY KEY (`id`)
162162
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
163+
164+
ALTER TABLE `web_domain` ADD `jailkit_jkupdate_cron` enum('n','y') NOT NULL DEFAULT 'y' AFTER `custom_php_ini`;

install/sql/ispconfig3.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,7 @@ CREATE TABLE `web_domain` (
18501850
`pm_max_requests` int(11) NOT NULL DEFAULT '0',
18511851
`php_open_basedir` mediumtext,
18521852
`custom_php_ini` mediumtext,
1853+
`jailkit_jkupdate_cron` enum('n','y') NOT NULL DEFAULT 'y',
18531854
`backup_interval` VARCHAR( 255 ) NOT NULL DEFAULT 'none',
18541855
`backup_copies` INT NOT NULL DEFAULT '1',
18551856
`backup_excludes` mediumtext,

interface/web/sites/form/web_vhost_domain.tform.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,12 @@
970970
'value' => '',
971971
'width' => '4',
972972
'maxlength' => '4'
973+
),
974+
'jailkit_jkupdate_cron' => array (
975+
'datatype' => 'VARCHAR',
976+
'formtype' => 'CHECKBOX',
977+
'default' => 'y',
978+
'value' => array(0 => 'n', 1 => 'y')
973979
)
974980
//#################################
975981
// ENDE Datatable fields

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ $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-
?>
158+
$wb['jailkit_jkupdate_cron_txt'] = 'Automatisches jkupdate';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,4 @@ $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-
?>
164+
$wb['jailkit_jkupdate_cron_txt'] = 'Automate jkupdate';

interface/web/sites/templates/web_vhost_domain_advanced.htm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ <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>
106+
<div class="col-sm-9">
107+
{tmpl_var name='jailkit_jkupdate_cron'}
108+
</div>
109+
</div>
104110
<div class="form-group apache">
105111
<label for="apache_directives" class="col-sm-3 control-label">{tmpl_var name='apache_directives_txt'}</label>
106112
<div class="col-sm-9"><textarea class="form-control" name="apache_directives" id="apache_directives" rows='10' cols='50'>{tmpl_var name='apache_directives'}</textarea>
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2013, Marius Cramer, pixcept KG
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
class cronjob_jkupdate extends cronjob {
32+
33+
// job schedule
34+
protected $_schedule = '45 22 * * *';
35+
protected $_run_at_new = true;
36+
37+
/* this function is optional if it contains no custom code */
38+
public function onPrepare() {
39+
global $app;
40+
41+
parent::onPrepare();
42+
}
43+
44+
/* this function is optional if it contains no custom code */
45+
public function onBeforeRun() {
46+
global $app;
47+
48+
return parent::onBeforeRun();
49+
}
50+
51+
public function onRunJob() {
52+
global $app, $conf;
53+
54+
$app->uses('getconf');
55+
$jailkit_conf = $app->getconf->get_server_config($conf['server_id'], 'jailkit');
56+
$jailkit_programs = explode(' ', $jailkit_conf['jailkit_chroot_app_programs']);
57+
58+
$sites = $app->db->queryAllRecords('SELECT domain_id, document_root FROM web_domain WHERE jailkit_jkupdate_cron = \'y\'');
59+
60+
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+
if ($users['user_count'] > 0 || $crons['cron_count'] > 0) {
64+
if (!is_dir($site['document_root'])) {
65+
return;
66+
}
67+
68+
$app->log('Running jailkit updates for '.$site['document_root']);
69+
70+
$this->run_jk_update($site['document_root']);
71+
$this->run_jk_cp($site['document_root'], $jailkit_programs);
72+
}
73+
}
74+
75+
parent::onRunJob();
76+
}
77+
78+
private function run_jk_update($document_root) {
79+
global $app;
80+
81+
$return_var = $this->exec_log('/usr/sbin/jk_update -j '.escapeshellarg($document_root));
82+
83+
if ($return_var > 0) {
84+
$app->log('jk_update failed with -j, trying again without -j', LOGLEVEL_DEBUG);
85+
$return_var = $this->exec_log('/usr/sbin/jk_update '.escapeshellarg($document_root));
86+
87+
if ($return_var > 0) {
88+
$app->log('jk_update failed (with and without -j parameter)', LOGLEVEL_WARN);
89+
}
90+
}
91+
}
92+
93+
private function run_jk_cp($document_root, $programs) {
94+
global $app;
95+
96+
foreach($programs as $program) {
97+
if (!file_exists($program)) {
98+
continue;
99+
}
100+
101+
$return_var = $this->exec_log('/usr/sbin/jk_cp '.escapeshellarg($document_root).' '.escapeshellarg($program));
102+
103+
if ($return_var > 0) {
104+
$app->log('jk_cp failed with -j, trying again with -j', LOGLEVEL_DEBUG);
105+
$return_var = $this->exec_log('/usr/sbin/jk_cp '.escapeshellarg($document_root).' '.escapeshellarg($program));
106+
107+
if ($return_var > 0) {
108+
$app->log('jk_cp failed (without and with -j parameter)', LOGLEVEL_WARN);
109+
}
110+
}
111+
}
112+
}
113+
114+
private function exec_log($cmd) {
115+
global $app;
116+
117+
$app->log("Running $cmd", LOGLEVEL_DEBUG);
118+
119+
exec($cmd, $output, $return_var);
120+
121+
if (count($output) > 0) {
122+
$app->log("Output:\n" . implode("\n", $output), LOGLEVEL_DEBUG);
123+
}
124+
125+
return $return_var;
126+
}
127+
128+
/* this function is optional if it contains no custom code */
129+
public function onAfterRun() {
130+
global $app;
131+
132+
parent::onAfterRun();
133+
}
134+
135+
}
136+
137+
?>

0 commit comments

Comments
 (0)