2
This commit is contained in:
3
modules/network/ftp-server/config.sh
Normal file
3
modules/network/ftp-server/config.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
POSTINSTALL_FTP_SETTINGS_FILE="config/ftp-server.yaml"
|
||||
POSTINSTALL_FTP_CONFIG_DIR="/etc/vsftpd"
|
||||
POSTINSTALL_FTP_CONFIG_FILE="/etc/vsftpd.conf"
|
||||
4
modules/network/ftp-server/metadata.conf
Normal file
4
modules/network/ftp-server/metadata.conf
Normal file
@@ -0,0 +1,4 @@
|
||||
MODULE_ID="network/ftp-server"
|
||||
MODULE_NAME="Serveur FTP"
|
||||
MODULE_CATEGORY="network"
|
||||
MODULE_DESCRIPTION="Installe et configure un serveur FTP via vsftpd"
|
||||
106
modules/network/ftp-server/module.sh
Normal file
106
modules/network/ftp-server/module.sh
Normal file
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
MODULE_FTP_SERVER_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
MODULE_FTP_SERVER_PROJECT_ROOT="$(cd "$MODULE_FTP_SERVER_DIR/../../.." && pwd)"
|
||||
|
||||
# shellcheck source=lib/package.sh
|
||||
source "$MODULE_FTP_SERVER_PROJECT_ROOT/lib/package.sh"
|
||||
# shellcheck source=modules/network/ftp-server/config.sh
|
||||
source "$MODULE_FTP_SERVER_DIR/config.sh"
|
||||
# shellcheck source=modules/network/ftp-server/metadata.conf
|
||||
source "$MODULE_FTP_SERVER_DIR/metadata.conf"
|
||||
|
||||
module_ftp_server_metadata() {
|
||||
printf '%s|%s|%s\n' "$MODULE_ID" "$MODULE_NAME" "$MODULE_DESCRIPTION"
|
||||
}
|
||||
|
||||
module_ftp_server_config_path() {
|
||||
printf '%s/%s\n' "$MODULE_FTP_SERVER_PROJECT_ROOT" "$POSTINSTALL_FTP_SETTINGS_FILE"
|
||||
}
|
||||
|
||||
module_ftp_server_settings() {
|
||||
local config_path=""
|
||||
local listen_port="21"
|
||||
local anonymous_enable="no"
|
||||
local local_enable="yes"
|
||||
local write_enable="no"
|
||||
local local_root="/home/gilles"
|
||||
|
||||
config_path="$(module_ftp_server_config_path)"
|
||||
if [[ -f "$config_path" ]]; then
|
||||
while IFS='=' read -r key value; do
|
||||
case "$key" in
|
||||
listen_port) listen_port="$value" ;;
|
||||
anonymous_enable) anonymous_enable="$value" ;;
|
||||
local_enable) local_enable="$value" ;;
|
||||
write_enable) write_enable="$value" ;;
|
||||
local_root) local_root="$value" ;;
|
||||
esac
|
||||
done < <(
|
||||
awk '
|
||||
/^[[:space:]]*listen_port:/ { print "listen_port=" $2 }
|
||||
/^[[:space:]]*anonymous_enable:/ { print "anonymous_enable=" $2 }
|
||||
/^[[:space:]]*local_enable:/ { print "local_enable=" $2 }
|
||||
/^[[:space:]]*write_enable:/ { print "write_enable=" $2 }
|
||||
/^[[:space:]]*local_root:/ { print "local_root=" $2 }
|
||||
' "$config_path"
|
||||
)
|
||||
fi
|
||||
|
||||
printf '%s|%s|%s|%s|%s\n' "$listen_port" "$anonymous_enable" "$local_enable" "$write_enable" "$local_root"
|
||||
}
|
||||
|
||||
module_ftp_server_write_config() {
|
||||
local listen_port="$1"
|
||||
local anonymous_enable="$2"
|
||||
local local_enable="$3"
|
||||
local write_enable="$4"
|
||||
local local_root="$5"
|
||||
|
||||
cat > "$POSTINSTALL_FTP_CONFIG_FILE" <<EOF
|
||||
listen=YES
|
||||
listen_port=$listen_port
|
||||
anonymous_enable=$anonymous_enable
|
||||
local_enable=$local_enable
|
||||
write_enable=$write_enable
|
||||
dirmessage_enable=YES
|
||||
use_localtime=YES
|
||||
xferlog_enable=YES
|
||||
connect_from_port_20=YES
|
||||
secure_chroot_dir=/var/run/vsftpd/empty
|
||||
pam_service_name=vsftpd
|
||||
ssl_enable=NO
|
||||
local_root=$local_root
|
||||
allow_writeable_chroot=YES
|
||||
EOF
|
||||
}
|
||||
|
||||
module_ftp_server_install() {
|
||||
local settings=""
|
||||
local listen_port=""
|
||||
local anonymous_enable=""
|
||||
local local_enable=""
|
||||
local write_enable=""
|
||||
local local_root=""
|
||||
|
||||
settings="$(module_ftp_server_settings)"
|
||||
IFS='|' read -r listen_port anonymous_enable local_enable write_enable local_root <<< "$settings"
|
||||
|
||||
package_refresh_indexes
|
||||
package_install vsftpd
|
||||
mkdir -p "$local_root"
|
||||
module_ftp_server_write_config "$listen_port" "$anonymous_enable" "$local_enable" "$write_enable" "$local_root"
|
||||
|
||||
systemctl enable --now vsftpd
|
||||
systemctl restart vsftpd
|
||||
|
||||
log_info "Serveur FTP configure sur le port $listen_port"
|
||||
ui_success "Serveur FTP configure sur le port $listen_port"
|
||||
}
|
||||
|
||||
module_ftp_server_test() {
|
||||
package_is_installed vsftpd || return 1
|
||||
test -f "$POSTINSTALL_FTP_CONFIG_FILE" || return 1
|
||||
test -f "$(module_ftp_server_config_path)" || return 1
|
||||
command -v ftp >/dev/null 2>&1 || true
|
||||
}
|
||||
35
modules/network/ftp-server/tests.sh
Normal file
35
modules/network/ftp-server/tests.sh
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
MODULE_FTP_SERVER_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$MODULE_FTP_SERVER_DIR/../../.." && pwd)"
|
||||
|
||||
# shellcheck source=lib/ui.sh
|
||||
source "$PROJECT_ROOT/lib/ui.sh"
|
||||
# shellcheck source=lib/log.sh
|
||||
source "$PROJECT_ROOT/lib/log.sh"
|
||||
# shellcheck source=lib/package.sh
|
||||
source "$PROJECT_ROOT/lib/package.sh"
|
||||
# shellcheck source=core/runtime.sh
|
||||
source "$PROJECT_ROOT/core/runtime.sh"
|
||||
# shellcheck source=modules/network/ftp-server/module.sh
|
||||
source "$MODULE_FTP_SERVER_DIR/module.sh"
|
||||
|
||||
runtime_init "$PROJECT_ROOT"
|
||||
log_init
|
||||
|
||||
if ! test -f "$PROJECT_ROOT/config/ftp-server.yaml"; then
|
||||
printf 'ftp-server test FAILED: missing repository config\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! package_is_installed vsftpd; then
|
||||
printf 'ftp-server test SKIPPED: vsftpd not installed\n'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if module_ftp_server_test; then
|
||||
printf 'ftp-server test OK\n'
|
||||
else
|
||||
printf 'ftp-server test FAILED\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user