<%
'-------------------清竹虚拟主机管理创建----------------------------
'页面验证封条，请勿修改，否则系统将无法正常运行
'-------------------------------------------------------------------
'创建新帐户+域名信息
Function AddUserDomain(Domain, mxuser, username, userpass, mxsize, EndDate)
    '创建域名
    mxuser=mxuser-0
    mxsize=mxsize-0
    Set MDomain = Server.CreateObject("EasyMail.Domain")
        MDomain.Load
        AllDomain = MDomain.GetCount
        I = 0
        Do While I < AllDomain
            If Domain = MDomain.GetDomain(I) Then
                AddUserDomain = "0001" '0001域名已经存在
                Set MDomain = Nothing
                ExitFunction=True
                Exit Do
            End If
            I = I + 1
        Loop
        If ExitFunction=True Then
        	Exit Function
        End If
        MDomain.AddDomain Domain
        MDomain.Save
    Set MDomain = Nothing
    '创建默认用户
    Set MAddUser = Application("em")
        MAddUser.AddUser username, userpass, Domain, "Create By Soft"
    Set MAddUser = Nothing
    a = Now
    While DateDiff("s", a, Now) < 2
    Wend
    '添加域控制信息
    Set MCDomain = Server.CreateObject("EasyMail.Domain")
        MCDomain.Load
        mxsize = mxsize * 1024
        MCDomain.AddControlMsgEx Domain, False, mxuser, username, mxsize, 102400, EndDate
        MCDomain.SaveControlMsg
        MCDomain.Save
    Set MDomain = Nothing
    AddUserDomain="1"
End Function
'获取域下用户列表函数
Function GetUserByDomain(Domain)
    Set UserList = Application("em")
    I = 0
    AllNum = UserList.GetUsersCount
    BackStr=""
    Do While I < AllNum
        UserList.GetUserByIndex I, outname, outdomain, outcomment

        If outdomain = Domain Then
            BackStr= BackStr& outname & ":"
        End If
        I = I + 1
    Loop
    Set UserList = Nothing
    GetUserByDomain=BackStr
End Function
'获取域管理员信息函数
Function GetManageDomainInfo(Domain)
    Set MDomain = Server.CreateObject("EasyMail.Domain")
    MDomain.Load
    MDomain.GetControlMsgEx Domain, IsShow, MaxUser, dmanager, MaxSize, AllSize, expire
    '计算该域名下的用户数
    Set UserList = Application("em")
    I = 0
    AllNum = UserList.GetUsersCount
    DomainUserNum = 0
    Do While I < AllNum
        UserList.GetUserByIndex I, outname, outdomain, outcomment
        If outdomain = Domain Then
            DomainUserNum = DomainUserNum + 1
        End If
        I = I + 1
    Loop
    Set UserList = Nothing
    '输出信息
    dout = CStr(MaxUser) & ":"
    dout = dout & DomainUserNum & ":"
    dout = dout & CStr(MaxSize / 1024) & ":"
    dout = dout & CStr(AllSize / 1024) & ":"
    dout = dout & CStr(expire)
    GetManageDomainInfo = dout
    Set MDomain = Nothing
End Function
'-------------------清竹虚拟主机管理创建----------------------------
'页面验证封条，请勿修改，否则系统将无法正常运行
'-------------------------------------------------------------------
'获取域名用户数函数
Function DomainUserCont(Domain)
    Set UserList = Application("em")
    I = 0
    AllNum = UserList.GetUsersCount
    DomainUserCont = 0
    Do While I < AllNum
        UserList.GetUserByIndex I, outname, outdomain, outcomment
        If outdomain = Domain Then
            DomainUserCont = DomainUserCont + 1
        End If
        I = I + 1
    Loop
    Set UserList = Nothing
End Function
'获取用户状态函数
Function GetUserState(username)
    Set UserList = Application("em")
    UserList.GetUserByName1 username, outname, outdomain, outcomment, outforbid, outlasttime
    GetUserState = outforbid
    Set UserList = Nothing
End Function
'获取信箱大小函数
Function GetUserSize(username)
    Set UserList = Application("em")
    GetUserSize = CStr(UserList.GetMailBoxSize(username) / 1024)
    Set UserList = Nothing
End Function
'删除用户函数
Function DelMailUser(username)
    Set UserList = Application("em")
    UserList.DelUserByName (username)
    DelMailUser = "1"
    Set UserList = Nothing
End Function
'删除域名函数
Function DelDomain(Domain)
	Dim ei
	Set ei = Server.CreateObject("easymail.domain")
	ei.Load
    Set UserList = Application("em")
    I = 0
    AllNum = UserList.GetUsersCount
    Do While I <= AllNum
        UserList.GetUserByIndex I, outname, outdomain, outcomment
        If outdomain = Domain Then
            delusers=outname&":"&delusers
        End If
        I = I + 1
    Loop
    delusers=left(delusers,len(delusers)-1)
    If delusers<>"" Then
	    If Instr(delusers,":")<>0 Then
	    	deluserArr=Split(delusers,":")
	    	For I=0 To UBound(deluserArr)
	    		UserList.DelUserByName deluserArr(I)
	    	Next
	    Else
	    	UserList.DelUserByName delusers
	    End If
	End If
    Set UserList = Nothing
	ei.DelDomainByName Domain
	ei.Save
	Set ei = Nothing
	DelDomain="1"
End Function
'判断是否存在该用户函数
Function CheckIsUser(username)
    Set UserList = Application("em")
    CheckIsUser = UserList.isUser(username)
    Set UserList = Nothing
End Function
'修改用户密码函数
Function ChangeUserPass(username, pass)
    Set UserList = Application("em")
    UserList.ChangeUserPassWord username, pass
    ChangeUserPass = "Complete"
    Set UserList = Nothing
End Function
'修改用户状态、最大容量值函数
Function ChaSizeState(username, mxsize, state)
    If state = "false" Then
        state = False
    Else: state = "true"
        state = True
    End If
    Set UserList = Application("em")
    UserList.SetMailBoxSize username, mxsize * 1024
    UserList.ForbidUserByName username, state
    ChaSizeState = "Complete"
    Set UserList = Nothing
End Function
'判断是否该域管理员
Function IsDomainAdmin(username)
    Set UserList = Application("em")
    IsDomainAdmin = UserList.IsDomainManager(username)
    Set UserList = Nothing
End Function
'-------------------清竹虚拟主机管理创建----------------------------
'页面验证封条，请勿修改，否则系统将无法正常运行
'-------------------------------------------------------------------
'创建用户函数
Function AddMailUser(username, pass, Domain, Size)
    Size = Size * 1024
    '判断是否存在该用户
    If CheckIsUser(username) = True Then
        AddMailUser = "0003" '错误代码0003用户名已存在
        Exit Function
    End If
    '判断是否存在域名
    Set MDomain = Server.CreateObject("EasyMail.Domain")
    MDomain.Load
    If MDomain.IsDomain(Domain) = False Then
        AddMailUser = "0004" '错误代码0004域名不存在
        Exit Function
    End If
     '判断是否超出用户数、是否超出可分配空间
    MDomain.GetControlMsgEx Domain, IsShow, MaxUser, dmanager, MaxSize, AllSize, expire
    CheckUserCont = MaxUser '取得该域下最大用户数
    NowUserCont = MDomain.GetUserNumberInDomain(Domain) + 1 '当前域名下的用户总数
    NowUserAllSize = AllSize + Size '当前域名下已分配的空间数额
    CheckUserAllSize = MaxSize '该域下可分配的最大数额
    If NowUserCont > CheckUserCont Then
        AddMailUser = "0005" '错误代码0005超过用户数额
        Exit Function
    End If
   If NowUserAllSize > CheckUserAllSize Then
        AddMailUser = "0006" '错误代码0006超过可分配空间
        Exit Function
   End If
   '以上条件通过，则创建开始用户
   Set MDomain = Nothing
   Set MAddUser = Application("em")
   MAddUser.AddUser username, pass, Domain, "Create By Soft"
   MAddUser.SetMailBoxSize username, Size
   Set MAddUser = Nothing
   AddMailUser="1"
End Function
'----------
'判断系统是否已启动函数
'----------------
Function CheSysIsOk()
Set mam = Server.CreateObject("easymail.AdminManager")
mam.Load
    I = 0
    Do While I < 30
        mam.LoadExt
        If mam.IsLoadOK = True Then
            Exit Do
        End If

        mam.Sleep 100
        I = I + 1
    Loop
If mam.IsLoadOK = True Then
    CheSysIsOk = 1 '表示已启动
    Set mam = Nothing
Else
    CheSysIsOk = 0 '未启动
    Set mam = Nothing
End If
End Function
'-------------------
'判断是否存在该域名函数
'--------------------
Function CheIsDomain(Domain)
 Dim ei
Set ei = Server.CreateObject("easymail.domain")
ei.Load
CheIsDomain = ei.IsDomain(Domain)
Set ei = Nothing
End Function
'----------------------
'修改域名最大使用值函数
'----------------------
Function ChaDomainMxSize(Domain, Size)
    Dim ei
    Set ei = Server.CreateObject("easymail.domain")
    ei.Load
    ei.GetControlMsgEx Domain, IsShow, MaxUser, Manager, MaxSize, AllSize, Expires
    GIsShow = IsShow
    GMaxUser = MaxUser
    GManager = Manager
    Size = Size * 1024
    GAllSize = AllSize
    GExpires = Expires
    ei.AddControlMsgEx Domain, GIsShow, GMaxUser, GManager, Size, GAllSize, GExpires
    ei.SaveControlMsg
    ei.Save
    Set ei = Nothing
    ChaDomainMxSize = "1" '返回创建成功值
End Function
'------------------
'修改域名最大用户数
'------------------
Function ChaDomainMxUser(Domain, UserNum)
    Dim ei
    Set ei = Server.CreateObject("easymail.domain")
    ei.Load
    ei.GetControlMsgEx Domain, IsShow, MaxUser, Manager, MaxSize, AllSize, Expires
    GIsShow = IsShow
    UserNum = UserNum-0
    GManager = Manager
    GMaxSize = MaxSize
    GAllSize = AllSize
    GExpires = Expires
    ei.AddControlMsgEx Domain, GIsShow, UserNum, GManager, GMaxSize, GAllSize, GExpires
    ei.SaveControlMsg
    ei.Save
    Set ei = Nothing
    ChaDomainMxUser = "1" '返回创建成功值
End Function
'------------------
'修改域名结束日期
'------------------
Function ChaDomainEndDate(EndDate, Domain)
    Dim ei
    Set ei = Server.CreateObject("easymail.domain")
    ei.Load
    ei.GetControlMsgEx Domain, IsShow, MaxUser, Manager, MaxSize, AllSize, Expires
    GIsShow = IsShow
    GMaxUser = MaxUser
    GManager = Manager
    GMaxSize = MaxSize
    GAllSize = AllSize
    ei.AddControlMsgEx Domain, GIsShow, GMaxUser, GManager, GMaxSize, GAllSize, EndDate
    ei.SaveControlMsg
    ei.Save
    Set ei = Nothing
    ChaDomainEndDate = "1" '返回创建成功值
End Function
'-------------------清竹虚拟主机管理创建----------------------------
'页面验证封条，请勿修改，否则系统将无法正常运行
'-------------------------------------------------------------------
%>