function net2ftp_module_sendHttpHeaders() { // -------------- // This function sends HTTP headers // -------------- global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output; // ------------------------------------ // 1. Register the global variables // ------------------------------------ if ($net2ftp_globals["screen"] == 2) { // Code for old file jupload applet (jupload version 0.86) // $file_counter = 0; // foreach($_FILES as $tagname=>$object) { // if ($object['name'] != "") { // $file_counter = $file_counter + 1; // $uploadedFilesArray["$file_counter"]["name"] = $object['name']; // $uploadedFilesArray["$file_counter"]["tmp_name"] = $object['tmp_name']; // $uploadedFilesArray["$file_counter"]["size"] = $object['size']; // $uploadedFilesArray["$file_counter"]["error"] = $object['error']; // // Look for special encoded jupload files // $contentType = $object['type']; // if (substr($contentType,0,7) == "jupload") { // $base64_encoded_path = substr($contentType,8); // $base64_decoded_path = base64_decode($base64_encoded_path); // $uploadedFilesArray["$file_counter"]["absolute_directory"] = $base64_decoded_path; // } // end if // } // end if // } // end foreach // Code for new file jupload applet (jupload version 5.0.8) $file_counter = 0; foreach ($_FILES as $tagname => $object) { if ($object['name'] != "") { $file_counter = $file_counter + 1; $uploadedFilesArray["{$file_counter}"]["name"] = $object['name']; $uploadedFilesArray["{$file_counter}"]["type"] = $object['type']; $uploadedFilesArray["{$file_counter}"]["tmp_name"] = $object['tmp_name']; $uploadedFilesArray["{$file_counter}"]["error"] = $object['error']; $uploadedFilesArray["{$file_counter}"]["size"] = $object['size']; $uploadedFilesArray["{$file_counter}"]["mime"] = validateEntry($_POST["mimetype" . $file_counter]); $uploadedFilesArray["{$file_counter}"]["relative_directory"] = validateDirectory($_POST["relpathinfo" . $file_counter]); $uploadedFilesArray["{$file_counter}"]["mtime"] = validateEntry($_POST["filemodificationdate" . $file_counter]); } // end if } // end foreach echo "Please wait, the files are being transferred to the FTP server...<br />\n"; flush(); // ------------------------------------ // 2. POST METHOD: Move files from the *webserver's* temporary directory to *net2ftp's* // temporary directory (move_uploaded_files). // ------------------------------------ if ($_SERVER["REQUEST_METHOD"] == "POST" && sizeof($uploadedFilesArray) > 0) { $moved_counter = 0; for ($j = 1; $j <= sizeof($uploadedFilesArray); $j++) { $file_name = $uploadedFilesArray["{$j}"]["name"]; $file_tmp_name = $uploadedFilesArray["{$j}"]["tmp_name"]; $file_size = $uploadedFilesArray["{$j}"]["size"]; $file_error = $uploadedFilesArray["{$j}"]["error"]; $file_relative_directory = $uploadedFilesArray["{$j}"]["relative_directory"]; if ($file_name != "" && $file_tmp_name == "" || $file_size > $net2ftp_settings["max_filesize"]) { // The case ($file_name != "" && $file_tmp_name == "") occurs when the file is bigger than the directives set in php.ini // In that case, only $uploadedFilesArray["$j"]["name"] is filled in. echo "WARNING: File <b>{$file_name}</b> skipped: this file is too big.<br />\n"; @unlink($file_tmp_name); continue; } elseif (checkAuthorizedName($file_name) == false || checkAuthorizedName($file_relative_directory) == false) { echo "WARNING: File <b>{$file_relative_directory}</b> skipped: it contains a banned keyword.<br />\n"; $skipped = $skipped + 1; @unlink($file_tmp_name); continue; } // Create the temporary filename as follows: (from left to right) // - Use prefix "upload__", to be able to identify from where this temporary file comes from // - Create a random filename // - Add the original filename extension, to be able to identify the filetype // - Add suffix ".txt" to avoid that the file would be executed on the webserver $extension = get_filename_extension($file_name); if (substr($file_name, -6) == "tar.gz") { $extension = "tar.gz"; } $tempfilename = tempnam2($net2ftp_globals["application_tempdir"], "upload__", "." . $extension . ".txt"); if ($tempfilename == false) { // If you get this warning message, you've probably forgotten to chmod 777 the /temp directory echo "WARNING: File <b>{$file_name}</b> skipped: unable to create a temporary file on the webserver.<br />\n"; @unlink($file_tmp_name); continue; } // Move the uploaded file $move_uploaded_file_result = move_uploaded_file($uploadedFilesArray["{$j}"]["tmp_name"], $tempfilename); if ($move_uploaded_file_result == false) { echo "WARNING: File <b>{$file_name}</b> skipped: unable to move the uploaded file to the webserver's temporary directory.<br />\n"; @unlink($file_tmp_name); @unlink($tempfilename); continue; } else { $moved_counter = $moved_counter + 1; $acceptedFilesArray["{$moved_counter}"] = $uploadedFilesArray["{$j}"]; // Copy all parameters for this file from the $uploadedFilesArray to the $acceptedFilesArray $acceptedFilesArray["{$moved_counter}"]["tmp_name"] = $tempfilename; // Overwrite the old temporary name by the new one } } // end for j flush(); } // end if elseif // ------------------------------------ // 3. Move the files from net2ftp's temporary directory to the FTP server. // ------------------------------------ if (sizeof($acceptedFilesArray) == 0 && sizeof($uploadedFilesArray) != 0) { echo "WARNING: No files were accepted (see messages above), so nothing will be transferred to the FTP server.<br />\n"; } elseif (sizeof($acceptedFilesArray) > 0) { // ------------------------------ // 3.1 Open connection // ------------------------------ // Open connection echo __("Connecting to the FTP server") . "<br />\n"; $conn_id = ftp_openconnection(); if ($net2ftp_result["success"] == false) { echo "ERROR: " . $net2ftp_result["errormessage"] . "<br />\n"; return false; } // ------------------------------ // For loop (loop over all the files) // ------------------------------ for ($k = 1; $k <= sizeof($acceptedFilesArray); $k++) { $file_name = $acceptedFilesArray["{$k}"]["name"]; $file_tmp_name = $acceptedFilesArray["{$k}"]["tmp_name"]; $file_size = $acceptedFilesArray["{$k}"]["size"]; $file_error = $acceptedFilesArray["{$k}"]["error"]; $file_relative_directory = $acceptedFilesArray["{$k}"]["relative_directory"]; $ftpmode = ftpAsciiBinary($file_name); if ($ftpmode == FTP_ASCII) { $printftpmode = "FTP_ASCII"; } elseif ($ftpmode == FTP_BINARY) { $printftpmode = "FTP_BINARY"; } // ------------------------------ // 3.2 Within the for loop: create the subdirectory if needed // ------------------------------ // Replace Windows-style backslashes \ by Unix-style slashes / $file_relative_directory = str_replace("\\", "/", trim($file_relative_directory)); // Get the names of the subdirectories by splitting the string using slashes / $file_subdirectories = explode("/", $file_relative_directory); // $targetdirectory contains the successive directories to be created $targetdirectory = $net2ftp_globals["directory"]; // Loop over sizeof()-1 because the last part is the filename itself: for ($m = 0; $m < sizeof($file_subdirectories) - 1; $m++) { // Create the targetdirectory string $targetdirectory = glueDirectories($targetdirectory, $file_subdirectories[$m]); // Check if the subdirectories exist if ($targetdirectory != "") { $result = @ftp_chdir($conn_id, $targetdirectory); if ($result == false) { $ftp_mkdir_result = ftp_mkdir($conn_id, $targetdirectory); if ($ftp_mkdir_result == false) { echo "WARNING: Unable to create the directory <b>{$targetdirectory}</b>. The script will try to continue...<br />\n"; continue; } echo "Directory {$targetdirectory} created.<br />\n"; } // end if flush(); } // end if } // end for m // Store the $targetdirectory in the $acceptedFilesArray if ($targetdirectory != "" && $targetdirectory != "/") { $acceptedFilesArray["{$k}"]["targetdirectory"] = $targetdirectory; } // ------------------------------ // 3.3 Within the for loop: put local file to remote file // ------------------------------ ftp_putfile($conn_id, "", $acceptedFilesArray["{$k}"]["tmp_name"], $acceptedFilesArray["{$k}"]["targetdirectory"], $acceptedFilesArray["{$k}"]["name"], $ftpmode, "move"); if ($net2ftp_result["success"] == false) { echo "ERROR: File <b>{$file_name}</b> skipped. Message: " . $net2ftp_result["errormessage"] . "<br />\n"; setErrorVars(true, "", "", "", ""); continue; } else { echo "The file <b>{$file_name}</b> was transferred to the FTP server successfully. <br />\n"; } flush(); } // End for k // Note: the java applet is looking for the word "SUCCESS" to determine if the upload result is OK or not (see applet parameter stringUploadSuccess) // The applet doesn't seem to recognize the words "SUCCESS", "WARNING" or "ERROR" when they are issued by the code above echo "SUCCESS"; // ------------------------------ // 3.4 Close connection // ------------------------------ ftp_quit($conn_id); } // end if } // end if $screen == 2 }
$net2ftp_globals["cookie_passivemode"] = validatePassivemode($_COOKIE["net2ftpcookie_passivemode"]); } else { $net2ftp_globals["cookie_passivemode"] = ""; } if (isset($_COOKIE["net2ftpcookie_sslconnect"]) == true) { $net2ftp_globals["cookie_sslconnect"] = validateSslconnect($_COOKIE["net2ftpcookie_sslconnect"]); } else { $net2ftp_globals["cookie_sslconnect"] = ""; } if (isset($_COOKIE["net2ftpcookie_viewmode"]) == true) { $net2ftp_globals["cookie_viewmode"] = validateViewmode($_COOKIE["net2ftpcookie_viewmode"]); } else { $net2ftp_globals["cookie_viewmode"] = ""; } if (isset($_COOKIE["net2ftpcookie_directory"]) == true) { $net2ftp_globals["cookie_directory"] = validateDirectory($_COOKIE["net2ftpcookie_directory"]); } else { $net2ftp_globals["cookie_directory"] = ""; } if (isset($_COOKIE["net2ftpcookie_sort"]) == true) { $net2ftp_globals["cookie_sort"] = validateSort($_COOKIE["net2ftpcookie_sort"]); } else { $net2ftp_globals["cookie_sort"] = ""; } if (isset($_COOKIE["net2ftpcookie_sortorder"]) == true) { $net2ftp_globals["cookie_sortorder"] = validateSortorder($_COOKIE["net2ftpcookie_sortorder"]); } else { $net2ftp_globals["cookie_sortorder"] = ""; } // ------------------------------------------------------------------------- // 7 Get information about the browser and protocol
$ftpserver = validateGenericInput($_POST["ftpserver"]); } if (isset($_POST["ftpserverport"]) == true) { $ftpserverport = validateGenericInput($_POST["ftpserverport"]); } if (isset($_POST["username"]) == true) { $username = validateGenericInput($_POST["username"]); } if (isset($_POST["password"]) == true) { $password = validateGenericInput($_POST["password"]); } if (isset($_POST["passivemode"]) == true) { $passivemode = validateGenericInput($_POST["passivemode"]); } if (isset($_POST["targetdirectory"]) == true) { $targetdirectory = validateDirectory($_POST["targetdirectory"]); } if (isset($_POST["screen"]) == true) { $screen = validateGenericInput($_POST["screen"]); } if (isset($_SERVER["SCRIPT_NAME"]) == true) { $php_self = $_SERVER["SCRIPT_NAME"]; } elseif (isset($_SERVER["PHP_SELF"]) == true) { $php_self = $_SERVER["PHP_SELF"]; } $tempdir = dirname(__FILE__) . "/net2ftp_temp_06er8"; // -------------------------------------------------------------------------------- // HTML start // -------------------------------------------------------------------------------- ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
function net2ftp_module_printBody() { // -------------- // This function prints the login screen // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output; if (isset($_POST["troubleshoot_ftpserver"]) == true) { $troubleshoot_ftpserver = validateFtpserver($_POST["troubleshoot_ftpserver"]); } else { $troubleshoot_ftpserver = ""; } if (isset($_POST["troubleshoot_ftpserverport"]) == true) { $troubleshoot_ftpserverport = validateFtpserverport($_POST["troubleshoot_ftpserverport"]); } else { $troubleshoot_ftpserverport = ""; } if (isset($_POST["troubleshoot_username"]) == true) { $troubleshoot_username = validateUsername($_POST["troubleshoot_username"]); } else { $troubleshoot_username = ""; } if (isset($_POST["troubleshoot_password"]) == true) { $troubleshoot_password = validatePassword($_POST["troubleshoot_password"]); } else { $troubleshoot_password = ""; } if (isset($_POST["troubleshoot_directory"]) == true) { $troubleshoot_directory = validateDirectory($_POST["troubleshoot_directory"]); } else { $troubleshoot_directory = ""; } if (isset($_POST["troubleshoot_passivemode"]) == true) { $troubleshoot_passivemode = validatePassivemode($_POST["troubleshoot_passivemode"]); } else { $troubleshoot_passivemode = ""; } $troubleshoot_ftpserver_html = htmlEncode2($troubleshoot_ftpserver); $troubleshoot_ftpserverport_html = htmlEncode2($troubleshoot_ftpserverport); $troubleshoot_username_html = htmlEncode2($troubleshoot_username); $troubleshoot_directory_html = htmlEncode2($troubleshoot_directory); $troubleshoot_passivemode_html = htmlEncode2($troubleshoot_passivemode); // ------------------------------------------------------------------------- // Variables for all screens // ------------------------------------------------------------------------- // Title $title = __("Troubleshoot an FTP server"); // Form name $formname = "AdvancedForm"; // ------------------------------------------------------------------------- // Variables for screen 1 // ------------------------------------------------------------------------- if ($net2ftp_globals["screen"] == 1) { // Next screen $nextscreen = 2; // Back and forward buttons $back_onclick = "document.forms['" . $formname . "'].state.value='advanced';document.forms['" . $formname . "'].screen.value='1';document.forms['" . $formname . "'].submit();"; $forward_onclick = "document.forms['" . $formname . "'].submit();"; } elseif ($net2ftp_globals["screen"] == 2) { // Back and forward buttons $back_onclick = "document.forms['" . $formname . "'].state.value='advanced_ftpserver'; document.forms['" . $formname . "'].submit();"; // Initial checks if ($troubleshoot_passivemode != "yes") { $troubleshoot_passivemode = "no"; } // Connect setStatus(1, 10, __("Connecting to the FTP server")); $conn_id = ftp_connect("{$troubleshoot_ftpserver}", $troubleshoot_ftpserverport); // Login with username and password setStatus(2, 10, __("Logging into the FTP server")); $ftp_login_result = ftp_login($conn_id, $troubleshoot_username, $troubleshoot_password); // Passive mode if ($troubleshoot_passivemode == "yes") { setStatus(3, 10, __("Setting the passive mode")); $ftp_pasv_result = ftp_pasv($conn_id, TRUE); } else { $ftp_pasv_result = true; } // Get the FTP system type setStatus(4, 10, __("Getting the FTP system type")); $ftp_systype_result = ftp_systype($conn_id); // Change the directory setStatus(5, 10, __("Changing the directory")); $ftp_chdir_result = ftp_chdir($conn_id, $troubleshoot_directory); // Get the current directory from the FTP server setStatus(6, 10, __("Getting the current directory")); $ftp_pwd_result = ftp_pwd($conn_id); // Try to get a raw list setStatus(7, 10, __("Getting the list of directories and files")); $ftp_rawlist_result = ftp_rawlist($conn_id, "-a"); if (sizeof($ftp_rawlist_result) <= 1) { $ftp_rawlist_result = ftp_rawlist($conn_id, ""); } // Parse the list setStatus(8, 10, __("Parsing the list of directories and files")); for ($i = 0; $i < sizeof($ftp_rawlist_result); $i++) { $parsedlist[$i] = ftp_scanline($troubleshoot_directory, $ftp_rawlist_result[$i]); } // end for // Quiting; ftp_quit doesn't return a value setStatus(9, 10, __("Logging out of the FTP server")); ftp_quit($conn_id); } // end if // ------------------------------------------------------------------------- // Print the output // ------------------------------------------------------------------------- setStatus(10, 10, __("Printing the result")); require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php"; }
function net2ftp_module_sendHttpHeaders() { // -------------- // This function sends HTTP headers // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result; // ------------------------------------------------------------------------- // Construct the symlink target // ------------------------------------------------------------------------- // A symlink has $entry = FreeBSD -> mirror/ftp.freebsd.org/pub/FreeBSD // Get the 2nd part, after the -> $pos = strpos($net2ftp_globals["entry"], " -> "); $entry_part2 = substr($net2ftp_globals["entry"], $pos + 4); // Glue the current directory with the symlink // and resolve the .. which it may contain (this is done by validateDirectory) $symlinktarget = validateDirectory(glueDirectories($net2ftp_globals["directory"], $entry_part2)); // ------------------------------------------------------------------------- // Check if the symlink points to a directory // ------------------------------------------------------------------------- // ------------------------------------ // Open connection // ------------------------------------ $conn_id = ftp_openconnection(); if ($net2ftp_result["success"] == false) { return false; } // ------------------------------------ // Get raw list of directories and files // ------------------------------------ $list = ftp_getlist($conn_id, $symlinktarget); if ($net2ftp_result["success"] == false) { $is_directory = false; setErrorVars(true, "", "", "", ""); } else { $is_directory = true; } // ------------------------------------ // Close connection // ------------------------------------ ftp_closeconnection($conn_id); // ------------------------------------------------------------------------- // Directory (main or popup): redirect to Browse page // ------------------------------------------------------------------------- if ($is_directory == true) { $action_url = printPHP_SELF("actions"); $action_url = str_replace("&", "&", $action_url); header("Location: " . $action_url . "&state=browse&state2=" . $net2ftp_globals["state2"] . "&directory=" . $symlinktarget); } elseif ($net2ftp_globals["state2"] == "popup") { $action_url = printPHP_SELF("actions"); $action_url = str_replace("&", "&", $action_url); header("Location: " . $action_url . "&state=browse&state2=" . $net2ftp_globals["state2"] . "&directory=" . $net2ftp_globals["directory"]); } elseif ($net2ftp_globals["state2"] == "main") { if ($net2ftp_settings["functionuse_downloadfile"] == "yes") { $newdirectory = dirname($symlinktarget); $newfile = basename($symlinktarget); ftp_downloadfile($newdirectory, $newfile); } else { $errormessage = __("This function has been disabled by the Administrator of this website."); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } } }