示例#1
0
function ftp_unziptransferfiles($archivesArray)
{
    // --------------
    // Extract the directories and files from the archive to a temporary directory on the web server, and
    // then create the directories and put the files on the FTP server
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_globals, $net2ftp_result, $net2ftp_output;
    // -------------------------------------------------------------------------
    // Open connection
    // -------------------------------------------------------------------------
    $conn_id = ftp_openconnection();
    if ($net2ftp_result["success"] == false) {
        for ($archive_nr = 1; $archive_nr <= sizeof($archivesArray); $archive_nr++) {
            @unlink($archivesArray[$archive_nr]["tmp_name"]);
        }
        return false;
    }
    // -------------------------------------------------------------------------
    // For each archive...
    // -------------------------------------------------------------------------
    for ($archive_nr = 1; $archive_nr <= sizeof($archivesArray); $archive_nr++) {
        // Set status
        setStatus($archive_nr, sizeof($archivesArray), __("Decompressing archives and transferring files"));
        // -------------------------------------------------------------------------
        // Determine the type of archive depending on the filename extension
        // -------------------------------------------------------------------------
        $archive_name = $archivesArray[$archive_nr]["name"];
        $archive_file = $archivesArray[$archive_nr]["tmp_name"];
        $archivename_without_dottext = substr($archivesArray[$archive_nr]["tmp_name"], 0, strlen($archive) - 4);
        $archive_type = get_filename_extension($archivename_without_dottext);
        $net2ftp_output["ftp_unziptransferfiles"][] = __("Processing archive nr %1\$s: <b>%2\$s</b>", $archive_nr, $archive_name);
        $net2ftp_output["ftp_unziptransferfiles"][] = "<ul>";
        if ($archive_type != "zip" && $archive_type != "tar" && $archive_type != "tgz" && $archive_type != "gz") {
            $net2ftp_output["ftp_unziptransferfiles"][] = __("Archive <b>%1\$s</b> was not processed because its filename extension was not recognized. Only zip, tar, tgz and gz archives are supported at the moment.", $archive_name);
            continue;
        }
        // -------------------------------------------------------------------------
        // Extract directories and files
        // -------------------------------------------------------------------------
        // ------------------------------
        // Check list of files to see if there are any malicious filenames
        // ------------------------------
        if ($archive_type == "zip") {
            $zip = new PclZip($archive_file);
            $list_to_check = $zip->listContent();
        } elseif ($archive_type == "tar" || $archive_type == "tgz" || $archive_type == "gz") {
            $list_to_check = PclTarList($archive_file);
        }
        if ($list_to_check <= 0) {
            $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to extract the files and directories from the archive");
            continue;
        }
        for ($i = 0; $i < sizeof($list_to_check); $i++) {
            $source = trim($list_to_check[$i]["filename"]);
            if (strpos($source, "../") !== false || strpos($source, "..\\") !== false) {
                $errormessage = __("Archive contains filenames with ../ or ..\\ - aborting the extraction");
                setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                return false;
            }
        }
        // ------------------------------
        // Generate random directory
        // ------------------------------
        $tempdir = tempdir2($net2ftp_globals["application_tempdir"], "unzip__", "");
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        registerTempfile("register", "{$tempdir}");
        // ------------------------------
        // Extract
        // ------------------------------
        if ($archive_type == "zip") {
            $zip = new PclZip($archive_file);
            $list = $zip->extract($p_path = $tempdir);
        } elseif ($archive_type == "tar" || $archive_type == "tgz" || $archive_type == "gz") {
            $list = PclTarExtract($archive_file, $tempdir);
        }
        // This code is not needed any more - see above: if ($list_to_check <= 0)
        if ($list <= 0) {
            //			$net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to extract the files and directories from the archive");
            continue;
        }
        // ------------------------------
        // Create the directories and put the files on the FTP server
        // ------------------------------
        for ($i = 0; $i < sizeof($list); $i++) {
            $source = trim($list[$i]["filename"]);
            $unzip_status = trim($list[$i]["status"]);
            $target_relative = substr($source, strlen($tempdir));
            $target = $net2ftp_globals["directory"] . $target_relative;
            $ftpmode = ftpAsciiBinary($source);
            if ($unzip_status != "ok") {
                $net2ftp_output["ftp_unziptransferfiles"][] = __("Could not unzip entry %1\$s (error code %2\$s)", $target_relative, $unzip_status);
                setErrorVars(true, "", "", "", "");
                continue;
            }
            // Directory entry in the archive: create the directory
            if (is_dir($source) == true) {
                ftp_newdirectory($conn_id, $target);
                if ($net2ftp_result["success"] == true) {
                    $net2ftp_output["ftp_unziptransferfiles"][] = __("Created directory %1\$s", $target);
                } else {
                    $net2ftp_output["ftp_unziptransferfiles"][] = __("Could not create directory %1\$s", $target);
                    setErrorVars(true, "", "", "", "");
                }
            } elseif (is_file($source) == true) {
                ftp_putfile($conn_id, dirname($source), basename($source), dirname($target), basename($target), $ftpmode, "move");
                if ($net2ftp_result["success"] == true) {
                    $net2ftp_output["ftp_unziptransferfiles"][] = __("Copied file %1\$s", $target);
                } else {
                    setErrorVars(true, "", "", "", "");
                    $target_relative_parts = explode("/", str_replace("\\", "/", dirname($target_relative)));
                    $directory_to_create = $net2ftp_globals["directory"];
                    for ($j = 0; $j < sizeof($target_relative_parts); $j = $j + 1) {
                        $directory_to_create = $directory_to_create . "/" . $target_relative_parts[$j];
                        $ftp_chdir_result = @ftp_chdir($conn_id, $directory_to_create);
                        if ($ftp_chdir_result == false) {
                            ftp_newdirectory($conn_id, $directory_to_create);
                            if ($net2ftp_result["success"] == true) {
                                $net2ftp_output["ftp_unziptransferfiles"][] = __("Created directory %1\$s", $directory_to_create);
                            } else {
                                setErrorVars(true, "", "", "", "");
                            }
                        }
                        // end if
                    }
                    // end for
                    ftp_putfile($conn_id, dirname($source), basename($source), dirname($target), basename($target), $ftpmode, "copy");
                    if ($net2ftp_result["success"] == true) {
                        $net2ftp_output["ftp_unziptransferfiles"][] = __("Copied file %1\$s", $target);
                    } else {
                        setErrorVars(true, "", "", "", "");
                        $net2ftp_output["ftp_unziptransferfiles"][] = __("Could not copy file %1\$s", $target);
                    }
                }
            }
            // end elseif file
        }
        // end for
        // -------------------------------------------------------------------------
        // Delete the uploaded archive and the temporary files
        // -------------------------------------------------------------------------
        // Delete the temporary directory and its contents
        $delete_dirorfile_result = delete_dirorfile($tempdir);
        if ($delete_dirorfile_result == false) {
            $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to delete the temporary directory");
        } else {
            registerTempfile("unregister", "{$tempdir}");
        }
        // Delete the archive
        $unlink_result = @unlink($archive_file);
        if ($unlink_result == false) {
            $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to delete the temporary file %1\$s", $archive_file);
        } else {
            registerTempfile("unregister", "{$archive_file}");
        }
        $net2ftp_output["ftp_unziptransferfiles"][] = "</ul>";
    }
    // End for
    // -------------------------------------------------------------------------
    // Close connection
    // -------------------------------------------------------------------------
    ftp_closeconnection($conn_id);
}
示例#2
0
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
}
     $ftp_pasv_result = @ftp_pasv($conn_id, TRUE);
 }
 // Create directories and put files
 for ($i = 0; $i < sizeof($list); $i++) {
     $source = trim($list[$i]["filename"]);
     $target_relative = substr($source, strlen($tempdir));
     $target = $targetdirectory . $target_relative;
     $ftpmode = ftpAsciiBinary($source);
     // Directory entry in the archive: create the directory
     if (is_dir($source) == true) {
         $ftp_mkdir_result = @ftp_mkdir($conn_id, $target);
         if ($ftp_mkdir_result == true) {
             echo "Created directory {$target} <br />\n";
         }
     } elseif (is_file($source) == true) {
         $ftpmode = ftpAsciiBinary($source);
         $ftp_put_result = @ftp_put($conn_id, $target, $source, $ftpmode);
         if ($ftp_put_result == true) {
             echo "Copied file {$target} <br />\n";
         } else {
             $target_relative_parts = explode("/", str_replace("\\", "/", dirname($target_relative)));
             $directory_to_create = $targetdirectory;
             for ($j = 0; $j < sizeof($target_relative_parts); $j = $j + 1) {
                 $directory_to_create = $directory_to_create . "/" . $target_relative_parts[$j];
                 $ftp_chdir_result = @ftp_chdir($conn_id, $directory_to_create);
                 if ($ftp_chdir_result == false) {
                     $ftp_mkdir_result = @ftp_mkdir($conn_id, $directory_to_create);
                     if ($ftp_mkdir_result == true) {
                         echo "Created directory {$directory_to_create}<br />\n";
                     }
                 }
示例#4
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the edit screen
    // For screen == 1, the file is read from the FTP server
    // For screen == 2, the textarea is changed, the file is not read from the FTP server but comes from the HTML form
    // For screen == 3, the file is saved to the FTP server
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
    if (isset($_POST["textareaType"]) == true) {
        $textareaType = validateTextareaType($_POST["textareaType"]);
    } else {
        $textareaType = "";
    }
    if (isset($_POST["text"]) == true) {
        $text = $_POST["text"];
    } else {
        $text = "";
    }
    if (isset($_POST["text_splitted"]) == true) {
        $text_splitted = $_POST["text_splitted"];
    } else {
        $text_splitted = "";
    }
    if (isset($_POST["encodingSelect"]) == true) {
        $encodingSelect = $_POST["encodingSelect"];
    } else {
        $encodingSelect = "";
    }
    if (isset($_POST["breakSelect"]) == true) {
        $breakSelect = $_POST["breakSelect"];
    } else {
        $breakSelect = "";
    }
    $text_encoding_selected = "";
    $line_break_selected = "";
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    // Form name, back and forward buttons
    $formname = "EditForm";
    $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
    // Directory + file name
    $dirfilename = htmlEncode2(glueDirectories($net2ftp_globals["directory"], $net2ftp_globals["entry"]));
    // TextareaSelect onchange
    $onchange = "document.forms['EditForm'].screen.value=2;document.forms['EditForm'].textareaType.value=document.forms['EditForm'].textareaSelect.options[document.forms['EditForm'].textareaSelect.selectedIndex].value;document.forms['EditForm'].submit();";
    // Character encoding (requires multibyte string module to be installed)
    // With this, you can save a text with specified encoding and line break sequence
    // http://www.net2ftp.org/forums/viewtopic.php?id=2449
    if (($net2ftp_globals["language"] == "ja" || $net2ftp_globals["language"] == "tc" || $net2ftp_messages["iso-8859-1"] == "UTF-8") && function_exists("mb_detect_encoding") == true) {
        // $textarea_encodings is an array which contains the possible character encodings
        $textarea_encodings = getTextareaEncodingsArray();
        // $textarea_breaks is an array which contains the possible line breaks
        $textarea_breaks[] = "CRLF";
        $textarea_breaks[] = "CR";
        $textarea_breaks[] = "LF";
        // $text_encoding_old is the original encoding which is detected when the file is first read
        // $text_encoding_new is the requested encoding from the drop-down box
        // Default = encoding used for the page, which is defined by the language file in /languages/xx.inc.php
        // HTML uses BIG5, PHP uses BIG-5 (Traditional Chinese)
        // If the HTML encoding is not foreseen in the PHP function, set it to the default ISO-8859-1
        // $text_encoding is changed further on too
        if ($encodingSelect != "" && in_array($encodingSelect, $textarea_encodings)) {
            $text_encoding_new = $encodingSelect;
        } else {
            $text_encoding_new = "";
        }
        // $line_break_old is the original line break which is detected when the file is first read
        // $line_break is the requested line break from the drop-down box
        if ($breakSelect != "" && in_array($breakSelect, $textarea_breaks) == true) {
            $line_break_new = $breakSelect;
        } else {
            $line_break_new = "LF";
        }
    }
    // Programming language (for CodePress syntax highlighting)
    if ($textareaType == "codepress") {
        $filename_extension = get_filename_extension($net2ftp_globals["entry"]);
        if ($filename_extension == "asp") {
            $codepress_programming_language = "asp";
        } elseif ($filename_extension == "css") {
            $codepress_programming_language = "css";
        } elseif ($filename_extension == "cgi") {
            $codepress_programming_language = "perl";
        } elseif ($filename_extension == "htm") {
            $codepress_programming_language = "html";
        } elseif ($filename_extension == "html") {
            $codepress_programming_language = "html";
        } elseif ($filename_extension == "java") {
            $codepress_programming_language = "java";
        } elseif ($filename_extension == "js") {
            $codepress_programming_language = "javascript";
        } elseif ($filename_extension == "javascript") {
            $codepress_programming_language = "javascript";
        } elseif ($filename_extension == "pl") {
            $codepress_programming_language = "perl";
        } elseif ($filename_extension == "perl") {
            $codepress_programming_language = "perl";
        } elseif ($filename_extension == "php") {
            $codepress_programming_language = "php";
        } elseif ($filename_extension == "phps") {
            $codepress_programming_language = "php";
        } elseif ($filename_extension == "phtml") {
            $codepress_programming_language = "php";
        } elseif ($filename_extension == "ruby") {
            $codepress_programming_language = "ruby";
        } elseif ($filename_extension == "sql") {
            $codepress_programming_language = "sql";
        } elseif ($filename_extension == "txt") {
            $codepress_programming_language = "text";
        } else {
            $codepress_programming_language = "generic";
        }
        $codepress_onclick = "text.toggleEditor();";
    } else {
        $codepress_programming_language = "";
        $codepress_onclick = "";
    }
    // -------------------------------------------------------------------------
    // Variables for screen 1
    // Read the remote file (edit), or read the local template (new file)
    // -------------------------------------------------------------------------
    if ($net2ftp_globals["screen"] == 1) {
        // Template file
        $templatefile = $net2ftp_globals["application_rootdir"] . "/modules/edit/template.txt";
        // Edit: read the file from the FTP server
        if ($net2ftp_globals["state2"] == "") {
            $text = ftp_readfile("", $net2ftp_globals["directory"], $net2ftp_globals["entry"]);
            if ($net2ftp_result["success"] == false) {
                return false;
            }
            // Character encoding (requires multibyte string module to be installed)
            // Detect the original encoding of the text, and change the encoding of the text to the encoding of the page
            if (($net2ftp_globals["language"] == "ja" || $net2ftp_globals["language"] == "tc" || $net2ftp_messages["iso-8859-1"] == "UTF-8") && function_exists("mb_detect_encoding") == true) {
                // Detect original encoding
                $text_encoding_old = mb_detect_encoding($text, $textarea_encodings);
                $text_encoding_selected = $text_encoding_old;
                // If original encoding is detected and different from the page encoding, convert the text to the page encoding
                if ($text_encoding_old != "" && strcasecmp($text_encoding_old, $net2ftp_messages["iso-8859-1"]) != 0) {
                    $text = mb_convert_encoding($text, $net2ftp_messages["iso-8859-1"], $text_encoding_old);
                }
                // Detect original line break
                if (strpos($text, "\r\n") !== false) {
                    $line_break_old = "CRLF";
                } elseif (strpos($text, "\n") !== false) {
                    $line_break_old = "LF";
                } elseif (strpos($text, "\r") !== false) {
                    $line_break_old = "CR";
                } else {
                    $line_break_old = "LF";
                }
                $line_break_selected = $line_break_old;
            }
        } elseif ($net2ftp_globals["state2"] == "newfile") {
            $handle = fopen($templatefile, "r");
            // Open the local template file for reading only
            if ($handle == false) {
                $errormessage = __("Unable to open the template file");
                setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                return false;
            }
            clearstatcache();
            // for filesize
            $text = trim(fread($handle, filesize($templatefile)));
            if ($text == false) {
                $errormessage = __("Unable to read the template file");
                setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                return false;
            }
            @fclose($handle);
        }
        // Save status
        $savestatus = __("Status: This file has not yet been saved");
        $savestatus_short = __("Not yet saved");
    } elseif ($net2ftp_globals["screen"] == 2) {
        // For HTML WYSIWYG editors, split the HTML
        if (($textareaType == "tinymce" || $textareaType == "ckeditor") && $text_splitted == "") {
            $text_splitted = splitHtml($text, $textareaType);
        } elseif (($textareaType == "plain" || $textareaType == "codepress") && $text == "" && isset($text_splitted["top"]) == true) {
            $text = $text_splitted["top"];
            $text .= $text_splitted["middle"];
            $text .= $text_splitted["bottom"];
        }
        // Save status
        $savestatus = __("Status: This file has not yet been saved");
        $savestatus_short = __("Not yet saved");
    } elseif ($net2ftp_globals["screen"] == 3) {
        // Check if a filename is specified
        if (strlen($net2ftp_globals["entry"]) < 1) {
            $errormessage = __("Please specify a filename");
            setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
            return false;
        }
        // For HTML WYSIWYG editors, join the HTML
        if ($textareaType == "tinymce" || $textareaType == "ckeditor") {
            $text = $text_splitted["top"];
            $text .= $text_splitted["middle"];
            $text .= $text_splitted["bottom"];
        }
        // $text_file contains the text which is written to the FTP server
        // It is equal to the text shown on screen, except if a different character encoding is chosen
        $text_file = $text;
        // Character encoding (requires multibyte string module to be installed)
        // Change the encoding of the text from the original or page encoding to the selected encoding
        if (($net2ftp_globals["language"] == "ja" || $net2ftp_globals["language"] == "tc" || $net2ftp_messages["iso-8859-1"] == "UTF-8") && function_exists("mb_detect_encoding") == true) {
            $break_map = array("CRLF" => "\r\n", "CR" => "\r", "LF" => "\n");
            if (isset($break_map[$line_break_new]) == true) {
                $text_file = preg_replace('/(\\r\\n)|\\r|\\n/', $break_map[$line_break_new], $text_file);
            }
            if ($text_encoding_new != "" && strcasecmp($text_encoding_new, $net2ftp_messages["iso-8859-1"]) != 0) {
                $text_file = mb_convert_encoding($text_file, $text_encoding_new, $net2ftp_messages["iso-8859-1"]);
            }
            $text_encoding_selected = $text_encoding_new;
            $line_break_selected = $line_break_new;
        }
        // Write the string to the FTP server
        // Note: this function also replaces CarriageReturn+LineFeed by LineFeed
        ftp_writefile("", $net2ftp_globals["directory"], $net2ftp_globals["entry"], $text_file);
        if ($net2ftp_result["success"] == false) {
            setErrorVars(true, "", "", "", "");
            // Continue anyway and print warning message
            $savestatus = __("Status: <b>This file could not be saved</b>");
            $savestatus_short = __("Could not be saved");
        } else {
            $mytime = mytime();
            $mytime_short = mytime_short();
            $ftpmode = ftpAsciiBinary($net2ftp_globals["entry"]);
            if ($ftpmode == FTP_ASCII) {
                $printftpmode = "FTP_ASCII";
            } elseif ($ftpmode == FTP_BINARY) {
                $printftpmode = "FTP_BINARY";
            }
            $savestatus = __("Status: Saved on <b>%1\$s</b> using mode %2\$s", $mytime, $printftpmode);
            $savestatus_short = __("Saved at %1\$s", $mytime_short);
        }
    }
    // -------------------------------------------------------------------------
    // Convert special characters to HTML entities
    // -------------------------------------------------------------------------
    // Plain textarea
    if ($textareaType == "" || $textareaType == "plain") {
        $text = htmlspecialchars($text, ENT_QUOTES);
    } elseif ($textareaType == "ckeditor") {
        $text_splitted["top"] = htmlspecialchars($text_splitted["top"], ENT_QUOTES);
        $text_splitted["bottom"] = htmlspecialchars($text_splitted["bottom"], ENT_QUOTES);
        // Do not encode the middle part, this is done by CKEditor itself
        //		$text_splitted["middle"] = htmlspecialchars($text_splitted["middle"], ENT_QUOTES);
    } elseif ($textareaType == "tinymce") {
        $text_splitted["top"] = htmlspecialchars($text_splitted["top"], ENT_QUOTES);
        $text_splitted["middle"] = htmlspecialchars($text_splitted["middle"], ENT_QUOTES);
        $text_splitted["bottom"] = htmlspecialchars($text_splitted["bottom"], ENT_QUOTES);
    } elseif ($textareaType == "codepress") {
        $text = htmlspecialchars($text, ENT_QUOTES);
    }
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/edit.template.php";
}
示例#5
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the unzip screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output;
    if (isset($_POST["list"]) == true) {
        $list = getSelectedEntries($_POST["list"]);
    } else {
        $list = "";
    }
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    // Title
    $title = __("Unzip archives");
    // Form name, back and forward buttons
    $formname = "UnzipForm";
    $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
    $forward_onclick = "document.forms['" . $formname . "'].submit();";
    // -------------------------------------------------------------------------
    // Variables for screen 1
    // -------------------------------------------------------------------------
    if ($net2ftp_globals["screen"] == 1) {
        // Next screen
        $nextscreen = 2;
    } elseif ($net2ftp_globals["screen"] == 2) {
        $net2ftp_output["unzip"] = array();
        $net2ftp_output["ftp_unziptransferfiles"] = array();
        // ---------------------------------------
        // Initialize variables
        // ---------------------------------------
        $moved_ok = 0;
        // Index of the archives that have been treated successfully
        $moved_notok = 0;
        // Index of the archives that have been treated unsuccessfully
        // ---------------------------------------
        // Open connection to the FTP server
        // ---------------------------------------
        setStatus(2, 10, __("Connecting to the FTP server"));
        $conn_id = ftp_openconnection();
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        // ---------------------------------------
        // Get the archives from the FTP server
        // ---------------------------------------
        for ($i = 1; $i <= $list["stats"]["files"]["total_number"]; $i = $i + 1) {
            // Set the status
            $message = __("Getting archive %1\$s of %2\$s from the FTP server", $i, $list["stats"]["files"]["total_number"]);
            setStatus($i, $list["stats"]["files"]["total_number"], $message);
            // Get the archive from the FTP server
            $localtargetdir = $net2ftp_globals["application_tempdir"];
            $localtargetfile = $list["files"][$i]["dirfilename"] . ".txt";
            $remotesourcedir = $net2ftp_globals["directory"];
            $remotesourcefile = $list["files"][$i]["dirfilename"];
            $ftpmode = ftpAsciiBinary($list["files"][$i]["dirfilename"]);
            $copymove = "copy";
            ftp_getfile($conn_id, $localtargetdir, $localtargetfile, $remotesourcedir, $remotesourcefile, $ftpmode, $copymove);
            if ($net2ftp_result["success"] == false) {
                setErrorVars(true, "", "", "", "");
                $net2ftp_output["unzip"][] = __("Unable to get the archive <b>%1\$s</b> from the FTP server", htmlEncode2($list["files"][$i]["dirfilename"]));
                $moved_notok = $moved_notok + 1;
                continue;
            }
            // Register the temporary file
            registerTempfile("register", glueDirectories($localtargetdir, $localtargetfile));
            // Enter the temporary filename and the real filename in the array
            $moved_ok = $moved_ok + 1;
            $acceptedArchivesArray[$moved_ok]["name"] = $list["files"][$i]["dirfilename"];
            $acceptedArchivesArray[$moved_ok]["tmp_name"] = glueDirectories($localtargetdir, $localtargetfile);
            $acceptedArchivesArray[$moved_ok]["targetdirectory"] = $list["files"][$i]["targetdirectory"];
            $acceptedArchivesArray[$moved_ok]["use_folder_names"] = $list["files"][$i]["use_folder_names"];
        }
        // end for
        // ---------------------------------------
        // Unzip archives and transfer the files (create subdirectories if needed)
        // ---------------------------------------
        if (isset($acceptedArchivesArray) == true && sizeof($acceptedArchivesArray) > 0) {
            ftp_unziptransferfiles($acceptedArchivesArray);
            $net2ftp_output["unzip"] = $net2ftp_output["unzip"] + $net2ftp_output["ftp_unziptransferfiles"];
            if ($net2ftp_result["success"] == false) {
                return false;
            }
        }
        // ---------------------------------------
        // Close the connection to the FTP server
        // ---------------------------------------
        ftp_closeconnection($conn_id);
    }
    // end elseif
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}