PHP开发的一个pureftpd管理工具
作者 : admin 于 2009年07月10日, 16:49:14
2009
07-10
07-10
用过pureftpd manager,虽然功能足够,但很多bug,无法使用,而pureftpd功能简单,写个管理工具也没多复杂,于是乎,花两个晚上写了个简单的管理脚本,分享给大家。不过没来得及写注释,回头会把注释补上。
分流下载 http://down.chinaz.com/soft/26439.htm
- < ?php
- error_reporting(2047);
- header("Content-Type: text/html; charset=utf-8");
- header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // 过去的时间
- define("FILENAME",$_SERVER['PHP_SELF']);
- $adminuser = "admin";
- $adminpass = "admin";
- $servtype = 'mysql';
- $hostname = 'localhost';
- $username = 'root';
- $password = '123456';
- $datebase = 'pure-ftpd';
- $table = "users";
- $charset = 'utf8';
- $crypt = "MD5";
- session_start();
- #session_destroy();
- $action = isset($_GET['action']) ? $_GET['action'] : "index";
- switch( $action )
- {
- case "index":
- checklogin();
- func_html( 0 );
- switch($_SESSION['user'])
- {
- case $adminuser:
- func_admin_index();
- break;
- default:
- func_user_index();
- break;
- }
- func_html( 1 );
- break;
- case "userlogin":
- case "adminlogin":
- func_html( 0 );
- func_userlogin();
- func_html( 1 );
- break;
- case "userloginaction":
- func_userloginaction( $_POST['username'] , $_POST['password'] , $_POST['logintype'] );
- break;
- case "userpasswordchang":
- checklogin();
- user_password_chang( $_POST['password'] );
- break;
- case "adminchangeuserpassword":
- case "useradd":
- checklogin(true);
- func_admin_user_edit( isset($_GET['user']) ? $_GET['user'] : false );
- break;
- case "userinfoac":
- checklogin(true);
- switch($_POST['action'])
- {
- case "edit":
- func_admin_useredit();
- break;
- case "add":
- func_admin_useradd();
- break;
- }
- break;
- case "adminuserdel":
- func_user_del( $_GET['user'] );
- break;
- case "logout":
- func_logout();
- break;
- }
- function func_html( $position = 0 )
- {
- switch( $position )
- {
- case 0:
- echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
- <html xmlns=\"http://www.w3.org/1999/xhtml\">
- <head>
- <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
- <title>PURE-FTPD简易管理系统</title>
- <style type=\"text/css\">
- td
- {
- padding:4px;
- }
- .bar
- {
- width:80%;
- border-bottom:dotted 1px #aaa;
- margin-bottom:20px;
- padding:10px;
- }
- </style>
- </head>
- <body>
- <div class=\"bar\">PURE-FTPD简易管理工具 孙博宇 http://www.sunboyu.cn QQ:176300676 MSN:sunboyu@gmail.com ";
- if(isset($_SESSION['user']))
- {
- echo "<input type=\"button\" name=\"logout\" id=\"logout\" value=\"退出\" onclick=\"window.location.href='?action=logout'\" />";
- }
- echo "</div>";
- break;
- case 1:
- echo "</body>
- </html>
- ";
- break;
- }
- }
- function checklogin( $type = false )
- {
- global $adminuser;
- if(!isset($_SESSION['user']))
- {
- header("Location:".FILENAME."?action=userlogin");
- }
- if($type&&$_SESSION['user']!=$adminuser)
- {
- header("Location:".FILENAME."?action=adminlogin");
- }
- }
- function func_userlogin( )
- {
- echo "<form name=\"loginform\" id=\"loginform\" action=\"?action=userloginaction\" method=\"post\">
- <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin:0px;\">
- <tr>
- <td colspan=\"2\" align=\"center\">用户登录</td>
- </tr>
- <tr>
- <td width=\"60\" align=\"right\">用户名</td><td width=\"200\"><input type=\"text\" name=\"username\" id=\"username\" /></td>
- </tr>
- <tr>
- <td align=\"right\">密码</td><td><input type=\"password\" name=\"password\" id=\"password\" /></td>
- </tr>
- <tr>
- <td align=\"center\" colspan=\"2\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"登录\" /><input type=\"hidden\" name=\"logintype\" id=\"logintype\" value=\"{$_GET['action']}\" /> ";
- if($_GET['action']=="userlogin")
- {
- echo "<a href=\"?action=adminlogin\">管理员登录</a>";
- }
- else
- {
- echo "<a href=\"?action=userlogin\">用户登录</a>";
- }
- echo "</td>
- </tr>
- <tr>
- <td align=\"center\" colspan=\"2\">".(isset($_GET['error']) ? $_GET['error'] : "")."</td>
- </tr>
- </table>
- </form>
- ";
- }
- function func_getdb()
- {
- global $hostname,$username,$password,$datebase,$charset;
- $handle = @mysql_connect( $hostname , $username , $password , false ) or die("Can't connetc to the DateBse.".mysql_error());
- @mysql_select_db( $datebase , $handle ) or die("Can't select the DateBase".mysql_error());
- mysql_query( "SET NAMES '{$charset}'" , $handle );
- return $handle;
- }
- function func_userloginaction( $usernames , $passwords , $logintype )
- {
- switch( $logintype )
- {
- case "userlogin":
- global $table,$username,$password,$crypt;
- $handle = func_getdb();
- #echo "SELECT COUNT(*) AS count FROM {$table} WHERE User = '{$usernames}' AND Password = ".$crypt."('".$passwords."')";
- $query = mysql_query("SELECT COUNT(*) AS count FROM {$table} WHERE User = '{$usernames}' AND Password = ".$crypt."('".$passwords."')" , $handle);
- $row = mysql_fetch_array( $query, MYSQL_ASSOC );
- if($row['count']==1)
- {
- $_SESSION['user'] = $usernames;
- echo "登录成功,跳转中……";
- echo "<meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
- }
- else
- {
- header("Location:".FILENAME."?action=userlogin&error=".urlencode("用户名或者密码错误!"));
- }
- break;
- case "adminlogin":
- global $adminuser,$adminpass;
- if($adminuser==$usernames&&$adminpass==$passwords)
- {
- $_SESSION['user'] = $usernames;
- echo "登录成功,跳转中……";
- echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
- }
- else
- {
- header("Location:".FILENAME."?action=adminlogin&error=".urlencode("用户名或者密码错误!"));
- }
- break;
- }
- }
- function func_user_index()
- {
- global $table,$username,$password,$crypt;
- $handle = func_getdb();
- $query = mysql_query("SELECT * FROM {$table} WHERE User = '{$_SESSION['user']}'" , $handle);
- $row = mysql_fetch_array( $query, MYSQL_ASSOC );
- echo "<form name=\"userpassword\" id=\"userpassword\" method=\"post\" action=\"?action=userpasswordchang\">
- <table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
- <tr>
- <td colspan=\"2\" align=\"center\">服务器信息</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">ip</td><td width=\"500\">".gethostbyname($_SERVER['SERVER_NAME'])."</td>
- </tr>
- <tr>
- <td colspan=\"2\" align=\"center\">账户信息</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">用户名</td><td width=\"500\">".$row['User']."</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">修改密码</td><td width=\"500\"><input type=\"password\" name=\"password\" id=\"password\" /> <input type=\"submit\" name=\"submit\" id=\"submit\" value=\"修改\" /></td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">Uid</td><td width=\"500\">".$row['Uid']."</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">Gid</td><td width=\"500\">".$row['Gid']."</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">Status</td><td width=\"500\">".$row['status']."</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">Dir</td><td width=\"500\">".$row['Dir']."</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">ULBandwidth</td><td width=\"500\">".$row['ULBandwidth']."</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">DLBandwidth</td><td width=\"500\">".$row['DLBandwidth']."</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">ipaccess</td><td width=\"500\">".$row['ipaccess']."</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">QuotaSize</td><td width=\"500\">".$row['QuotaSize']."</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">QuotaFiles</td><td width=\"500\">".$row['QuotaFiles']."</td>
- </tr>
- </table>
- </form>
- ";
- }
- function user_password_chang( $password )
- {
- global $crypt,$table;
- if(empty($password))
- {
- echo "密码不能为空,修改失败……";
- echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
- }
- else
- {
- $handle = func_getdb();
- $query = mysql_query("UPDATE {$table} SET Password = ".$crypt."('".$password."') WHERE User = '{$_SESSION['user']}'" , $handle);
- session_destroy();
- echo "修改成功,请重新登录。如果新的密码不能登录,请尝试使用旧密码进行登录……";
- echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=userlogin\">";
- }
- }
- function func_admin_index()
- {
- global $table,$username,$password,$crypt;
- $handle = func_getdb();
- $query = mysql_query("SELECT * FROM {$table} ORDER BY User ASC" , $handle);
- echo "<script language=\"javascript\">
- function del( username )
- {
- if(confirm('确认删除 '+username+'?'))
- {
- window.location.href=\"?action=adminuserdel&user=\"+username;
- }
- else
- {
- return false;
- }
- }
- </script><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
- <tr>
- <td colspan=\"4\" align=\"center\">用户列表</td>
- <td align=\"right\"><input type=\"button\" name=\"add\" id=\"add\" value=\"添加账户\" onclick=\"window.location.href='?action=useradd'\" /></td>
- </tr>
- <tr>
- <td align=\"center\">账号</td>
- <td align=\"center\">Uid</td>
- <td align=\"center\">Gid</td>
- <td align=\"center\">Dir</td>
- <td align=\"center\">操作</td>
- </tr>";
- while( $row = mysql_fetch_array( $query, MYSQL_ASSOC ) )
- {
- echo "<tr>
- <td>".$row['User']."</td>
- <td align=\"center\">".$row['Uid']."</td>
- <td align=\"center\">".$row['Gid']."</td>
- <td>".$row['Dir']."</td>
- <td align=\"center\"><input type=\"button\" name=\"button\" id=\"button\" value=\"修改\" onclick=\"window.location.href='?action=adminchangeuserpassword&user=".$row['User']."'\" />
- <input type=\"button\" name=\"del\" id=\"del\" value=\"删除\" onclick=\"del('".$row['User']."')\" /></td>
- </tr>";
- }
- echo "</table>";
- }
- function func_admin_user_edit( $user = false )
- {
- if($user)
- {
- global $table,$crypt;
- $handle = func_getdb();
- $query = mysql_query("SELECT * FROM {$table} WHERE User = '".$user."'" , $handle);
- $row = mysql_fetch_array( $query, MYSQL_ASSOC );
- if($row==false)
- {
- echo "不存在这个用户……";
- echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
- exit();
- }
- $action = "edit";
- }
- else
- {
- $row["User"] = "";
- $row['Uid'] = "";
- $row['Gid'] = "";
- $row['status'] = 0;
- $row['Dir'] = "";
- $row['ULBandwidth'] = 0;
- $row['DLBandwidth'] = 0;
- $row['ipaccess'] = "*";
- $row['QuotaSize'] = 0;
- $row['QuotaFiles'] = 0;
- $action = "add";
- }
- echo "<form name=\"userpassword\" id=\"userpassword\" method=\"post\" action=\"?action=userinfoac\">
- <table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
- <tr>
- <td colspan=\"2\" align=\"center\">账户信息</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">用户名</td><td width=\"500\">";
- if($action=="add")
- {
- echo "<input type=\"text\" name=\"User\" id=\"User\" value=\"".$row['User']."\" />";
- }
- else
- {
- echo $row['User']."<input type=\"hidden\" name=\"User\" id=\"User\" value=\"".$row['User']."\" />";
- }
- echo "</td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">密码</td><td width=\"500\"><input type=\"password\" name=\"password\" id=\"password\" /> </td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">Uid</td><td width=\"500\"> <input type=\"text\" name=\"Uid\" id=\"Uid\" value=\"".$row['Uid']."\" /></td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">Gid</td><td width=\"500\"> <input type=\"text\" name=\"Gid\" id=\"Gid\" value=\"".$row['Gid']."\" /></td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">Status</td><td width=\"500\"> <input type=\"text\" name=\"status\" id=\"status\" value=\"".$row['status']."\" /></td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">Dir</td><td width=\"500\"> <input type=\"text\" name=\"Dir\" id=\"Dir\" value=\"".$row['Dir']."\" /></td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">ULBandwidth</td><td width=\"500\"> <input type=\"text\" name=\"ULBandwidth\" id=\"ULBandwidth\" value=\"".$row['ULBandwidth']."\" /></td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">DLBandwidth</td><td width=\"500\"> <input type=\"text\" name=\"DLBandwidth\" id=\"DLBandwidth\" value=\"".$row['DLBandwidth']."\" /></td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">ipaccess</td><td width=\"500\"> <input type=\"text\" name=\"ipaccess\" id=\"ipaccess\" value=\"".$row['ipaccess']."\" /></td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">QuotaSize</td><td width=\"500\"> <input type=\"text\" name=\"QuotaSize\" id=\"QuotaSize\" value=\"".$row['QuotaSize']."\" /></td>
- </tr>
- <tr>
- <td width=\"100\" align=\"right\">QuotaFiles</td><td width=\"500\"> <input type=\"text\" name=\"QuotaFiles\" id=\"QuotaFiles\" value=\"".$row['QuotaFiles']."\" /></td>
- </tr>
- <tr>
- <td align=\"center\" colspan=\"2\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"提交\" /> <input type=\"button\" name=\"back\" id=\"back\" onclick=\"window.history.go(-1)\" value=\"返回\" /> <input type=\"hidden\" name=\"action\" id=\"action\" value=\"".$action."\" /></td>
- </tr>
- </table>
- </form>";
- }
- function func_admin_useredit()
- {
- global $table,$crypt;
- $handle = func_getdb();
- $query = mysql_query("SELECT * FROM {$table} WHERE User = '".$_POST['User']."'" , $handle);
- $row = mysql_fetch_array( $query, MYSQL_ASSOC );
- if($row==false)
- {
- echo "不存在这个用户……";
- echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
- exit();
- }
- $query = mysql_query("UPDATE {$table} SET password = ".$crypt."('".$_POST['password']."') , Uid = {$_POST['Uid']} , Gid = {$_POST['Gid']} , status = '{$_POST['status']}' , Dir = '{$_POST['Dir']}' , ULBandwidth = {$_POST['ULBandwidth']} , DLBandwidth = {$_POST['DLBandwidth']} , ipaccess = '{$_POST['ipaccess']}' , QuotaSize = {$_POST['QuotaSize']} , QuotaFiles = {$_POST['QuotaFiles']} WHERE User = '{$_POST['User']}'");
- if($query)
- {
- echo "修改成功,稍后返回……";
- }
- else
- {
- echo "修改失败,请仔细检查每个参数……";
- }
- echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
- exit();
- }
- function func_admin_useradd()
- {
- global $table,$crypt;
- $handle = func_getdb();
- $query = mysql_query("SELECT * FROM {$table} WHERE User = '".$_POST['User']."'" , $handle);
- $row = mysql_fetch_array( $query, MYSQL_ASSOC );
- if($row)
- {
- echo "用户已经存在……";
- echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
- exit();
- }
- $query = mysql_query("INSERT INTO {$table} SET password = ".$crypt."('".$_POST['password']."') , Uid = {$_POST['Uid']} , Gid = {$_POST['Gid']} , status = '{$_POST['status']}' , Dir = '{$_POST['Dir']}' , ULBandwidth = {$_POST['ULBandwidth']} , DLBandwidth = {$_POST['DLBandwidth']} , ipaccess = '{$_POST['ipaccess']}' , QuotaSize = {$_POST['QuotaSize']} , QuotaFiles = {$_POST['QuotaFiles']} , User = '{$_POST['User']}' , comment = ''");
- if($query)
- {
- echo "添加成功,稍后返回……";
- }
- else
- {
- echo "添加失败,请仔细检查每个参数……";
- }
- echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
- exit();
- }
- function func_user_del( $user )
- {
- global $table;
- $handle = func_getdb();
- $query = mysql_query("DELETE FROM {$table} WHERE User = '{$user}'" , $handle);
- if($query)
- {
- echo "删除成功,稍后返回……";
- }
- else
- {
- echo "删除失败,稍后返回……";
- }
- echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
- }
- function func_logout()
- {
- session_destroy();
- echo "退出成功……";
- echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=userlogin\">";
- }
- ?>
- </meta>