C# 管理Serv-U

// Serv-U 管理

using  System;
using  System.Data;
using  System.Data.OleDb;
using  System.Web.Security;

namespace  Host.AdminManager.Inc
{
///   <summary>
///  ServU 的摘要说明。
///   </summary>
// Access,AlwaysLogin,ChangePass,Disable,Expirationtype,Expiration,Groups,HideHidden,HomeDir,idleTimeOut,LogMesfile,MaxIp,MaxSpeedDown,MaxSpeedUp,MaxUsers,Name,Needsecure,Notes,PassType,Password,Privilege,QuotaCurrent,QuotaEnable,QuotaMax,RatioCredit,RatioDown,RatioType,RatioUP,RelPaths,SessionTimeOut,SkeyValues
public   class  ServU
{
#region  四程构造函数
///   <summary>
///  用户名,密码,ftp主目录,空间大小(单位M)
///   </summary>
///   <param name="帐号"></param>
///   <param name="密码"></param>
///   <param name="目录"></param>
public  ServU( string  帐号, string  密码, string  目录)
{
Name 
=  帐号;
Password 
=  密码;
HomeDir 
=  目录;
Access 
=  目录  +   " |RWAMLCDP " ;
}
///   <summary>
///  用户名,密码,ftp主目录,空间大小(单位M)
///   </summary>
///   <param name="帐号"></param>
///   <param name="密码"></param>
///   <param name="目录"></param>
///   <param name="权限"></param>
public  ServU( string  帐号, string  密码, string  目录, string  权限)
{
Name 
=  帐号;
Password 
=  密码;
HomeDir 
=  目录;
Access 
=  目录  +   " | "   +  权限;
}
///   <summary>
///  用户名,密码,ftp主目录,空间大小(单位M)
///   </summary>
///   <param name="帐号"></param>
///   <param name="密码"></param>
///   <param name="目录"></param>
///   <param name="权限"></param>
public  ServU( string  帐号, string  密码, string  目录, string  空间)
{
Name 
=  帐号;
Password 
=  密码;
HomeDir 
=  目录;
QuotaMax 
=  空间;
Access 
=  目录  +   " |RWAMLCDP " ;
QuotaEnable 
=   " 1 " ;
}
///   <summary>
///  用户名,密码,ftp主目录,空间大小(单位M)
///   </summary>
///   <param name="帐号"></param>
///   <param name="密码"></param>
///   <param name="目录"></param>
///   <param name="空间"></param>
///   <param name="权限"></param>
public  ServU( string  帐号, string  密码, string  目录, string  空间, string  权限)
{
Name 
=  帐号;
Password 
=  密码;
HomeDir 
=  目录;
QuotaMax 
=  空间;
Access 
=  目录  +   " | "   +  权限;
QuotaEnable 
=   " 1 " ;
}
#endregion
#region  属性定义
public   string  目录IP访问规则
{
get
{
return  Access;
}
set
{
Access 
=  value;
}
}
public   string  总是允许登陆
{
get
{
return  AlwaysLogin;
}
set
{
AlwaysLogin 
=  value;
}
}
public   string  是否允许更改密码
{
get
{
return  ChangePass;
}
set
{
ChangePass 
=  value;
}
}
public   string  启用禁用帐号
{
get
{
return  Disable;
}
set
{
Disable 
=  value;
}
}
public   string  帐号到期型类
{
get
{
return  Expirationtype;
}
set
{
Expirationtype 
=  value;
}
}
public   string  帐号到期时间
{
get
{
return  Expiration;
}
set
{
Expiration 
=  value;
}
}
public   string  成员组名称
{
get
{
return  Groups;
}
set
{
Groups 
=  value;
}
}
public   string  是否隐藏具有隐藏属性的文件
{
get
{
return  HideHidden;
}
set
{
HideHidden 
=  value;
}

public   string  空闲超时
{
get
{
return  idleTimeOut;
}
set
{
idleTimeOut 
=  value;
}
}
public   string  登陆消息文件
{
get
{
return  LogMesfile;
}
set
{
LogMesfile 
=  value;
}
}
public   string  同一IP的最大用户
{
get
{
return  MaxIp;
}
set
{
MaxIp 
=  value;
}
}
///   <summary>
///  连接速度 单位 KB/秒,
///   </summary>
public   string  最大下载链接速度
{
get
{
return  MaxSpeedDown;
}
set
{
MaxSpeedDown 
=  value;
}
}
///   <summary>
///  连接速度 单位 KB/秒,
///   </summary>
public   string  最大上传链接速度
{
get
{
return  MaxSpeedUp;
}
set
{
MaxSpeedUp 
=  value;
}
}
public   string  最大并发用户
{
get
{
return  MaxUsers;
}
set
{
MaxUsers 
=  value;
}
}
public   string  帐号名称
{
get
{
return  Name;
}
set
{
Name 
=  value;
}
}
public   string  进程加密
{
get
{
return  Needsecure;
}
set
{
Needsecure 
=  value;
}
}
public   string  帐号注解
{
get
{
return  Notes;
}
set
{
Notes 
=  value;
}
}
public   string  密码类型
{
get
{
return  PassType;
}
set
{
PassType 
=  value;
}
}
public   string  管理权限
{
get
{
return  Privilege;
}
set
{
Privilege 
=  value;
}
}
public   string  当前磁盘配额
{
get
{
return  QuotaCurrent;
}
set
{
QuotaCurrent 
=  value;
}
}
public   string  允许配额
{
get
{
return  QuotaEnable;
}
set
{
QuotaEnable 
=  value;
}
}
public   string  最大磁盘配置额
{
get
{
return  QuotaMax;
}
set
{
QuotaMax 
=  (Convert.ToInt32(value) * 1024 * 1024 ).ToString();
}
}
public   string  比率信任
{
get
{
return  RatioCredit;
}
set
{
RatioCredit 
=  value;
}
}
public   string  下载率
{
get
{
return  RatioDown;
}
set
{
RatioDown 
=  value;
}
}
public   string  比率类型
{
get
{
return  RatioType;
}
set
{
RatioType 
=  value;
}
}
public   string  上载率
{
get
{
return  RatioUP;
}
set
{
RatioUP 
=  value;
}
}
public   string  锁定于主目录
{
get
{
return  RelPaths;
}
set
{
RelPaths 
=  value;
}
}
public   string  进程超时
{
get
{
return  SessionTimeOut;
}
set
{
SessionTimeOut 
=  value;
}
}
public   string  S_KEY设置
{
get
{
return  SkeyValues;
}
set
{
SkeyValues 
=  value;
}
}

#endregion
#region  初始化
private   string  Access  =   "" // @"e:\web|RWAMLCDP";
private   string  AlwaysLogin  =   " 0 " ;
private   string  ChangePass  =   " 1 " ;
private   string  Disable  =   " 0 " ;
private   string  Expirationtype  =   " 0 " ;
private   string  Expiration  =   " 1980-1-1 " ;
private   string  Groups  =   "" ;
private   string  HideHidden  =   " 0 " ;
private   string  HomeDir  =   "" // 主目录 
private   string  idleTimeOut  =   " 600 " // 毫秒
private   string  LogMesfile  =   @" http://vs.2288.org/host/copyright.aspx " ;
private   string  MaxIp  =   " -1 " ;
private   string  MaxSpeedDown  =   " 204800 " // 下载 204800/1024=200KB/秒
private   string  MaxSpeedUp  =   " 204800 " // 上传
private   string  MaxUsers  =   " -1 " // 最大用户连接数
private   string  Name  =   "" ;
private   string  Needsecure  =   " 0 " ;
private   string  Notes  =   "" ;
private   string  PassType  =   " 0 " ;
private   string  Password  =   "" ;
private   string  Privilege  =   " 0 " ;
private   string  QuotaCurrent  =   " 0 " // 当前配额 10485760/1024/1024=10M
private   string  QuotaEnable  =   " 0 " ;
private   string  QuotaMax  =   " 0 " // 最大配额
private   string  RatioCredit  =   " 0 " ;
private   string  RatioDown  =   " 1 " ;
private   string  RatioType  =   " 0 " ;
private   string  RatioUP  =   " 1 " ;
private   string  RelPaths  =   " 1 " ;
private   string  SessionTimeOut  =   " 0 " ;
private   string  SkeyValues  =   "" ;
#endregion
#region  读取/增加/删除
public  DataSet Read()
{
string  str  =   @" Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings[ " ftp数据库路径 " ]);
OleDbConnection OleConn 
=   new  OleDbConnection(str);
OleDbDataAdapter OleDa 
=   new  OleDbDataAdapter( " SELECT * FROM useraccounts " , OleConn);
DataSet ds 
=   new  DataSet();
OleDa.Fill(ds, 
" 读取库 " );
OleConn.Close();
OleConn.Dispose();
return  ds;
}
public  Boolean Add()

Password 
=  NewMiMa(Password);
string  str1  =   " [Access],[AlwaysLogin],[ChangePass],[Disable],[Expirationtype],[Expiration],[Groups],[HideHidden],[HomeDir],[idleTimeOut],[LogMesfile],[MaxIp],[MaxSpeedDown],[MaxSpeedUp],[MaxUsers],[Name],[Needsecure],[Notes],[PassType],[Password],[Privilege],[QuotaCurrent],[QuotaEnable],[QuotaMax],[RatioCredit],[RatioDown],[RatioType],[RatioUP],[RelPaths],[SessionTimeOut],[SkeyValues] " ;
string  str2  =   " ' " + Access + " ', " + AlwaysLogin + " , " + ChangePass + " , " + Disable + " , " + Expirationtype + " ,# " + Expiration + " #,' " + Groups + " ', " + HideHidden + " ,' " + HomeDir + " ', " + idleTimeOut + " ,' " + LogMesfile + " ', " + MaxIp + " , " + MaxSpeedDown + " , " + MaxSpeedUp + " , " + MaxUsers + " ,' " + Name + " ', " + Needsecure + " ,' " + Notes + " ', " + PassType + " ,' " + Password + " ', " + Privilege + " , " + QuotaCurrent + " , " + QuotaEnable + " , " + QuotaMax + " , " + RatioCredit + " , " + RatioDown + " , " + RatioType + " , " + RatioUP + " , " + RelPaths + " , " + SessionTimeOut + " ,' " + SkeyValues + " ' " ;
string  str  =   @" Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings[ " ftp数据库路径 " ]);
OleDbConnection conn 
=   new  OleDbConnection(str);
OleDbCommand cmd 
=   new  OleDbCommand( " INSERT INTO [useraccounts] ( " + str1 + " ) VALUES ( " + str2 + " ) " , conn); 
conn.Open();
cmd.ExecuteNonQuery(); 
conn.Close();
conn.Dispose();
return   true ;
}
public   void  update( string  name,  string  password)
{
password 
=  NewMiMa(password);
string  str  =   @" Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings[ " ftp数据库路径 " ]);
OleDbConnection conn 
=   new  OleDbConnection(str);
OleDbCommand cmd 
=   new  OleDbCommand( " UPDATE [useraccounts] SET [name]=' " + name + " ', [password]=' " + password + " ' WHERE name=' " + name + " ' " , conn);
conn.Open();
cmd.ExecuteNonQuery(); 
cmd.Connection.Close();
conn.Dispose();
}

public  Boolean del( string  name)
{
string  str  =   @" Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings[ " ftp数据库路径 " ]);
OleDbConnection conn 
=   new  OleDbConnection(str);
OleDbCommand cmd 
=   new  OleDbCommand( " DELERE FROM [useraccounts] WHERE name=' " + name + " ' " , conn);
cmd.Connection.Open();
cmd.ExecuteNonQuery(); 
cmd.Connection.Close();
cmd.Connection.Dispose();
return   true ;
}

#endregion
#region  加密方法,取随时数
private   string  JiaMi( string  UserPassword,  string  Password)  // 取原密码前两位来加密,以此合对密码

string  Password2  =  UserPassword.Substring( 0 , 2 );
Password 
=  Password2  +  Password;  // 取密码的左边两位
Password  =  FormsAuthentication.HashPasswordForStoringInConfigFile(Password, " MD5 " );
return  Password2  +  Password;
}
private   string  NewMiMa( string  Password)  // 新密码加密
{
string  a  =  MakePassword();
string  p  =  a  +  Password;
Password 
=  FormsAuthentication.HashPasswordForStoringInConfigFile(p, " MD5 " );
return  a  +  Password;
}
private   string  MakePassword()

int  pwdlen  =   2 // 生成随机字符的位数
string  pwdchars  =   " abcdefghijklmnopkrstuvwxyzZBCDEFGHIJKLMNOPKRSTUVWXYZ " // 生成的字符包含那字
string  tmpstr  =   ""
int  iRandNum; 
Random rnd 
=   new  Random(); 
for ( int  i = 0 ;i < pwdlen;i ++ )

iRandNum 
=  rnd.Next(pwdchars.Length); 
tmpstr 
+=  pwdchars[iRandNum]; 

return  tmpstr; 
}
#endregion
}
}

  

转载于:https://www.cnblogs.com/qinfei/archive/2005/11/03/268238.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值