예제 #1
0
function ftp_chmod2($conn_id, $directory, $list, $divelevel)
{
    // --------------
    // This function chmods a directory or file
    //
    // $list[$i]["dirorfile"] contains d or - which indicates if the entry is a directory or a file
    // $list[$i]["dirfilename"] contains the name of the entry
    // $list[$i]["chmodoctal"] contains the 3-digit nr
    //
    // If the entry is a directory, $list[$i]["chmod_subdirectories"] and $list[$i]["chmod_subfiles"] are "yes" if
    // the subdirectories and files within the chmodded directory should also be chmodded
    // --------------
    // -------------------------------------------------------------------------
    // Global variables
    // -------------------------------------------------------------------------
    global $net2ftp_globals, $net2ftp_result, $net2ftp_output;
    // -------------------------------------------------------------------------
    // Initialization
    // -------------------------------------------------------------------------
    if ($divelevel == 0) {
        $net2ftp_output["ftp_chmod2"][] = "<ul>";
    }
    // -------------------------------------------------------------------------
    // For all directories
    // -------------------------------------------------------------------------
    for ($i = 1; $i <= $list["stats"]["directories"]["total_number"]; $i = $i + 1) {
        $currentdirectory = glueDirectories($directory, $list["directories"][$i]["dirfilename"]);
        // ------------------------------------
        // Determine if the directory must first be chmodded (if chmodded to 5 or 7),
        // or first be traversed (if chmodded to other values)
        // A problem is that we don't know if the FTP user is the owner/group/other of the file...
        // ------------------------------------
        if ($list["directories"][$i]["chmodoctal"] == 555 || $list["directories"][$i]["chmodoctal"] == 557 || $list["directories"][$i]["chmodoctal"] == 575 || $list["directories"][$i]["chmodoctal"] == 577 || $list["directories"][$i]["chmodoctal"] == 755 || $list["directories"][$i]["chmodoctal"] == 757 || $list["directories"][$i]["chmodoctal"] == 775 || $list["directories"][$i]["chmodoctal"] == 777) {
            $first_chmod_then_traverse = true;
        } else {
            $first_chmod_then_traverse = false;
        }
        // ------------------------------------
        // Chmod the directory - FIRST CHMOD THEN TRAVERSE
        // If the $divelevel == 0 then chmod it in any case as it is the top directory
        // If the $divelevel > 0  then chmod it only if chmod_subdirectories == "yes"
        // ------------------------------------
        if ($first_chmod_then_traverse == true && ($list["directories"][$i]["chmod_subdirectories"] == "yes" || $divelevel == 0)) {
            $sitecommand = "chmod 0" . $list["directories"][$i]["chmodoctal"] . " {$currentdirectory}";
            $success1 = ftp_site($conn_id, $sitecommand);
            if ($success1 == false) {
                $errormessage = __("Unable to execute site command <b>%1\$s</b>. Note that the CHMOD command is only available on Unix FTP servers, not on Windows FTP servers.", $sitecommand);
                setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                return false;
            } elseif ($success1 == true) {
                $net2ftp_output["ftp_chmod2"][] = __("Directory <b>%1\$s</b> successfully chmodded to <b>%2\$s</b>", $currentdirectory, $list["directories"][$i]["chmodoctal"]);
            }
        }
        // ------------------------------------
        // If the subdirectories and files within the current directory also have to be chmodded...
        // ------------------------------------
        if ($list["directories"][$i]["chmod_subdirectories"] == "yes" || $list["directories"][$i]["chmod_subfiles"] == "yes") {
            // Get a new list
            $newlist = ftp_getlist($conn_id, $currentdirectory);
            if ($net2ftp_result["success"] == false) {
                return false;
            }
            // Add information to the list
            for ($j = 1; $j <= $newlist["stats"]["directories"]["total_number"]; $j++) {
                $newlist["directories"][$j]["chmodoctal"] = $list["directories"][$i]["chmodoctal"];
                $newlist["directories"][$j]["chmod_subdirectories"] = $list["directories"][$i]["chmod_subdirectories"];
                $newlist["directories"][$j]["chmod_subfiles"] = $list["directories"][$i]["chmod_subfiles"];
            }
            for ($j = 1; $j <= $newlist["stats"]["files"]["total_number"]; $j++) {
                $newlist["files"][$j]["chmodoctal"] = $list["directories"][$i]["chmodoctal"];
                $newlist["files"][$j]["chmod_subdirectories"] = $list["directories"][$i]["chmod_subdirectories"];
                $newlist["files"][$j]["chmod_subfiles"] = $list["directories"][$i]["chmod_subfiles"];
            }
            // Call the function recursively
            $net2ftp_output["ftp_chmod2"][] = __("Processing entries within directory <b>%1\$s</b>:", $currentdirectory);
            $net2ftp_output["ftp_chmod2"][] = "<ul>";
            $newdivelevel = $divelevel + 1;
            ftp_chmod2($conn_id, $currentdirectory, $newlist, $newdivelevel);
            $net2ftp_output["ftp_chmod2"][] = "</ul>";
        }
        // end if subdirectories and files
        // ------------------------------------
        // Chmod the directory - FIRST TRAVERSE THEN CHMOD
        // If the $divelevel == 0 then chmod it in any case as it is the top directory
        // If the $divelevel > 0  then chmod it only if chmod_subdirectories == "yes"
        // ------------------------------------
        if ($first_chmod_then_traverse == false && ($list["directories"][$i]["chmod_subdirectories"] == "yes" || $divelevel == 0)) {
            $sitecommand = "chmod 0" . $list["directories"][$i]["chmodoctal"] . " {$currentdirectory}";
            $success1 = ftp_site($conn_id, $sitecommand);
            if ($success1 == false) {
                $errormessage = __("Unable to execute site command <b>%1\$s</b>. Note that the CHMOD command is only available on Unix FTP servers, not on Windows FTP servers.", $sitecommand);
                setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                return false;
            } elseif ($success1 == true) {
                $net2ftp_output["ftp_chmod2"][] = __("Directory <b>%1\$s</b> successfully chmodded to <b>%2\$s</b>", $currentdirectory, $list["directories"][$i]["chmodoctal"]);
            }
        }
    }
    // end for list_directories
    // -------------------------------------------------------------------------
    // Process the files
    // -------------------------------------------------------------------------
    for ($i = 1; $i <= $list["stats"]["files"]["total_number"]; $i = $i + 1) {
        $currentfile = glueDirectories($directory, $list["files"][$i]["dirfilename"]);
        // Chmod the files
        // If the $divelevel == 0 then chmod them in any case as they are the top files
        // If the $divelevel > 0  then chmod them only if chmod_subfiles == "yes"
        if ($list["files"][$i]["chmod_subfiles"] == "yes" || $divelevel == 0) {
            $sitecommand = "chmod 0" . $list["files"][$i]["chmodoctal"] . " {$currentfile}";
            $success2 = ftp_site($conn_id, $sitecommand);
            if ($success2 == false) {
                $errormessage = __("Unable to execute site command <b>%1\$s</b>. Note that the CHMOD command is only available on Unix FTP servers, not on Windows FTP servers.", $sitecommand);
                setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
                return false;
            } elseif ($success2 == true) {
                $net2ftp_output["ftp_chmod2"][] = __("File <b>%1\$s</b> was successfully chmodded to <b>%2\$s</b>", $currentfile, $list["files"][$i]["chmodoctal"]);
            }
        }
    }
    // end for list_files
    // Print message
    if ($divelevel == 0) {
        $net2ftp_output["ftp_chmod2"][] = __("All the selected directories and files have been processed.");
    }
}
예제 #2
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";
}