* * Last Modified: 15th July 2003 * */ error_reporting(0); if (!(include("./modules/header.lib.php"))) { die("
There was an error loading the header module
"); } // Get the variables $op = param("op", "GET"); if(empty($op)) { $op = param("op", "POST"); } $dir = param("dir", "GET"); if(empty($dir)) { $dir = param("dir", "POST"); } $dir = cleanpath($dir); $file = cleanpath(param("f", "GET")); if (eregi("win", PHP_OS) == TRUE) { // Check for / in the URL even though the system is Windows (i.e. the user is using Opera) $dir = str_replace("/", "\\", $dir); } if ($op == "edit") { $full = $dir != "" ? $params["root"] . $dir . $slash . $file : $params["root"] . $file; // Get the full path $ext = ext($file); // Get the file extension if ($params["edit"] != 1) { // The user isn't allowed to edit files redirect($scripts["main"] . "?msg=no_per_edit&dir=$dir"); } else if ($file == "") { // The user didn't select a file to edit redirect($scripts["main"] . "?msg=no_file_edit&dir=$dir"); } else if (file_exists($full) == FALSE) { // The file doesn't exist redirect($scripts["main"] . "?msg=not_exist&dir=$dir"); } else if ($hide_dot == TRUE && ereg("^\.", basename($full)) == TRUE) { // The file is a hidden file redirect($scripts["main"] . "?msg=dot_hide&dir=$dir"); } else if (in_array($ext, $ascii) == FALSE && $ext != "") { // The file can not be edited redirect($scripts["main"] . "?msg=no_edit&dir=$dir"); } else if ($ext == "" && $no_ext == 0) { // The file can not be edited redirect($scripts["main"] . "?msg=no_edit&dir=$dir"); } else { // Set some more values $edit["icon"] = get_icon(basename($full)); $edit["is_new"] = 0; $edit["next_dir"] = str_replace("\\", "/", $dir); $edit["title"] = $edit["edit"] . " "". $file . """; $edit["wrap"] = $javascript["disable_wrap"]; $edit["filename"] = $file; if (file_exists($full . ".fileman") == TRUE && $edit_lock == TRUE) { // Check to see if the lock file has been in place for more than 5 minutes $time = time() - 300; $left = filemtime($full . ".fileman") - $time; // If the amount of time left is less than or equal to 0 unlock the file if ($left <= 0) { unlink($full . ".fileman"); } } if (file_exists($full . ".fileman") == TRUE && $edit_lock == TRUE) { // The file still exists, so the lock is in place redirect($scripts["main"] . "?msg=locked&dir=$dir"); } else if (($fp = fopen($full, "r")) == FALSE) { // The file couldn't be opened redirect($scripts["main"] . "?msg=open_err&dir=$dir"); } else { // Read the data and then reset the chmod $fdata = fread($fp, filesize($full)); fclose($fp); // Convert entities so they display correctly $fdata = str_replace("", "</textarea>", $fdata); // A small fix so that the form isn't screwed up $fdata = preg_replace("/&(.+?);/", "&\\1;", $fdata); $fdata = str_replace("\\", "\\\\", $fdata); if ($edit_lock == TRUE) { // Create the locked file $fp = fopen($full . ".fileman", "w"); fwrite($fp, "File is locked"); fclose($fp); chmod($full . ".fileman", 0777); } } } } else if ($op == "cancel") { // Cancel the file edit, delete the lock file if ($edit_lock == TRUE) { // Remove the lock file $locked = $dir != "" ? $params["root"] . $dir . $slash . cleanpath(param("oldname", "POST")) : $params["root"] . cleanpath(param("oldname", "POST")); unlink($locked . ".fileman"); } // Redirect to the main script redirect($scripts["main"]); } else if ($op == "new") { if ($params["newfile"] != 1) { // The user isn't allowed to create new files redirect($scripts["main"] . "?msg=no_per_new_file&dir=$dir"); } // Get the template $key = param("templates", "POST"); $template = $script_dir . "/templates/" . $temp_name[$key] . ".tpl"; // Create the new filename if ($key == 0) { $edit["filename"] = $edit["new_file"] . ".txt"; } else { $edit["filename"] = $edit["new_file"] . "." . $temp_extension[$key]; } $edit["wrap"] = $javascript["disable_wrap"]; $edit["title"] = $edit["edit"] . " "". $edit["filename"] . """; $edit["icon"] = get_icon($edit["filename"]); $edit["is_new"] = 1; $edit["next_dir"] = str_replace("\\", "/", $dir); // Read the template file if ($key == 0 || ($fp = fopen($template, "r")) == FALSE) { $fdata = ""; } else { $fdata = fread($fp, filesize($template)); fclose($fp); } } else if ($op == "update") { // Get the file name if (param("filename", "POST") == "") { $filename = param("oldname", "POST"); } else { $filename = param("filename", "POST"); } $filename = cleanpath($filename); // Get the data and convert it back to normal $fdata = param("fdata", "POST"); $fdata = str_replace("</textarea>", "", $fdata); $fdata = preg_replace("/&(.+?);/", "&\\1;", $fdata); $full = $dir != "" ? $params["root"] . $dir . $slash . $filename : $params["root"] . $filename; // Get the full path if ($edit_lock == TRUE) { // Remove the lock file $locked = $dir != "" ? $params["root"] . $dir . $slash . cleanpath(param("oldname", "POST")) : $params["root"] . cleanpath(param("oldname", "POST")); unlink($locked . ".fileman"); } // Check that the user has enough space if (strlen($fdata) + dirsize($params["root"]) > $params["space"]) { // The user doesn't have enough free space redirect($scripts["main"] . "?msg=no_space&dir=$dir"); } // The user is making a new file, or has changed the name of an old file if (param("fileisnew", "POST") == 1 || cleanpath(param("oldname", "POST")) != cleanpath(param("filename", "POST"))) { if ($params["newfile"] != 1) { // The user isn't allowed to create new files redirect($scripts["main"] . "?msg=no_per_new_file&dir=$dir"); } else if (file_exists($full) && $params["overwrite"] != 1) { // The user can't overwrite files redirect($scripts["main"] . "?msg=no_per_over&dir=$dir"); } else if ((file_exists($full) && eregi("^\.", basename($full)) == TRUE && $hide_dot == TRUE) || eregi("\.fileman$", basename($full)) == TRUE) { // The user is trying to overwrite a hidden file redirect($scripts["main"] . "?msg=dot_hide&dir=$dir"); } else if (($fp = fopen($full, "w")) == FALSE) { // The file couldn't be opened redirect($scripts["main"] . "?msg=save_err&dir=$dir"); } else { // Write the data and then set the chmod fwrite($fp, $fdata); fclose($fp); chmod ($full, octdec((int) $new_chmod)); // The file was saved! redirect($scripts["main"] . "?msg=save_new&dir=$dir"); } } else { if (($fp = fopen($full, "w")) == FALSE) { // The file couldn't be opened redirect($scripts["main"] . "?msg=save_err&dir=$dir"); } else { // Write the data fwrite($fp, $fdata); fclose($fp); // The file was saved! redirect($scripts["main"] . "?msg=saved&dir=$dir"); } } } else { // Send the user back to the main page redirect($scripts["main"]); } $data = template($edit, $script_dir . "/settings/templates/edit.tpl"); $page = array("javascript" => template($javascript, $script_dir . "/settings/templates/javascript/edit.js"), "content" => $data, "title" => $edit["title"], "this" => $PHP_SELF, "copyright" => $copyright, "areas" => area_buttons(), "fdata" => $fdata); // Finish up by outputting the completed page template($page, $script_dir . "/settings/templates/global.tpl"); ?>