Proftpd learning note (four)
Today we speak Proftp MySQL quota applications, I think everyone is about this.
1. First we build corresponding users and user groups
GroupAdd -g 5500 ftpgroup
Adduser -u 5500 -s / bin / false -d / bin / null -c "proFTPD user" -g ftpgroup ftpuser
2. Operating the database
MySQL mysql -uroot -ppassword
Create Database FTPDB
Grant SELECT, UPDATE ON fTPDB. * to proFTPD @ localhost identified by 'password'
Use ftpdb
Create Table `ftpgroup` (
`groupname` VARCHAR (16) Not null default '',
`Gid` Smallint (6) Not Null Default '5500',
`MEMBERS` VARCHAR (16) Not null default '',
Key `Groupname` (` Groupname`)
) TYPE = Myisam comment = 'proftp group table';
INSERT INTO `FTPGROUP` VALUES ('ftpgroup', 5500, 'ftpuser');
Create Table `ftpquotalimits`
`Name` VARCHAR (30) Default Null,
`Quota_Type` Enum ('user', 'group', 'class', 'all') Not null default 'user',
`per_session` Enum ('false', 'true') Not null default 'false',
`limit_type` Enum ('Soft', 'Hard') Not Null Default 'Soft',
`Bytes_in_avail` Float Not Null Default '0',
`Bytes_out_avail` Float Not Null Default '0',
`Bytes_xfer_avail` Float Not Null Default '0',
`files_in_avail` int (10) unsigned not null default '0',
`files_out_avail` int (10) unsigned not null default '0',
`Files_xfer_avail` int (10) unsigned not null default '0'
) TYPE = MyISAM;
Create Table `ftpquotatallies (
`Name` VARCHAR (30) Not null default ',
`Quota_Type` Enum ('user', 'group', 'class', 'all') Not null default 'user',` bytes_in_used` Float Not Null Default '0',
`bytes_out_used` Float Not Null Default '0',
`Bytes_xfer_used` Float Not Null Default '0',
`files_in_used` int (10) Unsigned Not Null Default '0',
`files_out_used` int (10) Unsigned Not Null Default '0',
`files_xfer_used` int (10) unsigned not null default '0'
) TYPE = MyISAM;
Create Table `ftpuser` (
`id` int (10) unsigned not null auto_increment,
`Userid` VARCHAR (32) Not null default ',
`Passwd` VARCHAR (32) Not null default '',
`uid` smallint (6) Not null default '5500',
`Gid` Smallint (6) Not Null Default '5500',
`Homedir` VARCHAR (255) Not null default ',
`shell` Varchar (16) Not null default '/ sbin / nologin',
`count` int (11) Not null default '0',
`Accessed` DateTime Not Null Default '0000-00-00 00:00:00',
`Modified` DateTime Not Null Default '0000-00-00 00:00:00',
PRIMARY Key (`ID)
) TYPE = Myisam comment = 'proftp user table';
Note that everyone fills in the username and password of its own database according to the actual situation. If you are not familiar with the database, you can use phpMyAdmin to operate.
3. Configure the Proftp file
ServerName "Frank's FTP Server" Servertype Standalone Default Server ON
Port 21
Umask 022
MaxInstances 30
MaxLoginatTempts 3
User Nobody
Group nobody
Maxhostsperuser 1 "Sorry, You May Not Connect More Time Time."
MaxClientSper 2 "Only One Such User At A Time."
MaxClientSperhost 3 "Sorry, You May Not Connect More One Time." ROOTLOGIN OFF
Requirevalidshell Off
TimeOutstalled 10
MaxClients 10
AllowForeignAddress on
ALLOWSTORERESTART ON
ServerIdent Off
Defaultroot ~ ftpgroup
SQLAUTHTYPES BACKEND PLAINTEXT
#Backend represents the authentication method for the user authentication method for the mysql database
#Plaintext indicates the way of expressing the appropriation, the most in the first way is the way.
SQLAUTHENTICATE * GROUPS *
# DatabaseName @ Host Database_User User_password
SqlConnectinfo ftpdb @ localhost proFTPD Password
SQLUSERINFO FTPUSER USERID Passwd Uid Gid Homedir Shell
SqlgroupInfo ftpgroup groupname gid members
Sqlhomedirondemand on
# If the user main directory does not exist, the system will create a directory based on the value of this user in the user data table.
# Update Count Every Time User Logs in
SQLLog Pass UpdateCount
SqlnamedQuery UpdateCount Update "Count = Count 1, Accessed = now () Where userid = '% u'" ftpuser
# Update Modified Everytime User Uploads or deletes a file
SQLLOG Stor, Dele Modified
SQLNAMEDQUERY Modified Update "Modified = now () Where userid = '% u'" ftpuser
QuotaEngine ON
QuotadirectoryTALLY ON
QuotadisplayUnits MB
Quotashowquotas on
Quotalog "/ var / log / quota"
SQLNAMEDQUERY GET-Quota-Limit Select "Name, quota_type, per_session, limited_type, bytes_in_avail, bytes_out_avai
L, Bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail from fpquotalimits 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_i
n_used, files_out_used, files_xfer_used from ftpquotatallies 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}' "ftpquota
Tallies
SqlnamedQuery INSERT-quota-Tally Insert "% {0},% {1},% {2},% {3},% {4},% {5},% {6},% {7}" ftpquotatallies
QuotalimitTable SQL: / GET-Quota-Limit
QuotatallyTable SQL: / GET-quota-Tally / update-quota-tally / insert-quota-tally
OK, it's as simple, restart the PROFTP service can already use the function of ProftP MySQL Quota
We can add a virtual user in the database FTPUser,
INSERT INTO `FTPUSER` VALUES (1, 'Test', 'ftppasswd', 5500, 5500, '/ home / test', '/ sbin / nologin');
Everyone can add a user directly in PHPMYADMIN. I believe how to teach everyone.
If you want to set Quota, just set up in the ftpquotalimits table, the various parameters in this table represent:
Quotalimits table
Name: - User account
Quota Type: - User, Group, Class, All (We Use User)
Per_Session: - True Or False (We Use true)
LIMIT_TYPE: - Hard limit OR soft limit (we generally use hard limit)
BYTES_IN_AVAIL: - Allows the number of bytes to be uploaded
BYTES_OUT_AVAIL: - Allow the number of bytes to be downloaded
BYTES_XFER_AVAIL: - Allowed bytes (including upload / download)
FILES_IN_AVAIL: - Allows the number of files to be uploaded
FILES_OUT_AVAIL: - Allow downloaded files
FILES_XFER_AVAIL: - Allows the number of files (including upload / download)
Honestly use the MySQL and Quota modules to verify the user and set disk limit, but I always feel that it is not perfect, because in this method, there is no field of permissions in the database table, so I say that the authority of the corresponding user is actually used. The user is Mysql corresponding to the UID and GID to control the permissions. If the mysql database can completely control the permissions.
If you feel that you feel the format copy, you may go wrong, you may wish to download my profile and database table directly.
Download Proftpd.conf
Download ftpdb.sql