Warning: curl_exec() has been disabled for security reasons in /pub/host/sunboyu/sunboyu/www/wp-includes/http.php on line 1022
2009 七月 10 一个程序猿 孙小一,孙小二,PHP,MYSQL,LINUX,APACHE,原创技术,扯淡

PHP开发的一个pureftpd管理工具

作者 : admin 于 2009年07月10日, 16:49:14
2009
07-10

用过pureftpd manager,虽然功能足够,但很多bug,无法使用,而pureftpd功能简单,写个管理工具也没多复杂,于是乎,花两个晚上写了个简单的管理脚本,分享给大家。不过没来得及写注释,回头会把注释补上。

分流下载 http://down.chinaz.com/soft/26439.htm

点击下载

  1. < ?php
  2. error_reporting(2047);
  3. header("Content-Type: text/html; charset=utf-8");
  4. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  5. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // 过去的时间
  6. define("FILENAME",$_SERVER['PHP_SELF']);
  7. $adminuser = "admin";
  8. $adminpass = "admin";
  9.  
  10. $servtype = 'mysql';
  11. $hostname = 'localhost';
  12. $username = 'root';
  13. $password = '123456';
  14. $datebase = 'pure-ftpd';
  15. $table    = "users";
  16. $charset  = 'utf8';
  17. $crypt    = "MD5";
  18.  
  19. session_start();
  20. #session_destroy();
  21. $action = isset($_GET['action']) ? $_GET['action'] : "index";
  22.  
  23.  
  24. switch( $action )
  25. {
  26.     case "index":
  27.     checklogin();
  28. func_html( 0 );
  29. switch($_SESSION['user'])
  30. {
  31.     case $adminuser:
  32.     func_admin_index();
  33. break;
  34. default:
  35.     func_user_index();
  36. break;
  37. }
  38. func_html( 1 );
  39. break;
  40.     case "userlogin":
  41. case "adminlogin":
  42.     func_html( 0 );
  43.     func_userlogin();
  44. func_html( 1 );
  45. break;
  46. case "userloginaction":
  47.     func_userloginaction( $_POST['username'] , $_POST['password'] , $_POST['logintype'] );
  48. break;
  49. case "userpasswordchang":
  50.     checklogin();
  51. user_password_chang( $_POST['password'] );
  52. break;
  53. case "adminchangeuserpassword":
  54. case "useradd":
  55.     checklogin(true);
  56. func_admin_user_edit( isset($_GET['user']) ? $_GET['user'] : false );
  57. break;
  58. case "userinfoac":
  59.     checklogin(true);
  60. switch($_POST['action'])
  61. {
  62.     case "edit":
  63.     func_admin_useredit();
  64. break;
  65. case "add":
  66.     func_admin_useradd();
  67. break;
  68. }
  69. break;
  70. case "adminuserdel":
  71.     func_user_del( $_GET['user'] );
  72. break;
  73. case "logout":
  74.     func_logout();
  75. break;
  76. }
  77.  
  78.  
  79. function func_html( $position = 0 )
  80. {
  81.     switch( $position )
  82. {
  83.     case 0:
  84.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  85. <html xmlns=\"http://www.w3.org/1999/xhtml\">
  86. <head>
  87. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
  88. <title>PURE-FTPD简易管理系统</title>
  89. <style type=\"text/css\">
  90. td
  91. {
  92. padding:4px;
  93. }
  94. .bar
  95. {
  96.     width:80%;
  97. border-bottom:dotted 1px #aaa;
  98. margin-bottom:20px;
  99. padding:10px;
  100. }
  101. </style>
  102. </head>
  103. <body>
  104. <div class=\"bar\">PURE-FTPD简易管理工具 &nbsp; 孙博宇 &nbsp; http://www.sunboyu.cn &nbsp; QQ:176300676 &nbsp; MSN:sunboyu@gmail.com  &nbsp; ";
  105. if(isset($_SESSION['user']))
  106. {
  107.     echo "<input type=\"button\" name=\"logout\" id=\"logout\" value=\"退出\"  onclick=\"window.location.href='?action=logout'\" />";
  108. }
  109. echo "</div>";
  110. break;
  111. case 1:
  112.     echo "</body>
  113. </html>
  114. ";
  115. break;
  116. }
  117.     
  118. }
  119. function checklogin( $type = false )
  120. {
  121.     global $adminuser;
  122.     if(!isset($_SESSION['user']))
  123. {
  124. header("Location:".FILENAME."?action=userlogin");
  125. }
  126. if($type&&$_SESSION['user']!=$adminuser)
  127. {
  128.     header("Location:".FILENAME."?action=adminlogin");
  129. }
  130. }
  131.  
  132. function func_userlogin( )
  133. {
  134.     echo "<form name=\"loginform\" id=\"loginform\" action=\"?action=userloginaction\" method=\"post\">
  135. <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin:0px;\">
  136. <tr>
  137. <td colspan=\"2\" align=\"center\">用户登录</td>
  138. </tr>
  139. <tr>
  140. <td width=\"60\" align=\"right\">用户名</td><td width=\"200\"><input type=\"text\" name=\"username\" id=\"username\" /></td>
  141. </tr>
  142. <tr>
  143. <td align=\"right\">密码</td><td><input type=\"password\" name=\"password\" id=\"password\" /></td>
  144. </tr>
  145. <tr>
  146. <td align=\"center\" colspan=\"2\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"登录\" /><input type=\"hidden\" name=\"logintype\" id=\"logintype\" value=\"{$_GET['action']}\" /> &nbsp; ";
  147. if($_GET['action']=="userlogin")
  148. {
  149.     echo "<a href=\"?action=adminlogin\">管理员登录</a>";
  150. }
  151. else
  152. {
  153.     echo "<a href=\"?action=userlogin\">用户登录</a>";
  154. }
  155. echo "</td>
  156. </tr>
  157. <tr>
  158. <td align=\"center\" colspan=\"2\">".(isset($_GET['error']) ? $_GET['error'] : "")."</td>
  159. </tr>
  160. </table>
  161. </form>
  162. ";
  163. }
  164.  
  165. function func_getdb()
  166. {
  167.     global $hostname,$username,$password,$datebase,$charset;
  168. $handle = @mysql_connect( $hostname , $username , $password , false ) or die("Can't connetc to the DateBse.".mysql_error());
  169. @mysql_select_db( $datebase , $handle ) or die("Can't select the DateBase".mysql_error());
  170. mysql_query( "SET NAMES '{$charset}'" , $handle );
  171. return $handle;
  172. }
  173.  
  174. function func_userloginaction( $usernames , $passwords , $logintype )
  175. {
  176.     switch( $logintype )
  177. {
  178.     case "userlogin":
  179.     global $table,$username,$password,$crypt;
  180. $handle = func_getdb();
  181. #echo "SELECT COUNT(*) AS count FROM {$table} WHERE User = '{$usernames}' AND Password = ".$crypt."('".$passwords."')";
  182. $query = mysql_query("SELECT COUNT(*) AS count FROM {$table} WHERE User = '{$usernames}' AND Password = ".$crypt."('".$passwords."')" , $handle);
  183. $row = mysql_fetch_array( $query, MYSQL_ASSOC );
  184. if($row['count']==1)
  185. {
  186. $_SESSION['user'] = $usernames;
  187. echo "登录成功,跳转中……";
  188. echo "<meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  189. }
  190. else
  191. {
  192. header("Location:".FILENAME."?action=userlogin&error=".urlencode("用户名或者密码错误!"));
  193. }
  194. break;
  195. case "adminlogin":
  196.     global $adminuser,$adminpass;
  197.     if($adminuser==$usernames&&$adminpass==$passwords)
  198. {
  199.     $_SESSION['user'] = $usernames;
  200. echo "登录成功,跳转中……";
  201. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  202. }
  203. else
  204. {
  205.     header("Location:".FILENAME."?action=adminlogin&error=".urlencode("用户名或者密码错误!"));
  206. }
  207. break;
  208. }
  209. }
  210.  
  211. function func_user_index()
  212. {
  213.     global $table,$username,$password,$crypt;
  214. $handle = func_getdb();
  215. $query = mysql_query("SELECT * FROM {$table} WHERE User = '{$_SESSION['user']}'" , $handle);
  216. $row = mysql_fetch_array( $query, MYSQL_ASSOC );
  217.     echo "<form name=\"userpassword\" id=\"userpassword\" method=\"post\" action=\"?action=userpasswordchang\">
  218. <table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
  219.     <tr>
  220.     <td colspan=\"2\" align=\"center\">服务器信息</td>
  221. </tr>
  222.     <tr>
  223.     <td width=\"100\" align=\"right\">ip</td><td width=\"500\">".gethostbyname($_SERVER['SERVER_NAME'])."</td>
  224. </tr>
  225. <tr>
  226.     <td colspan=\"2\" align=\"center\">账户信息</td>
  227. </tr>
  228. <tr>
  229.     <td width=\"100\" align=\"right\">用户名</td><td width=\"500\">".$row['User']."</td>
  230. </tr>
  231. <tr>
  232.     <td width=\"100\" align=\"right\">修改密码</td><td width=\"500\"><input type=\"password\" name=\"password\" id=\"password\" /> &nbsp; <input type=\"submit\" name=\"submit\" id=\"submit\" value=\"修改\" /></td>
  233. </tr>
  234. <tr>
  235.     <td width=\"100\" align=\"right\">Uid</td><td width=\"500\">".$row['Uid']."</td>
  236. </tr>
  237. <tr>
  238.     <td width=\"100\" align=\"right\">Gid</td><td width=\"500\">".$row['Gid']."</td>
  239. </tr>
  240. <tr>
  241.     <td width=\"100\" align=\"right\">Status</td><td width=\"500\">".$row['status']."</td>
  242. </tr>
  243. <tr>
  244.     <td width=\"100\" align=\"right\">Dir</td><td width=\"500\">".$row['Dir']."</td>
  245. </tr>
  246. <tr>
  247.     <td width=\"100\" align=\"right\">ULBandwidth</td><td width=\"500\">".$row['ULBandwidth']."</td>
  248. </tr>
  249. <tr>
  250.     <td width=\"100\" align=\"right\">DLBandwidth</td><td width=\"500\">".$row['DLBandwidth']."</td>
  251. </tr>
  252. <tr>
  253.     <td width=\"100\" align=\"right\">ipaccess</td><td width=\"500\">".$row['ipaccess']."</td>
  254. </tr>
  255. <tr>
  256.     <td width=\"100\" align=\"right\">QuotaSize</td><td width=\"500\">".$row['QuotaSize']."</td>
  257. </tr>
  258. <tr>
  259.     <td width=\"100\" align=\"right\">QuotaFiles</td><td width=\"500\">".$row['QuotaFiles']."</td>
  260. </tr>
  261. </table>
  262. </form>
  263. ";
  264. }
  265.  
  266. function user_password_chang( $password )
  267. {
  268.     global $crypt,$table;
  269.     if(empty($password))
  270. {
  271.     echo "密码不能为空,修改失败……";
  272. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  273. }
  274. else
  275. {
  276. $handle = func_getdb();
  277. $query = mysql_query("UPDATE {$table} SET Password = ".$crypt."('".$password."') WHERE User = '{$_SESSION['user']}'" , $handle);
  278. session_destroy();
  279. echo "修改成功,请重新登录。如果新的密码不能登录,请尝试使用旧密码进行登录……";
  280. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=userlogin\">";
  281. }
  282. }
  283.  
  284. function func_admin_index()
  285. {
  286.     global $table,$username,$password,$crypt;
  287. $handle = func_getdb();
  288. $query = mysql_query("SELECT * FROM {$table} ORDER BY User ASC" , $handle);
  289. echo "<script language=\"javascript\">
  290. function del( username )
  291. {
  292.     if(confirm('确认删除 '+username+'?'))
  293. {
  294.     window.location.href=\"?action=adminuserdel&user=\"+username;
  295. }
  296. else
  297. {
  298.     return false;
  299. }
  300. }
  301. </script><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
  302. <tr>
  303. <td colspan=\"4\" align=\"center\">用户列表</td>
  304. <td align=\"right\"><input type=\"button\" name=\"add\" id=\"add\" value=\"添加账户\" onclick=\"window.location.href='?action=useradd'\" /></td>
  305. </tr>
  306. <tr>
  307. <td align=\"center\">账号</td>
  308. <td align=\"center\">Uid</td>
  309. <td align=\"center\">Gid</td>
  310. <td align=\"center\">Dir</td>
  311. <td align=\"center\">操作</td>   
  312. </tr>";
  313. while( $row = mysql_fetch_array( $query, MYSQL_ASSOC ) )
  314. {
  315.     echo "<tr>
  316. <td>".$row['User']."</td>
  317. <td align=\"center\">".$row['Uid']."</td>
  318. <td align=\"center\">".$row['Gid']."</td>
  319. <td>".$row['Dir']."</td>
  320. <td align=\"center\"><input type=\"button\" name=\"button\" id=\"button\" value=\"修改\" onclick=\"window.location.href='?action=adminchangeuserpassword&user=".$row['User']."'\" />
  321. <input type=\"button\" name=\"del\" id=\"del\" value=\"删除\" onclick=\"del('".$row['User']."')\" /></td>   
  322. </tr>";
  323. }
  324. echo "</table>";
  325. }
  326.  
  327. function func_admin_user_edit( $user = false )
  328. {
  329.     
  330.     if($user)
  331. {
  332.     global $table,$crypt;
  333. $handle = func_getdb();
  334. $query = mysql_query("SELECT * FROM {$table} WHERE User = '".$user."'" , $handle);
  335. $row = mysql_fetch_array( $query, MYSQL_ASSOC );
  336. if($row==false)
  337. {
  338.     echo "不存在这个用户……";
  339.     echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  340. exit();
  341. }
  342. $action = "edit";
  343. }
  344. else
  345. {
  346.     $row["User"] = "";
  347. $row['Uid'] = "";
  348. $row['Gid'] = "";
  349. $row['status'] = 0;
  350. $row['Dir'] = "";
  351. $row['ULBandwidth'] = 0;
  352. $row['DLBandwidth'] = 0;
  353. $row['ipaccess'] = "*";
  354. $row['QuotaSize'] = 0;
  355. $row['QuotaFiles'] = 0;
  356. $action = "add";
  357. }
  358. echo "<form name=\"userpassword\" id=\"userpassword\" method=\"post\" action=\"?action=userinfoac\">
  359. <table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
  360. <tr>
  361.     <td colspan=\"2\" align=\"center\">账户信息</td>
  362. </tr>
  363. <tr>
  364.     <td width=\"100\" align=\"right\">用户名</td><td width=\"500\">";
  365. if($action=="add")
  366. {
  367.     echo  "<input type=\"text\" name=\"User\" id=\"User\" value=\"".$row['User']."\" />";
  368. }
  369. else
  370. {
  371.     echo  $row['User']."<input type=\"hidden\" name=\"User\" id=\"User\" value=\"".$row['User']."\" />";
  372. }
  373. echo "</td>
  374. </tr>
  375. <tr>
  376.     <td width=\"100\" align=\"right\">密码</td><td width=\"500\"><input type=\"password\" name=\"password\" id=\"password\" /> </td>
  377. </tr>
  378. <tr>
  379.     <td width=\"100\" align=\"right\">Uid</td><td width=\"500\"> <input type=\"text\" name=\"Uid\" id=\"Uid\" value=\"".$row['Uid']."\" /></td>
  380. </tr>
  381. <tr>
  382.     <td width=\"100\" align=\"right\">Gid</td><td width=\"500\"> <input type=\"text\" name=\"Gid\" id=\"Gid\" value=\"".$row['Gid']."\" /></td>
  383. </tr>
  384. <tr>
  385.     <td width=\"100\" align=\"right\">Status</td><td width=\"500\"> <input type=\"text\" name=\"status\" id=\"status\" value=\"".$row['status']."\" /></td>
  386. </tr>
  387. <tr>
  388.     <td width=\"100\" align=\"right\">Dir</td><td width=\"500\"> <input type=\"text\" name=\"Dir\" id=\"Dir\" value=\"".$row['Dir']."\" /></td>
  389. </tr>
  390. <tr>
  391.     <td width=\"100\" align=\"right\">ULBandwidth</td><td width=\"500\"> <input type=\"text\" name=\"ULBandwidth\" id=\"ULBandwidth\" value=\"".$row['ULBandwidth']."\" /></td>
  392. </tr>
  393. <tr>
  394.     <td width=\"100\" align=\"right\">DLBandwidth</td><td width=\"500\"> <input type=\"text\" name=\"DLBandwidth\" id=\"DLBandwidth\" value=\"".$row['DLBandwidth']."\" /></td>
  395. </tr>
  396. <tr>
  397.     <td width=\"100\" align=\"right\">ipaccess</td><td width=\"500\"> <input type=\"text\" name=\"ipaccess\" id=\"ipaccess\" value=\"".$row['ipaccess']."\" /></td>
  398. </tr>
  399. <tr>
  400.     <td width=\"100\" align=\"right\">QuotaSize</td><td width=\"500\"> <input type=\"text\" name=\"QuotaSize\" id=\"QuotaSize\" value=\"".$row['QuotaSize']."\" /></td>
  401. </tr>
  402. <tr>
  403.     <td width=\"100\" align=\"right\">QuotaFiles</td><td width=\"500\"> <input type=\"text\" name=\"QuotaFiles\" id=\"QuotaFiles\" value=\"".$row['QuotaFiles']."\" /></td>
  404. </tr>
  405. <tr>
  406.     <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>
  407. </tr>
  408. </table>
  409. </form>";
  410. }
  411.  
  412. function func_admin_useredit()
  413. {
  414.     global $table,$crypt;
  415. $handle = func_getdb();
  416. $query = mysql_query("SELECT * FROM {$table} WHERE User = '".$_POST['User']."'" , $handle);
  417. $row = mysql_fetch_array( $query, MYSQL_ASSOC );
  418. if($row==false)
  419. {
  420. echo "不存在这个用户……";
  421. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  422. exit();
  423. }
  424. $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']}'");
  425. if($query)
  426. {
  427.     echo "修改成功,稍后返回……";
  428. }
  429. else
  430. {
  431.     echo "修改失败,请仔细检查每个参数……";
  432. }
  433. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  434. exit();
  435. }
  436.  
  437. function func_admin_useradd()
  438. {
  439.     global $table,$crypt;
  440. $handle = func_getdb();
  441. $query = mysql_query("SELECT * FROM {$table} WHERE User = '".$_POST['User']."'" , $handle);
  442. $row = mysql_fetch_array( $query, MYSQL_ASSOC );
  443. if($row)
  444. {
  445. echo "用户已经存在……";
  446. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  447. exit();
  448. }
  449. $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 = ''");
  450. if($query)
  451. {
  452.     echo "添加成功,稍后返回……";
  453. }
  454. else
  455. {
  456.     echo "添加失败,请仔细检查每个参数……";
  457. }
  458. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  459. exit();
  460. }
  461.  
  462. function func_user_del( $user )
  463. {
  464.     global $table;
  465. $handle = func_getdb();
  466. $query = mysql_query("DELETE FROM {$table} WHERE User = '{$user}'" , $handle);
  467. if($query)
  468. {
  469.     echo "删除成功,稍后返回……";
  470. }
  471. else
  472. {
  473.     echo "删除失败,稍后返回……";
  474. }
  475. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  476. }
  477.  
  478. function func_logout()
  479. {
  480.     session_destroy();
  481. echo "退出成功……";
  482. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=userlogin\">";
  483. }
  484. ?>
  485. </meta>