现在的位置: 首页Php>正文
安装Zpanel后ftp用户密码无法修改问题解决 [原创]
2011年11月04日 Php 评论数 1 ⁄ 被围观 13,619 次+

今天安装了Zpanel-6.1.1后添加个ftp用户结果密码输入时不知道多按了个什么,怎么都不正确,就尝试修改密码,可是怎么都修改不成功。报错如下:Can't Open FileZilla configuration file! 以为是没有装好Zpanel,就又重新安装了一次,结果还是出错!很是失望!迫不得已只有看代码了,看看到底是什么原因!经过一番周折最后终于找到原因了。原来在添加ftp用户和删除ftp用户时,都有一个判断,判断服务器操作系统是否为windows,如果为windows时操作windows格式的密码文件(FileZilla Server.xml)否则操作linux格式的密码文件(zftpd.passwd),而修改密码时没有此判断,而是直接使用操作windows格式的密码文件(FileZilla Server.xml)找到原因后就好办了,直接编写代码用crypt函数生成的密码替换zftpd.passwd中的相应ftp用户即可。

原代码如下:

  1. # Edit a FileZilla FTP Account   
  2. function zapi_ftpaccount_edit($filezilla_root$username$newpassword) {   
  3.     # Reset the account password for the FTP account!   
  4.     $filezilla_reload = "\"" . $filezilla_root . "FileZilla server.exe\" /reload-config";   
  5.     $fzpath = $filezilla_root . "FileZilla Server.xml";   
  6.     $fzfile = file_get_contents($fzpathor die("Can't Open FileZilla configuration file!");   
  7.     $startpos = strpos($fzfile"<User Name=\"" . $username . "\">");   
  8.     $endpos = strpos($fzfile"</User>");   
  9.     $endposlength = "</User>";   
  10.     $endposlength = strlen($endposlength);   
  11.     $fzrecord = substr($fzfile$startpos, ($endpos - $startpos) + $endposlength);   
  12.     $replacement = "<Option Name=\"Pass\">" . md5($newpassword) . "</Option>";   
  13.     $newfzrecord = preg_replace('/<Option Name=\"Pass\">.*?<\/Option>/', $replacement, $fzrecord);
  14.     $fzfile = substr_replace($fzfile, $newfzrecord, $startpos, ($endpos - $startpos) + $endposlength);  
  15.     $filehandle = fopen($fzpath, 'w') or die("Can't Open FileZilla configuration file!");   
  16.     if (!fwrite($filehandle$fzfile)) {   
  17.         return false;   
  18.     } else {   
  19.         return true;   
  20.     }   
  21.     fclose($filehandle);   
  22. }  

修改后如下:

  1. # Edit a FileZilla FTP Account   
  2. function zapi_ftpaccount_edit($filezilla_root$username$newpassword) {   
  3.     if (ShowServerPlatform() == "Windows") {   
  4.         # Reset the account password for the FTP account!   
  5.         $filezilla_reload = "\"" . $filezilla_root . "FileZilla server.exe\" /reload-config";   
  6.         $fzpath = $filezilla_root . "FileZilla Server.xml";   
  7.         $fzfile = file_get_contents($fzpathor die("Can't Open FileZilla configuration file!");   
  8.         $startpos = strpos($fzfile"<User Name=\"" . $username . "\">");   
  9.         $endpos = strpos($fzfile"</User>");   
  10.         $endposlength = "</User>";   
  11.         $endposlength = strlen($endposlength);   
  12.         $fzrecord = substr($fzfile$startpos, ($endpos - $startpos) + $endposlength);   
  13.         $replacement = "<Option Name=\"Pass\">" . md5($newpassword) . "</Option>";   
  14.         $newfzrecord = preg_replace('/<Option Name=\"Pass\">.*?<\/Option>/', $replacement, $fzrecord);
  15.         $fzfile = substr_replace($fzfile, $newfzrecord, $startpos, ($endpos - $startpos) + $endposlength);  
  16.         $filehandle = fopen($fzpath, 'w') or die("Can't Open FileZilla configuration file!");  
  17.         if (!fwrite($filehandle, $fzfile)) {  
  18.             return false;  
  19.         } else {  
  20.             return true;  
  21.         }  
  22.         fclose($filehandle);  
  23.     }else {  
  24.         $proftpd_config = "/etc/zpanel/conf/ftp/zftpd.passwd";  
  25.         $file = file_get_contents($proftpd_config) or die("Can't Open FileZilla configuration file!");  
  26.         preg_match("/".$username.":(.{12})([^:]*)(:.*)/i", $file$matches);   
  27.         $newpath = crypt($newpassword$matches[1]);   
  28.         $newfile = str_replace($matches[0], $username.':'.$newpath.$matches[3], $file);   
  29.         file_put_contents($proftpd_config,$newfile);   
  30.     }   
  31. }  
本文地址:http://www.92csz.com/03/982.html
如非注明则为本站原创文章,欢迎转载。转载请注明转载自:moon's blog
 

目前有 1 条留言 其中:访客:1 条, 博主:0 条

  1. 椎间孔镜 : 2012年06月16日10:14:21  -49楼

    我只懂一点的代码,呵呵,要潜心在这里看看文章了