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 ftp_processfiles($dowhat, $conn_id, $directory, $list, $options, $result, $divelevel) { // -------------- // This function does something with files (get size, find string, ...) // The $list contains both directories and files. The files are simply processed; the // directories are parsed recursively. // // $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]["size"] contains the size of the entry // // OPTIONS: // if ($dowhat == "calculatesize") then // $options = array() doesn't contain anything // if ($dowhat == "findstring") then // $options["string"] a string // $options["case_sensitive"] blank or yes // $options["filename"] a filename with possible wildcard character * (it should match this preg_match regular expression: "/^[a-zA-Z0-9_ *-]*$/") // $options["size_from"], $options["size_to"] a number (in Bytes) // $options["modified_from"], $options["modified_to"] unix timestamps of the modification dates // // RESULT: // if ($dowhat == "calculatesize") then // $result["size"] // $result["skipped"] // if ($dowhat == "findstring") then // $result[$k]["directory"] contains the directory // $result[$k]["dirfilename"] contains the filename // $result[$k]["line"] contains the line nr // // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals, $net2ftp_result; // ------------------------------------------------------------------------- // Initialization // ------------------------------------------------------------------------- if ($divelevel == 0) { } // ------------------------------------------------------------------------- // For all directories // ------------------------------------------------------------------------- for ($i = 1; $i <= $list["stats"]["directories"]["total_number"]; $i = $i + 1) { $currentdirectory = glueDirectories($directory, $list["directories"][$i]["dirfilename"]); // Check if the directory contains a banned keyword if ($list["directories"][$i]["selectable"] != "ok") { continue; } // Get a new list $newlist = ftp_getlist($conn_id, $currentdirectory); if ($net2ftp_result["success"] == false) { return false; } // Call the function recursively $newdivelevel = $divelevel + 1; $result = ftp_processfiles($dowhat, $conn_id, $currentdirectory, $newlist, $options, $result, $newdivelevel); if ($net2ftp_result["success"] == false) { return false; } } // end for list_directories // ------------------------------------------------------------------------- // Process the files // ------------------------------------------------------------------------- for ($i = 1; $i <= $list["stats"]["files"]["total_number"]; $i = $i + 1) { // ------------------------------- // Calculate size // ------------------------------- if ($dowhat == "calculatesize") { // Check if the size information is entered // Check also if the size is numeric if (isset($list["files"][$i]["size"]) && is_numeric($list["files"][$i]["size"])) { $result["size"] = $result["size"] + $list["files"][$i]["size"]; } else { $result["skipped"] = $result["skipped"] + 1; } } elseif ($dowhat == "findstring") { // Check that the file is smaller than the maximum file size that can be processed with net2ftp if ($list["files"][$i]["selectable"] != "ok") { continue; } // Check that the file is within the limits indicated on the selection screen if ($list["files"][$i]["size"] < $options["size_from"] || $list["files"][$i]["size"] > $options["size_to"]) { // echo "File $i skipped"; continue; } // Check modification date (if that data is returned by the FTP server in the correct format) $mtime_file = strtotime($list["files"][$i]["mtime"]); // If strtotime cannot interprete the data returned by the FTP server it returns -1 if ($mtime_file != -1 && ($mtime_file < $options["modified_from"] || $mtime_file > $options["modified_to"])) { continue; } // Check the filename $pattern = "/^" . $options["filename"] . "\$/i"; // i at the end is for a case-insensitive match if (preg_match($pattern, $list["files"][$i]["dirfilename"]) == 0) { continue; } // Read the file $text = ftp_readfile("", $directory, $list["files"][$i]["dirfilename"]); // If the file could not be read correctly, continue to the next one if ($net2ftp_result["success"] == false) { setErrorVars(true, "", "", "", ""); continue; } elseif ($text == "") { continue; } // Split the file in an array, each element of the array containing one line of the file $text_lines = explode_lines($text); // For each line, check if the string occurs for ($line = 0; $line < sizeof($text_lines); $line++) { // STRSTR AND STRISTR if ($options["case_sensitive"] == "yes") { $found = strstr($text_lines[$line], $options["string"]); } else { $found = stristr($text_lines[$line], $options["string"]); } if ($found != false) { $tempresult["directory"] = $directory; $tempresult["directory_html"] = htmlEncode2($directory); $tempresult["directory_js"] = javascriptEncode2($directory); $tempresult["dirfilename"] = $list["files"][$i]["dirfilename"]; $tempresult["dirfilename_html"] = $list["files"][$i]["dirfilename_html"]; $tempresult["dirfilename_js"] = $list["files"][$i]["dirfilename_js"]; $tempresult["line"] = $line + 1; // $text_lines[0] contains the line 1, etc... array_push($result, $tempresult); } } // end for } // end if findstring } // end for list_files return $result; }
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"; }