Exemple #1
0
function net2ftp_module_sendHttpHeaders()
{
    // --------------
    // This function sends HTTP headers
    // --------------
    global $net2ftp_globals, $net2ftp_settings;
    if (isset($_POST["list"]) == true) {
        $list = getSelectedEntries($_POST["list"]);
    } elseif (isset($_GET["list"]) == true) {
        $list = getSelectedEntries($_GET["list"]);
    } else {
        $list = "";
    }
    if ($net2ftp_settings["functionuse_downloadzip"] == "yes") {
        $zipactions["download"] = "yes";
        $zipactions["email"] = "no";
        $zipactions["save"] = "no";
        ftp_zip("", $net2ftp_globals["directory"], $list, $zipactions, "", 0);
    } else {
        $errormessage = __("This function has been disabled by the Administrator of this website.");
        setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
        return false;
    }
}
Exemple #2
0
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the login screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output;
    // The 2 go_to_state variables come from the bookmark, or from registerglobals.inc.php
    if (isset($_GET["go_to_state"]) == true) {
        $go_to_state = validateGenericInput($_GET["go_to_state"]);
    } else {
        $go_to_state = $net2ftp_globals["go_to_state"];
    }
    if (isset($_GET["go_to_state2"]) == true) {
        $go_to_state2 = validateGenericInput($_GET["go_to_state2"]);
    } else {
        $go_to_state2 = $net2ftp_globals["go_to_state2"];
    }
    if (isset($_GET["errormessage"]) == true) {
        $errormessage = validateGenericInput($_GET["errormessage"]);
    }
    // Most actions
    if (isset($_POST["list"]) == true) {
        $list = getSelectedEntries($_POST["list"]);
    } else {
        $list = "";
    }
    // Bookmark
    if (isset($_POST["url"]) == true) {
        $url = validateGenericInput($_POST["url"]);
    } else {
        $url = "";
    }
    if (isset($_POST["text"]) == true) {
        $text = validateGenericInput($_POST["text"]);
    } else {
        $text = "";
    }
    // Copy, move, delete
    if (isset($_POST["ftpserver2"]) == true) {
        $net2ftp_globals["ftpserver2"] = validateFtpserver($_POST["ftpserver2"]);
    } else {
        $net2ftp_globals["ftpserver2"] = "";
    }
    if (isset($_POST["ftpserverport2"]) == true) {
        $net2ftp_globals["ftpserverport2"] = validateFtpserverport($_POST["ftpserverport2"]);
    } else {
        $net2ftp_globals["ftpserverport2"] = "";
    }
    if (isset($_POST["username2"]) == true) {
        $net2ftp_globals["username2"] = validateUsername($_POST["username2"]);
    } else {
        $net2ftp_globals["username2"] = "";
    }
    if (isset($_POST["password2"]) == true) {
        $net2ftp_globals["password2"] = validatePassword($_POST["password2"]);
    } else {
        $net2ftp_globals["password2"] = "";
    }
    // Edit
    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 = "";
    }
    // Find string
    if (isset($_POST["searchoptions"]) == true) {
        $searchoptions = $_POST["searchoptions"];
    }
    // New directory
    // Rename
    if (isset($_POST["newNames"]) == true) {
        $newNames = validateEntry($_POST["newNames"]);
    } else {
        $newNames = "";
    }
    // Raw FTP command
    if (isset($_POST["command"]) == true) {
        $command = $_POST["command"];
    } else {
        $command = "CWD {$directory_html}\nPWD\n";
    }
    // Zip
    if (isset($_POST["zipactions"]) == true) {
        $zipactions = $_POST["zipactions"];
    } else {
        $zipactions = "";
    }
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    $formname = "LoginForm";
    $enctype = "";
    if ($net2ftp_globals["state2"] == "admin") {
        $message = __("Please enter your Administrator username and password.");
        $button_text = __("Login");
        $username_fieldname = "input_admin_username";
        $password_fieldname = "input_admin_password";
        $username_value = "";
        $password_value = "";
        $focus = $username_fieldname;
    } elseif ($net2ftp_globals["state2"] == "bookmark") {
        $message = __("Please enter your username and password for FTP server <b>%1\$s</b>.", htmlEncode2($net2ftp_globals["ftpserver"]));
        $button_text = __("Login");
        $username_fieldname = "username";
        $password_fieldname = "password";
        if (isset($net2ftp_globals["username"]) == true) {
            $username_value = htmlEncode2($net2ftp_globals["username"]);
            $focus = $password_fieldname;
        } else {
            $username_value = "";
            $focus = $username_fieldname;
        }
        $password_value = "";
    } elseif ($net2ftp_globals["state2"] == "session_expired") {
        $message = __("Your session has expired; please enter your password for FTP server <b>%1\$s</b> to continue.", htmlEncode2($net2ftp_globals["ftpserver"]));
        $button_text = __("Continue");
        $username_fieldname = "username";
        $password_fieldname = "password";
        if (isset($net2ftp_globals["username"]) == true) {
            $username_value = htmlEncode2($net2ftp_globals["username"]);
            $focus = $password_fieldname;
        } else {
            $username_value = "";
            $focus = $username_fieldname;
        }
        $password_value = "";
    } elseif ($net2ftp_globals["state2"] == "session_ipchange") {
        $message = __("Your IP address has changed; please enter your password for FTP server <b>%1\$s</b> to continue.", htmlEncode2($net2ftp_globals["ftpserver"]));
        $button_text = __("Continue");
        $username_fieldname = "username";
        $password_fieldname = "password";
        if (isset($net2ftp_globals["username"]) == true) {
            $username_value = htmlEncode2($net2ftp_globals["username"]);
            $focus = $password_fieldname;
        } else {
            $username_value = "";
            $focus = $username_fieldname;
        }
        $password_value = "";
    }
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/login_small.template.php";
}
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the rename 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["newNames"]) == true) {
        $newNames = validateEntry($_POST["newNames"]);
    } else {
        $newNames = "";
    }
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    // Title
    $title = __("Rename directories and files");
    // Form name, back and forward buttons
    $formname = "RenameForm";
    $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;
        }
        // Rename files
        setStatus(4, 10, __("Processing the entries"));
        for ($i = 1; $i <= sizeof($list["all"]); $i++) {
            if (strstr($list["all"][$i]["dirfilename"], "..") != false) {
                $net2ftp_output["rename"][] = __("The new name may not contain any dots. This entry was not renamed to <b>%1\$s</b>", htmlEncode2($newNames[$i])) . "<br />";
                continue;
            }
            if (checkAuthorizedName($newNames[$i]) == false) {
                $net2ftp_output["rename"][] = __("The new name may not contain any banned keywords. This entry was not renamed to <b>%1\$s</b>", htmlEncode2($newNames[$i])) . "<br />";
                continue;
            }
            ftp_rename2($conn_id, $net2ftp_globals["directory"], $list["all"][$i]["dirfilename"], $newNames[$i]);
            if ($net2ftp_result["success"] == false) {
                setErrorVars(true, "", "", "", "");
                $net2ftp_output["rename"][] = __("<b>%1\$s</b> could not be renamed to <b>%2\$s</b>", htmlEncode2($list["all"][$i]["dirfilename"]), htmlEncode2($newNames[$i]));
                continue;
            } else {
                $net2ftp_output["rename"][] = __("<b>%1\$s</b> was successfully renamed to <b>%2\$s</b>", htmlEncode2($list["all"][$i]["dirfilename"]), htmlEncode2($newNames[$i]));
            }
        }
        // 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";
}
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the login screen
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output;
    if (isset($_POST["list"]) == true) {
        $list = getSelectedEntries($_POST["list"]);
    } else {
        $list = "";
    }
    // -------------------------------------------------------------------------
    // Variables
    // -------------------------------------------------------------------------
    // Title
    $title = __("Size of selected directories and files");
    // Form name, back and forward buttons
    $formname = "CalculateSizeForm";
    $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
    // Open connection
    setStatus(2, 10, __("Connecting to the FTP server"));
    $conn_id = ftp_openconnection();
    if ($net2ftp_result["success"] == false) {
        return false;
    }
    // Calculate the size
    $options = array();
    $result['size'] = 0;
    $result['skipped'] = 0;
    $result = ftp_processfiles("calculatesize", $conn_id, $net2ftp_globals["directory"], $list, $options, $result, 0);
    // Close connection
    ftp_closeconnection($conn_id);
    // Print message
    $net2ftp_output["calculatesize"][] = __("The total size taken by the selected directories and files is:") . " <b>" . formatFilesize($result['size']) . "</b> (" . $result['size'] . " Bytes)";
    if ($result['skipped'] > 0) {
        $net2ftp_output["calculatesize"][] = __("The number of files which were skipped is:") . " <b>" . $result['skipped'] . "</b>";
    }
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
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";
}
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"]);
        }
    }
    // end if
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
function net2ftp_module_printBody()
{
    // --------------
    // This function prints the copy/move/delete 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["ftpserver2"]) == true) {
        $net2ftp_globals["ftpserver2"] = validateFtpserver($_POST["ftpserver2"]);
    } else {
        $net2ftp_globals["ftpserver2"] = "";
    }
    if (isset($_POST["ftpserverport2"]) == true) {
        $net2ftp_globals["ftpserverport2"] = validateFtpserverport($_POST["ftpserverport2"]);
    } else {
        $net2ftp_globals["ftpserverport2"] = "";
    }
    if (isset($_POST["username2"]) == true) {
        $net2ftp_globals["username2"] = validateUsername($_POST["username2"]);
    } else {
        $net2ftp_globals["username2"] = "";
    }
    if (isset($_POST["password2"]) == true) {
        $net2ftp_globals["password2"] = validatePassword($_POST["password2"]);
    } else {
        $net2ftp_globals["password2"] = "";
    }
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    // Title
    if ($net2ftp_globals["state2"] == "copy") {
        $title = __("Copy directories and files");
    } elseif ($net2ftp_globals["state2"] == "move") {
        $title = __("Move directories and files");
    } elseif ($net2ftp_globals["state2"] == "delete") {
        $title = __("Delete directories and files");
    }
    // Form name, back and forward buttons
    $formname = "CopyMoveDeleteForm";
    $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 to the source server
        // ---------------------------------------
        setStatus(2, 10, __("Connecting to the FTP server"));
        $conn_id_source = ftp_openconnection();
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        // ---------------------------------------
        // Open connection to the target server, if it is different from the source server, or if the username
        // is different (different users may have different authorizations on the same FTP server)
        // ---------------------------------------
        if (($net2ftp_globals["ftpserver2"] != "" || $net2ftp_globals["username2"] != "") && ($net2ftp_globals["ftpserver2"] != $net2ftp_globals["ftpserver"] || $net2ftp_globals["username2"] != $net2ftp_globals["username"])) {
            $conn_id_target = ftp_openconnection2();
            // Note: ftp_openconnection2 cleans the input values
            if ($net2ftp_result["success"] == false) {
                return false;
            }
        } else {
            $conn_id_target = $conn_id_source;
        }
        // ---------------------------------------
        // Copy, move or delete the files and directories
        // ---------------------------------------
        ftp_copymovedelete($conn_id_source, $conn_id_target, $list, $net2ftp_globals["state2"], 0);
        // ---------------------------------------
        // Close the connection to the source server
        // ---------------------------------------
        ftp_closeconnection($conn_id_source);
        // ---------------------------------------
        // Close the connection to the target server, if it is different from the source server
        // ---------------------------------------
        if ($conn_id_source != $conn_id_target) {
            ftp_closeconnection($conn_id_target);
        }
    }
    // end elseif
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
Exemple #8
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 zip 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["zipactions"]) == true) {
        $zipactions = $_POST["zipactions"];
    } else {
        $zipactions = "";
    }
    // -------------------------------------------------------------------------
    // Variables for all screens
    // -------------------------------------------------------------------------
    // Title
    $title = __("Zip entries");
    // Form name, back and forward buttons
    $formname = "ZipForm";
    $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;
        // Default filename of the zip file
        $zipfilename = get_filename_name($list["files"][1]["dirfilename"]) . ".zip";
    } elseif ($net2ftp_globals["screen"] == 2) {
        // --------------------
        // Check the input data
        // --------------------
        // Filename
        if ($zipactions["save"] == "yes" && $zipactions["save"]["filename"] == "") {
            $errormessage = __("You did not enter a filename for the zipfile. Go back and enter a filename.") . "<br />";
            setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
            return false;
        }
        // Email address
        if ($zipactions["email"] == "yes" && checkEmailAddress($zipactions["email_to"]) == false) {
            $errormessage = __("The email address you have entered (%1\$s) does not seem to be valid.<br />Please enter an address in the format <b>username@domain.com</b>", $zipactions["email_to"]) . "<br />";
            setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
            return false;
        }
        // --------------------
        // Execute the function
        // --------------------
        setStatus(4, 10, __("Processing the entries"));
        $zipactions["download"] == "no";
        ftp_zip("", $net2ftp_globals["directory"], $list, $zipactions, "", 0);
        if ($net2ftp_result["success"] == false) {
            return false;
        }
    }
    // end elseif
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
Exemple #10
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 = __("Chmod directories and files");
    // Form name, back and forward buttons
    $formname = "ChmodForm";
    $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;
        // Initialize variables
        $directory_index = 1;
        $file_index = 1;
        $symlink_index = 1;
        for ($i = 1; $i <= count($list["all"]); $i++) {
            if ($list["all"][$i]["dirorfile"] == "d") {
                $list["all"][$i]["message"] = __("Set the permissions of directory <b>%1\$s</b> to: ", $list["all"][$i]["dirfilename"]) . "<br />\n";
            } elseif ($list["all"][$i]["dirorfile"] == "-") {
                $list["all"][$i]["message"] = __("Set the permissions of file <b>%1\$s</b> to: ", $list["all"][$i]["dirfilename"]) . "<br />\n";
            } elseif ($list["all"][$i]["dirorfile"] == "l") {
                $list["all"][$i]["message"] = __("Set the permissions of symlink <b>%1\$s</b> to: ", $list["all"][$i]["dirfilename"]) . "<br />\n";
            }
            $owner_chmod = 0;
            if (substr($list["all"][$i]["permissions"], 0, 1) == "r") {
                $owner_chmod += 4;
                $list["all"][$i]["owner_read"] = "checked=\"checked\"";
            } else {
                $list["all"][$i]["owner_read"] = "";
            }
            if (substr($list["all"][$i]["permissions"], 1, 1) == "w") {
                $owner_chmod += 2;
                $list["all"][$i]["owner_write"] = "checked=\"checked\"";
            } else {
                $list["all"][$i]["owner_write"] = "";
            }
            if (substr($list["all"][$i]["permissions"], 2, 1) == "x") {
                $owner_chmod += 1;
                $list["all"][$i]["owner_execute"] = "checked=\"checked\"";
            } else {
                $list["all"][$i]["owner_execute"] = "";
            }
            $group_chmod = 0;
            if (substr($list["all"][$i]["permissions"], 3, 1) == "r") {
                $group_chmod += 4;
                $list["all"][$i]["group_read"] = "checked=\"checked\"";
            } else {
                $list["all"][$i]["group_read"] = "";
            }
            if (substr($list["all"][$i]["permissions"], 4, 1) == "w") {
                $group_chmod += 2;
                $list["all"][$i]["group_write"] = "checked=\"checked\"";
            } else {
                $list["all"][$i]["group_write"] = "";
            }
            if (substr($list["all"][$i]["permissions"], 5, 1) == "x") {
                $group_chmod += 1;
                $list["all"][$i]["group_execute"] = "checked=\"checked\"";
            } else {
                $list["all"][$i]["group_execute"] = "";
            }
            $other_chmod = 0;
            if (substr($list["all"][$i]["permissions"], 6, 1) == "r") {
                $other_chmod += 4;
                $list["all"][$i]["other_read"] = "checked=\"checked\"";
            } else {
                $list["all"][$i]["other_read"] = "";
            }
            if (substr($list["all"][$i]["permissions"], 7, 1) == "w") {
                $other_chmod += 2;
                $list["all"][$i]["other_write"] = "checked=\"checked\"";
            } else {
                $list["all"][$i]["other_write"] = "";
            }
            if (substr($list["all"][$i]["permissions"], 8, 1) == "x") {
                $other_chmod += 1;
                $list["all"][$i]["other_execute"] = "checked=\"checked\"";
            } else {
                $list["all"][$i]["other_execute"] = "";
            }
            $list["all"][$i]["chmodvalue"] = $owner_chmod . $group_chmod . $other_chmod;
            if ($list["all"][$i]["dirorfile"] == "d") {
                $list["directories"][$directory_index]["chmodvalue"] = $list["all"][$i]["chmodvalue"];
                $directory_index++;
            } elseif ($list["all"][$i]["dirorfile"] == "-") {
                $list["files"][$file_index]["chmodvalue"] = $list["all"][$i]["chmodvalue"];
                $file_index++;
            } elseif ($list["all"][$i]["dirorfile"] == "l") {
                $list["symlinks"][$symlink_index]["chmodvalue"] = $list["all"][$i]["chmodvalue"];
                $symlink_index++;
            }
        }
        // end for
    } elseif ($net2ftp_globals["screen"] == 2) {
        // Initialize variables
        $directory_index = 1;
        $file_index = 1;
        $symlink_index = 1;
        // Calculate the chmod octal
        for ($i = 1; $i <= count($list["all"]); $i++) {
            if (isset($list["all"][$i]["owner_read"]) == false) {
                $list["all"][$i]["owner_read"] = 0;
            }
            if (isset($list["all"][$i]["owner_write"]) == false) {
                $list["all"][$i]["owner_write"] = 0;
            }
            if (isset($list["all"][$i]["owner_execute"]) == false) {
                $list["all"][$i]["owner_execute"] = 0;
            }
            if (isset($list["all"][$i]["group_read"]) == false) {
                $list["all"][$i]["group_read"] = 0;
            }
            if (isset($list["all"][$i]["group_write"]) == false) {
                $list["all"][$i]["group_write"] = 0;
            }
            if (isset($list["all"][$i]["group_execute"]) == false) {
                $list["all"][$i]["group_execute"] = 0;
            }
            if (isset($list["all"][$i]["other_read"]) == false) {
                $list["all"][$i]["other_read"] = 0;
            }
            if (isset($list["all"][$i]["other_write"]) == false) {
                $list["all"][$i]["other_write"] = 0;
            }
            if (isset($list["all"][$i]["other_execute"]) == false) {
                $list["all"][$i]["other_execute"] = 0;
            }
            $ownerOctal = $list["all"][$i]["owner_read"] + $list["all"][$i]["owner_write"] + $list["all"][$i]["owner_execute"];
            $groupOctal = $list["all"][$i]["group_read"] + $list["all"][$i]["group_write"] + $list["all"][$i]["group_execute"];
            $otherOctal = $list["all"][$i]["other_read"] + $list["all"][$i]["other_write"] + $list["all"][$i]["other_execute"];
            $chmodOctal = $ownerOctal . $groupOctal . $otherOctal;
            if ($chmodOctal > 777 || $chmodOctal < 0) {
                $errormessage = __("The chmod nr <b>%1\$s</b> is out of the range 000-777. Please try again.", $chmodOctal);
                setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                return false;
            } else {
                $list["all"][$i]["chmodoctal"] = $chmodOctal;
                if ($list["all"][$i]["dirorfile"] == "d") {
                    $list["directories"][$directory_index]["chmodoctal"] = $list["all"][$i]["chmodoctal"];
                    $directory_index++;
                } elseif ($list["all"][$i]["dirorfile"] == "-") {
                    $list["files"][$file_index]["chmodoctal"] = $list["all"][$i]["chmodoctal"];
                    $file_index++;
                } elseif ($list["all"][$i]["dirorfile"] == "l") {
                    $list["symlinks"][$symlink_index]["chmodoctal"] = $list["all"][$i]["chmodoctal"];
                    $symlink_index++;
                }
            }
        }
        // End for
        // Open connection
        setStatus(2, 10, __("Connecting to the FTP server"));
        $conn_id = ftp_openconnection();
        if ($conn_id == false) {
            return false;
        }
        // Chmod the entries
        setStatus(4, 10, __("Processing the entries"));
        ftp_chmod2($conn_id, $net2ftp_globals["directory"], $list, 0);
        if ($net2ftp_result["success"] == false) {
            return false;
        }
        // Close connection
        ftp_closeconnection($conn_id);
    }
    // end elseif
    // -------------------------------------------------------------------------
    // Print the output
    // -------------------------------------------------------------------------
    require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}