#
# /etc/proftpd.conf -- This is a basic ProFTPD configuration file.
# To really apply changes reload proftpd after modifications.
# 

ServerName			"%v"
ServerType			standalone
DeferWelcome			on

DefaultRoot			~

MultilineRFC2228		on
DefaultServer			on
ShowSymlinks			on

TimeoutNoTransfer		600
TimeoutStalled			600
TimeoutIdle			1200

DisplayLogin                    welcome.msg
DisplayFirstChdir               .message
ListOptions                	"-l"

DenyFilter			\*.*/

# Uncomment this if you are using NIS or LDAP to retrieve passwords:
#PersistentPasswd		off

# Uncomment this if you would use TLS module:
#TLSEngine 			on

# Uncomment this if you would use quota module:
#Quotas				on

# Uncomment this if you would use ratio module:
#Ratios				on

# Port 21 is the standard FTP port.
Port				21

# Normally, when contacted, ProFTPd checks back the client on port 113
# (sending the username/password in CLEAR TEXT!). This may be turned off.
IdentLookups			off

# To prevent DoS attacks, set the maximum number of child processes
# to 30.  If you need to allow more than 30 concurrent connections
# at once, simply increase this value.  Note that this ONLY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd)
MaxInstances			20

# Set the user and group that the server normally runs at.
#User				nobody
#Group				nogroup
User				ftp
Group				users

# Umask 022 is a good standard umask to prevent new files and dirs
# (second parm) from being group and world writable.
Umask				022  022

# Normally, we want files to be overwriteable.
AllowOverwrite			on

# Delay engine reduces impact of the so-called Timing Attack described in
# http://security.lss.hr/index.php?page=details&ID=LSS-2004-10-02
# It is on by default. 
#DelayEngine 			off

# Performance, let's do DNS resolution when we process the logs...
UseReverseDNS        		off

# Where do we put the pid files?
ScoreboardFile                  /var/run/proftpd.score

# Logging options
TransferLog                     /var/log/xferlog

# Some logging formats
LogFormat         default "%h %l %u %t \"%r\" %s %b"
LogFormat         auth    "%v [%P] %h %t \"%r\" %s"
LogFormat         write   "%h %l %u %t \"%r\" %s %b"


<Global>

# SQL stuff (added by Serdica Software - Grigor)

# databasename@host database_user user_password
SQLConnectInfo                  virtual-users@localhost ftp catalog

SQLAuthTypes			Backend Plaintext
SQLAuthenticate                 users groups

# Here we tell ProFTPd the names of the database columns in the "usertable"
# we want it to interact with. Match the names with those in the db
# Table structure:              tablename username password uid gid homedir shell
SQLUserInfo                     ftp_users username password uid gid homedir NULL

# Default homedir for ALL users (use only if SQLUserInfo homedir is NULL above)
#SQLDefaultHomedir		"/tmp"

# Allow users even if we have no valid shell info for them?
# Must be off if SQLUserInfo shell is NULL above.
RequireValidShell		off

# Here we tell ProFTPd the names of the database columns in the "grouptable"
# we want it to interact with. Again the names match with those in the db.
SQLGroupInfo                    ftp_groups groupname gid members

# set min UID and GID - otherwise these are 999 each
SQLMinID                        100

# (don't) create a user's home directory on demand if it doesn't exist
SQLHomedirOnDemand		off




# User quotas
# ===========
QuotaEngine			on
QuotaDirectoryTally		on
QuotaDisplayUnits		Mb
QuotaShowQuotas			on

SQLNamedQuery get-quota-limit SELECT "name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avail, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail FROM ftp_quotalimits WHERE name = '%{0}' AND quota_type = '%{1}'"

SQLNamedQuery get-quota-tally SELECT "name, quota_type, bytes_in_used, bytes_out_used, bytes_xfer_used, files_in_used, files_out_used, files_xfer_used FROM ftp_quotatallies WHERE name = '%{0}' AND quota_type = '%{1}'"

SQLNamedQuery update-quota-tally UPDATE "bytes_in_used = bytes_in_used + %{0}, bytes_out_used = bytes_out_used + %{1}, bytes_xfer_used = bytes_xfer_used + %{2}, files_in_used = files_in_used + %{3}, files_out_used = files_out_used + %{4}, files_xfer_used = files_xfer_used + %{5} WHERE name = '%{6}' AND quota_type = '%{7}'" ftp_quotatallies

SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" ftp_quotatallies

QuotaLimitTable sql:/get-quota-limit
QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally

RootLogin 			off
RequireValidShell		off

SQLLog                          RETR,STOR insertfileinfo
SQLNamedQuery                   insertfileinfo UPDATE "bytes=bytes+'%b' where username='%u'" users

SQLDefaultUID                   5000       # [VMAIL-UID]
SQLDefaultGID                   5000       # [VMAIL-GID]

</Global>

# A basic anonymous configuration, no upload directories.

# <Anonymous ~ftp>
#   User				ftp
#   Group				nogroup
#   # We want clients to be able to login with "anonymous" as well as "ftp"
#   UserAlias			anonymous ftp
#   # Cosmetic changes, all files belongs to ftp user
#   DirFakeUser	on ftp
#   DirFakeGroup on ftp
# 
#   RequireValidShell		off
# 
#   # Limit the maximum number of anonymous logins
#   MaxClients			10
# 
#   # We want 'welcome.msg' displayed at login, and '.message' displayed
#   # in each newly chdired directory.
#   DisplayLogin			welcome.msg
#   DisplayFirstChdir		.message
# 
#   # Limit WRITE everywhere in the anonymous chroot
#   <Directory *>
#     <Limit WRITE>
#       DenyAll
#     </Limit>
#   </Directory>
# 
#   # Uncomment this if you're brave.
#   # <Directory incoming>
#   #   # Umask 022 is a good standard umask to prevent new files and dirs
#   #   # (second parm) from being group and world writable.
#   #   Umask				022  022
#   #            <Limit READ WRITE>
#   #            DenyAll
#   #            </Limit>
#   #            <Limit STOR>
#   #            AllowAll
#   #            </Limit>
#   # </Directory>
# 
# </Anonymous>
