Skip to content

Commit f14550a

Browse files
committed
cron add page
1 parent d218e55 commit f14550a

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed

web/add/cron/index.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
// Init
3+
//error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
$TAB = 'CRON';
7+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
8+
9+
// Header
10+
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
11+
12+
// Panel
13+
top_panel($user,$TAB);
14+
15+
// Are you admin?
16+
if ($_SESSION['user'] == 'admin') {
17+
if (!empty($_POST['ok'])) {
18+
// Check input
19+
if (empty($_POST['v_min'])) $errors[] = 'minute';
20+
if (empty($_POST['v_hour'])) $errors[] = 'hour';
21+
if (empty($_POST['v_day'])) $errors[] = 'day';
22+
if (empty($_POST['v_month'])) $errors[] = 'month';
23+
if (empty($_POST['v_wday'])) $errors[] = 'day of week';
24+
if (empty($_POST['v_cmd'])) $errors[] = 'cmd';
25+
26+
// Protect input
27+
$v_min = escapeshellarg($_POST['v_min']);
28+
$v_hour = escapeshellarg($_POST['v_hour']);
29+
$v_day = escapeshellarg($_POST['v_day']);
30+
$v_month = escapeshellarg($_POST['v_month']);
31+
$v_wday = escapeshellarg($_POST['v_wday']);
32+
$v_cmd = escapeshellarg($_POST['v_cmd']);
33+
34+
// Check for errors
35+
if (!empty($errors[0])) {
36+
foreach ($errors as $i => $error) {
37+
if ( $i == 0 ) {
38+
$error_msg = $error;
39+
} else {
40+
$error_msg = $error_msg.", ".$error;
41+
}
42+
}
43+
$_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
44+
} else {
45+
// Add Cron Job
46+
exec (VESTA_CMD."v_add_cron_job ".$user." ".$v_min." ".$v_hour." ".$v_day." ".$v_month." ".$v_wday." ".$v_cmd, $output, $return_var);
47+
$v_type = $_POST['v_type'];
48+
$v_charset = $_POST['v_charset'];
49+
if ($return_var != 0) {
50+
$error = implode('<br>', $output);
51+
if (empty($error)) $error = 'Error: vesta did not return any output.';
52+
$_SESSION['error_msg'] = $error;
53+
unset($v_password);
54+
unset($output);
55+
} else {
56+
$_SESSION['ok_msg'] = "OK: cron job has been created successfully.";
57+
unset($v_min);
58+
unset($v_hour);
59+
unset($v_day);
60+
unset($v_month);
61+
unset($v_wday);
62+
unset($v_cmd);
63+
unset($output);
64+
}
65+
}
66+
}
67+
exec (VESTA_CMD."v_list_database_types 'json'", $output, $return_var);
68+
$db_types = json_decode(implode('', $output), true);
69+
unset($output);
70+
71+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_cron.html');
72+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_cron.html');
73+
unset($_SESSION['error_msg']);
74+
unset($_SESSION['ok_msg']);
75+
}
76+
77+
// Footer
78+
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

web/templates/admin/add_cron.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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: 18 0 4 18;"></td></tr>
29+
</table>
30+
</td>
31+
<td class="data-dotted" width="830px" style="vertical-align:top;">
32+
<table width="830px"><tr>
33+
<td></td>
34+
</tr></table>
35+
<table class="data-col2" width="600px">
36+
<form method="post" name="v_add_user">
37+
<tr><td class="add-text" style="padding: 10 0 0 2px;">Minute</td></tr>
38+
<tr><td><input type="text" size="20" class="add-input" name="v_min" <?php if (!empty($v_min)) echo "value=".$v_min; ?>></td></tr>
39+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Hour</td></tr>
40+
<tr><td></span><input type="text" size="20" class="add-input" name="v_hour" <?php if (!empty($v_hour)) echo "value=".$v_hour; ?>></tr>
41+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Day</td></tr>
42+
<tr><td></span><input type="text" size="20" class="add-input" name="v_day" <?php if (!empty($v_day)) echo "value=".$v_day; ?>></tr>
43+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Month</td></tr>
44+
<tr><td></span><input type="text" size="20" class="add-input" name="v_month" <?php if (!empty($v_month)) echo "value=".$v_month; ?>></tr>
45+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Day of Week</td></tr>
46+
<tr><td></span><input type="text" size="20" class="add-input" name="v_wday" <?php if (!empty($v_wday)) echo "value=".$v_wday; ?>></tr>
47+
<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>
49+
50+
<tr><td style="padding: 24px 0 0 0;">
51+
<input type="submit" name="ok" value="OK" class="add-button"></form>
52+
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/cron/'">
53+
</td></tr>
54+
</table>
55+
</td>
56+
</tr>
57+
</table>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<table class="sub-menu">
2+
<tr>
3+
<td style="padding: 10px 2px 28px 0;" ><a class="add-name"><b>Adding Cron Job</b></a>
4+
<?php
5+
if (!empty($_SESSION['error_msg'])) {
6+
echo "<a class=\"add-error\"> → ".$_SESSION['error_msg']."</a>";
7+
} else {
8+
if (!empty($_SESSION['ok_msg'])) {
9+
echo "<a class=\"add-ok\"> → ".$_SESSION['ok_msg']."</a>";
10+
}
11+
}
12+
?>
13+
</td>
14+
</tr>
15+
</table>

0 commit comments

Comments
 (0)