Serghey Rodin 12 lat temu
rodzic
commit
44d907f202

+ 79 - 0
bin/v-add-cron-vesta-autoupdate

@@ -0,0 +1,79 @@
+#!/bin/bash
+# info: add cron job for vesta autoupdates
+# options: NONE
+#
+# The function adds cronjob for vesta autoupdate.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument defenition
+user=admin
+
+# Includes
+source $VESTA/func/main.sh
+source $VESTA/conf/vesta.conf
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
+is_package_full 'CRON_JOBS'
+get_next_cronjob
+check_cron=$(grep 'v-update-sys-vesta-all' $USER_DATA/cron.conf)
+if [ ! -z "$check_cron" ]; then
+    exit
+fi
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Define time somewhere at nigth
+min=$(gen_password '012345' '2')
+hour=$(gen_password '1234567' '1')
+day='*'
+month='*'
+WDAY='*'
+command='sudo /usr/local/vesta/bin/v-update-sys-vesta-all'
+
+# Concatenating cron string
+str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
+str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
+
+# Adding to crontab
+echo "$str" >> $VESTA/data/users/$user/cron.conf
+
+# Chaning permissions
+chmod 660 $VESTA/data/users/$user/cron.conf
+
+# Sort jobs by id number
+sort_cron_jobs
+
+# Sync cronjobs with system crond
+sync_cron_jobs
+
+
+#----------------------------------------------------------#
+#                       Vesta                              #
+#----------------------------------------------------------#
+
+# Increasing cron value
+increase_user_value $user '$U_CRON_JOBS'
+
+# Restart crond
+$BIN/v-restart-cron
+if [ $? -ne 0 ]; then
+    exit $E_RESTART
+fi
+
+# Logging
+log_history "added cron job $job"
+log_event "$OK" "$EVENT"
+
+exit

+ 63 - 0
bin/v-delete-cron-vesta-autoupdate

@@ -0,0 +1,63 @@
+#!/bin/bash
+# info: delete vesta autoupdate cron job
+# options: NONE
+#
+# The function deletes vesta autoupdate cron job.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument defenition
+user=admin
+
+# Includes
+source $VESTA/func/main.sh
+source $VESTA/conf/vesta.conf
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
+check_cron=$(grep 'v-update-sys-vesta-all' $USER_DATA/cron.conf)
+if [ -z "$check_cron" ]; then
+    exit
+fi
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+
+# Deleting job
+job=$(echo $check_cron|tr ' ' "\n"|grep JOB|cut -f 2 -d "'")
+sed -i "/JOB='$job' /d" $USER_DATA/cron.conf
+
+# Sorting jobs by id
+sort_cron_jobs
+
+# Sync system cron with user
+sync_cron_jobs
+
+
+#----------------------------------------------------------#
+#                       Vesta                              #
+#----------------------------------------------------------#
+
+# Decreasing cron value
+decrease_user_value "$user" '$U_CRON_JOBS'
+
+# Restart crond
+$BIN/v-restart-cron
+if [ $? -ne 0 ]; then
+    exit $E_RESTART
+fi
+
+# Logging
+log_event "$OK" "$EVENT"
+
+exit

+ 64 - 0
bin/v-list-sys-vesta-autoupdate

@@ -0,0 +1,64 @@
+#!/bin/bash
+# info: list vesta autoupdate settings
+# options: NONE
+#
+# The function for obtaining autoupdate setings.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument defenition
+user='admin'
+format=${1-shell}
+
+# Includes
+source $VESTA/func/main.sh
+
+# Json function
+json_list_autoupdate() {
+    echo '['
+    if [ -z "$check_cron" ]; then
+        echo -e  "\t\"Disabled\","
+    else
+        echo -e  "\t\"Enabled\""
+    fi
+    echo "]"
+}
+
+# Shell function
+shell_list_autoupdate() {
+    if [ -z "$nohead" ]; then
+        echo "AUTOUPDATE"
+        echo "----------"
+    fi
+    if [ -z "$check_cron" ]; then
+        echo "Disabled"
+    else
+        echo "Enabled"
+    fi
+}
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Check cron tab
+check_cron=$(grep 'v-update-sys-vesta-all' $USER_DATA/cron.conf)
+
+# Listing domains
+case $format in 
+    json)   json_list_autoupdate ;;
+    plain)  nohead=1; shell_list_autoupdate ;;
+    shell)  shell_list_autoupdate ;;
+    *)      check_args '1' '0' '[FORMAT]' ;;
+esac
+
+
+#----------------------------------------------------------#
+#                       Vesta                              #
+#----------------------------------------------------------#
+
+exit

+ 30 - 0
bin/v-update-sys-vesta-all

@@ -0,0 +1,30 @@
+#!/bin/bash
+# info: update all vesta packages
+# options: USER [RESTART]
+#
+# The function of updating all vesta packages
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Includes
+source $VESTA/func/main.sh
+source $VESTA/conf/vesta.conf
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Starting update loop
+for package in vesta vesta-ngin vesta-php; do
+    $BIN/v-update-sys-vesta "$package"
+done
+
+#----------------------------------------------------------#
+#                       Vesta                              #
+#----------------------------------------------------------#
+
+exit

+ 15 - 0
web/add/cron/autoupdate/index.php

@@ -0,0 +1,15 @@
+<?php
+// Init
+error_reporting(NULL);
+ob_start();
+session_start();
+include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
+
+if ($_SESSION['user'] == 'admin') {
+    exec (VESTA_CMD."v-add-cron-vesta-autoupdate", $output, $return_var);
+    $_SESSION['error_msg'] = __('Autoupdate has been susscessfully enabled');
+    unset($output);
+}
+
+header("Location: /list/updates/");
+exit;

+ 15 - 0
web/delete/cron/autoupdate/index.php

@@ -0,0 +1,15 @@
+<?php
+// Init
+error_reporting(NULL);
+ob_start();
+session_start();
+include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
+
+if ($_SESSION['user'] == 'admin') {
+    exec (VESTA_CMD."v-delete-cron-vesta-autoupdate", $output, $return_var);
+    $_SESSION['error_msg'] = __('Autoupdate has been susscessfully disabled');
+    unset($output);
+}
+
+header("Location: /list/updates/");
+exit;

+ 4 - 0
web/list/updates/index.php

@@ -16,6 +16,10 @@ if ($_SESSION['user'] == 'admin') {
     exec (VESTA_CMD."v-list-sys-vesta-updates json", $output, $return_var);
     $data = json_decode(implode('', $output), true);
     unset($output);
+    exec (VESTA_CMD."v-list-sys-vesta-autoupdate plain", $output, $return_var);
+    $autoupdate = $output['0'];
+    unset($output);
+
     include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_updates.html');
 }
 

+ 14 - 0
web/templates/admin/list_updates.html

@@ -1,3 +1,4 @@
+
             <table class="submenu">
                 <tr>
                     <td style="padding: 14px 10px">
@@ -16,6 +17,19 @@
                             </select>
                             <input type="submit" name="ok" value="›" class="submenu-button-select">
                         </div>
+                        <div class="submenu-select-block">
+                            <?php
+                                if($autoupdate == 'Enabled') {
+                            ?>
+                            <a class="submenu-select-link" href="/delete/cron/autoupdate/">[ <?php print __('disable autoupdate');?> ]</a>
+                            <?php
+                                } else {
+                            ?>
+                            <a class="submenu-select-link" href="/add/cron/autoupdate/">[ <?php print __('enable autoupdate');?> ]</a>
+                            <?php
+                                }
+                            ?>
+                        </div>
                         <?php display_error_block(); ?> 
                     </td>
                 </tr>