mirror of
https://github.com/RetroDECK/RetroDECK.git
synced 2024-11-21 21:45:39 +00:00
SFTP: adding SFTP Server
This commit is contained in:
parent
93b45bdc2d
commit
e26f238f26
|
@ -1,34 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
port=21
|
||||
ip=$(hostname -I | awk '{print $1}')
|
||||
|
||||
# Check if the port is in use
|
||||
if nc -z localhost $port; then
|
||||
zenity --error --no-wrap \
|
||||
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
|
||||
--title "RetroDECK - FTP Server" \
|
||||
--text="Port $port is already in use. Please stop any services on that port and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Start FTP server on port $port
|
||||
nohup vsftpd /var/config/retrodeck/ftp/vsftpd.conf &
|
||||
|
||||
# Get the PID of the FTP server process
|
||||
ftp_pid=$!
|
||||
|
||||
# Function to stop the FTP server
|
||||
stop_ftp_server() {
|
||||
kill -9 $ftp_pid
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Create a Zenity window with only the "Stop" button
|
||||
zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap \
|
||||
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
|
||||
--title "RetroDECK - FTP Server" \
|
||||
--text="FTP server started.\n\nAddress: $ip\nport: $port\nID:\tretrodeck\nPassword:\tretrodeck\npointing to:\n$rdhome\n\nPress Stop to terminate the server." --ok-label="Stop" || stop_ftp_server
|
||||
|
||||
# If the user clicks "Stop", call the function to stop the FTP server
|
||||
stop_ftp_server
|
|
@ -714,21 +714,6 @@ prepare_emulator() {
|
|||
|
||||
fi
|
||||
|
||||
# TODO: this is not properly an emulator but let's treat like this for the moment
|
||||
if [[ "$emulator" =~ ^(ftp|FTP|all)$ ]]; then
|
||||
# TODO: do a proper script
|
||||
# This is just a placeholder script to test the emulator's flow
|
||||
echo "------------------------"
|
||||
echo "Initializing FTP Server"
|
||||
echo "------------------------"
|
||||
|
||||
mkdir -p "/var/config/ftp"
|
||||
cp "/app/retrodeck/ftp/*" "/var/config/retrodeck/ftp"
|
||||
# TODO: this step is to be done properly: Replacing RETRODECKHOMEDIR placeholder
|
||||
sed -i 's#RETRODECKHOMEDIR#'$rdhome'#g' "/var/config/retrodeck/ftp/vsftpd.conf"
|
||||
|
||||
fi
|
||||
|
||||
# Update presets for all emulators after any reset or move
|
||||
if [[ ! "$emulator" == "retrodeck" ]]; then
|
||||
build_retrodeck_current_presets
|
||||
|
|
45
functions/sftp_server.sh
Normal file
45
functions/sftp_server.sh
Normal file
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
port=22
|
||||
ip=$(hostname -I | awk '{print $1}')
|
||||
|
||||
# Check if the port is in use
|
||||
if nc -z localhost $port; then
|
||||
zenity --error --no-wrap \
|
||||
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
|
||||
--title "RetroDECK - SFTP Server" \
|
||||
--text="Port $port is already in use. Please stop any services on that port and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a temporary directory for SFTP chroot
|
||||
mkdir -p /tmp/sftp_home/retrodeck
|
||||
echo "retrodeck:$(openssl passwd -1 retrodeck)" >> /tmp/sftp_home/retrodeck/etc/passwd
|
||||
|
||||
# Set rdhome as the home directory for retrodeck user
|
||||
echo "Match User retrodeck\n ChrootDirectory $rdhome" >> /etc/ssh/sshd_config
|
||||
|
||||
# Restart SSHD to apply the new configuration
|
||||
service ssh restart
|
||||
|
||||
# Start SSHD with SFTP support and specific user and password
|
||||
nohup /usr/sbin/sshd -p $port -o PasswordAuthentication=yes -o PubkeyAuthentication=no -o AuthorizedKeysFile=/dev/null -o UsePAM=no -o AllowTcpForwarding=no -o PermitRootLogin=no -o ChrootDirectory=/tmp/sftp_home/retrodeck &
|
||||
|
||||
# Get the PID of the SSH/SFTP server process
|
||||
ssh_pid=$!
|
||||
|
||||
# Function to stop the SSH/SFTP server
|
||||
stop_ssh_server() {
|
||||
kill -9 $ssh_pid
|
||||
rm -rf /tmp/sftp_home
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Create a Zenity window with only the "Stop" button
|
||||
zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap \
|
||||
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
|
||||
--title "RetroDECK - SFTP Server" \
|
||||
--text="SFTP server started.\n\nAddress: $ip\nport: $port\nID:\tretrodeck\nPassword:\tretrodeck\npointing to:\n$rdhome\n\nPress Stop to terminate the server." --ok-label="Stop" || stop_ssh_server
|
||||
|
||||
# If the user clicks "Stop", call the function to stop the SSH/SFTP server
|
||||
stop_ssh_server
|
|
@ -284,33 +284,25 @@ modules:
|
|||
# dependency of: CEMU, RPCS3
|
||||
- rd-submodules/shared-modules/glew/glew.json
|
||||
|
||||
# FTP Server
|
||||
# TODO: address
|
||||
# SFTP Server
|
||||
|
||||
- name: vsftpd
|
||||
- name: sftp-hostname
|
||||
buildsystem: simple
|
||||
build-commands:
|
||||
- ar -x vsftpd*.deb
|
||||
- rm -f vsftpd*.deb
|
||||
- ar -x hostname*.deb
|
||||
- tar -xf data.tar.zst
|
||||
- rm -f control.tar.gz data.tar.zst debian-binary
|
||||
- cp -r usr/* ${FLATPAK_DEST}
|
||||
- rm -rf usr lib etc
|
||||
- mkdir -p ${FLATPAK_DEST}/retrodeck/ftp
|
||||
- cp -r bin/* ${FLATPAK_DEST}/bin
|
||||
- mkdir -p ${FLATPAK_DEST}/libexec
|
||||
- cp -vf virtual_users.txt vsftpd.conf ${FLATPAK_DEST}/retrodeck/ftp
|
||||
- cp -vf ftp_server.sh ${FLATPAK_DEST}/libexec
|
||||
- chmod +x ${FLATPAK_DEST}/libexec/ftp_server.sh
|
||||
sources:
|
||||
- type: file
|
||||
url: http://de.archive.ubuntu.com/ubuntu/pool/main/v/vsftpd/vsftpd_3.0.5-0ubuntu1_amd64.deb
|
||||
sha256: 248582c4511ceaab5fd0d7f28d3a95af1a946a83bffe1a36d1accb72d99c2cf8
|
||||
url: http://de.archive.ubuntu.com/ubuntu/pool/main/h/hostname/hostname_3.23ubuntu2_amd64.deb
|
||||
sha256: cec0448fef88a43a3c232fd9df555ca4c468cf5e16ddf3a1b0a5f7b7f076e413
|
||||
- type: file
|
||||
path: tools/ftp/virtual_users.txt
|
||||
- type: file
|
||||
path: tools/ftp/vsftpd.conf
|
||||
- type: file
|
||||
path: functions/ftp_server.sh
|
||||
path: functions/sftp_server.sh
|
||||
|
||||
# SFTP Server - END
|
||||
|
||||
# ES-DE - START
|
||||
# https://gitlab.com/es-de/emulationstation-de
|
||||
|
|
|
@ -61,7 +61,7 @@ source /app/libexec/global.sh
|
|||
# - Install: RetroDECK SD Controller Profile
|
||||
# - Install: PS3 firmware
|
||||
# - RetroDECK: Change Update Setting
|
||||
# - Start FTP Server
|
||||
# - Start an SFTP Server
|
||||
# - Troubleshooting
|
||||
# - Backup: RetroDECK Userdata
|
||||
# - Check & Verify: BIOS
|
||||
|
@ -529,7 +529,7 @@ configurator_retrodeck_tools_dialog() {
|
|||
"Install: RetroDECK SD Controller Profile" "Install the custom RetroDECK controller layout for the Steam Deck" \
|
||||
"Install: PS3 Firmware" "Download and install PS3 firmware for use with the RPCS3 emulator" \
|
||||
"RetroDECK: Change Update Setting" "Enable or disable online checks for new versions of RetroDECK" \
|
||||
"Start FTP Server" "Start an FTP server to manage your retrodeck folder from another device"
|
||||
"Start an SFTP Server" "Start an SFTP server to manage your retrodeck folder from another device"
|
||||
)
|
||||
|
||||
case $choice in
|
||||
|
@ -574,8 +574,8 @@ configurator_retrodeck_tools_dialog() {
|
|||
configurator_online_update_setting_dialog
|
||||
;;
|
||||
|
||||
"Start FTP Server" )
|
||||
source /app/libexec/ftp_server.sh
|
||||
"Start an SFTP Server" )
|
||||
source /app/libexec/sftp_server.sh
|
||||
;;
|
||||
|
||||
"" ) # No selection made or Back button clicked
|
||||
|
@ -989,7 +989,7 @@ configurator_reset_dialog() {
|
|||
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --width=1200 --height=720 \
|
||||
--column="Choice" --column="Action" \
|
||||
"Reset Specific Emulator" "Reset only one specific emulator to default settings" \
|
||||
"Reset All Emulators" "Reset all emulators and FTP server to their default settings" \
|
||||
"Reset All Emulators" "Reset all emulators to their default settings" \
|
||||
"Reset RetroDECK" "Reset RetroDECK to default settings" )
|
||||
|
||||
case $choice in
|
||||
|
@ -1044,7 +1044,7 @@ configurator_reset_dialog() {
|
|||
;;
|
||||
|
||||
"Reset All Emulators" )
|
||||
if [[ $(configurator_reset_confirmation_dialog "all emulators" "Are you sure you want to reset all emulators and FTP server to their default settings?\n\nThis process cannot be undone.") == "true" ]]; then
|
||||
if [[ $(configurator_reset_confirmation_dialog "all emulators" "Are you sure you want to reset all emulators to their default settings?\n\nThis process cannot be undone.") == "true" ]]; then
|
||||
(
|
||||
prepare_emulator "reset" "all"
|
||||
) |
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
retrodeck:retrodeck
|
|
@ -1,17 +0,0 @@
|
|||
# vsftpd config file
|
||||
|
||||
anonymous_enable=NO
|
||||
virtual_users=YES
|
||||
userlist_file=/var/config/ftp/virtual_users.txt
|
||||
userlist_enable=YES
|
||||
userlist_deny=NO
|
||||
write_enable=YES
|
||||
local_root=RETRODECKHOMEDIR
|
||||
chroot_local_user=YES
|
||||
local_umask=000
|
||||
listen_port=777
|
||||
xferlog_enable=YES
|
||||
xferlog_file=RETRODECKHOMEDIR/.logs/ftp.log
|
||||
log_ftp_protocol=YES
|
||||
ftpd_banner=Welcome to RetroDECK
|
||||
force_dot_files=YES
|
Loading…
Reference in a new issue