proftpd+mysql+quota+vbb完善实现根据金钱购买的流量来下载FTP资源
1 引用材料:
A 现在网上流行的proftpd+mysql+quota教程。
B www.plusxp.net提供的vbb结合的HACK。
2 proftpd+mysql+quota可以参考:
http://www.avfox.com/forumdisplay.php?s=&forumid=11
3 和VBB结合的HACK,可以参考:
http://www.plusxp.net/cgi-bin/download1.cgi
4 我的proftpd.conf的配置文档,当然可能以后会改进:
ServerName "www.avfox.com"
ServerType standalone
DefaultServer on
ServerIdent off
Port 21
Umask 022
MaxLoginAttempts 3
TimeoutLogin 120
TimeoutIdle 600
TimeoutNoTransfer 900
TimeoutStalled 3600
RootLogin on
MaxClients 500
MaxClientsPerHost 1
MaxClientsPerUser 20
AllowOverwrite on
AllowStoreRestart on
AllowRetrieveRestart on
UseReverseDNS off
RequireValidShell off
DefaultRoot ~ FTPUSR
DefaultRoot ~ FTPGRP
MaxInstances 30
User FTPUSR
Group FTPGRP
SQLConnectInfo FTP@localhost root ********
SQLAuthTypes Backend Plaintext
SQLUserInfo FTPUSERS userid passwd uid gid homedir shell
SQLGroupInfo FTPGRPS groupname gid members
SQLAuthenticate users groups usersetfast groupsetfast
SQLHomedirOnDemand on
QuotaDirectoryTally on
QuotaDisplayUnits "Kb"
QuotaEngine on
QuotaLog "/var/log"
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 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 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}'" quotatallies
SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" quotatallies
QuotaLimitTable sql:/get-quota-limit
QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally
3 我的buy_byte.php文档:
- <?php
- $myver = "v1.00";
- $version = "返回论坛";
- $PlusName = "FTP中心";
- $MaxAllowIP = 2; # 最多允许的IP
- $PerGBSize = 1024 * 1024 * 1000; # 每GB文件的大小(Bytes)
- $BuyMaxGB = 1000; # 允许购买下载量的最多GB数
- $NameAddStr = "avfox_";
- mt_srand ((double) microtime() * 1000000);
- $newpass = mt_rand(11111111,99999999);
- error_reporting(7);
- require("./global.php");
- $postinfo=getpostinfo($postid);
- $threadinfo=getthreadinfo($postinfo[threadid]);
- $foruminfo=getthreadinfo($threadinfo[forumid]);
- // check moderator permissions for getting ip
- if ($bbuserinfo[userid]==0) {
- show_nopermission();
- }
- $postinfo[hostaddress]=gethostbyaddr($ipaddress);
- // ############################### list FTP ###############################
- if ($action=="") {
- // $postid=verifyid("post",$postid);
- // updateftpforum($threadinfo['forumid']);
- //查FTP数据
- $ftplistbits = "";
- $perpage = 20;
- $limitlower=($pagenumber-1)*$perpage+1;
- $limitupper=($pagenumber)*$perpage;
- $counter=0;
- $ftpcount=$DB_site->query_first("SELECT COUNT(*) AS ftps FROM FTP_info");
- $ftptotal=$ftpscount[ftps];
- if ($limitupper>$totalftps) {
- $limitupper=$totalftps;
- if ($limitlower>$totalftps) {
- $limitlower=$totalftps-$perpage;
- }
- }
- if ($limitlower<=0) {
- $limitlower=1;
- }
- $ftps=$DB_site->query("SELECT * FROM FTP_info ORDER BY FTP_ItemName");
- $counter=0;
- while ($ftpinfo=$DB_site->fetch_array($ftps) and $counter++<$perpage) {
- eval("\$ftp_listbits .= "".gettemplate("ftp_listbits")."";");
- } // end while
- eval("dooutput("".gettemplate("ftp_list")."");");
- }
- // ############################### 修改密码 ###############################
- if ($action=="buy_pass") {
- $ftps=$DB_site->query("SELECT * FROM FTP_info where FTP_ID=$ftpid");
- $ftpinfo=$DB_site->fetch_array($ftps);
- $f_server=Trim($ftpinfo[FTP_SQLIP]).":".Trim($ftpinfo[FTP_SQLPort]);
- //$f_server=Trim($ftpinfo[FTP_SQLIP]);
- $DB_ftp=new DB_Sql_vb;
- $DB_ftp->appname='vbb_ftp';
- $DB_ftp->appshortname='vbb_ftp (forum)';
- $DB_ftp->database=Trim($ftpinfo[FTP_SQLDatabase]);
- $DB_ftp->server=$f_server;
- $DB_ftp->user=Trim($ftpinfo[FTP_SQLUser]);
- $DB_ftp->password=Trim($ftpinfo[FTP_SQLPass]);
- $DB_ftp->connect();
- $ftpuser=$NameAddStr.$bbuserinfo[username];
- $ftps2=$DB_ftp->query("SELECT * FROM quotalimits where name='$ftpuser'");
- $DB_ftp->query("UPDATE FTPUSERS SET passwd=$newpass WHERE userid='$ftpuser'");
- $buyerror="$ftpinfo[FTP_ItemName]上的密码已经改为【<normalfont color='blue'>".$newpass."</normalfont>】,请牢记! (注:密码是【】内8位蓝色数字,密码一分钟后生效)";
- eval("dooutput("".gettemplate("buy_error")."");");
-
- }
- // ############################### start 购买流量 ###############################
- if ($action=="buy_byte") {
- // $postid=verifyid("post",$postid);
- $ftps=$DB_site->query("SELECT * FROM FTP_info where FTP_ID=$ftpid");
- $ftpinfo=$DB_site->fetch_array($ftps);
- if($ftpinfo[FTP_Enable]==0) {
- $buyerror=$ftpinfo[FTP_ItemName]."目前关闭,无法购买流量!";
- eval("dooutput("".gettemplate("buy_error")."");");
- exit();
- }
- $f_server=Trim($ftpinfo[FTP_SQLIP]).":".Trim($ftpinfo[FTP_SQLPort]);
- //$f_server=Trim($ftpinfo[FTP_SQLIP]);
- $DB_ftp=new DB_Sql_vb;
- $DB_ftp->appname='vbb_ftp';
- $DB_ftp->appshortname='vbb_ftp (forum)';
- $DB_ftp->database=Trim($ftpinfo[FTP_SQLDatabase]);
- $DB_ftp->server=$f_server;
- $DB_ftp->user=Trim($ftpinfo[FTP_SQLUser]);
- $DB_ftp->password=Trim($ftpinfo[FTP_SQLPass]);
- $DB_ftp->connect();
- $ftpuser=$NameAddStr.$bbuserinfo[username];
- $ftps2=$DB_ftp->query("SELECT * FROM quotalimits where name='$ftpuser'");
- $ftpinfo2=$DB_ftp->fetch_array($ftps2);
- $ftps3=$DB_ftp->query("SELECT * FROM quotatallies where name='$ftpuser'");
- $ftpinfo3=$DB_ftp->fetch_array($ftps3);
- $GB_downover = intval($ftpinfo3[bytes_out_used] / $PerGBSize);
- $GB_down = intval($ftpinfo2[bytes_out_avail] / $PerGBSize);
- $GB_moneycheck = $DB_site->query_first("SELECT money FROM user WHERE userid=$bbuserinfo[userid]");
- $GB_money = $GB_moneycheck[money];
- $GB_buy = intval($GB_money / $ftpinfo[FTP_BuyPrice]);
- if($GB_buy>($BuyMaxGB-$GB_down)){$GB_buy=($BuyMaxGB-$GB_down);}
- $ipaddress=getenv("REMOTE_ADDR");
- $ipadd=explode(".",trim($ipaddress));
-
- // updateftpforum($threadinfo['forumid']);
- eval("dooutput("".gettemplate("buy_byte")."");");
- }
- // ###################### 购买确认 #######################
- if ($action=="buy_bytechanged") {
- $ftps=$DB_site->query("SELECT * FROM FTP_info where FTP_ID=$ftpid");
- $ftpinfo=$DB_site->fetch_array($ftps);
- $f_server=Trim($ftpinfo[FTP_SQLIP]).":".Trim($ftpinfo[FTP_SQLPort]);
- $DB_ftp=new DB_Sql_vb;
- $DB_ftp->appname='vbb_ftp';
- $DB_ftp->appshortname='vbb_ftp (forum)';
- $DB_ftp->database=Trim($ftpinfo[FTP_SQLDatabase]);
- $DB_ftp->server=$f_server;
- $DB_ftp->user=Trim($ftpinfo[FTP_SQLUser]);
- $DB_ftp->password=Trim($ftpinfo[FTP_SQLPass]);
- $DB_ftp->connect();
- $ftpuser=$NameAddStr.$bbuserinfo[username];
- $ftps2=$DB_ftp->query("SELECT * FROM quotalimits where name='$ftpuser'");
- $ftpinfo2=$DB_ftp->fetch_array($ftps2);
- $ftps3=$DB_ftp->query("SELECT * FROM quotatallies where name='$ftpuser'");
- $ftpinfo3=$DB_ftp->fetch_array($ftps3);
- $GB_downover = intval($ftpinfo3[bytes_out_used] / $PerGBSize);
- $GB_down = intval($ftpinfo2[bytes_out_avail] / $PerGBSize);
- $GB_moneycheck = $DB_site->query_first("SELECT money,usergroupid FROM user WHERE userid=$bbuserinfo[userid]");
- //$GB_moneycheck=$DB_site->fetch_array($GB_moneychecks);
- $GB_money = $GB_moneycheck[money];
- $GB_buy = intval($GB_money / $ftpinfo[FTP_BuyPrice]);
- if($GB_buy>($BuyMaxGB-$GB_down)){$GB_buy=($BuyMaxGB-$GB_down);}
- $donate=$donate+0;
- if($donate=='' or $donate<=0) {
- $buyerror="你没有输入任何数字!";
- eval("dooutput("".gettemplate("buy_error")."");");
- exit();
- }
- if(!is_int($donate)) {
- $buyerror="你输入的不是整数!";
- eval("dooutput("".gettemplate("buy_error")."");");
- exit();
- }
- if($donate > $GB_buy) {
- $buyerror="资金不足,或你已超过购买量,无法购买!";
- eval("dooutput("".gettemplate("buy_error")."");");
- exit();
- }
- if($donate > $BuyMaxGB) {
- $buyerror="对不起,FTP最多只允许购买 $BuyMaxGB GB的流量!";
- eval("dooutput("".gettemplate("buy_error")."");");
- exit();
- }
- $f_server=Trim($ftpinfo[FTP_SQLIP]).":".Trim($ftpinfo[FTP_SQLPort]);
- //$f_server=Trim($ftpinfo[FTP_SQLIP]);
- $ftpuser=$NameAddStr.$bbuserinfo[username];
- // $ftpcount=$DB_ftp->query_first("SELECT COUNT(*) AS usercc,bytes_out_avail FROM quotalimits where name='$ftpuser'");
- // $usercount=$ftpcount[usercc];
- $ftpcount=$DB_ftp->query_first("SELECT name,bytes_out_avail FROM quotalimits where name='$ftpuser'");
- $username=$ftpcount[name];
- $userdown=$ftpcount[bytes_out_avail];
- $ftpgroups=$DB_site->query_first("SELECT Group_ftpname FROM FTP_group WHERE Group_vbbid='$GB_moneycheck[usergroupid]' and Group_ftpid='$ftpid' ");
- $ftpgroup=$ftpgroups[Group_ftpname];
- if($ftpgroup==''){
- $buyerror="你没有权利购买密码!可能是你的帐号还没有被激活!";
- eval("dooutput("".gettemplate("buy_error")."");");
- exit();
- }
- //$DB_sice->query("UPDATE FTP_info SET FTP_Click='$ftpinfo[FTP_Click]+1',FTP_BuyTotal='$ftpinfo[FTP_BuyTotal]+$donate' WHERE FTP_ID='$ftpid'");
- $DB_site->query("UPDATE FTP_info SET FTP_Click=FTP_Click+1,FTP_BuyTotal=FTP_BuyTotal+$donate WHERE FTP_ID='$ftpid'");
- if($username==''){
- $ipaddress=getenv("REMOTE_ADDR");
- $ipadd=explode(".",trim($ipaddress));
- $DB_ftp->query("INSERT INTO FTPUSERS (userid,passwd,uid, gid, homedir, shell) VALUES ('$ftpuser', '$newpass','2001','2001','/home/FTP/film','')");
- $DB_ftp->query("INSERT INTO quotalimits (`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`) VALUES ('$ftpuser', 'user', 'false', 'soft', '0', $donate*$PerGBSize, '0', '0', '0', '0')");
- $eventid = $DB_ftp->insert_id();
- $passmessage="<b>【<normalfont%20color=blue>".$newpass."</normalfont>】</b>请牢记此密码,此密码只能在本FTP上使用,为确保您的FTP密码不被盗用,此密码今后将只能修改不能查询!(注:密码是【】内8位蓝色数字)";
- $DB_site->query("UPDATE user SET money=(money-$donate*$ftpinfo[FTP_BuyPrice]) WHERE userid=$bbuserinfo[userid]");
- }else{
- $DB_ftp->query("UPDATE quotalimits SET bytes_out_avail=($userdown+$donate*$PerGBSize) WHERE name='$ftpuser'");
- $passmessage="<normalfont%20color=blue>您的FTP密码为您以前使用的密码,如您忘记该密码,请在前一窗口修改!";
- $DB_site->query("UPDATE user SET money=(money-$donate*$ftpinfo[FTP_BuyPrice]) WHERE userid=$bbuserinfo[userid]");
- }
- $GB_money=$GB_money-$donate*$ftpinfo[FTP_BuyPrice];
- $ftps2=$DB_ftp->query("SELECT * FROM quotalimits where name='$ftpuser'");
- $ftpinfo2=$DB_ftp->fetch_array($ftps2);
- $ftps3=$DB_ftp->query("SELECT * FROM quotatallies where name='$ftpuser'");
- $ftpinfo3=$DB_ftp->fetch_array($ftps3);
-
- $GB_downover = intval($ftpinfo3[bytes_out_used] / $PerGBSize);
- $GB_down = intval($ftpinfo2[bytes_out_avail] / $PerGBSize);
- Header("Location: buy_byte.php?action=buy_bytemessage&s=$session[sessionhash]&ftpid=$ftpinfo[FTP_ID]&donate2=$donate&GB_money=$GB_money&passmessage=$passmessage");
- }
- // ############################### 显示购买成功! ###############################
- if ($action=="buy_bytemessage") {
- $ftps=$DB_site->query("SELECT * FROM FTP_info where FTP_ID=$ftpid");
- $ftpinfo=$DB_site->fetch_array($ftps);
- $f_server=Trim($ftpinfo[FTP_SQLIP]).":".Trim($ftpinfo[FTP_SQLPort]);
- $DB_ftp=new DB_Sql_vb;
- $DB_ftp->appname='vbb_ftp';
- $DB_ftp->appshortname='vbb_ftp (forum)';
- $DB_ftp->database=Trim($ftpinfo[FTP_SQLDatabase]);
- $DB_ftp->server=$f_server;
- $DB_ftp->user=Trim($ftpinfo[FTP_SQLUser]);
- $DB_ftp->password=Trim($ftpinfo[FTP_SQLPass]);
- $DB_ftp->connect();
- $ftpuser=$NameAddStr.$bbuserinfo[username];
- $ftps2=$DB_ftp->query("SELECT * FROM quotalimits where name='$ftpuser'");
- $ftpinfo2=$DB_ftp->fetch_array($ftps2);
- $ftps3=$DB_ftp->query("SELECT * FROM quotatallies where name='$ftpuser'");
- $ftpinfo3=$DB_ftp->fetch_array($ftps3);
-
- $GB_downover = intval($ftpinfo3[bytes_out_used] / $PerGBSize);
- $GB_down = intval($ftpinfo2[bytes_out_avail] / $PerGBSize);
-
- eval("dooutput("".gettemplate("buy_message")."");");
-
-
- }
- // ############################### 修改IP地址 ###############################
- if ($action=="buy_ipchanged") {
- if($allowip==''){
- $buyerror="你没有输入任何IP地址!";
- eval("dooutput("".gettemplate("buy_error")."");");
- exit();
- }
- $allowip2=explode("\n",$allowip);
- $counter=-1;
- while (++$counter < $MaxAllowIP){
- $allowip3=explode(".",trim($allowip2[$counter]));
- $allowip4=$allowip4.trim($allowip2[$counter])."\n";
- if (!($allowip3[0]>=0 and $allowip3[0]<=255) or !($allowip3[1]>=0 and $allowip3[1]<=255) or $allowip3[0]=='*' or $allowip3[1]=='*'){
- $buyerror="你输入的IP地址不正确或范围有误!";
- eval("dooutput("".gettemplate("buy_error")."");");
- exit();
- }
- }
- $ftps=$DB_site->query("SELECT * FROM FTP_info where FTP_ID=$ftpid");
- $ftpinfo=$DB_site->fetch_array($ftps);
- $f_server=Trim($ftpinfo[FTP_SQLIP]).":".Trim($ftpinfo[FTP_SQLPort]);
- $DB_ftp=new DB_Sql_vb;
- $DB_ftp->appname='vbb_ftp';
- $DB_ftp->appshortname='vbb_ftp (forum)';
- $DB_ftp->database=Trim($ftpinfo[FTP_SQLDatabase]);
- $DB_ftp->server=$f_server;
- $DB_ftp->user=Trim($ftpinfo[FTP_SQLUser]);
- $DB_ftp->password=Trim($ftpinfo[FTP_SQLPass]);
- $DB_ftp->connect();
- $ftpuser=$NameAddStr.$bbuserinfo[username];
- $ftps2=$DB_ftp->query("SELECT * FROM quotalimits where name='$ftpuser'");
- $DB_ftp->query("UPDATE FTPUSERS SET FAllow_IP='$allowip4' WHERE userid='$ftpuser'");
- $buyerror="$ftpinfo[FTP_ItemName]上允许的 IP 段已改为:<textarea cols=60 rows=$MaxAllowIP name='allowip'>$allowip4</textarea>";
- eval("dooutput("".gettemplate("buy_error")."");");
- }
- ?>
复制代码
4 相关改变的模板请自选修改
5 演示站点
http://www.avfox.com
6 还有很多功能需要更多的人来完善。 |