onresize="setFileWindowSize('ajaxContentWindow',0,0);"> 0 && $date_now < $_SESSION["login_lockout"]) { $n = ceil(($_SESSION["login_lockout"] - $date_now) / 60); $_SESSION["login_error"] = str_replace("[n]",$n,$lang_max_logins); } // Check for posted form if ($posted == 1) { // Set vars $ftp_ssl = $_POST["ftp_ssl"]; $ftp_host = trim($_POST["ftp_host"]); $ftp_user = trim($_POST["ftp_user"]); $ftp_pass = trim($_POST["ftp_pass"]); $ftp_port = trim($_POST["ftp_port"]); $ftp_pasv = $_POST["ftp_pasv"]; $interface = $_POST["interface"]; $lang = $_POST["lang"]; $skin = $_POST["skin"]; $login_save = $_POST["login_save"]; $ip_check = $_POST["ip_check"]; $_SESSION["domain"] = $_SERVER["SERVER_NAME"]; } else { // Set values from cookies if ($_COOKIE["login_save"] == 1) { $ftp_ssl = $_COOKIE["ftp_ssl"]; $ftp_host = $_COOKIE["ftp_host"]; $ftp_user = $_COOKIE["ftp_user"]; $ftp_pass = $_COOKIE["ftp_pass"]; $ftp_port = $_COOKIE["ftp_port"]; $ftp_pasv = $_COOKIE["ftp_pasv"]; $interface = $_COOKIE["interface"]; $lang = $_COOKIE["lang"]; $skin = $_COOKIE["skin"]; $login_save = $_COOKIE["login_save"]; $ip_check = $_COOKIE["ip_check"]; } else { $ftp_port = 21; $ftp_pasv = 1; } } if ($ajaxRequest == 1) { sessionExpired($lang_session_expired); logOut(); } else { // Check for errors if ($_SESSION["login_error"] != "") { $height = 522; } else { $height = 458; } ?>
WebFTP (CWP)
"> :
"> : " tabindex="-1">

:
">

:
" autocomplete="off">




tabindex="-1">

tabindex="-1">

tabindex="-1">

tabindex="-1">

tabindex="-1">


0 && $date_now > $_SESSION["login_lockout"])) { // Authenticate if (@ftp_login ($conn_id, $_SESSION["ftp_user"], $_SESSION["ftp_pass"])) { if ($_SESSION["ftp_pasv"] == 1) @ftp_pasv($conn_id, true); $_SESSION["loggedin"] = 1; $_SESSION["login_fails"] = 0; return 1; } else { $_SESSION["login_error"] = $lang_cant_authenticate; // Count the failed login attempts (if form posted) if ($posted == 1) { $_SESSION["login_fails"]++; // Lock user for 5 minutes if 3 failed attempts if ($_SESSION["login_fails"] >= 3) $_SESSION["login_lockout"] = date("YmdHis") + ($lockOutTime * 60); } return 0; } } } } else { return 0; } } ############################################### # WRITE HIDDEN DIVS ############################################### function writeHiddenDivs() { ?>
"; echo ""; echo ""; echo ""; echo "".getFtpColumnSpan("n",$lang_table_name).""; echo "".getFtpColumnSpan("s",$lang_table_size).""; echo "".getFtpColumnSpan("d",$lang_table_date).""; echo "".getFtpColumnSpan("t",$lang_table_time).""; // Only display permissions/user/group for Linux advanced if ($_SESSION["interface"] == "adv" && $_SESSION["win_lin"] != "win") { echo "".$lang_table_user.""; echo "".$lang_table_group.""; echo "".$lang_table_perms.""; } echo ""; #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # FOLDER UP BUTTON #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if ($_SESSION["dir_current"] != "/" && $_SESSION["dir_current"] != "~") { echo ""; echo ""; echo ""; if ($_SESSION["interface"] == "adv") echo ""; else echo ""; // Get the parent directory $parent = getParentDir(); echo "
...
"; echo ""; echo ""; } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # FOLDERS & FILES #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (sizeof($ftp_rawlist) > 0) { // Linux if ($_SESSION["win_lin"] == "lin") { echo createFileFolderArrayLin($ftp_rawlist,"folders"); echo createFileFolderArrayLin($ftp_rawlist,"links"); echo createFileFolderArrayLin($ftp_rawlist,"files"); } // Windows if ($_SESSION["win_lin"] == "win") { echo createFileFolderArrayWin($ftp_rawlist,"folders"); echo createFileFolderArrayWin($ftp_rawlist,"files"); } } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # CLOSE TABLE #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo ""; } ############################################### # GET PLATFORM ############################################### function getPlatform() { global $conn_id; global $platformTestCount; if ($_SESSION["win_lin"] == "") { $ftp_rawlist = ftp_rawlist($conn_id, "."); // Check for content in array if (sizeof($ftp_rawlist) == 0) { $platformTestCount++; // Create a test folder if (@ftp_mkdir($conn_id, "test")) { if ($platformTestCount < 2) { getPlatform(); @ftp_rmdir($conn_id, "test"); } } } else { // Get first item in array $ff = $ftp_rawlist[0]; // Split up array into values $ff = preg_split("/[\s]+/",$ff,9); // First item in Linux rawlist is permissions. In Windows it's date. // If length of first item in array line is 8 chars, without a-z, it's a date. if (strlen($ff[0]) == 8 && !preg_match("/[a-z]/i", $ff[0], $matches)) $win_lin = "win"; if (strlen($ff[0]) == 10 && !preg_match("/[0-9]/i", $ff[0], $matches)) $win_lin = "lin"; $_SESSION["win_lin"] = $win_lin; } } } ############################################### # CREATE FILE/FOLDER ARRAY FOR LINUX ############################################### function createFileFolderArrayLin($ftp_rawlist,$type) { // Go through array of files/folders foreach($ftp_rawlist AS $ff) { // Reset values $time=""; $year=""; // Split up array into values $ff = preg_split("/[\s]+/",$ff,9); $perms = $ff[0]; $user = $ff[2]; $group = $ff[3]; $size = $ff[4]; $month = $ff[5]; $day = $ff[6]; $file = $ff[8]; // Check if file starts with a dot $dot_prefix=0; if (preg_match("/^\.+/",$file) && $_SESSION["interface"] == "bas") $dot_prefix=1; if ($file != "." && $file != ".." && $dot_prefix == 0) { // Where the last mod date is the previous year, the year will be displayed in place of the time if (preg_match("/:/",$ff[7])) $time = $ff[7]; else $year = $ff[7]; // Set date $date = formatFtpDate($day,$month,$year); // Reset user and group if ($user == "0") $user = "-"; if ($group == "0") $group = "-"; // Add folder to array if (getFileType($perms) == "d") { $foldAllAr[] = $file."|d|".$date."|".$time."|".$user."|".$group."|".$perms; $foldNameAr[] = $file; $foldDateAr[] = $date; $foldTimeAr[] = $time; $foldUserAr[] = $user; $foldGroupAr[] = $group; $foldPermsAr[] = $perms; } // Add link to array if (getFileType($perms) == "l") { $linkAllAr[] = $file."|l|".$date."|".$time."|".$user."|".$group."|".$perms; $linkNameAr[] = $file; $linkDateAr[] = $date; $linkTimeAr[] = $time; $linkUserAr[] = $user; $linkGroupAr[] = $group; $linkPermsAr[] = $perms; } // Add file to array if (getFileType($perms) == "f") { $fileAllAr[] = $file."|".$size."|".$date."|".$time."|".$user."|".$group."|".$perms; $fileNameAr[] = $file; $fileSizeAr[] = $size; $fileDateAr[] = $date; $fileTimeAr[] = $time; $fileUserAr[] = $user; $fileGroupAr[] = $group; $filePermsAr[] = $perms; } } } // Check there are files and/or folders to display if (is_array($foldAllAr) || is_array($linkAllAr) || is_array($fileAllAr)) { // Set sorting order if ($_POST["sort"] == "") $sort = "n"; else $sort = $_POST["sort"]; if ($_POST["ord"] == "") $ord = "asc"; else $ord = $_POST["ord"]; // Return folders if ($type == "folders") { if (is_array($foldAllAr)) { // Set the folder arrays to sort if ($sort == "n") $sortAr = $foldNameAr; if ($sort == "d") $sortAr = $foldDateAr; if ($sort == "t") $sortAr = $foldTimeAr; if ($sort == "u") $sortAr = $foldUserAr; if ($sort == "g") $sortAr = $foldGroupAr; if ($sort == "p") $sortAr = $foldPermsAr; // Multisort array if (is_array($sortAr)) { if ($ord == "asc") array_multisort($sortAr, SORT_ASC, $foldAllAr); else array_multisort($sortAr, SORT_DESC, $foldAllAr); } // Format and display folder content $folders = getFileListHtml($foldAllAr, "icon_16_folder.gif"); } return $folders; } // Return links if ($type == "links") { if (is_array($linkAllAr)) { // Set the folder arrays to sort if ($sort == "n") $sortAr = $linkNameAr; if ($sort == "d") $sortAr = $linkDateAr; if ($sort == "t") $sortAr = $linkTimeAr; if ($sort == "u") $sortAr = $linkUserAr; if ($sort == "g") $sortAr = $linkGroupAr; if ($sort == "p") $sortAr = $linkPermsAr; // Multisort array if (is_array($sortAr)) { if ($ord == "asc") array_multisort($sortAr, SORT_ASC, $linkAllAr); else array_multisort($sortAr, SORT_DESC, $linkAllAr); } // Format and display folder content $links = getFileListHtml($linkAllAr, "icon_16_link.gif"); } return $links; } // Return files if ($type == "files") { if (is_array($fileAllAr)) { // Set the folder arrays to sort if ($sort == "n") $sortAr = $fileNameAr; if ($sort == "s") $sortAr = $fileSizeAr; if ($sort == "d") $sortAr = $fileDateAr; if ($sort == "t") $sortAr = $fileTimeAr; if ($sort == "u") $sortAr = $fileUserAr; if ($sort == "g") $sortAr = $fileGroupAr; if ($sort == "p") $sortAr = $filePermsAr; // Multisort folders if ($ord == "asc") array_multisort($sortAr, SORT_ASC, $fileAllAr); else array_multisort($sortAr, SORT_DESC, $fileAllAr); // Format and display file content $files = getFileListHtml($fileAllAr, "icon_16_file.gif"); } return $files; } } } ############################################### # CREATE FILE/FOLDER ARRAY FOR WINDOWS ############################################### function createFileFolderArrayWin($ftp_rawlist,$type) { // Go through array of files/folders foreach($ftp_rawlist AS $ff) { // Split up array into values $ff = preg_split("/[\s]+/",$ff,4); $date = $ff[0]; $time = $ff[1]; $size = $ff[2]; $file = $ff[3]; if ($size == "") $size = "d"; // Format date $day = substr($date,3,2); $month = substr($date,0,2); $year = substr($date,6,2); $date = formatFtpDate($day,$month,$year); // Format time $time = formatWinFtpTime($time); // Add folder to array if ($size == "d") { $foldAllAr[] = $file."|d|".$date."|".$time."|||"; $foldNameAr[] = $file; $foldDateAr[] = $date; $foldTimeAr[] = $time; } // Add file to array if ($size != "d") { $fileAllAr[] = $file."|".$size."|".$date."|".$time."|||"; $fileNameAr[] = $file; $fileSizeAr[] = $size; $fileDateAr[] = $date; $fileTimeAr[] = $time; } } // Check there are files and/or folders to display if (is_array($foldAllAr) || is_array($fileAllAr)) { // Set sorting order if ($_POST["sort"] == "") $sort = "n"; else $sort = $_POST["sort"]; if ($_POST["ord"] == "") $ord = "asc"; else $ord = $_POST["ord"]; // Return folders if ($type == "folders") { if (is_array($foldAllAr)) { // Set the folder arrays to sort if ($sort == "n") $sortAr = $foldNameAr; if ($sort == "d") $sortAr = $foldDateAr; if ($sort == "t") $sortAr = $foldTimeAr; // Multisort array if (is_array($sortAr)) { if ($ord == "asc") array_multisort($sortAr, SORT_ASC, $foldAllAr); else array_multisort($sortAr, SORT_DESC, $foldAllAr); } // Format and display folder content $folders = getFileListHtml($foldAllAr, "icon_16_folder.gif"); } return $folders; } // Return files if ($type == "files") { if (is_array($fileAllAr)) { // Set the folder arrays to sort if ($sort == "n") $sortAr = $fileNameAr; if ($sort == "s") $sortAr = $fileSizeAr; if ($sort == "d") $sortAr = $fileDateAr; if ($sort == "t") $sortAr = $fileTimeAr; // Multisort folders if ($ord == "asc") array_multisort($sortAr, SORT_ASC, $fileAllAr); else array_multisort($sortAr, SORT_DESC, $fileAllAr); // Format and display file content $files = getFileListHtml($fileAllAr, "icon_16_file.gif"); } return $files; } } } ############################################### # GET FTP COLUMN SPAN ############################################### function getFileListHtml($array,$image) { global $trCount; global $dateFormatUsa; if ($trCount == 1) $trCount=1; else $trCount=0; $i=1; foreach ($array AS $file) { list($file,$size,$date,$time,$user,$group,$perms) = explode("|",$file); // Folder check (lin/win) if ($size == "d") $action = "folderAction"; // Link check (lin/win) if ( $size == "l") $action = "linkAction"; // File check (lin/win) if ($size != "d" && $size != "l") $action = "fileAction"; // Set file path if ($size == "l") { $file_path = getPathFromLink($file); $file = preg_replace("/ -> .*/","",$file); } else { if ($_SESSION["dir_current"] == "/") $file_path = "/".$file; else $file_path = $_SESSION["dir_current"]."/".$file; } if ($trCount == 0) { $trClass = "trBg0"; $trCount=1; } else { $trClass = "trBg1"; $trCount=0; } // Check for checkbox check (only if action button clicked" if ($_POST["ftpAction"] != "") { if ( (sizeof($_SESSION["clipboard_rename"]) > 1 && in_array($file,$_SESSION["clipboard_rename"])) || (sizeof($_SESSION["clipboard_chmod"]) > 1 && in_array($file_path,$_SESSION["clipboard_chmod"]))) $checked = "checked"; else $checked = ""; } else { $checked = ""; } // Set the date if ($dateFormatUsa == 1) $date = substr($date,4,2)."/".substr($date,6,2)."/".substr($date,2,2); else $date = substr($date,6,2)."/".substr($date,4,2)."/".substr($date,2,2); $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; // Display Folders if ($action == "folderAction") $html .= "
".sanitizeStr($file)."
"; // Display Links if ($action == "linkAction") $html .= "
".sanitizeStr($file)."
"; // Display files if ($action == "fileAction") $html .= "".sanitizeStr($file).""; $html .= ""; $html .= "".formatFileSize($size).""; $html .= "".$date.""; $html .= "".$time.""; if ($_SESSION["interface"] == "adv" && $_SESSION["win_lin"] == "lin") { $html .= "".$user.""; $html .= "".$group.""; $html .= "".$perms.""; } $html .= ""; $i++; } return $html; } ############################################### # GET PATH FROM LINK ############################################### function getPathFromLink($file) { $file_path = preg_replace("/.* -> /","",$file); // Check if path is not absolute if (substr($file_path,0,1) != "/") { // Count occurances of ../ $i=0; while (substr($file_path,0,3) == "../") { $i++; $file_path = substr($file_path,3,strlen($file_path)); } $dir_current = $_SESSION["dir_current"]; // Get the real parent for ($j=0;$j<$i;$j++) { $path_parts = pathinfo($dir_current); $dir_current = $path_parts['dirname']; } // Set the path if ($dir_current == "/") $file_path = "/".$file_path; else $file_path = $dir_current."/".$file_path; } if ($file_path == "~/") $file_path = "~"; return $file_path; } ############################################### # FORMAT FTP DATE ############################################### function formatFtpDate($day,$month,$year) { if (strlen($day) == 1) $day = "0".$day; if ($year == "") $year = date("Y"); if (strlen($year) == 2) { // To avoid a future Y2K problem, check the first two digits of year on Windows if ($year > 00 && $year < 99) $year = substr(date("Y"),0,2).$year; else $year = (substr(date("Y"),0,2)-1).$year; } if ($month == "Jan") $month = "01"; if ($month == "Feb") $month = "02"; if ($month == "Mar") $month = "03"; if ($month == "Apr") $month = "04"; if ($month == "May") $month = "05"; if ($month == "Jun") $month = "06"; if ($month == "Jul") $month = "07"; if ($month == "Aug") $month = "08"; if ($month == "Sep") $month = "09"; if ($month == "Oct") $month = "10"; if ($month == "Nov") $month = "11"; if ($month == "Dec") $month = "12"; $date = $year.$month.$day; return $date; } ############################################### # FORMAT WINDOWS FTP TIME ############################################### function formatWinFtpTime($time) { $h = substr($time,0,2); $m = substr($time,3,2); $am_pm = substr($time,5,2); if ($am_pm == "PM") $h = $h + 12; $time = $h.":".$m; return $time; } ############################################### # CHANGE FTP DIRECTORY (OPEN FOLDER) ############################################### function openFolder() { global $conn_id; global $lang_folder_doesnt_exist; $isError=0; if ($_SESSION["loggedin"] == 1) { // Set the folder to open if ($_SESSION["dir_current"] != "") $dir = $_SESSION["dir_current"]; if ($_POST["openFolder"] != "") $dir = quotesUnescape($_POST["openFolder"]); // Check dir is set if ($dir == "") { // No folder set (must be first login), so set home dir if ($_SESSION["win_lin"] == "lin") $dir = "~"; if ($_SESSION["win_lin"] == "win") $dir = "/"; } // Attempt to change directory if (!@ftp_chdir($conn_id, $dir)) { if (checkFirstCharTilde($dir) == 1) { if (!@ftp_chdir($conn_id, replaceTilde($dir))) { recordFileError("folder",$dir,$lang_folder_doesnt_exist); $isError=1; } } else { recordFileError("folder",$dir,$lang_folder_doesnt_exist); $isError=1; } } if ($isError == 0) { // Set new directory $_SESSION["dir_current"] = $dir; // Record new directory to history if (!is_array($_SESSION["dir_history"])) // array check $_SESSION["dir_history"] = array(); if (!in_array($dir,$_SESSION["dir_history"])) { $_SESSION["dir_history"][] = $dir; asort($_SESSION["dir_history"]); // sort array } return 1; } else { // Delete item from history deleteFtpHistory($dir); // Change to previous directory (if folder to open is currently open) if ($_POST["openFolder"] == $_SESSION["dir_current"] || $_POST["openFolder"] == "") $_SESSION["dir_current"] = getParentDir(); return 0; } } } ############################################### # CHECK LOG OUT ############################################### function checkLogOut() { if ($_GET["logout"] == 1) logOut(); } ############################################### # LOG OUT ############################################### function logOut() { $_SESSION["user_ip"] = ""; $_SESSION["loggedin"] = ""; $_SESSION["win_lin"] = ""; $_SESSION["login_error"] = ""; $_SESSION["login_fails"] = ""; $_SESSION["login_lockout"] = ""; $_SESSION["ftp_host"] = ""; $_SESSION["ftp_user"] = ""; $_SESSION["ftp_pass"] = ""; $_SESSION["ftp_port"] = ""; $_SESSION["ftp_pasv"] = ""; $_SESSION["interface"] = ""; $_SESSION["dir_current"] = ""; $_SESSION["dir_history"] = ""; $_SESSION["clipboard_chmod"] = ""; $_SESSION["clipboard_files"] = ""; $_SESSION["clipboard_folders"] = ""; $_SESSION["clipboard_rename"] = ""; $_SESSION["copy"] = ""; $_SESSION["errors"] = ""; $_SESSION["upload_limit"] = ""; session_destroy(); } ############################################### # FORMAT FILE SIZES ############################################### function formatFileSize($size) { global $lang_size_b; global $lang_size_kb; global $lang_size_mb; global $lang_size_gb; if ($size == "d" || $size == "l") { $size=""; } else { if ($size < 1024) { $size = round($size,2); //$size = round($size,2).$lang_size_b; } elseif ($size < (1024*1024)) { $size = round(($size/1024),0).$lang_size_kb; } elseif ($size < (1024*1024*1024)) { $size = round((($size/1024)/1024),0).$lang_size_mb; } elseif ($size < (1024*1024*1024*1024)) { $size = round(((($size/1024)/1024)/1024),0).$lang_size_gb; } } return $size; } ############################################### # GET FTP COLUMN SPAN ############################################### function getFtpColumnSpan($sort,$name) { // Check current column if ($_POST["sort"] == $sort && $_POST["ord"] == "desc") { $ord = "asc"; } else { $ord = "desc"; } return "".$name.""; } ############################################### # DISPLAY FTP BUTTONS ############################################### function displayFtpActions() { global $lang_btn_refresh; global $lang_btn_cut; global $lang_btn_copy; global $lang_btn_paste; global $lang_btn_rename; global $lang_btn_delete; global $lang_btn_chmod; global $lang_btn_logout; ?>
: : :
0) { $sourceFolder = str_replace("/","\/",$_SESSION["clipboard_folders"][0]); if (preg_match("/".$sourceFolder."/", $folderMoveTo)) { $_SESSION["errors"][] = $lang_move_conflict; $moveError=1; } } if ($moveError != 1) { // Folders foreach ($_SESSION["clipboard_folders"] as $folder_to_move) { $isError=0; // Create the new filename and path $file_destination = getFileFromPath($folder_to_move); $folder = getFileFromPath($folder_to_move); // Check if folder exists if (checkFileExists("d",$folder,$folderMoveTo) == 1) { recordFileError("folder",tidyFolderPath($folderMoveTo,$folder),$lang_folder_exists); } else { if (!@ftp_rename($conn_id, $folder_to_move, $file_destination)) { if (checkFirstCharTilde($folder_to_move) == 1) { if (!@ftp_rename($conn_id, replaceTilde($folder_to_move), replaceTilde($file_destination))) { recordFileError("folder",tidyFolderPath($file_destination,$folder_to_move),$lang_folder_cant_move); $isError=1; } } else { recordFileError("folder",tidyFolderPath($file_destination,$folder_to_move),$lang_folder_cant_move); $isError=1; } } if ($isError == 0) deleteFtpHistory($folder_to_move); } } // Files foreach ($_SESSION["clipboard_files"] as $file_to_move) { $isError=0; // Create the new filename and path $file_destination = $folderMoveTo."/".getFileFromPath($file_to_move); $file = getFileFromPath($file_to_move); // Check if file exists if (checkFileExists("f",$file,$folderMoveTo) == 1) { recordFileError("file",$file,$lang_file_exists); } else { if (!@ftp_rename($conn_id, $file_to_move, $file_destination)) { if (checkFirstCharTilde($file_to_move) == 1) { if (!@ftp_rename($conn_id, replaceTilde($file_to_move), replaceTilde($file_destination))) { recordFileError("file",$file_to_move,$lang_file_cant_move); } } else { recordFileError("file",$file_to_move,$lang_file_cant_move); } } } } } $_SESSION["clipboard_folders"] = array(); $_SESSION["clipboard_files"] = array(); } ############################################### # DRAG & DROP FILES ############################################### function dragDropFiles() { global $conn_id; global $lang_file_exists; global $lang_folder_exists; global $lang_file_cant_move; $fileExists=0; $dragFile = quotesUnescape($_POST["dragFile"]); $dropFolder = quotesUnescape($_POST["dropFolder"]); $file_name = getFileFromPath($dragFile); // Check if file exists if (checkFileExists("f",$file_name,$dropFolder) == 1) { recordFileError("file",tidyFolderPath($dropFolder,$file_name),$lang_file_exists); $fileExists=1; } // Check if folder exists if (checkFileExists("d",$file_name,$dropFolder) == 1) { recordFileError("folder",tidyFolderPath($dropFolder,$file_name),$lang_folder_exists); $fileExists=1; } if ($fileExists == 0) { $isError=0; if (!@ftp_rename($conn_id, $dragFile, $dropFolder."/".$file_name)) { if (checkFirstCharTilde($dragFile) == 1) { if (!@ftp_rename($conn_id, replaceTilde($dragFile), replaceTilde($dropFolder)."/".$file_name)) { recordFileError("file",getFileFromPath($dragFile),$lang_file_cant_move); $isError=1; } } else { recordFileError("file",getFileFromPath($dragFile),$lang_file_cant_move); $isError=1; } } if ($isError == 0) { // Delete item from history deleteFtpHistory($dragFile); } } } ############################################### # COPY FILES ############################################### function copyFiles() { // As there is no PHP function to copy files by FTP on a remote server, the files // need to be downloaded to the client server and then uploaded to the copy location. global $conn_id; global $serverTmp; global $lang_folder_exists; global $lang_file_exists; global $lang_server_error_down; global $lang_server_error_up; // Check for a right-clicked folder (else it's current) if (isset($_POST["rightClickFolder"])) $folderMoveTo = quotesUnescape($_POST["rightClickFolder"]); else $folderMoveTo = $_SESSION["dir_current"]; // Folders foreach ($_SESSION["clipboard_folders"] as $folder) { $folder_name = getFileFromPath($folder); $path_parts = pathinfo($folder); $dir_source = $path_parts['dirname']; // Check if folder exists if (checkFileExists("f",$folder_name,$folderMoveTo) == 1) { recordFileError("folder",tidyFolderPath($folderMoveTo,$folder_name),$lang_folder_exists); } else { copyFolder($folder_name,$folderMoveTo,$dir_source); } } // Files foreach ($_SESSION["clipboard_files"] as $file) { $isError=0; $file_name = getFileFromPath($file); $fp1 = $serverTmp."/".$file_name; $fp2 = $file; $fp3 = $folderMoveTo."/".$file_name; // Check if file exists if (checkFileExists("f",$file_name,$folderMoveTo) == 1) { recordFileError("file",tidyFolderPath($folderMoveTo,$file_name),$lang_file_exists); } else { // Download file to client server if (!@ftp_get($conn_id, $fp1, $fp2, FTP_BINARY)) { if (checkFirstCharTilde($fp2) == 1) { if (!@ftp_get($conn_id, $fp1, replaceTilde($fp2), FTP_BINARY)) { recordFileError("file",$file_name,$lang_server_error_down); $isError=1; } } else { recordFileError("file",$file_name,$lang_server_error_down); $isError=1; } } if ($isError == 0) { // Upload file to remote server if (!@ftp_put($conn_id, $fp3, $fp1, FTP_BINARY)) { if (checkFirstCharTilde($fp3) == 1) { if (!@ftp_put($conn_id, replaceTilde($fp3), $fp1, FTP_BINARY)) recordFileError("file",$file_name,$lang_server_error_up); } else { recordFileError("file",$file_name,$lang_server_error_up); } } } } // Delete tmp file unlink($fp1); } } ############################################### # GET PERMISSIONS OF FILE/FOLDER ############################################### function getPerms($folder,$file_name) { global $conn_id; $ftp_rawlist = getFtpRawList($folder); if (is_array($ftp_rawlist)) { foreach($ftp_rawlist AS $ff) { // Split up array into values $ff = preg_split("/[\s]+/",$ff,9); $perms = $ff[0]; $file = $ff[8]; if ($file == $file_name) { $perms = getChmodNumber($perms); $perms = formatChmodNumber($perms); return $perms; } } } } ############################################### # COPY FOLDERS ############################################### function copyFolder($folder,$dir_destin,$dir_source) { global $conn_id; global $serverTmp; global $lang_folder_cant_access; global $lang_folder_exists; global $lang_folder_cant_chmod; global $lang_folder_cant_make; global $lang_server_error_down; global $lang_file_cant_chmod; global $lang_chmod_no_support; $isError=0; // Check if ftp_chmod() exists if (!function_exists('ftp_chmod')) { $_SESSION["errors"][] = $lang_chmod_no_support; } // Check source folder exists if (!@ftp_chdir($conn_id, $dir_source."/".$folder)) { if (checkFirstCharTilde($dir_source) == 1) { if (!@ftp_chdir($conn_id, replaceTilde($dir_source)."/".$folder)) { recordFileError("folder",tidyFolderPath($dir_destin,$folder),$lang_folder_cant_access); $isError=1; } } else { recordFileError("folder",tidyFolderPath($dir_destin,$folder),$lang_folder_cant_access); $isError=1; } } if ($isError == 0) { // Check if destination folder exists if (checkFileExists("d",$folder,$dir_destin) == 1) { recordFileError("folder",tidyFolderPath($dir_destin,$folder),$lang_folder_exists); } else { // Create the new folder if (!@ftp_mkdir($conn_id, $dir_destin."/".$folder)) { if (checkFirstCharTilde($dir_destin) == 1) { if (!@ftp_mkdir($conn_id, replaceTilde($dir_destin)."/".$folder)) { recordFileError("folder",tidyFolderPath($dir_destin,$folder),$lang_folder_cant_make); $isError=1; } } else { recordFileError("folder",tidyFolderPath($dir_destin,$folder),$lang_folder_cant_make); $isError=1; } } } } if ($isError == 0) { // Copy permissions (Lin) if ($_SESSION["win_lin"] == "lin") { $mode = getPerms($dir_source,$folder); $lang_folder_cant_chmod = str_replace("[perms]",$mode,$lang_folder_cant_chmod); if (function_exists('ftp_chmod')) { if (!ftp_chmod($conn_id, $mode, $dir_destin."/".$folder)) { if (checkFirstCharTilde($dir_destin) == 1) { if (!@ftp_chmod($conn_id, $mode, replaceTilde($dir_destin)."/".$folder)) { recordFileError("folder",$folder,$lang_folder_cant_chmod); } } else { recordFileError("folder",$folder,$lang_folder_cant_chmod); } } } } // Go through array of files/folders $ftp_rawlist = getFtpRawList($dir_source."/".$folder); if (is_array($ftp_rawlist)) { foreach($ftp_rawlist AS $ff) { $isDir=0; $isError=0; // Split up array into values (Lin) if ($_SESSION["win_lin"] == "lin") { $ff = preg_split("/[\s]+/",$ff,9); $perms = $ff[0]; $file = $ff[8]; if (getFileType($perms) == "d") $isDir=1; } // Split up array into values (Win) if ($_SESSION["win_lin"] == "win") { $ff = preg_split("/[\s]+/",$ff,4); $size = $ff[2]; $file = $ff[3]; if ($size == "") $isDir=1; } if ($file != "." && $file != "..") { // Check for sub folders and then perform this function if (getFileType($perms) == "d") { copyFolder($file,$dir_destin."/".$folder,$dir_source."/".$folder); } else { $fp1 = $serverTmp."/".$file; $fp2 = $dir_source."/".$folder."/".$file; $fp3 = $dir_destin."/".$folder."/".$file; // Download if (!@ftp_get($conn_id, $fp1, $fp2, FTP_BINARY)) { if (checkFirstCharTilde($fp2) == 1) { if (!@ftp_get($conn_id, $fp1, replaceTilde($fp2), FTP_BINARY)) { recordFileError("file",$file,$lang_server_error_down); $isError=1; } } else { recordFileError("file",$file,$lang_server_error_down); $isError=1; } } // Upload if ($isError == 0) { if (!@ftp_put($conn_id, $fp3, $fp1, FTP_BINARY)) { if (checkFirstCharTilde($fp3) == 1) { if (!@ftp_put($conn_id, replaceTilde($fp3), $fp1, FTP_BINARY)) { recordFileError("file",$file,$lang_server_error_down); $isError=1; } } else { recordFileError("file",$file,$lang_server_error_down); $isError=1; } } } if ($isError == 0) { // Chmod files (Lin) if ($_SESSION["win_lin"] == "lin") { $perms = getChmodNumber($perms); $mode = formatChmodNumber($perms); $lang_file_cant_chmod = str_replace("[perms]",$perms,$lang_file_cant_chmod); if (function_exists('ftp_chmod')) { if (!@ftp_chmod($conn_id, $mode, $fp3)) { if (checkFirstCharTilde($fp3) == 1) { if (!@ftp_chmod($conn_id, $mode, replaceTilde($fp3))) { recordFileError("file",$file,$lang_server_error_down); } } else { recordFileError("file",$file,$lang_server_error_down); } } } } } // Delete tmp file unlink($fp1); } } } } } } ############################################### # RECREATE FOLDER & FILE ARRAYS ############################################### function recreateFileFolderArrays($type) { $arrayNew = array(); if ($_POST["fileSingle"] != "" || $_POST["folderSingle"] != "") { // Single file/folder if ($type == "file" && $_POST["fileSingle"] != "") { $file = quotesUnescape($_POST["fileSingle"]); $arrayNew[] = $file; } if ($type == "folder" && $_POST["folderSingle"] != "") $arrayNew[] = quotesUnescape($_POST["folderSingle"]); } else { // Array file/folder if ($type == "file") $array = $_POST["fileAction"]; if ($type == "folder") $array = $_POST["folderAction"]; if (is_array($array)) { foreach($array AS $file) { $file = quotesUnescape($file); if ($file != "") $arrayNew[] = $file; } } } return $arrayNew; } ############################################### # RENAME FILES ############################################### function renameFiles() { global $conn_id; global $lang_file_exists; global $lang_folder_exists; global $lang_cant_rename; global $lang_title_rename; // Check for processing of form if ($_POST["processAction"] == 1) { $i=0; // Go through array of saved names foreach ($_SESSION["clipboard_rename"] AS $file) { $isError=0; $file_name = trim($_POST["file".$i]); $file_name = quotesUnescape($file_name); $file = quotesUnescape($file); $fileExists=0; // Check for a different name if ($file_name != $file) { if ($_SESSION["dir_current"] == "/") $file_to_move = "/".$file; if ($_SESSION["dir_current"] == "~") $file_to_move = "~/".$file; if ($_SESSION["dir_current"] != "/" && $_SESSION["dir_current"] != "~") $file_to_move = $_SESSION["dir_current"]."/".$file; $file_destination = $_SESSION["dir_current"]."/".$file_name; // Check if file exists if (checkFileExists("f",$file_name,$_SESSION["dir_current"]) == 1) { recordFileError("file",sanitizeStr($file_name),$lang_file_exists); $fileExists=1; } // Check if folder exists if (checkFileExists("d",$file_name,$_SESSION["dir_current"]) == 1) { recordFileError("folder",sanitizeStr($file_name),$lang_folder_exists); $fileExists=1; } if ($fileExists == 0) { if (!@ftp_rename($conn_id, $file_to_move, $file_destination)) { if (checkFirstCharTilde($file_to_move) == 1) { if (!@ftp_rename($conn_id, replaceTilde($file_to_move), replaceTilde($file_destination))) { recordFileError("file",sanitizeStr($file),$lang_cant_rename); $isError=1; } } else { recordFileError("file",sanitizeStr($file),$lang_cant_rename); $isError=1; } } if ($isError == 0) { // Delete item from history deleteFtpHistory($file_to_move); } } } $i++; } // Reset var $_SESSION["clipboard_rename"] = array(); } else { // Recreate arrays $fileArray = recreateFileFolderArrays("file"); $folderArray = recreateFileFolderArrays("folder"); $_SESSION["clipboard_rename"] = array(); $n = sizeof($fileArray) + sizeof($folderArray); $height = $n * 35; $width = 565; $title = $lang_title_rename; // Display pop-up displayPopupOpen(1,$width,$height,0,$title); $i=0; // Set vars $vars = "&ftpAction=rename&processAction=1"; $onKeyPress = "onkeypress=\"if (event.keyCode==13){ processForm('".$vars."'); activateActionButtons(0,0); return false; }\""; // Display folders foreach($folderArray AS $folder) { $folder = getFileFromPath($folder); echo " "; echo "
"; $_SESSION["clipboard_rename"][] = $folder; $i++; } // Display files foreach($fileArray AS $file) { $file = getFileFromPath($file); echo " "; echo "
"; $_SESSION["clipboard_rename"][] = $file; $i++; } displayPopupClose(0,$vars,1); } } ############################################### # CHMOD FILES ############################################### function chmodFiles() { global $conn_id; global $lang_chmod_max_777; global $lang_file_cant_chmod; global $lang_chmod_owner; global $lang_chmod_group; global $lang_chmod_public; global $lang_chmod_manual; global $lang_title_chmod; global $lang_chmod_no_support; if (!function_exists('ftp_chmod')) { $_SESSION["errors"][] = $lang_chmod_no_support; } else { // Check for a posted form if ($_POST["processForm"] == 1) { if (trim($_POST["chmodNum"]) > 777) { $_SESSION["errors"][] = $lang_chmod_max_777; } else { $mode = formatChmodNumber($_POST["chmodNum"]); $lang_file_cant_chmod = str_replace("[perms]",$mode,$lang_file_cant_chmod); foreach($_SESSION["clipboard_chmod"] AS $file) { if (!@ftp_chmod($conn_id, $mode, $file)) { if (checkFirstCharTilde($file) == 1) { if (!@ftp_chmod($conn_id, $mode, replaceTilde($file))) { recordFileError("file",$file,$lang_file_cant_chmod); } } else { recordFileError("file",$file,$lang_file_cant_chmod); } } } } // Reset var $_SESSION["clipboard_chmod"] = array(); } else { // Recreate arrays $fileArray = recreateFileFolderArrays("file"); $folderArray = recreateFileFolderArrays("folder"); $_SESSION["clipboard_chmod"] = array(); // Count items checked $n = sizeof($fileArray) + sizeof($folderArray); // Get attributes if 1 item selected if ($n == 1) { if ($theFile == "") $theFile = $fileArray[0]; if ($theFile == "") $theFile = $folderArray[0]; $theFile = getFileFromPath($theFile); $ftp_rawlist = getFtpRawList($_SESSION["dir_current"]); // Go through array of files/folders foreach($ftp_rawlist AS $ff) { // Split up array into values $ff = preg_split("/[\s]+/",$ff,9); $perms = $ff[0]; $file = $ff[8]; // Check for a match if ($file == $theFile) { $chmod = getChmodNumber($perms); $o_wrx = substr($perms,1,3); $g_wrx = substr($perms,4,3); $p_wrx = substr($perms,7,3); } } } // Save folders foreach($folderArray AS $folder) { $_SESSION["clipboard_chmod"][] = $folder; } // Save files foreach($fileArray AS $file) { $_SESSION["clipboard_chmod"][] = $file; } $height = 335; $width = 420; $title = $lang_title_chmod; // Display pop-up displayPopupOpen(1,$width,$height,0,$title); $vars = "&ftpAction=chmod&processForm=1"; displayChmodFieldset($lang_chmod_owner,"owner",$o_wrx,$vars); displayChmodFieldset($lang_chmod_group,"group",$g_wrx,$vars); displayChmodFieldset($lang_chmod_public,"public",$p_wrx,$vars); displayChmodFieldset($lang_chmod_manual,"manual",$chmod,$vars); displayPopupClose(0,$vars,1); } } } ############################################### # FORMAT CHMOD NUMBER ############################################### function formatChmodNumber($str) { $str = trim($str); $str = octdec ( str_pad ( $str, 4, '0', STR_PAD_LEFT ) ); $str = (int) $str; return $str; } ############################################### # GET CHMOD NUMBER ############################################### function getChmodNumber($str) { $j=0; $strlen = strlen($str); for ($i=0;$i<$strlen;$i++) { if ($i>=1&&$i<=3) $m=100; if ($i>=4&&$i<=6) $m=10; if ($i>=7&&$i<=9) $m=1; $l = substr($str,$i,1); if ($l != "d" && $l != "-") { if ($l=="r") $n=4; if ($l=="w") $n=2; if ($l=="x") $n=1; $j = $j+($n*$m); } } return $j; } ############################################### # CHMOD FIELDSET ############################################### function displayChmodFieldset($title,$type,$chmod,$vars) { global $lang_chmod_read; global $lang_chmod_write; global $lang_chmod_exe; ?>
onclick="updateChmodNum(this.id,)">
onclick="updateChmodNum(this.id,)">
onclick="updateChmodNum(this.id,)">
0) { $fd = @fopen($fp1,"r"); $content = @fread($fd, filesize($fp1)); @fclose($fd); } displayEditFileForm($file,$content); } // Delete tmp file unlink($fp1); } ############################################### # EDIT FILE PROCESS (EDIT FILE) ############################################### function displayEditFileForm($file,$content) { global $lang_title_edit_file; global $lang_btn_save; global $lang_btn_close; $width = $_POST["windowWidth"] - 250; $height = $_POST["windowHeight"] - 220; $editorHeight = $height - 85; $file_display = $file; $file_display = sanitizeStr($file_display); $file_display = replaceTilde($file_display); $title = $lang_title_edit_file.": ".$file_display; // Display pop-up displayPopupOpen(0,$width,$height,0,$title); echo ""; echo ""; // Save button echo " "; // Close button echo " "; displayPopupClose(0,"",0); } ############################################### # EDIT FILE PROCESS (SAVE FILE) ############################################### // Saving the file to the iframe preserves the cursor position in the edit div. function editProcess() { global $conn_id; global $serverTmp; global $lang_server_error_up; $isError=0; // Get file contents $file = quotesUnescape($_POST["file"]); $file_name = getFileFromPath($file); $fp1 = $serverTmp."/".$file_name; $fp2 = $file; $editContent = $_POST["editContent"]; // Write content to a file $tmpFile = @fopen($fp1,"w+"); @fputs($tmpFile,$editContent); @fclose($tmpFile); if (!@ftp_put($conn_id, $fp2, $fp1, FTP_BINARY)) { if (checkFirstCharTilde($fp2) == 1) { if (!@ftp_put($conn_id, replaceTilde($fp2), $fp1, FTP_BINARY)) { recordFileError("file",$file_name,$lang_server_error_up); } } else { recordFileError("file",$file_name,$lang_server_error_up); } } // Delete tmp file unlink($fp1); } ############################################### # DOWNLOAD FILE ############################################### function downloadFile() { global $conn_id; global $serverTmp; global $lang_server_error_down; $isError=0; $file = quotesUnescape($_GET["dl"]); $file_name = getFileFromPath($file); $fp1 = $serverTmp."/".$file_name; $fp2 = $file; // Download the file if (!@ftp_get($conn_id, $fp1, $fp2, FTP_BINARY)) { if (checkFirstCharTilde($fp2) == 1) { if (!@ftp_get($conn_id, $fp1, replaceTilde($fp2), FTP_BINARY)) { recordFileError("file",quotesEscape($file,"s"),$lang_server_error_down); $isError=1; } } else { recordFileError("file",quotesEscape($file,"s"),$lang_server_error_down); $isError=1; } } if ($isError == 0) { header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".quotesEscape($file_name,"d")."\""); // quotes required for spacing in filename header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Description: File Transfer"); header("Content-Length: ".filesize($fp1)); flush(); $fp = @fopen($fp1, "r"); while (!feof($fp)) { echo @fread($fp, 65536); @flush(); } @fclose($fp); } // Delete tmp file unlink($fp1); } ############################################### # UNESCAPE QUOTES ############################################### function quotesUnescape($str) { $str = str_replace("\'","'",$str); $str = str_replace('\"','"',$str); return $str; } ############################################### # ESCAPE QUOTES ############################################### function quotesEscape($str,$type) { if ($type == "s" || $type == "") $str = str_replace("'","\'",$str); if ($type == "d" || $type == "") $str = str_replace('"','\"',$str); return $str; } ############################################### # REPLACE QUOTES ############################################### function quotesReplace($str,$type) { $str = quotesUnescape($str); if ($type == "s") $str = str_replace("'","´",$str); if ($type == "d") $str = str_replace('"','"',$str); return $str; } ############################################### # SANITIZE VARS (DEPRECATED) ############################################### /* function sanitizeVars() { foreach($_POST AS $key => $value) { if ($key != "editContent") { $value = str_replace("<","<",$value); $value = str_replace(">",">",$value); $_POST[$key] = $value; } } foreach($_GET AS $key => $value) { if ($key != "editContent") { $value = str_replace("<","<",$value); $value = str_replace(">",">",$value); $_POST[$key] = $value; } } } */ ############################################### # DELETE FILES & FOLDERS ############################################### function deleteFiles () { global $conn_id; global $lang_file_doesnt_exist; global $lang_cant_delete; $folderArray = recreateFileFolderArrays("folder"); $fileArray = recreateFileFolderArrays("file"); // folders foreach($folderArray AS $folder) { $folder = getFileFromPath($folder); deleteFolder($folder,$_SESSION["dir_current"]); } // files foreach($fileArray AS $file) { $isError=0; $file_decoded = urldecode($file); if ($file != "") { // Check if file exists if (checkFileExists("f",$file,$_SESSION["dir_current"]) == 1) { recordFileError("file",$file,$lang_file_doesnt_exist); } else { if (!@ftp_delete($conn_id, $file_decoded)) { if (checkFirstCharTilde($file_decoded) == 1) { if (!@ftp_delete($conn_id, replaceTilde($file_decoded))) { $isError=1; } } else { $isError=1; } } // If deleting decoded file fails, try original file name if ($isError == 1) { if (!@ftp_delete($conn_id, "".$file."")) { if (checkFirstCharTilde($file) == 1) { if (!@ftp_delete($conn_id, "".replaceTilde($file)."")) { recordFileError("file",getFileFromPath($file),$lang_cant_delete); } } else { recordFileError("file",getFileFromPath($file),$lang_cant_delete); } } } } } } } ############################################### # DELETE FOLDER ############################################### function deleteFolder($folder,$path) { global $conn_id; global $lang_cant_delete; global $lang_folder_doesnt_exist; global $lang_folder_cant_delete; $isError=0; // List contents of folder if ($path != "/" && $path != "~") { $folder_path = $path."/".$folder; } else { if ($_SESSION["win_lin"] == "lin") if ($_SESSION["dir_current"] == "/") $folder_path = "/".$folder; if ($_SESSION["dir_current"] == "~") $folder_path = "~/".$folder; if ($_SESSION["win_lin"] == "win") $folder_path = "/".$folder; } $ftp_rawlist = getFtpRawList($folder_path); // Go through array of files/folders if (sizeof($ftp_rawlist) > 0) { foreach($ftp_rawlist AS $ff) { // Split up array into values (Lin) if ($_SESSION["win_lin"] == "lin") { $ff = preg_split("/[\s]+/",$ff,9); $perms = $ff[0]; $file = $ff[8]; if (getFileType($perms) == "d") $isFolder=1; else $isFolder=0; } // Split up array into values (Win) if ($_SESSION["win_lin"] == "win") { $ff = preg_split("/[\s]+/",$ff,4); $size = $ff[2]; $file = $ff[3]; if ($size == "") $isFolder=1; else $isFolder=0; } if ($file != "." && $file != "..") { // Check for sub folders and then perform this function if ($isFolder == 1) { deleteFolder($file,$folder_path); } else { // otherwise delete file $file_path = $folder_path."/".$file; if (!@ftp_delete($conn_id, "".$file_path."")) { if (checkFirstCharTilde($file_path) == 1) { if (!@ftp_delete($conn_id, "".replaceTilde($file_path)."")) { recordFileError("file",$file_path,$lang_cant_delete); } } else { recordFileError("file",$file_path,$lang_cant_delete); } } } } } } // Check if file exists if (checkFileExists("d",$folder,$folder_path) == 1) { $_SESSION["errors"][] = str_replace("[file]","".tidyFolderPath($folder_path,$folder)."",$lang_folder_doesnt_exist); } else { // Chage dir up before deleting ftp_cdup($conn_id); // Delete the empty folder if (!@ftp_rmdir($conn_id, "".$folder_path."")) { if (checkFirstCharTilde($folder_path) == 1) { if (!@ftp_rmdir($conn_id, "".replaceTilde($folder_path)."")) { recordFileError("folder",$folder_path,$lang_folder_cant_delete); $isError=1; } } else { recordFileError("folder",$folder_path,$lang_folder_cant_delete); $isError=1; } } // Remove directory from history if ($isError == 0) deleteFtpHistory($folder_path); } } ############################################### # NEW FILE ############################################### function newFile() { global $conn_id; global $serverTmp; global $lang_title_new_file; global $lang_new_file_name; global $lang_template; global $lang_no_template; global $lang_file_exists; global $lang_file_cant_make; $isError=0; // Set vars $vars = "&ftpAction=newFile"; // Display templates $templates_dir = "templates"; $file_name = trim(quotesUnescape($_POST["newFile"])); if ($file_name == "") { $title = $lang_title_new_file; $width = 400; $height = 95; // Display pop-up displayPopupOpen(0,$width,$height,0,$title); echo ""; if (is_dir($templates_dir)) { if ($dh = opendir($templates_dir)) { $i=0; while (($file = readdir($dh)) !== false) { if ($file != "" && $file != "." && $file != ".." && $file != "index.html") { $file_name = $file; $template_found=1; $langs .= ""; } } closedir($dh); } } echo "

".$lang_template.": "; echo ""; displayPopupClose(0,$vars,1); } else { $fp1 = $serverTmp."/".$file_name; if ($_SESSION["dir_current"] == "/") $fp2 = "/".$file_name; else $fp2 = $_SESSION["dir_current"]."/".$file_name; // Check if file already exists if (checkFileExists("f",$file_name,$_SESSION["dir_current"]) == 1) { recordFileError("file",$file_name,$lang_file_exists); } else { // Get template if ($_POST["template"] != $lang_no_template) { $file_name = $templates_dir."/".$_POST["template"]; $fd = @fopen($file_name,"r"); $content = @fread($fd,filesize($file_name)); @fclose($fd); } // Write file to server $tmpFile = @fopen($fp1,"w+"); @fputs($tmpFile,$content); @fclose($tmpFile); // Upload the file if (!@ftp_put($conn_id, $fp2, $fp1, FTP_BINARY)) { if (checkFirstCharTilde($fp2) == 1) { if (!@ftp_put($conn_id, replaceTilde($fp2), $fp1, FTP_BINARY)) { recordFileError("file",$file_name,$lang_file_cant_make); $isError=1; } } else { recordFileError("file",$file_name,$lang_file_cant_make); $isError=1; } } if ($isError == 0) { // Open editor $file = $fp2; displayEditFileForm($file,$content); } } // Delete tmp file unlink($fp1); } } ############################################### # CHECK IF FILE EXISTS ############################################### function checkFileExists($type,$file_name,$folder_path) { $ftp_rawlist = getFtpRawList($folder_path); if (is_array($ftp_rawlist)) { $fileNameAr = array(); // Go through array of files/folders foreach($ftp_rawlist AS $ff) { // Lin if ($_SESSION["win_lin"] == "lin") { // Split up array into values $ff = preg_split("/[\s]+/",$ff,9); $perms = $ff[0]; $file = $ff[8]; if ($file != "." && $file != "..") { if ($type == "f" && getFileType($perms) == "f") $fileNameAr[] = $file; if ($type == "d" && getFileType($perms) == "d") $fileNameAr[] = $file; } } // Win if ($_SESSION["win_lin"] == "win") { // Split up array into values $ff = preg_split("/[\s]+/",$ff,4); $size = $ff[2]; $file = $ff[3]; if ($size == "

") $size = "d"; if ($type == "d" && $size == "d") $fileNameAr[] = $file; if ($type == "f" && $size != "d") $fileNameAr[] = $file; } } // Check if file is in array if (in_array($file_name,$fileNameAr)) return 1; } else { return 0; } } ############################################### # NEW FOLDER ############################################### function newFolder() { global $conn_id; global $lang_title_new_folder; global $lang_new_folder_name; global $lang_folder_exists; global $lang_folder_cant_make; // Set vars $vars = "&ftpAction=newFolder"; $folder = trim(quotesUnescape($_POST["newFolder"])); if ($folder == "") { $title = $lang_title_new_folder; $width = 400; $height = 40; // Display pop-up displayPopupOpen(0,$width,$height,0,$title); echo ""; displayPopupClose(0,$vars,1); } else { // Check if folder exists if (checkFileExists("d",$folder,$_SESSION["dir_current"]) == 1 || $folder == "..") { recordFileError("folder",$folder,$lang_folder_exists); } else { if (!@ftp_mkdir($conn_id, $folder)) recordFileError("folder",$folder,$lang_folder_cant_make); } } } ############################################### # UPLOAD FILE ############################################### function uploadFile() { global $conn_id; global $serverTmp; global $lang_server_error_up; global $lang_browser_error_up; $file_name = $_SERVER['HTTP_X_FILENAME']; $path = $_GET["filePath"]; if ($file_name) { $fp1 = $serverTmp."/".$file_name; // Check if a folder is being uploaded if ($path != "") { // Check to see folder path exists (and create) createFolderHeirarchy($path); $fp2 = $_SESSION["dir_current"]."/".$path.$file_name; } else { if ($_SESSION["dir_current"] == "/") $fp2 = "/".$file_name; else $fp2 = $_SESSION["dir_current"]."/".$file_name; } // Check if file reached server if (file_put_contents($fp1,file_get_contents('php://input'))) { if (!@ftp_put($conn_id, $fp2, $fp1, FTP_BINARY)) { if (checkFirstCharTilde($fp2) == 1) { if (!@ftp_put($conn_id, replaceTilde($fp2), $fp1, FTP_BINARY)) { recordFileError("file",$file_name,$lang_server_error_up); } } else { recordFileError("file",$file_name,$lang_server_error_up); } } } else { recordFileError("file",$file_name,$lang_browser_error_up); } // Delete tmp file unlink($fp1); } } ############################################### # CREATE FOLDER HEIRARCHY ############################################### function createFolderHeirarchy($path) { global $conn_id; global $lang_folder_cant_make; $folderAr = explode("/",$path); $n = sizeof($folderAr); for ($i=0;$i<$n;$i++) { if ($folder == "") $folder = $folderAr[$i]; else $folder = $folder."/".$folderAr[$i]; if (!@ftp_mkdir($conn_id, $folder)) { if (checkFirstCharTilde($folder) == 1) @ftp_mkdir($conn_id, replaceTilde($folder)); } } } ############################################### # UPLOAD FILE (IFRAME) ############################################### function iframeUpload() { global $conn_id; global $lang_server_error_up; global $lang_browser_error_up; $fp1 = $_FILES["uploadFile"]["tmp_name"]; $fp2 = $_SESSION["dir_current"]."/".$_FILES["uploadFile"]["name"]; if ($fp1 != "") { if (!@ftp_put($conn_id, $fp2, $fp1, FTP_BINARY)) { if (checkFirstCharTilde($fp2) == 1) { if (!@ftp_put($conn_id, replaceTilde($fp2), $fp1, FTP_BINARY)) { recordFileError("file",$file_name,$lang_server_error_up); } } else { recordFileError("file",$file_name,$lang_server_error_up); } } } else { recordFileError("file",$file_name,$lang_browser_error_up); } } ############################################### # DELETE FTP HISTORY ############################################### function deleteFtpHistory($dirDelete) { $dirDelete = str_replace("/","\/",$dirDelete); // Check each item in the history if (is_array($_SESSION["dir_history"])) { foreach($_SESSION["dir_history"] AS $dir) { if (!@preg_match("/^".$dirDelete."/", $dir)) $dir_history[] = $dir; } // Set new array $_SESSION["dir_history"] = $dir_history; // Sort array if (is_array($_SESSION["dir_history"])) asort($_SESSION["dir_history"]); } } ############################################### # SINGLE QUOTE ESCAPE ############################################### function singleQuoteEscape($str) { return str_replace("'","\'",$str); } ############################################### # GET FILE TYPE ############################################### function getFileType($perms) { if (substr($perms,0,1) == "d") return "d"; // directory if (substr($perms,0,1) == "l") return "l"; // link if (substr($perms,0,1) == "-") return "f"; // file } ############################################### # DISPLAY AJAX DIV OPEN ############################################### function displayAjaxDivOpen() { ?>
0) { $width = (getMaxStrLen($_SESSION["errors"]) * 10) + 30; $height = sizeof($_SESSION["errors"]) * 25; $title = $lang_title_errors; // Display pop-up displayPopupOpen(1,$width,$height,1,$title); $errors = array_reverse($_SESSION["errors"]); foreach($errors AS $error) { echo $error."
"; } $vars = "&ftpAction=openFolder&resetErrorArray=1"; displayPopupClose(1,$vars,0); } } //############################################## // DISPLAY POP-UP FRAME OPEN //############################################## function displayPopupOpen($resize,$width,$height,$isError,$title) { // Set default sizes of exceeded if ($resize == 1) { if ($width < 400) $width = 400; if ($height > 400) $height = 400; } $windowWidth = $_POST["windowWidth"]; $windowHeight = $_POST["windowHeight"]; // Center window if ($windowWidth > 0) $left = round(($windowWidth - $width) / 2 - 15); // -15 for H padding else $left = 250; if ($windowHeight > 0) $top = round(($_POST["windowHeight"] - $height) / 2 - 50); else $top = 250; echo "
"; echo "
"; if ($isError == 1) $divId = "popupHeaderError"; else $divId = "popupHeaderAction"; echo "
"; echo $title; echo "
"; if ($isError == 1) $divId = "popupBodyError"; else $divId = "popupBodyAction"; echo "
"; } //############################################## // DISPLAY POP-UP FRAME CLOSE //############################################## function displayPopupClose($isError,$vars,$btnCancel) { global $lang_btn_ok; global $lang_btn_cancel; echo "
"; if ($isError == 1) $divId = "popupFooterError"; else $divId = "popupFooterAction"; echo "
"; // OK button if ($vars != "") echo " "; // Cancel button if ($btnCancel == 1) echo " "; echo "
"; echo "
"; echo "
"; } //############################################## // GET MAX STR LENGTH FROM ARRAY //############################################## function getMaxStrLen($array) { foreach ($array AS $str) { $thisLen = strlen($str); if ($thisLen > $maxLen) $maxLen = $thisLen; } return $maxLen; } //############################################## // GET FILE/FOLDER NAME //############################################## function getFileFromPath($str) { $str = preg_replace("/^(.)+\//","",$str); $str = preg_replace("/^~/","",$str); return $str; } //############################################## // PARENT OPEN FOLDER //############################################## function parentOpenFolder() { ?> "; $skins .= preg_replace("/\..*$/","",$file_name); $skins .= ""; $skinsAr[] = $skins; } } closedir($dh); if ($skin_found == 0) { echo "

".$lang_skin.": "; echo str_replace("[skins]","skins", $lang_skins_empty); } else { if ($i > 1) { sort($skinsAr); echo "

".$lang_skin.": "; echo ""; } else { echo ""; } } } else { echo "

".$lang_skin.": "; echo str_replace("[skins]","skins", $lang_skins_locked); } } else { echo "

".$lang_skin.": "; echo str_replace("[skins]","skins", $lang_skins_missing); } } //############################################## // DISPLAY LANGUAGE SELECT //############################################## function displayLangSelect($lang) { global $lang_language; $dir = "languages"; $lang_found=0; if (is_dir($dir)) { if ($dh = opendir($dir)) { $i=0; while (($file = readdir($dh)) !== false) { if ($file != "" && $file != "." && $file != ".." && $file != "index.html") { $i++; $file_name = $file; // Open file to get language name include($dir."/".$file_name); $lang_found=1; // Strip extension $file_name = preg_replace("/\..*$/","",$file_name); $langs = "