From 253bf8714c75d355170c24aefd867177b9c650db Mon Sep 17 00:00:00 2001 From: FanDjango Date: Sat, 22 Oct 2022 00:31:44 +0200 Subject: [PATCH 1/2] FileZilla integration test server --- FluentFTP.Dockers/Build.bat | 2 + FluentFTP.Dockers/Build.sh | 2 + FluentFTP.Dockers/filezilla/Dockerfile | 153 ++++++++++++++++++ .../filezilla/docker-compose.yml | 13 ++ FluentFTP.Dockers/filezilla/run-filezilla.sh | 19 +++ FluentFTP.Dockers/filezilla/settings.xml | 100 ++++++++++++ FluentFTP.Dockers/filezilla/users.xml | 27 ++++ .../Integration/IntegrationTests.cs | 5 + .../Docker/Containers/FileZillaContainer.cs | 36 +++++ .../Docker/DockerFtpContainerIndex.cs | 3 +- 10 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 FluentFTP.Dockers/filezilla/Dockerfile create mode 100644 FluentFTP.Dockers/filezilla/docker-compose.yml create mode 100644 FluentFTP.Dockers/filezilla/run-filezilla.sh create mode 100644 FluentFTP.Dockers/filezilla/settings.xml create mode 100644 FluentFTP.Dockers/filezilla/users.xml create mode 100644 FluentFTP.Xunit/Docker/Containers/FileZillaContainer.cs diff --git a/FluentFTP.Dockers/Build.bat b/FluentFTP.Dockers/Build.bat index 92d6bc45..286504e4 100644 --- a/FluentFTP.Dockers/Build.bat +++ b/FluentFTP.Dockers/Build.bat @@ -11,4 +11,6 @@ docker build bftpd -t bftpd:fluentftp docker build glftpd -t glftpd:fluentftp +docker build filezilla -t filezilla:fluentftp + pause \ No newline at end of file diff --git a/FluentFTP.Dockers/Build.sh b/FluentFTP.Dockers/Build.sh index 7b4e8694..bc76aa79 100644 --- a/FluentFTP.Dockers/Build.sh +++ b/FluentFTP.Dockers/Build.sh @@ -10,3 +10,5 @@ sudo docker build pyftpdlib -t pyftpdlib:fluentftp sudo docker build bftpd -t bftpd:fluentftp sudo docker build glftpd -t glftpd:fluentftp + +sudo docker build filezilla -t filezilla:fluentftp diff --git a/FluentFTP.Dockers/filezilla/Dockerfile b/FluentFTP.Dockers/filezilla/Dockerfile new file mode 100644 index 00000000..b706fa0d --- /dev/null +++ b/FluentFTP.Dockers/filezilla/Dockerfile @@ -0,0 +1,153 @@ +# +# Stage 1: build +# + +FROM debian:bullseye-slim AS build + +SHELL ["/bin/bash", "-c"] + +ARG LIBFILEZILLA_VERSION=0.39.2 +ARG FILEZILLA_VERSION=1.5.1 + +ARG LIBFILEZILLA_URL=https://download.filezilla-project.org/libfilezilla/libfilezilla-${LIBFILEZILLA_VERSION}.tar.bz2 +ARG FILEZILLA_URL=https://download.filezilla-project.org/server/FileZilla_Server_${FILEZILLA_VERSION}_src.tar.bz2 + +ARG DEBIAN_FRONTEND=noninteractive +ARG APT_CMD='apt install -y --no-install-recommends' + +WORKDIR / +RUN apt update && apt upgrade -y && apt install -y apt-utils && \ + \ + $APT_CMD \ + curl \ + ca-certificates \ + bzip2 \ + binutils \ + build-essential \ + pkg-config \ + libgmp-dev \ + nettle-dev \ + gnutls-dev \ + gettext \ + libwxgtk3.0-gtk3-dev + +WORKDIR /tmp/libfilezilla +RUN curl -L ${LIBFILEZILLA_URL} | tar xj --strip 1 -C /tmp/libfilezilla + +WORKDIR /tmp/filezilla +RUN curl -L ${FILEZILLA_URL} | tar xj --strip 1 -C /tmp/filezilla + +# +# configure, make, make install sequences for libfilezilla and filezilla-server +# +WORKDIR / +RUN export CFLAGS="-Os -fomit-frame-pointer" && \ + export CXXFLAGS="$CFLAGS" && \ + export CPPFLAGS="$CFLAGS" && \ + export LDFLAGS="-Wl,--as-needed" && \ +# +# libfilezilla +# + cd /tmp/libfilezilla && \ + \ + ./configure --enable-shared=no --with-pic && \ + \ + make -j$(nproc) && \ + make install && \ +# +# filezilla-server +# + cd /tmp/filezilla/src/server && \ +# +# need to changes the source code to not refuse to work if unprotected_hardlinks is 0 +# + sed -i "s/(has_unprotected_hardlinks)/(false)/" main.cpp && \ +# +# need to create some bogus files because there is a bug in filezilla-server Makefile +# + cd /tmp/filezilla/res/share/icons/hicolor && \ + \ + mkdir -p 128x128/apps && cd $_ && echo '.' > filezilla-server-gui.png && cd ../.. && \ + mkdir -p 16x16/apps && cd $_ && echo '.' > filezilla-server-gui.png && cd ../.. && \ + mkdir -p 20x20/apps && cd $_ && echo '.' > filezilla-server-gui.png && cd ../.. && \ + mkdir -p 24x24/apps && cd $_ && echo '.' > filezilla-server-gui.png && cd ../.. && \ + mkdir -p 256x256/apps && cd $_ && echo '.' > filezilla-server-gui.png && cd ../.. && \ + mkdir -p 32x32/apps && cd $_ && echo '.' > filezilla-server-gui.png && cd ../.. && \ + mkdir -p 48x48/apps && cd $_ && echo '.' > filezilla-server-gui.png && cd ../.. && \ + mkdir -p scalable/apps && cd $_ && echo '.' > filezilla-server-gui.svg && cd ../.. && \ + \ + cd /tmp/filezilla && \ + \ + export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig && \ + ./configure --with-pugixml=builtin && \ + \ + make -j$(nproc) && \ + make install + +WORKDIR /tmp/filezilla + +# +# The certificate and the certificate signature +# +# Make self signed key/cert pair: +# openssl ecparam -name prime256v1 -genkey -noout -out key.pem && \ +# openssl req -new -x509 -key key.pem -out cert.pem -days 3650 +# +RUN openssl ecparam -name prime256v1 -genkey -noout -out key.pem && \ + openssl req -new -x509 -key key.pem -out cert.pem -days 3650 -subj "/C=US/ST=State/L=/O=Dev/CN=fluentftp" + +# +# Stage 2: production +# + +FROM debian:bullseye-slim AS production + +SHELL ["/bin/bash", "-c"] + +ARG DEBIAN_FRONTEND=noninteractive +ARG APT_CMD='apt install -y --no-install-recommends' + +WORKDIR / +RUN apt update && apt upgrade -y && apt install -y apt-utils + +# +# Bring in settings.xml (PASV port ranges, certificate refs), +# and users.xml (contains fluentuser and his password) +# +COPY --from=build /usr/local/bin /usr/local/bin + +COPY --from=build /tmp/filezilla/cert.pem /root/cert.pem +COPY --from=build /tmp/filezilla/key.pem /root/key.pem + +WORKDIR /root/.config/filezilla-server + +COPY settings.xml /root/.config/filezilla-server/settings.xml +COPY users.xml /root/.config/filezilla-server/users.xml + +RUN sed -i "s/<\/keyfile>/\/root\/key.pem<\/keyfile>/" /root/.config/filezilla-server/settings.xml && \ + sed -i "s/<\/certsfile>/\/root\/cert.pem<\/certsfile>/" /root/.config/filezilla-server/settings.xml && \ +# +# All other settings files can be empty but must exist. +# + touch allowed_ips.xml && \ + touch disallowed_ips.xml && \ + touch groups.xml + +WORKDIR / + +COPY run-filezilla.sh /usr/sbin/ + +RUN sed -i -e "s/\r//" /usr/sbin/run-filezilla.sh && \ + chmod +x /usr/sbin/run-filezilla.sh && \ + \ + useradd -m -p savatlcb.1m26 fluentuser && \ + \ + mkdir -p /home/fluentuser/ && \ + chown -R fluentuser:users /home/fluentuser + +VOLUME /home/fluentuser +VOLUME /var/log/filezilla + +EXPOSE 20 21 + +CMD ["/usr/sbin/run-filezilla.sh"] diff --git a/FluentFTP.Dockers/filezilla/docker-compose.yml b/FluentFTP.Dockers/filezilla/docker-compose.yml new file mode 100644 index 00000000..50db8e74 --- /dev/null +++ b/FluentFTP.Dockers/filezilla/docker-compose.yml @@ -0,0 +1,13 @@ +services: + filezilla: + build: + context: . + network: host + restart: unless-stopped + ports: + - 0.0.0.0:20:20 + - 0.0.0.0:21:21 + - 21100-21110:21100-21110 + volumes: + - ./home:/home/filezilla + - ./logs:/var/log/filezilla diff --git a/FluentFTP.Dockers/filezilla/run-filezilla.sh b/FluentFTP.Dockers/filezilla/run-filezilla.sh new file mode 100644 index 00000000..81714b4c --- /dev/null +++ b/FluentFTP.Dockers/filezilla/run-filezilla.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# stdout server info: +cat << EOB + ************************************************* + * * + * Docker image: fluentftp filezilla * + * * + ************************************************* + + SERVER SETTINGS + --------------- + · FTP User: fluentuser + · FTP Password: fluentpass +EOB + +# Run filezilla: + +&>/dev/null /usr/local/bin/filezilla-server diff --git a/FluentFTP.Dockers/filezilla/settings.xml b/FluentFTP.Dockers/filezilla/settings.xml new file mode 100644 index 00000000..7a101241 --- /dev/null +++ b/FluentFTP.Dockers/filezilla/settings.xml @@ -0,0 +1,100 @@ + + + + + + + + + + 0 + + 9223372036854775807 + + 15 + + 0 + + true + + + + + + + 300000 + + 100 + + 0 + + + + + 0 + + -1 + + -1 + + + + + 60000 + + 3600000 + + + + + + +
0.0.0.0
+ 21 + 0 +
+ +
::
+ 21 + 0 +
+ + + + + + localhost + + true + + + + 21100 + + 21199 + + + + + + + + + + + + + + +
+ + + + + + + + + + +
diff --git a/FluentFTP.Dockers/filezilla/users.xml b/FluentFTP.Dockers/filezilla/users.xml new file mode 100644 index 00000000..fcd7b9b1 --- /dev/null +++ b/FluentFTP.Dockers/filezilla/users.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + This user can impersonate any system user. + + + + + + + + + + l9jcg8P68htZEZF7iIy6GhrbS8HLFGSikYzaUAnHo5E + oFoJsx+xI6ZIEg9dc7fJUnLqjHWklAi2QcuHe5QVhTE + 100000 + + + diff --git a/FluentFTP.Tests/Integration/IntegrationTests.cs b/FluentFTP.Tests/Integration/IntegrationTests.cs index 65220115..f7c51442 100644 --- a/FluentFTP.Tests/Integration/IntegrationTests.cs +++ b/FluentFTP.Tests/Integration/IntegrationTests.cs @@ -35,6 +35,11 @@ public async Task Glftpd() { await IntegrationTestRunner.Run(FtpServer.glFTPd); } + [Fact] + public async Task FileZilla() { + await IntegrationTestRunner.Run(FtpServer.FileZilla); + } + // These can only do FTP [Fact] public async Task Bftpd() { diff --git a/FluentFTP.Xunit/Docker/Containers/FileZillaContainer.cs b/FluentFTP.Xunit/Docker/Containers/FileZillaContainer.cs new file mode 100644 index 00000000..91f4259c --- /dev/null +++ b/FluentFTP.Xunit/Docker/Containers/FileZillaContainer.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DotNet.Testcontainers.Builders; +using DotNet.Testcontainers.Containers; + +namespace FluentFTP.Xunit.Docker.Containers { + internal class FileZillaContainer : DockerFtpContainer { + + public FileZillaContainer() { + ServerType = FtpServer.FileZilla; + ServerName = "filezilla"; + DockerImage = "filezilla:fluentftp"; + //without SSL: + // not possible + //with SSL: + // RunCommand = "docker run --rm -it -p 21:21 -p 21100-21199:21100-21199 filezilla:fluentftp"; + } + + /// + /// For help creating this section see https://github.com/testcontainers/testcontainers-dotnet#supported-commands + /// + public override ITestcontainersBuilder Configure(ITestcontainersBuilder builder) { + + builder = builder.WithPortBinding(20); + + builder = ExposePortRange(builder, 21100, 21199); + + return builder; + } + + } + +} diff --git a/FluentFTP.Xunit/Docker/DockerFtpContainerIndex.cs b/FluentFTP.Xunit/Docker/DockerFtpContainerIndex.cs index 7d3fb985..27a6abd3 100644 --- a/FluentFTP.Xunit/Docker/DockerFtpContainerIndex.cs +++ b/FluentFTP.Xunit/Docker/DockerFtpContainerIndex.cs @@ -14,7 +14,8 @@ internal static class DockerFtpContainerIndex { new PyFtpdLibContainer(), new VsFtpdContainer(), new BFtpdContainer(), - new GlFtpdContainer() + new GlFtpdContainer(), + new FileZillaContainer(), }; } } From 374f9e03065c78554ba29cd5125a61ffa57155f4 Mon Sep 17 00:00:00 2001 From: FanDjango Date: Sat, 22 Oct 2022 00:33:26 +0200 Subject: [PATCH 2/2] tweak --- FluentFTP.Dockers/filezilla/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FluentFTP.Dockers/filezilla/docker-compose.yml b/FluentFTP.Dockers/filezilla/docker-compose.yml index 50db8e74..22d8d99a 100644 --- a/FluentFTP.Dockers/filezilla/docker-compose.yml +++ b/FluentFTP.Dockers/filezilla/docker-compose.yml @@ -7,7 +7,7 @@ services: ports: - 0.0.0.0:20:20 - 0.0.0.0:21:21 - - 21100-21110:21100-21110 + - 21100-21110:21100-21199 volumes: - ./home:/home/filezilla - ./logs:/var/log/filezilla