//By default this script will allow you to edit all the files in $filedir that
//have extensions in the valid_ext array and are writable. It also allows you
//to edit all the files that are writable and have valid extensions in the sub
//folders of $filedir. In other words, it recursively searches for files you
//can edit in $filedir. If you wish to change this behavior, so that it only
//stays in $filedir and doesn't drill down to any of its subdirs,--search for
//$filelist = directoryToArray($filedir, true); and change true to false.
//YOU MUST CHANGE THIS VARIABLE!! Specify the full path to the directory of
//files you wish to be able to edit. NO TRAILING SLASH.
$filedir = "/home/dustin/public_html";
//Valid Extension array.
//The array below lists the extensions files must have in order to
//show up in the selection drop down box of fileed.php. NOTE: In order for you
//to be able to edit a file it must have an extension in the array below and
//must be writable (chmoded 666). It must also be in the $filedir folder or
//in a subfolder in the $filedir folder. All folders that the script must
//transverse in order to reach your file must be chmoded at least 555. To
//add a new extenstion to this array do the following:
//1. Copy the bottom valid_ext line. Insert a new line below it
// (hit enter). Paste the line you copied.
//2. Increase [x] by one.
//3. Change the text inside the quotes to the extension you want to allow.
// Case must match exactly.
//4. Save your changes.
$valid_ext[0] = "TXT";
$valid_ext[1] = "txt";
$valid_ext[2] = "htm";
$valid_ext[3] = "HTM";
$valid_ext[4] = "html";
$valid_ext[5] = "HTML";
$valid_ext[6] = "shtm";
$valid_ext[7] = "SHTM";
$valid_ext[8] = "shtml";
$valid_ext[9] = "SHTML";
$valid_ext[10] = "pl";
$valid_ext[11] = "PL";
$valid_ext[12] = "cgi";
$valid_ext[13] = "CGI";
$valid_ext[14] = "CSS";
$valid_ext[15] = "css";
$valid_ext[16] = "conf";
$valid_ext[17] = "CONF";
$valid_ext[18] = "ASP";
$valid_ext[19] = "asp";
$valid_ext[20] = "JSP";
$valid_ext[21] = "jsp";
$valid_ext[22] = "js";
$valid_ext[23] = "JS";
$valid_ext[24] = "php";
$valid_ext[25] = "PHP";
$valid_ext[26] = "php3";
$valid_ext[27] = "PHP3";
$valid_ext[28] = "PHTML";
$valid_ext[29] = "phtml";
$valid_ext[30] = "ini";
$valid_ext[31] = "INI";
$valid_ext[32] = "cfm";
$valid_ext[33] = "CFM";
$valid_ext[34] = "inc";
$valid_ext[35] = "INC";
//That should cover what most people use! I hope anyhow :)
//The following password auth code was contributed by spaghettilogic.org.
//Note: It is rather simple and really shouldn't be used on sites
//that have highly sensitive information or by people that have lots of
//enimies; as it doesn't do hashing, brute force prevention, log outs, etc.
//None the less, it is a great addition for small sites! They can use it instead
//of or in addition to an htaccess file. Thanks for the code James!
$password_enabled = 'false'; //Change to 'true' to enable passwords
$password = 'password'; //If you enable passwords, change this!
if($password_enabled == 'true'){
session_start(); //Enable cookies
//If neither password nor cookie is present
if($_POST['password']!= $password && $_SESSION['password'] != $password){
print '
Simple File Editor
Simple File Editor
';
return;
}elseif($_POST['password'] == $password && $_SESSION['password'] != $password){
//If password is present but cookie has not been set
$_SESSION['password'] = $password;
}
}
//You should not have to change anything below this line.
//IF browser does not send a POST request (ie: if open/save has not been
//pressed) then display the form and the list of files.
if(!$_POST['open'] && !$_POST['save']){
//if ($_SERVER['REQUEST_METHOD'] != 'POST'){
//If filedir is readable do...
if (is_readable($filedir)) {
?>
Simple File Editor
Simple File Editor
}
else
{
//If directory can't be opened complain
echo "
Simple File Editor: ERROR!
Simple File Editor: ERROR!
Could not open directory!! Permissions Problem??
";
}
}
///////////////////////////////////////////////////////////////////
//If the open button has been pressed
////////////////////////////////////////////////////////////////////
else if (isset($_POST['open'])){
//If the file can be opened and is writable do....
//This should not be needed because files that aren't writable should
//have never been shown in the selection box.
if (is_writable($_POST["the_file"])) {
//Start page
//INFO for below: Since variable data is not saved across multiple
//form posts-- we must create a hidden input box with the same value as the
//select box on the previous form. That way the 3rd and final form (ie: the
//saving process) can use the same variable as the first form (read: write to
//the file you choose in the select box.)
?>
Simple File Editor: File Opened
Simple File Editor: File Opened
}
else
{
//If file can't be opened complain
echo "
Simple File Editor: ERROR!
Simple File Editor: ERROR!
Could not open file!! Permissions Problem??
";
}
}
///////////////////////////////////////////////////////
//If save button has been pushed....
//////////////////////////////////////////////////////
else if (isset($_POST['save'])){
//If the file can be opened and is writable do....
//This should not be needed because files that aren't writable should
//have never been shown in the selection box. And should not have been opened
//on the previous page.
if (is_writable($_POST["the_file2"])) {
//Get variable data for the file we are working with from the hidden input box
//in the previous form. Then open it.
$file2ed = fopen($_POST["the_file2"], "w+");
//Dirty hack part 2. Copy all of the data in the previous forms
//editing textarea to the variable $data_to_save.
$data_to_save = $_POST["updatedfile"];
//Do the opposite of above. This time convert the [/textarea] tag you
//see in the editing form back to its proper tag so when your files
//are saved the forms on them will still look/work right.
#$data_to_save = eregi_replace("", "", $data_to_save);
//The following code was contributed by anoldman.com. Thanks for modernizing
//and dealing with this issue in a more logical fashion Ken!
$data_to_save = preg_replace( "!\[textarea([^\]]+)\](.*?)\[/textarea\]!is", "", $data_to_save );
//Remove any slashes that may be added do to " ' " s. Thats a single tick, btw.
//NOTE: If you want to work on files that have slashes in them, comment out the
//line below.
$data_to_save = stripslashes($data_to_save);
//Get the data to write from the previously posted text area, plus all the
//processing we did on it above. Write the changes to the file.
if (fwrite($file2ed,$data_to_save)) {
//If write is successful show success page.
echo "
Simple File Editor: File Saved