From bc589549f374052798cb4fa92b38e34f73d8c9ab Mon Sep 17 00:00:00 2001 From: mattpass Date: Wed, 30 Dec 2020 14:57:37 +0000 Subject: [PATCH] Remove FTP functionality & UI from ICEcoder --- assets/css/ftp-manager.css | 16 --- assets/js/icecoder.js | 15 --- classes/Backup.php | 4 +- classes/FTP.php | 188 ----------------------------- classes/File.php | 60 +++------- index.php | 11 -- lang/chinese-simplified.php | 32 ----- lang/chinese-traditional.php | 32 ----- lang/dutch.php | 32 ----- lang/english.php | 32 ----- lang/french.php | 32 ----- lang/german.php | 32 ----- lang/italian.php | 32 ----- lang/norwegian.php | 32 ----- lang/persian.php | 32 ----- lang/portuguese-brazilian.php | 32 ----- lang/spanish.php | 32 ----- lib/backup-versions.php | 2 +- lib/file-control.php | 177 +++++++--------------------- lib/ftp-manager.php | 215 ---------------------------------- lib/get-branch.php | 65 ++-------- lib/go-localhost-root.php | 36 ------ lib/icecoder.php | 1 - lib/settings-common.php | 14 +-- lib/settings-screen.php | 2 +- lib/settings-update.php | 1 - lib/settings.php | 12 -- lib/template-config-users.php | 2 +- 28 files changed, 77 insertions(+), 1096 deletions(-) delete mode 100644 assets/css/ftp-manager.css delete mode 100644 classes/FTP.php delete mode 100644 lib/ftp-manager.php delete mode 100644 lib/go-localhost-root.php diff --git a/assets/css/ftp-manager.css b/assets/css/ftp-manager.css deleted file mode 100644 index c44357f..0000000 --- a/assets/css/ftp-manager.css +++ /dev/null @@ -1,16 +0,0 @@ -body {overflow: hidden; - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; -} - -h1 {font-size: 36px; font-weight: normal; color: #888; margin-bottom: 20px} -a {color: #2187e7; text-decoration: none} -input {padding: 4px; border: 0; background-color: #444; color: #fff} -select {padding: 3px 4px; border: 0; background-color: #444; color: #fff} -input:focus {outline: none; background: rgba(0,198,255,0.5); color: #fff} -select:focus {outline: none} - -.ftpManager {background-color: #1c1c19; color: #fff; padding: 20px} -.ftpManager .info {font-size: 10px; color: rgba(0,198,255,0.7); cursor: help} \ No newline at end of file diff --git a/assets/js/icecoder.js b/assets/js/icecoder.js index 32815f5..23cf5c8 100644 --- a/assets/js/icecoder.js +++ b/assets/js/icecoder.js @@ -3672,21 +3672,6 @@ var ICEcoder = { this.showHide('show', get('blackMask')); }, - // Go to localhost root - goLocalhostRoot: function() { - this.filesFrame.contentWindow.frames['fileControl'].location.href = - this.iceLoc + - "/lib/go-localhost-root.php"; - }, - - // Show the FTP manager - ftpManager: function() { - get('mediaContainer').innerHTML = ''; - this.showHide('show', get('blackMask')); - }, - // Update the settings used when we make a change to them useNewSettings: function(settings) { let styleNode, thisCSS, strCSS, activeLineBG; diff --git a/classes/Backup.php b/classes/Backup.php index 59c2102..f168e02 100644 --- a/classes/Backup.php +++ b/classes/Backup.php @@ -14,13 +14,13 @@ class Backup } public function makeBackup($fileLoc, $fileName, $contents) { - global $ftpSite, $t, $ICEcoder; + global $t, $ICEcoder; $backupDirFormat = "Y-m-d"; // Establish the base, host and date dir parts... $backupDirBase = str_replace("\\", "/", dirname(__FILE__)) . "/../data/backups/"; - $backupDirHost = isset($ftpSite) ? parse_url($ftpSite, PHP_URL_HOST) : "localhost"; + $backupDirHost = "localhost"; $backupDirDate = date($backupDirFormat); // Establish an array of dirs from base to our file location diff --git a/classes/FTP.php b/classes/FTP.php deleted file mode 100644 index cef29c5..0000000 --- a/classes/FTP.php +++ /dev/null @@ -1,188 +0,0 @@ -systemClass = new System(); - } - - public function writeFile() { - global $fileLoc, $fileName, $ftpConn, $ftpRoot, $ftpHost, $ftpMode, $ICEcoder, $doNext, $filemtime, $tabNum; - - $ftpFilepath = ltrim($fileLoc . "/" . $fileName, "/"); - if (isset($_POST['changes'])) { - // Get existing file contents as lines - $loadedFile = toUTF8noBOM($this->ftpGetContents($ftpConn, $ftpRoot . $fileLoc . "/" . $fileName, $ftpMode), false); - $fileLines = explode("\n", str_replace("\r", "", $loadedFile)); - // Need to add a new line at the end of each because explode will lose them, - // want want to end up with same array that 'file($file)' produces for a local file - // - it keeps the line endings at the end of each array item - for ($i = 0; $i < count($fileLines); $i++) { - if ($i < count($fileLines) - 1) { - $fileLines[$i] .= $ICEcoder["lineEnding"]; - } - } - // Stitch changes onto it - $contents = $this->systemClass->stitchChanges($fileLines, $_POST['changes']); - - // get old file contents and count stats on usage \n and \r there - // in this case we can keep line endings, which file had before, without - // making code version control systems going crazy about line endings change in whole file. - $unixNewLines = preg_match_all('/[^\r][\n]/u', $loadedFile); - $windowsNewLines = preg_match_all('/[\r][\n]/u', $loadedFile); - } else { - $contents = $_POST['contents']; - } - - // replace \r\n (Windows), \r (old Mac) and \n (Linux) line endings with whatever we chose to be lineEnding - $contents = str_replace("\r\n", $ICEcoder["lineEnding"], $contents); - $contents = str_replace("\r", $ICEcoder["lineEnding"], $contents); - $contents = str_replace("\n", $ICEcoder["lineEnding"], $contents); - if (isset($_POST['changes']) && ($unixNewLines > 0) || ($windowsNewLines > 0)) { - if ($unixNewLines > $windowsNewLines){ - $contents = str_replace($ICEcoder["lineEnding"], "\n", $contents); - } elseif ($windowsNewLines > $unixNewLines){ - $contents = str_replace($ICEcoder["lineEnding"], "\r\n", $contents); - } - } - // Write our file contents - if (!$this->ftpWriteFile($ftpConn, $ftpFilepath, $contents, $ftpMode)) { - $doNext .= 'ICEcoder.message("Sorry, could not write ' . $ftpFilepath . ' at ' . $ftpHost . '");'; - } else { - $doNext .= 'ICEcoder.openFileMDTs[' . ($tabNum - 1) .']="' . $filemtime . '";'; - $doNext .= '(function() {var x = ICEcoder.openFileVersions; var y = ' . ($tabNum - 1) .'; x[y] = "undefined" != typeof x[y] ? x[y] + 1 : 1})(); ICEcoder.updateVersionsDisplay();'; - } - } - - // Start a FTP connection - function ftpStart() - { - global $ftpConn, $ftpLogin, $ftpHost, $ftpUser, $ftpPass, $ftpPasv; - - // Establish connection, login and maybe use pasv - $ftpConn = ftp_connect($ftpHost); - $ftpLogin = ftp_login($ftpConn, $ftpUser, $ftpPass); - if ($ftpPasv) { - ftp_pasv($ftpConn, true); - } - } - - // End a FTP connection - function ftpEnd() - { - global $ftpConn; - - ftp_close($ftpConn); - } - - // Get dir/file lists (simple and detailed) from FTP detailed rawlist response - function ftpGetList($ftpConn, $directory = '.') - { - $simpleList = $detailedList = array(); - // If we have a FTP rawlist to work with - if (is_array($rows = @ftp_rawlist($ftpConn, $directory))) { - foreach ($rows as $row) { - // Split row up by spaces and set keys on $item array - $chunks = preg_split("/\s+/", $row); - list($item['rights'], $item['number'], $item['user'], $item['group'], $item['size'], $item['month'], $item['day'], $item['time']) = $chunks; - // Also set if this is a dir or file - $item['type'] = $chunks[0][0] === 'd' ? 'directory' : 'file'; - // Splice the array and finally work out $simpleList and $detailedList - array_splice($chunks, 0, 8); - $detailedList[implode(" ", $chunks)] = $item; - $simpleList[] = implode(" ", $chunks); - } - // Return simple array list and detailed items list also - return array('simpleList' => $simpleList, 'detailedList' => $detailedList); - } - return false; - } - - // Get detailed info on a file from returned info from ftpGetList - function ftpGetFileInfo($ftpConn, $directory = '.', $fileName) - { - // Get both sets of arrays back and get our detailed list - $ftpListArrays = $this->ftpGetList($ftpConn, $directory); - $detailedList = $ftpListArrays['detailedList']; - - // Now get the file info for our file - $fileInfo = $detailedList[$fileName]; - - // Return the info - return $fileInfo; - } - - // Get contents over FTP - function ftpGetContents($ftpConn, $filepath, $ftpMode) - { - // Create temp handler, this type needed for extended char set - $tempHandle = fopen('php://temp', 'r+'); - - // Get file from FTP assuming that it exists - ftp_fget($ftpConn, $tempHandle, $filepath, $ftpMode, 0); - - // Return our content - return stream_get_contents($tempHandle, -1, 0); - } - - // Write file contents over FTP - function ftpWriteFile($ftpConn, $filepath, $contents, $ftpMode) - { - // Create temp handler, this type needed for extended char set - $tempHandle = fopen('php://temp', 'r+'); - - // Write contents to handle and rewind head - fwrite($tempHandle, $contents); - rewind($tempHandle); - - // Write our content and return true/false - return ftp_fput($ftpConn, $filepath, $tempHandle, $ftpMode, 0); - } - - // Make a new dir over FTP - function ftpMkDir($ftpConn, $perms, $dir) - { - // Create the new dir - if (!ftp_mkdir($ftpConn, $dir)) { - return false; - } else { - // Also then set perms (we must be able to do that if we created dir, so can always return true) - $this->ftpPerms($ftpConn, $perms, $dir); - return true; - } - } - - // Rename a dir/dile over FTP - function ftpRename($ftpConn, $oldPath, $newPath) - { - // Return success status of rename - return ftp_rename($ftpConn, $oldPath, $newPath); - } - - // Change dir/file perms over FTP - function ftpPerms($ftpConn, $perms, $filePath) - { - // Return success status of perms change - return ftp_chmod($ftpConn, $perms, $filePath); - } - - // Delete dir/file over FTP - function ftpDelete($ftpConn, $type, $path) - { - if ($type == "file") { - // Delete our file and return true/false - return ftp_delete($ftpConn, $path); - } else { - // Delete our dir and return true/false - return ftp_rmdir($ftpConn, $path); - } - } - -} diff --git a/classes/File.php b/classes/File.php index 9053c93..efc909e 100644 --- a/classes/File.php +++ b/classes/File.php @@ -4,19 +4,16 @@ namespace ICEcoder; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; -use ICEcoder\FTP; use ICEcoder\System; use scssc; use lessc; class File { - private $ftpClass; private $systemClass; public function __construct() { - $this->ftpClass = new FTP(); $this->systemClass = new System(); } @@ -67,7 +64,7 @@ class File // On the banned file/dir list ($bannedFileFound) || // A local folder that isn't the doc root or starts with the doc root - ("getRemoteFile" !== $_GET['action'] && !isset($ftpSite) && + ("getRemoteFile" !== $_GET['action'] && rtrim($allFiles[$i], "/") !== rtrim($docRoot, "/") && true === realpath(rtrim(dirname($allFiles[$i]), "/")) && 0 !== strpos(realpath(rtrim(dirname($allFiles[$i]), "/")), realpath(rtrim($docRoot, "/"))) @@ -111,7 +108,7 @@ class File } public function load() { - global $file, $fileLoc, $fileName, $t, $ftpConn, $ftpHost, $ftpLogin, $ftpRoot, $ftpUser, $ftpMode; + global $file, $fileLoc, $fileName, $t; echo 'action="load";'; $lineNumber = max(isset($_REQUEST['lineNumber']) ? intval($_REQUEST['lineNumber']) : 1, 1); // Check this file isn't on the banned list at all @@ -124,10 +121,10 @@ class File if (false === $canOpen) { echo 'fileType="nothing"; parent.parent.ICEcoder.message(\'' . $t['Sorry, could not...'] . ' ' . $fileLoc . "/" . $fileName . '\');'; - } elseif (isset($ftpSite) || file_exists($file)) { + } elseif (file_exists($file)) { $finfo = "text"; // Determine what to do based on mime type - if (!isset($ftpSite) && function_exists('finfo_open')) { + if (function_exists('finfo_open')) { $finfoMIME = finfo_open(FILEINFO_MIME); $finfo = finfo_file($finfoMIME, $file); finfo_close($finfoMIME); @@ -144,20 +141,9 @@ class File if (0 === strpos($finfo, "text") || 0 === strpos($finfo, "application/json") || 0 === strpos($finfo, "application/xml") || false !== strpos($finfo, "empty")) { echo 'fileType="text";'; - // Get file over FTP? - if (isset($ftpSite)) { - $this->ftpClass->ftpStart(); - // Show user warning if no good connection - if (!$ftpConn || !$ftpLogin) { - die('parent.parent.ICEcoder.message("Sorry, no FTP connection to ' . $ftpHost . ' for user ' . $ftpUser . '");parent.parent.ICEcoder.serverMessage();parent.parent.ICEcoder.serverQueue("del");'); - } - // Get our file contents and close the FTP connection - $loadedFile = toUTF8noBOM($this->ftpClass->ftpGetContents($ftpConn, $ftpRoot . $fileLoc . "/" . $fileName, $ftpMode), false); - $this->ftpClass->ftpEnd(); - // Get local file - } else { - $loadedFile = toUTF8noBOM(getData($file), true); - } + // Get data from file + $loadedFile = toUTF8noBOM(getData($file), true); + $encoding = ini_get("default_charset"); if ("" == $encoding) { $encoding = "UTF-8"; @@ -186,7 +172,7 @@ class File $script = 'if ("text" === fileType) {'; - if (isset($ftpSite) || file_exists($file)) { + if (file_exists($file)) { $script .= ' setTimeout(function() { if (!parent.parent.ICEcoder.content.contentWindow.createNewCMInstance) { @@ -247,7 +233,7 @@ class File parent.parent.document.getElementById(\'blackMask\').style.visibility = "visible"; parent.parent.document.getElementById(\'mediaContainer\').innerHTML = "" + - " 700 || this.naturalHeight > 500) ? \', ' .$t['displayed at'] . '\' + this.width + \' x \' + this.height : \'\'; document.getElementById(\'imgInfo\').innerHTML += \' (\' + this.naturalWidth + \' x \' + this.naturalHeight + reducedImgMsg + \')\'; ICEcoder.initCanvasImage(this); ICEcoder.interactCanvasImage(this)\">
" + + " 700 || this.naturalHeight > 500) ? \', ' .$t['displayed at'] . '\' + this.width + \' x \' + this.height : \'\'; document.getElementById(\'imgInfo\').innerHTML += \' (\' + this.naturalWidth + \' x \' + this.naturalHeight + reducedImgMsg + \')\'; ICEcoder.initCanvasImage(this); ICEcoder.interactCanvasImage(this)\">
" + "
" + "' . $fileLoc . "/" . $fileName . '" + "

" + @@ -273,7 +259,6 @@ class File $fileName = $fileDetails['fileName']; $fileMDTURLPart = $fileDetails['fileMDTURLPart']; $fileVersionURLPart = $fileDetails['fileVersionURLPart']; - $ftpSite = $fileDetails['ftpSite']; $doNext = ' ICEcoder.serverMessage(); @@ -300,7 +285,7 @@ class File /* Saving under conditions: Confirmation of overwrite or there is no filename conflict, it is a new file, in either case we can save */ if (overwriteOK || noConflictSave) { - newFileName = "' . (true === $ftpSite ? "" : $docRoot) . '" + newFileName; + newFileName = "' . $docRoot . '" + newFileName; saveURL = "lib/file-control.php?action=save' . $fileMDTURLPart . $fileVersionURLPart . '&csrf=' . $_GET["csrf"] . '"; var xhr = ICEcoder.xhrObj(); @@ -721,26 +706,13 @@ class File } public function returnJSON() { - global $ftpSite, $ftpConn, $fileLoc, $fileName, $ftpRoot, $file, $filemtime, $finalAction, $timeStart, $error, $errorStr, $errorMsg, $doNext; + global $fileLoc, $fileName, $file, $filemtime, $finalAction, $timeStart, $error, $errorStr, $errorMsg, $doNext; - if (isset($ftpSite)) { - // Get info on dir/file now - $ftpFileDirInfo = $this->ftpClass->ftpGetFileInfo($ftpConn, ltrim($fileLoc, "/"), $fileName); - // End the connection - $this->ftpClass->ftpEnd(); - // Then set info - $itemAbsPath = $ftpRoot . $fileLoc . '/' . $fileName; - $itemPath = dirname($ftpRoot.$fileLoc . '/' . $fileName); - $itemBytes = $ftpFileDirInfo['size']; - $itemType = (isset($ftpFileDirInfo['type']) ? ("directory" === $ftpFileDirInfo['type'] ? "dir" : "file") : "unknown"); - $itemExists = (isset($ftpFileDirInfo['type']) ? "true" : "false"); - } else { - $itemAbsPath = $file; - $itemPath = dirname($file); - $itemBytes = is_dir($file) || !file_exists($file) ? null : filesize($file); - $itemType = (file_exists($file) ? (is_dir($file) ? "dir" : "file") : "unknown"); - $itemExists = (file_exists($file) ? "true" : "false"); - } + $itemAbsPath = $file; + $itemPath = dirname($file); + $itemBytes = is_dir($file) || !file_exists($file) ? null : filesize($file); + $itemType = (file_exists($file) ? (is_dir($file) ? "dir" : "file") : "unknown"); + $itemExists = (file_exists($file) ? "true" : "false"); return '{ "file": { diff --git a/index.php b/index.php index 3c2fe5c..8f9b204 100644 --- a/index.php +++ b/index.php @@ -275,17 +275,6 @@ if (true === $havePrettier && true === file_exists(dirname(__FILE__) . "/plugins
  • Plugins
  • -