Skip to content

Commit 94be0a2

Browse files
author
Till Brehm
committed
Merge branch '5652-crontab-deletion-after-website-removal' into 'stable-3.1'
Resolve "Crontab deletion after website removal" See merge request ispconfig/ispconfig3!1069
2 parents 06d0edf + 760efc1 commit 94be0a2

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

server/plugins-available/cron_plugin.inc.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function update($event_name, $data) {
103103
$app->log("Websites (and Crons) cannot be owned by the root user or group.", LOGLEVEL_WARN);
104104
return false;
105105
}
106-
106+
107107
// Get the client ID
108108
$client = $app->dbmaster->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ?", $data["new"]["sys_groupid"]);
109109
$client_id = intval($client["client_id"]);
@@ -123,7 +123,7 @@ function update($event_name, $data) {
123123
$app->system->exec_safe("useradd -d ? -g ? ? -s /bin/false", $parent_domain["document_root"], $groupname, $username);
124124
$app->log("Adding the user: $username", LOGLEVEL_DEBUG);
125125
}
126-
126+
127127
// Set the quota for the user
128128
if($username != '' && $app->system->is_user($username)) {
129129
if($parent_domain['hd_quota'] > 0) {
@@ -144,7 +144,7 @@ function update($event_name, $data) {
144144
$app->system->exec_safe('setquota -u ? ? ? 0 0 -a &> /dev/null', $username, $blocks_soft, $blocks_hard);
145145
$app->system->exec_safe('setquota -T -u ? 604800 604800 -a &> /dev/null', $username);
146146
} elseif ($file_system == 'xfs') {
147-
147+
148148
$app->system->exec_safe("xfs_quota -x -c ? ?", "limit -u bsoft=$mb_soft" . 'm'. " bhard=$mb_hard" . 'm'. " $username", $primitive_root);
149149

150150
// xfs only supports timers globally, not per user.
@@ -177,21 +177,23 @@ function update($event_name, $data) {
177177
}
178178

179179
function delete($event_name, $data) {
180-
global $app, $conf;
180+
global $app;
181181

182182
//* get data from web
183183
$parent_domain = $app->db->queryOneRecord("SELECT `domain_id`, `system_user`, `system_group`, `document_root`, `hd_quota` FROM `web_domain` WHERE `domain_id` = ?", $data["old"]["parent_domain_id"]);
184-
if(!$parent_domain["domain_id"]) {
185-
$app->log("Parent domain not found", LOGLEVEL_WARN);
186-
return 0;
187-
}
188-
189-
// Get the client ID
190-
$client = $app->dbmaster->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ?", $data["old"]["sys_groupid"]);
191-
$client_id = intval($client["client_id"]);
192-
unset($client);
193184

194-
$this->parent_domain = $parent_domain;
185+
if(!$parent_domain) {
186+
$tmp = $app->db->queryOneRecord('SELECT * FROM sys_datalog WHERE dbtable = ? AND dbidx = ? AND `action` = ? ORDER BY `datalog_id` DESC', 'web_domain', 'domain_id:' . $data['old']['parent_domain_id'], 'd');
187+
$tmp = unserialize($tmp);
188+
if($tmp && isset($tmp['old'])) {
189+
$this->parent_domain = $tmp['old'];
190+
} else {
191+
$app->log("Parent domain not found", LOGLEVEL_WARN);
192+
return 0;
193+
}
194+
} else {
195+
$this->parent_domain = $parent_domain;
196+
}
195197
$this->_write_crontab();
196198
}
197199

@@ -223,18 +225,18 @@ function _write_crontab() {
223225
} else {
224226
$cron_line = str_replace(" ", "", $job['run_min']) . "\t" . str_replace(" ", "", $job['run_hour']) . "\t" . str_replace(" ", "", $job['run_mday']) . "\t" . str_replace(" ", "", $job['run_month']) . "\t" . str_replace(" ", "", $job['run_wday']);
225227
}
226-
228+
227229
$log_target = "";
228230
$log_wget_target = '/dev/null';
229231
$log_root = '';
230232
if($job['log'] == 'y') {
231233
if($job['type'] != 'chrooted') $log_root = $this->parent_domain['document_root'];
232234
$log_root .= '/private';
233-
235+
234236
$log_target = '>>' . $log_root . '/cron.log 2>>' . $log_root . '/cron_error.log';
235237
$log_wget_target = $log_root . '/cron_wget.log';
236238
}
237-
239+
238240
$cron_line .= "\t{$this->parent_domain['system_user']}"; //* running as user
239241
if($job['type'] == 'url') {
240242
$cron_line .= "\t{$cron_config['wget']} --no-check-certificate --user-agent='Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0' -q -t 1 -T 7200 -O " . $log_wget_target . " " . escapeshellarg($job['command']) . " " . $log_target;
@@ -243,7 +245,7 @@ function _write_crontab() {
243245
$app->log("Insecure Cron job SKIPPED: " . $job['command'], LOGLEVEL_WARN);
244246
continue;
245247
}
246-
248+
247249
$web_root = '';
248250
if($job['type'] == 'chrooted') {
249251
if(substr($job['command'], 0, strlen($this->parent_domain['document_root'])) == $this->parent_domain['document_root']) {
@@ -253,7 +255,7 @@ function _write_crontab() {
253255
} else {
254256
$web_root = $this->parent_domain['document_root'];
255257
}
256-
258+
257259
$web_root .= '/web';
258260
$job['command'] = str_replace('[web_root]', $web_root, $job['command']);
259261

0 commit comments

Comments
 (0)