示例#1
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
}
示例#2
0
function ftp_zip($conn_id, $directory, $list, $zipactions, $zipdir, $divelevel)
{
    // --------------
    // This function allows to download/save/email a zipfile which contains the selected directories and files
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_globals, $net2ftp_settings, $net2ftp_result, $net2ftp_output;
    // -------------------------------------------------------------------------
    // Initialization
    // -------------------------------------------------------------------------
    if ($divelevel == 0) {
        // Create the zipfile
        $net2ftp_globals["zipfile"] = new zipfile();
        $timenow = time();
        $zipdir = "";
        // Open the connection
        $conn_id = ftp_openconnection();
        if ($net2ftp_result["success"] == false) {
            return false;
        }
    }
    // -------------------------------------------------------------------------
    // For all directories...
    // -------------------------------------------------------------------------
    for ($i = 1; $i <= $list["stats"]["directories"]["total_number"]; $i = $i + 1) {
        $newdir = glueDirectories($directory, $list["directories"][$i]["dirfilename"]);
        $newzipdir = glueDirectories($zipdir, $list["directories"][$i]["dirfilename"]);
        $newdivelevel = $divelevel + 1;
        // Check if the directory contains a banned keyword
        if ($list["directories"][$i]["selectable"] == "banned_keyword") {
            continue;
        }
        // Get a new list
        $newlist = ftp_getlist($conn_id, $newdir);
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        ftp_zip($conn_id, $newdir, $newlist, $zipactions, $newzipdir, $newdivelevel);
        if ($net2ftp_result["success"] == false) {
            setErrorVars(true, "", "", "", "");
            continue;
        }
        if ($divelevel == 0 && ($zipactions["save"] == "yes" || $zipactions["email"] == "yes")) {
            $total = $list["stats"]["directories"]["total_number"] + $list["stats"]["files"]["total_number"];
            setStatus($i, $total, __("Processing the entries"));
        }
    }
    // end for directories
    // -------------------------------------------------------------------------
    // For all files...
    // -------------------------------------------------------------------------
    for ($i = 1; $i <= $list["stats"]["files"]["total_number"]; $i = $i + 1) {
        if ($list["files"][$i]["selectable"] != "ok") {
            continue;
        }
        $text = ftp_readfile($conn_id, $directory, $list["files"][$i]["dirfilename"]);
        if ($net2ftp_result["success"] == false) {
            setErrorVars(true, "", "", "", "");
            continue;
        }
        $filename = stripDirectory(glueDirectories($zipdir, $list["files"][$i]["dirfilename"]));
        $net2ftp_globals["zipfile"]->addFile($text, $filename);
        if ($divelevel == 0 && ($zipactions["save"] == "yes" || $zipactions["email"] == "yes")) {
            $total = $list["stats"]["directories"]["total_number"] + $list["stats"]["files"]["total_number"];
            setStatus($list["stats"]["directories"]["total_number"] + $i - 1, $total, __("Processing the entries"));
        }
    }
    // end for files
    // -------------------------------------------------------------------------
    // End
    // -------------------------------------------------------------------------
    if ($divelevel == 0) {
        // ------------------------
        // Send the zipfile to the browser
        // ------------------------
        if ($zipactions["download"] == "yes") {
            $timenow = time();
            $filenameToSend = "net2ftp-" . $timenow . ".zip";
            $filesizeToSend = strlen($net2ftp_globals["zipfile"]->file());
            sendDownloadHeaders($filenameToSend, $filesizeToSend);
            echo $net2ftp_globals["zipfile"]->file();
            flush();
        }
        // ------------------------
        // Save the zipfile string to a file
        // ------------------------
        if ($zipactions["save"] == "yes" || $zipactions["email"] == "yes") {
            $string = $net2ftp_globals["zipfile"]->file();
            $tempfilename = tempnam($net2ftp_globals["application_tempdir"], "zip__");
            if ($tempfilename == false) {
                @unlink($tempfilename);
                $errormessage = __("Unable to create the temporary file. Check the permissions of the %1\$s directory.", $net2ftp_globals["application_tempdir"]);
                setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                return false;
            }
            registerTempfile("register", $tempfilename);
            local_writefile($tempfilename, $string);
            if ($net2ftp_result["success"] == false) {
                return false;
            }
        }
        // ------------------------
        // Save the zip file to the FTP server
        // ------------------------
        if ($zipactions["save"] == "yes") {
            ftp_putfile($conn_id, "", $tempfilename, $directory, $zipactions["save_filename"], FTP_BINARY, "copy");
            if ($net2ftp_result["success"] == false) {
                @unlink($tempfilename);
                //				$errormessage = __("Unable to put the file <b>%1\$s</b> on the FTP server.<br />You may not have write permissions on the directory.", $zipactions["save_filename"]);
                //				setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                return false;
            } else {
                $net2ftp_output["ftp_zip"][] = __("The zip file has been saved on the FTP server as <b>%1\$s</b>", $zipactions["save_filename"]) . "<br /><br />\n";
            }
        }
        // ------------------------
        // Close the connection
        // ------------------------
        ftp_closeconnection($conn_id);
        // ------------------------
        // Email
        // ------------------------
        if ($zipactions["email"] == "yes") {
            $FromName = "net2ftp";
            $From = $net2ftp_settings["email_feedback"];
            $ToName = "";
            $To = $zipactions["email_to"];
            $Subject = __("Requested files");
            // Email message
            $Text = __("Dear,") . "\n\n";
            $Text .= __("Someone has requested the files in attachment to be sent to this email account (%1\$s).", $To) . "\n";
            $Text .= __("If you know nothing about this or if you don't trust that person, please delete this email without opening the Zip file in attachment.") . "\n";
            $Text .= __("Note that if you don't open the Zip file, the files inside cannot harm your computer.") . "\n";
            $Text .= "\n\n---------------------------------------\n";
            $Text .= __("Information about the sender: ") . "\n";
            $Text .= __("IP address: ") . $REMOTE_ADDR . "\n";
            $Text .= __("Time of sending: ") . mytime() . "\n";
            $Text .= __("Sent via the net2ftp application installed on this website: ") . $HTTP_REFERER . "\n";
            $Text .= __("Webmaster's email: ") . $From . "\n";
            $Text .= "\n\n---------------------------------------\n";
            $Text .= __("Message of the sender: ") . "\n";
            $Text .= $zipactions["message"] . "\n";
            $Text .= "\n\n---------------------------------------\n";
            $Text .= __("net2ftp is free software, released under the GNU/GPL license. For more information, go to http://www.net2ftp.com.") . "\n\n\n";
            $AttmFiles = array($tempfilename);
            SendMail($From, $FromName, $To, $ToName, $Subject, $Text, $Html, $AttmFiles);
            if ($net2ftp_result["success"] == false) {
                @unlink($tempfilename);
                return false;
            }
            $net2ftp_output["ftp_zip"][] = __("The zip file has been sent to <b>%1\$s</b>.", $To) . "<br /><br />";
        }
        // ------------------------
        // Delete the temporary zipfile
        // ------------------------
        if ($zipactions["save"] == "yes" || $zipactions["email"] == "yes") {
            $success4 = @unlink($tempfilename);
            if ($success4 == false) {
                $errormessage = __("Unable to delete the temporary file");
                setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                return false;
            }
            registerTempfile("unregister", $tempfilename);
        }
        // Set the variable to NULL to save memory
        $net2ftp_globals["zipfile"] = NULL;
    }
    // end if $divelevel == 0
}
示例#3
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";
}
示例#4
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the browse screen ($state2=="main") or the directory popup screen ($state2=="popup")
    // For the browse screen ($state2=="main"), 2 template files are called
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
    // -------------------------------------------------------------------------
    // Check if the directory name contains \' and if it does, print an error message
    // Note: these directories cannot be browsed, but can be deleted
    // -------------------------------------------------------------------------
    //	if (strstr($directory, "\'") != false) {
    //		$errormessage = __("Directories with names containing \' cannot be displayed correctly. They can only be deleted. Please go back and select another subdirectory.");
    //		setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
    //		return false;
    //	}
    // -------------------------------------------------------------------------
    // Variables
    // With status update if $state2=="main"
    // -------------------------------------------------------------------------
    // ------------------------------------
    // Open connection
    // ------------------------------------
    if ($net2ftp_globals["state2"] == "main") {
        setStatus(2, 10, __("Connecting to the FTP server"));
    }
    $conn_id = ftp_openconnection();
    if ($net2ftp_result["success"] == false) {
        return false;
    }
    // ------------------------------------
    // Get raw list of directories and files; parse the raw list and return a nice list
    // This function may change the current $directory; a warning message is returned in that case
    // ------------------------------------
    if ($net2ftp_globals["state2"] == "main") {
        setStatus(4, 10, __("Getting the list of directories and files"));
    }
    $list = ftp_getlist($conn_id, $net2ftp_globals["directory"]);
    if ($net2ftp_result["success"] == false) {
        return false;
    }
    // ------------------------------------
    // Close connection
    // ------------------------------------
    ftp_closeconnection($conn_id);
    // ------------------------------------
    // Sort the list
    // ------------------------------------
    $list_directories = sort_list($list["directories"]);
    $list_files = sort_list($list["files"]);
    $list_symlinks = sort_list($list["symlinks"]);
    $list_unrecognized = sort_list($list["unrecognized"]);
    $warning_directory = $list["stats"]["warnings"];
    $directory = $list["stats"]["newdirectory"];
    $directory_html = htmlEncode2($directory);
    $directory_url = urlEncode2($directory);
    $directory_js = javascriptEncode2($directory);
    $updirectory = upDir($directory);
    $updirectory_html = htmlEncode2($updirectory);
    $updirectory_url = urlEncode2($updirectory);
    $updirectory_js = javascriptEncode2($updirectory);
    // ------------------------------------
    // Calculate the list of HTTP URLs
    // ------------------------------------
    if ($net2ftp_globals["state2"] == "main") {
        $list_links_js = ftp2http($net2ftp_globals["directory"], $list_files, "no");
        $list_links_url = ftp2http($net2ftp_globals["directory"], $list_files, "yes");
    }
    // ------------------------------------
    // Consumption message
    // ------------------------------------
    $warning_consumption = "";
    if (checkConsumption() == false) {
        $warning_consumption .= "<b>" . __("Daily limit reached: you will not be able to transfer data") . "</b><br /><br />\n";
        $warning_consumption .= __("In order to guarantee the fair use of the web server for everyone, the data transfer volume and script execution time are limited per user, and per day. Once this limit is reached, you can still browse the FTP server but not transfer data to/from it.") . "<br /><br />\n";
        $warning_consumption .= __("If you need unlimited usage, please install net2ftp on your own web server.") . "<br />\n";
    }
    // ------------------------------------
    // Browse message
    // ------------------------------------
    if ($net2ftp_settings["message_browse"] != "" && $net2ftp_settings["message_browse"] != "Setting message_browse does not exist") {
        $warning_message = $net2ftp_settings["message_browse"];
    }
    // ------------------------------------
    // Directory tree
    // ------------------------------------
    $directory_exploded = explode("/", stripDirectory($directory));
    if ($directory != "/" && checkAuthorizedDirectory("/") == true) {
        $directory_tree = "<a href=\"javascript:submitBrowseForm('/','','browse','main');\">root</a> ";
    } else {
        $directory_tree = "root ";
    }
    $directory_goto = "";
    for ($i = 0; $i < sizeof($directory_exploded) - 1; $i++) {
        $directory_goto = glueDirectories($directory_goto, $directory_exploded[$i]);
        $directory_goto_url = urlEncode2($directory_goto);
        if (checkAuthorizedDirectory($directory_goto) == true) {
            $directory_tree .= "/<a href=\"javascript:submitBrowseForm('" . $directory_goto_url . "','','browse','main');\">" . htmlEncode2($directory_exploded[$i]) . "</a> ";
        } else {
            $directory_tree .= "/" . $directory_exploded[$i] . " ";
        }
    }
    $directory_tree .= "/" . $directory_exploded[sizeof($directory_exploded) - 1];
    // ------------------------------------
    // Language
    // ------------------------------------
    $language_onchange = "document.BrowseForm.language.value=document.forms['BrowseForm'].language2.options[document.forms['BrowseForm'].language2.selectedIndex].value; submitBrowseForm('{$directory_js}', '', 'browse', 'main');";
    // ------------------------------------
    // Skin
    // ------------------------------------
    $skin_onchange = "document.BrowseForm.skin.value=document.forms['BrowseForm'].skin2.options[document.forms['BrowseForm'].skin2.selectedIndex].value; submitBrowseForm('{$directory_js}', '', 'browse', 'main');";
    // ------------------------------------
    // $rowcounter counts the total nr of rows
    // ------------------------------------
    $rowcounter = 0;
    // ------------------------------------
    // Column spans
    // ------------------------------------
    $action_colspan = 1;
    if ($net2ftp_settings["functionuse_view"] == "yes") {
        $action_colspan++;
    }
    if ($net2ftp_settings["functionuse_edit"] == "yes") {
        $action_colspan++;
    }
    if ($net2ftp_settings["functionuse_update"] == "yes") {
        $action_colspan++;
    }
    // Total nr of columns
    $total_colspan = $action_colspan + 9;
    // ------------------------------------
    // Name, Type, Size, ...
    // Determine the sort criteria and direction (ascending/descending)
    // ------------------------------------
    $sortArray["dirfilename"]["text"] = __("Name");
    $sortArray["type"]["text"] = __("Type");
    $sortArray["size"]["text"] = __("Size");
    $sortArray["owner"]["text"] = __("Owner");
    $sortArray["group"]["text"] = __("Group");
    $sortArray["permissions"]["text"] = __("Perms");
    $sortArray["mtime"]["text"] = __("Mod Time");
    $icon_directory = $net2ftp_globals["application_rootdir_url"] . "/skins/" . $net2ftp_globals["skin"] . "/images/mime";
    // Loop over all the sort possibilities
    while (list($key, $value) = each($sortArray)) {
        // The list is sorted by the current $key
        // Print the icon representing the current sortorder
        // Print the link to sort using the other sortorder
        if ($net2ftp_globals["sort"] == $key) {
            // Ascending
            if ($net2ftp_globals["sortorder"] == "ascending") {
                $sortArray[$key]["title"] = __("Click to sort by %1\$s in descending order", $value["text"]);
                $sortArray[$key]["onclick"] = "do_sort('" . $key . "','descending');";
                $icon = "ascend.png";
                $alt = __("Ascending order");
            } else {
                $sortArray[$key]["title"] = __("Click to sort by %1\$s in ascending order", $value["text"]);
                $sortArray[$key]["onclick"] = "do_sort('" . $key . "','ascending');";
                $icon = "descend.png";
                $alt = __("Descending order");
            }
        } else {
            $sortArray[$key]["title"] = __("Click to sort by %1\$s in ascending order", $value["text"]);
            $sortArray[$key]["onclick"] = "do_sort('" . $key . "','ascending');";
            $icon = "";
            $alt = "";
        }
        // The icon to be printed is determined above
        // Now, print the full HTML depending on the browser agent, version and platform
        if ($icon != "") {
            if ($net2ftp_globals["browser_agent"] == "IE" && ($net2ftp_globals["browser_version"] == "5.5" || $net2ftp_globals["browser_version"] == "6") && $net2ftp_globals["browser_platform"] == "Win") {
                $sortArray[$key]["icon"] = "<img src=\"{$icon_directory}/spacer.gif\"   alt=\"{$alt}\" style=\"border: 0px; width: 16px; height: 16px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{$icon_directory}/{$icon}', sizingMethod='scale');\" />\n";
            } else {
                $sortArray[$key]["icon"] = "<img src=\"{$icon_directory}/{$icon}\"        alt=\"{$alt}\" style=\"border: 0px; width: 16px; height: 16px;\" />\n";
            }
        } else {
            $sortArray[$key]["icon"] = "";
        }
    }
    // ------------------------------------
    // popup - FormAndFieldname
    // ------------------------------------
    if (isset($_POST["FormAndFieldName"]) == true) {
        $FormAndFieldName = validateGenericInput($_POST["FormAndFieldName"]);
    } else {
        $FormAndFieldName = "";
    }
    // ------------------------------------
    // Action URL
    // Used for Up, Subdirectories, Files (download + actions)
    // ------------------------------------
    $action_url = printPHP_SELF("actions");
    // ------------------------------------
    // Data transfer statistics
    // Print this only if the consumption statistics are available (logging must be on, using a MySQL database)
    // ------------------------------------
    if (isset($net2ftp_globals["consumption_ipaddress_datatransfer"]) == true || isset($net2ftp_globals["consumption_ftpserver_datatransfer"]) == true) {
        $print_consumption = true;
        $consumption_ipaddress_datatransfer = formatFilesize($net2ftp_globals["consumption_ipaddress_datatransfer"]);
        $consumption_ftpserver_datatransfer = formatFilesize($net2ftp_globals["consumption_ftpserver_datatransfer"]);
    } else {
        $print_consumption = false;
    }
    // ------------------------------------
    // HTTP URL
    // ------------------------------------
    $list_files_tmp[1]["dirfilename_url"] = "";
    $httplink = ftp2http($directory, $list_files_tmp, "no");
    // -------------------------------------------------------------------------
    // Print the output - part 2
    // -------------------------------------------------------------------------
    if ($net2ftp_globals["state2"] == "main") {
        setStatus(6, 10, __("Printing the list of directories and files"));
        require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/browse_main.template.php";
    } elseif ($net2ftp_globals["state2"] == "popup") {
        require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/browse_popup.template.php";
    }
}
示例#5
0
function includeLanguageFile()
{
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_globals, $net2ftp_messages;
    $languageArray = getLanguageArray();
    // If language exists, include the language file
    if (array_key_exists($net2ftp_globals["language"], $languageArray) == true) {
        $languageFile = glueDirectories($net2ftp_globals["application_languagesdir"], $languageArray[$net2ftp_globals["language"]]["file"]);
        require_once $languageFile;
    } else {
        $net2ftp_globals["language"] = "en";
        $languageFile = glueDirectories($net2ftp_globals["application_languagesdir"], $languageArray[$net2ftp_globals["language"]]["file"]);
        require_once $languageFile;
    }
}
示例#6
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the chmod 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 = __("Install software packages");
    // Form name, back and forward buttons
    $formname = "InstallForm";
    $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
    // -------------------------------------------------------------------------
    // Screen 1
    // -------------------------------------------------------------------------
    if ($net2ftp_globals["screen"] == 1) {
        // ----------------------------------------------
        // Read the net2ftp installer script template $text
        // ----------------------------------------------
        $templatefile = $net2ftp_globals["application_rootdir"] . "/modules/install/net2ftp_installer.txt";
        $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 = 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);
        // ----------------------------------------------
        // Read the list of packages
        // ----------------------------------------------
        $packagelistfile_net2ftp = "http://www.net2ftp.com/package_list.txt";
        $packagelistfile_local = $net2ftp_globals["application_rootdir"] . "/modules/install/package_list.txt";
        // Get the list of packages from net2ftp.com
        $handle_net2ftp = @fopen($packagelistfile_net2ftp, "r");
        clearstatcache();
        // for filesize
        $packagelist_net2ftp = @fread($handle_net2ftp, filesize($packagelistfile_net2ftp));
        @fclose($handle_net2ftp);
        // If net2ftp.com can't be reached, get it from the local installation
        if ($packagelist_net2ftp == false) {
            $handle_local = @fopen($packagelistfile_local, "r");
            clearstatcache();
            // for filesize
            $packagelist_local = @fread($handle_local, filesize($packagelistfile_local));
            @fclose($handle_local);
        }
        // Issue an error message if no list could be read
        if ($packagelist_net2ftp != "") {
            $packagelist = $packagelist_net2ftp;
        } elseif ($packagelist_local != "") {
            $packagelist = $packagelist_local;
        } else {
            $errormessage = __("Unable to get the list of packages");
            setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
            return false;
        }
        // ----------------------------------------------
        // Security code
        // Random key generator by goochivasquez -at- gmail (15-Apr-2005 11:53)
        // ----------------------------------------------
        // Random key generator
        $keychars = "abcdefghijklmnopqrstuvwxyz0123456789";
        $length = 20;
        $security_code = "";
        for ($i = 0; $i < $length; $i++) {
            $security_code .= substr($keychars, rand(1, strlen($keychars)), 1);
        }
        // Random key generator
        $keychars = "abcdefghijklmnopqrstuvwxyz0123456789";
        $length = 5;
        $tempdir_extension = "";
        for ($i = 0; $i < $length; $i++) {
            $tempdir_extension .= substr($keychars, rand(1, strlen($keychars)), 1);
        }
        $tempdir_ftp = glueDirectories($net2ftp_globals["directory"], "net2ftp_temp_") . $tempdir_extension;
        // ----------------------------------------------
        // Replace certain values
        // ----------------------------------------------
        $text = str_replace("NET2FTP_SECURITY_CODE", $security_code, $text);
        $text = str_replace("NET2FTP_TEMPDIR_EXTENSION", $tempdir_extension, $text);
        $text = str_replace("NET2FTP_PACKAGELIST", $packagelist, $text);
        $text = str_replace("NET2FTP_FTP_SERVER", $net2ftp_globals["ftpserver"], $text);
        $text = str_replace("NET2FTP_FTPSERVER_PORT", $net2ftp_globals["ftpserverport"], $text);
        $text = str_replace("NET2FTP_USERNAME", $net2ftp_globals["username"], $text);
        $text = str_replace("NET2FTP_DIRECTORY", $net2ftp_globals["directory"], $text);
        // ----------------------------------------------
        // Open connection
        // ----------------------------------------------
        setStatus(2, 10, __("Connecting to the FTP server"));
        $conn_id = ftp_openconnection();
        if ($conn_id == false) {
            return false;
        }
        // ----------------------------------------------
        // Create temporary /net2ftp_temp directory
        // ----------------------------------------------
        setStatus(4, 10, __("Creating a temporary directory on the FTP server"));
        ftp_newdirectory($conn_id, $tempdir_ftp);
        if ($net2ftp_result["success"] == false) {
            setErrorVars(true, "", "", "", "");
        }
        // ----------------------------------------------
        // Chmodding the temporary /net2ftp_temp directory to 777
        // ----------------------------------------------
        setStatus(6, 10, __("Setting the permissions of the temporary directory"));
        $sitecommand = "chmod 0777 " . $tempdir_ftp;
        $ftp_site_result = @ftp_site($conn_id, $sitecommand);
        // ----------------------------------------------
        // Put a .htaccess in the /net2ftp_temp directory to avoid anyone else reading the contents it
        // (Works only for Apache web servers...)
        // ----------------------------------------------
        ftp_writefile($conn_id, $tempdir_ftp, ".htaccess", "deny from all");
        if ($net2ftp_result["success"] == false) {
            setErrorVars(true, "", "", "", "");
        }
        // ----------------------------------------------
        // Write the net2ftp installer script to the FTP server
        // ----------------------------------------------
        setStatus(8, 10, __("Copying the net2ftp installer script to the FTP server"));
        ftp_writefile($conn_id, $net2ftp_globals["directory"], "net2ftp_installer.php", $text);
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        // ----------------------------------------------
        // Close connection
        // ----------------------------------------------
        ftp_closeconnection($conn_id);
        // ----------------------------------------------
        // Variables for screen 1
        // ----------------------------------------------
        // URL to the installer script
        $list_files[1]["dirfilename_js"] = "net2ftp_installer.php?security_code=" . $security_code;
        $ftp2http_result = ftp2http($net2ftp_globals["directory"], $list_files, "no");
        $net2ftp_installer_url = $ftp2http_result[1];
    }
    // end if
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
示例#7
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the login screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
    // -------------------------------------------------------------------------
    // Variables
    // -------------------------------------------------------------------------
    $url = $net2ftp_globals["action_url"];
    // -------------------------------------------------------------------------
    // Delete all temporary files in the /temp folder which are older than 10 minutes
    // -------------------------------------------------------------------------
    $max_age_seconds = 600;
    // default: 10 minutes
    if ($handle = @opendir($net2ftp_globals["application_tempdir"])) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && $file != ".htaccess" && $file != ".htpasswd" && $file != "chmod_this_dir_to_777.txt" && $file != "index.php") {
                $dirfile = glueDirectories($net2ftp_globals["application_tempdir"], $file);
                $age_in_seconds = time() - @filemtime($dirfile);
                if ($age_in_seconds > $max_age_seconds) {
                    @unlink($dirfile);
                }
            }
        }
        closedir($handle);
    }
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/logout.template.php";
}
function ftp_getlist($conn_id, $directory)
{
    // --------------
    // This function connects to the FTP server and returns an array with a list of directories and files.
    // One row per directory or file, with rows from index 1 to n
    //
    // Step 1: send ftp_rawlist request to the FTP server; this returns a string
    // Step 2: parse that string and get a first array ($templist)
    // Step 3: move the rows to another array, to index 1 to n ($list)
    //
    // This function is used in all functions which process directories recursively.
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_globals, $net2ftp_settings;
    // -------------------------------------------------------------------------
    // Initialization
    // -------------------------------------------------------------------------
    $warnings = "";
    // -------------------------------------------------------------------------
    // Step 1: Chdir to the directory and get the current directory
    // -------------------------------------------------------------------------
    // ----------------------------------------------
    // Step 1a - Directory is "/"
    // Chdir to the directory because otherwise the ftp_rawlist does not work on some FTP servers
    // ----------------------------------------------
    if ($directory == "/") {
        $result1a = @ftp_chdir($conn_id, $directory);
    } elseif ($directory == "") {
        $result1b = @ftp_chdir($conn_id, $directory);
        $directory = @ftp_pwd($conn_id);
    } else {
        // 1c1 - Replace \' by \\' to be able to delete directories with names containing \'
        $directory1 = str_replace("\\'", "\\\\'", $directory);
        // 1c2 - Chdir to the directory
        // This is to check if the directory exists, but also because otherwise
        // the ftp_rawlist does not work on some FTP servers.
        $result1c = @ftp_chdir($conn_id, $directory1);
        // 1c3 - If the first ftp_chdir returns false, try a second time without the leading /
        // Some Windows FTP servers do not work when you use a leading /
        if ($result1c == false) {
            $directory2 = stripDirectory($directory1);
            $result2 = @ftp_chdir($conn_id, $directory2);
            // 1c3 - If the second ftp_chdir also does not work:
            //           For the Browse screen ==> go to the user's root directory
            //           For all other screens ==> return error
            if ($result2 == false) {
                if ($net2ftp_globals["state"] == "browse") {
                    $rootdirectory = getRootdirectory();
                    // User's root directory is different from the current directory, so switch to it
                    if ($directory != $rootdirectory) {
                        $warnings .= __("The directory <b>%1\$s</b> does not exist or could not be selected, so the directory <b>%2\$s</b> is shown instead.", $directory, $rootdirectory);
                        $directory = $rootdirectory;
                        $result3 = @ftp_chdir($conn_id, $directory);
                    } else {
                        $errormessage = __("Your root directory <b>%1\$s</b> does not exist or could not be selected.", $directory);
                        setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                    }
                } else {
                    $errormessage = __("The directory <b>%1\$s</b> could not be selected - you may not have sufficient rights to view this directory, or it may not exist.", $directory);
                    setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                }
            }
            // end if result2
        }
        // end if result1
    }
    // end if / or "" or else
    // -------------------------------------------------------------------------
    // Step 2 - Get list of directories and files
    // The -a option is used to show the hidden files as well on some FTP servers
    // Some servers do not return anything when using -a, so in that case try again without the -a option
    // -------------------------------------------------------------------------
    $rawlist = ftp_rawlist($conn_id, "-a");
    if (sizeof($rawlist) <= 1) {
        $rawlist = ftp_rawlist($conn_id, "");
    }
    // -------------------------------------------------------------------------
    // Step 3 - Parse the raw list
    // -------------------------------------------------------------------------
    // ----------------------------------------------
    // Initialize variables
    // ----------------------------------------------
    $list["directories"] = array();
    $list["files"] = array();
    $list["symlinks"] = array();
    $list["unrecognized"] = array();
    $directory_index = 1;
    $file_index = 1;
    $symlink_index = 1;
    $unrecognized_index = 1;
    $list["stats"]["directories"]["total_number"] = 0;
    $list["stats"]["directories"]["total_size"] = 0;
    $list["stats"]["directories"]["total_skipped"] = 0;
    $list["stats"]["files"]["total_number"] = 0;
    $list["stats"]["files"]["total_size"] = 0;
    $list["stats"]["files"]["total_skipped"] = 0;
    $list["stats"]["symlinks"]["total_number"] = 0;
    $list["stats"]["symlinks"]["total_size"] = 0;
    $list["stats"]["symlinks"]["total_skipped"] = 0;
    $list["stats"]["unrecognized"]["total_number"] = 0;
    $list["stats"]["unrecognized"]["total_size"] = 0;
    $list["stats"]["unrecognized"]["total_skipped"] = 0;
    // ----------------------------------------------
    // Loop over the raw list lines
    // ----------------------------------------------
    $nr_entries_banned_keyword = 0;
    $nr_entries_too_big = 0;
    for ($i = 0; $i < sizeof($rawlist); $i++) {
        // ----------------------------------------------
        // Scan each line
        // ----------------------------------------------
        $listline = ftp_scanline($directory, $rawlist[$i]);
        // If $listline is empty (e.g. if it contained ".."), continue to the next line
        if ($listline == "") {
            continue;
        }
        // Encode the name for HTML and Javascript
        if (isset($listline["dirfilename"])) {
            $listline["dirfilename_html"] = htmlEncode2($listline["dirfilename"]);
            $listline["dirfilename_url"] = urlEncode2($listline["dirfilename"]);
            $listline["dirfilename_js"] = javascriptEncode2($listline["dirfilename"]);
        }
        // Check if the filename contains a forbidden keyword
        // If it does, then this line will not be selectable on the Browse screen
        // Note: even if "selectable" is set to true here, it can still be set to false just below if the filesize is too big
        if (checkAuthorizedName($listline["dirfilename"]) == true) {
            $listline["selectable"] = "ok";
        } else {
            $listline["selectable"] = "banned_keyword";
            $nr_entries_banned_keyword++;
        }
        // Check if the filesize is bigger than the maximum authorized filesize
        if ($listline["dirorfile"] == "-" && isset($listline["size"]) && is_numeric($listline["size"])) {
            if ($listline["selectable"] == "ok" && $listline["size"] > $net2ftp_settings["max_filesize"]) {
                $listline["selectable"] = "too_big";
                $nr_entries_too_big++;
            }
        }
        // Form the new directory filename and encode it too
        if ($listline["dirorfile"] == "d") {
            $listline["newdir"] = glueDirectories($directory, $listline["dirfilename"]);
            $listline["newdir_html"] = htmlEncode2($listline["newdir"]);
            $listline["newdir_url"] = urlEncode2($listline["newdir"]);
            $listline["newdir_js"] = javascriptEncode2($listline["newdir"]);
        }
        // ----------------------------------------------
        // Depending on if the line contained a directory/file/symlink/unrecognized
        // row, store the result in different variables
        // ----------------------------------------------
        if ($listline["dirorfile"] == "d") {
            $list["directories"][$directory_index] = $listline;
            $directory_index++;
            if (isset($listline["size"]) && is_numeric($listline["size"])) {
                $list["stats"]["directories"]["total_size"] = $list["stats"]["directories"]["total_size"] + $listline["size"];
            } else {
                $list["stats"]["directories"]["total_skipped"] = $list["stats"]["directories"]["total_skipped"] + 1;
            }
        } elseif ($listline["dirorfile"] == "-") {
            $list["files"][$file_index] = $listline;
            $file_index++;
            if (isset($listline["size"]) && is_numeric($listline["size"])) {
                $list["stats"]["files"]["total_size"] = $list["stats"]["files"]["total_size"] + $listline["size"];
            } else {
                $list["stats"]["files"]["total_skipped"] = $list["stats"]["files"]["total_skipped"] + 1;
            }
        } elseif ($listline["dirorfile"] == "l") {
            $list["symlinks"][$symlink_index] = $listline;
            $symlink_index++;
        } elseif ($listline["dirorfile"] == "u") {
            $list["unrecognized"][$unrecognized_index] = $listline;
            $unrecognized_index++;
        }
        // end elseif
    }
    // end for
    // Print a warning message if some directories, files or symlinks contain a banned keyword or if a file is
    // too big to be downloaded
    if ($nr_entries_banned_keyword > 0) {
        $warnings .= __("Entries which contain banned keywords can't be managed using net2ftp. This is to avoid Paypal or Ebay scams from being uploaded through net2ftp.");
        $warnings .= "<br />\n";
    }
    if ($nr_entries_too_big > 0) {
        $warnings .= __("Files which are too big can't be downloaded, uploaded, copied, moved, searched, zipped, unzipped, viewed or edited; they can only be renamed, chmodded or deleted.");
        $warnings .= "<br />\n";
    }
    // Store the warnings and new directory in $list["stats"]
    if (isset($warnings) == true) {
        $list["stats"]["warnings"] = $warnings;
    } else {
        $list["stats"]["warnings"] = "";
    }
    $list["stats"]["newdirectory"] = $directory;
    // Store the statistics
    $list["stats"]["directories"]["total_size_formated"] = formatFilesize($list["stats"]["directories"]["total_size"]);
    $list["stats"]["files"]["total_size_formated"] = formatFilesize($list["stats"]["files"]["total_size"]);
    $list["stats"]["directories"]["total_number"] = $directory_index - 1;
    $list["stats"]["files"]["total_number"] = $file_index - 1;
    $list["stats"]["symlinks"]["total_number"] = $symlink_index - 1;
    $list["stats"]["unrecognized"]["total_number"] = $unrecognized_index - 1;
    // Put everything together in $list["all"]
    $list["all"] = $list["directories"] + $list["files"] + $list["symlinks"] + $list["unrecognized"];
    // -------------------------------------------------------------------------
    // Step 4 - Return the result
    // -------------------------------------------------------------------------
    return $list;
    // -------------------------------------------------------------------------
    // Some documentation:
    // 1 - Some FTP servers return a total on the first line
    // 2 - Some FTP servers return . and .. in their list of directories
    // ftp_scanline does not return those entries.
    // -------------------------------------------------------------------------
    // 1 - After doing some tests on different public FTP servers, it appears that
    // they reply differently to the ftp_rawlist request:
    //      - some FTP servers, like ftp.belnet.be, start with a line summarizing how
    //        many subdirectories and files there are in the current directory. The
    //        real list of subdirectories and files starts on the second line.
    //               [0] => total 15
    //               [1] => drwxr-xr-x 11 BELNET Archive 512 Feb 6 2000 BELNET
    //               [2] => drwxr-xr-x 2 BELNET Archive 512 Oct 29 2001 FVD-SFI
    //      - some other FTP servers, like ftp.redhat.com/pub, start directly with the
    //        list of subdirectories and files.
    //               [0] => drwxr-xr-x 9 ftp ftp 4096 Jan 11 06:34 contrib
    //               [1] => drwxr-xr-x 13 ftp ftp 4096 Jan 29 21:59 redhat
    //               [2] => drwxrwsr-x 6 ftp ftp 4096 Jun 05 2002 up2date
    // 2 - Some FTP servers return "." and ".." as directories. These fake entries
    // have to be eliminated!
    // They would cause infinite loops in the copy/move/delete functions.
    //               [0] => drwxr-xr-x 5 80 www 512 Apr 10 09:39 .
    //               [1] => drwxr-xr-x 16 80 www 512 Apr 9 08:51 ..
    //               [2] => -rw-r--r-- 1 80 www 5647 Apr 9 08:12 _CHANGES_v0.5
    //               [3] => -rw-r--r-- 1 80 www 1239 Apr 9 08:12 _CREDITS_v0.5
}
示例#9
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the new directory screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output;
    if (isset($_POST["newNames"]) == true) {
        $newNames = validateEntry($_POST["newNames"]);
    } else {
        $newNames = "";
    }
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    // Title
    $title = __("Create new directories");
    // Form name, back and forward buttons
    $formname = "NewDirForm";
    $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) {
        // Open connection
        setStatus(2, 10, __("Connecting to the FTP server"));
        $conn_id = ftp_openconnection();
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        // Create new directories
        setStatus(4, 10, __("Processing the entries"));
        for ($k = 1; $k <= sizeof($newNames); $k++) {
            if (strlen($newNames[$k]) > 0) {
                $newsubdir = glueDirectories($net2ftp_globals["directory"], $newNames[$k]);
                ftp_newdirectory($conn_id, $newsubdir);
                if ($net2ftp_result["success"] == false) {
                    setErrorVars(true, "", "", "", "");
                    // Continue anyway
                    $net2ftp_output["newdir"][] = __("Directory <b>%1\$s</b> could not be created.", htmlEncode2($newNames[$k]));
                } else {
                    $net2ftp_output["newdir"][] = __("Directory <b>%1\$s</b> was successfully created.", htmlEncode2($newNames[$k]));
                }
            }
            // End if
        }
        // End for
        // Close connection
        ftp_closeconnection($conn_id);
    }
    // end elseif
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
示例#10
0
function includeLanguageFile() {

// -------------------------------------------------------------------------
// Global variables
// -------------------------------------------------------------------------
	global $net2ftp_globals, $net2ftp_messages;
	$languageArray = getLanguageArray();

// If language exists, include the language file
	if (array_key_exists($net2ftp_globals["language"], $languageArray) == true) { 
		$languageFile = glueDirectories($net2ftp_globals["application_languagesdir"], $languageArray[$net2ftp_globals["language"]]["file"]);
		require_once($languageFile); 
	}

// If it does not exist, use the default language nr "en" (English)
	else { 
		$net2ftp_globals["language"] = "en";
		$languageFile = glueDirectories($net2ftp_globals["application_languagesdir"], $languageArray[$net2ftp_globals["language"]]["file"]);
		require_once($languageFile);
	}

} // end  function includeLanguageFile
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the login screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
    // -------------------------------------------------------------------------
    // Variables
    // -------------------------------------------------------------------------
    $url = $net2ftp_globals["action_url"];
    // -------------------------------------------------------------------------
    // Delete all temporary files in the /temp folder which are older than 10 minutes
    // -------------------------------------------------------------------------
    $max_age_seconds = 600;
    // default: 10 minutes
    if ($handle = @opendir($net2ftp_globals["application_tempdir"])) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && $file != ".htaccess" && $file != ".htpasswd" && $file != "chmod_this_dir_to_777.txt" && $file != "index.php") {
                $dirfile = glueDirectories($net2ftp_globals["application_tempdir"], $file);
                $age_in_seconds = time() - @filemtime($dirfile);
                if ($age_in_seconds > $max_age_seconds) {
                    @unlink($dirfile);
                }
            }
        }
        closedir($handle);
    }
    // -------------------------------------------------------------------------
    // Delete the log entries which are older than X days (as set in settings.inc.php)
    // -------------------------------------------------------------------------
    if ($net2ftp_settings["use_database"] == "yes") {
        $datefrom = "1978-01-01";
        // date far in the past
        $dateto = date("Y-m-d", time() - 3600 * 24 * $net2ftp_settings["log_length_days"]);
        // by default: 2 weeks ago
        emptyLogs($datefrom, $dateto);
    }
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/logout.template.php";
}
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the login screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
    if (isset($_POST["input_admin_username"]) == true) {
        $input_admin_username = htmlEncode2(validateGenericInput($_POST["input_admin_username"]));
    } else {
        $input_admin_username = "";
    }
    if (isset($_POST["input_admin_password"]) == true) {
        $input_admin_password = htmlEncode2(validateGenericInput($_POST["input_admin_password"]));
    } else {
        $input_admin_password = "";
    }
    if (isset($_POST["dbusername2"]) == true) {
        $dbusername2 = validateUsername($_POST["dbusername2"]);
    } else {
        $dbusername2 = "";
    }
    if (isset($_POST["dbpassword2"]) == true) {
        $dbpassword2 = validatePassword($_POST["dbpassword2"]);
    } else {
        $dbpassword2 = "";
    }
    if (isset($_POST["dbname2"]) == true) {
        $dbname2 = validateGenericInput($_POST["dbname2"]);
    } else {
        $dbname2 = "";
    }
    if (isset($_POST["dbserver2"]) == true) {
        $dbserver2 = validateGenericInput($_POST["dbserver2"]);
    } else {
        $dbserver2 = "";
    }
    $dbusername2_html = htmlEncode2($dbusername2);
    $dbpassword2_html = htmlEncode2($dbpassword2);
    $dbname2_html = htmlEncode2($dbname2);
    $dbserver2_html = htmlEncode2($dbserver2);
    if ($dbserver2 == "") {
        $dbserver2 = "localhost";
    }
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    // Output variable
    $net2ftp_output["admin_createtables"][] = "";
    // Title
    $title = __("Admin functions");
    // Form name
    $formname = "AdminForm";
    // Read the SQL file
    $filename = glueDirectories($net2ftp_globals["application_rootdir"], "create_tables.sql");
    $handle = fopen($filename, "rb");
    // Open the file for reading only
    if ($handle == false) {
        $net2ftp_output["admin_createtables"][] = __("The handle of file %1\$s could not be opened.", $filename);
    }
    clearstatcache();
    // for filesize
    $sqlquerystring = fread($handle, filesize($filename));
    if ($sqlquerystring == false) {
        $net2ftp_output["admin_createtables"][] = __("The file %1\$s could not be opened.", $filename);
    }
    $result1 = fclose($handle);
    if ($result1 == false) {
        $net2ftp_output["admin_createtables"][] = __("The handle of file %1\$s could not be closed.", $filename);
    }
    // Split the SQL file in individual queries
    $sqlquerypieces = explode("\n", $sqlquerystring);
    // -------------------------------------------------------------------------
    // Variables for screen 1
    // -------------------------------------------------------------------------
    if ($net2ftp_globals["screen"] == 1) {
        // Next screen
        $nextscreen = 2;
        // Back and forward buttons
        $back_onclick = "document.forms['" . $formname . "'].state.value='admin';document.forms['" . $formname . "'].screen.value='1';document.forms['" . $formname . "'].submit();";
        $forward_onclick = "document.forms['" . $formname . "'].submit();";
    } elseif ($net2ftp_globals["screen"] == 2) {
        // Next screen
        $nextscreen = 1;
        // Back and forward buttons
        $back_onclick = "document.forms['" . $formname . "'].state.value='admin';document.forms['" . $formname . "'].screen.value='1';document.forms['" . $formname . "'].submit();";
        $dbpassword2_length = strlen($dbpassword2);
        // ------------------------------------
        // Connect
        // ------------------------------------
        $mydb = mysql_connect($dbserver2, $dbusername2, $dbpassword2);
        if ($mydb == false) {
            $net2ftp_output["admin_createtables"][] = __("The connection to the server <b>%1\$s</b> could not be set up. Please check the database settings you've entered.", $dbserver2_html) . "\n";
        }
        // ------------------------------------
        // Select
        // ------------------------------------
        if ($mydb != false) {
            $mysql_select_db_result = mysql_select_db($dbname2);
            if ($mysql_select_db_result == false) {
                $net2ftp_output["admin_createtables"][] = __("Unable to select the database <b>%1\$s</b>.", $dbserver2_html) . "\n";
            }
        }
        // ------------------------------------
        // Query
        // ------------------------------------
        if ($mydb != false && $mysql_select_db_result != false) {
            for ($i = 0; $i < sizeof($sqlquerypieces); $i++) {
                $mysql_query_results[$i] = mysql_query($sqlquerypieces[$i]);
                if ($mysql_query_results[$i] == false) {
                    $net2ftp_output["admin_createtables"][] = __("The SQL query nr <b>%1\$s</b> could not be executed.", $i + 1) . "\n";
                } else {
                    $net2ftp_output["admin_createtables"][] = __("The SQL query nr <b>%1\$s</b> was executed successfully.", $i + 1) . "\n";
                }
            }
        }
    }
    // end elseif
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
示例#13
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";
}
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the search 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 = "";
    }
    if (isset($_POST["searchoptions"]) == true) {
        $searchoptions = $_POST["searchoptions"];
    }
    if (isset($searchoptions["string"]) == false) {
        $searchoptions["string"] = "";
    }
    if (isset($searchoptions["case_sensitive"]) == false) {
        $searchoptions["case_sensitive"] = "";
    }
    if (isset($searchoptions["filename"]) == false) {
        $searchoptions["filename"] = "";
    }
    if (isset($searchoptions["size_from"]) == false) {
        $searchoptions["size_from"] = "";
    }
    if (isset($searchoptions["size_to"]) == false) {
        $searchoptions["size_to"] = "";
    }
    if (isset($searchoptions["modified_from"]) == false) {
        $searchoptions["modified_from"] = "";
    }
    if (isset($searchoptions["modified_to"]) == false) {
        $searchoptions["modified_to"] = "";
    }
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    // Title
    // See below
    // Form name, back and forward buttons
    $formname = "FindstringForm";
    $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
    $forward_onclick = "document.forms['" . $formname . "'].submit();";
    // Next screen
    $nextscreen = 2;
    // -------------------------------------------------------------------------
    // Variables for screen 1
    // -------------------------------------------------------------------------
    if ($net2ftp_globals["screen"] == 1) {
        // Title
        $title = __("Search directories and files");
        // From and to dates
        $tomorrow = date("Y-m-d", time() + 3600 * 24);
        $oneweekago = date("Y-m-d", time() - 3600 * 24 * 7);
        $modified_from = $oneweekago;
        $modified_to = $tomorrow;
    } elseif ($net2ftp_globals["screen"] == 2) {
        // Title
        $title = __("Search results");
        // Check if $searchoptions["string"] is a valid string
        if (is_string($searchoptions["string"]) == false) {
            $errormessage = __("Please enter a valid search word or phrase.");
            setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
            return false;
        }
        // Check if $searchoptions["filename"] is a valid filename with a possible wildcard character *
        if ($searchoptions["filename"] != "" && preg_match("/^[a-zA-Z0-9_ *\\.-]*\$/", $searchoptions["filename"]) == 0) {
            $errormessage = __("Please enter a valid filename.");
            setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
            return false;
        }
        // Check if $searchoptions["size_from"] and $searchoptions["size_to"] are valid numbers
        if ($searchoptions["size_from"] != "" && is_numeric($searchoptions["size_from"]) == false) {
            $errormessage = __("Please enter a valid file size in the \"from\" textbox, for example 0.");
            setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
            return false;
        }
        if ($searchoptions["size_to"] != "" && is_numeric($searchoptions["size_to"]) == false) {
            $errormessage = __("Please enter a valid file size in the \"to\" textbox, for example 500000.");
            setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
            return false;
        }
        // Check if $searchoptions["modified_from"] and $searchoptions["modified_to"] are valid dates
        if ($searchoptions["modified_from"] != "" && preg_match("/^[0-9-]*\$/", $searchoptions["modified_from"]) == 0) {
            $errormessage = __("Please enter a valid date in Y-m-d format in the \"from\" textbox.");
            setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
            return false;
        }
        if ($searchoptions["modified_to"] != "" && preg_match("/^[0-9-]*\$/", $searchoptions["modified_to"]) == 0) {
            $errormessage = __("Please enter a valid date in Y-m-d format in the \"to\" textbox.");
            setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
            return false;
        }
        // ------------
        // CONVERSIONS
        // ------------
        // Convert the wildcard character * in the filename by the wildcard .* that can be read by preg_match
        // So this *.* becomes this .*..*
        $searchoptions["filename"] = str_replace("*", ".*", $searchoptions["filename"]);
        // Convert the mtime to a unix timestamp
        $searchoptions["modified_from"] = strtotime($searchoptions["modified_from"]);
        $searchoptions["modified_to"] = strtotime($searchoptions["modified_to"]);
        // Open connection
        setStatus(2, 10, __("Connecting to the FTP server"));
        $conn_id = ftp_openconnection();
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        // Find the files
        $result = array();
        setStatus(4, 10, __("Searching the files..."));
        $result = ftp_processfiles("findstring", $conn_id, $net2ftp_globals["directory"], $list, $searchoptions, $result, 0);
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        // Close connection
        ftp_closeconnection($conn_id);
        if (sizeof($result) == 0) {
            $net2ftp_output["findstring"][] = __("The word <b>%1\$s</b> was not found in the selected directories and files.", $searchoptions["string"]);
        } else {
            $net2ftp_output["findstring"][] = __("The word <b>%1\$s</b> was found in the following files:", $searchoptions["string"]);
            for ($i = 0; $i < sizeof($result); $i++) {
                $net2ftp_output["findstring"][] = glueDirectories($result[$i]["directory"], $result[$i]["dirfilename"]) . " line " . $result[$i]["line"];
            }
            // end for
        }
    }
    // end if
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
示例#15
0
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("&amp;", "&", $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("&amp;", "&", $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;
        }
    }
}