Skip to content

Commit 2c237a8

Browse files
committed
cron web pages
1 parent f14550a commit 2c237a8

File tree

11 files changed

+361
-10
lines changed

11 files changed

+361
-10
lines changed

bin/v_change_cron_job

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ is_object_valid 'cron' 'JOB' "$job"
4343

4444
# Concatenating cron string
4545
command=$(echo $command | sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
46-
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month WDAY='$wday'"
47-
str="$v_str' CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
46+
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
47+
str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
4848

4949
# Deleting old job
5050
sed -i "/JOB='$job' /d" $USER_DATA/cron.conf
5151

5252
# Adding new
53-
echo "$v_str" >> $USER_DATA/cron.conf
53+
echo "$str" >> $USER_DATA/cron.conf
5454

5555
# Sorting jobs by id
5656
sort_cron_jobs

bin/v_list_cron_job

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
# info: list cron job
3+
# options: user job [format]
4+
#
5+
# The function of obtaining cron job settings.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
job=$2
15+
format=${3-shell}
16+
17+
# Includes
18+
source $VESTA/func/main.sh
19+
20+
# Json function
21+
json_list_job() {
22+
i=1
23+
fileds_count=$(echo "$fields" | wc -w)
24+
line=$(grep "JOB='$job'" $conf)
25+
echo '{'
26+
eval $line
27+
for field in $fields; do
28+
eval value=$field
29+
value=$(echo "$value"|sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
30+
if [ "$i" -eq 1 ]; then
31+
echo -e "\t\"$value\": {"
32+
else
33+
if [ "$fileds_count" -eq "$i" ]; then
34+
echo -e "\t\t\"${field//$/}\": \"$value\""
35+
else
36+
echo -e "\t\t\"${field//$/}\": \"$value\","
37+
fi
38+
fi
39+
(( ++i))
40+
done
41+
if [ -n "$value" ]; then
42+
echo -e ' }'
43+
fi
44+
echo -e "}"
45+
}
46+
47+
# Shell function
48+
shell_list_job() {
49+
line=$(grep "JOB='$job'" $conf)
50+
eval $line
51+
for field in $fields; do
52+
eval key="$field"
53+
if [ -z "$key" ]; then
54+
key=NULL
55+
fi
56+
echo "${field//$/}: $key "
57+
done
58+
}
59+
60+
61+
#----------------------------------------------------------#
62+
# Verifications #
63+
#----------------------------------------------------------#
64+
65+
check_args '2' "$#" 'user job [format]'
66+
is_object_valid 'user' 'USER' "$user"
67+
68+
69+
#----------------------------------------------------------#
70+
# Action #
71+
#----------------------------------------------------------#
72+
73+
# Defining config and fields to select
74+
conf=$USER_DATA/cron.conf
75+
fields="\$JOB \$MIN \$HOUR \$DAY \$MONTH \$WDAY \$CMD \$SUSPENDED"
76+
fields="$fields \$TIME \$DATE"
77+
78+
# Listing domains
79+
case $format in
80+
json) json_list_job ;;
81+
plain) nohead=1; shell_list_job ;;
82+
shell) shell_list_job |column -t ;;
83+
*) check_args '2' '0' 'user job [format]'
84+
esac
85+
86+
87+
#----------------------------------------------------------#
88+
# Vesta #
89+
#----------------------------------------------------------#
90+
91+
exit

bin/v_list_cron_jobs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ is_object_valid 'user' 'USER' "$user"
8383
conf=$USER_DATA/cron.conf
8484

8585
# Defining fileds to select
86-
fields='$JOB $MIN $HOUR $DAY $MONTH $WDAY $CMD $SUSPENDED $TIME $DATE'
86+
fields='$JOB $MIN $HOUR $DAY $MONTH $WDAY $CMD $JOB $SUSPENDED $TIME $DATE'
8787

8888
# Listing domains
8989
case $format in

web/delete/cron/index.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
7+
8+
if ($_SESSION['user'] == 'admin') {
9+
if (!empty($_GET['job'])) {
10+
$v_username = escapeshellarg($user);
11+
$v_job = escapeshellarg($_GET['job']);
12+
exec (VESTA_CMD."v_delete_cron_job ".$v_username." ".$v_job, $output, $return_var);
13+
unset($output);
14+
}
15+
}
16+
17+
header("Location: /list/cron/");

web/edit/cron/index.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
7+
$TAB = 'CRON';
8+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
9+
10+
// Header
11+
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
12+
13+
// Panel
14+
top_panel($user,$TAB);
15+
16+
// Are you admin?
17+
if ($_SESSION['user'] == 'admin') {
18+
19+
// Check user argument?
20+
if (empty($_GET['job'])) {
21+
header("Location: /list/cron/");
22+
exit;
23+
}
24+
25+
$v_job = escapeshellarg($_GET['job']);
26+
exec (VESTA_CMD."v_list_cron_job ".$user." ".$v_job." 'json'", $output, $return_var);
27+
if ($return_var != 0) {
28+
$error = implode('<br>', $output);
29+
if (empty($error)) $error = 'Error: vesta did not return any output.';
30+
$_SESSION['error_msg'] = $error;
31+
} else {
32+
$data = json_decode(implode('', $output), true);
33+
unset($output);
34+
$v_username = $user;
35+
$v_job = $_GET['job'];
36+
$v_min = $data[$v_job]['MIN'];
37+
$v_hour = $data[$v_job]['HOUR'];
38+
$v_day = $data[$v_job]['DAY'];
39+
$v_month = $data[$v_job]['MONTH'];
40+
$v_wday = $data[$v_job]['WDAY'];
41+
$v_cmd = $data[$v_job]['CMD'];
42+
$v_date = $data[$v_job]['DATE'];
43+
$v_time = $data[$v_job]['TIME'];
44+
$v_suspended = $data[$v_job]['SUSPENDED'];
45+
if ( $v_suspended == 'yes' ) {
46+
$v_status = 'suspended';
47+
} else {
48+
$v_status = 'active';
49+
}
50+
51+
// Action
52+
if (!empty($_POST['save'])) {
53+
$v_username = $user;
54+
// Change job
55+
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']))) {
56+
$v_min = escapeshellarg($_POST['v_min']);
57+
$v_hour = escapeshellarg($_POST['v_hour']);
58+
$v_day = escapeshellarg($_POST['v_day']);
59+
$v_month = escapeshellarg($_POST['v_month']);
60+
$v_wday = escapeshellarg($_POST['v_wday']);
61+
$v_cmd = escapeshellarg($_POST['v_cmd']);
62+
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);
63+
if ($return_var != 0) {
64+
$error = implode('<br>', $output);
65+
if (empty($error)) $error = 'Error: vesta did not return any output.';
66+
$_SESSION['error_msg'] = $error;
67+
}
68+
unset($output);
69+
$v_cmd = $_POST['v_cmd'];
70+
}
71+
if (empty($_SESSION['error_msg'])) {
72+
$_SESSION['ok_msg'] = "OK: changes has been saved.";
73+
}
74+
}
75+
}
76+
77+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_cron.html');
78+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_cron.html');
79+
unset($_SESSION['error_msg']);
80+
unset($_SESSION['ok_msg']);
81+
}
82+
83+
// Footer
84+
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

web/suspend/cron/index.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
7+
8+
if ($_SESSION['user'] == 'admin') {
9+
if (!empty($_GET['job'])) {
10+
$v_username = escapeshellarg($user);
11+
$v_job = escapeshellarg($_GET['job']);
12+
exec (VESTA_CMD."v_suspend_cron_job ".$v_username." ".$v_job, $output, $return_var);
13+
unset($output);
14+
}
15+
}
16+
17+
header("Location: /list/cron/");

web/templates/admin/add_cron.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Day of Week</td></tr>
4646
<tr><td></span><input type="text" size="20" class="add-input" name="v_wday" <?php if (!empty($v_wday)) echo "value=".$v_wday; ?>></tr>
4747
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Command</td></tr>
48-
<tr><td></span><input type="text" size="20" class="add-input" name="v_cmd" <?php if (!empty($v_cmd)) echo "value=".$v_cmd; ?>></tr>
48+
<tr><td></span><input type="text" size="20" class="add-input" name="v_cmd" <?php if (!empty($v_cmd)) echo "value='".$v_cmd."'"; ?>></tr>
4949

5050
<tr><td style="padding: 24px 0 0 0;">
5151
<input type="submit" name="ok" value="OK" class="add-button"></form>

web/templates/admin/edit_cron.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<script type="text/javascript">
2+
function elementHideShow(elementToHideOrShow) {
3+
var el = document.getElementById(elementToHideOrShow);
4+
if (el.style.display == "block") {
5+
el.style.display = "none";
6+
} else {
7+
el.style.display = "block";
8+
}
9+
}
10+
11+
function randomString() {
12+
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
13+
var string_length = 10;
14+
var randomstring = '';
15+
for (var i=0; i<string_length; i++) {
16+
var rnum = Math.floor(Math.random() * chars.length);
17+
randomstring += chars.substring(rnum,rnum+1);
18+
}
19+
document.v_add_user.v_password.value = randomstring;
20+
}
21+
</script>
22+
23+
24+
<table class='data'>
25+
<tr class="data-add">
26+
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
27+
<table class="data-col1">
28+
<tr><td style="padding: 20px 0 4px 4px;"><a class="data-date" ?><?php echo date("d M Y", strtotime($v_date))?></a></td></tr>
29+
<tr><td style="padding: 0 0 6px 4px;"><a class="data-date" ?><?php echo $v_time?></a></td></tr>
30+
<tr><td style="padding: 0 0 0 24px;" class="data-<?php echo $v_status ?>"><b><?php echo $v_status ?></b></td></tr>
31+
</table>
32+
</td>
33+
<td class="data-dotted" width="830px" style="vertical-align:top;">
34+
<table width="830px"><tr>
35+
<td></td>
36+
</tr></table>
37+
<table class="data-col2" width="600px">
38+
<form method="post" name="v_add_user">
39+
<tr><td class="add-text" style="padding: 10 0 0 2px;">Minute</td></tr>
40+
<tr><td><input type="text" size="20" class="add-input" name="v_min" <?php if (!empty($v_min)) echo "value=".$v_min; ?>></td></tr>
41+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Hour</td></tr>
42+
<tr><td></span><input type="text" size="20" class="add-input" name="v_hour" <?php if (!empty($v_hour)) echo "value=".$v_hour; ?>></tr>
43+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Day</td></tr>
44+
<tr><td></span><input type="text" size="20" class="add-input" name="v_day" <?php if (!empty($v_day)) echo "value=".$v_day; ?>></tr>
45+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Month</td></tr>
46+
<tr><td></span><input type="text" size="20" class="add-input" name="v_month" <?php if (!empty($v_month)) echo "value=".$v_month; ?>></tr>
47+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Day of Week</td></tr>
48+
<tr><td></span><input type="text" size="20" class="add-input" name="v_wday" <?php if (!empty($v_wday)) echo "value=".$v_wday; ?>></tr>
49+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Command</td></tr>
50+
<tr><td></span><input type="text" size="20" class="add-input" name="v_cmd" <?php if (!empty($v_cmd)) echo "value='".$v_cmd."'"; ?>></tr>
51+
52+
<tr><td style="padding: 24px 0 0 0;">
53+
<input type="submit" name="save" value="Save" class="add-button"></form>
54+
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/cron/'">
55+
</td></tr>
56+
</table>
57+
</td>
58+
</tr>
59+
</table>

web/templates/admin/list_cron.html

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
++$i;
66
if ($data[$key]['SUSPENDED'] == 'yes') {
77
$status = 'suspended';
8-
$spnd_action = 'ususpend' ;
8+
$spnd_action = 'unsuspend' ;
99
} else {
1010
$status = 'active';
11-
$spnd_action = 'suspend' ;
11+
$spnd_action = 'suspend';
1212
}
1313

1414
if (empty($data[$key]['CATCHALL'])) {
@@ -17,6 +17,45 @@
1717
?>
1818

1919
<tr class="data-row">
20+
<script type="text/javascript">
21+
$(function(){
22+
$('#<?php echo $spnd_action ?>_dialog_<?php echo "$i" ?>').dialog({
23+
modal: true,
24+
autoOpen: false,
25+
width: 360,
26+
buttons: {
27+
"Ok": function(event, ui) {
28+
location.href = '/<?php echo $spnd_action ?>/cron/?job=<?php echo $data[$key]['JOB']; ?>';
29+
},
30+
"Cancel": function() {
31+
$(this).dialog("close");
32+
}
33+
}
34+
});
35+
$('#<?php echo $spnd_action ?>_link_<?php echo "$i" ?>').click(function(){
36+
$('#<?php echo $spnd_action ?>_dialog_<?php echo "$i" ?>').dialog('open');
37+
return false;
38+
});
39+
40+
$('#delete_dialog_<?php echo "$i" ?>').dialog({
41+
modal: true,
42+
autoOpen: false,
43+
width: 360,
44+
buttons: {
45+
"Ok": function(event, ui) {
46+
location.href = '/delete/cron/?job=<?php echo $data[$key]['JOB']; ?>';
47+
},
48+
"Cancel": function() {
49+
$(this).dialog("close");
50+
}
51+
}
52+
});
53+
$('#delete_link_<?php echo "$i" ?>').click(function(){
54+
$('#delete_dialog_<?php echo "$i" ?>').dialog('open');
55+
return false;
56+
});
57+
});
58+
</script>
2059
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
2160
<table class="data-col1">
2261
<tr><td style="padding: 18 0 4 18;"><input type="checkbox" name="object" ></td></tr>
@@ -29,9 +68,21 @@
2968

3069
<table width="830px"><tr>
3170
<td></td>
32-
<td class="data-controls" width="50px"><img src="/images/edit.png" width="8px" height="8px"><a href="#"> edit</a></td>
33-
<td class="data-controls" width="80px"><img src="/images/suspend.png" width="7px" height="8px"><a href="#"> <?php echo $spnd_action ?></a></td>
34-
<td class="data-controls" width="70px"><img src="/images/delete.png" width="7px" height="7px"><a href="#"> delete</a></td>
71+
<td class="data-controls" width="50px"><img src="/images/edit.png" width="8px" height="8px"><a href="/edit/cron/?job=<?php echo $data[$key]['JOB'] ?>"> edit</a></td>
72+
<td class="data-controls" width="80px">
73+
<img src="/images/suspend.png" width="7px" height="8px">
74+
<a href="#" id="<?php echo $spnd_action ?>_link_<?php echo "$i" ?>"> <?php echo $spnd_action ?></a>
75+
<div id="<?php echo $spnd_action ?>_dialog_<?php echo "$i" ?>" title="Confirmation">
76+
<p class="counter-value">Are you sure you want to <?php echo $spnd_action ?> cron job?</p>
77+
</div>
78+
</td>
79+
<td class="data-controls" width="70px">
80+
<img src="/images/delete.png" width="7px" height="7px">
81+
<a href="#" id="delete_link_<?php echo $i ?>"> delete</a>
82+
<div id="delete_dialog_<?php echo $i ?>" title="Confirmation">
83+
<p class="counter-value">Are you sure you want to delete cron job?</p>
84+
</div>
85+
</td>
3586
</tr></table>
3687

3788
<table class="data-col2" width="800px">

0 commit comments

Comments
 (0)