Beispiel #1
0
 function deleteFile($file_name) {


 if (!file_exists($file_name)) {
  return true; //if file doesn't exist than don't worry about it
 }
 clearstatcache(); //clear cache since will be checking same file again
 $path_errors=isPathBad($file_name, true, true);

 if ( !$path_errors["directory"]["write"] and !$path_errors["file"])  {

   if(MS_WINDOWS) {
   $file_name=formatPath($file_name);

   exec("del $file_name");

   } else {

    unlink($file_name);

   }
   return true;
 } else {


 return false;    //return false if errors - can't write to path
 }
}
Beispiel #2
0
$option_feedback .="\tSystem Name is: $system_name\r\n<br>";

if($redirect_output) {

  echo "\r\nRedirecting Output to: ".formatPath($redirect_file)."\r\n<br>";
}


/*************End Build of Feedback on Options *******/

/* Write phpcron_psinfo_file containing process info. This serves to communicate info to
PHPCron Admin and tells it whether this script is running.*/



$path_errors=isPathBad($phpcron_psinfo_file, true);
if ($path_errors["directory"] or $path_errors["file"]["write"]) {

  $output="Error:  Cannot write to $phpcron_psinfo_file. The following errors were encountered.:<br>\r\n";

  while ( list($file_or_dir, $error_messages) = each($path_errors)) {

              while (list($each_message)  = each($error_messages)) {
                $output.= $path_errors[$file_or_dir][$each_message]."<br>\r\n";
              }
  }

  stopPhpcron("\r\nERROR: PHPCRON must be able to create $phpcron_psinfo_file, please fix the problem, and try again.<br><br>\r\n\r\n");


Beispiel #3
0
function editTabByForm($phpcrontab_filename){
global $PHP_SELF;
global $new_tabfilename;
global $edit_table_title;
global $edit_table_title_no_border;
global $edit_tab_by_form;
global $tab_save_error;
global $new_tab_contents;
global $old_tabfilename;
global $create_tab;
global $secure;



/*NOTE: Allow create file: if there is no phpcrontab file or no parameters then 
substitute another array for $line and save new file. */

if ($tab_save_error) {
  $new_tabfilename=""; //initialize
  $phpcrontab_filename=$old_tabfilename;
  /* Don't read from file - just use attempted saved contents if save failure */
  $phpcronconf_array=explode("\n",stripslashes($new_tab_contents));
} elseif(!$path_errors=isPathBad($phpcrontab_filename,true,true)) {
 /* Read conf file into an array, with each line being an element in the array */

$phpcronconf_array=file($phpcrontab_filename);
} else {

if (is_readable($phpcrontab_filename)) {
$phpcronconf_array=file($phpcrontab_filename);
}
//If there are  path errors, report them

    while ( list($file_or_dir, $error_string) = each($path_errors)) {

      while (list($each_message)  = each($error_string)) {
        $error_messages.=$path_errors[$file_or_dir][$each_message];

      }
    }

    $error_messages="<h3>Cannot Edit $phpcrontab_filename because of file errors:</h3>".$error_messages;
   
}





    //Tests for existence of phpcrontab file - if does not exist, creates one

   if(!file_exists($phpcrontab_filename) or $create_tab) {

    if (!$create_tab) {
      $error_messages.="Creating new phpcrontab file - No existing file found for $phpcrontab_filename<br>";
    } else {
      $error_messages.="Creating new phpcrontab file<br>";
    }
    $create_tab=true;
    $create_tab_contents=
"# comments: lines must begin with a #
#  Phpcrontab.conf
#The phpcontab.conf file contains a schedule of scripts/programs to
# run in the traditional crontab format:
# minute (0-59) hour (0-23) day of month (1-31) month(1-12) day of week(0-6)  command
# Wild Cards are allowed. Each parameter is separated by one space.
# Example:
#
# 59 3 * * 5  php sample_script.php   # every Friday at 3:59 a.m.
#Ranges and multiple values will also work:
# 0 0 1-15 * *   perl sample_script.pl   #executes on 1st through 15th of month
# 0 0 1-3,15 * *   perl sample_script.pl   # executes on 1st-3rd and 15th of month
#
# MINUTES HOUR MONTHDAY MONTH WEEKDAYNUM
";

    $phpcronconf_array=explode("\n",$create_tab_contents);

    
   }

$crontab_stripped=formatPath($phpcrontab_filename); 


$output.="
    <!--**********Begin JavaScript*******************-->
    <SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\">
     <!--  

	   function isNumberBetween(string,low,high) {
	    for (i = 0; i < string.length; i++)
	    {   
        	// Check that each character is number.
        	var c = string.charAt(i);

        	if (!((c >= \"0\") && (c <= \"9\"))) return false;
	    }

	   var number = parseInt (string); //converts string to integer 
	    return ((number >= low) && (number <= high));

	   }

	function trim(str)
	{
	var i = 0,j = str.length - 1;

        	while(str.charAt(i) == ' ') i++;
        	while(str.charAt(j) == ' ') j--;
	j++;

	return str.substring(i,j);

	}




	function validateField (field_string, textvalue, individual_parameter, theField, max_low, max_high) {
	       var warning_message=\"\";

	       if(!textvalue.match(/^(([0-9]{1,2}|[0-9]{1,2}-[0-9]{1,2}),?)+$/))
		 return warn(theField, textvalue + \" in the \" + field_string + \"  field is in an incorrect format.\");



	      for (i_array in individual_parameter)
	      {

	     /*warning_message=warning_message+\"i_array: \" + i_array + \"Being Evaluated:\" + individual_parameter[i_array] + \"\\r\\n\";
	     */
	       /* Check for Range */
	      if(individual_parameter[i_array].match(/^[0-9]*-[0-9]*,?$/)) {

	       var range=new Array();
	      range=individual_parameter[i_array].match(/[0-9]*-?/g) /* explode by hyphen*/

		  /*Just deletes , or - at end of string if it exists */
        	 range[0]=range[0].replace(/[,-]/g,\"\"); 	
		 range[1]=range[1].replace(/[,-]/g,\"\");
		/*warning_message=warning_message+ \"Low Value: \" + range[0] + \" High Value is: \" + range[1] + \"\\r\\n \";;
		*/

		/*Make Sure High > Low */

		if (parseInt(range[0])>=parseInt(range[1])) {

		warning_message=warning_message + \"Low value of range \" + individual_parameter[i_array] + \" in \" + field_string + \" field is greater than or equal to high value.\\r\\n\";


		}
		for (i_range in range)
		{

		  /*check each range to see if between correct values */
		   if (isNumberBetween(range[i_range],max_low,max_high)!=true)
        	  {
		  if(range[i_range]==\"\") {

		  continue; //continue inner loop

		  }
        	  warning_message=warning_message + range[i_range] + \" is in the \" + field_string + \" field which requires a number between \" + max_low + \" and \" + max_high +\".\\r\\n\";

		  }


		}		      


	      continue; //continue outer loop
	      }
        	/*warning_message=warning_message+ \"Second Being Evaluated:\" + individual_parameter[i_array] + \"\\r\\n\";
        	*/
		/*Just deletes , or - at end of string if it exists */
        	individual_parameter[i_array]=individual_parameter[i_array].replace(/[,-]/g,\"\"); 


        	   if (isNumberBetween(individual_parameter[i_array],max_low,max_high)!=true)
        	  {
		  if(individual_parameter[i_array]==\"\") return true;
        	  warning_message=warning_message + individual_parameter[i_array] + \" is in the \" + field_string + \" field which requires a number between \" + max_low + \" and \" + max_high +\".\\r\\n\";
        	  }
		  i_array++;
	      }    

	      if(warning_message !=\"\") {
	      warning_message=\"Error(s):\\r\\n\" + warning_message;      
	      return warn(theField,warning_message);
	      } else {
	      return true;
	      }


	}



  function checkParameter(theField, parameter_type) {
  
    
      /*Textvalue is string hold all of values in field */
      textvalue=trim(theField.value);
      var i_array=0;
 
            
      if (textvalue == \"*\") return true;
      var individual_parameter=new Array();
      
      /*Fill Array Individual Parameter with Values Separated by , or hyphens*/
      individual_parameter=textvalue.match(/[0-9]+(-[0-9]+)?,?/g) /* took out hypen*/
  
          
      switch (parameter_type) {
      
            
      case 0:
      return validateField (\"Minutes\", textvalue, individual_parameter, theField, 0, 59);

      case 1:
      return validateField (\"Hour\", textvalue, individual_parameter, theField, 0, 23);

      case 2:
      return validateField (\"Day of Month\", textvalue, individual_parameter, theField, 0, 31);

      case 3:
      return validateField (\"Month\", textvalue, individual_parameter, theField, 1, 12);

      case 4:
      return validateField (\"Week Day\", textvalue, individual_parameter, theField, 0, 6);
      
      default:
      return warn(theField, \"Error in Code: Parameter Type is Invalid - Can't validate entry\");
      
       }


    }   

    

    function warn (theField, s){   

        alert(s);

        return false;
    }


    function NoEmpty(theField, s) {
    if(theField.value==\"\")
        alert(\"The \" + s + \" field requires an entry\");
    }

    -->  

    </SCRIPT>
    <!--**********End *******************-->
    
      
    <form action=\"$PHP_SELF?admin_subpage=Save_Edtab\" STYLE=\"margin-bottom: 0\" method=\"post\">
      
    <!--*************** Begin Schedule Programs Table (edit phpcrontab info ) *********-->
    <table align=\"center\" width=\"600px\" style=$edit_tab_by_form border=\"0\" cellspacing=\"0\" cellpadding=\"2\" summary=\"PHPCRONTAB Edit Form\">

     <tr >
      <td colspan=\"7\" align=\"center\" style=$edit_table_title>
      
        <h2>Schedule Programs</h2>";

if ($create_tab) {
  $output.= "
  <h4>New PHPCRONTAB File</h4>";
} else {
     $output.=
     "<h4>(edit ".chunk_split($crontab_stripped, 20, " ").")</h4>";
}

$output.="
       </td>
      </tr>
      ";

          $line_number=0;
        
         /* Loop through the array containing the lines of the phpcrontab.conf file */
         while ($line=$phpcronconf_array[$line_number]) {   
 

                 $line=trim($line); //trim extra spaces
                 /* Get lines which contain mixed parameters and comments */
                 preg_match("/#.*$/",$line, $side_line_comments);
                 /* Gets rid of # as first character of each line - 
                 add this back later when save file. User does not have to enter */
                    $side_line_comments[0]=preg_replace("/^#/m", "", trim($side_line_comments[0]));  

                 preg_match("/^#.*$/",$line, $full_line_comments); 
                
                 /* Get rid of # as first character of each line - add this back later when save file. 
                   User does not have to enter. Also move lines over preserve vertical whitespace. */
                 $full_line_comments[0]=trim(preg_replace("/^#(.)/m", "\\1", trim($full_line_comments[0])));
                   //  preserve vertial whitespace
                   $full_line_comments[0]=preg_replace("/^#/m", " ", $full_line_comments[0]);
  
  
                   if($full_line_comments[0]) {
                  $top_line_comments.=$full_line_comments[0]."\r\n";
                  $number_of_top_comments++;
                }
  
              
                   if($param_headings_printed  and $full_line_comments[0]) {
                  $bottom_line_comments.=$full_line_comments[0]."\r\n";
                  $number_of_bottom_comments++;
                }
                 /* Delete commented out sections and lines */
                 $line=preg_replace("/#.*$/","",$line); 

                 /* If line is a blank line then ignore line, otherwise
                   process commands */

                       if(!preg_match ("/^\s*$/", $line)) {

                  /*Print out Top Comments into a Text Area if haven't printed*/

                   if (!$param_headings_printed) {              

                     $output.=tabTopComments($top_line_comments, $number_of_top_comments);  
                    $param_headings_printed=true; //print headings only once
            
                  }

                      /* Parse line into a 6 element array (0-5), 
                        5 time parameters (minute, hour, day of month, month, day of week)
                        + command string */
                            $line = explode(" ", $line,6);
          
                            $command_text=array_pop($line);  // pop off the command text 
                      $command_text=trim ($command_text); //trim extra spaces
        
                        /* Cycle through first five parameters horizontally and put in 
                      text boxes */

                            $parameter_no=0;       
                                  
                      while ($parameter_no<5){
              
                      $box_size=4;
                    

                      $output.= "
          
          <td align=\"center\" >        
            <input class=\"color\" name=\"ct_param[$line_number][$parameter_no]\" type=\"text\"  size=\"$box_size\" value=\"$line[$parameter_no]\" onChange=\"checkParameter(this, $parameter_no)\" >
          </td>";
                    
                                            
                      $parameter_no++;
                      }    
      
                      /* Add Commands and Side Line Comment Boxes */

                      $output.="
              <td align=\"center\">
                <input class=\"color\" type=\"text\" name=\"commands[$line_number]\" value=\"$command_text\"  onChange=\"NoEmpty(this, 'Commands')\">
              </td>
              <td align=\"center\">
                 <input class=\"color\" type=\"text\" name=\"side_line_comments[$line_number]\" value=\"$side_line_comments[0]\"> 
              </td>
              </tr>";
              
        
                } // end of check for blank line
                    $line_number++;
        
      } //end of parse loop  

       if (!$param_headings_printed) {

         /* If no commands in file, print out Top Comments into a Text Area as would not have
          previously printed */
         
         $output.=tabTopComments($top_line_comments, $number_of_top_comments);  
        $param_headings_printed=true; //print headings only once
      }

      /* Add 5 additional lines for new commands. Can do 5 at a time. */

          $max_lines=$line_number+5; //defines line number of last additional command input
          $output.="    
          <tr>
              <td align=\"center\" style=$edit_table_title colspan=\"7\">
                Add Commands (up to 5 at a time):
              </td>
          </tr>
         <tr>
	 ";
      

       while($line_number<$max_lines) { 

             $parameter_no=0;       
  
          while ($parameter_no<5){

          $box_size=4;
      

          $output.= "
<td align=\"center\" >        
<input class=\"color\" name=\"ct_param[$line_number][$parameter_no]\" type=\"text\"  size=\"$box_size\" value=\"$line[$parameter_no]\" onChange=\"checkParameter(this, $parameter_no)\" >
</td>
";
        
                                
          $parameter_no++;
          }    

         $output.="         
           <td align=\"center\">
             <input class=\"color\" type=\"text\" name=\"commands[$line_number]\" onChange=\"NoEmpty(this, 'Commands')\"> 
           </td>
           <td align=\"center\">
             <input class=\"color\" type=\"text\" name=\"side_line_comments[$line_number]\">
           </td>
         </tr>
	<tr>
         ";

          $line_number++; 
      }
        
      /* Bottom Comments */
      $output.="
        <td align=\"center\" colspan=\"7\" style=$edit_table_title>Bottom Comments:</td></tr>
        <tr>
        <td colspan=\"7\" align=\"center\">
            <textarea name=\"bottom_line_comments\" cols=\"80\" rows=\"$number_of_bottom_comments\">$bottom_line_comments
          </textarea>
          </td>
      </tr>
      <!--*************** End Schedule Programs Section of Table (edit phpcrontab info ) *********-->   
      
  <tr>
    <td style=$edit_table_title_no_border colspan=7>
  
  <!--******* FORM SUBMITS*********-->
   ";
   if ($create_tab) {
   if (!$secure) {
   $output.="
     File: <em>New PHPCRONTAB File </em><br> 
     <input type=\"submit\" value=\"Save As:\">

      <input class=\"color\" type=\"text\" name=\"new_tabfilename\">" ;
    }
    $output.="
      <br>
      Check to Save Over Existing File:
       <input type=\"checkbox\" name=\"overwrite\" value=\"true\" class=\"title\">
        <input type=\"hidden\"  name=\"max_line_number\" value=\"$line_number\"> 
  
      <input type=\"hidden\" name=\"current_tabfilename\" value=\"$phpcrontab_filename\">
      
      </form>
    </td>
    </tr>
  <tr>
  <td style=$edit_table_title_no_border  colspan=7>
      ";

   } else {
   $output.="
       <HR>
      <input type=\"submit\" value=\"Save\">";
  if (!$secure) {
  $output.=  "
      <input type=\"submit\" value=\"Save As:\">
      <input class=\"color\" type=\"text\" name=\"new_tabfilename\">";
  }
  $output.="
      <br> 
      Check to Save Over Existing File:
      <input type=\"checkbox\" name=\"overwrite\" value=\"true\" class=\"title\">  
        <input type=\"hidden\" value=\"$line_number\" name=\"max_line_number\"> 
      <input type=\"hidden\" name=\"current_tabfilename\" value=\"$phpcrontab_filename\">
  
      
      </form>
    </td>
    </tr>
  <tr>
  <td border=0  style=$edit_table_title_no_border colspan=7>
      ";

      /* This allows another file to be opened - commenting this out because I changed my mind.
      Think its better for a crontab file to be opened by changing user configuration file. 
      But if you want to use this feature it is implemented, just uncomment.
         <form action=\"$PHP_SELF\" method=\"post\">
        <input type=\"submit\" value=\"Open:\">
      <input class=\"color\" type=\"text\" name=\"new_tabfilename\"> 
      <input type=\"hidden\" value=\"Edit_Tab_By_Form\" name=\"admin_subpage\">
      </form>
      */

  $output.="
      <form action=\"$PHP_SELF\" method=\"post\">
        <input type=\"submit\" value=\"Create New PHPCRONTAB File\">
      <input type=\"hidden\" value=\"Edit_Tab_By_Form\" name=\"admin_subpage\">
      
      <input type=\"hidden\" value=\"true\" name=\"create_tab\">
     </form> 
    </td>
    </tr>
  <tr>
  <td border=0 style=$edit_table_title_no_border  colspan=7> 
      ";
  } 

$output.="
      <HR>
      File: <em>$crontab_stripped</em>
      </td>
      </tr>
  </table>
  <br>
   <!--*******END FORM SUBMITS *********-->";

  
              if ($new_tabfilename) {

            if($path_errors=isPathBad($new_tabfilename, true)) {

                 while ( list($file_or_dir, $error_messages) = each($path_errors)) {

                  while (list($each_message)  = each($error_messages)) {
                    $error_messages.=$path_errors[$file_or_dir][$each_message]; 
                  }
              }

             }


            else {
              $phpcrontab_filename=$new_tabfilename;
              }
            }

  
  if($error_messages) {echoErrorMessages($error_messages);};
  echo $output;   



} //end of function