\", ' --> \' // Has only to be done when getting info from get post cookie if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() == 1) { if (is_array($x)) { foreach ($x as $key => $value) { if ($value) { remove_magic_quotes($x[$key],$key); } } } else { $quote = "'"; $doublequote = "\""; $backslash = "\\"; $x = str_replace("$backslash$quote", $quote, $x); $x = str_replace("$backslash$doublequote", $doublequote, $x); $x = str_replace("$backslash$backslash", $backslash, $x); } } // end if get_magic_quotes_gpc return $x; } // end function remove_magic_quotes // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateFtpserver($ftpserver) { // -------------- // Input: " ftp://something.domainname.com:123/directory/file " // Output: "something.domainname.com" // -------------- // Remove invisible characters in the beginning and at the end $ftpserver = trim($ftpserver); // Remove possible "ftp://" if (substr($ftpserver, 0, 6) == "ftp://") { $ftpserver = substr($ftpserver, 6); } // Remove a possible port nr ":123" if (preg_match("/(.*)[:]{1}[0-9]+/", $ftpserver, $regs) == true) { $ftpserver = $regs[1]; } // Remove a possible trailing / or \ // Remove a possible directory and file "/directory/file" if (preg_match("/[\\/\\\\]*(.*)[\\/\\\\]{1,}.*/", $ftpserver, $regs) == true) { // Any characters like / or \ // Anything // Followed by at least one / or \ // Followed by any characters $ftpserver = $regs[1]; } // FTP server may only contain specific characters $ftpserver = preg_replace("/[^A-Za-z0-9._-]/", "", $ftpserver); return $ftpserver; } // end validateFTPserver // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateFtpserverport($ftpserverport) { // -------------- // This function validates the FTP server port // -------------- // Remove invisible characters in the beginning and at the end $ftpserverport = trim($ftpserverport); // FTP server port must be numeric and > 0 and < 65536, else set it to 21 if (is_numeric($ftpserverport) != true || $ftpserverport < 0 || $ftpserverport > 65536) { $ftpserverport = 21; } return $ftpserverport; } // end validateFtpserverport // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateUsername($username) { // -------------- // This function validates the username // -------------- // Remove invisible characters in the beginning and at the end $username = trim($username); // Remove XSS code // $username = RemoveXSS($username); return $username; } // end validateUsername // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validatePasswordEncrypted($password_encrypted) { // -------------- // This function validates the encrypted password // -------------- // Remove invisible characters in the beginning and at the end $password_encrypted = trim($password_encrypted); // Encrypted password may only contain specific characters $password_encrypted = preg_replace("/[^A-Fa-f0-9]/", "", $password_encrypted); return $password_encrypted; } // end validatePasswordEncrypted // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validatePassword($password) { // -------------- // This function validates the plain password // -------------- // Remove invisible characters in the beginning and at the end $password = trim($password); // Remove XSS code // $password = RemoveXSS($password); return $password; } // end validatePassword // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateLanguage($language) { // -------------- // This function validates the language // -------------- global $net2ftp_settings; $languageArray = getLanguageArray(); if (isset($languageArray[$language]) == true) { return $language; } elseif (isset($_COOKIE["net2ftpcookie_language"]) == true && isset($languageArray[$_COOKIE["net2ftpcookie_language"]]) == true) { return $_COOKIE["net2ftpcookie_language"]; } elseif (isset($languageArray[$net2ftp_settings["default_language"]]) == true){ return $net2ftp_settings["default_language"]; } else { return "en"; } } // end validateLanguage // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateSkin($skin) { // -------------- // This function validates the skin // -------------- global $net2ftp_settings; $skinArray = getSkinArray(); if (isset($skinArray[$skin]) == true) { return $skin; } elseif (isset($_COOKIE["net2ftpcookie_skin"]) == true && isset($skinArray[$_COOKIE["net2ftpcookie_skin"]]) == true) { return $_COOKIE["net2ftpcookie_skin"]; } else { if (defined("_VALID_MOS") == true) { return "mambo"; } elseif (defined("CACHE_PERMANENT") == true) { return "drupal"; } elseif (defined("XOOPS_ROOT_PATH") == true) { return "xoops"; } elseif (getBrowser("platform") == "iPhone") { return "iphone"; } elseif (getBrowser("platform") == "Mobile") { return "mobile"; } elseif (isset($skinArray[$net2ftp_settings["default_skin"]]) == true) { return $net2ftp_settings["default_skin"]; } else { return "shinra"; } } } // end validateSkin // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateFtpmode($ftpmode) { // -------------- // This function validates the FTP mode // -------------- if ($ftpmode == "ascii" || $ftpmode == "binary" || $ftpmode == "automatic") { return $ftpmode; } elseif (isset($_COOKIE["net2ftpcookie_ftpmode"]) == true && ($_COOKIE["net2ftpcookie_ftpmode"] == "ascii" || $_COOKIE["net2ftpcookie_ftpmode"] == "binary" || $_COOKIE["net2ftpcookie_ftpmode"] == "automatic")) { return $_COOKIE["net2ftpcookie_ftpmode"]; } else { // Before PHP version 4.3.11, bug 27633 can cause problems in ASCII mode ==> use BINARY mode // As from PHP version 4.3.11, bug 27633 is fixed ==> use Automatic mode if (version_compare(phpversion(), "4.3.11", "<")) { return "binary"; } else { return "automatic"; } } } // end validateFtpmode // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validatePassivemode($passivemode) { // -------------- // This function validates the passive mode // -------------- if ($passivemode != "yes") { $passivemode = "no"; } return $passivemode; } // end validatePassivemode // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateProtocol($protocol) { // -------------- // This function validates the protocol // -------------- if ($protocol == "FTP" || $protocol == "FTP-SSL" || $protocol == "FTP-SSH") { return $protocol; } else { return "FTP"; } } // end validateProtocol // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateViewmode($viewmode) { // -------------- // This function validates the view mode // -------------- if ($viewmode != "icons") { $viewmode = "list"; } return $viewmode; } // end validateViewmode // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateSort($sort) { // -------------- // This function validates the sorting criteria // -------------- if ( $sort != "" && $sort != "dirfilename" && $sort != "type" && $sort != "size" && $sort != "owner" && $sort != "group" && $sort != "permissions" && $sort != "mtime") { $sort = "dirfilename"; } return $sort; } // end validateSort // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateSortorder($sortorder) { // -------------- // This function validates the sort order // -------------- if ( $sortorder != "" && $sortorder != "descending") { $sortorder = "ascending"; } return $sortorder; } // end validateSortorder // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateState($state) { // -------------- // This function validates the state variable // -------------- $statelist[] = "admin"; $statelist[] = "admin_createtables"; $statelist[] = "admin_emptylogs"; $statelist[] = "admin_viewlogs"; $statelist[] = "advanced"; $statelist[] = "advanced_ftpserver"; $statelist[] = "advanced_parsing"; $statelist[] = "advanced_webserver"; $statelist[] = "bookmark"; $statelist[] = "browse"; $statelist[] = "calculatesize"; $statelist[] = "chmod"; $statelist[] = "clearcookies"; $statelist[] = "copymovedelete"; $statelist[] = "downloadfile"; $statelist[] = "downloadzip"; $statelist[] = "edit"; $statelist[] = "findstring"; $statelist[] = "followsymlink"; $statelist[] = "getcookies"; $statelist[] = "install"; $statelist[] = "jupload"; $statelist[] = "login"; $statelist[] = "login_small"; $statelist[] = "logout"; $statelist[] = "newdir"; $statelist[] = "raw"; $statelist[] = "rename"; $statelist[] = "unzip"; $statelist[] = "upload"; $statelist[] = "view"; $statelist[] = "zip"; if (in_array($state, $statelist) == false) { $state = "login"; } return $state; } // end validateState // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateState2($state2) { // -------------- // This function validates the state2 variable // -------------- if ($state2 != "") { // State2 may only contain specific characters $state2 = preg_replace("/[^A-Za-z0-9_-]/", "", $state2); } return $state2; } // end validateState2 // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateEntry($entry) { // -------------- // This function validates the entry // Remove the following characters \/:*?"<>| // -------------- // Remove XSS code // $entry = RemoveXSS($entry); // Remove \ / : * ? < > | // Do not remove / or > otherwise the module "followsymlink" does not work // $entry = preg_replace("/[\\\\\\/\\:\\*\\?\\<\\>\\|]/", "", $entry); return $entry; } // end validateEntry // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateScreen($screen) { // -------------- // This function validates the screen variable // -------------- if ($screen != 1 && $screen != 2 && $screen != 3) { $screen = 1; } return $screen; } // end validateScreen // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateDirectory($directory) { // -------------- // Input: "/dir1/dir2/dir3/../../dir4/dir5" // Output: "/dir1/dir4/dir5" // Remove the following characters \/:*?"<>| // -------------- // ------------------------------------------------------------------------- // Nothing to do if the directory is the root directory // ------------------------------------------------------------------------- if ($directory == "") { return ""; } elseif ($directory == "/") { return "/"; } // ------------------------------------------------------------------------- // Remove XSS code // ------------------------------------------------------------------------- // $directory = RemoveXSS($directory); // ------------------------------------------------------------------------- // Check if the directory contains ".." // ------------------------------------------------------------------------- if (strpos($directory, "..") === false) { $directory = "/" . stripDirectory($directory); } else { $directory = stripDirectory($directory); // Split down into parts // directoryparts[0] contains the first part, directoryparts[1] the second,... $directoryparts = explode("/", $directory); // Start from the end // If you encounter N times a "..", do not take into account the next N parts which are not ".." // Example: "/dir1/dir2/dir3/../../dir4/dir5" ----> "/dir1/dir4/dir5" $doubledotcounter = 0; $newdirectory = ""; $sizeof_directoryparts = sizeof($directoryparts); for ($i=$sizeof_directoryparts-1; $i>=0; $i=$i-1) { if ($directoryparts[$i] == "..") { $doubledotcounter = $doubledotcounter + 1; } else { if ($doubledotcounter == 0) { $newdirectory = $directoryparts[$i] . "/" . $newdirectory; } // Add the new part in front elseif ($doubledotcounter > 0) { $doubledotcounter = $doubledotcounter - 1; } // Don't add the part, and reduce the counter by 1 } } // end for $directory = "/" . stripDirectory($newdirectory); } // end if else // Remove : * ? " < > | // $directory = preg_replace("/[\\:\\*\\?\\\"\\<\\>\\|]/", "", $directory); // Remove : * ? < > | $directory = preg_replace("/[\\:\\*\\?\\<\\>\\|]/", "", $directory); return $directory; } // end validateDirectory // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateGenericInput($input) { // -------------- // Remove the following characters <> // -------------- // Remove XSS code // $input = RemoveXSS($input); // Remove < > $input = preg_replace("/[\\<\\>]/", "", $input); return $input; } // end validateGenericInput // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function validateTextareaType($textareaType) { // -------------- // Remove the following characters <> // -------------- if ( $textareaType != "plain" && $textareaType != "ckeditor" && $textareaType != "tinymce" && $textareaType != "ace") { $textareaType = "plain"; } return $textareaType; } // end validateTextareaType // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function RemoveXSS($val) { // -------------- // This function removes malicious cross-site scripting (XSS) code from user input // From http://quickwired.com/smallprojects/php_xss_filter_function.php // -------------- // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed // this prevents some character re-spacing such as // note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs $val = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', '', $val); // straight replacements, the user should never need these since they're normal characters // this prevents like $search = 'abcdefghijklmnopqrstuvwxyz'; $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $search .= '1234567890!@#$%^&*()'; $search .= '~`";:?+/={}[]-_|\'\\'; for ($i = 0; $i < strlen($search); $i++) { // ;? matches the ;, which is optional // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars // @ @ search for the hex values $val = preg_replace('/(&#[x|X]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ; // @ @ 0{0,7} matches '0' zero to seven times $val = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ; } // now the only remaining whitespace attacks are \t, \n, and \r $ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base'); $ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'); $ra = array_merge($ra1, $ra2); $found = true; // keep replacing as long as the previous round replaced something while ($found == true) { $val_before = $val; for ($i = 0; $i < sizeof($ra); $i++) { $pattern = '/'; for ($j = 0; $j < strlen($ra[$i]); $j++) { if ($j > 0) { $pattern .= '('; $pattern .= '(&#[x|X]0{0,8}([9][a][b]);?)?'; $pattern .= '|(�{0,8}([9][10][13]);?)?'; $pattern .= ')?'; } $pattern .= $ra[$i][$j]; } // end for $pattern .= '/i'; $replacement = substr($ra[$i], 0, 2).''.substr($ra[$i], 2); // add in <> to nerf the tag $val = preg_replace($pattern, $replacement, $val); // filter out the hex tags if ($val_before == $val) { // no replacements were made, so exit the loop $found = false; } // end if } // end for } // end while return $val; } // end RemoveXSS // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** ?>