function net2ftp_module_sendHttpHeaders() { // -------------- // This function sends HTTP headers // -------------- global $net2ftp_globals, $net2ftp_settings; if ($net2ftp_settings["functionuse_downloadfile"] == "yes") { ftp_downloadfile($net2ftp_globals["directory"], $net2ftp_globals["entry"]); } else { $errormessage = __("This function has been disabled by the Administrator of this website."); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } }
function connect2db() { // -------------- // This function logs user accesses to the site // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_settings; $mydb = mysql_connect($net2ftp_settings["dbserver"], $net2ftp_settings["dbusername"], $net2ftp_settings["dbpassword"]); if ($mydb == false) { setErrorVars(false, __("Unable to connect to the MySQL database. Please check your MySQL database settings in net2ftp's configuration file settings.inc.php."), debug_backtrace(), __FILE__, __LINE__); return false; } $result2 = mysql_select_db($net2ftp_settings["dbname"]); if ($result2 == false) { setErrorVars(false, __("Unable to select the MySQL database. Please check your MySQL database settings in net2ftp's configuration file settings.inc.php."), debug_backtrace(), __FILE__, __LINE__); return false; } return $mydb; }
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; } }
function putConsumption() { // -------------- // This function writes the consumption to the database. // It is run at the end of the script. // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals, $net2ftp_settings, $net2ftp_result; // ------------------------------------------------------------------------- // Initial checks // ------------------------------------------------------------------------- // Verify if a database is used, and if consumption checking is turned on. If not: don't continue. if ($net2ftp_settings["use_database"] != "yes" || $net2ftp_settings["check_consumption"] != "yes") { return true; } // When user is not logged in, the FTP server is not set if ($net2ftp_globals["ftpserver"] == "") { return true; } // If the REMOTE_ADDR is not filled in, then there is a problem (IP spoofing), so return an error if ($net2ftp_globals["REMOTE_ADDR"] == "") { setErrorVars(false, __("Unable to determine your IP address."), debug_backtrace(), __FILE__, __LINE__); return false; } // If the database has already been updated, don't do it a second time. // This is to avoid updating the database twice. The putConsumption() function // is called from index.php and from shutdown() in filesystem.inc.php. On Windows // the shutdown() function is called after *every* script execution. if ($net2ftp_globals["consumption_database_updated"] == 1) { return true; } // Add slashes to variables which are used in a SQL query, and which are // potentially unsafe (supplied by the user). // $date is calculated in this function // $time is calculated in this function $REMOTE_ADDR_safe = addslashes($net2ftp_globals["REMOTE_ADDR"]); $net2ftp_ftpserver_safe = addslashes($net2ftp_globals["ftpserver"]); // ------------------------------------------------------------------------- // Check the input // ------------------------------------------------------------------------- // if (preg_match("/^[0-9]+$/", $net2ftp_globals["consumption_ipaddress_datatransfer) == FALSE) { // setErrorVars(false, __("The variable <b>consumption_ipaddress_datatransfer</b> is not numeric."), debug_backtrace(), __FILE__, __LINE__); // return false; // } // ------------------------------------------------------------------------- // Connect // ------------------------------------------------------------------------- $mydb = connect2db(); if ($net2ftp_result["success"] == false) { return false; } // ------------------------------------------------------------------------- // Get date // ------------------------------------------------------------------------- $date = date("Y-m-d"); // ------------------------------------------------------------------------- // Put consumed data volume and execution time by the current IP address // ------------------------------------------------------------------------- $sqlquery1 = "SELECT * FROM net2ftp_log_consumption_ipaddress WHERE date = '{$date}' AND ipaddress = '{$REMOTE_ADDR_safe}';"; $result1 = mysql_query("{$sqlquery1}"); $nrofrows1 = mysql_num_rows($result1); if ($nrofrows1 == 1) { $sqlquery2 = "UPDATE net2ftp_log_consumption_ipaddress SET datatransfer = '" . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "', executiontime = '" . round($net2ftp_globals["consumption_ipaddress_executiontime"]) . "' WHERE date = '{$date}' AND ipaddress = '{$REMOTE_ADDR_safe}';"; $result2 = mysql_query("{$sqlquery2}"); $nrofrows2 = mysql_affected_rows($mydb); // Don't check on the UPDATE nr of rows, because when the values in the variables and in the table are the same, // the $nrofrows2 is set to 0. (This happens on the Browse screen, when the loading is fast: the datatransfer is 0 // and the executiontime is the same as in the table.) // if ($nrofrows2 != 1) { // setErrorVars(false, __("Table net2ftp_log_consumption_ipaddress could not be updated."), debug_backtrace(), __FILE__, __LINE__); // return false; // } } elseif ($nrofrows1 == 0) { $sqlquery3 = "INSERT INTO net2ftp_log_consumption_ipaddress VALUES('{$date}', '{$REMOTE_ADDR_safe}', '" . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "', '" . round($net2ftp_globals["consumption_ipaddress_executiontime"]) . "');"; $result3 = mysql_query("{$sqlquery3}"); $nrofrows3 = mysql_affected_rows($mydb); if ($nrofrows3 != 1) { setErrorVars(false, __("Table net2ftp_log_consumption_ipaddress could not be updated."), debug_backtrace(), __FILE__, __LINE__); return false; } } else { setErrorVars(false, __("Table net2ftp_log_consumption_ipaddress contains duplicate entries."), debug_backtrace(), __FILE__, __LINE__); return false; } // MySQL > 4.1.0 // $sqlquery1 = "INSERT INTO net2ftp_log_consumption_ipaddress VALUES('$date', '$REMOTE_ADDR_safe', '" . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "', '" . round($net2ftp_globals["consumption_ipaddress_executiontime"]) . "') ON DUPLICATE KEY UPDATE datatransfer = '" . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "', executiontime = '" . round($net2ftp_globals["consumption_ipaddress_executiontime"]) . "';"; // ------------------------------------------------------------------------- // Put consumed data volume and execution time to the current FTP server // ------------------------------------------------------------------------- $sqlquery4 = "SELECT * FROM net2ftp_log_consumption_ftpserver WHERE date = '{$date}' AND ftpserver = '{$net2ftp_ftpserver_safe}';"; $result4 = mysql_query("{$sqlquery4}"); $nrofrows4 = mysql_num_rows($result4); if ($nrofrows4 == 1) { $sqlquery5 = "UPDATE net2ftp_log_consumption_ftpserver SET datatransfer = '" . $net2ftp_globals["consumption_ftpserver_datatransfer"] . "', executiontime = '" . round($net2ftp_globals["consumption_ftpserver_executiontime"]) . "' WHERE date = '{$date}' AND ftpserver = '{$net2ftp_ftpserver_safe}';"; $result5 = mysql_query("{$sqlquery5}"); $nrofrows5 = mysql_affected_rows($mydb); // Don't check on the UPDATE nr of rows, because when the values in the variables and in the table are the same, // the $nrofrows2 is set to 0. (This happens on the Browse screen, when the loading is fast: the datatransfer is 0 // and the executiontime is the same as in the table.) // if ($nrofrows5 != 1) { // setErrorVars(false, __("Table net2ftp_log_consumption_ftpserver could not be updated."), debug_backtrace(), __FILE__, __LINE__); // return false; // } } elseif ($nrofrows4 == 0) { $sqlquery6 = "INSERT INTO net2ftp_log_consumption_ftpserver VALUES('{$date}', '{$net2ftp_ftpserver_safe}', '" . $net2ftp_globals["consumption_ftpserver_datatransfer"] . "', '" . round($net2ftp_globals["consumption_ftpserver_executiontime"]) . "');"; $result6 = mysql_query("{$sqlquery6}"); $nrofrows6 = mysql_affected_rows($mydb); if ($nrofrows6 != 1) { setErrorVars(false, __("Table net2ftp_log_consumption_ftpserver could not be updated."), debug_backtrace(), __FILE__, __LINE__); return false; } } else { setErrorVars(false, __("Table net2ftp_log_consumption_ftpserver contains duplicate entries."), debug_backtrace(), __FILE__, __LINE__); return false; } // ------------------------------------------------------------------------- // Update the net2ftp_log_access record with the consumed data volume and execution time // ------------------------------------------------------------------------- $sqlquery7 = "SELECT * FROM net2ftp_log_access WHERE id = '" . $net2ftp_globals["log_access_id"] . "';"; $result7 = mysql_query("{$sqlquery7}"); $nrofrows7 = mysql_num_rows($result7); if ($nrofrows7 == 1) { $sqlquery8 = "UPDATE net2ftp_log_access SET datatransfer = '" . $net2ftp_globals["consumption_datatransfer"] . "', executiontime = '" . round($net2ftp_globals["consumption_executiontime"]) . "' WHERE id = '" . $net2ftp_globals["log_access_id"] . "'"; $result8 = mysql_query("{$sqlquery8}"); $nrofrows8 = mysql_affected_rows($mydb); // Don't check on the UPDATE nr of rows, because when the values in the variables and in the table are the same, // the $nrofrows2 is set to 0. (This happens on the Browse screen, when the loading is fast: the datatransfer is 0 // and the executiontime is the same as in the table.) // if ($nrofrows8 != 1) { // setErrorVars(false, __("Table net2ftp_log_access could not be updated."), debug_backtrace(), __FILE__, __LINE__); // return false; // } } elseif ($nrofrows7 == 0) { $sqlquery9 = "INSERT INTO net2ftp_log_access VALUES('{$date}', '{$REMOTE_ADDR_safe}', '" . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "', '" . round($net2ftp_globals["consumption_ipaddress_executiontime"]) . "');"; $result9 = mysql_query("{$sqlquery9}"); $nrofrows9 = mysql_affected_rows($mydb); if ($nrofrows9 != 1) { setErrorVars(false, __("Table net2ftp_log_access could not be updated."), debug_backtrace(), __FILE__, __LINE__); return false; } } else { setErrorVars(false, __("Table net2ftp_log_access contains duplicate entries."), debug_backtrace(), __FILE__, __LINE__); return false; } // ------------------------------------------------------------------------- // If all 3 tables have been updated, set the flag to 1 // ------------------------------------------------------------------------- $net2ftp_globals["consumption_database_updated"] = 1; // Return true return true; }
function net2ftp($action) { // -------------- // This function is the main net2ftp function; it is the interface between 3rd party // scripts (CMS, control panels, etc), and the internal net2ftp modules and plugins. // // This function is called 5 times per pageload: to send the HTTP headers, to print // the javascript code, to print the CSS code, to print the body onload actions and // finally to print the body content. // -------------- // ------------------------------------------------------------------------- // Check that "sendHttpHeaders" action is only executed once // Check that no other actions can be executed if "sendHttpHeaders" has not yet been executed // ------------------------------------------------------------------------- if ($action == "sendHttpHeaders") { if (defined("NET2FTP_SENDHTTPHEADERS") == true) { echo "Error: please call the net2ftp(\$action) function only once with \$action = \"sendHttpHeaders\"!"; return false; } else { define("NET2FTP_SENDHTTPHEADERS", 1); } } else { if (defined("NET2FTP_SENDHTTPHEADERS") == false) { echo "Error: please call the net2ftp(\$action) function first with \$action = \"sendHttpHeaders\"!"; return false; } } // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_settings, $net2ftp_globals, $net2ftp_result, $net2ftp_messages; // Set the NET2FTP constant which is used to check if template files are called by net2ftp if (defined("NET2FTP") == false) { define("NET2FTP", 1); } // Initialize the global variables if ($action == "sendHttpHeaders") { $net2ftp_globals = array(); $net2ftp_messages = array(); $net2ftp_output = array(); $net2ftp_result["success"] = true; $net2ftp_result["errormessage"] = ""; $net2ftp_result["debug_backtrace"] = ""; $net2ftp_result["exit"] = false; $net2ftp_settings = array(); } // ------------------------------------------------------------------------- // If an error occured during a previous execution of net2ftp(), return false // and let index.php print the error message // ------------------------------------------------------------------------- if ($net2ftp_result["success"] == false) { return false; } // ------------------------------------------------------------------------- // Input checks // ------------------------------------------------------------------------- if ($action != "sendHttpHeaders" && $action != "printJavascript" && $action != "printCss" && $action != "printBodyOnload" && $action != "printBody") { $net2ftp_result["success"] = false; $net2ftp_result["errormessage"] = "The \$action variable has an unknown value: {$action}."; $net2ftp_result["debug_backtrace"] = debug_backtrace(); logError(); return false; } // ------------------------------------------------------------------------- // Read settings files // ------------------------------------------------------------------------- if ($action == "sendHttpHeaders") { require NET2FTP_APPLICATION_ROOTDIR . "/settings.inc.php"; require NET2FTP_APPLICATION_ROOTDIR . "/settings_authorizations.inc.php"; require NET2FTP_APPLICATION_ROOTDIR . "/settings_screens.inc.php"; } // ------------------------------------------------------------------------- // Main directories // ------------------------------------------------------------------------- $net2ftp_globals["application_rootdir"] = NET2FTP_APPLICATION_ROOTDIR; if (NET2FTP_APPLICATION_ROOTDIR_URL == "/") { $net2ftp_globals["application_rootdir_url"] = ""; } else { $net2ftp_globals["application_rootdir_url"] = NET2FTP_APPLICATION_ROOTDIR_URL; } $net2ftp_globals["application_includesdir"] = $net2ftp_globals["application_rootdir"] . "/includes"; $net2ftp_globals["application_languagesdir"] = $net2ftp_globals["application_rootdir"] . "/languages"; $net2ftp_globals["application_modulesdir"] = $net2ftp_globals["application_rootdir"] . "/modules"; $net2ftp_globals["application_pluginsdir"] = $net2ftp_globals["application_rootdir"] . "/plugins"; $net2ftp_globals["application_skinsdir"] = $net2ftp_globals["application_rootdir"] . "/skins"; $net2ftp_globals["application_tempdir"] = $net2ftp_globals["application_rootdir"] . "/temp"; // ------------------------------------------------------------------------- // Set basic settings // ------------------------------------------------------------------------- if ($action == "sendHttpHeaders") { // Run the script to the end, even if the user hits the stop button ignore_user_abort(); // Execute function shutdown() if the script reaches the maximum execution time (usually 30 seconds) // DON'T REGISTER IT HERE YET, as this causes errors on newer versions of PHP; first include the function libraries // register_shutdown_function("net2ftp_shutdown"); // Set the error reporting level if ($net2ftp_settings["error_reporting"] == "ALL") { error_reporting(E_ALL); } elseif ($net2ftp_settings["error_reporting"] == "NONE") { error_reporting(0); } else { error_reporting(E_ERROR | E_WARNING | E_PARSE); } // Timer: start $net2ftp_globals["starttime"] = microtime(); $net2ftp_globals["endtime"] = microtime(); } // Set the PHP temporary directory // putenv("TMPDIR=" . $net2ftp_globals["application_tempdir"]); // ------------------------------------------------------------------------- // Function libraries: // 1. Libraries which are always needed // 2. Register global variables // 3. Function libraries which are needed depending on certain variables // // --> Do this only once, when $action == "sendHttpHeaders" // ------------------------------------------------------------------------- if ($action == "sendHttpHeaders") { // 1. Libraries which are always needed require_once $net2ftp_globals["application_includesdir"] . "/authorizations.inc.php"; require_once $net2ftp_globals["application_includesdir"] . "/consumption.inc.php"; require_once $net2ftp_globals["application_includesdir"] . "/database.inc.php"; require_once $net2ftp_globals["application_includesdir"] . "/errorhandling.inc.php"; require_once $net2ftp_globals["application_includesdir"] . "/filesystem.inc.php"; require_once $net2ftp_globals["application_includesdir"] . "/html.inc.php"; require_once $net2ftp_globals["application_includesdir"] . "/StonePhpSafeCrypt.php"; require_once $net2ftp_globals["application_languagesdir"] . "/languages.inc.php"; require_once $net2ftp_globals["application_skinsdir"] . "/skins.inc.php"; // 1. Define functions which are used, but which did not exist before PHP version 4.3.0 if (version_compare(phpversion(), "4.3.0", "<")) { require_once $net2ftp_globals["application_includesdir"] . "/before430.inc.php"; } // 2. Register global variables (POST, GET, GLOBAL, ...) require_once $net2ftp_globals["application_includesdir"] . "/registerglobals.inc.php"; // 3. Function libraries which are needed depending on certain variables if ($net2ftp_globals["state"] == "upload" || $net2ftp_globals["state"] == "unzip") { require_once $net2ftp_globals["application_includesdir"] . "/pclerror.lib.php"; require_once $net2ftp_globals["application_includesdir"] . "/pcltar.lib.php"; require_once $net2ftp_globals["application_includesdir"] . "/pcltrace.lib.php"; require_once $net2ftp_globals["application_includesdir"] . "/pclzip.lib.php"; } if ($net2ftp_globals["state"] == "advanced_ftpserver" || $net2ftp_globals["state"] == "advanced_parsing" || $net2ftp_globals["state"] == "advanced_webserver" || $net2ftp_globals["state"] == "browse" || $net2ftp_globals["state"] == "copymovedelete" || $net2ftp_globals["state"] == "chmod" || $net2ftp_globals["state"] == "calculatesize" || $net2ftp_globals["state"] == "downloadzip" || $net2ftp_globals["state"] == "findstring" || $net2ftp_globals["state"] == "followsymlink" || $net2ftp_globals["state"] == "install" || $net2ftp_globals["state"] == "zip") { require_once $net2ftp_globals["application_includesdir"] . "/browse.inc.php"; } if ($net2ftp_globals["state"] == "downloadzip" || $net2ftp_globals["state"] == "zip") { require_once $net2ftp_globals["application_includesdir"] . "/zip.lib.php"; } // 4. Load the plugins require_once $net2ftp_globals["application_pluginsdir"] . "/plugins.inc.php"; $net2ftp_globals["activePlugins"] = getActivePlugins(); net2ftp_plugin_includePhpFiles(); // 5. Load the language file includeLanguageFile(); } // ------------------------------------------------------------------------- // Execute function shutdown() if the script reaches the maximum execution time (usually 30 seconds) // ------------------------------------------------------------------------- if ($action == "sendHttpHeaders") { register_shutdown_function("net2ftp_shutdown"); } // ------------------------------------------------------------------------- // Log access // --> Do this only once, when $action == "sendHttpHeaders" // ------------------------------------------------------------------------- if ($action == "sendHttpHeaders") { logAccess(); if ($net2ftp_result["success"] == false) { logError(); return false; } } // ------------------------------------------------------------------------- // Check authorizations // --> Do this only once, when $action == "sendHttpHeaders" // ------------------------------------------------------------------------- if ($action == "sendHttpHeaders" && $net2ftp_settings["check_authorization"] == "yes" && $net2ftp_globals["ftpserver"] != "") { checkAuthorization($net2ftp_globals["ftpserver"], $net2ftp_globals["ftpserverport"], $net2ftp_globals["directory"], $net2ftp_globals["username"]); if ($net2ftp_result["success"] == false) { logError(); return false; } } // ------------------------------------------------------------------------- // Get the consumption counter values from the database // This retrieves the consumption of network and server resources for the // current IP address and FTP server from the database, and stores these // values in global variables. See /includes/consumption.inc.php for the details. // --> Do this only once, when $action == "sendHttpHeaders" // ------------------------------------------------------------------------- if ($action == "sendHttpHeaders") { getConsumption(); if ($net2ftp_result["success"] == false) { logError(); return false; } } // ------------------------------------------------------------------------- // Execute the action! // ------------------------------------------------------------------------- // ------------------------------------ // For most modules, everything must be done: send headers, print body, etc // ------------------------------------ if ($net2ftp_globals["state"] == "admin" || $net2ftp_globals["state"] == "admin_createtables" || $net2ftp_globals["state"] == "admin_emptylogs" || $net2ftp_globals["state"] == "admin_viewlogs" || $net2ftp_globals["state"] == "advanced" || $net2ftp_globals["state"] == "advanced_ftpserver" || $net2ftp_globals["state"] == "advanced_parsing" || $net2ftp_globals["state"] == "advanced_webserver" || $net2ftp_globals["state"] == "bookmark" || $net2ftp_globals["state"] == "browse" || $net2ftp_globals["state"] == "calculatesize" || $net2ftp_globals["state"] == "chmod" || $net2ftp_globals["state"] == "copymovedelete" || $net2ftp_globals["state"] == "edit" || $net2ftp_globals["state"] == "findstring" || $net2ftp_globals["state"] == "install" || $net2ftp_globals["state"] == "jupload" && $net2ftp_globals["screen"] == 1 || $net2ftp_globals["state"] == "login" || $net2ftp_globals["state"] == "login_small" || $net2ftp_globals["state"] == "logout" || $net2ftp_globals["state"] == "newdir" || $net2ftp_globals["state"] == "raw" || $net2ftp_globals["state"] == "rename" || $net2ftp_globals["state"] == "unzip" || $net2ftp_globals["state"] == "upload" || $net2ftp_globals["state"] == "view" && $net2ftp_globals["state2"] == "" || $net2ftp_globals["state"] == "zip") { require_once $net2ftp_globals["application_modulesdir"] . "/" . $net2ftp_globals["state"] . "/" . $net2ftp_globals["state"] . ".inc.php"; if ($action == "sendHttpHeaders") { net2ftp_module_sendHttpHeaders(); // If needed, exit to avoid sending non-header output (by net2ftp or other application) // Example: if a module sends a HTTP redirect header (See /includes/authorizations.inc.php function checkAdminUsernamePassword()!) if ($net2ftp_result["exit"] == true) { exit; } } elseif ($action == "printJavascript") { net2ftp_module_printJavascript(); net2ftp_plugin_printJavascript(); } elseif ($action == "printCss") { net2ftp_module_printCss(); net2ftp_plugin_printCss(); } elseif ($action == "printBodyOnload") { net2ftp_module_printBodyOnload(); net2ftp_plugin_printBodyOnload(); } elseif ($action == "printBody") { // Print the status bar to be able to show the progress if (isStatusbarActive() == true) { require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/statusbar.template.php"; } require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/status/status.inc.php"; // Do the work and meanwhile update the progress bar net2ftp_module_printBody(); // Update the consumption statistics $net2ftp_globals["endtime"] = microtime(); $net2ftp_globals["time_taken"] = timer(); addConsumption(0, $net2ftp_globals["time_taken"]); putConsumption(); // Set the progress bar to "finished" if (isStatusbarActive() == true) { $statusmessage = __("Script finished in %1\$s seconds", $net2ftp_globals["time_taken"]); setStatus(1, 1, $statusmessage); } } } elseif ($net2ftp_globals["state"] == "clearcookies" || $net2ftp_globals["state"] == "downloadfile" || $net2ftp_globals["state"] == "downloadzip" || $net2ftp_globals["state"] == "followsymlink" || $net2ftp_globals["state"] == "jupload" && $net2ftp_globals["screen"] == 2 || $net2ftp_globals["state"] == "view" && $net2ftp_globals["state2"] != "") { require_once $net2ftp_globals["application_modulesdir"] . "/" . $net2ftp_globals["state"] . "/" . $net2ftp_globals["state"] . ".inc.php"; if ($action == "sendHttpHeaders") { // Do the work - do not update the progress bar net2ftp_module_sendHttpHeaders(); // Update the consumption statistics $net2ftp_globals["endtime"] = microtime(); $net2ftp_globals["time_taken"] = timer(); addConsumption(0, $net2ftp_globals["time_taken"]); putConsumption(); // Exit to avoid sending non-header output (by net2ftp or other application) exit; } elseif ($action == "printJavascript") { } elseif ($action == "printCss") { } elseif ($action == "printBodyOnload") { } elseif ($action == "printBody") { } } elseif ($net2ftp_globals["state"] == "error") { logError(); return false; } else { $errormessage = __("Unexpected state string: %1\$s. Exiting.", $net2ftp_globals["state"]); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); logError(); return false; } }
function net2ftp_module_printBody() { // -------------- // This function prints the edit screen // For screen == 1, the file is read from the FTP server // For screen == 2, the textarea is changed, the file is not read from the FTP server but comes from the HTML form // For screen == 3, the file is saved to the FTP server // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result; if (isset($_POST["textareaType"]) == true) { $textareaType = validateTextareaType($_POST["textareaType"]); } else { $textareaType = ""; } if (isset($_POST["text"]) == true) { $text = $_POST["text"]; } else { $text = ""; } if (isset($_POST["text_splitted"]) == true) { $text_splitted = $_POST["text_splitted"]; } else { $text_splitted = ""; } if (isset($_POST["encodingSelect"]) == true) { $encodingSelect = $_POST["encodingSelect"]; } else { $encodingSelect = ""; } if (isset($_POST["breakSelect"]) == true) { $breakSelect = $_POST["breakSelect"]; } else { $breakSelect = ""; } $text_encoding_selected = ""; $line_break_selected = ""; // ------------------------------------------------------------------------- // Variables for all screens // ------------------------------------------------------------------------- // Form name, back and forward buttons $formname = "EditForm"; $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();"; // Directory + file name $dirfilename = htmlEncode2(glueDirectories($net2ftp_globals["directory"], $net2ftp_globals["entry"])); // TextareaSelect onchange $onchange = "document.forms['EditForm'].screen.value=2;document.forms['EditForm'].textareaType.value=document.forms['EditForm'].textareaSelect.options[document.forms['EditForm'].textareaSelect.selectedIndex].value;document.forms['EditForm'].submit();"; // Character encoding (requires multibyte string module to be installed) // With this, you can save a text with specified encoding and line break sequence // http://www.net2ftp.org/forums/viewtopic.php?id=2449 if (($net2ftp_globals["language"] == "ja" || $net2ftp_globals["language"] == "tc" || $net2ftp_messages["iso-8859-1"] == "UTF-8") && function_exists("mb_detect_encoding") == true) { // $textarea_encodings is an array which contains the possible character encodings $textarea_encodings = getTextareaEncodingsArray(); // $textarea_breaks is an array which contains the possible line breaks $textarea_breaks[] = "CRLF"; $textarea_breaks[] = "CR"; $textarea_breaks[] = "LF"; // $text_encoding_old is the original encoding which is detected when the file is first read // $text_encoding_new is the requested encoding from the drop-down box // Default = encoding used for the page, which is defined by the language file in /languages/xx.inc.php // HTML uses BIG5, PHP uses BIG-5 (Traditional Chinese) // If the HTML encoding is not foreseen in the PHP function, set it to the default ISO-8859-1 // $text_encoding is changed further on too if ($encodingSelect != "" && in_array($encodingSelect, $textarea_encodings)) { $text_encoding_new = $encodingSelect; } else { $text_encoding_new = ""; } // $line_break_old is the original line break which is detected when the file is first read // $line_break is the requested line break from the drop-down box if ($breakSelect != "" && in_array($breakSelect, $textarea_breaks) == true) { $line_break_new = $breakSelect; } else { $line_break_new = "LF"; } } // Programming language (for CodePress syntax highlighting) if ($textareaType == "codepress") { $filename_extension = get_filename_extension($net2ftp_globals["entry"]); if ($filename_extension == "asp") { $codepress_programming_language = "asp"; } elseif ($filename_extension == "css") { $codepress_programming_language = "css"; } elseif ($filename_extension == "cgi") { $codepress_programming_language = "perl"; } elseif ($filename_extension == "htm") { $codepress_programming_language = "html"; } elseif ($filename_extension == "html") { $codepress_programming_language = "html"; } elseif ($filename_extension == "java") { $codepress_programming_language = "java"; } elseif ($filename_extension == "js") { $codepress_programming_language = "javascript"; } elseif ($filename_extension == "javascript") { $codepress_programming_language = "javascript"; } elseif ($filename_extension == "pl") { $codepress_programming_language = "perl"; } elseif ($filename_extension == "perl") { $codepress_programming_language = "perl"; } elseif ($filename_extension == "php") { $codepress_programming_language = "php"; } elseif ($filename_extension == "phps") { $codepress_programming_language = "php"; } elseif ($filename_extension == "phtml") { $codepress_programming_language = "php"; } elseif ($filename_extension == "ruby") { $codepress_programming_language = "ruby"; } elseif ($filename_extension == "sql") { $codepress_programming_language = "sql"; } elseif ($filename_extension == "txt") { $codepress_programming_language = "text"; } else { $codepress_programming_language = "generic"; } $codepress_onclick = "text.toggleEditor();"; } else { $codepress_programming_language = ""; $codepress_onclick = ""; } // ------------------------------------------------------------------------- // Variables for screen 1 // Read the remote file (edit), or read the local template (new file) // ------------------------------------------------------------------------- if ($net2ftp_globals["screen"] == 1) { // Template file $templatefile = $net2ftp_globals["application_rootdir"] . "/modules/edit/template.txt"; // Edit: read the file from the FTP server if ($net2ftp_globals["state2"] == "") { $text = ftp_readfile("", $net2ftp_globals["directory"], $net2ftp_globals["entry"]); if ($net2ftp_result["success"] == false) { return false; } // Character encoding (requires multibyte string module to be installed) // Detect the original encoding of the text, and change the encoding of the text to the encoding of the page if (($net2ftp_globals["language"] == "ja" || $net2ftp_globals["language"] == "tc" || $net2ftp_messages["iso-8859-1"] == "UTF-8") && function_exists("mb_detect_encoding") == true) { // Detect original encoding $text_encoding_old = mb_detect_encoding($text, $textarea_encodings); $text_encoding_selected = $text_encoding_old; // If original encoding is detected and different from the page encoding, convert the text to the page encoding if ($text_encoding_old != "" && strcasecmp($text_encoding_old, $net2ftp_messages["iso-8859-1"]) != 0) { $text = mb_convert_encoding($text, $net2ftp_messages["iso-8859-1"], $text_encoding_old); } // Detect original line break if (strpos($text, "\r\n") !== false) { $line_break_old = "CRLF"; } elseif (strpos($text, "\n") !== false) { $line_break_old = "LF"; } elseif (strpos($text, "\r") !== false) { $line_break_old = "CR"; } else { $line_break_old = "LF"; } $line_break_selected = $line_break_old; } } elseif ($net2ftp_globals["state2"] == "newfile") { $handle = fopen($templatefile, "r"); // Open the local template file for reading only if ($handle == false) { $errormessage = __("Unable to open the template file"); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } clearstatcache(); // for filesize $text = trim(fread($handle, filesize($templatefile))); if ($text == false) { $errormessage = __("Unable to read the template file"); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } @fclose($handle); } // Save status $savestatus = __("Status: This file has not yet been saved"); $savestatus_short = __("Not yet saved"); } elseif ($net2ftp_globals["screen"] == 2) { // For HTML WYSIWYG editors, split the HTML if (($textareaType == "tinymce" || $textareaType == "ckeditor") && $text_splitted == "") { $text_splitted = splitHtml($text, $textareaType); } elseif (($textareaType == "plain" || $textareaType == "codepress") && $text == "" && isset($text_splitted["top"]) == true) { $text = $text_splitted["top"]; $text .= $text_splitted["middle"]; $text .= $text_splitted["bottom"]; } // Save status $savestatus = __("Status: This file has not yet been saved"); $savestatus_short = __("Not yet saved"); } elseif ($net2ftp_globals["screen"] == 3) { // Check if a filename is specified if (strlen($net2ftp_globals["entry"]) < 1) { $errormessage = __("Please specify a filename"); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } // For HTML WYSIWYG editors, join the HTML if ($textareaType == "tinymce" || $textareaType == "ckeditor") { $text = $text_splitted["top"]; $text .= $text_splitted["middle"]; $text .= $text_splitted["bottom"]; } // $text_file contains the text which is written to the FTP server // It is equal to the text shown on screen, except if a different character encoding is chosen $text_file = $text; // Character encoding (requires multibyte string module to be installed) // Change the encoding of the text from the original or page encoding to the selected encoding if (($net2ftp_globals["language"] == "ja" || $net2ftp_globals["language"] == "tc" || $net2ftp_messages["iso-8859-1"] == "UTF-8") && function_exists("mb_detect_encoding") == true) { $break_map = array("CRLF" => "\r\n", "CR" => "\r", "LF" => "\n"); if (isset($break_map[$line_break_new]) == true) { $text_file = preg_replace('/(\\r\\n)|\\r|\\n/', $break_map[$line_break_new], $text_file); } if ($text_encoding_new != "" && strcasecmp($text_encoding_new, $net2ftp_messages["iso-8859-1"]) != 0) { $text_file = mb_convert_encoding($text_file, $text_encoding_new, $net2ftp_messages["iso-8859-1"]); } $text_encoding_selected = $text_encoding_new; $line_break_selected = $line_break_new; } // Write the string to the FTP server // Note: this function also replaces CarriageReturn+LineFeed by LineFeed ftp_writefile("", $net2ftp_globals["directory"], $net2ftp_globals["entry"], $text_file); if ($net2ftp_result["success"] == false) { setErrorVars(true, "", "", "", ""); // Continue anyway and print warning message $savestatus = __("Status: <b>This file could not be saved</b>"); $savestatus_short = __("Could not be saved"); } else { $mytime = mytime(); $mytime_short = mytime_short(); $ftpmode = ftpAsciiBinary($net2ftp_globals["entry"]); if ($ftpmode == FTP_ASCII) { $printftpmode = "FTP_ASCII"; } elseif ($ftpmode == FTP_BINARY) { $printftpmode = "FTP_BINARY"; } $savestatus = __("Status: Saved on <b>%1\$s</b> using mode %2\$s", $mytime, $printftpmode); $savestatus_short = __("Saved at %1\$s", $mytime_short); } } // ------------------------------------------------------------------------- // Convert special characters to HTML entities // ------------------------------------------------------------------------- // Plain textarea if ($textareaType == "" || $textareaType == "plain") { $text = htmlspecialchars($text, ENT_QUOTES); } elseif ($textareaType == "ckeditor") { $text_splitted["top"] = htmlspecialchars($text_splitted["top"], ENT_QUOTES); $text_splitted["bottom"] = htmlspecialchars($text_splitted["bottom"], ENT_QUOTES); // Do not encode the middle part, this is done by CKEditor itself // $text_splitted["middle"] = htmlspecialchars($text_splitted["middle"], ENT_QUOTES); } elseif ($textareaType == "tinymce") { $text_splitted["top"] = htmlspecialchars($text_splitted["top"], ENT_QUOTES); $text_splitted["middle"] = htmlspecialchars($text_splitted["middle"], ENT_QUOTES); $text_splitted["bottom"] = htmlspecialchars($text_splitted["bottom"], ENT_QUOTES); } elseif ($textareaType == "codepress") { $text = htmlspecialchars($text, ENT_QUOTES); } // ------------------------------------------------------------------------- // Print the output // ------------------------------------------------------------------------- require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/edit.template.php"; }
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 getRootdirectory() { // -------------- // This function gets the user's root directory from the database and // stores it in $net2ftp_globals["homedirectory"]. // // If $net2ftp_globals["homedirectory"] is already filled in (cache), no connection // is made to the DB and this value is returned. // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals, $net2ftp_settings, $net2ftp_result; // ------------------------------------------------------------------------- // Initial checks // ------------------------------------------------------------------------- if ($net2ftp_settings["use_database"] != "yes" || $net2ftp_settings["check_homedirectory"] != "yes") { $net2ftp_globals["homedirectory"] = "/"; } // ------------------------------------------------------------------------- // Get the homedirectory from the database, then store it in a global // variable, and from then on, don't access the database any more // ------------------------------------------------------------------------- if (isset($net2ftp_globals["homedirectory"]) == false) { // ------------------------------------------------------------------------- // Add slashes to variables which are used in a SQL query, and which are // potentially unsafe (supplied by the user) // ------------------------------------------------------------------------- $net2ftp_ftpserver_safe = addslashes($net2ftp_globals["ftpserver"]); $net2ftp_username_safe = addslashes($net2ftp_globals["username"]); // ------------------------------------------------------------------------- // Connect // ------------------------------------------------------------------------- $mydb = connect2db(); if ($net2ftp_result["success"] == false) { return false; } // ------------------------------------------------------------------------- // Get user's home directory // ------------------------------------------------------------------------- $sqlquery1 = "SELECT homedirectory FROM net2ftp_users WHERE ftpserver = '{$net2ftp_ftpserver_safe}' AND username = '******';"; $result1 = mysql_query("{$sqlquery1}") or die("Unable to execute SQL SELECT query (isAuthorizedDirectory > sqlquery1) <br /> {$sqlquery1}"); $nrofrows1 = mysql_num_rows($result1); if ($nrofrows1 == 0) { $net2ftp_globals["homedirectory"] = "/"; } elseif ($nrofrows1 == 1) { $resultRow1 = mysql_fetch_row($result1); $net2ftp_globals["homedirectory"] = $resultRow1[0]; } else { setErrorVars(false, __("Table net2ftp_users contains duplicate rows."), debug_backtrace(), __FILE__, __LINE__); return false; } } return $net2ftp_globals["homedirectory"]; }
function putLogStatus($logStatus) { // -------------- // This function writes the log rotation status to the database. // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals, $net2ftp_settings, $net2ftp_result; // ------------------------------------------------------------------------- // Initial checks // ------------------------------------------------------------------------- // Verify if a database is used. If not: don't continue. if ($net2ftp_settings["use_database"] != "yes") { return true; } // ------------------------------------------------------------------------- // Determine current month and last month // ------------------------------------------------------------------------- $currentmonth = date("Ym"); // e.g. 201207 $lastmonth = date("Ym", mktime(0, 0, 0, date("m") - 1, date("d"), date("Y"))); $datetime = mytime(); // ------------------------------------------------------------------------- // Connect to the database // ------------------------------------------------------------------------- $mydb = connect2db(); if ($net2ftp_result["success"] == false) { return false; } // ------------------------------------------------------------------------- // Put log rotation status // ------------------------------------------------------------------------- $sqlquery1 = "SELECT status, changelog FROM net2ftp_log_status WHERE month = '{$currentmonth}';"; $result1 = mysql_query("{$sqlquery1}"); $nrofrows1 = mysql_num_rows($result1); if ($nrofrows1 == 1) { $resultRow1 = mysql_fetch_row($result1); $logStatus_old = $resultRow1[0]; $changelog_old = $resultRow1[1]; $changelog_new = $changelog_old . "From {$logStatus_old} to {$logStatus} on {$datetime}. "; $sqlquery2 = "UPDATE net2ftp_log_status SET status = '" . $logStatus . "', changelog = '" . $changelog_new . "' WHERE month = '{$currentmonth}';"; $result2 = mysql_query("{$sqlquery2}"); $nrofrows2 = mysql_affected_rows($mydb); } elseif ($nrofrows1 == 0) { $changelog_new = "Set to {$logStatus} on {$datetime}. "; $sqlquery3 = "INSERT INTO net2ftp_log_status VALUES('{$currentmonth}', '" . $logStatus . "', '" . $changelog_new . "');"; $result3 = mysql_query("{$sqlquery3}"); $nrofrows3 = mysql_affected_rows($mydb); if ($nrofrows3 != 1) { setErrorVars(false, __("Table net2ftp_log_status could not be updated."), debug_backtrace(), __FILE__, __LINE__); return false; } } else { setErrorVars(false, __("Table net2ftp_log_status contains duplicate entries."), debug_backtrace(), __FILE__, __LINE__); return false; } // ------------------------------------------------------------------------- // Return true // ------------------------------------------------------------------------- return true; }
function net2ftp_module_sendHttpHeaders() { // -------------- // This function sends HTTP headers // -------------- global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output; // ------------------------------------ // 1. Register the global variables // ------------------------------------ if ($net2ftp_globals["screen"] == 2) { // Code for old file jupload applet (jupload version 0.86) // $file_counter = 0; // foreach($_FILES as $tagname=>$object) { // if ($object['name'] != "") { // $file_counter = $file_counter + 1; // $uploadedFilesArray["$file_counter"]["name"] = $object['name']; // $uploadedFilesArray["$file_counter"]["tmp_name"] = $object['tmp_name']; // $uploadedFilesArray["$file_counter"]["size"] = $object['size']; // $uploadedFilesArray["$file_counter"]["error"] = $object['error']; // // Look for special encoded jupload files // $contentType = $object['type']; // if (substr($contentType,0,7) == "jupload") { // $base64_encoded_path = substr($contentType,8); // $base64_decoded_path = base64_decode($base64_encoded_path); // $uploadedFilesArray["$file_counter"]["absolute_directory"] = $base64_decoded_path; // } // end if // } // end if // } // end foreach // Code for new file jupload applet (jupload version 5.0.8) $file_counter = 0; foreach ($_FILES as $tagname => $object) { if ($object['name'] != "") { $file_counter = $file_counter + 1; $uploadedFilesArray["{$file_counter}"]["name"] = $object['name']; $uploadedFilesArray["{$file_counter}"]["type"] = $object['type']; $uploadedFilesArray["{$file_counter}"]["tmp_name"] = $object['tmp_name']; $uploadedFilesArray["{$file_counter}"]["error"] = $object['error']; $uploadedFilesArray["{$file_counter}"]["size"] = $object['size']; $uploadedFilesArray["{$file_counter}"]["mime"] = validateEntry($_POST["mimetype" . $file_counter]); $uploadedFilesArray["{$file_counter}"]["relative_directory"] = validateDirectory($_POST["relpathinfo" . $file_counter]); $uploadedFilesArray["{$file_counter}"]["mtime"] = validateEntry($_POST["filemodificationdate" . $file_counter]); } // end if } // end foreach echo "Please wait, the files are being transferred to the FTP server...<br />\n"; flush(); // ------------------------------------ // 2. POST METHOD: Move files from the *webserver's* temporary directory to *net2ftp's* // temporary directory (move_uploaded_files). // ------------------------------------ if ($_SERVER["REQUEST_METHOD"] == "POST" && sizeof($uploadedFilesArray) > 0) { $moved_counter = 0; for ($j = 1; $j <= sizeof($uploadedFilesArray); $j++) { $file_name = $uploadedFilesArray["{$j}"]["name"]; $file_tmp_name = $uploadedFilesArray["{$j}"]["tmp_name"]; $file_size = $uploadedFilesArray["{$j}"]["size"]; $file_error = $uploadedFilesArray["{$j}"]["error"]; $file_relative_directory = $uploadedFilesArray["{$j}"]["relative_directory"]; if ($file_name != "" && $file_tmp_name == "" || $file_size > $net2ftp_settings["max_filesize"]) { // The case ($file_name != "" && $file_tmp_name == "") occurs when the file is bigger than the directives set in php.ini // In that case, only $uploadedFilesArray["$j"]["name"] is filled in. echo "WARNING: File <b>{$file_name}</b> skipped: this file is too big.<br />\n"; @unlink($file_tmp_name); continue; } elseif (checkAuthorizedName($file_name) == false || checkAuthorizedName($file_relative_directory) == false) { echo "WARNING: File <b>{$file_relative_directory}</b> skipped: it contains a banned keyword.<br />\n"; $skipped = $skipped + 1; @unlink($file_tmp_name); continue; } // Create the temporary filename as follows: (from left to right) // - Use prefix "upload__", to be able to identify from where this temporary file comes from // - Create a random filename // - Add the original filename extension, to be able to identify the filetype // - Add suffix ".txt" to avoid that the file would be executed on the webserver $extension = get_filename_extension($file_name); if (substr($file_name, -6) == "tar.gz") { $extension = "tar.gz"; } $tempfilename = tempnam2($net2ftp_globals["application_tempdir"], "upload__", "." . $extension . ".txt"); if ($tempfilename == false) { // If you get this warning message, you've probably forgotten to chmod 777 the /temp directory echo "WARNING: File <b>{$file_name}</b> skipped: unable to create a temporary file on the webserver.<br />\n"; @unlink($file_tmp_name); continue; } // Move the uploaded file $move_uploaded_file_result = move_uploaded_file($uploadedFilesArray["{$j}"]["tmp_name"], $tempfilename); if ($move_uploaded_file_result == false) { echo "WARNING: File <b>{$file_name}</b> skipped: unable to move the uploaded file to the webserver's temporary directory.<br />\n"; @unlink($file_tmp_name); @unlink($tempfilename); continue; } else { $moved_counter = $moved_counter + 1; $acceptedFilesArray["{$moved_counter}"] = $uploadedFilesArray["{$j}"]; // Copy all parameters for this file from the $uploadedFilesArray to the $acceptedFilesArray $acceptedFilesArray["{$moved_counter}"]["tmp_name"] = $tempfilename; // Overwrite the old temporary name by the new one } } // end for j flush(); } // end if elseif // ------------------------------------ // 3. Move the files from net2ftp's temporary directory to the FTP server. // ------------------------------------ if (sizeof($acceptedFilesArray) == 0 && sizeof($uploadedFilesArray) != 0) { echo "WARNING: No files were accepted (see messages above), so nothing will be transferred to the FTP server.<br />\n"; } elseif (sizeof($acceptedFilesArray) > 0) { // ------------------------------ // 3.1 Open connection // ------------------------------ // Open connection echo __("Connecting to the FTP server") . "<br />\n"; $conn_id = ftp_openconnection(); if ($net2ftp_result["success"] == false) { echo "ERROR: " . $net2ftp_result["errormessage"] . "<br />\n"; return false; } // ------------------------------ // For loop (loop over all the files) // ------------------------------ for ($k = 1; $k <= sizeof($acceptedFilesArray); $k++) { $file_name = $acceptedFilesArray["{$k}"]["name"]; $file_tmp_name = $acceptedFilesArray["{$k}"]["tmp_name"]; $file_size = $acceptedFilesArray["{$k}"]["size"]; $file_error = $acceptedFilesArray["{$k}"]["error"]; $file_relative_directory = $acceptedFilesArray["{$k}"]["relative_directory"]; $ftpmode = ftpAsciiBinary($file_name); if ($ftpmode == FTP_ASCII) { $printftpmode = "FTP_ASCII"; } elseif ($ftpmode == FTP_BINARY) { $printftpmode = "FTP_BINARY"; } // ------------------------------ // 3.2 Within the for loop: create the subdirectory if needed // ------------------------------ // Replace Windows-style backslashes \ by Unix-style slashes / $file_relative_directory = str_replace("\\", "/", trim($file_relative_directory)); // Get the names of the subdirectories by splitting the string using slashes / $file_subdirectories = explode("/", $file_relative_directory); // $targetdirectory contains the successive directories to be created $targetdirectory = $net2ftp_globals["directory"]; // Loop over sizeof()-1 because the last part is the filename itself: for ($m = 0; $m < sizeof($file_subdirectories) - 1; $m++) { // Create the targetdirectory string $targetdirectory = glueDirectories($targetdirectory, $file_subdirectories[$m]); // Check if the subdirectories exist if ($targetdirectory != "") { $result = @ftp_chdir($conn_id, $targetdirectory); if ($result == false) { $ftp_mkdir_result = ftp_mkdir($conn_id, $targetdirectory); if ($ftp_mkdir_result == false) { echo "WARNING: Unable to create the directory <b>{$targetdirectory}</b>. The script will try to continue...<br />\n"; continue; } echo "Directory {$targetdirectory} created.<br />\n"; } // end if flush(); } // end if } // end for m // Store the $targetdirectory in the $acceptedFilesArray if ($targetdirectory != "" && $targetdirectory != "/") { $acceptedFilesArray["{$k}"]["targetdirectory"] = $targetdirectory; } // ------------------------------ // 3.3 Within the for loop: put local file to remote file // ------------------------------ ftp_putfile($conn_id, "", $acceptedFilesArray["{$k}"]["tmp_name"], $acceptedFilesArray["{$k}"]["targetdirectory"], $acceptedFilesArray["{$k}"]["name"], $ftpmode, "move"); if ($net2ftp_result["success"] == false) { echo "ERROR: File <b>{$file_name}</b> skipped. Message: " . $net2ftp_result["errormessage"] . "<br />\n"; setErrorVars(true, "", "", "", ""); continue; } else { echo "The file <b>{$file_name}</b> was transferred to the FTP server successfully. <br />\n"; } flush(); } // End for k // Note: the java applet is looking for the word "SUCCESS" to determine if the upload result is OK or not (see applet parameter stringUploadSuccess) // The applet doesn't seem to recognize the words "SUCCESS", "WARNING" or "ERROR" when they are issued by the code above echo "SUCCESS"; // ------------------------------ // 3.4 Close connection // ------------------------------ ftp_quit($conn_id); } // end if } // end if $screen == 2 }
function logError() { // -------------- // This function logs user accesses to the site // // IMPORTANT: this function uses, but does not change the global $net2ftp_result[""] variables. // It returns true on success, false on failure. // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals, $net2ftp_settings, $net2ftp_result; if ($net2ftp_settings["log_error"] == "yes") { // ------------------------------------------------------------------------- // Take a copy of the $net2ftp_result // If an error occurs within logError, logError will return false and reset the // $net2ftp_result variable to it's original value // Also if no error occurs logError will return the variable to it's original value // ------------------------------------------------------------------------- $net2ftp_result_original = $net2ftp_result; setErrorVars(true, "", "", "", ""); // ------------------------------------------------------------------------- // Errormessage and debug backtrace // ------------------------------------------------------------------------- $errormessage = addslashes($net2ftp_result_original["errormessage"]); $debug_backtrace = ""; $i = sizeof($net2ftp_result_original["debug_backtrace"]) - 1; if ($i > 0) { $debug_backtrace .= addslashes("function " . $net2ftp_result_original["debug_backtrace"][$i]["function"] . " (" . $net2ftp_result_original["debug_backtrace"][$i]["file"] . " on line " . $net2ftp_result_original["debug_backtrace"][$i]["line"] . ")\n"); for ($j = 0; $j < sizeof($net2ftp_result_original["debug_backtrace"][$i]["args"]); $j++) { $debug_backtrace .= addslashes("argument {$j}: " . $net2ftp_result_original["debug_backtrace"][$i]["args"][$j] . "\n"); } } // ------------------------------------------------------------------------- // Date and time // ------------------------------------------------------------------------- $date = date("Y-m-d"); $time = date("H:i:s"); // ------------------------------------------------------------------------- // Logging to the database // ------------------------------------------------------------------------- if ($net2ftp_settings["use_database"] == "yes") { // ---------------------------------------------- // Input checks // ---------------------------------------------- // Add slashes to variables which are used in a SQL query, and which are // potentially unsafe (supplied by the user). // $date is calculated in this function // $time is calculated in this function $net2ftp_ftpserver_safe = addslashes($net2ftp_globals["ftpserver"]); $net2ftp_username_safe = addslashes($net2ftp_globals["username"]); $state_safe = addslashes($net2ftp_globals["state"]); $state2_safe = addslashes($net2ftp_globals["state2"]); $directory_safe = addslashes($net2ftp_globals["directory"]); $REMOTE_ADDR_safe = addslashes($net2ftp_globals["REMOTE_ADDR"]); $REMOTE_PORT_safe = addslashes($net2ftp_globals["REMOTE_PORT"]); $HTTP_USER_AGENT_safe = addslashes($net2ftp_globals["HTTP_USER_AGENT"]); // ---------------------------------------------- // Connect to the DB // ---------------------------------------------- $mydb = connect2db(); if ($net2ftp_result["success"] == false) { setErrorVars($net2ftp_result_original["success"], $net2ftp_result_original["errormessage"], $net2ftp_result_original["debug_backtrace"], $net2ftp_result_original["file"], $net2ftp_result_original["line"]); return false; } // ---------------------------------------------- // Add record to the database table // ---------------------------------------------- $sqlquerystring = "INSERT INTO net2ftp_log_error VALUES('{$date}', '{$time}', '{$net2ftp_ftpserver_safe}', '{$net2ftp_username_safe}', '{$errormessage}', '{$debug_backtrace}', '{$state_safe}', '{$state2_safe}', '{$directory_safe}', '{$REMOTE_ADDR_safe}', '{$REMOTE_PORT_safe}', '{$HTTP_USER_AGENT_safe}')"; $result_mysql_query = @mysql_query($sqlquerystring); if ($result_mysql_query == false) { setErrorVars($net2ftp_result_original["success"], $net2ftp_result_original["errormessage"], $net2ftp_result_original["debug_backtrace"], $net2ftp_result_original["file"], $net2ftp_result_original["line"]); return false; } } // end if use_database // ------------------------------------------------------------------------- // Logging to the system log // ------------------------------------------------------------------------- if ($net2ftp_settings["use_syslog"] == "yes") { // ---------------------------------------------- // Get consumption values // ---------------------------------------------- if (isset($net2ftp_globals["consumption_datatransfer"]) == true) { $consumption_datatransfer = $net2ftp_globals["consumption_datatransfer"]; } else { $consumption_datatransfer = "0"; } if (isset($net2ftp_globals["consumption_executiontime"]) == true) { $consumption_executiontime = $net2ftp_globals["consumption_executiontime"]; } else { $consumption_executiontime = "0"; } // ---------------------------------------------- // Create message // ---------------------------------------------- $message2log = "{$date} {$time} " . $net2ftp_globals["ftpserver"] . " " . $net2ftp_globals["username"] . " " . $net2ftp_result["errormessage"] . " {$debug_backtrace} " . $net2ftp_globals["state"] . " " . $net2ftp_globals["state2"] . " " . $net2ftp_globals["directory"] . " " . $net2ftp_globals["REMOTE_ADDR"] . " " . $net2ftp_globals["HTTP_USER_AGENT"]; $result2 = openlog($net2ftp_settings["syslog_ident"], 0, $net2ftp_settings["syslog_facility"]); if ($result2 == false) { $errormessage = __("Unable to open the system log."); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } // ---------------------------------------------- // Write message to system logger // ---------------------------------------------- $result3 = syslog($net2ftp_settings["syslog_priority"], $message2log); if ($result3 == false) { $errormessage = __("Unable to write a message to the system log."); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } } // end if use_syslog // ------------------------------------------------------------------------- // Reset the variable to it's original value // ------------------------------------------------------------------------- setErrorVars($net2ftp_result_original["success"], $net2ftp_result_original["errormessage"], $net2ftp_result_original["debug_backtrace"], $net2ftp_result_original["file"], $net2ftp_result_original["line"]); } // end if logErrors }
function net2ftp_module_printBody() { // -------------- // This function prints the new directory screen // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output; if (isset($_POST["newNames"]) == true) { $newNames = validateEntry($_POST["newNames"]); } else { $newNames = ""; } // ------------------------------------------------------------------------- // Variables for all screens // ------------------------------------------------------------------------- // Title $title = __("Create new directories"); // Form name, back and forward buttons $formname = "NewDirForm"; $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();"; $forward_onclick = "document.forms['" . $formname . "'].submit();"; // ------------------------------------------------------------------------- // Variables for screen 1 // ------------------------------------------------------------------------- if ($net2ftp_globals["screen"] == 1) { // Next screen $nextscreen = 2; } elseif ($net2ftp_globals["screen"] == 2) { // Open connection setStatus(2, 10, __("Connecting to the FTP server")); $conn_id = ftp_openconnection(); if ($net2ftp_result["success"] == false) { return false; } // Create new directories setStatus(4, 10, __("Processing the entries")); for ($k = 1; $k <= sizeof($newNames); $k++) { if (strlen($newNames[$k]) > 0) { $newsubdir = glueDirectories($net2ftp_globals["directory"], $newNames[$k]); ftp_newdirectory($conn_id, $newsubdir); if ($net2ftp_result["success"] == false) { setErrorVars(true, "", "", "", ""); // Continue anyway $net2ftp_output["newdir"][] = __("Directory <b>%1\$s</b> could not be created.", htmlEncode2($newNames[$k])); } else { $net2ftp_output["newdir"][] = __("Directory <b>%1\$s</b> was successfully created.", htmlEncode2($newNames[$k])); } } // End if } // End for // Close connection ftp_closeconnection($conn_id); } // end elseif // ------------------------------------------------------------------------- // Print the output // ------------------------------------------------------------------------- require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php"; }
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"; }
function net2ftp_module_printBody() { // -------------- // This function prints the login screen // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result; // ------------------------------------------------------------------------- // Variables // ------------------------------------------------------------------------- // ------------------------------------ // Title // ------------------------------------ $login_title = __("Login!"); // ------------------------------------ // FTP server // $ftpserver["inputType"] can be "text", "select" or "hidden" // $ftpserver"][$i]["text"] is "ftp.server.com" // $ftpserver"][$i]["selected"] is "selected" or "" // ------------------------------------ // All FTP servers are allowed // Prefill the textbox with the value that was filled in (when changing the language the page refreshes) // or else with the value from the cookie if ($net2ftp_settings["allowed_ftpservers"][1] == "ALL") { // Input type is textbox $ftpserver["inputType"] = "text"; // Prefill with the previous input value if ($net2ftp_globals["ftpserver"] != "") { $ftpserver["list"][1] = htmlEncode2($net2ftp_globals["ftpserver"]); } else { $ftpserver["list"][1] = htmlEncode2($net2ftp_globals["cookie_ftpserver"]); } } elseif (sizeof($net2ftp_settings["allowed_ftpservers"]) > 1) { // Input type is drop-down box $ftpserver["inputType"] = "select"; // List of allowed FTP servers $ftpserver["list"] = $net2ftp_settings["allowed_ftpservers"]; // Preselect the right FTP server // ... using the previous input value $array_search_result1 = array_search($net2ftp_globals["ftpserver"], $ftpserver); if (is_numeric($array_search_result1) == true) { $ftpserver["list"][$array_search_result1]["selected"] = "selected=\"selected\""; } else { $array_search_result2 = array_search($net2ftp_globals["cookie_ftpserver"], $ftpserver); if (is_numeric($array_search_result2) == true) { $ftpserver["list"][$array_search_result2]["selected"] = "selected=\"selected\""; } } } elseif (sizeof($net2ftp_settings["allowed_ftpservers"]) == 1) { $ftpserver["inputType"] = "hidden"; $ftpserver["list"][1] = $net2ftp_settings["allowed_ftpservers"][1]; } else { $errormessage = "There is an error in the net2ftp configuration file <b>settings_authorizations.inc.php</b>: variable <b>\$net2ftp_allowed_ftpservers</b> does not follow the expected format."; setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } // ------------------------------------ // FTP server port // $ftpserverport["inputType"] can be "text" or "hidden" // $ftpserverport is "21" // ------------------------------------ if ($net2ftp_settings["allowed_ftpserverport"] == "ALL") { // Input type is textbox $ftpserverport["inputType"] = "text"; // Prefill with the previous input value if ($net2ftp_globals["ftpserverport"] != "") { $ftpserverport["value"] = htmlEncode2($net2ftp_globals["ftpserverport"]); } elseif ($net2ftp_globals["cookie_ftpserverport"] != "") { $ftpserverport["value"] = htmlEncode2($net2ftp_globals["cookie_ftpserverport"]); } else { $ftpserverport["value"] = 21; } } else { $ftpserverport["inputType"] = "hidden"; $ftpserverport["value"] = $net2ftp_settings["allowed_ftpserverport"]; } // ------------------------------------ // Username // ------------------------------------ // Prefill with the previous input value if ($net2ftp_globals["username"] != "") { $username = htmlEncode2($net2ftp_globals["username"]); } else { $username = htmlEncode2($net2ftp_globals["cookie_username"]); } // ------------------------------------ // Password // ------------------------------------ // Do not prefill this field $password = ""; // ------------------------------------ // Passive mode // ------------------------------------ if ($net2ftp_globals["passivemode"] == "yes") { $passivemode["checked"] = "checked=\"checked\""; } elseif ($net2ftp_globals["cookie_passivemode"] == "yes") { $passivemode["checked"] = "checked=\"checked\""; } else { $passivemode["checked"] = ""; } // ------------------------------------ // Initial directory // ------------------------------------ if (strlen($net2ftp_globals["directory"]) > 1) { $directory = $net2ftp_globals["directory_html"]; } elseif (strlen($net2ftp_globals["cookie_directory"]) > 1) { $directory = htmlEncode2($net2ftp_globals["cookie_directory"]); } else { $directory = ""; } // ------------------------------------ // Protocol // ------------------------------------ $protocol["inputType"] = "hidden"; $protocol["list"][1] = "FTP"; if (function_exists("ssh2_connect") == true) { $protocol["list"][2] = "FTP over SSH2"; $protocol["inputType"] = "select"; } if (function_exists("ftp_ssl_connect") == true) { $protocol["list"][3] = "FTP with SSL"; $protocol["inputType"] = "select"; } // ------------------------------------ // Language // ------------------------------------ $language_onchange = "document.forms['LoginForm'].state.value='login'; document.forms['LoginForm'].submit();"; // ------------------------------------ // Skin // ------------------------------------ $skin_onchange = ""; // ------------------------------------ // FTP mode // ------------------------------------ // Determine the FTP mode if ($net2ftp_globals["ftpmode"] != "") { $ftpmode["type"] = htmlEncode2($net2ftp_globals["ftpmode"]); } elseif ($net2ftp_globals["cookie_ftpmode"] != "") { $ftpmode["type"] = htmlEncode2($net2ftp_globals["cookie_ftpmode"]); } else { // Before PHP version 4.3.11, bug 27633 can cause problems in ASCII mode ==> use BINARY mode if (version_compare(phpversion(), "4.3.11", "<")) { $ftpmode["type"] = "binary"; } else { $ftpmode["type"] = "automatic"; } } // Fill the values that will be used in the template if ($ftpmode["type"] == "automatic") { $ftpmode["automatic"] = "checked=\"checked\""; $ftpmode["binary"] = ""; } elseif ($ftpmode["type"] == "binary") { $ftpmode["automatic"] = ""; $ftpmode["binary"] = "checked=\"checked\""; } // ------------------------------------ // FTP mode // ------------------------------------ $admin_url = $net2ftp_globals["action_url"] . "?state=login_small&state2=admin&go_to_state=admin"; // ------------------------------------ // Focus // ------------------------------------ if ($net2ftp_settings["allowed_ftpservers"][1] == "ALL") { $focus = "ftpserver"; } else { $focus = "username"; } // ------------------------------------------------------------------------- // Print the output // ------------------------------------------------------------------------- require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/login.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 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"; }
function printTable($sqlquery) { // -------------- // This function executes the SQL query and prints a nice HTML table with the results // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- // global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output; // ------------------------------------------------------------------------- // Execute the SQL query // ------------------------------------------------------------------------- $result = mysql_query("{$sqlquery}"); if ($result == false) { $errormessage = __("Unable to execute the SQL query <b>%1\$s</b>.", $sqlquery); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } $nrofrows = mysql_num_rows($result); $nrofcolumns_withindex = mysql_num_fields($result) + 1; // ------------------------------------------------------------------------- // Print the table // ------------------------------------------------------------------------- // Table begin $output = "<table border=\"1\">\n"; // First row: SQL query $output .= "<tr><td colspan=\"{$nrofcolumns_withindex}\" class=\"tdheader1\" style=\"font-size: 120%;\">{$sqlquery}</td></tr>\n"; if ($nrofrows != 0) { // Second row: header $row = mysql_fetch_array($result, MYSQL_ASSOC); $output .= "<tr>\n"; $output .= "<td>Index</td>\n"; while (list($fieldname, $fieldvalue) = each($row)) { $output .= "<td>{$fieldname}</td>\n"; } $output .= "</tr>\n"; mysql_data_seek($result, 0); // reset row pointer to the first row // 3rd and next rows: data $rowcounter = 1; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $output .= "<tr>\n"; $output .= "<td>{$rowcounter}</td>\n"; while (list($fieldname, $fieldvalue) = each($row)) { $output .= "<td>" . htmlEncode2($fieldvalue) . "</td>\n"; } $output .= "</tr>\n"; $rowcounter++; } } else { $output .= "<tr><td colspan=\"{$nrofcolumns_withindex}\">" . __("No data") . "</td></tr>"; } // Table end $output .= "</table>\n"; // ------------------------------------------------------------------------- // Free the $result // ------------------------------------------------------------------------- mysql_free_result($result); return $output; }
function ftp_getlist($conn_id, $directory) { // -------------- // This function connects to the FTP server and returns an array with a list of directories and files. // One row per directory or file, with rows from index 1 to n // // Step 1: send ftp_rawlist request to the FTP server; this returns a string // Step 2: parse that string and get a first array ($templist) // Step 3: move the rows to another array, to index 1 to n ($list) // // This function is used in all functions which process directories recursively. // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals, $net2ftp_settings; // ------------------------------------------------------------------------- // Initialization // ------------------------------------------------------------------------- $warnings = ""; // ------------------------------------------------------------------------- // Step 1: Chdir to the directory and get the current directory // ------------------------------------------------------------------------- // ---------------------------------------------- // Step 1a - Directory is "/" // Chdir to the directory because otherwise the ftp_rawlist does not work on some FTP servers // ---------------------------------------------- if ($directory == "/") { $result1a = @ftp_chdir($conn_id, $directory); } elseif ($directory == "") { $result1b = @ftp_chdir($conn_id, $directory); $directory = @ftp_pwd($conn_id); } else { // 1c1 - Replace \' by \\' to be able to delete directories with names containing \' $directory1 = str_replace("\\'", "\\\\'", $directory); // 1c2 - Chdir to the directory // This is to check if the directory exists, but also because otherwise // the ftp_rawlist does not work on some FTP servers. $result1c = @ftp_chdir($conn_id, $directory1); // 1c3 - If the first ftp_chdir returns false, try a second time without the leading / // Some Windows FTP servers do not work when you use a leading / if ($result1c == false) { $directory2 = stripDirectory($directory1); $result2 = @ftp_chdir($conn_id, $directory2); // 1c3 - If the second ftp_chdir also does not work: // For the Browse screen ==> go to the user's root directory // For all other screens ==> return error if ($result2 == false) { if ($net2ftp_globals["state"] == "browse") { $rootdirectory = getRootdirectory(); // User's root directory is different from the current directory, so switch to it if ($directory != $rootdirectory) { $warnings .= __("The directory <b>%1\$s</b> does not exist or could not be selected, so the directory <b>%2\$s</b> is shown instead.", $directory, $rootdirectory); $directory = $rootdirectory; $result3 = @ftp_chdir($conn_id, $directory); } else { $errormessage = __("Your root directory <b>%1\$s</b> does not exist or could not be selected.", $directory); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); } } else { $errormessage = __("The directory <b>%1\$s</b> could not be selected - you may not have sufficient rights to view this directory, or it may not exist.", $directory); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); } } // end if result2 } // end if result1 } // end if / or "" or else // ------------------------------------------------------------------------- // Step 2 - Get list of directories and files // The -a option is used to show the hidden files as well on some FTP servers // Some servers do not return anything when using -a, so in that case try again without the -a option // ------------------------------------------------------------------------- $rawlist = ftp_rawlist($conn_id, "-a"); if (sizeof($rawlist) <= 1) { $rawlist = ftp_rawlist($conn_id, ""); } // ------------------------------------------------------------------------- // Step 3 - Parse the raw list // ------------------------------------------------------------------------- // ---------------------------------------------- // Initialize variables // ---------------------------------------------- $list["directories"] = array(); $list["files"] = array(); $list["symlinks"] = array(); $list["unrecognized"] = array(); $directory_index = 1; $file_index = 1; $symlink_index = 1; $unrecognized_index = 1; $list["stats"]["directories"]["total_number"] = 0; $list["stats"]["directories"]["total_size"] = 0; $list["stats"]["directories"]["total_skipped"] = 0; $list["stats"]["files"]["total_number"] = 0; $list["stats"]["files"]["total_size"] = 0; $list["stats"]["files"]["total_skipped"] = 0; $list["stats"]["symlinks"]["total_number"] = 0; $list["stats"]["symlinks"]["total_size"] = 0; $list["stats"]["symlinks"]["total_skipped"] = 0; $list["stats"]["unrecognized"]["total_number"] = 0; $list["stats"]["unrecognized"]["total_size"] = 0; $list["stats"]["unrecognized"]["total_skipped"] = 0; // ---------------------------------------------- // Loop over the raw list lines // ---------------------------------------------- $nr_entries_banned_keyword = 0; $nr_entries_too_big = 0; for ($i = 0; $i < sizeof($rawlist); $i++) { // ---------------------------------------------- // Scan each line // ---------------------------------------------- $listline = ftp_scanline($directory, $rawlist[$i]); // If $listline is empty (e.g. if it contained ".."), continue to the next line if ($listline == "") { continue; } // Encode the name for HTML and Javascript if (isset($listline["dirfilename"])) { $listline["dirfilename_html"] = htmlEncode2($listline["dirfilename"]); $listline["dirfilename_url"] = urlEncode2($listline["dirfilename"]); $listline["dirfilename_js"] = javascriptEncode2($listline["dirfilename"]); } // Check if the filename contains a forbidden keyword // If it does, then this line will not be selectable on the Browse screen // Note: even if "selectable" is set to true here, it can still be set to false just below if the filesize is too big if (checkAuthorizedName($listline["dirfilename"]) == true) { $listline["selectable"] = "ok"; } else { $listline["selectable"] = "banned_keyword"; $nr_entries_banned_keyword++; } // Check if the filesize is bigger than the maximum authorized filesize if ($listline["dirorfile"] == "-" && isset($listline["size"]) && is_numeric($listline["size"])) { if ($listline["selectable"] == "ok" && $listline["size"] > $net2ftp_settings["max_filesize"]) { $listline["selectable"] = "too_big"; $nr_entries_too_big++; } } // Form the new directory filename and encode it too if ($listline["dirorfile"] == "d") { $listline["newdir"] = glueDirectories($directory, $listline["dirfilename"]); $listline["newdir_html"] = htmlEncode2($listline["newdir"]); $listline["newdir_url"] = urlEncode2($listline["newdir"]); $listline["newdir_js"] = javascriptEncode2($listline["newdir"]); } // ---------------------------------------------- // Depending on if the line contained a directory/file/symlink/unrecognized // row, store the result in different variables // ---------------------------------------------- if ($listline["dirorfile"] == "d") { $list["directories"][$directory_index] = $listline; $directory_index++; if (isset($listline["size"]) && is_numeric($listline["size"])) { $list["stats"]["directories"]["total_size"] = $list["stats"]["directories"]["total_size"] + $listline["size"]; } else { $list["stats"]["directories"]["total_skipped"] = $list["stats"]["directories"]["total_skipped"] + 1; } } elseif ($listline["dirorfile"] == "-") { $list["files"][$file_index] = $listline; $file_index++; if (isset($listline["size"]) && is_numeric($listline["size"])) { $list["stats"]["files"]["total_size"] = $list["stats"]["files"]["total_size"] + $listline["size"]; } else { $list["stats"]["files"]["total_skipped"] = $list["stats"]["files"]["total_skipped"] + 1; } } elseif ($listline["dirorfile"] == "l") { $list["symlinks"][$symlink_index] = $listline; $symlink_index++; } elseif ($listline["dirorfile"] == "u") { $list["unrecognized"][$unrecognized_index] = $listline; $unrecognized_index++; } // end elseif } // end for // Print a warning message if some directories, files or symlinks contain a banned keyword or if a file is // too big to be downloaded if ($nr_entries_banned_keyword > 0) { $warnings .= __("Entries which contain banned keywords can't be managed using net2ftp. This is to avoid Paypal or Ebay scams from being uploaded through net2ftp."); $warnings .= "<br />\n"; } if ($nr_entries_too_big > 0) { $warnings .= __("Files which are too big can't be downloaded, uploaded, copied, moved, searched, zipped, unzipped, viewed or edited; they can only be renamed, chmodded or deleted."); $warnings .= "<br />\n"; } // Store the warnings and new directory in $list["stats"] if (isset($warnings) == true) { $list["stats"]["warnings"] = $warnings; } else { $list["stats"]["warnings"] = ""; } $list["stats"]["newdirectory"] = $directory; // Store the statistics $list["stats"]["directories"]["total_size_formated"] = formatFilesize($list["stats"]["directories"]["total_size"]); $list["stats"]["files"]["total_size_formated"] = formatFilesize($list["stats"]["files"]["total_size"]); $list["stats"]["directories"]["total_number"] = $directory_index - 1; $list["stats"]["files"]["total_number"] = $file_index - 1; $list["stats"]["symlinks"]["total_number"] = $symlink_index - 1; $list["stats"]["unrecognized"]["total_number"] = $unrecognized_index - 1; // Put everything together in $list["all"] $list["all"] = $list["directories"] + $list["files"] + $list["symlinks"] + $list["unrecognized"]; // ------------------------------------------------------------------------- // Step 4 - Return the result // ------------------------------------------------------------------------- return $list; // ------------------------------------------------------------------------- // Some documentation: // 1 - Some FTP servers return a total on the first line // 2 - Some FTP servers return . and .. in their list of directories // ftp_scanline does not return those entries. // ------------------------------------------------------------------------- // 1 - After doing some tests on different public FTP servers, it appears that // they reply differently to the ftp_rawlist request: // - some FTP servers, like ftp.belnet.be, start with a line summarizing how // many subdirectories and files there are in the current directory. The // real list of subdirectories and files starts on the second line. // [0] => total 15 // [1] => drwxr-xr-x 11 BELNET Archive 512 Feb 6 2000 BELNET // [2] => drwxr-xr-x 2 BELNET Archive 512 Oct 29 2001 FVD-SFI // - some other FTP servers, like ftp.redhat.com/pub, start directly with the // list of subdirectories and files. // [0] => drwxr-xr-x 9 ftp ftp 4096 Jan 11 06:34 contrib // [1] => drwxr-xr-x 13 ftp ftp 4096 Jan 29 21:59 redhat // [2] => drwxrwsr-x 6 ftp ftp 4096 Jun 05 2002 up2date // 2 - Some FTP servers return "." and ".." as directories. These fake entries // have to be eliminated! // They would cause infinite loops in the copy/move/delete functions. // [0] => drwxr-xr-x 5 80 www 512 Apr 10 09:39 . // [1] => drwxr-xr-x 16 80 www 512 Apr 9 08:51 .. // [2] => -rw-r--r-- 1 80 www 5647 Apr 9 08:12 _CHANGES_v0.5 // [3] => -rw-r--r-- 1 80 www 1239 Apr 9 08:12 _CREDITS_v0.5 }
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 local_writefile($file, $string) { // -------------- // Open the local file $file and write the $string to it // -------------- global $net2ftp_globals; $handle = fopen($file, "wb"); if ($handle == false) { $errormessage = __("Unable to open the temporary file. Check the permissions of the %1\$s directory.", $net2ftp_globals["application_tempdir"]); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } $success1 = fwrite($handle, $string); if ($success1 == false && strlen($string) > 0) { $errormessage = __("Unable to write the string to the temporary file <b>%1\$s</b>.<br />Check the permissions of the %2\$s directory.", $file, $net2ftp_globals["application_tempdir"]); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } $success2 = fclose($handle); if ($success2 == false) { $errormessage = __("Unable to close the handle of the temporary file"); setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__); return false; } }
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("&", "&", $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("&", "&", $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; } } }