Просмотр исходного кода

Allow admin to change panel cronjobs (#3974)

* Fix permissions issues with cron not running

* Allow  admin to change panel cronjobs

* Fix back link
Jaap Marcus 2 лет назад
Родитель
Сommit
5c43ae42be

+ 1 - 0
bin/v-change-sys-service-config

@@ -73,6 +73,7 @@ case $service in
 	clamd) dst=$($BIN/v-list-sys-clamd-config plain) ;;
 	fail2ban) dst='/etc/fail2ban/jail.local' ;;
 	ssh) dst='/etc/ssh/sshd_config' ;;
+	hestiaweb) dst='/var/spool/cron/crontabs/hestiaweb' ;;
 	*) check_result $E_NOTEXIST "service $service doesn't exist" ;;
 esac
 

+ 2 - 2
bin/v-open-fs-config

@@ -37,13 +37,13 @@ if [ -n "$src_file" ]; then
 	rpath=$(readlink -f "$src_file")
 	services="nginx|apache|httpd|php|ftp|bind|named|exim|dovecot|spamassassin"
 	services="$services|clam|mysql|postgresql|pgsql|cron|ssh|fail2ban|iptables"
-	services="$services|my.cnf"
+	services="$services|my.cnf|hestiaweb"
 	spath=$(echo "$rpath" | egrep "$services")
 	if [ -z "$spath" ]; then
 		echo "Error: invalid source path $src_file"
 		exit 2
 	fi
-	spath=$(echo "$rpath" | egrep "/etc|/var/lib")
+	spath=$(echo "$rpath" | egrep "/etc|/var/lib|/var/spool/cron/")
 	if [ -z "$spath" ]; then
 		echo "Error: invalid source path $src_file"
 		exit 2

+ 3 - 0
install/hst-install-debian.sh

@@ -2283,6 +2283,9 @@ echo "*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-rrd" >> /var/spool/cro
 echo "$min $hour * * * sudo /usr/local/hestia/bin/v-update-letsencrypt-ssl" >> /var/spool/cron/crontabs/hestiaweb
 echo "41 4 * * * sudo /usr/local/hestia/bin/v-update-sys-hestia-all" >> /var/spool/cron/crontabs/hestiaweb
 
+chmod 600 /var/spool/cron/crontabs/hestiaweb
+chown hestiaweb:hestiaweb /var/spool/cron/crontabs/hestiaweb
+
 # Enable automatic updates
 $HESTIA/bin/v-add-cron-hestia-autoupdate apt
 

+ 3 - 0
install/hst-install-ubuntu.sh

@@ -2242,6 +2242,9 @@ echo "*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-rrd" >> /var/spool/cro
 echo "$min $hour * * * sudo /usr/local/hestia/bin/v-update-letsencrypt-ssl" >> /var/spool/cron/crontabs/hestiaweb
 echo "41 4 * * * sudo /usr/local/hestia/bin/v-update-sys-hestia-all" >> /var/spool/cron/crontabs/hestiaweb
 
+chmod 600 /var/spool/cron/crontabs/hestiaweb
+chown hestiaweb:hestiaweb /var/spool/cron/crontabs/hestiaweb
+
 # Enable automatic updates
 $HESTIA/bin/v-add-cron-hestia-autoupdate apt
 

+ 4 - 0
install/upgrade/versions/1.9.0.sh

@@ -65,6 +65,10 @@ if [ ! -f "/var/spool/cron/crontabs/hestiaweb" ]; then
 			$BIN/v-delete-cron-job admin "$JOB"
 		fi
 	done < $HESTIA/data/users/admin/cron.conf
+	# Update permissions
+	chmod 600 /var/spool/cron/crontabs/hestiaweb
+	chown hestiaweb:hestiaweb /var/spool/cron/crontabs/hestiaweb
+
 fi
 
 chown hestiaweb:hestiaweb /usr/local/hestia/data/sessions

+ 44 - 0
web/edit/server/hestiaweb/index.php

@@ -0,0 +1,44 @@
+<?php
+
+$TAB = "SERVER";
+
+// Main include
+include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
+
+// Check user
+if ($_SESSION["userContext"] !== "admin" && $user_plain === "$ROOT_USER") {
+	header("Location: /list/user");
+	exit();
+}
+
+// Check POST request
+if (!empty($_POST["save"])) {
+	if (!empty($_POST["v_config"])) {
+		exec("mktemp", $mktemp_output, $return_var);
+		$new_conf = $mktemp_output[0];
+		$fp = fopen($new_conf, "w");
+		fwrite($fp, str_replace("\r\n", "\n", $_POST["v_config"]));
+		fclose($fp);
+		exec(
+			HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " hestiaweb no",
+			$output,
+			$return_var,
+		);
+		check_return_code($return_var, $output);
+		unset($output);
+		unlink($new_conf);
+	}
+}
+
+$v_config_path = "/var/spool/cron/crontabs/hestiaweb";
+$v_service_name = _("Panel Cronjobs");
+
+// Read config
+$v_config = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path);
+
+// Render page
+render_page($user, $TAB, "edit_server_service");
+
+// Flush session messages
+unset($_SESSION["error_msg"]);
+unset($_SESSION["ok_msg"]);

+ 3 - 0
web/templates/pages/edit_server.php

@@ -11,6 +11,9 @@
 			<a href="/edit/server/whitelabel/" class="button button-secondary">
 				<i class="fas fa-paint-brush icon-blue"></i><?= _("White Label") ?>
 			</a>
+			<a href="/edit/server/hestiaweb/" class="button button-secondary">
+				<i class="fas fa-clock icon-blue"></i><?= _("Panel Cronjobs") ?>
+			</a>
 		</div>
 		<div class="toolbar-buttons">
 			<button type="submit" class="button" form="main-form">

+ 9 - 0
web/templates/pages/edit_server_service.php

@@ -2,9 +2,18 @@
 <div class="toolbar">
 	<div class="toolbar-inner">
 		<div class="toolbar-buttons">
+			<?php if($v_config_path == "/var/spool/cron/crontabs/hestiaweb"){
+				?>
+				<a class="button button-secondary button-back js-button-back" href="/edit/server/">
+					<i class="fas fa-arrow-left icon-blue"></i><?= _("Back") ?>
+				</a>
+			<?php
+			}else{
+				?>
 			<a class="button button-secondary button-back js-button-back" href="/list/server/">
 				<i class="fas fa-arrow-left icon-blue"></i><?= _("Back") ?>
 			</a>
+			<?php } ?>
 		</div>
 		<div class="toolbar-buttons">
 			<button type="submit" class="button" form="main-form">