De
oude versie van de cronjob was best leuk, maar deze vind ik mooier... Hij staat al in principe ook al op die pagina, maar valt daar een beetje weg. In deze post is ook de beveiliging een tikje aangescherpt(op de hulppagina's)...
Zoals je ziet een wat andere lay-out en een paar extra schermen voor bewerken en een nieuwe job
De code:
Appication.cfg:
text = NewCron
description = NewCron
icon_16 = cron16.png
icon_32 = cron32.png
type = embedded
path = /phpsrc/newcron/cronjob.php
cronjob.php:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Cronjobs</title>
<style>body,input,select,option,td{font:11px Arial}body{background-color:#EEEEEE}legend{font-weight:bold;color:#15428b}fieldset{border:1px solid #bbb; padding:5px}a:hover,a:link,a:visited{color: #000;text-decoration:none}</style>
<script type="text/javascript" language="JavaScript">
function markCheckbox(state){
var checkboxes=document.getElementsByName('choicecron[]');
for(var n=0;n<checkboxes.length;n++){
checkboxes[n].checked=state;
}
}
function disp_confirm(){
var r=confirm("Are you sure you want to delete the selected job(s)?");
if (r==true){
document.cronindex.submit();
} else {
alert("Deletion aborted...");
}
}
function emptytest() {
message = 0;
nmbr = 0;
var checkboxes=document.getElementsByName('choicecron[]');
for(var n=0;n<checkboxes.length;n++){
if (checkboxes[n].checked == 1){
message=1;
nmbr++;
}
}
if (message == 0) {
switch(document.getElementById('action').value)
{
case 'delete':
alert("Please choose one or more jobs you want to delete");
break;
case 'enabledisable':
alert("Please choose one or more jobs you want to enable/disable");
break;
case 'changejob':
alert("Please choose a job you want to change");
break;
}
} else {
if (document.getElementById('action').value == 'delete') {
disp_confirm();
} else if (document.getElementById('action').value == 'changejob' && nmbr > 1) {
alert("You can change only one job at a time!");
} else {
document.cronindex.submit();
}
}
}
</script></head>
<?php
putenv('HTTP_COOKIE='.$_SERVER['HTTP_COOKIE']);
putenv('REMOTE_ADDR='.$_SERVER['REMOTE_ADDR']);
$user=exec('/usr/syno/synoman/webman/modules/authenticate.cgi');
if($user != 'admin'){
header("HTTP/1.0 403 Forbidden");
exit;
}
$lines=10;
if ($_REQUEST['action2'] == 'deletelog')
file_put_contents('/var/log/cron.log', '');
if ($_REQUEST['action2'] == 'refreshlog')
$lines=$_REQUEST['customlines'];
$crontabfile=file('/etc/crontab');
$t=count($crontabfile);
echo '<form name="cronindex" action="editcron.php" method="post">';
echo '<input type="hidden" id="action" name="action" value="">';
echo '<fieldset><legend>etc/crontab</legend>
<table width=100%" cellspacing=1" cellpadding="2" bgcolor="#eeeeee"><tr bgcolor="#cdcdcd">
<td width="30px" align="center"><input type="checkbox" title="Select/Deselect all" name="checkall" value="" onclick="markCheckbox(this.checked)" /></td><td width="60px"><b>Status</b></td><td><b>Who</b></td><td><b>Command</b></td><td><b>Description</b></td></tr>';
$z=0;
while ($z < $t){
foreach($crontabfile as $last) {
$command=explode(chr(9),$last);
$delete_change=implode(chr(9),$command);
if ($command[0]{0}=='#'){
$active='Stopped'; $cellcol="CC0000";}
else{$active='Running'; $cellcol="#006600";}
echo '<tr bgcolor="#e1e1e1">';
if ($command[0]=='#minute'){
echo '<td align="center" height=22">...</td><td>...</td><td>...</td><td>#minute hour mday month wday who command</td><td>Default header</td></tr>';
}
else{
$description = substr_replace($command[7], '', 0, 1);
echo '<td align="center" ><input type="checkbox" name="choicecron[]" value="'.$delete_change.'"></td><td><font color='.$cellcol.'>'.$active.'</font></td><td title="'.$delete_change.'">'.$command[5].'</td><td title="'.$delete_change.'">'.$command[6].'</td><td>'.$description.'</td></tr>';
}
$z++;
}
}
echo '</table></fieldset>';
//echo '<fieldset><legend>Actions</legend>';
echo '<input type="button" title="Delete selected job(s) and restart crond" value=" Delete job & Restart " onclick="document.getElementById('action').value='delete';emptytest()"/>';
echo '<input type="button" title="Enable or Disable selected job(s) and restart crond" value=" Enable/Disable & Restart " style="margin-left:3px" onclick="document.getElementById('action').value='enabledisable';emptytest()"/>';
echo '<input type="button" title="Edit selected job" value=" Edit selected job " style="margin-left:3px" onclick="document.getElementById('action').value='changejob';emptytest()"/>';
echo '<input type="button" title="Create a new cronjob" value=" Set new job " style="margin-left:3px" onclick="window.location='newcron.php'">';
echo '</fieldset></form>';
echo '<fieldset><legend>/var/log/cron.log</legend>';
$logread=exec('tail -'.$lines.' /var/log/cron.log', $cronlog);
$cl=count($cronlog);
echo '<table width=100%" cellspacing=0" cellpadding="1" bgcolor="#e1e1e1">';
for ($i=0;$i<$cl;$i++){
echo '<tr><td>'.$cronlog[$i].'</td></tr><tr>';
}
echo '</tr></table></fieldset>';
echo '<form name="cronlog" action="cronjob.php" method="post">';
echo '<input type="hidden" id="log" name="action2" value="">';
echo '<fieldset><legend>Actions</legend>';
echo '<input type="button" title="Delete cron.log file" value=" Delete Log " onclick="document.getElementById('log').value='deletelog';submit()"/>';
echo '<input type="button" title="Refresh cron.log" value=" Refresh Log " style="margin-left:3px" onclick="document.getElementById('log').value='refreshlog';submit()"/>';
echo '<input type="text" name="customlines" size="1" value="'.$lines.'" style="margin-left:5px"> Lines</input>';
echo '</input>';
echo '</fieldset></form>';
if ($empty==1){
echo '<font color="#ff0000"><b> Please select a job to edit (Multiple choice is impossible).</b></font>';
}
?>
newcron.php:
<?php
putenv('HTTP_COOKIE='.$_SERVER['HTTP_COOKIE']);
putenv('REMOTE_ADDR='.$_SERVER['REMOTE_ADDR']);
$user=exec('/usr/syno/synoman/webman/modules/authenticate.cgi');
if($user != 'admin'){
header("HTTP/1.0 403 Forbidden");
exit;
}
?>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Cronjobs</title>
<style>body,input,select,option,td{font:11px Arial}body{background-color:#EEEEEE}legend{font-weight:bold;color:#15428b}fieldset{border:1px solid #bbb; padding:5px}a:hover,a:link,a:visited{color: #000;text-decoration:none}</style>
<script language="JavaScript" type="text/javascript">
function makeminDisable()
{
for( var i=1; i<6; i++ ){
document.getElementById('min' +i).disabled=true;
}
}
function makeminEnable()
{
for( var i=1; i<6; i++ ){
document.getElementById('min' +i).disabled=false;
}
}
function makehourDisable()
{
for( var i=1; i<3; i++ ){
document.getElementById('hour' +i).disabled=true;
}
}
function makehourEnable()
{
for( var i=1; i<3; i++ ){
document.getElementById('hour' +i).disabled=false;
}
}
function makedayDisable()
{
for( var i=1; i<4; i++ ){
document.getElementById('day' +i).disabled=true;
}
}
function makedayEnable()
{
for( var i=1; i<4; i++ ){
document.getElementById('day' +i).disabled=false;
}
}
function makemonDisable()
{
document.getElementById('mon').disabled=true;
}
function makemonEnable()
{
document.getElementById('mon').disabled=false;
}
function makeweekdayDisable()
{
document.getElementById('wday').disabled=true;
}
function makeweekdayEnable()
{
document.getElementById('wday').disabled=false;
}
function pushUser()
{
document.cron.user.value=document.cron.user_select.value;
}
</script></head>
<?php
$error = $_POST['empty'];
echo '<fieldset><legend>Details</legend><form name="cron" action="setcron.php" method="post">';
echo '<table><tr height="25">';
echo '<td width="150"><b>User</b></td><td><input title="Enter user for running this cronjob" type=text id="user" name="user" size="12"</input>';
echo '<select name="user_select" size="1" style="margin-left:10px" value="" selected onChange="javascript:pushUser();">';
echo 'echo <option value="">Choose user</option>';
$user_shadow=file('/etc/shadow');
foreach($user_shadow as $each_user) {
$count_string=strlen($each_user);
$pos = strpos($each_user, ":");
$select_user=substr_replace($each_user, '', $pos, -1);
echo '<option value="'.$select_user.'">'.$select_user.'</option>';
}
echo '</select></td>';
echo '<tr height="25"><td><b>Active</b></td><td><input type="radio" name="active" value="" checked="checked"> Yes</input><input type="radio" name="active" value="#"> No</input></td>';
echo '<tr height="25"><td><b>Command</b></td><td><input title="Enter cron command here" type=text name="command" size="50"</input></td>';
echo '<tr height="25"><td><b>Description</b></td><td><input title="Enter jobdescription here" type=text name="description" size="50"</input></td>';
echo '</tr></table></fieldset>';
echo '<table cellspacing="0"><tr>';
echo '<td valign="top"><fieldset style="height:240px;"><legend>Minute</legend>
<input name="radiomin" type="radio" value="minall" onClick="makeminDisable();" checked="true"> All</input><br />
<input name="radiomin" type="radio" value="minchoice" onClick="makeminEnable(this);" > Selection</input><br /><br />
<select name="min1[]" id="min1" size="12" multiple="true" disabled="true">';
$x=0; $y=12;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="min2[]" id="min2" size="12" multiple="true" disabled="true" style="margin-left:5px">';
$x=12; $y=24;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="min3[]" id="min3" size="12" multiple="true" disabled="true" style="margin-left:5px">';
$x=24; $y=36;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="min4[]" id="min4" size="12" multiple="true" disabled="true" style="margin-left:5px">';
$x=36; $y=48;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="min5[]" id="min5" size="12" multiple="true" disabled="true" style="margin-left:5px">';
$x=48; $y=60;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select></fieldset></td>';
echo '<td valign="top"><fieldset style="height:240px;"><legend>Hour</legend>
<input name="radiohour" type="radio" value="hourall" onClick="makehourDisable(this)" checked="checked"> All</input><br />
<input name="radiohour" type="radio" value="hourchoice" onClick="makehourEnable(this)"> Selection</input><br /><br />
<select name="hour1[]" id="hour1" size="12" multiple="true" disabled="true">';
$x=0; $y=12;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="hour2[]" id="hour2" size="12" multiple="true" disabled="true" style="margin-left:5px">';
$x=12; $y=24;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select></fieldset></td>';
echo '<td valign="top"><fieldset style="height:240px;"><legend>Day</legend>
<input name="radioday" type="radio" value="dayall" onClick="makedayDisable(this)" checked="checked"> All</input><br />
<input name="radioday" type="radio" value="daychoice" onClick="makedayEnable(this)"> Selection</input><br /><br />
<select name="day1[]" id="day1" size="12" multiple="true" disabled="true">';
$x=1; $y=13;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="day2[]" id="day2" size="12" multiple="true" disabled="true" style="margin-left:5px">';
$x=13; $y=25;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="day3[]" id="day3" size="12" multiple="true" disabled="true" style="margin-left:5px">';
$x=25; $y=32;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select></fieldset></td>';
echo '<td valign="top"><fieldset style="height:240px;"><legend>Month</legend>
<input name="radiomon" type="radio" value="monall" onClick="makemonDisable(this)" checked="checked"> All</input><br />
<input name="radiomon" type="radio" value="monchoice" onClick="makemonEnable(this)"> Selection</input><br /><br />
<select name="mon[]" id="mon" size="12" multiple="true" disabled="true">';
$x=1; $y=13;
while ($x<$y){
echo '<option value="'.$x.'">'.$x.'</option>';
$x++;
}
echo '</select></fieldset></td>';
echo '<td valign="top"><fieldset style="height:240px;"><legend>Weekday</legend>
<input name="radioweekday" type="radio" value="weekdayall" onClick="makeweekdayDisable(this)" checked="checked"> All</input><br />
<input name="radioweekday" type="radio" value="weekdaychoice" onClick="makeweekdayEnable(this)"> Selection</input><br /><br />
<select name="weekday[]" id="wday" size="12" multiple="true" disabled="true">';
$wday=array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
$x=1; $y=8; $z=0;
while ($x<$y){
echo '<option value="'.$x.'">'.$wday[$z].'</option>';
$x++; $z++;
}
echo '</select></fieldset></td>';
echo '</tr></table>';
echo '<fieldset><legend>Actions</legend>';
echo '<input type="button" title="Abort new job and go back to index" value=" Cancel " onclick="window.location='cronjob.php'">';
echo '<input type="submit" title="Save cronjob and restart crond" style="margin-left:3px" value=" Save job & Restart ">';
echo '</fieldset></form>';
echo '<br />* Hold "CTRL" for multiple selection and deselection';
if ($empty==1){
echo '<br /><br /><font color="#ff0000"><b>Value for User and Command is required!</b></font>';
}
?>
editcron.php:
<?php
putenv('HTTP_COOKIE='.$_SERVER['HTTP_COOKIE']);
putenv('REMOTE_ADDR='.$_SERVER['REMOTE_ADDR']);
$user=exec('/usr/syno/synoman/webman/modules/authenticate.cgi');
if($user != 'admin'){
header("HTTP/1.0 403 Forbidden");
exit;
}
$deletechange = $_POST['choicecron'];
$button = $_POST['action'];
$crontabfile=file('/etc/crontab');
$x=count($crontabfile);
$c=count($deletechange);
if ($button == 'enabledisable'){
for ($i=0; $i<$c; $i++){
$search=$deletechange[$i];
for ($y=0;$y<$x;$y++){
if(array_key_exists($y,$crontabfile)){
if(substr_count($crontabfile[$y], $search) > 0){
if ($crontabfile[$y]{0}=='#'){
$crontabfile[$y]{0}='';
$crontabfile_mod = $crontabfile[$y];
$crontabfile[$y] = ltrim($crontabfile_mod);
}
else{
$crontabfile_mod = $crontabfile[$y];
$crontabfile[$y] = '#'.$crontabfile_mod;
}
}
}
}
}
file_put_contents('/etc/crontab', $crontabfile);
exec('killall crond;crond -l 8 -L /var/log/cron.log');
header("Location: cronjob.php");
exit();
}
If ($button == 'delete'){
for ($i=0; $i<$c; $i++){
$search=$deletechange[$i];
for ($y=0;$y<$x;$y++){
if(array_key_exists($y,$crontabfile)){
if(substr_count($crontabfile[$y], $search) > 0)
unset($crontabfile[$y]);
}
}
}
file_put_contents('/etc/crontab', $crontabfile);
exec('killall crond;crond -l 8 -L /var/log/cron.log');
header("Location: cronjob.php");
exit();
}
if ($button == 'changejob'){
if ($deletechange =='' or $c > 1){
header("Location: cronjob.php?empty=1");
exit();
}
?>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Cronjobs</title>
<style>body,input,select,option,td{font:11px Arial}body{background-color:#EEEEEE}legend{font-weight:bold;color:#15428b}fieldset{border:1px solid #bbb; padding:5px}a:hover,a:link,a:visited{color: #000;text-decoration:none}</style>
<script language="JavaScript" type="text/javascript">
function makeminDisable()
{
for( var i=1; i<6; i++ ){
document.getElementById('min' +i).disabled=true;
}
}
function makeminEnable()
{
for( var i=1; i<6; i++ ){
document.getElementById('min' +i).disabled=false;
}
}
function makestdDisable()
{
for( var i=1; i<3; i++ ){
document.getElementById('std' +i).disabled=true;
}
}
function makestdEnable()
{
for( var i=1; i<3; i++ ){
document.getElementById('std' +i).disabled=false;
}
}
function makedayDisable()
{
for( var i=1; i<4; i++ ){
document.getElementById('day' +i).disabled=true;
}
}
function makedayEnable()
{
for( var i=1; i<4; i++ ){
document.getElementById('day' +i).disabled=false;
}
}
function makemonDisable()
{
document.getElementById('mon').disabled=true;
}
function makemonEnable()
{
document.getElementById('mon').disabled=false;
}
function makeweekdayDisable()
{
document.getElementById('wday').disabled=true;
}
function makeweekdayEnable()
{
document.getElementById('wday').disabled=false;
}
function pushUser()
{
document.cron.user.value=document.cron.user_select.value;
}
</script></head>
<?php
function decrypt($decrypt){
$text = explode(",",$decrypt);
foreach ($text as $value) {
$count++;
$begin = "";
$end = "";
$temp = "";
if (strpos($value,"-") > 0) {
$begin = substr($value,0,strpos($value,"-"));
$end = substr($value,strpos($value,"-")+1);
for ($begin; $begin<=$end; $begin++) {
$temp = $temp.",".$begin;
}
$text[$count-1] = $temp;
}
}
$decrypt = implode(",",$text);
if ($decrypt{0}!='*'){
$decrypt = ','.$decrypt.',';
}
return $decrypt;
}
$error = $_POST['empty'];
$search=$deletechange[0];
$change=$deletechange[0];
for($y=0;$y<$x;$y++){
if(array_key_exists($y,$crontabfile)){
if(substr_count($crontabfile[$y], $search) > 0){
$result_edit = $crontabfile[$y];
}
}
}
$edit_cron=explode(chr(9),$result_edit);
$user = $edit_cron[5];
$command = $edit_cron[6];
$description = substr_replace($edit_cron[7], '', 0, 1);
if ($edit_cron[0]{0}=='#'){
$active_no='checked="true"';
$active_yes='';
}
else{
$active_yes='checked="true"';
$active_no='';
}
if ($edit_cron[0]{0}=='*' or $edit_cron[0]{1}=='*'){
$minno='checked="true"';
$minyes='';
$showmin='disabled="true"';
}
else{
$minyes='checked="true"';
$minno='';
$showmin='';
}
if ($edit_cron[1]{0}=='*'){
$stdno='checked="true"';
$stdyes='';
$showstd='disabled="true"';
}
else{
$stdyes='checked="true"';
$stdno='';
$showstd='';
}
if ($edit_cron[2]{0}=='*'){
$dayno='checked="true"';
$dayyes='';
$showday='disabled="true"';
}
else{
$dayyes='checked="true"';
$dayno='';
$showday='';
}
if ($edit_cron[3]{0}=='*'){
$monno='checked="true"';
$monyes='';
$showmon='disabled="true"';
}
else{
$monyes='checked="true"';
$monno='';
$showmon='';
}
if ($edit_cron[4]{0}=='*'){
$wdayno='checked="true"';
$wdayyes='';
$showwday='disabled="true"';
}
else{
$wdayyes='checked="true"';
$wdayno='';
$showwday='';
}
if ($edit_cron[0]{0}=='#'){
$edit_cron[0] = substr_replace($edit_cron[0], '', 0, 1);
}
$edit_cron[0] = decrypt($edit_cron[0]);
$edit_cron[1] = decrypt($edit_cron[1]);
$edit_cron[2] = decrypt($edit_cron[2]);
$edit_cron[3] = decrypt($edit_cron[3]);
$edit_cron[4] = decrypt($edit_cron[4]);
echo '<fieldset><legend>Details</legend><form name="cron" action="setcron.php" method="post">';
echo '<input type="hidden" id="action" name="action" value="">';
echo '<input type="hidden" id="tochange" name="tochange" value="'.$change.'">';
echo '<table><tr height="25">';
echo '<td width="150"><b>User</b></td><td><input title="Enter user for running this cronjob" type=text id="user" name="user" value="'.$user.'" size="12"</input>';
echo '<select name="user_select" size="1" style="margin-left:10px" value="" selected onChange="javascript:pushUser();">';
echo 'echo <option value="">Choose user</option>';
$user_shadow=file('/etc/shadow');
foreach($user_shadow as $each_user) {
$count_string=strlen($each_user);
$pos = strpos($each_user, ":");
$select_user=substr_replace($each_user, '', $pos, -1);
echo '<option value="'.$select_user.'">'.$select_user.'</option>';
}
echo '</select></td>';
echo '<tr height="25"><td><b>Active</b></td><td><input type="radio" name="active" value="" '.$active_yes.'> Yes</input><input type="radio" name="active" value="#" '.$active_no.'> No</input></td>';
echo '<tr height="25"><td><b>Command</b></td><td><input title="Enter cron command here" type=text name="command" value="'.$command.'" size="50"</input></td>';
echo '<tr height="25"><td><b>Description</b></td><td><input title="Enter jobdescription here" type=text name="description" value="'.$description.'"size="50"</input></td>';
echo '</tr></table></fieldset>';
echo '<table cellspacing="0"><tr>';
echo '<td valign="top"><fieldset style="height:240px;"><legend>Minute</legend>
<input name="radiomin" type="radio" value="minall" onClick="makeminDisable();" '.$minno.'> All</input><br />
<input name="radiomin" type="radio" value="minchoice" onClick="makeminEnable(this);" '.$minyes.'> Selection</input><br /><br />
<select name="min1[]" id="min1" size="12" multiple="true" '.$showmin.'>';
$x=0; $y=12;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[0])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="min2[]" id="min2" size="12" multiple="true" '.$showmin.' style="margin-left:5px">';
$x=12; $y=24;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[0])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="min3[]" id="min3" size="12" multiple="true" '.$showmin.' style="margin-left:5px">';
$x=24; $y=36;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[0])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="min4[]" id="min4" size="12" multiple="true" '.$showmin.' style="margin-left:5px">';
$x=36; $y=48;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[0])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="min5[]" id="min5" size="12" multiple="true" '.$showmin.' style="margin-left:5px">';
$x=48; $y=60;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[0])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select></fieldset></td>';
echo '<td valign="top"><fieldset style="height:240px;"><legend>Hour</legend>
<input name="radiostd" type="radio" value="stdall" onClick="makestdDisable(this)" '.$stdno.'> All</input><br />
<input name="radiostd" type="radio" value="stdchoice" onClick="makestdEnable(this)" '.$stdyes.'> Selection</input><br /><br />
<select name="std1[]" id="std1" size="12" multiple="true" '.$showstd.'>';
$x=0; $y=12;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[1])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="std2[]" id="std2" size="12" multiple="true" '.$showstd.' style="margin-left:5px">';
$x=12; $y=24;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[1])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select></fieldset></td>';
echo '<td valign="top"><fieldset style="height:240px;"><legend>Day</legend>
<input name="radioday" type="radio" value="dayall" onClick="makedayDisable(this)" '.$dayno.'> All</input><br />
<input name="radioday" type="radio" value="daychoice" onClick="makedayEnable(this)" '.$dayyes.'> Selection</input><br /><br />
<select name="day1[]" id="day1" size="12" multiple="true" '.$showday.'>';
$x=1; $y=13;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[2])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="day2[]" id="day2" size="12" multiple="true" '.$showday.' style="margin-left:5px">';
$x=13; $y=25;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[2])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select>';
echo '<select name="day3[]" id="day3" size="12" multiple="true" '.$showday.' style="margin-left:5px">';
$x=25; $y=32;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[2])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select></fieldset></td>';
echo '<td valign="top"><fieldset style="height:240px;"><legend>Month</legend>
<input name="radiomon" type="radio" value="monall" onClick="makemonDisable(this)" '.$monno.'> All</input><br />
<input name="radiomon" type="radio" value="monchoice" onClick="makemonEnable(this)" '.$monyes.'> Selection</input><br /><br />
<select name="mon[]" id="mon" size="12" multiple="true" '.$showmon.'>';
$x=1; $y=13;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[3])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
$x++;
}
echo '</select></fieldset></td>';
echo '<td valign="top"><fieldset style="height:240px;"><legend>Weekday</legend>
<input name="radioweekday" type="radio" value="weekdayall" onClick="makeweekdayDisable(this)" '.$wdayno.'> All</input><br />
<input name="radioweekday" type="radio" value="weekdaychoice" onClick="makeweekdayEnable(this)" '.$wdayyes.'> Selection</input><br /><br />
<select name="weekday[]" id="wday" size="12" multiple="true" '.$showwday.'>';
$wday=array("Monday", "Thuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
$x=1; $y=8; $z=0; $w=0;
while ($x<$y){
$z=$x; settype($z, "string");
if (preg_match("/," .$z. ",/", $edit_cron[4])){
$selected = 'selected="selected"';
}
else{
$selected='';
}
echo '<option value="'.$x.'" '.$selected.'>'.$wday[$w].'</option>';
$x++; $z++; $w++;
}
echo '</select></fieldset></td>';
echo '</tr></table>';
echo '<fieldset><legend>Actions</legend>';
echo '<input type="button" title="Abort and go back to cron index" value=" Cancel " onclick="window.location='cronjob.php'">';
echo '<input type="button" title="Save job and restart crond" value="Save cronjob and restart crond" style="margin-left:3px" onclick="document.getElementById('action').value='editcron';submit()">';
echo '</fieldset></fieldset></form>';
echo '<br />* Hold "CTRL" for multiple selection and deselection';
if ($empty==1){
echo '<br /><br /><font color="#ff0000"><b>Value for User and Command is required!</b></font>';
}
}
?>
en tot slot setcron.php
<?php
putenv('HTTP_COOKIE='.$_SERVER['HTTP_COOKIE']);
putenv('REMOTE_ADDR='.$_SERVER['REMOTE_ADDR']);
$user=exec('/usr/syno/synoman/webman/modules/authenticate.cgi');
if($user != 'admin'){
header("HTTP/1.0 403 Forbidden");
exit;
}
function MakeCompact($what) {
$cronarray = explode(",",$what);
$dummyarray = $cronarray;
$loop = 0;
foreach ($cronarray as $value) {
if ($loop > 0) {
if ($temp+1 == $value) {
$dummyarray[$loop] = "-";
$temp = $value;
} else {
$dummyarray[$loop-1] = $cronarray[$loop-1];
$temp = $value;
}
} else {
$temp = $value;
}
$loop++;
}
$what = implode(",",$dummyarray);
$what = str_ireplace(",-","-",$what);
$what = str_ireplace("-,","-",$what);
while (stripos($what,",-,") > 0) {
$what = str_ireplace(",-,","",$what);
}
while (stripos($what,"--") > 0) {
$what = str_ireplace("--","-",$what);
}
if (substr($what,strlen($what)-1,1) == ",") {$what = substr($what,0,strlen($what)-1);}
unset($dummyarray);
unset($cronarray);
return $what;
}
$minall = $_POST['radiomin'];
$minute1 = $_POST['min1'];
$minute2 = $_POST['min2'];
$minute3 = $_POST['min3'];
$minute4 = $_POST['min4'];
$minute5 = $_POST['min5'];
$hourall = $_POST['radiohour'];
$hour1 = $_POST['std1'];
$hour2 = $_POST['std2'];
$tagall = $_POST['radioday'];
$day1 = $_POST['dag1'];
$day2 = $_POST['dag2'];
$day3 = $_POST['dag3'];
$monall = $_POST['radiomon'];
$mon1 = $_POST['mon'];
$weekdayall = $_POST['radioweekday'];
$wday1 = $_POST['weekday'];
$user1 = $_POST['user'];
$active1 = $_POST['active'];
$command1 = $_POST['command'];
$description1 = $_POST['description'];
$button = $_POST['action'];
$deletechange = $_POST['tochange'];
if ($user1=='' or $command1 ==''){
header("Location: newcron.php?empty=1");
exit();
}
$crontabfile=file('/etc/crontab');
$x=count($crontabfile);
if ($button == 'editcron'){
for ($y=0;$y<$x;$y++){
if(array_key_exists($y,$crontabfile)){
if(substr_count($crontabfile[$y],substr($deletechange,0,strlen($deletechange)-5)) > 0) {
$crontabfile[$y]='edit';
$t=$y;
}
}
}
}
if ($minall == 'minall'){
$cron_minute_write = $active . '*';
}
else{
if (isset($minute1)){
$cron_minute1 = implode(",", $minute1) . ",";
}
if (isset($minute2)){
$cron_minute2 = implode(",", $minute2) . ",";
}
if (isset($minute3)){
$cron_minute3 = implode(",", $minute3) . ",";
}
if (isset($minute4)){
$cron_minute4 = implode(",", $minute4) . ",";
}
if (isset($minute5)){
$cron_minute5 = implode(",", $minute5) . ",";
}
if ($cron_minute1=='' and $cron_minute2=='' and $cron_minute3=='' and $cron_minute4=='' and $cron_minute5=='') {
$cron_minute_write = $active . '*';
} else {
$cron_minute=$cron_minute1 . $cron_minute2 . $cron_minute3 . $cron_minute4 . $cron_minute5;
$cron_minute = MakeCompact($cron_minute);
$cron_minute_write=$active . $cron_minute;
}
}
if ($hourall == 'hourall'){
$cron_std_write ='*';
}
else{
if (isset($hour1)){
$cron_std1 = implode(",", $hour1) . ",";
}
if (isset($hour2)){
$cron_std2 = implode(",", $hour2) . ",";
}
if ($cron_std1=='' and $cron_std2=='') {
$cron_std_write = '*';
} else {
$cron_std=$cron_std1 . $cron_std2;
$cron_std_write=MakeCompact($cron_std);
}
}
if ($tagall == 'tagall'){
$cron_day_write ='*';
}
else{
if (isset($day1)){
$cron_day1 = implode(",", $day1) . ",";
}
if (isset($day2)){
$cron_day2 = implode(",", $day2) . ",";
}
if (isset($day3)){
$cron_day3 = implode(",", $day3) . ",";
}
if ($cron_day1=='' and $cron_day2=='' and $cron_day3=='') {
$cron_day_write = '*';
} else {
$cron_day=$cron_day1 . $cron_day2 . $cron_day3;
$cron_day_write = MakeCompact($cron_day);
}
}
if ($monall == 'monall'){
$cron_mon_write ='*';
}
else{
if (isset($mon1)){
$cron_mon = implode(",", $mon1) . ",";
}
if ($cron_mon=='') {
$cron_mon_write = '*';
} else {
$cron_mon_write = MakeCompact($cron_mon);
}
}
if ($weekdayall == 'weekdayall'){
$cron_wday_write ='*';
}
else{
if (isset($wday1)){
$cron_wday = implode(",", $wday1) . ",";
}
if ($cron_wday=='') {
$cron_wday_write = '*';
} else {
$cron_wday_write = MakeCompact($cron_wday);
}
}
$tab=chr(9);
$newline=chr(10);
if ($description1 ==''){
$seperator='';
}
else{
$seperator='#';
}
$cron_write = $cron_minute_write.$tab.$cron_std_write.$tab.$cron_day_write.$tab.$cron_mon_write.$tab.$cron_wday_write.$tab.$user1.$tab.$command1.$tab.$seperator.$description1.$newline;
$crontabfile[$t] = str_replace(chr(13),'',$cron_write);
file_put_contents('/etc/crontab', $crontabfile);
exec('killall crond;crond -l 8 -L /var/log/cron.log');
header("Location: cronjob.php");
exit();
?>
De icoontjes:
Veel plezier er mee!
Wizjos