Skip to content

Commit 5c43ae4

Browse files
authored
Allow admin to change panel cronjobs (hestiacp#3974)
* Fix permissions issues with cron not running * Allow admin to change panel cronjobs * Fix back link
1 parent 48acc9a commit 5c43ae4

File tree

8 files changed

+69
-2
lines changed

8 files changed

+69
-2
lines changed

bin/v-change-sys-service-config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ case $service in
7373
clamd) dst=$($BIN/v-list-sys-clamd-config plain) ;;
7474
fail2ban) dst='/etc/fail2ban/jail.local' ;;
7575
ssh) dst='/etc/ssh/sshd_config' ;;
76+
hestiaweb) dst='/var/spool/cron/crontabs/hestiaweb' ;;
7677
*) check_result $E_NOTEXIST "service $service doesn't exist" ;;
7778
esac
7879

bin/v-open-fs-config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ if [ -n "$src_file" ]; then
3737
rpath=$(readlink -f "$src_file")
3838
services="nginx|apache|httpd|php|ftp|bind|named|exim|dovecot|spamassassin"
3939
services="$services|clam|mysql|postgresql|pgsql|cron|ssh|fail2ban|iptables"
40-
services="$services|my.cnf"
40+
services="$services|my.cnf|hestiaweb"
4141
spath=$(echo "$rpath" | egrep "$services")
4242
if [ -z "$spath" ]; then
4343
echo "Error: invalid source path $src_file"
4444
exit 2
4545
fi
46-
spath=$(echo "$rpath" | egrep "/etc|/var/lib")
46+
spath=$(echo "$rpath" | egrep "/etc|/var/lib|/var/spool/cron/")
4747
if [ -z "$spath" ]; then
4848
echo "Error: invalid source path $src_file"
4949
exit 2

install/hst-install-debian.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,9 @@ echo "*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-rrd" >> /var/spool/cro
22832283
echo "$min $hour * * * sudo /usr/local/hestia/bin/v-update-letsencrypt-ssl" >> /var/spool/cron/crontabs/hestiaweb
22842284
echo "41 4 * * * sudo /usr/local/hestia/bin/v-update-sys-hestia-all" >> /var/spool/cron/crontabs/hestiaweb
22852285

2286+
chmod 600 /var/spool/cron/crontabs/hestiaweb
2287+
chown hestiaweb:hestiaweb /var/spool/cron/crontabs/hestiaweb
2288+
22862289
# Enable automatic updates
22872290
$HESTIA/bin/v-add-cron-hestia-autoupdate apt
22882291

install/hst-install-ubuntu.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,9 @@ echo "*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-rrd" >> /var/spool/cro
22422242
echo "$min $hour * * * sudo /usr/local/hestia/bin/v-update-letsencrypt-ssl" >> /var/spool/cron/crontabs/hestiaweb
22432243
echo "41 4 * * * sudo /usr/local/hestia/bin/v-update-sys-hestia-all" >> /var/spool/cron/crontabs/hestiaweb
22442244

2245+
chmod 600 /var/spool/cron/crontabs/hestiaweb
2246+
chown hestiaweb:hestiaweb /var/spool/cron/crontabs/hestiaweb
2247+
22452248
# Enable automatic updates
22462249
$HESTIA/bin/v-add-cron-hestia-autoupdate apt
22472250

install/upgrade/versions/1.9.0.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ if [ ! -f "/var/spool/cron/crontabs/hestiaweb" ]; then
6565
$BIN/v-delete-cron-job admin "$JOB"
6666
fi
6767
done < $HESTIA/data/users/admin/cron.conf
68+
# Update permissions
69+
chmod 600 /var/spool/cron/crontabs/hestiaweb
70+
chown hestiaweb:hestiaweb /var/spool/cron/crontabs/hestiaweb
71+
6872
fi
6973

7074
chown hestiaweb:hestiaweb /usr/local/hestia/data/sessions
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
$TAB = "SERVER";
4+
5+
// Main include
6+
include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
7+
8+
// Check user
9+
if ($_SESSION["userContext"] !== "admin" && $user_plain === "$ROOT_USER") {
10+
header("Location: /list/user");
11+
exit();
12+
}
13+
14+
// Check POST request
15+
if (!empty($_POST["save"])) {
16+
if (!empty($_POST["v_config"])) {
17+
exec("mktemp", $mktemp_output, $return_var);
18+
$new_conf = $mktemp_output[0];
19+
$fp = fopen($new_conf, "w");
20+
fwrite($fp, str_replace("\r\n", "\n", $_POST["v_config"]));
21+
fclose($fp);
22+
exec(
23+
HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " hestiaweb no",
24+
$output,
25+
$return_var,
26+
);
27+
check_return_code($return_var, $output);
28+
unset($output);
29+
unlink($new_conf);
30+
}
31+
}
32+
33+
$v_config_path = "/var/spool/cron/crontabs/hestiaweb";
34+
$v_service_name = _("Panel Cronjobs");
35+
36+
// Read config
37+
$v_config = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path);
38+
39+
// Render page
40+
render_page($user, $TAB, "edit_server_service");
41+
42+
// Flush session messages
43+
unset($_SESSION["error_msg"]);
44+
unset($_SESSION["ok_msg"]);

web/templates/pages/edit_server.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<a href="/edit/server/whitelabel/" class="button button-secondary">
1212
<i class="fas fa-paint-brush icon-blue"></i><?= _("White Label") ?>
1313
</a>
14+
<a href="/edit/server/hestiaweb/" class="button button-secondary">
15+
<i class="fas fa-clock icon-blue"></i><?= _("Panel Cronjobs") ?>
16+
</a>
1417
</div>
1518
<div class="toolbar-buttons">
1619
<button type="submit" class="button" form="main-form">

web/templates/pages/edit_server_service.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
<div class="toolbar">
33
<div class="toolbar-inner">
44
<div class="toolbar-buttons">
5+
<?php if($v_config_path == "/var/spool/cron/crontabs/hestiaweb"){
6+
?>
7+
<a class="button button-secondary button-back js-button-back" href="/edit/server/">
8+
<i class="fas fa-arrow-left icon-blue"></i><?= _("Back") ?>
9+
</a>
10+
<?php
11+
}else{
12+
?>
513
<a class="button button-secondary button-back js-button-back" href="/list/server/">
614
<i class="fas fa-arrow-left icon-blue"></i><?= _("Back") ?>
715
</a>
16+
<?php } ?>
817
</div>
918
<div class="toolbar-buttons">
1019
<button type="submit" class="button" form="main-form">

0 commit comments

Comments
 (0)