Skip to content

Commit 4f6eb2c

Browse files
committed
Transform the domain placeholder in command_format function
1 parent 5026674 commit 4f6eb2c

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

interface/lib/classes/validate_cron.inc.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,37 @@ function get_error($errmsg) {
4545
Validator function to check if a given cron command is in correct form (url only).
4646
*/
4747
function command_format($field_name, $field_value, $validator) {
48+
global $app, $page;
49+
4850
if(preg_match("'^(\w+):\/\/'", $field_value, $matches)) {
51+
if(preg_match("/\{DOMAIN\}/", $field_value)) {
52+
if(isset($app->remoting_lib->primary_id)) {
53+
$domain = $app->remoting_lib->dataRecord;
54+
} else {
55+
$domain = $page->dataRecord;
56+
}
57+
58+
if($domain['parent_domain_id'] > 0){
59+
$parent_domain = $app->db->queryOneRecord("SELECT `domain` FROM `web_domain` WHERE `domain_id` = ?", $domain['parent_domain_id']);
60+
}
61+
62+
$trans = array(
63+
'{DOMAIN}' => $parent_domain['domain']
64+
);
65+
66+
$field_value = strtr($field_value, $trans);
67+
}
4968

5069
$parsed = parse_url($field_value);
70+
5171
if($parsed === false) return $this->get_error($validator['errmsg']);
5272

5373
if($parsed["scheme"] != "http" && $parsed["scheme"] != "https") return $this->get_error($validator['errmsg']);
74+
if(preg_match("'^([a-z0-9][a-z0-9\-]{0,62}\.)+([A-Za-z0-9\-]{2,63})$'i", $parsed["host"]) == false) return $this->get_error($validator['errmsg']);
75+
5476

55-
if(preg_match("'^([a-z0-9][a-z0-9_\-]{0,62}\.)+([A-Za-z0-9\-]{2,63})$'i", $parsed["host"]) == false) return $this->get_error($validator['errmsg']);
5677
}
78+
5779
if(strpos($field_value, "\n") !== false || strpos($field_value, "\r") !== false || strpos($field_value, chr(0)) !== false) {
5880
return $this->get_error($validator['errmsg']);
5981
}

interface/web/sites/templates/cron_edit.htm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<div class="form-group">
22
<tmpl_if name="edit_disabled">
3+
34
<label for="parent_domain_id" class="col-sm-3 control-label">{tmpl_var name='parent_domain_id_txt'}</label>
4-
<div class="col-sm-9"><select name="parent_domain_id" id="parent_domain_id" class="form-control" disabled="disabled">
5+
<div class="col-sm-9"><i class="fa-solid fa-circle-info"></i><select name="parent_domain_id" id="parent_domain_id" class="form-control" disabled="disabled">
56
{tmpl_var name='parent_domain_id'}
67
</select></div>
78
<input type="hidden" name="parent_domain_id" value="{tmpl_var name='parent_domain_id_value'}" />
@@ -12,6 +13,7 @@
1213
</select></div>
1314
</tmpl_if>
1415
</div>
16+
1517
<div class="form-group">
1618
<label for="run_min" class="col-sm-3 control-label">{tmpl_var name='run_min_txt'}</label>
1719
<div class="col-sm-9">
@@ -70,8 +72,6 @@
7072
{tmpl_var name='active'}
7173
</div>
7274
</div>
73-
74-
7575
<input type="hidden" name="id" value="{tmpl_var name='id'}">
7676

7777
<div class="clear"><div class="right">
@@ -85,7 +85,7 @@
8585
jQuery('#parent_domain_id').trigger('change');
8686
});
8787
// Reload cron placeholders if a different domain was selected
88-
jQuery('#parent_domain_id').change(function(){
88+
jQuery('#parent_domain_id').change(function() {
8989
reloadCronPlaceholders();
9090
});
9191

server/plugins-available/cron_plugin.inc.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ function _write_crontab() {
231231
$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']);
232232
}
233233

234+
$web_domain = $this->parent_domain['domain'];
234235
$log_target = "";
235236
$log_wget_target = '/dev/null';
236237
$log_root = '';
@@ -242,8 +243,16 @@ function _write_crontab() {
242243
$log_wget_target = $log_root . '/cron_wget.log';
243244
}
244245

246+
247+
245248
$cron_line .= "\t{$this->parent_domain['system_user']}"; //* running as user
246249
if($job['type'] == 'url') {
250+
$trans = array(
251+
'{DOMAIN}' => $web_domain
252+
);
253+
254+
$job['command'] = strtr($job['command'], $trans);
255+
247256
$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;
248257
} else {
249258
if(strpos($job['command'], "\n") !== false || strpos($job['command'], "\r") !== false || strpos($job['command'], chr(0)) !== false) {
@@ -253,8 +262,6 @@ function _write_crontab() {
253262

254263
$web_docroot_client = '';
255264

256-
$web_domain = $this->parent_domain['domain'];
257-
258265
// web folder is hardcoded to /web:
259266
$web_folder = '/web';
260267

server/plugins-available/shelluser_jailkit_plugin.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ function _add_bashrc_jailkit() {
726726
}
727727

728728
if($app->system->is_redhat_os() == true) {
729+
//$bashrc = $this->web['document_root'] . '/home/' . $this->web['system_user'] . '/.bashrc';
729730
$bashrc = $this->web['document_root'] . '/etc/bashrc';
730731
} else {
731732
$bashrc = $this->web['document_root'] . '/etc/bash.bashrc';

0 commit comments

Comments
 (0)