2 # postinst script for proftpd-cn
4 # see: dh_installdeb(1)
8 # summary of how this script can be called:
9 # * <postinst> `configure' <most-recently-configured-version>
10 # * <old-postinst> `abort-upgrade' <new version>
11 # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
13 # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
14 # <failed-install-package> <version> `removing'
15 # <conflicting-package> <version>
16 # for details, see http://www.debian.org/doc/debian-policy/ or
17 # the debian-policy package
21 configure|reconfigure)
30 # created: 2002-11-15 Bozo Juretic <bjuretic@srce.hr>
31 # last update: 2007-05-14 Zoran Dzelajlija <zoran.dzelajlija@carnet.hr>
32 # last update: 2011-04-24 Dinko Korunic <kreator@carnet.hr>
34 # Source debconf library.
35 . /usr/share/debconf/confmodule
38 . /usr/share/carnet-tools/functions.sh
40 FTP_CONF=/etc/proftpd/proftpd.conf
41 FTP_TMP=`mktemp /etc/proftpd/proftpd.conf.XXXXXX`
42 FTP_OLD=/var/backups/proftpd.conf.bak
43 SSL_CERT=/etc/ssl/certs/ftpd.pem
44 SSL_KEY=/etc/ssl/private/ftpd.pem
46 # Backup stare konfiguracije
47 cp_backup_conffile $FTP_CONF
48 cp -p $FTP_CONF $FTP_TMP
50 # Onemogucavanje Anonymous ftp pristupa
53 if grep -qi "^<Anonymous" $FTP_TMP; then
54 echo "CN: Anonymous access has been disabled in $FTP_CONF."
55 # Brisanje Anonymous linija
56 sed -n -i -e '/<Anonymous /,/\/Anon/!p' $FTP_TMP
60 # Popravi razne stvari u confu
63 if [ -f $FTP_TMP ]; then
65 sed -i -e 's/lsdefaultoptions/ListOptions/i' $FTP_TMP
68 sed -i -e "s/tcpreceivewindow/SocketOptions rcvbuf/i" \
69 -e "s/tcpsendwindow/SocketOptions sndbuf/i" $FTP_TMP
72 sed -i -e "s/\(scoreboardpath.*\)/#\n#ScoreboardPath is deprecated in 1.2.9, use ScoreboardFile instead\n#\1\n#\n#ScoreboardFile\t\/var\/run\/proftpd\/proftpd.scoreboard\n#/i" $FTP_TMP
74 # Ubaci pravi hostname
75 CARNET_HOSTNAME=`hostname`
76 CARNET_DOMAINNAME=`hostname --domain`
77 sed -i -e "s/^ServerName.*\"Debian\"/ServerName \"$CARNET_HOSTNAME.$CARNET_DOMAINNAME\"/i" $FTP_TMP
80 sed -i -e 's/^#.*DelayEngine.*/DelayEngine on/i' $FTP_TMP
82 # Omoguci da bude standalone servis
83 sed -i -e 's/^\(ServerType.*\)inetd/\1standalone/' $FTP_TMP
84 update-inetd --disable ftp || true
85 db_set shared/proftpd/inetd_or_standalone "standalone"
91 # Dodaj TLS konfiguraciju ako je potrebna
94 if [ -f $FTP_TMP ]; then
95 cp-update proftpd-cn $FTP_TMP <<EOF
98 TLSLog /var/log/proftpd/tls.log
101 # Are clients required to use FTP over TLS when talking to this server?
104 # Server's certificate
105 TLSRSACertificateFile $SSL_CERT
106 TLSRSACertificateKeyFile $SSL_KEY
108 # CA the server trusts
109 #TLSCACertificateFile /etc/ftpd/root.cert.pem
111 # Authenticate clients that want to use FTP over TLS?
114 # Allow SSL/TLS renegotiations when the client requests them, but
115 # do not force the renegotations. Some clients do not support
116 # SSL/TLS renegotiations; when mod_tls forces a renegotiation, these
117 # clients will close the data connection, or there will be a timeout
118 # on an idle data connection.
119 TLSRenegotiate required off
125 # include za slucaj da sistemac nije prihvatio izmjene od Debiana
128 if [ -f $FTP_TMP ] ; then
129 if ! egrep -qi "^[[:space:]]*Include.*/etc/proftpd/modules.conf" $FTP_TMP ; then
130 printf "#\n# Includes required DSO modules. This is mandatory in proftpd 1.3\n#\nInclude\t/etc/proftpd/modules.conf\n\n" >$FTP_TMP.tmp.$$
131 cat $FTP_TMP >>$FTP_TMP.tmp.$$
132 cp_mv $FTP_TMP.tmp.$$ $FTP_TMP
137 # Generiranje SSL certifikata
140 if [ \( ! -f $SSL_CERT \) -o \( ! -f $SSL_KEY \) ] ; then
141 echo "CN: Generating SSL certificate... "
142 HOSTNAME=`hostname -s`
144 MAILNAME=`cat /etc/mailname 2> /dev/null || hostname -f`
145 (openssl req -new -x509 -days 365 -nodes -out $SSL_CERT -keyout $SSL_KEY >/dev/null 2>&1 <<EOF
150 $hostname.$domainname
155 echo "CN: Self-signed SSL certificate generated in $SSL_CERT."
156 echo "CN: Please note that the certificate will expire in one year."
160 # purge starog proftpd-common paketa bi napravio rusvaj
163 if [ -f /var/lib/dpkg/info/proftpd-common.postrm ]; then
164 cp_check_and_sed '^[^#]*(update-rc.d|update-inetd|/var/run/proftpd)' \
165 '/update-rc.d/d; /update-inetd/d; /var\/run\/proftpd/d' \
166 /var/lib/dpkg/info/proftpd-common.postrm || true
178 echo "CN: Proftpd-cn is configured with disabled anonymous FTP access,"
179 echo "CN: for the security reasons."
182 if ! cmp -s $FTP_TMP $FTP_CONF; then
183 echo "CN: Original configuration file is saved in $FTP_OLD."
184 cp_mv $FTP_TMP $FTP_CONF
189 echo "CN: Restarting proftpd..."
191 if [ -x /usr/sbin/invoke-rc.d ]; then
192 invoke-rc.d proftpd restart
194 /etc/init.d/proftpd restart
197 # dh_installdeb will replace this with shell code automatically
198 # generated by other debhelper scripts.