电脑技术学习

pure-ftpd + mysql.......Management 安装配置实例

dn001
from: http://bbs.bsdbase.com/index.php?s=&act=ST&f=1&t=224&st=0&#entry307

代码:

################## pure-ftpd ###########################

Aborigen Yin
tutu@bsdbase.com
2003.06.07

pure-ftpd + mysql + PureFTP PHP User Management 安装配置实例

FreeBSD 4.8 stable

#mysql apache请自行安装。
#文档中的一些路径是我的环境中使用的,请自行修改以符合你的实际情况;

#相关网址:
http://www.pureftpd.org (国内可能无法访问)
http://sourceforge.net/projects/pureftpd/ (国内现在可以访问了)

8.1.安装
cd /usr/local/src/distfiles
##172.16.100.245是我的文件服务器
wget ftp://172.16.100.245/pub/distfiles/pure-ftpd-1.0.14.tar.gz
tar xfz pure-ftpd-1.0.14.tar.gz -C ..
cd ../pure-ftpd-1.0.14
mkdir -p /usr/local/modules/support/pure-ftpd/etc
mkdir -p /usr/local/modules/support/pure-ftpd/var/run
mkdir -p /usr/local/modules/support/pure-ftpd/var/log
#用puredb;
#使用英文,WITH_LANG=simplifIEd-chinese可以使用简体中文,不过在某些情况下,你可能更希望看到英文;

./configure --prefix=/usr/local/modules/support/pure-ftpd
--with-everything
--with-diraliases
--with-paranoidmsg
--with-virtualchroot
--without-shadow
--with-welcomemsg
--with-quotas
--with-sysquotas
--without-inetd
--without-banner
--with-uploadscript
--with-mysql=/usr/local/modules/support/mysql

#安装程序好象“忘记”这两个文件了
cp configuration-file/pure-ftpd.conf /usr/local/modules/support/pure-ftpd/etc
cp configuration-file/pure-config.pl /usr/local/modules/support/pure-ftpd/sbin
chmod 755 /usr/local/modules/support/pure-ftpd/sbin/pure-config.pl

8.2.配置主配置文件
#程序在/usr/local/modules/support/pure-ftpd/sbin/pure-ftpd,配置文件在/usr/local/modules/support/pure-ftpd/etc/pure-ftpd.conf
#注意一下参数,配置文件中默认的文件位置不对(其实放哪里看自己喜欢罢了);
#vi /usr/local/modules/support/pure-ftpd/etc/pure-ftpd.conf

#begin of pure-ftpd.conf
############################################################
# #
# Configuration file for pure-ftpd wrappers #
# #
############################################################
ChrootEveryone yes
BrokenClientsCompatibility yes
MaxClientsNumber 150
Daemonize yes
MaxClientsPerIP 20
VerboseLog no
DisplayDotFiles no
AnonymousOnly no
NoAnonymous no
SyslogFacility ftp
DontResolve yes
MaxIdleTime 5
MySQLConfigFile /usr/local/modules/support/pure-ftpd/etc/pureftpd-mysql.conf
#PureDB /usr/local/modules/support/pure-ftpd/etc/pureftpd.pdb
LimitRecursion 2000 8
AnonymousCanCreateDirs no
MaxLoad 4
PassivePortRange 40000 50000
#ForcePassiveIP 192.168.0.1
AntiWarez yes
# Bind 127.0.0.1,21
#AnonymousBandwidth 50
# UserBandwidth 8
Umask 133:022
#MinUID 100
MinUID 100
AllowUserFXP yes
AllowAnonymousFXP no
ProhibitDotFilesWrite no
ProhibitDotFilesRead no
AutoRename no
AnonymousCantUpload yes
#NoChmod yes
#Quota 1000:10
PIDFile /usr/local/modules/support/pure-ftpd/var/run/pure-ftpd.pid
AltLog w3c:/usr/local/modules/support/pure-ftpd/var/log/pure-ftpd-w3c.log
MaxDiskUsage 95
CustomerProof yes
#end of pure-ftpd.conf

###日志设置
###没有这一行,ftp日志就会发到/var/log/messages,很讨厌的说。
echo "ftp.* /usr/local/modules/support/pure-ftpd/var/log/pure-ftpd.log" >> /etc/syslog.conf
###
touch /usr/local/modules/support/pure-ftpd/var/log/pure-ftpd-w3c.log
touch /usr/local/modules/support/pure-ftpd/var/log/pure-ftpd.log

#使日志设置生效;
killall -HUP syslogd

#####
#用phpMyAdmin 创建用户配置 ###
user:pureftpd@localhost
passwd:wahaha
database:pureftpd

################为了使用 PureFTPD PHP User Management #####
###mysql 的设置是按照PureFTPD PHP User Management的readme作的。
##
################
http://www.solariz.de
http://www.solariz.de/Ffiledb/filedb.php?action=category&id=1

http://www.solariz.de/Ffiledb/download.php?id=1


#mysql 配置文件。
#vi /usr/local/modules/support/pure-ftpd/etc/pureftpd-mysql.conf
#
# If you want to use the Socket connect methode comment out the
# Lines with MMYSQLServer and MYSQLPort.
# If you want to use the Port methode comment out the MYSQLSocket line
#MYSQLSocket /var/lib/mysql/mysql.sock
MYSQLServer localhost
MYSQLPort 3306
MYSQLUser pureftpd
MYSQLPassWord wahaha
MYSQLDatabase pureftpd
MYSQLCrypt cleartext
MYSQLGetPW SELECT Password FROM ftpd WHERE User="L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MYSQLGetUID SELECT Uid FROM ftpd WHERE User="L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MYSQLGetGID SELECT Gid FROM ftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MYSQLGetDir SELECT Dir FROM ftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MySQLGetBandwidthUL SELECT ULBandwidth FROM ftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MySQLGetBandwidthDL SELECT DLBandwidth FROM ftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MySQLGetQTASZ SELECT QuotaSize FROM ftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MySQLGetQTAFS SELECT QuotaFiles FROM ftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
#end of mysql configure.



#####数据库初始化 ####用phpmyadmin 执行
use pureftpd;
DROP TABLE IF EXISTS ftpd;
CREATE TABLE ftpd (
User varchar(16) NOT NULL default '',
status enum('0','1') NOT NULL default '0',
Password varchar(64) NOT NULL default '',
Uid varchar(11) NOT NULL default '-1',
Gid varchar(11) NOT NULL default '-1',
Dir varchar(128) NOT NULL default '',
ULBandwidth smallint(5) NOT NULL default '0',
DLBandwidth smallint(5) NOT NULL default '0',
comment tinytext NOT NULL,
ipaccess varchar(15) NOT NULL default '*',
QuotaSize smallint(5) NOT NULL default '0',
QuotaFiles int(11) NOT NULL default 0,
PRIMARY KEY (User),
UNIQUE KEY User (User)
) TYPE=MyISAM;
####

####
8.5.虚拟用户管理

#为匿名用户设置帐户,必须有一个系统帐户ftp,匿名ftp才会生效;
#ftp用户的主目录就是匿名ftp的根;
#匿名ftp是为ftp://ftp.anti-spamming.com这个匿名服务器服务的;
userdel ftp
groupdel ftp
groupadd ftp
useradd -g ftp ftp

#虚拟用户统一用这个帐号和组;
pw groupadd virtual
mkdir -p /data/home/virtual
pw useradd virtual -g virtual -d /data/home/virtual -s /sbin/nologin
chown -R virtual:virtual /data/home/virtual
#为了方便管理,clone一个可以登陆的virtual帐号:
#vipw
virtual:x:503:503::/data/home/virtual:/sbin/nologin
vvuser:x:503:503::/data/home/virtual:/bin/sh
#end

#end
修改密码
passwd vvuser

################为了使用 PureFTPD PHP User Management #####
###mysql 的设置是按照PureFTPD PHP User Management的readme作的。
http://www.solariz.de
http://www.solariz.de/Ffiledb/filedb.php?action=category&id=1

http://www.solariz.de/Ffiledb/download.php?id=1
###
cd /usr/local/modules/support/apache/htdocs
fetch ftp://172.16.100.245/pub/distfiles/pureftpd_php_manager.tgz
tar xfz pureftpd_php_manager.tgz
rm -f pureftpd_php_manager.tgz
cd pureftpd_php_manager
#vi pureftp.config.php
<?php
######################
####### SETUP ########
######################

// Your exactly located mysql config file for pureftpd
//$PUREFTP_CONFIG_FILE = '/etc/pureftpd-mysql.conf';
$PUREFTP_CONFIG_FILE = '/usr/local/modules/support/pure-ftpd/etc/pureftpd-mysql.conf';

// The location where all the Forms directed to. (Mayby no change needed)
$SELF_URL = 'index.php';

// The location of your pure-ftpdwho binary (set this to chmod 4711)
//$FTP_WHO = "/usr/local/sbin/pure-ftpwho";
$FTP_WHO = "/usr/local/modules/support/pure-ftpd/sbin";

#######################
# DEFAULT NEW-USER PARAMS #
#######################

$DefaultUser = ""; # Default User Logon
$DefaultPass = ""; # Default User Password
$DefaultUid = "virtual"; # Default User ID ( must be a real user acct )
$DefaultGid = "virtual"; # Default Group ID ( must be a real group acct )
$DefaultDir = "/data/home/virtual"; # Default User Dir ( use /./ at the end to chroot )
$DefaultUL = "0"; # Default Upload Throttle ( 0 disables it )
$DefaultDL = "0"; # Default Download Throttle ( 0 disables it )
$Defaultip = "*"; # Default IP restrictions ( * = any IP )
$DefaultQS = "10240"; # Default Quota Size ( 0 disables it )
$Defaultcmt = "New ftp user"; # Default Comment for user

// UA
$DefaultQF = "10240"; # Default Quota Files ( 0 disables it )
$PWC = "55"; # Vorsatz fuerr Crypt Password
?>
#end


http://172.16.100.249:9180/pureftpd_php_manager

###############
NOTE:
If you want to use VirtualQuaotas your PureFTPD must be
compiled with the "--with-quotas" option.
Else it is better to comment out the line
beginning with MySQLGetQTASZ in the pureftpd-mysql.conf
file or some errors can occure while launching pureftpd.

2nd NOTE:
To set up the PureFTP Who display tool you must set chmod 4711
to yout pure-ftpwho command. Get sure that the Pure-FTPWho command
is executable in this Directory: /usr/local/sbin/
If this isn't the directory where you're binary is installed please setup a
symbolic Link. ln -s /usr/local/sbin/pure-ftpwho <path and name of your
pure-ftpwho file>


#################
##由于php_manager创建用户时并不创建对应的用户目录,使用如下脚本来进行用户创建工作,php_manager 只用于管理
#vi /usr/local/modules/support/pure-ftpd/bin/vvadduser

#!/bin/sh
#警告:没有任何错误检查
V_BASE="/data/home/virtual"
R_USER="virtual"
R_GROUP="virtual"

#set by user.
V_USERNAME=""
V_PASSWD=""

HTTP_ROOT="public_HTML"
HTTPS_ROOT="https"
HTTP_CGI="cgi-bin"
HTTPS_CGI="cgi-bins"
V_SETTINGS="settings"

MYSQL_HOME=/usr/local/modules/support/mysql
MYSQL_CLIENT=$MYSQL_HOME/bin/mysql

MYSQL_USER=GET_FROM_CFG
MYSQL_PASSWD=GET_FROM_CFG
MYSQL_DB=GET_FROM_CFG
MYSQL_HOST=GET_FROM_CFG
MYSQL_PORT=GET_FROM_CFG

PURE_TABLE=ftpd
PURE_MYSQL_CFG=/usr/local/modules/support/pure-ftpd/etc/pureftpd-mysql.conf
#PURE_PW="/usr/local/modules/support/pure-ftpd/bin/pure-pw"

MYSQL_USER=`grep -v '#' $PURE_MYSQL_CFG | grep '^MYSQLUser' | awk '{ print $2 }' `
if [ -z $MYSQL_USER ]
then
echo "Error:probe mysql user name from $PURE_MYSQL_CFG fail."
exit 1
fi

MYSQL_PASSWD=`grep -v '#' $PURE_MYSQL_CFG | grep '^MYSQLPassword' | awk '{ print $2 }' `
if [ -z $MYSQL_PASSWD ]
then
echo "Error:probe mysql password from $PURE_MYSQL_CFG fail."
exit 1
fi

MYSQL_DB=`grep -v '#' $PURE_MYSQL_CFG | grep '^MYSQLDatabase' | awk '{ print $2 }' `
if [ -z $MYSQL_DB ]
then
echo "Error:probe mysql database $PURE_MYSQL_CFG fail."
exit 1
fi

MYSQL_HOST=`grep -v '#' $PURE_MYSQL_CFG | grep '^MYSQLServer' | awk '{ print $2 }' `
if [ -z $MYSQL_HOST ]
then
echo "Error:probe mysql host from $PURE_MYSQL_CFG fail."
exit 1
fi

MYSQL_PORT=`grep -v '#' $PURE_MYSQL_CFG | grep '^MYSQLPort' | awk '{ print $2 }' `
if [ -z $MYSQL_PORT ]
then
echo "Error:probe mysql port from $PURE_MYSQL_CFG fail."
exit 1
fi

if [ -z $1 ]
then
#$PURE_PW mkdb
echo "Usage: $0 <Virtual user name>"
exit 1
fi

V_USERNAME=$1
O_TTY=`stty -g`
stty -echo
echo -n "Enter password for Virtual user $V_USERNAME:"
read _PW_A
echo -n "Enter password again:"
read _PW_B
stty $O_TTY
#echo "A=$_PW_A ,B=$_PW_B"
if [ "$_PW_A" != "$_PW_B" ]
then
echo "Error:Password mismatch."
exit 1
fi
V_PASSWD=$_PW_A

User=$V_USERNAME
Password=$V_PASSWD
Uid=$R_USER
Gid=$R_GROUP
# 0,for inactive,1 for active.
Dir="$V_BASE/$V_USERNAME/./"
status=0
# Default Upload Throttle ( 0 disables it )
ULThrottle=0
# Default Download Throttle ( 0 disables it )
DLThrottle=0
comment="New ftp user $V_USERNAME"
# Default IP restrictions ( * = any IP )
ipaccess="*"
# Default Quota Size ( 0 disables it )
QuotaSize=100
# Default Quota file count ( 0 disables it )
QuotaFiles=4096

MYSQL_CONN="$MYSQL_CLIENT --silent --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$MYSQL_USER --password=$MYSQL_PASSWD --database=$MYSQL_DB "
INSERT_USER="INSERT INTO $PURE_TABLE SET User='$User',status='$status',Password='$Password',Uid='$Uid',Gid='$Gid',Dir='$Dir',ULBandwidth='$ULThrottle',DLBandwidth='$DLThrottle',comment='$comment',ipaccess='$ipaccess',QuotaSize='$QuotaSize',QuotaFiles='$QuotaFiles';"
#No update support in adduser script.
UPDATE_USER="UPDATE $PURE_TABLE SET User='$User',status='$status',Password='$Password',Uid='$Uid',Gid='$Gid',Dir='$Dir',ULBandwidth='$ULThrottle',DLBandwidth='$DLThrottle',comment='$comment',ipaccess='$ipaccess',QuotaSize='$QuotaSize',QuotaFiles='$QuotaFiles';"

$MYSQL_CONN <<MADAY
$INSERT_USER
commit;

MADAY

if [ $? -ne 0 ]
then
echo "Error:Database insert fail."
echo "MYSQL_CONN=$MYSQL_CONN"
echo "INSERT_USER=$INSERT_USER"
echo "UPDATE_USER=$UPDATE_USER"
exit 1
fi

#END of mysql insert.
#$PURE_PW useradd $V_USERNAME -u $R_USER -d $V_BASE/$V_USERNAME
#更新puredb;
#$PURE_PW mkdb
mkdir -p $V_BASE/$V_USERNAME/$HTTP_ROOT
#http web cgi 目录;
mkdir -p $V_BASE/$V_USERNAME/$HTTP_CGI
#https web 根目录;
mkdir -p $V_BASE/$V_USERNAME/$HTTPS_ROOT
#http web cgi 目录;
mkdir -p $V_BASE/$V_USERNAME/$HTTPS_CGI
#虚拟用户设置、日志文件目录;
mkdir -p $V_BASE/$V_USERNAME/$V_SETTINGS
mkdir -p $V_BASE/$V_USERNAME/$V_SETTINGS/apache/log
mkdir -p $V_BASE/$V_USERNAME/$V_SETTINGS/apache/ca
chmod 777 $V_BASE/$V_USERNAME/$V_SETTINGS/apache/log
chown -R $R_USER:$R_GROUP $V_BASE/$V_USERNAME
if [ $status -eq 0 ]
then
echo "warning:User $V_USERNAME is inactive now,use PureFTP User PHP Management to modify it."
fi
echo "all over."
#end

chmod 755 /usr/local/modules/support/pure-ftpd/bin/vvadduser
ln -s /usr/local/modules/support/pure-ftpd/bin/vvadduser /usr/local/sbin

8.4.简单的启动关闭shell;
#vi /usr/local/modules/support/pure-ftpd/sbin/pure-config.pl
#指定pure-ftpd的位置。
my $PUREFTPD;
-x && ($PUREFTPD=$_, last) for qw(
#指定pure-ftpd的位置。
/usr/local/modules/support/pure-ftpd/sbin/pure-ftpd
);

#使用如下perl脚本将配置文件转化为命令行参数,并启动pure-ftpd;
/usr/local/modules/support/pure-ftpd/sbin/pure-config.pl /usr/local/modules/support/pure-ftpd/etc/pure-ftpd.conf

/usr/local/modules/support/pure-ftpd/sbin/pure-ftpd -A -b -c150 -B -C20 -fftp -H -I5 -lmysql:/usr/local/modules/support/pure-ftpd/etc/pureftpd-mysql.conf -L2000:8 -m4 -p40000:50000 -s -U133:022 -u100 -w -i -g/usr/local/modules/support/pure-ftpd/var/run/pure-ftpd.pid -Ow3c:/usr/local/modules/support/pure-ftpd/var/log/pure-ftpd-w3c.log -k95 -Z
##添加-4参数,可以使ftp只在tcpv4监听。

#开机自动执行的脚本:

#vi /usr/local/modules/support/pure-ftpd/bin/support-pure-ftpd-mgr.sh

#!/bin/sh
case "$1" in

start)
if [ -x /usr/local/modules/support/pure-ftpd/sbin/pure-config.pl ]; then
/usr/local/modules/support/pure-ftpd/sbin/pure-config.pl /usr/local/modules/support/pure-ftpd/etc/pure-ftpd.conf && echo 'Pure-ftpd server started.'
else
echo "Error:pure-config.pl can not exec."
exit 1
fi


stop)
kill `cat /usr/local/modules/support/pure-ftpd/var/run/pure-ftpd.pid 2>/dev/null` >/dev/nul 2>&1 && echo 'Pure-ftpd server stopped.'

restart)
echo .
echo Restart Pure-ftpd server ......
$0 stop
sleep 5
$0 start

*)
echo "$0 start | stop | restart"


esac
#end of support-pure-ftpd-mgr.sh

chmod 755 /usr/local/modules/support/pure-ftpd/bin/support-pure-ftpd-mgr.sh
ln -s /usr/local/modules/support/pure-ftpd/bin/support-pure-ftpd-mgr.sh /usr/local/sbin/
ln -s /usr/local/sbin/support-pure-ftpd-mgr.sh /usr/local/etc/rc.d

#end

标签: