cron web pages

This commit is contained in:
Serghey Rodin 2012-06-22 15:40:29 +03:00
commit 2c237a82dd
11 changed files with 361 additions and 10 deletions

View file

@ -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

91
bin/v_list_cron_job Executable file
View file

@ -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

View file

@ -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

17
web/delete/cron/index.php Normal file
View file

@ -0,0 +1,17 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if ($_SESSION['user'] == 'admin') {
if (!empty($_GET['job'])) {
$v_username = escapeshellarg($user);
$v_job = escapeshellarg($_GET['job']);
exec (VESTA_CMD."v_delete_cron_job ".$v_username." ".$v_job, $output, $return_var);
unset($output);
}
}
header("Location: /list/cron/");

84
web/edit/cron/index.php Normal file
View file

@ -0,0 +1,84 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
$TAB = 'CRON';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
// Check user argument?
if (empty($_GET['job'])) {
header("Location: /list/cron/");
exit;
}
$v_job = escapeshellarg($_GET['job']);
exec (VESTA_CMD."v_list_cron_job ".$user." ".$v_job." 'json'", $output, $return_var);
if ($return_var != 0) {
$error = implode('<br>', $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('<br>', $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');

View file

@ -0,0 +1,17 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if ($_SESSION['user'] == 'admin') {
if (!empty($_GET['job'])) {
$v_username = escapeshellarg($user);
$v_job = escapeshellarg($_GET['job']);
exec (VESTA_CMD."v_suspend_cron_job ".$v_username." ".$v_job, $output, $return_var);
unset($output);
}
}
header("Location: /list/cron/");

View file

@ -45,7 +45,7 @@
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Day of Week</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_wday" <?php if (!empty($v_wday)) echo "value=".$v_wday; ?>></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Command</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_cmd" <?php if (!empty($v_cmd)) echo "value=".$v_cmd; ?>></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_cmd" <?php if (!empty($v_cmd)) echo "value='".$v_cmd."'"; ?>></tr>
<tr><td style="padding: 24px 0 0 0;">
<input type="submit" name="ok" value="OK" class="add-button"></form>

View file

@ -0,0 +1,59 @@
<script type="text/javascript">
function elementHideShow(elementToHideOrShow) {
var el = document.getElementById(elementToHideOrShow);
if (el.style.display == "block") {
el.style.display = "none";
} else {
el.style.display = "block";
}
}
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 10;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
document.v_add_user.v_password.value = randomstring;
}
</script>
<table class='data'>
<tr class="data-add">
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
<table class="data-col1">
<tr><td style="padding: 20px 0 4px 4px;"><a class="data-date" ?><?php echo date("d M Y", strtotime($v_date))?></a></td></tr>
<tr><td style="padding: 0 0 6px 4px;"><a class="data-date" ?><?php echo $v_time?></a></td></tr>
<tr><td style="padding: 0 0 0 24px;" class="data-<?php echo $v_status ?>"><b><?php echo $v_status ?></b></td></tr>
</table>
</td>
<td class="data-dotted" width="830px" style="vertical-align:top;">
<table width="830px"><tr>
<td></td>
</tr></table>
<table class="data-col2" width="600px">
<form method="post" name="v_add_user">
<tr><td class="add-text" style="padding: 10 0 0 2px;">Minute</td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_min" <?php if (!empty($v_min)) echo "value=".$v_min; ?>></td></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Hour</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_hour" <?php if (!empty($v_hour)) echo "value=".$v_hour; ?>></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Day</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_day" <?php if (!empty($v_day)) echo "value=".$v_day; ?>></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Month</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_month" <?php if (!empty($v_month)) echo "value=".$v_month; ?>></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Day of Week</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_wday" <?php if (!empty($v_wday)) echo "value=".$v_wday; ?>></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Command</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_cmd" <?php if (!empty($v_cmd)) echo "value='".$v_cmd."'"; ?>></tr>
<tr><td style="padding: 24px 0 0 0;">
<input type="submit" name="save" value="Save" class="add-button"></form>
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/cron/'">
</td></tr>
</table>
</td>
</tr>
</table>

View file

@ -5,7 +5,7 @@ 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';
@ -17,6 +17,45 @@ foreach ($data as $key => $value) {
?>
<tr class="data-row">
<script type="text/javascript">
$(function(){
$('#<?php echo $spnd_action ?>_dialog_<?php echo "$i" ?>').dialog({
modal: true,
autoOpen: false,
width: 360,
buttons: {
"Ok": function(event, ui) {
location.href = '/<?php echo $spnd_action ?>/cron/?job=<?php echo $data[$key]['JOB']; ?>';
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
$('#<?php echo $spnd_action ?>_link_<?php echo "$i" ?>').click(function(){
$('#<?php echo $spnd_action ?>_dialog_<?php echo "$i" ?>').dialog('open');
return false;
});
$('#delete_dialog_<?php echo "$i" ?>').dialog({
modal: true,
autoOpen: false,
width: 360,
buttons: {
"Ok": function(event, ui) {
location.href = '/delete/cron/?job=<?php echo $data[$key]['JOB']; ?>';
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
$('#delete_link_<?php echo "$i" ?>').click(function(){
$('#delete_dialog_<?php echo "$i" ?>').dialog('open');
return false;
});
});
</script>
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
<table class="data-col1">
<tr><td style="padding: 18 0 4 18;"><input type="checkbox" name="object" ></td></tr>
@ -29,9 +68,21 @@ foreach ($data as $key => $value) {
<table width="830px"><tr>
<td></td>
<td class="data-controls" width="50px"><img src="/images/edit.png" width="8px" height="8px"><a href="#"> edit</a></td>
<td class="data-controls" width="80px"><img src="/images/suspend.png" width="7px" height="8px"><a href="#"> <?php echo $spnd_action ?></a></td>
<td class="data-controls" width="70px"><img src="/images/delete.png" width="7px" height="7px"><a href="#"> delete</a></td>
<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>
<td class="data-controls" width="80px">
<img src="/images/suspend.png" width="7px" height="8px">
<a href="#" id="<?php echo $spnd_action ?>_link_<?php echo "$i" ?>"> <?php echo $spnd_action ?></a>
<div id="<?php echo $spnd_action ?>_dialog_<?php echo "$i" ?>" title="Confirmation">
<p class="counter-value">Are you sure you want to <?php echo $spnd_action ?> cron job?</p>
</div>
</td>
<td class="data-controls" width="70px">
<img src="/images/delete.png" width="7px" height="7px">
<a href="#" id="delete_link_<?php echo $i ?>"> delete</a>
<div id="delete_dialog_<?php echo $i ?>" title="Confirmation">
<p class="counter-value">Are you sure you want to delete cron job?</p>
</div>
</td>
</tr></table>
<table class="data-col2" width="800px">

View file

@ -0,0 +1,15 @@
<table class="sub-menu">
<tr>
<td style="padding: 10px 2px 28px 0;" ><a class="add-name"><b>Editing Cron Job</b></a>
<?php
if (!empty($_SESSION['error_msg'])) {
echo "<a class=\"add-error\"> → ".$_SESSION['error_msg']."</a>";
} else {
if (!empty($_SESSION['ok_msg'])) {
echo "<a class=\"add-ok\"> → ".$_SESSION['ok_msg']."</a>";
}
}
?>
</td>
</tr>
</table>

View file

@ -0,0 +1,17 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if ($_SESSION['user'] == 'admin') {
if (!empty($_GET['job'])) {
$v_username = escapeshellarg($user);
$v_job = escapeshellarg($_GET['job']);
exec (VESTA_CMD."v_unsuspend_cron_job ".$v_username." ".$v_job, $output, $return_var);
unset($output);
}
}
header("Location: /list/cron/");