Naar aanleiding van een publicatie op het duitse forum van een vernieuwde versie van deze 3rd party oplossing ben ik zelf ook nog eens aan 't knutselen geslagen
Zo ziet het er nu uit:
Wat is er nieuw, behalve de aanblik?
Er zijn (door mij) beveiligingen ingebouwd: als je op Delete klikt wordt je gevraagd of je inderdaad wilt verwijderen; als je niets selecteert krijg je een melding en net zo als je te veel selecteert...
Er zijn schermen om een job te bewerken en toe te voegen, waarbij de selectie van gebruiker, tijd enz. iets simpeler is gemaakt
In de huidige duitse versie is het niet mogelijk om een job aan te maken die een reeks met een '-' kan aangeven (als je bijvoorbeeld een job van 7 tot 11 's-avonds wilt laten lopen krijg je in de duitse versie: 7,8,9,10,11....,23; dat wordt nu dus 7-23)
Het script is beveiligd via de oplossing
Beveiligen van php/html 3rd party code middels authorisatie. Zie daar ook voor details ten aanzien van het benodigde cgi script!
de bestanden (4 stuks) kun je plaatsen in dezelfde dir als de eerdere post (/usr/syno/synoman/webman/3rdparty/cronjobs) en zien er als volgt uit:
cronjob.php de hoofdpagina
LET OP! Code van Merty voor beveiliging toegepast (regels 56 t/m 63).<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>';
}
?>
editcron.php de pagina waarmee je een job bewerkt
<?php
$deletechange = $_POST['choicecron'];
$button = $_POST['action'];
$crontabfile=file('/etc/crontab'); //gewijzigd
$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 maketagDisable()
{
for( var i=1; i<4; i++ ){
document.getElementById('tag' +i).disabled=true;
}
}
function maketagEnable()
{
for( var i=1; i<4; i++ ){
document.getElementById('tag' +i).disabled=false;
}
}
function makemonDisable()
{
document.getElementById('mon').disabled=true;
}
function makemonEnable()
{
document.getElementById('mon').disabled=false;
}
function makewochtagDisable()
{
document.getElementById('wday').disabled=true;
}
function makewochtagEnable()
{
document.getElementById('wday').disabled=false;
}
function pushUser()
{
document.cron.user.value=document.cron.user_select.value;
}
</script></head>
<?php
function decrypt($decrypt){
//Expand '-' ....
$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.',';
}
/*$position = strpos($decrypt, "-");
$pre = substr($decrypt,0,$position-2);
if (substr($pre,strlen($pre)-1,1) != ",") {$pre=$pre.",";}
while (strpos($decrypt, "-") > 0){
$position = strpos($decrypt, "-");
$begin = substr($decrypt,$position-2,2);
$begin = str_replace(",","",$begin);
$end = substr($decrypt,$position+1,2);
$remain = substr($decrypt,$position+3);
if (substr($remain,0,1) != ",") {$remain = ",".$remain;}
for ($i=$begin; $i<$end+1; $i++){$pre = $pre.$i.",";}
$decrypt = $pre.substr($decrypt,$position+3);
}
//cleanup last ','
$decrypt = str_ireplace(",,",",",$decrypt);
echo $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}=='*'){
$tagno='checked="true"';
$tagyes='';
$showtag='disabled="true"';
}
else{
$tagyes='checked="true"';
$tagno='';
$showtag='';
}
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="radiotag" type="radio" value="tagall" onClick="maketagDisable(this)" '.$tagno.'> All</input><br />
<input name="radiotag" type="radio" value="tagchoice" onClick="maketagEnable(this)" '.$tagyes.'> Selection</input><br /><br />
<select name="tag1[]" id="tag1" size="12" multiple="true" '.$showtag.'>';
$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="tag2[]" id="tag2" size="12" multiple="true" '.$showtag.' 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="tag3[]" id="tag3" size="12" multiple="true" '.$showtag.' 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="radiowochtag" type="radio" value="wochtagall" onClick="makewochtagDisable(this)" '.$wdayno.'> All</input><br />
<input name="radiowochtag" type="radio" value="wochtagchoice" onClick="makewochtagEnable(this)" '.$wdayyes.'> Selection</input><br /><br />
<select name="wochtag[]" 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>';
}
}
?>
newcron.php hiermee maak je een nieuwe job aan
<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 maketagDisable()
{
for( var i=1; i<4; i++ ){
document.getElementById('tag' +i).disabled=true;
}
}
function maketagEnable()
{
for( var i=1; i<4; i++ ){
document.getElementById('tag' +i).disabled=false;
}
}
function makemonDisable()
{
document.getElementById('mon').disabled=true;
}
function makemonEnable()
{
document.getElementById('mon').disabled=false;
}
function makewochtagDisable()
{
document.getElementById('wday').disabled=true;
}
function makewochtagEnable()
{
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="radiostd" type="radio" value="stdall" onClick="makestdDisable(this)" checked="checked"> All</input><br />
<input name="radiostd" type="radio" value="stdchoice" onClick="makestdEnable(this)"> Selection</input><br /><br />
<select name="std1[]" id="std1" 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="std2[]" id="std2" 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="radiotag" type="radio" value="tagall" onClick="maketagDisable(this)" checked="checked"> All</input><br />
<input name="radiotag" type="radio" value="tagchoice" onClick="maketagEnable(this)"> Selection</input><br /><br />
<select name="tag1[]" id="tag1" 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="tag2[]" id="tag2" 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="tag3[]" id="tag3" 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="radiowochtag" type="radio" value="wochtagall" onClick="makewochtagDisable(this)" checked="checked"> All</input><br />
<input name="radiowochtag" type="radio" value="wochtagchoice" onClick="makewochtagEnable(this)"> Selection</input><br /><br />
<select name="wochtag[]" 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>';
}
?>
setcron.php verwerkt nieuwe en gewijzigde jobs en past /etc/crontab aan
<?php
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'];
$stdall = $_POST['radiostd'];
$hour1 = $_POST['std1'];
$hour2 = $_POST['std2'];
$tagall = $_POST['radiotag'];
$day1 = $_POST['tag1'];
$day2 = $_POST['tag2'];
$day3 = $_POST['tag3'];
$monall = $_POST['radiomon'];
$mon1 = $_POST['mon'];
$wochtagall = $_POST['radiowochtag'];
$wday1 = $_POST['wochtag'];
$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 ($stdall == 'stdall'){
$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 ($wochtagall == 'wochtagall'){
$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);
//die($crontabfile[$t]);
file_put_contents('/etc/crontab', $crontabfile);
exec('killall crond;crond -l 8 -L /var/log/cron.log');
header("Location: cronjob.php");
exit();
?>
Ter illustratie nog een afbeeldinkje van het edit-scherm:
Als je e.e.a. bijplaatst in de directory /usr/syno/synoman/webman/3rdparty/cronjobs, pas dan application.cfg aan zodat de nieuwe cronjob-pagina getoond wordt i.p.v. de oude:
application.cfg was:
text = cronjobs
description = cronjobs
type=embedded
path = /phpsrc/cronjobs/cronjobs.php
en wordt:
text = cronjobs
description = cronjobs
type=embedded
path = /phpsrc/cronjobs/cronjob.php
Dus één hele 's' minder
Enne, vergeet de chmod 755 niet op de php bestanden!
Veel plezier er mee!
Wizjos