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";
    }
}
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
}
Example #3
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;
        }
    }
}