分类: BSD
2006-04-30 16:13:34
FreeBSD全能服务器安装手册FTP篇之B管理界面篇
##################################设置ftp管理界面##############################
require 'language.php';
$LANG = $ZH_CN; //Language (Options are $DUTCH, $ENGLISH, $PT_BR, $RUSSIAN
//$SPANISH, $COREAN, $FRENCH, $HUNGARIAN, $GERMAN
// $TURKISH, $DANISH , $NORWEGIAN or $ZH_CN)
$LocationImages = "images"; // Location of images
$DBHost = "localhost"; // Ip-adres of MySQL server
// (Dont change this if you are using the default database)
$DBLogin = "ftp"; // Username of MySQL user
$DBPassword = "password"; // Password of MySQL user
$DBDatabase = "ftpusers"; // Name of database
$FTPaddress = "192.168.0.205:21"; // Domain name or ip-address of your ftp server
$DEFUserID = "2000"; // nobody // Default user id of virtual ftp user.
$DEFGroupID = "2000"; // guest // Default group is of virtual ftp user.
###############################FTP管理界面源代码##############################
注意:共四个页面、一个样式、图片不付、存放图片的文件夹名为images
(admin.php、config.php、index.php、language.php、style.css)
%%%%%%%%%%%%%%%%%%%% admin.php%%%%%%%%%%%%%%%%%%%%%%
session_start();
require 'config.php';
if ($_SESSION['Login'] != '1')
{
header("location: index.php");
}else
{
if(!$mysql_ftp = @mysql_connect("$DBHost","$DBLogin","$DBPassword"))
{
echo $Translate[2][$LANG];
}
@mysql_select_db($DBDatabase);
$table_archief = "SELECT * FROM users ORDER BY User ASC";
$query_archief = mysql_query($table_archief);
$length_archief = mysql_numrows($query_archief);
function compare_array($word,$array)
{
$iCounter = 0;
while ($iCounter < count($array))
{
if($word == $array[$iCounter])
{
return $iCounter;
break;
}
$iCounter++;
}
return -1;
}
$filename = $UsersFile;
$fh = fopen($filename,"r");
$iNrofunixusers = 0;
while (!feof ($fh))
{
$line = fgets($fh,4096);
$data = explode(":",$line);
$user = trim($data[0]);
$user_id = trim($data[2]);
if ($user[0] != '#' &&
strlen($user) != 0 &&
strlen($user_id) != 0)
{
if(compare_array($user,$BlacklistUsers) == -1) /* no hit */
{
$unix_users[$iNrofunixusers] [0] = $user;
$unix_users[$iNrofunixusers] [1] = $user_id;
$iNrofunixusers++;
}
}
}
fclose($fh);
$filename = $GroupFile;
$fh = fopen($filename,"r");
$iNrofunixgroups = 0;
while (!feof ($fh))
{
$line = fgets($fh,4096);
$data = explode(":",$line);
$group = trim($data[0]);
$group_id = trim($data[2]);
if ($group[0] != '#' &&
strlen($group) != 0 &&
strlen($group_id) != 0)
{
if(compare_array($group,$BlacklistGroups) == -1) /* no hit */
{
$unix_groups[$iNrofunixgroups] [0] = $group;
$unix_groups[$iNrofunixgroups] [1] = $group_id;
$iNrofunixgroups++;
}
}
}
fclose($fh);
if($_GET['new'] == 1)
$new = 1;
$data_saved=1;
if(isset($_POST['save']))
{
$empty_password = 0;
$vallid_password = 1;
/* Default values, not used in this version but fields exist in database table */
$quotafiles = "0";
$quotasize = "0";
/* check if password if filled */
if (strlen($_POST['password_box']) == 0 || ($_POST['password_box'] == "empty"))
$empty_password = 1;
/* check for vallid password */
if ($_POST['confirm_password_box'] != $_POST['password_box'])
$vallid_password = 0;
$iExistUser=0;
$iCounter=0;
/* Find out of user exist */
while ($iCounter < $length_archief)
{
$bericht_nr = mysql_result($query_archief,$iCounter,"User");
if ($bericht_nr == $_POST['user_box'])
{
$iExistUser=1;
break;
}
$iCounter++;
}
if ($iExistUser == 1)
{
/* update current ftp account */
if ($vallid_password == 0)
{
echo ("\n");
}else
{
if ($empty_password == 1)
{
echo ("\n");
/*echo ("Uid=".$_POST['uid_box']."
Gid=".$_POST['gid_box']."
Dir=".$_POST['dir_box']."
QuotaFiles=".$_POST['quotafiles_box']."
QuotaSize=".$_POST['quotasize_box']."
ULBandwidth=".$_POST['ulbandwidth_box']."
DLBandwidth=".$_POST['dlbandwidth_box']."
User=".$_POST['user_box']."
\n");*/
if(!mysql_query("UPDATE users SET Uid='".$_POST['uid_box']."',
Gid='".$_POST['gid_box']."',
Dir='".$_POST['dir_box']."',
QuotaFiles='".$_POST['quotafiles_box']."',
QuotaSize='".$_POST['quotasize_box']."',
ULBandwidth='".$_POST['ulbandwidth_box']."',
DLBandwidth='".$_POST['dlbandwidth_box']."'
WHERE User='".$_POST['user_box']."'",$mysql_ftp))
{
echo $Translate[5][$LANG];
}
}else
{
if(!mysql_query("UPDATE users SET Password='".md5($_POST['password_box'])."',
Uid='".$_POST['uid_box']."',
Gid='".$_POST['gid_box']."',
Dir='".$_POST['dir_box']."',
QuotaFiles='".$_POST['quotafiles_box']."',
QuotaSize='".$_POST['quotasize_box']."',
ULBandwidth='".$_POST['ulbandwidth_box']."',
DLBandwidth='".$_POST['dlbandwidth_box']."'
WHERE User='".$_POST['user_box']."'",$mysql_ftp))
{
echo $Translate[5][$LANG];
}else
{
echo ("\n");
}
}
}
}else
{
// echo ("empty_password = $empty_password
\n");
// echo ("vallid_password = $vallid_password
\n");
/* Create new User */
if ($vallid_password == 0 || $empty_password == 1)
{
echo ("\n");
$data_saved = 0;
}else
{
if(!mysql_query("INSERT INTO users (User,Password,Uid,Gid,Dir,QuotaFiles,QuotaSize,ULBandwidth,DLBandwidth)
VALUES ('".$_POST['user_box']."',
'".md5($_POST['password_box'])."',
'".$_POST['uid_box']."',
'".$_POST['gid_box']."',
'".$_POST['dir_box']."',
'".$_POST['quotafiles']."',
'".$_POST['quotasize']."',
'".$_POST['ulbandwidth_box']."',
'".$_POST['dlbandwidth_box']."')",$mysql_ftp))
{
echo $Translate[5][$LANG];
}
}
}
$table_archief = "SELECT * FROM users ORDER BY User ASC";
$query_archief = mysql_query($table_archief);
$length_archief = mysql_numrows($query_archief);
}
if(isset($_GET['delete']))
{
if(!mysql_query("DELETE FROM users WHERE User='".$_GET['user_box']."'",$mysql_ftp))
{
echo $Translate[5][$LANG];
}else
{
$table_archief = "SELECT * FROM users ORDER BY User ASC";
$query_archief = mysql_query($table_archief);
$length_archief = mysql_numrows($query_archief);
}
$new=1;
}
function help($help_text)
{
global $LocationImages;
echo ("
echo (" title=\"$help_text\" hspace=\"1\" align=\"middle\" border=\"0\">");
}
echo ("\n");
echo ("\n");
echo ("
echo ("\n");
?>
print("\n");
echo ("\n");
echo ("\n");
// phpinfo();
echo ("
echo (" echo (" echo (" echo (" echo (" echo (" echo (" echo (" ".$Translate[0][$LANG]."\n"); echo (" echo (" echo (""); echo (""); echo (" ".$Translate[9][$LANG]." "); echo (" echo (" echo (" echo (" echo (" echo (" echo (" echo (" echo (" echo (" // echo (" echo (" echo (" echo (" echo (" echo (" echo (" echo (" echo (" echo (" $iCounter = 0; while ($iCounter < $length_archief) { $user = mysql_result($query_archief,$iCounter,"User"); $password = mysql_result($query_archief,$iCounter,"Password"); $uid = mysql_result($query_archief,$iCounter,"Uid"); $gid = mysql_result($query_archief,$iCounter,"Gid"); $dir = mysql_result($query_archief,$iCounter,"Dir"); $quotafiles = mysql_result($query_archief,$iCounter,"QuotaFiles"); $quotasize = mysql_result($query_archief,$iCounter,"QuotaSize"); $ulbandwidth = mysql_result($query_archief,$iCounter,"ULBandwidth"); $dlbandwidth = mysql_result($query_archief,$iCounter,"DLBandwidth"); echo (" echo (" echo ("$user echo (" echo (" echo (" echo (" echo (" echo (" echo (" echo (" /* Edit ftp account */ echo (""); echo (" width=\"16\" height=\"18\" border=\"0\" "); echo ("title=\"".$Translate[19][$LANG]."\" "); echo ("alt=\"".$Translate[19][$LANG]."\"> "); /* Delete ftp account */ echo (""); echo (" echo ("title=\"".$Translate[20][$LANG]."\" "); echo ("alt=\"".$Translate[20][$LANG]."\"> "); // /* Open ftp account */ echo (""); echo (" echo ("title=\"".$Translate[21][$LANG]."\" "); echo ("alt=\"".$Translate[21][$LANG]."\">"); echo (" echo (" $iCounter++; } echo (" echo (" echo (" echo (" $password = "empty"; if(!empty($_GET['id'])) { $iCounter=0; while ($iCounter < $length_archief) { $bericht_nr = mysql_result($query_archief,$iCounter,"User"); if ($bericht_nr == $_GET['id']) { $user = $bericht_nr; // $password = mysql_result($query_archief,$iCounter,"Password"); $uid = mysql_result($query_archief,$iCounter,"Uid"); $gid = mysql_result($query_archief,$iCounter,"Gid"); $dir = mysql_result($query_archief,$iCounter,"Dir"); $quotafiles = mysql_result($query_archief,$iCounter,"QuotaFiles"); $quotasize = mysql_result($query_archief,$iCounter,"QuotaSize"); $ulbandwidth = mysql_result($query_archief,$iCounter,"ULBandwidth"); $dlbandwidth = mysql_result($query_archief,$iCounter,"DLBandwidth"); break; } $iCounter++; } }else if(empty($new)) { // $_GET['id'] // $_POST[''] $user = $_POST['user_box']; $password = "empty"; $uid = $_POST['uid_box']; $gid = $_POST['gid_box']; $dir = $_POST['dir_box']; $ulbandwidth = $_POST['ulbandwidth_box']; $dlbandwidth = $_POST['dlbandwidth_box']; }else { $user = $Translate[22][$LANG]; $password = ""; $uid = $DEFUserID; $gid = $DEFGroupID; $dir = "/"; $ulbandwidth = "80"; $dlbandwidth = "5"; } if(isset($_POST['select_user']) && $_POST['select_user'] != $select_user_old && !isset($_POST['save'])) { $uid = $_POST['select_user']; $password = $_POST['password_box']; } if(isset($_POST['select_group']) && $_POST['select_group'] != $select_group_old && !isset($_POST['save'])) { $gid = $_POST['select_group']; $password = $_POST['password_box']; } session_register("select_group_old"); session_register("select_user_old"); echo (" echo (" echo (" echo (" echo (" echo ("\n"); echo (" echo (" echo (" echo (" echo (" // echo ("\n"); echo ("\n"); // echo ("$password echo (" echo (" echo (" echo (" echo (" // echo ("\n"); echo ("\n"); echo (" echo (" echo (" echo (" echo (" echo (" echo (""); $iCounter = 0; $iFound_uid = 0; while ($iCounter < $iNrofunixusers) { echo (" if ($uid == $unix_users[$iCounter][1]) { echo (" selected=\"selected\""); $select_user_old = $unix_users[$iCounter][1]; $iFound_uid = 1; } echo (">".$unix_users[$iCounter][0].""); $iCounter++; } echo ("\n"); echo (" echo (" hspace=\"1\" align=\"middle\" border=\"0\"> "); echo ("\n"); help($Translate[26][$LANG]); echo (" echo (" echo (" echo (" echo (" echo (" echo (""); $iCounter = 0; $iFound_gid = 0; while ($iCounter < $iNrofunixgroups) { echo (" if ($gid == $unix_groups[$iCounter][1]) { echo (" selected=\"selected\""); $select_group_old = $unix_groups[$iCounter][1]; $iFound_gid = 1; } echo (">".$unix_groups[$iCounter][0].""); $iCounter++; } echo ("\n"); echo (" echo (" hspace=\"1\" align=\"middle\" border=\"0\"> "); echo ("\n"); help($Translate[27][$LANG]); echo (" echo (" echo (" echo (" echo (" echo ("\n"); echo (" echo (" echo (" echo (" echo (" echo ("\n"); help($Translate[37][$LANG]); echo (" echo (" echo (" echo (" echo (" echo ("\n"); help($Translate[38][$LANG]); echo (" echo (" echo (" echo (" echo (" echo ("\n"); help($Translate[28][$LANG]); echo (" echo (" echo (" echo (" echo (" echo ("\n"); help($Translate[29][$LANG]); echo (" echo (" echo (" echo (" echo ("\n"); echo (" echo (" echo (" echo ("\n");
\n");\n"); \n");\n"); \n");\n");
\n");\n"); \n");\n"); \n");"); \n");\n"); \n");\n"); \n");\n");
\n");\n"); \n");".$Translate[10][$LANG]." ");".$Translate[11][$LANG]." ");".$Translate[12][$LANG]." ");".$Translate[13][$LANG]." ");".$Translate[14][$LANG]." ");".$Translate[35][$LANG]." ");".$Translate[36][$LANG]." ");".$Translate[15][$LANG]." ");".$Translate[16][$LANG]." ");".$Translate[17][$LANG]." ");\n"); \n");"); \n");".$uid." \n");".$gid." \n");".$dir." \n");".$quotafiles." \n");".$quotasize." \n");".$ulbandwidth." \n");".$dlbandwidth." \n");"); \n");
");\n");
\n");\n"); \n");".$Translate[10][$LANG]." \n");\n "); \n");\n"); \n");".$Translate[11][$LANG]." \n");\n "); \n");
\n");\n"); \n");".$Translate[23][$LANG]." \n");\n "); \n");\n"); \n");".$Translate[12][$LANG]." \n");\n "); \n");\n"); \n");".$Translate[13][$LANG]." \n");\n "); \n");\n"); \n");".$Translate[14][$LANG]." \n");\n "); \n");\n"); \n");".$Translate[35][$LANG]." \n");\n "); \n");\n"); \n");".$Translate[36][$LANG]." \n");\n "); \n");\n"); \n");".$Translate[24][$LANG]." \n");\n "); \n");\n"); \n");".$Translate[25][$LANG]." \n");\n "); \n");\n"); \n");\n"); \n");
if ($iFound_uid == 0)
$select_user_old = "";
if ($iFound_gid == 0)
$select_group_old = "";
// echo ("select_user_old = $select_user_old
\n");
// echo ("select_group_old = $select_group_old
\n");
echo ("
\n");
echo ("\n");
}
?>
%%%%%%%%%%%%%%%%%%%% config.php%%%%%%%%%%%%%%%%%%%%%%
/* 'User Management for PureFTPd server' is made by M.Mastenbroek 2002 - 2004
* For more info look at http://machiel.generaal.net
* Version 1.3.1
*/
require 'language.php';
$LANG = $ZH_CN; // Language (Options are $DUTCH, $ENGLISH, $PT_BR, $RUSSIAN
// $SPANISH, $COREAN, $FRENCH, $HUNGARIAN, $GERMAN
// $TURKISH, $DANISH , $NORWEGIAN or $ZH_CN)
$LocationImages = "images"; // Location of images
$DBHost = "localhost"; // Ip-adres of MySQL server
// (Don抰 change this if you are using the default database)
$DBLogin = "ftp"; // Username of MySQL user
$DBPassword = "e89120d9dfeb"; // Password of MySQL user
$DBDatabase = "ftpusers"; // Name of database
$FTPAddress = "222.36.42.111:21"; // Domain name or ip-address of your ftp server
$DEFUserID = "2000"; // nobody // Default user id of virtual ftp user.
$DEFGroupID = "2000"; // guest // Default group is of virtual ftp user.
$UsersFile = "/etc/passwd"; // The unix user file
$GroupFile = "/etc/group"; // The unix group file
/* This list of users will not appear in the dropdown menu. */
$BlacklistUsers = array ('adm','bin','bind','daemon','gopher','halt','kmem','lp',
'mailnull','man','named','nfsnobody','nscd','operator',
'pop','root','rpc','rpcuser','rpm','shutdown','smmsp',
'sshd','sync','toor','tty','uucp','vcsa','xfs');
/* This list of groups will not appear in the dropdown menu. */
$BlacklistGroups = array ('adm','bin','bind','daemon','dialer','dip','disk','floppy','gopher','kmem',
'lock','lp','mailnull','man','named','mem','network','news',
'nscd','ntp','operator','pcap','root','rpc','rpcuser','rpm','slocate','smmsp',
'sshd','staff','sys','tty','utmp','uucp','vcsa','wheel','xfs');
?>
%%%%%%%%%%%%%%%%%%%% index.php%%%%%%%%%%%%%%%%%%%%%%
session_start();
require 'config.php';
if(!mysql_connect("$DBHost", "$DBLogin", "$DBPassword"))
{
echo $Translate[2][$LANG];
} else
{
@mysql_select_db("$DBDatabase");
}
$table_gebruikers = "SELECT * FROM admin ORDER BY Username ASC";
$query_gebruikers = mysql_query($table_gebruikers);
$length_gebruikers = mysql_num_rows($query_gebruikers);
if ($_POST['Submit'])
{
$LoginNaam = addslashes($_POST['LoginNaam']);
$LoginPassword = addslashes($_POST['LoginPassword']);
$Query = mysql_query("SELECT * FROM admin WHERE Username = '$LoginNaam' AND Password = '".md5($LoginPassword)."'");
$Results = mysql_num_rows($Query);
if ($Results == '1')
{
$_SESSION['Login'] = 1;
session_register("Login");
header("location: admin.php?new=1");
}
}
?>
if ($Results != '1' && isset($_POST['Submit'])) { // echo(" // echo(" echo("".$Translate[31][$LANG]."\n // echo(" // echo(" } ?> $iCounter = 0; while ($iCounter < $length_gebruikers) { $naam = mysql_result($query_gebruikers,$iCounter,"Username"); echo ("\n"); $iCounter++; } ?> 登录"> \n"); \n");\n"); \n");
\n
\n"); =$Translate[10][$LANG]?> =$Translate[11][$LANG]?>:
%%%%%%%%%%%%%%%%%%% language.php%%%%%%%%%%%%%%%%%%%%%
$ZH_CN = 12; /* ZH_CN translated by Kevin Xu */
$Translate[0][$ZH_CN] = "PureFTPd服务用户管理";
$Translate[1][$ZH_CN] = "Version 1.3.1";
$Translate[2][$ZH_CN] = "数据库服务没有启动,请稍后再试。";
$Translate[3][$ZH_CN] = "您的密码不正确,当前所做的修改将不能保存。";
$Translate[4][$ZH_CN] = "密码将被设置为默认值并保存所有修改。";
$Translate[5][$ZH_CN] = "不合法的查询,请联系管理员。";
$Translate[6][$ZH_CN] = "修改已经保存。";
$Translate[7][$ZH_CN] = "FTP用户";
$Translate[8][$ZH_CN] = "将被删除。";
$Translate[9][$ZH_CN] = "新建用户";
$Translate[10][$ZH_CN] = "用户名";
$Translate[11][$ZH_CN] = "密码";
$Translate[12][$ZH_CN] = "用户id";
$Translate[13][$ZH_CN] = "用户组id";
$Translate[14][$ZH_CN] = "用户主目录";
$Translate[15][$ZH_CN] = "上传速度(Kb/s)";
$Translate[16][$ZH_CN] = "下载速度(Kb/s)";
$Translate[17][$ZH_CN] = "设置";
$Translate[19][$ZH_CN] = "编辑";
$Translate[20][$ZH_CN] = "删除";
$Translate[21][$ZH_CN] = "打开";
$Translate[22][$ZH_CN] = "用户名";
$Translate[23][$ZH_CN] = "密码确认";
$Translate[24][$ZH_CN] = "上传速度(Kb/s)";
$Translate[25][$ZH_CN] = "下载速度(Kb/s)";
$Translate[26][$ZH_CN] = "FTP用户等同于UNIX系统中哪个系统用户。";
$Translate[27][$ZH_CN] = "FTP用户组等同于UNIX系统中哪个系统组。";
$Translate[28][$ZH_CN] = "FTP用户的最大上传速度(Kb/s)。";
$Translate[29][$ZH_CN] = "FTP用户的最大下载速度(Kb/s)。";
$Translate[30][$ZH_CN] = "登录页面";
$Translate[31][$ZH_CN] = "错误的用户和密码。";
$Translate[32][$ZH_CN] = "保存";
$Translate[33][$ZH_CN] = "";
$Translate[34][$ZH_CN] = "";
$Translate[35][$ZH_CN] = "文件限额";
$Translate[36][$ZH_CN] = "磁盘限额(Mb)";
$Translate[37][$ZH_CN] = "FTP用户上传最大文件数。";
$Translate[38][$ZH_CN] = "FTP用户上传最大磁盘空间(Mb)。";
?>
%%%%%%%%%%%%%%%%%%%% style.css%%%%%%%%%%%%%%%%%%%%%%%
a {
font-face: Verdana, Arial, Helvetica, sans-serif;
text-decoration:none;
color: #000000;
font-size: 14px;
}
a:visited {
text-decoration: none;
color: default;
}
a:hover {
font-face: Verdana, Arial, Helvetica, sans-serif;
text-decoration: underline;
color: #FF0000;
font-size: 14px;
}
.help {
cursor: help
}