function saveFile($new_file_contents, $file_name) { /* Save File over file_name (overwrites); returns an array of $save_results; $save_results[0] is true on success, false on failure and failure messages are in remaining elements of array */ $new_file_contents=trim(stripslashes($new_file_contents)); //strip slashes from paths $filename_stripped=formatPath($file_name); $path_errors=isPathbad($file_name, true, false); if (!isset($path_errors)) { //check if directory is valid and file name is legal $fp = @fopen( $file_name,"w"); //open for writing, place file pointer at beginning of file, if does not exist attempt to create it if (!$fp) { $open_error="Error: File $filename_stripped Cannot Be opened. Check Permissions.<br>\n"; } else { fwrite($fp,$new_file_contents); fclose ($fp); $save_results[0]="<strong>File $filename_stripped has been successfully saved.<strong><br>"; } $i=1; } else { $i=2; $save_results[1]="Error: Cannot save file $filename_stripped.<br>"; while ( list($file_or_dir, $error_message) = each($path_errors)) { while (list($each_message) = each($error_message)) { $save_results[$i].= $path_errors[$file_or_dir][$each_message]; $i++; } } } if ($open_error) { $save_results[$i]=$open_error; } return $save_results; }
if (!is_readable($phpcrontab_filename)) { $option_errors= "ERROR: Phpcrontab configuration file $crontab_stripped cannot be read. Please create and/or check permissions and try again. See the readme.txt file for more information.\r\n\n<br>"; $fatal_error=true; } //Make Sure That given file name is Not a parameter if(preg_match("/^-.*$/",basename($log_result_file))) { $option_errors.="ERROR: Make sure -l has a valid file name as an additional parameter\r\n"; } //Check validity of $log_result_file directory $path_errors=isPathbad($log_result_file); /*Extract directory name from file name and check to see whether we can use it */ if($path_errors["directory"]) { $ps_info=getProcessInfo(); $option_errors .= "ERROR: Invalid Log Path - Make sure that $base_logresult_stripped is a valid file name and $dir_logresult_stripped exists and allows the user to read and write to it. \r\n\t<br>"; $fatal_error=true; //cause program to exit } //Check Validity of Notification Email Address
function fullEditBox($file_name, $box_title){ global $admin_subpage; global $PHP_SELF; global $modified_contents; global $mc_rows; global $fe_save_error; global $full_edit_title; global $secure; if($path_errors=isPathbad($file_name, true, true)) { 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 $file_name because of file errors:<br></h3>".$error_messages; //if path errors, echo message and retur if (!is_readable($file_name)){ echoErrorMessages($error_messages); echo $output; return; } } //Empty file into array $file_array=file($file_name); if ($fe_save_error) { //if previously bad save, display modified contents that weren't saved $file_string=$modified_contents; } else { //Implode file_array to put string in text area element $file_string=addslashes(trim(implode("",$file_array))); //Set number of rows if ($file_array) { $total_lines=count($file_array); } $mc_rows=$total_lines+10; } //Build output $output=" <!--*********** Begin Full Edit Box For $file_name************--> <br> <table border=\"1\" cellpadding=\"2\" width=\"600px\" cellspacing=\"0\" align=\"center\"> <tr> <td align=center style=$full_edit_title colspan=7 > <h3> $box_title <br><br> (edit ".chunk_split(formatPath($file_name), 20, " ").") <br> </h3> </td> </tr> <tr> <td style=$full_edit_title> <form action=\"$PHP_SELF\" method=\"post\"> <div align=\"center\"> <textarea name=\"modified_contents\" wrap=\"off\" cols=\"80\" rows=\"$mc_rows\" class=\"fulledit\">".stripslashes($file_string)." </textarea> </div> <HR> <input type=\"submit\" value=\"Save\">"; if (!$secure) { $output.= "<input type=\"submit\" value=\"Save As:\"> <input type=\"text\" class=\"color\" name=\"new_filename\">"; } $output.=" <br> Check to Save Over Existing File: <input type=\"checkbox\" name=\"overwrite\" value=\"true\" class=\"title\"> <input type=\"hidden\" class=\"color\" name=\"current_filename\" value=\"$file_name\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"$admin_subpage\"> <input type=\"hidden\" name=\"mc_rows\" value=\"$mc_rows\"> </form> <form action=\"$PHP_SELF\" method=\"post\"> <input type=\"submit\" value=\"Reload Current File\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"$admin_subpage\"> </form> <HR> Current File: ".formatPath($file_name)." </td> </tr> </table> <br> <!--*********** End Full Edit Box For $file_name*************--> "; if($error_messages) { echoErrorMessages($error_messages); } echo $output; }