diff --git a/bin/v_change_cron_job b/bin/v_change_cron_job index 2183fefa..b7280965 100755 --- a/bin/v_change_cron_job +++ b/bin/v_change_cron_job @@ -43,14 +43,14 @@ is_object_valid 'cron' 'JOB' "$job" # Concatenating cron string command=$(echo $command | sed -e "s/'/%quote%/g" -e "s/:/%dots%/g") -str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month WDAY='$wday'" -str="$v_str' CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'" +str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'" +str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'" # Deleting old job sed -i "/JOB='$job' /d" $USER_DATA/cron.conf # Adding new -echo "$v_str" >> $USER_DATA/cron.conf +echo "$str" >> $USER_DATA/cron.conf # Sorting jobs by id sort_cron_jobs diff --git a/bin/v_list_cron_job b/bin/v_list_cron_job new file mode 100755 index 00000000..3e9488be --- /dev/null +++ b/bin/v_list_cron_job @@ -0,0 +1,91 @@ +#!/bin/bash +# info: list cron job +# options: user job [format] +# +# The function of obtaining cron job settings. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 +job=$2 +format=${3-shell} + +# Includes +source $VESTA/func/main.sh + +# Json function +json_list_job() { + i=1 + fileds_count=$(echo "$fields" | wc -w) + line=$(grep "JOB='$job'" $conf) + echo '{' + eval $line + for field in $fields; do + eval value=$field + value=$(echo "$value"|sed -e 's/"/\\"/g' -e "s/%quote%/'/g") + if [ "$i" -eq 1 ]; then + echo -e "\t\"$value\": {" + else + if [ "$fileds_count" -eq "$i" ]; then + echo -e "\t\t\"${field//$/}\": \"$value\"" + else + echo -e "\t\t\"${field//$/}\": \"$value\"," + fi + fi + (( ++i)) + done + if [ -n "$value" ]; then + echo -e ' }' + fi + echo -e "}" +} + +# Shell function +shell_list_job() { + line=$(grep "JOB='$job'" $conf) + eval $line + for field in $fields; do + eval key="$field" + if [ -z "$key" ]; then + key=NULL + fi + echo "${field//$/}: $key " + done +} + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '2' "$#" 'user job [format]' +is_object_valid 'user' 'USER' "$user" + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Defining config and fields to select +conf=$USER_DATA/cron.conf +fields="\$JOB \$MIN \$HOUR \$DAY \$MONTH \$WDAY \$CMD \$SUSPENDED" +fields="$fields \$TIME \$DATE" + +# Listing domains +case $format in + json) json_list_job ;; + plain) nohead=1; shell_list_job ;; + shell) shell_list_job |column -t ;; + *) check_args '2' '0' 'user job [format]' +esac + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v_list_cron_jobs b/bin/v_list_cron_jobs index 990e9a74..944bada2 100755 --- a/bin/v_list_cron_jobs +++ b/bin/v_list_cron_jobs @@ -83,7 +83,7 @@ is_object_valid 'user' 'USER' "$user" conf=$USER_DATA/cron.conf # Defining fileds to select -fields='$JOB $MIN $HOUR $DAY $MONTH $WDAY $CMD $SUSPENDED $TIME $DATE' +fields='$JOB $MIN $HOUR $DAY $MONTH $WDAY $CMD $JOB $SUSPENDED $TIME $DATE' # Listing domains case $format in diff --git a/web/delete/cron/index.php b/web/delete/cron/index.php new file mode 100644 index 00000000..c99c4efe --- /dev/null +++ b/web/delete/cron/index.php @@ -0,0 +1,17 @@ +', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } else { + $data = json_decode(implode('', $output), true); + unset($output); + $v_username = $user; + $v_job = $_GET['job']; + $v_min = $data[$v_job]['MIN']; + $v_hour = $data[$v_job]['HOUR']; + $v_day = $data[$v_job]['DAY']; + $v_month = $data[$v_job]['MONTH']; + $v_wday = $data[$v_job]['WDAY']; + $v_cmd = $data[$v_job]['CMD']; + $v_date = $data[$v_job]['DATE']; + $v_time = $data[$v_job]['TIME']; + $v_suspended = $data[$v_job]['SUSPENDED']; + if ( $v_suspended == 'yes' ) { + $v_status = 'suspended'; + } else { + $v_status = 'active'; + } + + // Action + if (!empty($_POST['save'])) { + $v_username = $user; + // Change job + if (($v_min != $_POST['v_min']) || ($v_hour != $_POST['v_hour']) || ($v_day != $_POST['v_day']) || ($v_month != $_POST['v_month']) || ($v_wday != $_POST['v_wday']) || ($v_cmd != $_POST['v_cmd']) &&(empty($_SESSION['error_msg']))) { + $v_min = escapeshellarg($_POST['v_min']); + $v_hour = escapeshellarg($_POST['v_hour']); + $v_day = escapeshellarg($_POST['v_day']); + $v_month = escapeshellarg($_POST['v_month']); + $v_wday = escapeshellarg($_POST['v_wday']); + $v_cmd = escapeshellarg($_POST['v_cmd']); + exec (VESTA_CMD."v_change_cron_job ".$v_username." ".$v_job." ".$v_min." ".$v_hour." ".$v_day." ".$v_month." ".$v_wday." ".$v_cmd, $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $v_cmd = $_POST['v_cmd']; + } + if (empty($_SESSION['error_msg'])) { + $_SESSION['ok_msg'] = "OK: changes has been saved."; + } + } + } + + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_cron.html'); + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_cron.html'); + unset($_SESSION['error_msg']); + unset($_SESSION['ok_msg']); +} + +// Footer +include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); diff --git a/web/suspend/cron/index.php b/web/suspend/cron/index.php new file mode 100644 index 00000000..eeeb0a6e --- /dev/null +++ b/web/suspend/cron/index.php @@ -0,0 +1,17 @@ +Day of Week Command - > diff --git a/web/templates/admin/edit_cron.html b/web/templates/admin/edit_cron.html new file mode 100644 index 00000000..6dece4f3 --- /dev/null +++ b/web/templates/admin/edit_cron.html @@ -0,0 +1,59 @@ + + + + + + + + +
+ + + + +
+
+ + +
+ + + + + + + + + + + +
Minute
Hour
Day
Month
Day of Week
Command
>
+ + +
+
diff --git a/web/templates/admin/list_cron.html b/web/templates/admin/list_cron.html index 5802a8bc..76943e05 100644 --- a/web/templates/admin/list_cron.html +++ b/web/templates/admin/list_cron.html @@ -5,10 +5,10 @@ foreach ($data as $key => $value) { ++$i; if ($data[$key]['SUSPENDED'] == 'yes') { $status = 'suspended'; - $spnd_action = 'ususpend' ; + $spnd_action = 'unsuspend' ; } else { $status = 'active'; - $spnd_action = 'suspend' ; + $spnd_action = 'suspend'; } if (empty($data[$key]['CATCHALL'])) { @@ -17,6 +17,45 @@ foreach ($data as $key => $value) { ?> + @@ -29,9 +68,21 @@ foreach ($data as $key => $value) {
- - - + + +
edit delete edit + + "> +
" title="Confirmation"> +

Are you sure you want to cron job?

+
+
+ + delete +
+

Are you sure you want to delete cron job?

+
+
diff --git a/web/templates/admin/menu_edit_cron.html b/web/templates/admin/menu_edit_cron.html new file mode 100644 index 00000000..16bf2612 --- /dev/null +++ b/web/templates/admin/menu_edit_cron.html @@ -0,0 +1,15 @@ +
+ + + + diff --git a/web/unsuspend/cron/index.php b/web/unsuspend/cron/index.php new file mode 100644 index 00000000..a23e1ff4 --- /dev/null +++ b/web/unsuspend/cron/index.php @@ -0,0 +1,17 @@ +