diff --git a/src/Core/System/Storage.php b/src/Core/System/Storage.php index 1d61439da..206073c1b 100644 --- a/src/Core/System/Storage.php +++ b/src/Core/System/Storage.php @@ -172,147 +172,6 @@ public function copyMohFilesToStorage(): void } } - /** - * Mount an SFTP disk. - * - * @param string $host The SFTP server host. - * @param string $port The SFTP server port. - * @param string $user The SFTP server username. - * @param string $pass The SFTP server password. - * @param string $remote_dir The remote directory on the SFTP server. - * @param string $local_dir The local directory to mount the SFTP disk. - * @return bool Returns true if the SFTP disk is successfully mounted, false otherwise. - */ - public static function mountSftpDisk(string $host, string $port, string $user, string $pass, string $remote_dir, string $local_dir): bool - { - - // Create the local directory if it doesn't exist - Util::mwMkdir($local_dir); - - $out = []; - $timeoutPath = Util::which('timeout'); - $sshfsPath = Util::which('sshfs'); - - // Build the command to mount the SFTP disk - $command = "$timeoutPath 3 $sshfsPath -p $port -o nonempty -o password_stdin -o 'StrictHostKeyChecking=no' " . "$user@$host:$remote_dir $local_dir << EOF\n" . "$pass\n" . "EOF\n"; - - // Execute the command to mount the SFTP disk - Processes::mwExec($command, $out); - $response = trim(implode('', $out)); - - if ('Terminated' === $response) { - // The remote server did not respond or an incorrect password was provided. - unset($response); - } - - return self::isStorageDiskMounted("$local_dir "); - } - - /** - * Mount an FTP disk. - * - * @param string $host The FTP server host. - * @param string $port The FTP server port. - * @param string $user The FTP server username. - * @param string $pass The FTP server password. - * @param string $remote_dir The remote directory on the FTP server. - * @param string $local_dir The local directory to mount the FTP disk. - * @return bool Returns true if the FTP disk is successfully mounted, false otherwise. - */ - public static function mountFtp(string $host, string $port, string $user, string $pass, string $remote_dir, string $local_dir): bool - { - - // Create the local directory if it doesn't exist - Util::mwMkdir($local_dir); - $out = []; - - // Build the authentication line for the FTP connection - $auth_line = ''; - if (!empty($user)) { - $auth_line .= 'user="' . $user; - if (!empty($pass)) { - $auth_line .= ":$pass"; - } - $auth_line .= '",'; - } - - // Build the connect line for the FTP connection - $connect_line = 'ftp://' . $host; - if (!empty($port)) { - $connect_line .= ":$port"; - } - if (!empty($remote_dir)) { - $connect_line .= $remote_dir; - } - - $timeoutPath = Util::which('timeout'); - $curlftpfsPath = Util::which('curlftpfs'); - - // Build the command to mount the FTP disk - $command = "$timeoutPath 3 $curlftpfsPath -o allow_other -o {$auth_line}fsname=$host $connect_line $local_dir"; - - // Execute the command to mount the FTP disk - Processes::mwExec($command, $out); - $response = trim(implode('', $out)); - if ('Terminated' === $response) { - // The remote server did not respond or an incorrect password was provided. - unset($response); - } - - return self::isStorageDiskMounted("$local_dir "); - } - - /** - * Mount a WebDAV disk. - * - * @param string $host The WebDAV server host. - * @param string $user The WebDAV server username. - * @param string $pass The WebDAV server password. - * @param string $dstDir The destination directory on the WebDAV server. - * @param string $local_dir The local directory to mount the WebDAV disk. - * @return bool Returns true if the WebDAV disk is successfully mounted, false otherwise. - */ - public static function mountWebDav(string $host, string $user, string $pass, string $dstDir, string $local_dir): bool - { - $host = trim($host); - $dstDir = trim($dstDir); - - // Remove trailing slash from host if present - if (substr($host, -1) === '/') { - $host = substr($host, 0, -1); - } - - // Remove leading slash from destination directory if present - if ($dstDir[0] === '/') { - $dstDir = substr($dstDir, 1); - } - - // Create the local directory if it doesn't exist - Util::mwMkdir($local_dir); - $out = []; - $conf = 'dav_user www' . PHP_EOL . - 'dav_group www' . PHP_EOL; - - - // Write WebDAV credentials to secrets file - file_put_contents('/etc/davfs2/secrets', "$host$dstDir $user $pass"); - file_put_contents('/etc/davfs2/davfs2.conf', $conf); - $timeoutPath = Util::which('timeout'); - $mount = Util::which('mount.davfs'); - - // Build the command to mount the WebDAV disk - $command = "$timeoutPath 3 yes | $mount $host$dstDir $local_dir"; - - // Execute the command to mount the WebDAV disk - Processes::mwExec($command, $out); - $response = trim(implode('', $out)); - if ('Terminated' === $response) { - // The remote server did not respond or an incorrect password was provided. - unset($response); - } - return self::isStorageDiskMounted("$local_dir "); - } - /** * Create a file system on a disk. *