pureftpd+web界面管理
时间:2007-03-29 来源:manyan1985
1:安装pureftpd pw groupadd ftpusers -g 1001 pw adduser ftpusers -u 1001 -g ftpusers -d /usr/www -s /sbin/nologin chown ftpusers:ftpusers /usr/www ##其中用户、组、/usr/www等可根据自己的实际情况选择 tar jxvf pure-ftpd-1.0.20.tar.bz2 cd pure-ftpd-1.0.20 ./configure --prefix=/usr/local/pureftpd --with-mysql --with-paranoidmsg --with-shadow --with-welcomemsg --with-uploadscript --with-quotas --with-cookie --with-virtualhosts --with-virtualroot --with-diraliases --with-sysquotas --with-ratios --with-ftpwho --with-throttling --with-altlog --with-language=simplified-chinese make make install ######################################### 以前用pureftpd的时候还不知道最好用ports安装,所以一直自己编译安装,现在要装,最好用ports安装。 cd /usr/ports/ftp/pure-ftpd ee Makefile 改成这样就行了:
CODE:
[Copy to clipboard]
CONFIGURE_ARGS= --with-everything \ --with-paranoidmsg \ --with-virtualchroot \ --with-tls \ --with-largefile \ --sysconfdir=${PREFIX}/etc 然后make install clean即可。 注:多谢benbenblood 兄提示,原来写的不够清楚,容易误导大家 :em06: ###################################### mkdir /usr/local/pureftpd/etc cp configuration-file/pure-ftpd.conf /usr/local/pureftpd/etc/pure-ftpd.conf cp configuration-file/pure-config.pl /usr/local/pureftpd/sbin/pure-config.pl chmod u+x /usr/local/pureftpd/sbin/pure-config.pl ee /usr/local/pureftpd/etc/pure-ftpd.conf 可参考其他文章进行设置,需要注意的是: BrokenClientsCompatibility YES #如果不设置的话,用IE登陆时.ftpquota会不计数,用户的磁盘配额将不起作用。 # MySQL configuration file (see README.MySQL) # pureftpd-mysql.conf文件的位置 MySQLConfigFile /usr/local/pureftpd/etc/pureftpd-mysql.conf ##这个文件的地方一定要写对 2:安装pureftpd_php_manager tar zxvf pureftpd_php_manager.tar.gz cp -R pureftpd_php_manager /usr/www/phpmanager #或者直接mv,/usr/www目录为apache的主目录,如果不同请更换 find /usr/www/phpmanager -type d -exec chmod 755 {} \; find /usr/www/phpmanager -type f -exec chmod 644 {} \; cd /usr/www/phpmanager/ cp pureftpd-mysql.conf.sample /usr/local/pureftpd/etc/pureftpd-mysql.conf ee /usr/local/pureftpd/etc/pureftpd-mysql.conf #MYSQLSocket /var/lib/mysql/mysql.sock MYSQLServer localhost MYSQLPort 3306 MYSQLUser pureftpd ##注意此处的用户要和后面在数据库中添加的一致 MYSQLPassword abcdefg ##注意此处的密码要和后面在数据库中添加的一致 MYSQLDatabase pureftpd ##注意此处的数据库名字要和后面在数据库中添加的一致 MYSQLCrypt md5 ##如果是默认的pureftpd_php_manager则不能用md5,要用crypt或者cleartext,不管是crypt还是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") ############################################### ee /usr/www/phpmanager/pureftp.config.php <?php ###################### ####### SETUP ######## ###################### // Your exactly located mysql config file for pureftpd $PUREFTP_CONFIG_FILE = '/usr/local/pureftpd/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"; ####################### # DEFAULT NEW-USER PARAMS # ####################### $DefaultUser = ""; # Default User Logon $DefaultPass = ""; # Default User Password $DefaultUid = "1001"; # Default User ID ( must be a real user acct ) ##此处填上安装pureftpd的时候添加的用户id $DefaultGid = "1001"; # Default Group ID ( must be a real group acct ) ##此处填上安装pureftpd的时候添加的用户组id $DefaultDir = "/usr/www"; # Default User Dir ( use /./ at the end to chroot ) $DefaultUL = "2000"; # Default Upload Throttle ( 0 disables it ) $DefaultDL = "2000"; # Default Download Throttle ( 0 disables it ) $Defaultip = "*"; # Default IP restrictions ( * = any IP ) $DefaultQS = "2000"; # Default Quota Size ( 0 disables it ) $Defaultcmt = ""; # Default Comment for user // UA $DefaultQF = "200000"; # Default Quota Files ( 0 disables it ) $PWC = "24"; # Vorsatz fuerr Crypt Password ?>; mysql -u root -p mysql>; drop database pureftpd; CREATE DATABASE pureftpd; 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; grant all privileges on pureftpd.* to pureftpd@localhost identified by 'abcdefg'; ##grant all privileges on 你刚建立的数据库名称.* to 你要建的mysql用户名称@localhost identified by 'mysql新用户密码' FLUSH PRIVILEGES; ##重载受权表 3:启动pureftpd /usr/local/pureftpd/sbin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf 为了以后方便的进行Ftp服务的管理,我自己在/usr/local/etc/rc.d中新建了一个pureftpd.sh文件。 ee /usr/local/etc/rc.d/pureftpd.sh #!/bin/sh case "$1" in start) if [ -f /usr/local/pureftpd/etc/pure-ftpd.conf ]; then /usr/local/pureftpd/sbin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf >; /dev/null 2>;&1 && echo -n 'pure-ftpd Begin!' fi ;; stop) /usr/bin/killall pure-ftpd >; /dev/null 2>;&1 && echo -n 'pure-ftpd Stop!' ;; *) echo "" echo "Usage: `basename $0` { start | stop }" echo "" exit 64 ;; esac 设置该文件的可执行权限 chmod u+x /usr/local/etc/rc.d/pureftpd.sh 以后可以用下列命令启动PureFTPd服务 /usr/local/etc/rc.d/pureftpd.sh start 用下列命令停止PureFTPd服务 /usr/local/etc/rc.d/pureftpd.sh stop 让它开机自动启动,在/etc/rc.conf里面加入pureftpd_enable="YES"或者不加也可以。 4:web界面管理 安装了pureftpd_php_manager以后就可以通过http://你的域名或ip/phpmanager/index.php来添加、删除用户了。[/code] 5:用户密码问题md5?crypt? 没有修改过的pureftpd_php_manager/index.php文件内容为: 就自己用vi 打开看吧 这个文件下的话将不能将用户密码设置为md5,只需要修改为如下的内容即可: <? // Aenderungen 25.5. Uwe Ahrendt // www.bildpartner.de // READ THE README !!! /**************************************************** * PureFTP - PHP USer Manager by solariz * Soruce (c) 2002 - www.solariz.de **************************************************** * Please read the General Public License * ENGLISH: http://www.gnu.org/licenses/gpl.html * GERMAN : http://www.gnu.de/gpl-ger.html **************************************************** CheckOut: http://www.solariz.de */ include("pureftp.config.php"); ################################################################# ############### NO NEED FOR CHANGES BELOW HERE ################## ################################################################# // Config einlesen if(!file_exists($PUREFTP_CONFIG_FILE)) DIE("FATAL ERROR: Pure FTPD Config file not found.<br />;$PUREFTP_CONFIG_FILE"); $USERARRAY = array(); $raw = file($PUREFTP_CONFIG_FILE); foreach($raw AS $zeile): if(!ereg("^#",$zeile)): #skip comments // Einlesen der einzelnen Zeilen als Variable $tmp = split(" ",trim($zeile)); // UNIX Tab workaround if(count($tmp) < 2) $tmp = explode("\t",trim($zeile)); $var = strtoupper(trim($tmp[0])); for($n=1;$n<count($tmp);++$n) { if(!empty($tmp[$n])) { $$var = trim($tmp[$n]); break; }#end if }#end for // Einlesen der Tabelle if(empty($DB_TABLE) AND eregi("FROM\ [[]]{1,20}\ WHERE",$zeile)): $tmp2 = split("FROM ",$zeile); $tmp2 = split(" WHERE",trim($tmp2[1])); $DB_TABLE = trim($tmp2[0]); unset($tmp2); EndIF; EndIf; EndForEach; if(empty($MYSQLSERVER)) $MYSQLSERVER = "localhost"; if(empty($DB_TABLE)) DIE("ERROR: Config error in pureftpd config file. No table specified."); // UA if ($MYSQLCRYPT == "crypt") {$PW = TRUE;} else {$PW = FALSE;} if ($MYSQLCRYPT == "md5") {$md5 = TRUE;} else {$md5 = FALSE;} // Aktual Version $VERSION = "2.23"; $BUILD = "1017"; // Setein header PAGE_HEADER(); // SQL Connection herstellen DB_OPEN(); // FORM SUBIT AUSWERTUNG // Globals $action = get_var("action"); $user = get_var("user"); if( $action == "edit" || $action == "add" ) { // ADD value setter if($action == "add"): $USERARRAY['User'] = $DefaultUser; // UA if ($PW) {$USERARRAY['Password'] = crypt($DefaultPass,$PWC); } else if ($md5) {$USERARRAY['Password'] = md5($DefaultPass); } else {$USERARRAY['Password'] = $DefaultPass; } $USERARRAY['Password'] = $DefaultPass; $USERARRAY['Uid'] = $DefaultUid; $USERARRAY['Gid'] = $DefaultGid; $USERARRAY['Dir'] = $DefaultDir; $USERARRAY['ULBandwidth'] = $DefaultUL; $USERARRAY['DLBandwidth'] = $DefaultDL; $USERARRAY['ipaccess'] = $Defaultip; $USERARRAY['QuotaSize'] = $DefaultQS; // UA $USERARRAY['QuotaFiles'] = $DefaultQF; $USERARRAY['comment'] = $Defaultcmt; else: unset($USERARRAY); EndIf; if(!empty($user) AND $user != "0") { $USERARRAY=@MYSQL_FETCH_ARRAY(DB_QUERY("SELECT * FROM `$DB_TABLE` WHERE User LIKE '$user'")); }#end if if(!is_array($USERARRAY)) DIE("User Not found or DB error.<br />;".mysql_error()); echo '<form method=post action="'.$SELF_URL.'" onSubmit="return checkrequired(this)">;'; if(!empty($user)) echo '<input type="hidden" name="requireduser" value="'.stripslashes($USERARRAY['User']).'">;'; else echo '<input type="hidden" name="addnew" value="True">;'; echo '<input type="hidden" name="action" value="save">;'; echo '<table width="100%" class=TABLE>;'; echo '<tr>;<th>;Status</th>;<td class=TD>;<input type="radio" name="status" value="0"'; if($USERARRAY['status'] == 0) echo ' checked'; echo '>; Inactive&&&<input type="radio" name="status" value="1"'; if($USERARRAY['status'] == 1) echo ' checked'; echo '>; Active</td>;</tr>;'; if(!empty($user)) { echo '<tr>;<th>;Delete user ?</th>;<td class=TD>;<input type="checkbox" name="delete">; Yes, i am know exactly what i am doing! (NO UNDO)</td>;</tr>;'; echo '<tr>;<th>;Username</th>;<td class=TD>;'.stripslashes($USERARRAY['User']).'</td>;</tr>;'; } else echo '<tr>;<th>;Username</th>;<td class=TD>;<input type="text" name="requireduser" class="input">;</td>;</tr>;'; echo '<tr>;'; echo '<th>;Password</th>;'; // UA if ($PW) { echo '<td class=TD>;<input type="text" name="requiredpass" value="<crypted>;" class="input">;</td>;</tr>;'; } else { echo '<td class=TD>;<input type="text" name="requiredpass" value="'.stripslashes($USERARRAY['Password']).'" class="input">;</td>;</tr>;'; } echo '<tr>;<th>;UID</th>;<td class=TD>;<input type="text" name="requireduid" value="'.stripslashes($USERARRAY['Uid']).'" class="input">;</td>;</tr>;'; echo '<tr>;<th>;GID</th>;<td class=TD>;<input type="text" name="requiredgid" value="'.stripslashes($USERARRAY['Gid']).'" class="input">;</td>;</tr>;'; echo '<tr>;<th>;DIR</th>;<td class=TD>;<input type="text" name="requireddir" value="'.stripslashes($USERARRAY['Dir']).'" class="input">;</td>;</tr>;'; echo '<tr>;<th>;UL Throttle kb/s</th>;<td class=TD>;<input type="text" name="requiredulthrottle" value="'.stripslashes($USERARRAY['ULBandwidth']).'" class="input">;</td>;</tr>;'; echo '<tr>;<th>;DL Throttle kb/s</th>;<td class=TD>;<input type="text" name="requireddlthrottle" value="'.stripslashes($USERARRAY['DLBandwidth']).'" class="input">;</td>;</tr>;'; echo '<tr>;<th>;IP ACCESS</th>;<td class=TD>;<input type="text" name="requiredipaccess" value="'.stripslashes($USERARRAY['ipaccess']).'" class="input">;<br />;<small>;Type in <b>;*</b>; for any IP</td>;</tr>;'; // UA echo '<tr>;<th>;QuotaSize in MB</th>;<td class=TD>;<input type="text" name="requiredQuotaSize" value="'.stripslashes($USERARRAY['QuotaSize']).'" class="input">;<br />;<small>;Type in <b>;0</b>; for NO VirtualQuotaSize</td>;</tr>;'; // UA echo '<tr>;<th>;QuotaFiles Anzahl</th>;<td class=TD>;<input type="text" name="requiredQuotaFiles" value="'.stripslashes($USERARRAY['QuotaFiles']).'" class="input">;<br />;<small>;Type in <b>;0</b>; for NO VirtualQuotaFiles</td>;</tr>;'; echo '<tr>;<th>;COMMENT</th>;<td class=TD>;<textarea name="comment" rows="6" cols="20" class="input">;'.stripslashes($USERARRAY['comment']).'</textarea>;</td>;</tr>;'; echo '</table>;'; echo '<center>;<input type="submit" value="Save" class="button" width="100%">;</center>;</form>;'; }#end edit elseif($action == "save") { $addnew = addslashes( get_var("addnew") ); $User = addslashes(get_var("requireduser")); // UA - MG Optimized ;) $Password = addslashes(get_var("requiredpass")); IF($Password == '<crypted>;') $Password = ''; ELSEif($PW) $Password = crypt($Password, $PWC); elseif($md5) $Password = md5($Password); $Uid = addslashes(get_var("requireduid")); $Gid = addslashes(get_var("requiredgid")); $Dir = addslashes(get_var("requireddir")); $ULThrottle = addslashes(get_var("requiredulthrottle")); $DLThrottle = addslashes(get_var("requireddlthrottle")); $QuotaSize = addslashes(get_var("requiredQuotaSize")); // UA $QuotaFiles = addslashes(get_var("requiredQuotaFiles")); $comment = addslashes(get_var("comment")); $status = addslashes(get_var("status")); $delete = addslashes(get_var("delete")); $ipaccess = addslashes(get_var("requiredipaccess")); if(empty($User) || empty($Uid) || empty($Gid) || empty($Dir)) DIE("Invalid or missing data entered..."); if(empty($delete)) { // Mini workarounds if($Password) $PW_QUERY = ",Password='$Password'"; if(!$status) $status = (string) '0'; if(!$ULBandwidth) $ULBandwidth = (string) '0'; if(!$DLBandwidth) $DLBandwidth = (string) '0'; if(!$QuotaSize) $QuotaSize = (string) '0'; if(!$QuotaFiles) $QuotaFiles = (string) '0'; if($addnew == False) { $SQL = "UPDATE `$DB_TABLE` SET status='$status'".$PW_QUERY.",Uid='$Uid',Gid='$Gid',Dir='$Dir',ULBandwidth='$ULThrottle',DLBandwidth='$DLThrottle',comment='$comment',ipaccess='$ipaccess',QuotaSize='$QuotaSize',QuotaFiles='$QuotaFiles' WHERE User LIKE '$User' LIMIT 1"; $Q = DB_QUERY($SQL); if($Q) echo ";\n"; }#end if else{ $Q = DB_QUERY("INSERT INTO `$DB_TABLE` SET User='$User',status='$status'".$PW_QUERY.",Uid='$Uid',Gid='$Gid',Dir='$Dir',ULBandwidth='$ULThrottle',DLBandwidth='$DLThrottle',comment='$comment',ipaccess='$ipaccess',QuotaSize='$QuotaSize',QuotaFiles='$QuotaFiles'"); if($Q) echo ";\n"; }#end if }#end if elseif($User && !empty($delete)){#DELETE $Q = DB_QUERY("DELETE FROM `$DB_TABLE` WHERE User LIKE '$User' LIMIT 1"); if($Q) echo ";\n"; }#end if echo ";\n"; }#end else (save) ###### elseif($action == "ftpwho") { echo '<table border="4">;'; exec($FTP_WHO." -s", $ftpresult ); $arraySize = sizeof($ftpresult); $x = 0; echo '<table width="100%" class=TABLE>;'; echo '<th class=THsmall>;PID</td>;'; echo '<th class=THsmall>;user</td>;'; echo '<th class=THsmall>;min\'s</td>;'; echo '<th class=THsmall>;state</td>;'; echo '<th class=THsmall>;file</td>;'; echo '<th class=THsmall>;IP</td>;'; echo '<th class=THsmall>;current</td>;'; echo '<th class=THsmall>;total</td>;'; echo '<th class=THsmall>;%</td>;'; echo '<th class=THsmall>;bw.</td>;'; while($x < $arraySize): $ftpwho = $ftpresult[$x]; list($pid, $user, $mins, $state, $file, $host, $port,$h, $current, $total, $percent, $bandwidth ) = explode("|", $ftpwho ); $mins = round($mins / 60); if (empty($file) or !isset($file)) { ( $file = "---" ); ++$ftp_activity; } else { if(strlen($file) >; 10) $file_short = substr($file,0,10); $file = "<a href=\"#\" onClick=\"javascript:alert('$file');\">;$file_short...</a>;"; }#end else $host = gethostbyname($host); echo '<tr>;'; echo '<td class=TDsmall>;' .$pid. '</td>;'; echo '<td class=TDsmall>;' .$user. '</td>;'; echo '<td class=TDsmall>;' .$mins. '</td>;'; echo '<td class=TDsmall>;' .$state. '</td>;'; echo '<td class=TDsmall>;' .$file. '</td>;'; echo '<td class=TDsmall>;' .$host. '</td>;'; echo '<td class=TDsmall>;' .$current. '</td>;'; echo '<td class=TDsmall>;' .$total. '</td>;'; echo '<td class=TDsmall>;' .$percent. '</td>;'; echo '<td class=TDsmall>;' .$bandwidth. ' kb/s</td>;'; echo '</tr>;'; $x++; EndWhile; echo '</table>;'; if(!$ftp_activity) echo 'No users currenty using the FTP.<br>;'; echo '<p>;<center>;<input type=button value=" Close " onclick=self.close()>;'; echo '<input type=button value=" Refresh " onClick=" JavaScript : window.location.reload()">;</center>;'; }#end else (ftpwho) ###### elseif($action == "info") { ?>; <font color=silver face="Verdana,Arial">; <b>;sOLARiZ PureFTPd Manager</b>;<br>; Version <?=$VERSION?>; Build <?=$BUILD?>; <table width="100%" cellpadding=0 cellspacing=0 bgcolor="#C0C0C0">; <tr>;<td bgcolor="#005279">;<b>;<font color=silver>;About</b>;</td>;</tr>; <tr>;<td>; <ul>; <a href="http://www.pureftpd.org" target=_blank>;<img src="gfx/pure-ftpd.png" align=right border=0>;</a>; Ok, whats to say about this small script ?<br>; Not much. The Basic version was written due the need of a simply User management for the PureFTPd Daemon. Now it's more than a simple management script. </ul>; </td>;</tr>; <tr>;<td bgcolor="#005279">;<b>;<font color=silver>;History</b>;</td>;</tr>; <tr>;<td>; <ul>;<font face=Arial size=1>; <? $raw = file("history.txt"); foreach($raw AS $hline): echo stripslashes($hline)."<br>;\n"; EndForEach; ?>; </font>;</ul>; </td>;</tr>; <tr>;<td bgcolor="#005279">;<b>;<font color=silver>;Thanks to</b>;</td>;</tr>; <tr>;<td>; <ul>; <li>;<i>;Uwe Ahrendt - www.bildpartner.de</i>; cryptmod & QuotaFiles support <li>;<i>;erevo.com</i>; for detailed bug reporting <li>;<i>;CrowMan</i>; for STATUS modification </ul>; </td>;</tr>; </table>; <? } ELSE { // User auslesen und in Table darstellen $viewpw = get_var("viewpw"); $Q=DB_QUERY("SELECT * FROM `$DB_TABLE` ORDER BY User"); echo '<table width="100%" class=TABLE>;'; echo '<tr>;<th>;LOGIN</th>;'; if($viewpw) echo '<th>;PASSWORD</th>;'; // UA echo '<th>;UID</th>;<th>;GID</th>;<th>;DIR</th>;<th>;UL/ks</th>;<th>;DL/ks</th>;<th>;Quota Size</th>;<th>;Quota Files</th>;<th>;IP Access</th>;<th>;Status</th>;<th>;&</th>;</tr>;'; WHILE($R=MYSQL_FETCH_ARRAY($Q)) { echo '<tr>;'; echo '<td class=TD>;'.$R['User'].'</td>;'; if($viewpw) echo '<td class=TDPW>;'.$R['Password'].'</td>;'; echo '<td class=TD>;'.$R['Uid'].'</td>;'; echo '<td class=TD>;'.$R['Gid'].'</td>;'; echo '<td class=TD>;'.$R['Dir'].'</td>;'; if($R['ULBandwidth']) echo '<td class=TD>;'.$R['ULBandwidth'].'</td>;'; ELSE echo '<td class=TD>;-</td>;'; if($R['DLBandwidth']) echo '<td class=TD>;'.$R['DLBandwidth'].'</td>;'; ELSE echo '<td class=TD>;-</td>;'; if($R['QuotaSize']) echo '<td class=TD>;'.$R['QuotaSize'].' MB</td>;'; ELSE echo '<td class=TD>;-</td>;'; // UA if($R['QuotaFiles']) echo '<td class=TD>;'.$R['QuotaFiles'].'</td>;'; ELSE echo '<td class=TD>;-</td>;'; echo '<td class=TD>;'.$R['ipaccess'].'</td>;'; if($R['status'] == '0') echo '<td class="inactive">;inactive</td>;'; elseif($R['status'] == '1') echo '<td class="active">;active</td>;'; echo "<td width=30 class=TD>;<input type=submit class=button value=edit onClick=\"javascript:fenster('$SELF_URL?action=edit&user=".$R['User']."')\">;</td>;"; echo "</tr>;\n"; }#end while echo '</table>;'; ?>; <table width="100%" class=TABLE2>; <tr>; <td align=left>; PureFTP User Management.<br />; v<?=$VERSION?>; written 2002 by sOLARiZ <br />; [<a href="javascript:fenster('<?=$SELF_URL?>;?action=info')">;<font color=silver size=1>;Information</font>;</a>;]<br />; </td>; <td>;&</td>; <td align=right valign=top>; <? // Nav Button stuff echo "<table cellspacing=0 cellpadding=0>;<tr>;"; // Add User Button ECHO "<td>;<input type=\"image\" src=\"gfx/addusr.gif\" class=button onClick=\"javascript:fenster('$SELF_URL?action=add')\">;</td>;"; // View Password Button echo '<form method=post action="'.$PHP_SELF.'">;'; if($viewpw) echo '<input type="hidden" value=0 name="viewpw">;'; ELSE echo '<input type="hidden" value=1 name="viewpw">;'; ECHO '<td>;<input type="image" src="gfx/passwd.gif" value="View Passwords" alt="Toggle Passworddisplay"'; if(!$viewpw) echo ' class=button'; ECHO '>;</td>;'; echo '</form>;'; // Status Button ECHO "<td>;<input type=\"image\" src=\"gfx/status.gif\" class=button onClick=\"javascript:fenster('$SELF_URL?action=ftpwho')\">;</td>;"; // Update Button ECHO "<td>;<input type=\"image\" src=\"gfx/updates.gif\" class=button onClick=\"javascript:fenster('http://www.solariz.de/updates/pureftpdm.php?ver=$VERSION&ab=$BUILD')\">;</td>;"; echo "</tr>;</table>;"; ######## echo '</td>;</tr>;</table>;'; }#end else // SQL Verbindung schliessen DB_CLOSE(); // Seite abschliessen PAGE_FOOTER(); // EOC <--* // Funktionen function PAGE_HEADER() { ?>;<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">; <html lang="en">; <html>; <head>; <title>; PuRE FTPD - User Managemant </title>; <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">; <meta name="Generator" content="http://www.EditPlus.com">; <meta name="Author" content="Marco 'solariz' G鰐ze">; <meta name="Keywords" content="solariz, pureftp, user, management">; <meta name="Description" content="Pure FTP User manager">; <?include("styles.css")?>; ; </head>; <body text=black>; <? }#end func function PAGE_FOOTER() { ?>;</body>; </html>;<? }#end func function DB_OPEN() { GLOBAL $MYSQLSERVER,$MYSQLUSER,$MYSQLPASSWORD,$MYSQLDATABASE,$MYSQLCON; $MYSQLCON = @mysql_connect($MYSQLSERVER,$MYSQLUSER,$MYSQLPASSWORD); if(!$MYSQLCON OR @mysql_error()) DIE("Can't establish DB connection.<br />;".mysql_error()); if(!@mysql_select_Db($MYSQLDATABASE)) DIE("Can't establish DB connection.<br />;".mysql_error()); }#end func function DB_CLOSE() { GLOBAL $MYSQLCON; RETURN @mysql_close($MYSQLCON); }#end func function DB_QUERY($sql) { GLOBAL $MYSQLCON,$MYSQLDATABASE; $Q = @MySql_DB_query($MYSQLDATABASE,$sql,$MYSQLCON); if(@mysql_error()) DIE("<b>;MySQL Error during Query !</b>;<br />;<br />;[$sql]<br />;".mysql_error()); return $Q; }#end func function get_var($var){ GLOBAL $$var; GLOBAL $_POST,$_GET,$HTTP_POST_VAR,$HTTP_GET_VAR; $inhalt = $$var; # This function checks if the _GET or _POST var is set or if an old PHP version used if($_POST[$var]) RETURN $_POST[$var]; elseif($HTTP_POST_VAR[$var]) RETURN $HTTP_POST_VAR[$var]; elseif($_GET[$var]) RETURN $_GET[$var]; elseif($HTTP_GET_VAR[$var]) RETURN $HTTP_GET_VAR[$var]; elseif($inhalt) RETURN $inhalt; }#end func ?>; 这样的话在/usr/local/pureftpd/etc/pureftpd-mysql.conf里面就可以设置为md5了,crypt也可以,自己喜欢哪个就用哪个吧,呵呵 6:通过web界面让用户修改密码 使用ftp最烦的就是用户经常说密码忘记了,或者说想改个密码,忘记密码的话,可以通过web界面进去帮他们修改,他如果想自己修改密码,这都要麻烦你的话,你会烦死的,因此要想办法让他们能自己通过web来修改,只需要很简单的几个页面就可以了,当然只是实现了该功能,安全等等还需要自己再加强了。 mkdir /usr/www/editpasswd ee config.php 内容为:
CODE:
[Copy to clipboard]
<? $local="localhost"; $u_name="pureftpd"; $cpasswd="abcdefg"; $db_name="pureftpd"; //用户名、密码、数据库名字请自行修改为自己的 ?>; <? function local(){ global $local; return $local; } function u_name(){ global $u_name; return $u_name; } function passwd(){ global $cpasswd; return $cpasswd; } function db_name(){ global $db_name; return $db_name; } ?>; ee connect.php 内容为:
CODE:
[Copy to clipboard]
<? $connectino=mysql_connect(local(),u_name(),passwd()) or die ("数据库连接失败"); $select=mysql_select_db(db_name()) or die ("数据库打开失败"); ?>; ee index.php 内容为;
CODE:
[Copy to clipboard]
<?php require("config.php"); if(!empty($_GET["action"])) { if($_GET["action"]=="edit"){ require("connect.php"); $flag=0; if(empty($_POST['passwd'])){ $flag=1; echo ";"; } if(empty($_POST['passwd1'])){ $flag=1; echo ";"; } if(empty($_POST['passwd2'])){ $flag=1; echo ";"; } if((strlen($_POST["passwd1"])<8)||(strlen($_POST["passwd1"])>;16)){ $flag=1; echo ";"; } if((strlen($_POST["passwd2"])<8)||(strlen($_POST["passwd2"])>;16)){ $flag=1; echo ";"; } if($_POST["passwd1"]!=$_POST["passwd2"]){ $flag=1; echo ";"; } $passwd_old=crypt($_POST['passwd'],"$1$"); $passwd_new=crypt($_POST['passwd1'],"$1$"); if($flag==0){ $sql="select * from ftpd where User='".$_POST['User']."' and Password='".$passwd_old."'"; $result=mysql_query($sql); $myrow1=mysql_num_rows($result); if($myrow1==0){ echo ";"; }else{ $sql ="update ftpd set Password='".$passwd_new."' where User='".$_POST['User']."'"; $resulta=mysql_query($sql) or die("sdfsdf"); echo "修改成功!"; } } } }else{ ?>; <html>; <head>; <meta http-equiv="Content-Type" content="text/html; charset=gb2312">; <title>;--修改密码</title>; </head>; <body>; <form name="form1" method="post" action="index.php?action=edit">; <table width="300" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">; <tr>; <td>;<table width="300" border="0" cellspacing="1" cellpadding="0">; <tr>; <td height="22">;<font color="#ffffff" class="pt9">;<strong>;修改FTP服务器登陆密码</strong>;</font>;</td>; </tr>; <tr>; <td bgcolor="#FFFFFF">;<span class="pt9">; 用户名:</span>; <input name="User" style="border-style:solib;border-color:'#333333';border-width:1;" type="text" size="20">;</td>; </tr>; <tr>; <td bgcolor="#FFFFFF">;<span class="pt9">; 原密码:</span>; <input name="passwd" style="border-style:solib;border-color:'#333333';border-width:1;" type="password" size="20">;</td>; </tr>; <tr>; <td bgcolor="#FFFFFF">;<span class="pt9">; 新密码:</span>; <input name="passwd1" style="border-style:solib;border-color:'#333333';border-width:1;" type="password" size="20">;</td>; </tr>; <tr>; <td bgcolor="#FFFFFF">;<span class="pt9">; 密码确认:</span>; <input name="passwd2" style="border-style:solib;border-color:'#333333';border-width:1;" type="password" size="20">; </td>; </tr>; <tr>; <td height="22" bgcolor="#999999">; <input type="submit" name="Submit" value="提交">; <input type="reset" name="Submit2" value="还原">;</td>; </tr>; </table>;</td>; </tr>; </table>; </form>; </body>; </html>; <?php } ?>; 这样就可以通过http://您的ip或域名/editpasswd/index.php来访问去修改密码了 7:安全 phpmanager目录绝对不能让人随便访问,否则要乱套了,一般我都是在apache中对这个目录进行限制。 ee /usr/local/etc/apache2/httpd.conf <Directory "/usr/www/phpmanager">; deny from all Options None AllowOverride AuthConfig Order deny,allow </Directory>; ee /usr/www/phpmanager/.htaccess AuthType Basic AuthUserFile /usr/local/pureftpd.passwd AuthName 想添加用户就得过我这一关,嘿嘿^_^ require valid-user satisfy any /usr/local/sbin/htpasswd -bc /usr/local/pureftpd.passwd jxtm lovefreebsd /usr/local/etc/rc.d/apache2.sh restart重启apache 这样再以http://ip或域名/phpmanager/index.php来访问的时候会提示要用户名密码了,必须输入jxtm和lovefreebsd才可以进去的。 另外还可以写个shell来定期的修改用户名、密码,这样就更安全些,密码也要复杂些。 关于pureftpd,大概的就说这么多吧,至于具体的配置,google一下吧,很多帖子专门讲的就是它的每一行配置是什么意思的,可根据实际情况选择。 原地址: http://bbs.chinaunix.net/viewthread.php?tid=591054 |
相关阅读 更多 +