Pour compléter le petit tuto et ajouter ma contribution, ci-joint un petit shell d'installation de pure-ftpd par les paquets ipkg sur un TS-509, qui tient compte des remarques précédentes et permet de démarrer automatiquement pure-ftpd après un reboot. Le principe est le même sur d'autres modèles de QNAP, il n'y aura qu'à ajuster les répertoires selon votre config (selon votre modele et mode RAID ou non).
EDIT:
il faut que la database puredb se trouve dans /etc, sinon je n'arrive pas à me connecter avec un user donné.
Le moyen est de créer un lien symbolique /etc/pureftpd.pdb vers le lieu physique ou se trouve effectivement cette db.
N'importe quoi ! il faut juste mettre le bon path..

Et en cadeau bonux, j'ajoute l'option "-o" au lancement de pure-ftpd, et je mets en fin de script le code commenté à executer si d'aventure vous vouliez lancer un script (bash, perl, C...) de contrôle des fichiers uploadés. Sinon, supprimer l'option RUN_UPLOAD_SCRIPT ("-o").
Ensuite, il me faut encore trouver comment activer SSL/TLS.
#!/bin/sh
# *****************************************************************************************************
# * Install pure-ftpd on NAS QNAP TS509
# * Created PhB 24/01/2011
# *****************************************************************************************************
# *****************************************************************************************************
# doc
# http://forum.qnapclub.fr/topic/1259-creation-repertoire-ftp/
# http://forum.qnap.com/viewtopic.php?f=90&t=2851
# http://drpixel.tuxfamily.org/index.php?2006/06/25/8-pure-ftpd-installation-et-configuration-1-2
# http://download.pureftpd.org/pub/pure-ftpd/doc/README
# *****************************************************************************************************
# ########################
# STOP FTP DAEMON
# ########################
function Qftp_stop()
{
# Stop FTP if already started
echo -n "Stopping current FTP services: "
if [ -f /etc/init.d/rcv_port.sh ]; then
/etc/init.d/rcv_port.sh stop
fi
if [ -f /usr/local/sbin/proftpd ] && [ `/sbin/getcfg FTP Enable -u -d FALSE` = TRUE ]; then
/sbin/daemon_mgr proftpd stop "/usr/local/sbin/proftpd -n 2>/dev/null 1>/dev/null &"
fi
echo "proftpd stopped"
/etc/init.d/ftp.sh stop
}
# ########################
# DATAS
# ########################
# USERS
FTP_USER="pureftp_user" # you can change this name
FTP_GROUP="pureftp_group" # you can change this name
# DIRECTORIES
FTP_ROOT=/share/MD0_DATA/Qftp # path for RAID5 on TS-509, change this path accoring to your own directory setup
FTP_DIRECTORIES="public private users" # change to what you need but take care by yourself about the permissions then
FTP_ROOTDIR_PERM="444"
FTP_USERDIR_PERM="600"
IPKG_DIR=/share/MD0_DATA/.qpkg/Optware # path for RAID5 on TS-509, change this path according to your own directory setup
PUREDB_DIR=$IPKG_DIR/etc/pureftp
# BINARIES
IPKG_BIN=/opt/bin
# FILES
AUTORUN=/tmp/config/autorun.sh
AUTORUN_PERMANENT=/share/MD0_DATA/.qpkg/autorun/autorun.sh # permanent autorun shell addressed by /tmp/config/autorun.sh
AUTORUN_PERMISSION="755"
# SETUP pure-ftpd options
DAEMONIZE="-B"
DEFAULT_PORT_RANGE="55536:56000" # open passive ports shall be twice the concurrent sessions (eg if 100 clients connected=> 200 ports)
CREATE_USER_DIR="-j" # create virtual user dir when creating the user
MAXCONNECTIONS="-c 100"
MAXCLIENTPERIP="-C 10" # as there will be max 10 connections by client
noanonymous="-E" # anonymous not allowed
nochmod="-R"
minuid="-u 1"
peruserlimits="-y 5:0" # session limitation <per user max>:<max anonymous sessions>
CHROOTEVERYONE="-A"
ipv4only="-4"
BANDWIDTH="-T 50:200" # bandwidth limitation for [<upload>]:[<download>] in kb/s
customerproof="-Z" # prevents your users against making bad 'chmod' commands, that would deny access to files/directories to themselves
MAX_FILES=1000
DOS="-L $MAX_FILES:2" # <max files>:<max depth> : To avoid stupid denial-of-service attacks
DISK_LIMIT="-k 80" # Don't allow uploads if the partition is more than <percentage>% full
TIMEOUT="-I 1" # <timeout in minutes>, default is 15 min"
QUOTA="-n $MAX_FILES:1000" # "-n maxfiles:maxsize in Megabytes 1 Mb = 1024 kb => 10Go <=> 1000 Mb"
NO_DNSRESOLVE="-H"
LOGFILE=/share/MD0_DATA/admin/log/pureftp.log
# ALLOW_SYSLOG="-f none" # use "none" for server high load cases
ALLOW_SYSLOG="-f"
FTPLOG="-O CLF:$LOGFILE" # Record all file transfers into a specific log
RUN_UPLOAD_SCRIPT="-o" # To tell the FTP server to use upload scripts (to be avoided for cpu load reasons)
#PUREDB="-l puredb:/opt/etc/pureftpd.pdb" # virtual users db
PUREDB="-l puredb:/share/MD0_DATA/.qpkg/Optware/etc/pureftpd.pdb" # virtual users db
# ########################
# PREREQUISITES & CHECKS
# ########################
# ftpasswd or htpasswd shall be available
# autorun
[[ ! -d $(dirname $AUTORUN_PERMANENT) ]] && mkdir -p $(dirname $AUTORUN_PERMANENT)
# check /opt/bin directory
echo -n "Checking ipkg directory : "
[[ ! -d $IPKG_DIR ]] && echo " pls check exact path for IPKG_DIR and update it " && exit 1
echo "Ok"
echo -n "Checking /opt/bin directory : "
[[ ! -d $IPKG_BIN ]] && echo " pls check exact path for binaries DIR and update it " && exit 1
echo "Ok"
# create the ftp dir if not exists
echo -n "Create FTP root directory $FTP_ROOT : "
[[ ! -d $FTP_ROOT ]] && echo -n "(was not existing) : " && mkdir $FTP_ROOT
echo "Ok"
# check available disk space on this directory
echo -n "Checking available disk free space on $FTP_ROOT: "
USAGE=$(df $FTP_ROOT | tail -n1 | awk '{print $5}' | sed "s/%//")
[[ $USAGE -ge 80 ]] && echo "pls check available disk space and change the ftp root dir for a dir with enough available space" && df -h $FTP_ROOT && exit 1
echo "Ok"
# check pure-ftpd is not already installed
echo -n "Checking pure-ftpd not already installed : "
INSTALLED=$($IPKG_BIN/ipkg list_installed | grep pure-ftpd)
[[ ! -z $INSTALLED ]] && echo "Nok" && exit 1
echo "Ok"
# check puredb directory for virtual users
echo -n "Checking puredb directory (virtual users) : "
[[ ! -d $PUREDB_DIR ]] && mkdir -p $PUREDB_DIR
echo "Ok"
# ###########################
# NOW let's start the install
# ###########################
# disable current QNAP ftp server daemon, e.g. proftpd
# NOTA: QNAP proftpd is the default ftp service on QNAP,
# running a modified version from original source files (but not the case if installed by "ipkg proftpd")
Qftp_stop
# "nobody" user shall exists before running "ipkg install pure-ftpd"
echo -n "Checking nobody user "
NOBODY=$(cat /etc/passwd | grep -e "^nobody" | cut -d":" -f1)
[[ -z $NOBODY ]] && echo -n "(was not existing) " && addgroup nobody && adduser -H -h /dev/null -s /bin/false -G nobody nobody
echo ": Ok"
# create ftp group and user
echo -n "Creating FTP group $FTP_GROUP : "
addgroup $FTP_GROUP
echo "Ok"
echo -n "Creating FTP real user $FTP_USER (pwd= $PASSWORD) : "
USER=$(cat /etc/passwd | grep -e "^$FTP_USER" | cut -d":" -f1)
if [[ -z $USER ]] || [[ "$USER" != "$FTP_USER" ]];then
PASSWORD=$(htpasswd -nbm $FTP_USER $FTP_USER)
adduser -G $FTP_GROUP -h /dev/null -s /bin/false -p $PASSWORD $FTP_USER
fi
echo "Ok"
# create ftp directories
echo -n "Creating FTP directories $FTP_ROOT/{$FTP_DIRECTORIES} : "
for dir in $FTP_DIRECTORIES
do
mkdir -p $FTP_ROOT/$dir 2>/dev/null
[[ -d $FTP_ROOT/$dir ]] && chown $FTP_USER:$FTP_GROUP $FTP_ROOT/$dir
[[ -d $FTP_ROOT/$dir ]] && chmod $FTP_USERDIR_PERM $FTP_ROOT/$dir
done
echo "Ok"
# set ftp root dir permissions
echo -n "Check ftp root dir permissions ($FTP_ROOT) : "
chown $FTP_USER:$FTP_GROUP $FTP_ROOT
chmod $FTP_ROOTDIR_PERM $FTP_ROOT
echo "Ok"
# sothat the lettering files stays in /tmp
[[ ! -d $IPKG_DIR/tmp ]] && mkdir $IPKG_DIR/tmp
cd $IPKG_DIR/tmp
# install pure-ftpd
echo -n "Installing pure-ftpd package : "
$IPKG_BIN/ipkg update
$IPKG_BIN/ipkg install pure-ftpd
echo "Ok"
# remove lettering files
# rm -i *
# symlink pure-ftpd if symlimk not already existing
# [[ ! -L $IPKG_BIN/pure-ftpd ]] && ln -s $IPKG_DIR/sbin/pure-ftpd $IPKG_BIN/pure-ftpd
# start pure-ftpd
COMMAND="$IPKG_BIN/pure-ftpd"
OPTION_basic="$DAEMONIZE $DEFAULT_PORT_RANGE $CREATE_USER_DIR "
OPTION_network="$ipv4only $MAXCONNECTIONS $MAXCLIENTPERIP $TIMEOUT $NO_DNSRESOLVE"
OPTION_security="$noanonymous $nochmod $CHROOTEVERYONE $customerproof $DOS $ALLOW_SYSLOG $DISK_LIMIT $RUN_UPLOAD_SCRIPT"
OPTION_users="$minuid $peruserlimits $QUOTA $PUREDB"
$COMMAND $OPTION_basic $OPTION_network $OPTION_security $OPTION_users
# symlink pure-ftpd database
# ln -s /share/MD0_DATA/.qpkg/Optware/etc/pureftpd.pdb /etc/pureftpd.pdb
[[ ! -L /etc/pureftpd.pdb ]] && ln -s $IPKG_DIR/etc/pureftpd.pdb /etc/pureftpd.pdb
# setup NAS autorun.sh: pure-ftpd to start automatically at reboot
# see http://wiki.qnap.com/wiki/Running_Your_Own_Application_at_Startup
mount -t ext2 /dev/sdx6 /tmp/config
# create the autorun file if not exists
if [[ ! -f $AUTORUN ]];then
echo -e "#!/bin/sh\n/share/MD0_DATA/.qpkg/autorun/autorun.sh" > $AUTORUN
chmod $AUTORUN_PERMISSION $AUTORUN
else
# do not overwrite "permanent autorun" is already addressed
CHECK=$(grep $AUTORUN_PERMANENT $AUTORUN)
if [[ -z $CHECK ]];then
echo -e "$AUTORUN_PERMANENT" >> $AUTORUN
fi
fi
umount /tmp/config
# complete permanent_autorun.sh to start pure-ftpd at reboot
CHECK=$(grep "pure*ftp*" $AUTORUN_PERMANENT)
[[ -z $CHECK ]] && echo "$COMMAND $OPTION_basic $OPTION_network $OPTION_security $OPTION_users" >> $AUTORUN_PERMANENT
# create a virtual user foreach directory
# /opt/bin/pure-pw useradd testuser -u ftpuser -d /home/ftpusers/testuser
# -----------------------------------
# HOOK uploaded file mime check
# -----------------------------------
# pure-uploadscript (to be started after server daemon)
# /opt/sbin/pure-uploadscript -B -r /opt/bin/my_mime_check.pl
# POST_UPLOAD_SHELL=$IPKG_BIN/my_mime_check.pl
# [[ -x $POST_UPLOAD_SHELL ]] && [[ -f /opt/sbin/pure-uploadscript ]] && /opt/sbin/pure-uploadscript $DAEMONIZE -r $POST_UPLOAD_SHELL 2>/dev/null
exit 0