<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<!--#include virtual="/autorun/do-inc.asp"-->
<!--#include virtual="/autorun/cdnvps.asp"-->
<!--#include virtual="/autorun/cdnhost.asp"-->
<!--#include virtual="/autorun/cdnbind.asp"-->
<%
If Not Request.ServerVariables("REMOTE_ADDR")="127.0.0.1" Then
response.write "只能在主控上访问，不允许远程访问"
response.End
ElseIf Request("ip1")<>"" And not IsNumeric(replace(Request("ip1"),".","")) Then
	ef=True
	ec="ip1不对"
ElseIf Request("ip2")<>"" And not IsNumeric(replace(Request("ip2"),".","")) Then
	ef=True
	ec="ip2不对"
End if

'注意!原来可以自定义的变量已改成在同目录的do-inc.asp中定义,防止升级代替这个文件.
on error resume next

server.ScriptTimeout =1800

Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")

CDNVPSANALOG

CDNHOSTANALOG

CDNBindANALOG


'6.月流量清0
if hour(now)=6 then
'每月一次的计划，将thismonbytes=0,oldmonthbytes=thismonbytes
if Day(now)=1 then '每月1日更新
conn.Execute "update freehost.FreeHost_Product_Host set oldmonthbytes=thismonbytes,thismonbytes=0,thismonbytesALL=0"
response.write "----------------成功将虚拟主机月流量清零。<br>-----------------------------"
conn.Execute "update freehost.FreeHost_Product_VPS set CDNMBlastmonth=CDNMBthismonth,CDNMBthismonth=0"
response.write "----------------成功将VPS-CDN月流量清零。<br>-----------------------------"
conn.Execute "update freehost.FreeHost_Product_CDN set CDNMBlastmonth=CDNMBthismonth,CDNMBthismonth=0"
response.write "----------------成功将CDN多点月流量清零。<br>-----------------------------"
end If
end if

'isdoinglog=false


If Request("donow")="yes" Then
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>运行中...............................</title>
<meta http-equiv="refresh" content="5;URL=do.asp?donow=yes">
</head>
<body>
正在运行清理域名.......<%=now%>....<br>5秒后本页会自动刷新
<%
Response.Flush()
End If


'-------------------------
'1.检查库大小.....
if hour(now)=6 then
response.write "检查库大小....<br>"
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Sql"
	dsph.Open sql,conn,1,3
while not dsph.eof

	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerSQLlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
userid=dsserver ("admname")
pwd=dsserver("admpass")
homedir=dsserver("homedir")
sqlname=dsph("sqlname")
username=dsph("ftpname")
sqlpassword=dsph("sqlpassword")
softtype=dsserver("softtype")
if dsserver("softtype")="MySQL" then
getsize=ShowDirSize (dsserver("site"),FreeHostsharekey,dsserver("homedir")&"\"&dsph("sqlname"))
'response.write getsize
if instr(getsize,"出错")>1 then 
returnstr = returnstr &" 数据库放置的目录设置不正确：" &dsserver("homedir")
else
getsize=GETvalue(getsize,";目录大小为：",";FreeHostEnd")
returnstr = getsize
getsize=int(getsize/1024/1024)
returnstr = returnstr &"字节("& getsize&"M)"
dsph("userspacelimtReal")=getsize
end if%>
<%=dsph("sqlname")%>已用数据库空间：<%=returnstr%><%if getsize>dsph("userspacelimt") then%>超出上限！<%end if%>　库上限：<%=dsph("userspacelimt")%> M
<%else




URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
userid=dsserver ("admname")
pwd=dsserver("admpass")

sql="exec sp_spaceused"
Cname="database_size"
recon=SqlGetName(URL,FreeHostsharekey,dsph("sqlname"),sqlpassword,backupdir,Cname,sql)
arrystr=split(recon,"@|freehost|@")
returnstr=arrystr(0)

'response.write recon
'response.end

if (instr(recon ,"登录失败")>0 or instr(recon ,"法打开用户默认数据库")>0) then
temp=ResetSQLPassword(URL,FreeHostsharekey,userid,pwd,sqlname,sqlpassword)
'Response.Redirect "e.asp?e=由于原来的密码不同步，已自动同步数据库密码，请返回重试。"&recon
'Response.end
end if

if ubound(arrystr)<1 then
' Response.Redirect "e.asp?e=请先升级受控端"
returnstr2="未知"
returnstr3="未知"
end if

sql="DBCC SQLPERF(LOGSPACE)"
Cname="Database Name"
recon=SqlGetName(URL,FreeHostsharekey,userid,pwd,backupdir,Cname,sql)
arrystr=split(recon,"@|freehost|@")
if ubound(arrystr)<2 then
' Response.Redirect "e.asp?e=请先升级受控端"
end if
y=0
for i=0 to ubound(arrystr)
if lcase(arrystr(i))=sqlname then y=i
next
sql="DBCC SQLPERF(LOGSPACE)"
Cname="Log Size (MB)"
recon=SqlGetName(URL,FreeHostsharekey,userid,pwd,backupdir,Cname,sql)
arrystr=split(recon,"@|freehost|@")
returnstr2=arrystr(y)
if returnstr2<1 then returnstr2="0"&returnstr2
returnstr=replace(returnstr," MB","")
if (instr(1,returnstr,"GB")>0) then
returnstr=trim(replace(returnstr," GB","")*1024)
end if
if IsNumeric(returnstr) and IsNumeric(returnstr2) then returnstr3=returnstr-returnstr2

dsph("userspacelimtReal")=FormatNumber(returnstr3,3,-1)
dsph("logspacelimtReal")=FormatNumber(returnstr2,3,-1)

%>
<%=dsph("sqlname")%>已用数据库空间：<%=FormatNumber(returnstr3,3,-1)%>M　已用日志空间：<%=FormatNumber(returnstr2,3,-1)%>M　<%if getsize>dsph("userspacelimt") then%>超出上限！<%end if%>　库上限：<%=dsph("userspacelimt")%> M　日志上限：<%=dsph("logspacelimt")%> M
<%




end if
end if
dsph("checktime")=now
dsph.update
dsph.movenext
wend
dsph.close
end if
'完成检查库大小.....








'2.清理过期删除不光的文件,提取日志
set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist"
if hour(now)=4 Or hour(now)=5 Or hour(now)=6 Then
sql="Select top 25 * from FreeHost.FreeHost_Serverlist where lastlogtime<'"&date&"' or lastlogtime is null"
End If

if hour(now)=7 Then
sql="Select * from FreeHost.FreeHost_Serverlist where lastlogtime<'"&date&"'"
End if

	dsserver.Open Sql,conn,1,1
while not dsserver.Eof
'response.write "服务器："&dsserver("id")&" "
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
	ostype=dsserver("ostype")'linux
dirname=dsserver("homedir")

if hour(now)=1 then
if autodeloldfiel=true Then
response.write "删除清空不了的数据....<br>"
Response.Write CleanRoot(URL,FreeHostsharekey,dirname)
end If
end if

'3.控制受控端分析日志
if hour(now)=1 then
if autodeloldlog then
Response.Write CountLOG(URL,FreeHostsharekey,"a yes -1")&"成功发出统计并删除过期日志指令服务器ID:"&dsserver("id")'&"受控网址:"&URL
else
Response.Write CountLOG(URL,FreeHostsharekey,"a b -1")&"成功发出统计指令服务器ID:"&dsserver("id")&"受控网址:"&URL
end if
conn.Execute "update freehost.FreeHost_Serverlist set lastanatime='"&now&"' where id="&dsserver("id")&""
conn.Execute "update freehost.FreeHost_Product_Host set BytesReceived=0,BytesSent=0,TimeTaken=0"'add by 2007-4-28
response.write "初始化流量数据....<br>"
end if
'控制受控端分析日志

'4.控制受控端备份
'if hour(now)=backuphour Then
'response.write "当前进入备份小时<br>"
'End If
'if Weekday(now)=dsserver("backupday") Then
'response.write "当前进入备份星期<br>"
'End If
'if dsserver("backupyes")="y" then
'response.write "当前进入备份服务器<br>"
'End if
if hour(now)=backuphour and Weekday(now)=dsserver("backupday") and dsserver("backupyes")="y" then
response.write "受控虚拟主机备份....<br>"
FreeHost_oplog "自动任务","信息","开始受控虚拟主机备份ID:"&dsserver("id")'&"受控网址:"&URL&vbcrlf
nottype=dsserver("nottype")
if isnull(dsserver("nottype")) then nottype="*.log"
Response.Write siteback(URL,FreeHostsharekey,"-"&dsserver("backupsave"),dsserver("backupdir"),nottype)&"成功发出备份指令服务器ID:"&dsserver("id")'&"受控网址:"&URL
end if
'控制受控端备份

'update log
'response.write GetXMLLOG (URL)
'5.更新流量表
if hour(now)=4 Or hour(now)=5 Or hour(now)=6 Or hour(now)=7 Then '早上4点更新
serverbyte=0
 txml=dateadd("y",-1,now)
 httpurl=Url&"/log/"&year(txml)&"-"&month(txml)&"-"&day(txml)&".xml"

Response.Write "开始更新以下服务器的流量表:"&dsserver("id")'&"受控网址:"&URL&vbcrlf

FreeHost_oplog "自动任务","信息","开始更新以下服务器的流量表:"&dsserver("id")'&"受控网址:"&URL&vbcrlf

Set http=Server.CreateObject("MSXML2.ServerXMLHTTP")
http.Open "GET",httpurl,False
http.send
Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.load(http.ResponseXML)
Set root = xmlDoc.documentElement
   For i = 0 To (root.childNodes.length - 1)
   if RegExpTest("[A-Za-z0-9]",root.childNodes.Item(i).childNodes.Item(0).Text) then

If RegExpTest("[^A-Za-z0-9]",root.childNodes.Item(i).childNodes.Item(0).Text) Then
response.write "err--非法FTP名:"&root.childNodes.Item(i).childNodes.Item(0).Text
Else



   	Set dsphtemp = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Host where  ServerlistID="&dsserver("id")&"  and ( ftpname='"&root.childNodes.Item(i).childNodes.Item(0).Text&"' or iisid='"&root.childNodes.Item(i).childNodes.Item(0).Text&"')"    

dsphtemp.Open Sql,conn,1,3
if not dsphtemp.Eof then
if DateDiff("h" , dsphtemp("lastlogtime"),Now)>12 or isnull(dsphtemp("lastlogtime")) then
'response.write "更新以下主机的流量记录："&dsphtemp("ftpname")&"<br>"
dsphtemp("lastlogtime")=now
if IsNumeric(root.childNodes.Item(i).childNodes.Item(1).Text) then
dsphtemp("BytesReceived")=root.childNodes.Item(i).childNodes.Item(1).Text
else
dsphtemp("BytesReceived")=0
end if
if IsNumeric(root.childNodes.Item(i).childNodes.Item(2).Text) then
dsphtemp("BytesSent")=root.childNodes.Item(i).childNodes.Item(2).Text
else
dsphtemp("BytesSent")=0
end if
if IsNumeric(root.childNodes.Item(i).childNodes.Item(3).Text) then
dsphtemp("TimeTaken")=root.childNodes.Item(i).childNodes.Item(3).Text
else
dsphtemp("TimeTaken")=0
end if
dsphtemp("thismonbytes")=CDbl(dsphtemp("BytesReceived"))+CDbl(dsphtemp("BytesSent"))+CDbl(dsphtemp("thismonbytes"))

serverbyte=serverbyte+CDbl(dsphtemp("BytesReceived"))+CDbl(dsphtemp("BytesSent"))

dsphtemp.update

End If

end if

end if


  '  conn.Execute "update FreeHost_Product_Host set  lastlogtime='"&now&"',BytesReceived="&root.childNodes.Item(i).childNodes.Item(1).Text&",BytesSent="&root.childNodes.Item(i).childNodes.Item(2).Text&",TimeTaken="&root.childNodes.Item(i).childNodes.Item(3).Text&" ,tempbytes= "&root.childNodes.Item(i).childNodes.Item(1).Text&"+"&root.childNodes.Item(i).childNodes.Item(2).Text&"+thismonbytes where ftpname='"&root.childNodes.Item(i).childNodes.Item(0).Text&"'"  
	'    conn.Execute "update FreeHost_Product_Host set thismonbytes= tempbytes  where ftpname='"&root.childNodes.Item(i).childNodes.Item(0).Text&"'"    
	'	response.write "A"&root.childNodes.Item(i).childNodes.Item(0).Text
	end if
   Next
response.write vbcrlf&"<br>服务器服ID:"&dsserver("id")&"总流量："&serverbyte'&" Xml文件网址:"&httpurl&vbcrlf
conn.Execute "update freehost.FreeHost_Serverlist set lastlogtime='"&now&"',Bytes='"&serverbyte&"' where id="&dsserver("id")&""
end if'是4点

dsserver.movenext
wend



'response.end

'7.提取日志给用户
if hour(now)=8 then
response.write "提取日志给用户....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Host where  hosttype<>'子目录绑定' and getmelog='y'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
username=dsph("Ftpname")
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
	ostype=dsserver("ostype")'linux
'response.write vbcrlf&"<br>提取ftp用户："&username&vbcrlf
Response.Write MakeLOG(URL,FreeHostsharekey,username,"-1")
end if
dsph("getmelog")="n"
dsph.update
dsph.movenext
wend
end if
'完成提取日志给用户

'8.汇总子目录网站的流量给主站
if hour(now)=8 then
response.write "汇总子目录网站的流量给主站....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Host where  hosttype<>'子目录绑定' and status<>'暂停'"
	dsph.Open Sql,conn,1,3
'response.write sql
while not dsph.Eof
dim thismonbytesALLsub,CPUALLsub
thismonbytesALLsub=0
CPUALLsub=0
'处理sub
'response.write " "&dsph("ftpname")&" "&dsph("thismonbytes")
Set dsphsub = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where allowsubbyid='"&dsph("id")&"' and allowsub='n' and ftpname='"&dsph("ftpname")&"'"
	dsphsub.Open Sql,conn,1,1
while not dsphsub.eof
thismonbytesALLsub=CDbl(thismonbytesALLsub)+CDbl(dsphsub("thismonbytes"))
CPUALLsub=CPUALLsub+CDbl(dsphsub("TimeTaken"))
dsphsub.movenext
wend
dsphsub.close
dsph("thismonbytesALL")=CDbl(dsph("thismonbytes"))+CDbl(thismonbytesALLsub)
If IsNull(dsph("thismonbytesALL")) Then dsph("thismonbytesALL")=CDbl(dsph("thismonbytes"))
'If dsph("thismonbytesALL")=0 Then dsph("thismonbytesALL")=CDbl(dsph("thismonbytes"))
dsph("cpuALL")=CDbl(dsph("TimeTaken"))+CPUALLsub
dsph.update
dsph.movenext
wend
dsph.close
end If


'9.开始执行自动暂停超流量的网站
if autopausebytesite then
response.write "虚拟主机/CDN超流量暂停....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Host where  hosttype<>'子目录绑定' and status<>'暂停' and ((Maxbytes>0 and Maxbytes<thismonbytesALL) or (CDNMaxMb<CDNMBthismonth and CDNMaxMb>0))"
if autopausecpusite then Sql="Select * from FreeHost.FreeHost_Product_Host where  hosttype<>'子目录绑定' and status<>'暂停' and ((Maxbytes>0 and Maxbytes<thismonbytesALL) or (MaxCPU>0 and MaxCPU<cpuALL) or (CDNMaxMb<CDNMBthismonth and CDNMaxMb>0))"
	dsph.Open Sql,conn,1,3
while not dsph.Eof


Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
username=dsph("Ftpname")
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
tourl=dsserver("pauseweb3")
	ostype=dsserver("ostype")'linux

if dsph ("agent1")<>"n" then
  Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&dsph ("agent1")&"'"
		dsagent.Open Sql,conn,1,1
If not dsagent.Eof Then
if len(dsagent("pauseweb3"))>3 then
tourl=dsagent("pauseweb3")
end if
end if
dsagent.close
end if

'处理sub
Set dsphsub = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where allowsubbyid='"&dsph("id")&"'"
	dsphsub.Open Sql,conn,1,3
while not dsphsub.eof
IISID=dsphsub("IISID")
op=1
Response.Write PauseSiteSub(URL,FreeHostsharekey,IISID,tourl,op)
dsphsub("status")="暂停"
dsphsub("pausereason")=3
dsphsub.update
dsphsub.movenext
wend
dsphsub.close


op=1
Response.Write PauseSite(URL,FreeHostsharekey,username,tourl,op)

if  autopausesiteftp then Response.Write FTPOP(URL,FreeHostsharekey,username,1)'停止ftp

dsph("status")="暂停"
dsph("pausereason")=3
dsph.update
end if

dsph.movenext
wend
dsph.close

'恢复自动暂停超流量的网站
if (hour(now)=6 Or hour(now)=7 Or hour(now)=8 Or hour(now)=9 Or hour(now)=10 Or hour(now)=11) and day(now)=1 then '早上4点更新

response.write "虚拟主机超CPU/超流量恢复....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Host where  hosttype<>'子目录绑定' and status<>'正常' and pausereason=3 and ((Maxbytes>thismonbytesALL and Maxbytes>0) or (CDNMaxMb>CDNMBthismonth and CDNMaxMb>0) or (MaxCPU>0 and MaxCPU>cpuALL))"
'Sql="Select * from FreeHost.FreeHost_Product_Host where  hosttype<>'子目录绑定' and status<>'正常' and MaxCPU>0 and MaxCPU>cpuALL and pausereason=3"
'if autopausecpusite then Sql="Select * from FreeHost.FreeHost_Product_Host where  hosttype<>'子目录绑定' and status<>'正常' and ((Maxbytes>0 and Maxbytes<thismonbytesALL) or (MaxCPU>0 and MaxCPU<cpuALL))"
	dsph.Open Sql,conn,1,3
while not dsph.Eof


Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
username=dsph("Ftpname")
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
tourl=dsserver("pauseweb")
	ostype=dsserver("ostype")'linux

'处理sub
Set dsphsub = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where allowsubbyid='"&dsph("id")&"'"
	dsphsub.Open Sql,conn,1,3
while not dsphsub.eof
IISID=dsphsub("IISID")
op=0
Response.Write PauseSiteSub(URL,FreeHostsharekey,IISID,tourl,op)
dsphsub("status")="正常"
dsphsub.update
dsphsub.movenext
wend
dsphsub.close

op=0
Response.Write PauseSite(URL,FreeHostsharekey,username,tourl,op)

if  autopausesiteftp then Response.Write FTPOP(URL,FreeHostsharekey,username,0)'停止ftp

dsph("status")="正常"
dsph.update
end if

dsph.movenext
wend
dsph.close

end if
'完成恢复自动暂停超流量的网站
end if
'完成执行自动暂停超流量的网站


'11.开始执行自动暂停超期的网站
if autopausesite then
response.write "虚拟主机过期暂停....<br>"
'Err.Clear
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Host where  hosttype<>'子目录绑定' and endtime<'"&now&"' and status<>'暂停' order by endtime desc"
'response.write sql
	dsph.Open Sql,conn,1,3
while not dsph.Eof


Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
username=dsph("Ftpname")
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
tourl=dsserver("pauseweb")
	ostype=dsserver("ostype")'linux

if dsph ("agent1")<>"n" then
  Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&dsph ("agent1")&"'"
		dsagent.Open Sql,conn,1,1
If not dsagent.Eof Then
if len(dsagent("pauseweb"))>3 then
tourl=dsagent("pauseweb")
end if
end if
dsagent.close
end if

'处理sub
Set dsphsub = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where allowsubbyid='"&dsph("id")&"'"
	dsphsub.Open Sql,conn,1,3
while not dsphsub.eof
IISID=dsphsub("IISID")
op=1
outcon=PauseSiteSub(URL,FreeHostsharekey,IISID,tourl,op)
'if err.number=0 then
if instr(outcon,"成功暂停")>1 then
dsphsub("status")="暂停"
dsphsub("pausereason")=1
Response.Write outcon&"子目录："&dsphsub("ftpname")
end if
dsphsub.update
dsphsub.movenext
wend
dsphsub.close


op=1
outcon=PauseSite(URL,FreeHostsharekey,username,tourl,op)

if  autopausesiteftp then Response.Write FTPOP(URL,FreeHostsharekey,username,1)'停止ftp

if instr(outcon,"成功暂停")>1 Or ostype="linux" then
dsph("status")="暂停"
dsph("pausereason")=1
Response.Write outcon&dsph("ftpname")
end if
dsph.update
end if

dsph.movenext
wend
dsph.close

end if












'12.域名到期邮件通知
response.write "域名到期邮件通知....<br>"
dim Subject,body
'域名到期通知.....
for inotice=0 to 2
Set dsph = Server.CreateObject("ADODB.Recordset")
if inotice=0 then Sql="Select * from FreeHost.FreeHost_Product_Domain where endtime<'"&dateadd("d",emaild1,now)&"' and emailstatus is null"
if inotice=1 then Sql="Select * from FreeHost.FreeHost_Product_Domain where endtime<'"&dateadd("d",emaild2,now)&"' and emailstatus='a'"
if inotice=2 then Sql="Select * from FreeHost.FreeHost_Product_Domain where endtime<'"&dateadd("d",emaild3,now)&"' and emailstatus='b'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
while not dsph.eof
if dsph("emailstatus")="b" then dsph("emailstatus")="c"
if dsph("emailstatus")="a" then dsph("emailstatus")="b"
if isnull(dsph("emailstatus")) then dsph("emailstatus")="a"
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
'	response.write sql&"<br>"
ds.Open Sql,conn,1,3
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　域名：<%=Left(dsph("Domain"),3)%>...　邮箱：<%=Left(ds("email"),3)%>...　到期时间：<%=dsph("endtime")%>
<%
emaildomainend
ret=Send2Mail(conn,ds("username"),Subject,body)
response.write ret&"<br>"

'通知用户
If IsNull(ds("usernotice")) Then ds("usernotice")=""
ds("usernotice")="域名类产品"&dsph("Domain")&"即将到期.<br>"&ds("usernotice")
ds("lastnotice")=now
ds.update

end if
ds.close

dsph.update
dsph.movenext
wend
dsph.close
next
'完成域名到期通知.....


'13.域名到期sms通知
If Application("smsdomaintimeout")=True then
response.write "域名到期短信通知....<br>"
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Domain where endtime<'"&dateadd("d",Application("smstimeout"),now)&"' and status<>'预注册成功' and smsstatus is null"
	dsph.Open sql,conn,1,3
while not dsph.eof
'If dsph("agent1")="n" Or Application("agncangetsms")=True Then
'if isnull(dsph("smsstatus")) then 
dsph("smsstatus")="a"
dsph.update
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,1
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　域名：<%=Left(dsph("Domain"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%
Dim username
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smsdomaintimeoutcon")
smsContent=Replace(smsContent,"#用户名#",dsph("username"))
smsContent=Replace(smsContent,"#域名#",dsph("Domain"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))

if lastMobi=mobi and lastSmsContent=smsContect then
 response.write "号码和内容与上次相同，跳过发送"
else
 response.write SendSms(mobi,smsContent,1,Now,"")
 lastMobi=mobi
 lastSmsContent=smsContect
end if

end if
ds.close
'End if
dsph.movenext
wend
dsph.close
End if
'完成域名到期短信通知.....

'14.主机到期sms通知
If Application("smshosttimeout")=True then
response.write "虚拟主机到期短信通知....<br>"
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Host where hosttype<>'子目录绑定' and (endtime<'"&dateadd("d",Application("smstimeout"),now)&"' and istest<>'y' and smsstatus is null)"
	dsph.Open sql,conn,1,3
while not dsph.eof
'If dsph("agent1")="n" Or Application("agncangetsms")=True Then
'if isnull(dsph("smsstatus")) then dsph("smsstatus")="a"
dsph("smsstatus")="a"
dsph.update
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,1
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　FTP名：<%=Left(dsph("ftpname"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smshosttimeoutcon")
smsContent=Replace(smsContent,"#用户名#",dsph("username"))
smsContent=Replace(smsContent,"#FTP#",dsph("ftpname"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
if lastMobi=mobi and lastSmsContent=smsContect then
 response.write "号码和内容与上次相同，跳过发送"
else
 response.write SendSms(mobi,smsContent,1,Now,"")
 lastMobi=mobi
 lastSmsContent=smsContect
end if
end if
ds.close
'dsph.update
'End if
dsph.movenext
wend
dsph.close
End if
'完成主机到期短信通知.....

'14.邮箱到期sms通知
If Application("smsemailtimeout")=True then
response.write "邮箱到期短信通知....<br>"
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Email where endtime<'"&dateadd("d",Application("smstimeout"),now)&"' and smsstatus is null and istest<>'y' and byhost is null"
	dsph.Open sql,conn,1,3
while not dsph.eof
'If dsph("agent1")="n" Or Application("agncangetsms")=True Then
'if isnull(dsph("smsstatus")) then dsph("smsstatus")="a"
dsph("smsstatus")="a"
dsph.update
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,1
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　邮箱类型：<%=Left(dsph("emailtype"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smsemailtimeoutcon")
smsContent=Replace(smsContent,"#用户名#",dsph("username"))
smsContent=Replace(smsContent,"#产品类型#",dsph("Emailtype"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
if lastMobi=mobi and lastSmsContent=smsContect then
 response.write "号码和内容与上次相同，跳过发送"
else
 response.write SendSms(mobi,smsContent,1,Now,"")
 lastMobi=mobi
 lastSmsContent=smsContect
end if
end if
ds.close
'dsph.update
'End if
dsph.movenext
wend
dsph.close
End if
'完成主机到期sms通知.....

'14.数据库到期sms通知
If Application("smssqltimeout")=True then
response.write "数据库到期短信通知....<br>"
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_SQL where endtime<'"&dateadd("d",Application("smstimeout"),now)&"' and smsstatus is null and istest<>'y' and byhost is null"
	dsph.Open sql,conn,1,3
while not dsph.eof
'If dsph("agent1")="n" Or Application("agncangetsms")=True Then
'if isnull(dsph("smsstatus")) then dsph("smsstatus")="a"
dsph("smsstatus")="a"
dsph.update
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,1
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　数据库名：<%=Left(dsph("sqlname"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smssqltimeoutcon")
smsContent=Replace(smsContent,"#用户名#",dsph("username"))
smsContent=Replace(smsContent,"#数据库名#",dsph("sqlname"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
if lastMobi=mobi and lastSmsContent=smsContect then
 response.write "号码和内容与上次相同，跳过发送"
else
 response.write SendSms(mobi,smsContent,1,Now,"")
 lastMobi=mobi
 lastSmsContent=smsContect
end if
end if
ds.close
'dsph.update
'End if
dsph.movenext
wend
dsph.close
End if
'完成主机到期sms通知.....


'15.其他类到期sms通知
If Application("smsothertimeout")=True then
response.write "其他类到期短信通知....<br>"
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Other where endtime<'"&dateadd("d",Application("smstimeout"),now)&"' and istest<>'y' and smsstatus is null"
	dsph.Open sql,conn,1,3
while not dsph.eof
'If dsph("agent1")="n" Or Application("agncangetsms")=True Then
'if isnull(dsph("smsstatus")) then dsph("smsstatus")="a"
dsph("smsstatus")="a"
dsph.update
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,1
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　类型：<%=Left(dsph("othertype"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smsothertimeoutcon")
smsContent=Replace(smsContent,"#用户名#",dsph("username"))
smsContent=Replace(smsContent,"#产品类型#",dsph("othertype"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
if lastMobi=mobi and lastSmsContent=smsContect then
 response.write "号码和内容与上次相同，跳过发送"
else
 response.write SendSms(mobi,smsContent,1,Now,"")
 lastMobi=mobi
 lastSmsContent=smsContect
end if
end if
ds.close
'dsph.update
'End if
dsph.movenext
wend
dsph.close
End if
'完成主机到期sms通知.....


'15.IDC类到期sms通知
If Application("smsidctimeout")=True then
response.write "IDC类到期短信通知....<br>"
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_IDC where endtime<'"&dateadd("d",Application("smstimeout"),now)&"' and smsstatus is null and istest<>'y'"
If smstimeoutIDC<>Application("smstimeout") And smstimeoutIDC<>"" then Sql="Select * from FreeHost.FreeHost_Product_IDC where endtime<'"&dateadd("d",smstimeoutIDC,now)&"' and smsstatus is null and istest<>'y'"
	dsph.Open sql,conn,1,3
while not dsph.eof
'If dsph("agent1")="n" Or Application("agncangetsms")=True Then
'if isnull(dsph("smsstatus")) then dsph("smsstatus")="a"
dsph("smsstatus")="a"
dsph.update
Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_IDCIP where PDID="&dsph("id")
		dsX.Open Sql,conn,1,1
If Not dsX.Eof Then
idcip=dsX("IP")
End If
dsX.close

Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,1
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　类型：<%=Left(dsph("IDCtype"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smsidctimeoutcon")
smsContent=Replace(smsContent,"#用户名#",dsph("username"))
smsContent=Replace(smsContent,"#产品类型#",dsph("IDCtype")&"(IP:"&idcip&")")
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
if lastMobi=mobi and lastSmsContent=smsContect then
 response.write "号码和内容与上次相同，跳过发送"
else
 response.write SendSms(mobi,smsContent,1,Now,"")
 lastMobi=mobi
 lastSmsContent=smsContect
end if
end if
ds.close
'dsph.update
'End if
dsph.movenext
wend
dsph.close
End if
'完成主机到期sms通知.....

'VPS类到期通知.....
response.write "VPS到期邮件通知....<br>"
for inotice=0 to 2
Set dsph = Server.CreateObject("ADODB.Recordset")
if inotice=0 then Sql="Select * from FreeHost.FreeHost_Product_VPS where endtime<'"&dateadd("d",emaild1,now)&"' and emailstatus is null  and istest='n'"
if inotice=1 then Sql="Select * from FreeHost.FreeHost_Product_VPS where endtime<'"&dateadd("d",emaild2,now)&"' and emailstatus='a'  and istest='n'"
if inotice=2 then Sql="Select * from FreeHost.FreeHost_Product_VPS where endtime<'"&dateadd("d",emaild3,now)&"' and emailstatus='b'  and istest='n'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
while not dsph.eof
if dsph("emailstatus")="b" then dsph("emailstatus")="c"
if dsph("emailstatus")="a" then dsph("emailstatus")="b"
if isnull(dsph("emailstatus")) then dsph("emailstatus")="a"

if dsph("isagentpd")=true then
if not isnull(dsph("AgnUpIP")) Then vpsip=Left(dsph("AgnUpIP"),21)
else

	Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where VPSID="&dsph("id")
		dsX.Open Sql,conn,1,1
If not dsX.eof then
vpsip=dsX("IP")
portstart=dsX("portstart")
End If
dsX.close

	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where id='"&dsph("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
If not dsserver.Eof Then
If dsserver("isONEip")=True Then
Set dsPORTserver = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_ServerPORTlist where id='"&dsserver("useportserver")&"'"
		dsPORTserver.Open Sql,conn,1,3
If Not dsPORTserver.Eof Then
If Not isnull(dsPORTserver("cname")) Then
vpsip=dsPORTserver("cname")&":"&portstart
Else
vpsip=vpsip&":"&portstart
End if
End if
End if
End if

End If


Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,3
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　类型：<%=Left(dsph("VPStype"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%

'通知用户
If IsNull(ds("usernotice")) Then ds("usernotice")=""
ds("usernotice")="云服务器类产品 "&dsph("VPStype")&" 即将到期.<br>"&ds("usernotice")
ds("lastnotice")=now
ds.update

emailVPSend
ret=Send2Mail(conn,ds("username"),Subject,body)
response.write ret&"<br>"

end if
ds.close

dsph.update
dsph.movenext
wend
dsph.close
next
'VPS类到期通知.....

'IDC类到期通知.....
response.write "IDC到期邮件通知....<br>"
for inotice=0 to 2
Set dsph = Server.CreateObject("ADODB.Recordset")
if inotice=0 then Sql="Select * from FreeHost.FreeHost_Product_IDC where endtime<'"&dateadd("d",emaild1,now)&"' and emailstatus is null  and istest='n'"
if inotice=1 then Sql="Select * from FreeHost.FreeHost_Product_IDC where endtime<'"&dateadd("d",emaild2,now)&"' and emailstatus='a'  and istest='n'"
if inotice=2 then Sql="Select * from FreeHost.FreeHost_Product_IDC where endtime<'"&dateadd("d",emaild3,now)&"' and emailstatus='b'  and istest='n'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
while not dsph.eof
if dsph("emailstatus")="b" then dsph("emailstatus")="c"
if dsph("emailstatus")="a" then dsph("emailstatus")="b"
if isnull(dsph("emailstatus")) then dsph("emailstatus")="a"

Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_IDCIP where PDID="&dsph("id")
		dsX.Open Sql,conn,1,1
If Not dsX.Eof Then
idcip=dsX("IP")
End If
dsX.close


Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,3
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　类型：<%=Left(dsph("IDCtype"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%

'通知用户
If IsNull(ds("usernotice")) Then ds("usernotice")=""
ds("usernotice")="IDC类产品 "&dsph("IDCtype")&" 即将到期.<br>"&ds("usernotice")
ds("lastnotice")=now
ds.update

emailIDCend
ret=Send2Mail(conn,ds("username"),Subject,body)
response.write ret&"<br>"

end if
ds.close

dsph.update
dsph.movenext
wend
dsph.close
next
'IDC类到期通知.....

'15.VPS类到期sms通知
If Application("smsVPStimeout")=True then
response.write "VPS类到期短信通知....<br>"
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_VPS where endtime<'"&dateadd("d",Application("smstimeout"),now)&"' and smsstatus is null and istest<>'y'"
If smstimeoutIDC<>Application("smstimeout") And smstimeoutIDC<>"" then Sql="Select * from FreeHost.FreeHost_Product_VPS where endtime<'"&dateadd("d",smstimeoutIDC,now)&"' and smsstatus is null and istest<>'y'"
	dsph.Open sql,conn,1,3
while not dsph.eof
'If dsph("agent1")="n" Or Application("agncangetsms")=True Then
'if isnull(dsph("smsstatus")) then dsph("smsstatus")="a"
dsph("smsstatus")="a"
dsph.update

if dsph("isagentpd")=true then
if not isnull(dsph("AgnUpIP")) Then vpsip=Left(dsph("AgnUpIP"),21)
else

	Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where VPSID="&dsph("id")
		dsX.Open Sql,conn,1,1
If not dsX.eof then
vpsip=dsX("IP")
portstart=dsX("portstart")
End If
dsX.close

	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where id='"&dsph("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
If not dsserver.Eof Then
If dsserver("isONEip")=True Then
Set dsPORTserver = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_ServerPORTlist where id='"&dsserver("useportserver")&"'"
		dsPORTserver.Open Sql,conn,1,3
If Not dsPORTserver.Eof Then
If Not isnull(dsPORTserver("cname")) Then
vpsip=dsPORTserver("cname")&":"&portstart
Else
vpsip=vpsip&":"&portstart
End if
End if
End if
End if

End If

Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,1
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　类型：<%=Left(dsph("VPStype"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smsVPStimeoutcon")
smsContent=Replace(smsContent,"#用户名#",dsph("username"))
smsContent=Replace(smsContent,"#产品类型#",dsph("VPStype")&"(云服务器名:"&dsph("vpsname")&")"&"(IP:"&vpsip&")")
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
if lastMobi=mobi and lastSmsContent=smsContect then
 response.write "号码和内容与上次相同，跳过发送"
else
 response.write SendSms(mobi,smsContent,1,Now,"")
 lastMobi=mobi
 lastSmsContent=smsContect
end if
end if
ds.close
'dsph.update
'End if
dsph.movenext
wend
dsph.close
End if
'完成VPS到期sms通知.....



'预注册域名到期删除.....
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Domain where status='预注册成功' and starttime<'"&dateadd("d",-7,now)&"'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
'	response.end
while not dsph.eof
response.write "超过七天预注册域名:"&Left(dsph("domain"),3)&"...已删除 "
FreeHost_oplog dsph("username"),"信息","自动任务操作删除过期预注册域名:"&dsph ("domain")
dsph.delete
dsph.update
dsph.movenext
wend
dsph.close
'完成预注册域名到期删除.....

'域名过期删除.....
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Domain where status='正常' and endtime<'"&dateadd("d",-autodelDomaintime,now)&"'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
'	response.end
while not dsph.eof
conn.Execute "Select * from FreeHost.FreeHost_Product_URLRE where PdDID='"&dsph("id")&"'"

if dsph("DNS_API")=1 then
 	Set dsALLDNS = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_ALLDNS where PdDID='"&dsph("id")&"'"
	dsALLDNS.Open Sql,conn,1,1
count=dsALLDNS.recordcount
'del zone
if count>0 then
Set dnsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerDNSlist"
	dnsserver.Open Sql,conn,1,1
while not dnsserver.eof
outcon=outcon&DNSOP(dnsserver("site"),"/zonedelete "&ComX.idntoac_7i24_com(Cstr(dsdom("domain"))),dnsserver("FreeHostsharekey"))
dnsserver.movenext
wend
dnsserver.close
end if
dsALLDNS.close
End if

conn.Execute "delete from FreeHost.FreeHost_Product_ALLDNS where PdDID='"&dsph("id")&"'"


response.write "超过35天过期域名:"&Left(dsph("domain"),3)&"...已删除 "
FreeHost_oplog dsph("username"),"信息","自动任务操作删除过期域名:"&dsph ("domain")&" 原到期时间:"&dsph ("endtime")
dsph.delete
dsph.update
dsph.movenext
wend
dsph.close
'完成域名过期删除.....


'虚拟主机到期通知.....
response.write "虚拟主机到期通知....<br>"
for inotice=0 to 2
Set dsph = Server.CreateObject("ADODB.Recordset")
if inotice=0 then Sql="Select * from FreeHost.FreeHost_Product_Host where hosttype<>'子目录绑定' and endtime<'"&dateadd("d",emaild1,now)&"' and emailstatus is null and istest='n'"
if inotice=1 then Sql="Select * from FreeHost.FreeHost_Product_Host where hosttype<>'子目录绑定' and endtime<'"&dateadd("d",emaild2,now)&"' and emailstatus='a' and istest='n'"
if inotice=2 then Sql="Select * from FreeHost.FreeHost_Product_Host where hosttype<>'子目录绑定' and endtime<'"&dateadd("d",emaild3,now)&"' and emailstatus='b' and istest='n'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
while not dsph.eof
if dsph("emailstatus")="b" then dsph("emailstatus")="c"
if dsph("emailstatus")="a" then dsph("emailstatus")="b"
if isnull(dsph("emailstatus")) then dsph("emailstatus")="a"
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,3
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　FTP名：<%=Left(dsph("ftpname"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%

emailhostend
ret=Send2Mail(conn,ds("username"),Subject,body)
response.write ret&"<br>"

'通知用户
If IsNull(ds("usernotice")) Then ds("usernotice")=""
ds("usernotice")="虚拟主机类产品"&dsph("ftpname")&"即将到期.<br>"&ds("usernotice")
ds("lastnotice")=now
ds.update

end if
ds.close

dsph.update
dsph.movenext
wend
dsph.close
next
'完成虚拟主机到期通知.....



response.write "邮箱到期通知....<br>"
'邮箱到期通知.....
for inotice=0 to 2
Set dsph = Server.CreateObject("ADODB.Recordset")
if inotice=0 then Sql="Select * from FreeHost.FreeHost_Product_Email where endtime<'"&dateadd("d",emaild1,now)&"' and emailstatus is null  and istest='n'"
if inotice=1 then Sql="Select * from FreeHost.FreeHost_Product_Email where endtime<'"&dateadd("d",emaild2,now)&"' and emailstatus='a'  and istest='n'"
if inotice=2 then Sql="Select * from FreeHost.FreeHost_Product_Email where endtime<'"&dateadd("d",emaild3,now)&"' and emailstatus='b'  and istest='n'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
while not dsph.eof
if dsph("emailstatus")="b" then dsph("emailstatus")="c"
if dsph("emailstatus")="a" then dsph("emailstatus")="b"
if isnull(dsph("emailstatus")) then dsph("emailstatus")="a"
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,3
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　邮箱类型：<%=Left(dsph("emailtype"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%

emailend
ret=Send2Mail(conn,ds("username"),Subject,body)
response.write ret&"<br>"

'通知用户
If IsNull(ds("usernotice")) Then ds("usernotice")=""
ds("usernotice")="邮箱类产品 "&dsph("emailtype")&" 即将到期.<br>"&ds("usernotice")
ds("lastnotice")=now
ds.update

end if
ds.close

dsph.update
dsph.movenext
wend
dsph.close
next
'完成邮箱期通知.....

response.write "SQL到期通知....<br>"
'SQL到期通知.....
for inotice=0 to 2
Set dsph = Server.CreateObject("ADODB.Recordset")
if inotice=0 then Sql="Select * from FreeHost.FreeHost_Product_Sql where endtime<'"&dateadd("d",emaild1,now)&"' and emailstatus is null  and istest='n'"
if inotice=1 then Sql="Select * from FreeHost.FreeHost_Product_Sql where endtime<'"&dateadd("d",emaild2,now)&"' and emailstatus='a'  and istest='n'"
if inotice=2 then Sql="Select * from FreeHost.FreeHost_Product_Sql where endtime<'"&dateadd("d",emaild3,now)&"' and emailstatus='b' and istest='n'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
while not dsph.eof
if dsph("emailstatus")="b" then dsph("emailstatus")="c"
if dsph("emailstatus")="a" then dsph("emailstatus")="b"
if isnull(dsph("emailstatus")) then dsph("emailstatus")="a"
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,3
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　数据库名：<%=Left(dsph("sqlname"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%

'通知用户
If IsNull(ds("usernotice")) Then ds("usernotice")=""
ds("usernotice")="数据类产品,数据库名"&dsph("sqlname")&"即将到期.<br>"&ds("usernotice")
ds("lastnotice")=now
ds.update

emailsqlend
ret=Send2Mail(conn,ds("username"),Subject,body)
response.write ret&"<br>"

end if
ds.close

dsph.update
dsph.movenext
wend
dsph.close
next
'完成SQL到期通知.....


'其他类到期通知.....
response.write "其他类到期通知....<br>"
for inotice=0 to 2
Set dsph = Server.CreateObject("ADODB.Recordset")
if inotice=0 then Sql="Select * from FreeHost.FreeHost_Product_Other where endtime<'"&dateadd("d",emaild1,now)&"' and emailstatus is null  and istest='n'"
if inotice=1 then Sql="Select * from FreeHost.FreeHost_Product_Other where endtime<'"&dateadd("d",emaild2,now)&"' and emailstatus='a'  and istest='n'"
if inotice=2 then Sql="Select * from FreeHost.FreeHost_Product_Other where endtime<'"&dateadd("d",emaild3,now)&"' and emailstatus='b'  and istest='n'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
while not dsph.eof
if dsph("emailstatus")="b" then dsph("emailstatus")="c"
if dsph("emailstatus")="a" then dsph("emailstatus")="b"
if isnull(dsph("emailstatus")) then dsph("emailstatus")="a"
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,3
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　类型：<%=Left(dsph("othertype"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　到期时间：<%=dsph("endtime")%>
<%

'通知用户
If IsNull(ds("usernotice")) Then ds("usernotice")=""
ds("usernotice")="其他类产品 "&dsph("othertype")&" 即将到期.<br>"&ds("usernotice")
ds("lastnotice")=now
ds.update

emailotherend
ret=Send2Mail(conn,ds("username"),Subject,body)
response.write ret&"<br>"

end if
ds.close

dsph.update
dsph.movenext
wend
dsph.close
next
'完成其他类到期通知.....


'-------------------------
'备份FTP删除.....
response.write "删除备份数据库用的FTP....<br>"
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Sql where ftpendtime<'"&now&"'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
while not dsph.eof

	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerSQLlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
userid=dsserver ("admname")
pwd=dsserver("admpass")
homedir=dsserver("homedir")
sqlname=dsph("sqlname")
username=dsph("ftpname")
ftpdir=dsserver("homedir")&"\backup\"&sqlname&"_"&dsph("randir")
varcon=" /E /T /R "&username
todeluser=1
delacl=1
todelftp=1
ret=DelFTP(URL,FreeHostsharekey,username,ftpdir,varcon,todeluser,delacl,todelftp)

end if



%>
删除备份数据库用的FTP：<%=Left(dsph("username"),3)%>... 库名：<%=Left(dsph("sqlname"),3)%>...返回信息：<%=ret%>


<%
dsph("ftpname")=null
dsph("ftppassword")=null
dsph("ftpendtime")=null
dsph.update
dsph.movenext
wend
dsph.close
'备份FTP删除.....


'自动备份主控的库
if hour(now)=4 then
Set dsreg = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_System_Info where id=0"
		dsreg.Open Sql,conn,1,3
If dsreg("autobackup")="y" Then
response.write "自动备份主控的库....<br>"
FreeHost_oplog dsph("username"),"信息","自动任务开始备份主控数据库"
if isnull(dsreg("lastbackuptime")) then dsreg("lastbackuptime")=dateadd("d",-1,now)
if DateDiff("h",dsreg("lastbackuptime"), now)>20 then
dsreg("lastbackuptime")=now
dsreg.update
Randomize
Rkey=Cstr(Int((99999999 - 100000 + 1) * Rnd + 100000))
backuptime=year(now)&month(now)&day(now)&hour(now)&Minute(now)&Second(now)&"_"&md5(now&Rkey)
sql="BACKUP DATABASE FREEHOST TO DISK = '"&dsreg("autobackupdir")&"\freehost_"&backuptime&".bak'"
conn.Execute Sql
end if
dsreg.close
FreeHost_oplog dsph("username"),"信息","自动任务备份主控数据库操作完成."
end if
End if

'11.-2 开始执行自动删除超期的网站
todeldate=30
if not isnull(Application("todelday")) then todeldate=Application("todelday")
if Application("autodelhost") then
response.write "虚拟主机过期删除....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Host where  hosttype<>'子目录绑定' and endtime<'"&dateadd("d",-todeldate,now)&"' order by endtime desc"
'response.write sql
	dsph.Open Sql,conn,1,3
while not dsph.Eof

Sql="update FreeHost.FreeHost_Product_Host_IP set HOSTID=0 where hostid='"&dsph("id")&"'"
conn.Execute Sql
'response.write Sql

Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
username=dsph("Ftpname")
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
tourl=dsserver("pauseweb")
ostype=dsserver("ostype")'linux

'处理sub
Set dsphsub = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where allowsubbyid='"&dsph("id")&"'"
	dsphsub.Open Sql,conn,1,3
while not dsphsub.eof
IISID=dsphsub("IISID")
op=1
Response.Write DelUserSub(URL,FreeHostsharekey,IISID)
Response.Write outcon&"自动删除子目录："&dsphsub("ftpname")
dsphsub.delete
dsphsub.update
dsphsub.movenext
wend
dsphsub.close

Response.Write DelUser(URL,FreeHostsharekey,username)
Response.Write outcon&"自动删除主站："&dsph("ftpname")
'删除ICPDB
conn.Execute "delete from FreeHost.FreeHost_ICPDB where ftpname='"&dsph("ftpname")&"'"
dsph.delete

dsph.update
end if

dsph.movenext
wend
dsph.close

end if
'final



'11.-2 开始执行自动删除超期---试用的网站
if Application("autodeltesthostnow") then
response.write "试用虚拟主机过期删除....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Host where  hosttype<>'子目录绑定' and  endtime<'"&dateadd("d",-autodeltestdelay,now)&"' and istest='y' order by endtime desc"
'response.write sql
	dsph.Open Sql,conn,1,3
while not dsph.Eof

Sql="update FreeHost.FreeHost_Product_Host_IP set HOSTID=0 where hostid='"&dsph("id")&"'"
conn.Execute Sql

Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
username=dsph("Ftpname")
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
tourl=dsserver("pauseweb")
ostype=dsserver("ostype")'linux

'处理sub
Set dsphsub = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where allowsubbyid='"&dsph("id")&"'"
	dsphsub.Open Sql,conn,1,3
while not dsphsub.eof
IISID=dsphsub("IISID")
op=1
Response.Write DelUserSub(URL,FreeHostsharekey,IISID)
Response.Write outcon&"自动删除试用子目录："&dsphsub("ftpname")
dsphsub.delete
dsphsub.update
dsphsub.movenext
wend
dsphsub.close

Response.Write DelUser(URL,FreeHostsharekey,username)
Response.Write outcon&"自动删除试用主站："&dsph("ftpname")
'删除ICPDB
conn.Execute "delete from FreeHost.FreeHost_ICPDB where ftpname='"&dsph("ftpname")&"'"
dsph.delete

dsph.update
end if

dsph.movenext
wend
dsph.close

end if
'final



if Application("autodelicp")=false then'不启用icp检查,同步linux域名
Response.Write "进入同步linux域名工作...<br>"
if hour(now)=10 Then
set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where ostype='linux'"
	dsserver.Open Sql,conn,1,1
while not dsserver.Eof
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
InCmd="CMD_API_DOMAIN_OWNERS"
returnstr=URLDecode(DAAPIGET(URL,"sefreehost",FreeHostsharekey,InCmd))
domary=Split(returnstr,"&")
'For i=0 To UBound(domary)
'response.write domary(i)&"<br>"
'next
'response.write "DA返回:"&returnstr

	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where ServerlistID='"&dsserver("id")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
response.write "同步linux域名:ftpname："&dsph("ftpname")&"<br>"
'得到用户绑的域名列表:
'
hostname=""
For i=0 To UBound(domary)

If Right(domary(i),Len(dsph("ftpname"))+1)="="&dsph("ftpname") Then
domain=Left(domary(i),Len(domary(i))-Len(dsph("ftpname"))-1)
hostname=hostname&":80:"&replace(replace(domain, " ",""),":80:","")&","
'response.write domain&"<br>得到主域名:"
'domain=GetDomainMain(domain)
'response.write domain&"<br>"
End If

Next

if right(hostname,1)="," then hostname=left(hostname,len(hostname)-1)
response.write "最后域名:"&hostname&"<br>"
If hostname<>"" Then dsph("hostname")=hostname'更新DA接口中主机的域名
dsph.update

InCmd="CMD_API_SHOW_USER_USAGE?user="&dsph("ftpname")
returnstr=DAAPIGET(URL,"admin",FreeHostsharekey,InCmd)
response.write "<br>检查linux DA中的ftpname："&dsph("ftpname")&"流量:"'&returnstr
bodyary=Split(returnstr,"&")
For i=0 To UBound(bodyary)
If left(bodyary(i),10)="bandwidth=" Then
response.write Replace(bodyary(i),"bandwidth=","")&"<br>"
dsph("thismonbytes")=CDbl(CLng(Replace(bodyary(i),"bandwidth=",""))*1048576)
dsph.update
End if
next

dsph.movenext
Wend
dsserver.movenext
wend
dsserver.close
End if

End If'同步linux域名


if Application("autodelicp")=true then'如果启用后台检查
Response.Write "进入清理linux未备案域名工作...<br>"
'检查linux接口
if hour(now)=10 Then
set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where ostype='linux' and autodelicp=1"
	dsserver.Open Sql,conn,1,1
while not dsserver.Eof
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
InCmd="CMD_API_DOMAIN_OWNERS"
returnstr=URLDecode(DAAPIGET(URL,"sefreehost",FreeHostsharekey,InCmd))
domary=Split(returnstr,"&")
'For i=0 To UBound(domary)
'response.write domary(i)&"<br>"
'next
'response.write "DA返回:"&returnstr

	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where ServerlistID='"&dsserver("id")&"'"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
response.write "检查linux DA中的域名是否备案:ftpname："&dsph("ftpname")&"<br>"
'得到用户绑的域名列表:
'先删除不存在的域名
If UBound(domary)>2 then
hostname=""
	Set dsICPDB = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ICPDB where ftpname='"&dsph("ftpname")&"'"
	dsICPDB.Open Sql,conn,1,3
While Not dsICPDB.Eof
havedomain=false'没有这个域名
For i=0 To UBound(domary)
If Right(domary(i),Len(dsph("ftpname"))+1)="="&dsph("ftpname") Then
domain=Left(domary(i),Len(domary(i))-Len(dsph("ftpname"))-1)
hostname=hostname&":80:"&replace(replace(domain, " ",""),":80:","")&","
'response.write domain&"<br>得到主域名:"
domain=GetDomainMain(domain)
'response.write domain&"<br>"
If domain=dsICPDB("domain") Then havedomain=true'没有这个域名
End if
Next

If havedomain=False Then
response.write "检查linux DA中的域名:ftpname："&Left(dsph("ftpname"),3)&"...的域名"&Left(domain,3)&"...不存在已同步删除<br>"
dsICPDB.delete
dsICPDB.update
End if
dsICPDB.movenext
wend
End if


'再添加新域名
hostname=""
For i=0 To UBound(domary)

If Right(domary(i),Len(dsph("ftpname"))+1)="="&dsph("ftpname") Then

domain=Left(domary(i),Len(domary(i))-Len(dsph("ftpname"))-1)
hostname=hostname&":80:"&replace(replace(domain, " ",""),":80:","")&","
'response.write domain&"<br>得到主域名:"
domain=GetDomainMain(domain)
'response.write domain&"<br>"

	Set dsICPDB = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ICPDB where domain='"&domain&"'"
	dsICPDB.Open Sql,conn,1,3
if dsICPDB.Eof Then
dsICPDB.addnew
dsICPDB("username")=ds("username")
dsICPDB("ftpname")=dsph("ftpname")
dsICPDB("domain")=domain
dsICPDB("status")="尚未检测"
dsICPDB("firstaddtime")=Now
dsICPDB("agent1")=ds("agent1")
dsICPDB("agent2")=ds("agent2")
response.write "加入检查列表中:"&Left(domain,3)&"...<br>"
'dsph("alldomainok")=0
dsICPDB.update
end If
dsICPDB.close

End If

Next

if right(hostname,1)="," then hostname=left(hostname,len(hostname)-1)
dsph("hostname")=hostname'更新DA接口中主机的域名
dsph.update

InCmd="CMD_API_SHOW_USER_USAGE?user="&dsph("ftpname")
returnstr=DAAPIGET(URL,"admin",FreeHostsharekey,InCmd)
'response.write "<br>检查linux DA中的ftpname："&dsph("ftpname")&"流量:"'&returnstr
bodyary=Split(returnstr,"&")
For i=0 To UBound(bodyary)
If left(bodyary(i),10)="bandwidth=" Then
response.write Replace(bodyary(i),"bandwidth=","")&"<br>"
dsph("thismonbytes")=CDbl(CLng(Replace(bodyary(i),"bandwidth=",""))*1048576)
dsph.update
End if
next

dsph.movenext
Wend
dsserver.movenext
wend
dsserver.close
End if
End if





'开始执行清理过期未备案的网站
'1.七天内没有提交备安全信息的
'2.30天内没有备案成功的
if Application("autodelicp")=true Or Request("donow")="yes" Then'如果启用后台检查

Response.Write "进入清理未备案域名工作...<br>"
'if hour(now)=2 Or hour(now)=3 Or hour(now)=4 Or hour(now)=5 Or hour(now)=6 then

if hour(now)=2 then
Sql="delete FreeHost.FreeHost_ICPDB where firstaddtime<'"&dateadd("d",-(autodelbeiandomain+canadddomainagain),now)&"' and status<>'备案成功'"
    conn.Execute Sql
End if

'response.write "<br>开始检查所有没有备案成功的域名...<br>"
Set dsICPDB = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_ICPDB where ((status='未提交备案' or status='备案被拒绝') and firstaddtime<'"&dateadd("d",-autodelbeiandomain7,now)&"') or ((status='未提交备案' or status='已提交备案，尚未备案成功') and firstaddtime<'"&dateadd("d",-autodelbeiandomain,now)&"')"
If Application("beianupsaok")=True Then Sql="Select * from FreeHost.FreeHost_ICPDB where ((status='未提交备案' or status='备案被拒绝') and firstaddtime<'"&dateadd("d",-autodelbeiandomain7,now)&"') "
	dsICPDB.Open sql,conn,1,3
while not dsICPDB.eof
'response.write "<br>清理域名"&dsICPDB ("domain")&"...<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Host where  hostname+',' like '%"&dsICPDB ("domain")&",%'"
'Sql="Select * from FreeHost.FreeHost_Product_Host where  beianstatus<>'备案成功' and hostname+',' like '%"&dsICPDB ("domain")&",%'"'2008-4-23改成备案状态是成功的网站不处理.
	dsph.Open Sql,conn,1,3
while not dsph.Eof

'response.write "FTP名:"dsph("ftpname")&"本地库域名:"&dsICPDB ("domain")&"本地库域名ID:"&dsICPDB ("id")&"<br>"

hostname=Trim(LCase(dsph("hostname")))
hostname=replace(hostname, ":80:","")
hostname_arry=Split(hostname, ",")
hostnameNew=""
for idname=0 to ubound(hostname_arry)
curdomain=hostname_arry(idname)
If GetDomainMain(curdomain)<>GetDomainMain(dsICPDB ("domain")) Then'为了兼容部分没处理成功的用户改的
hostnameNew=hostnameNew&":80:"&replace(replace(hostname_arry(idname), " ",""),":80:","")&","
End if
next
if right(hostnameNew,1)="," then hostnameNew=left(hostnameNew,len(hostnameNew)-1)
if left(hostnameNew,1)="," then hostnameNew=right(hostnameNew,len(hostnameNew)-1)



	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&dsph ("ServerlistID")&"' and autodelicp=1"
	dsserver.Open Sql,conn,1,1
if Not dsserver.Eof Then
ostype=dsserver("ostype")
'hostname=dsph("hostname")
'hostname=hostnameNew
'hostname=replace(replace(hostname, ":80:"&dsICPDB ("domain"),""),",,",",")
'if right(hostname,1)="," then hostname=left(hostname,len(hostname)-1)
'if left(hostname,1)="," then hostname=right(hostname,len(hostname)-1)
host=hostnameNew
'Response.Write hostname
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
username=dsph("ftpname")


radid=Cstr(Int((99999999 - 100000 + 1) * Rnd + 100000))
If host="" Then

 
hostnameX=ComX.idntoac_7i24_com(cstr("绑定的域名中没有一个备案成功被全部清理."&dsph("ftpname")&radid&".com"))
host=":80:"&hostnameX
hostnameNew=host
End if

response.write "原域名"&Left(hostname,3)&"...新域名"&Left(hostnameNew,3)&"..."

'Response.Write hostname
'Response.end
Dim homedirnew
homedirnew=""
spacelimit=""
hostcomment=""
MaxConnections=""

If ostype="linux" Then
op=1
temp=PauseSite(URL,FreeHostsharekey,username,tourl,op)
dsph("status")="暂停"
else
If dsph("hosttype")<>"子目录绑定" then
temp=ModifyUser2(URL,FreeHostsharekey,username,comment,homedirnew,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth)
else
IISID=dsph("IISID")
temp=ModifyUserSub(URL,FreeHostsharekey,username,password,IISID,comment,homedirnew,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth)
End If
End If

If InStr(temp,"设置主机头")>1 then

'清理域名
Response.Write "自动清理ftp名:"&Left(dsph("ftpname"),3)&"...主域名："&Left(dsICPDB("domain"),3)&"..."&temp&"<br>"

dsph("hostname")=hostnameNew
dsph.update
'通知用户
Set dsreg = Server.CreateObject("ADODB.Recordset")	
		Sql="Select usernotice from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
		dsreg.Open Sql,conn,1,3
If Not dsreg.Eof Then
If IsNull(dsreg("usernotice")) Then dsreg("usernotice")=""
If ostype="linux" Then
dsreg("usernotice")="由于域名"&dsICPDB("domain")&"超过指定时间没有备案,您在linux接口中的用户名已被冻结(ftp名:"&dsph("ftpname")&").<br>"&dsreg("usernotice")
else
dsreg("usernotice")="由于域名"&dsICPDB("domain")&"超过指定时间没有备案,已经被自动清理(ftp名:"&dsph("ftpname")&").<br>"&dsreg("usernotice")
End if
dsreg("lastnotice")=now
dsreg.update
end If
dsreg.close

If logicpdelsite=True Then FreeHost_oplog dsph("username"),"信息","自动任务清理没备案的网站("&ostype&"):原域名"&hostname&"新域名"&hostnameNew&" FTP用户名"&dsph("ftpname")&"返回:"&temp
Else
FreeHost_oplog dsph("username"),"信息","自动任务清理没备案的网站!!!失败!!!("&ostype&"):原域名"&hostname&"新域名"&hostnameNew&" FTP用户名"&dsph("ftpname")&"返回:"&temp
End if


End if'如果有这个服务器定义
dsserver.close

'下一条主机记录
dsph.movenext
wend
dsph.close
'dsICPDB.update
dsICPDB.movenext
wend
dsICPDB.close

'End if'限制时间
End if'完成后台务案检查










'必须在最后
'2008-2-22 开始执行自动删除超期的数据库
if Application("autodelhost")=true and Application("autodelsql")=true then
response.write "数据库过期删除....<br>"
todeldate=Application("todelday")
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_SQL where  endtime<'"&dateadd("d",-todeldate,now)&"' "
if Application("autodeltesthostnow") Then Sql="Select * from FreeHost.FreeHost_Product_SQL where  (endtime<'"&dateadd("d",-todeldate,now)&"') or (endtime<'"&dateadd("d",-autodeltestdelay,now)&"' and istest='y') "
'response.write sql
	dsph.Open Sql,conn,1,3
while not dsph.Eof

	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerSqllist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if Not dsserver.Eof then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
userid=dsserver ("admname")
pwd=dsserver("admpass")
sqlname=dsph("sqlname")
sqlpassword=dsph("sqlpassword")


dim softtype,MySQLver,MSSQLver
softtype=dsserver("softtype")
MySQLver=dsserver("MySQLver")
MSSQLver=dsserver("MSSQLver")

op=2
ret=PauseSQL(URL,FreeHostsharekey,userid,pwd,sqlname,sqlpassword,op)

ret=ret&"删除成功"
homedir=dsserver("homedir")
username=dsph("ftpname")
ftpdir=homedir&"\backup\"&sqlname&"_"&dsph("randir")
varcon=" /E /T /R "&username
todeluser=1
delacl=1
todelftp=1
if not isnull(dsph("ftpendtime")) then
ret = ret&"删除这个库的备份FTP："&DelFTP(URL,FreeHostsharekey,username,ftpdir,varcon,todeluser,delacl,todelftp)
end if
if not isnull(dsph("randir")) then
ret = ret&"删除这个库的备份目录："&DelDir(URL,FreeHostsharekey,ftpdir)
end if

opport=dsserver("port")
for iipsec=1 to 2
if not isnull(dsph("ip"&iipsec)) then
	Set dsphip = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Sql where (ip1='"&dsph("ip"&iipsec)&"' or ip2='"&dsph("ip"&iipsec)&"') and id<>'"&dsph ("id")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsphip.Open Sql,conn,1,3
if dsphip.Eof then
response.write "删除允许的IP："&dsph("ip"&iipsec)&"<br>"
opvar="del"
ret=ret&OPIpsec(URL,FreeHostsharekey,opvar,dsph("ip"&iipsec),opport)
end if
dsphip.close
end if
next

FreeHost_oplog dsph("username"),"信息","自动任务操作删除数据库id"&dsph ("id")&ret

dsph.delete

End if'有这个服务器定义
dsph.movenext
wend
dsph.close

	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Email where  endtime<'"&dateadd("d",-todeldate,now)&"' "
if Application("autodeltesthostnow") Then Sql="Select * from FreeHost.FreeHost_Product_Email where  (endtime<'"&dateadd("d",-todeldate,now)&"') or (endtime<'"&dateadd("d",-autodeltestdelay,now)&"' and istest='y') "
	dsph.Open Sql,conn,1,3
'response.write sql&"<br>"
while not dsph.Eof

Set dspdallemail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_ALLEmail where PdEID='"&dsph ("id")&"' order by emailname"
		dspdallemail.Open Sql,conn,1,3
'response.write sql&"<br>"

if not dspdallemail.Eof then
email=trim(dspdallemail("emailname"))
emailarry=split(email,"@")
name1=emailarry(0)
olddomain=lcase(trim(emailarry(1)))
ret=DelAdmEmail(dsph ("ServerlistID"),olddomain)
end if

'response.write sql
'response.end

while not dspdallemail.eof
Response.Write ret
dspdallemail.delete
dspdallemail.movenext
wend
dspdallemail.close

FreeHost_oplog dsph("username"),"信息","自动任务操作删除邮箱id"&dsph ("id")&ret

dsph.delete

dsph.movenext
wend
dsph.close

end if
'完成删除过期数据库



'自动暂停过期的数据库
if hour(now)=10 Or hour(now)=14 Then

response.write "数据库过期暂停....<br>"

	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_Sql where (endtime<'"&now&"' and status<>'暂停' and byhost is null) or ( ((endtime<'"&dateadd("d",-todeldate,now)&"') or (endtime<'"&dateadd("d",-autodeltestdelay,now)&"' and istest='y') ) and status<>'暂停' and byhost is not null) "
'response.write sql
	dsph.Open Sql,conn,1,3
while not dsph.Eof

	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerSqllist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if Not dsserver.Eof then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
userid=dsserver ("admname")
pwd=dsserver("admpass")
sqlname=dsph("sqlname")
sqlpassword=dsph("sqlpassword")
softtype=dsserver("softtype")
op=1
ret=PauseSQL(URL,FreeHostsharekey,userid,pwd,sqlname,sqlpassword,op)
Response.Write "暂停过期SQL:"&Left(sqlname,3)&"...返回:"&ret&"<br>"
FreeHost_oplog dsph("username"),"信息","自动任务操作暂停过期数据库:"&dsph ("sqlname")&ret
dsph("status")="暂停"
dsph.update
end if

dsph.movenext
wend
dsph.close

End if'自动暂停过期的数据库





'VPS
response.write "VPS过期停止....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_VPS where  endtime<'"&dateadd("d",0,now)&"' and status<>'停止'"
If Application("VPStestHour")>0 Then Sql="Select * from FreeHost.FreeHost_Product_VPS where  endtime<'"&now&"' and status<>'停止'"
'response.write sql
	dsph.Open Sql,conn,1,3
while not dsph.Eof
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if Not dsserver.Eof then
username=dsph("username")
vpsname=dsph("vpsname")
FreeHostsharekey=dsserver("FreeHostsharekey")
URL=dsserver("site")
action="turnoff"
varcon="action "&vpsname&" "&action&" now"
temp=VPSOP(URL,FreeHostsharekey,varcon,0)'0=now
FreeHost_oplog dsph("username"),"信息","自动任务操作关机VPS返回:"&Left(dsph ("vpsname"),3)&"..."&ret
dsph("status")="停止"
dsph("pausebyagn")="a"
dsph.update
End if
dsph.movenext
wend
dsph.close
'完成VPS


'CDN类到期通知.....
response.write "CDN到期邮件通知....<br>"
for inotice=0 to 2
Set dsph = Server.CreateObject("ADODB.Recordset")
if inotice=0 then Sql="Select * from FreeHost.FreeHost_Product_cdn where endtime<'"&dateadd("d",emaild1,now)&"' and emailstatus is null  and istest='n'"
if inotice=1 then Sql="Select * from FreeHost.FreeHost_Product_cdn where endtime<'"&dateadd("d",emaild2,now)&"' and emailstatus='a'  and istest='n'"
if inotice=2 then Sql="Select * from FreeHost.FreeHost_Product_cdn where endtime<'"&dateadd("d",emaild3,now)&"' and emailstatus='b'  and istest='n'"
	dsph.Open sql,conn,1,3
'	response.write sql&"<br>"
while not dsph.eof
if dsph("emailstatus")="b" then dsph("emailstatus")="c"
if dsph("emailstatus")="a" then dsph("emailstatus")="b"
if isnull(dsph("emailstatus")) then dsph("emailstatus")="a"
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,3
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　类型：<%=Left(dsph("cdntype"),3)%>...　邮箱：<%=Left(ds("email"),3)%>...　到期时间：<%=dsph("endtime")%>
<%

'通知用户
If IsNull(ds("usernotice")) Then ds("usernotice")=""
ds("usernotice")="其他类产品 "&dsph("cdntype")&" 即将到期.<br>"&ds("usernotice")
ds("lastnotice")=now
ds.update

emailcdnend
ret=Send2Mail(conn,ds("username"),Subject,body)
response.write ret&"<br>"

end if
ds.close

dsph.update
dsph.movenext
wend
dsph.close
next
'CDN类到期通知.....

'15.CDN到期sms通知
If Application("smscdntimeout")=True then
response.write "CDN类到期短信通知....<br>"
Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_cdn where endtime<'"&dateadd("d",Application("smstimeout"),now)&"' and istest<>'y' and smsstatus is null"
	dsph.Open sql,conn,1,3
while not dsph.eof
'If dsph("agent1")="n" Or Application("agncangetsms")=True Then
'if isnull(dsph("smsstatus")) then dsph("smsstatus")="a"
dsph("smsstatus")="a"
dsph.update
Set ds = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_USER where username='"&dsph("username")&"'"
ds.Open Sql,conn,1,1
if not ds.eof then%>
用户名：<%=Left(ds("username"),3)%>...　类型：<%=Left(dsph("cdntype"),3)%>...　手机：<%=Left(ds("mobi"),3)%>...　邮箱：<%=Left(ds("email"),3)%>...　到期时间：<%=dsph("endtime")%>
<%
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smscdntimeoutcon")
smsContent=Replace(smsContent,"#用户名#",dsph("username"))
smsContent=Replace(smsContent,"#产品类型#",dsph("cdntype"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
if lastMobi=mobi and lastSmsContent=smsContect then
 response.write "号码和内容与上次相同，跳过发送"
else
 response.write SendSms(mobi,smsContent,1,Now,"")
 lastMobi=mobi
 lastSmsContent=smsContect
end if
end if
ds.close
'dsph.update
'End if
dsph.movenext
wend
dsph.close
End if
'完成CDN到期sms通知.....


'CDN
Bindserverid1=0
Bindserverid2=0
response.write "CDN过期暂停....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_CDN where  endtime<'"&dateadd("d",0,now)&"' and status<>'暂停'"
'response.write sql
	dsph.Open Sql,conn,1,3
while not dsph.Eof
FreeHost_oplog dsph("username"),"信息","自动任务操作暂停过期CDN:"&dsph ("ftpname")
dsph("status")="暂停"
dsph("pausebyagn")="a"
dsph.update
Bindserverid1=dsph ("Bindserverid1")
Bindserverid2=dsph ("Bindserverid2")
dsph.movenext
wend
dsph.close
'完成CDN


'CDN
response.write "CDN过期删除....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_CDN where  endtime<'"&dateadd("d",-todeldate,now)&"'"
'response.write todeldate&sql
	dsph.Open Sql,conn,1,3
while not dsph.Eof
FreeHost_oplog dsph("username"),"信息","自动任务操作删除CDN:"&dsph ("ftpname")
Bindserverid1=dsph ("Bindserverid1")
Bindserverid2=dsph ("Bindserverid2")
dsph.delete
dsph.update
dsph.movenext
wend
dsph.close
'完成CDN

'9.开始执行自动暂停超流量的网站

response.write "独立CDN超流量暂停....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_CDN where  status<>'暂停' and (CDNMaxMb<CDNMBthismonth and CDNMaxMb>0)"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
dsph("status")="暂停"
dsph("pausereason")=3
FreeHost_oplog dsph("username"),"信息","自动任务操作暂停超流量CDN:"&dsph ("ftpname")
Bindserverid1=dsph ("Bindserverid1")
Bindserverid2=dsph ("Bindserverid2")
dsph.update
dsph.movenext
wend
dsph.close
If Bindserverid1>0 Then conn.Execute "update FreeHost.FreeHost_ServerCDNlist set lastchangetime='"&now&"'  where (Bindserverid1='"&Bindserverid1&"' or Bindserverid1='"&Bindserverid2&"' or Bindserverid2='"&Bindserverid1&"' or Bindserverid2='"&Bindserverid2&"')"
set dsph=Nothing

'response.write WEEKDAY(now)
if hour(now)=1 Or hour(now)=2 Or hour(now)=3 Or hour(now)=4 Or hour(now)=5 Or hour(now)=6 Or hour(now)=7 Then
response.write "自动备份VHDX....<br>"
set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist"
if hour(now)=1 Or hour(now)=2 Or hour(now)=3 Or hour(now)=4 Or hour(now)=5 Or hour(now)=6 Then
sql="Select top 25 * from FreeHost.FreeHost_ServerVPSlist where lastBAKtime<'"&date&"' or lastBAKtime is null"
End If
if hour(now)=7 Then
sql="Select * from FreeHost.FreeHost_ServerVPSlist where lastBAKtime<'"&date&"'"
End if
	dsserver.Open Sql,conn,1,3
	response.write sql
while not dsserver.Eof

if Weekday(now)=dsserver("backupday") and dsserver("backupyes")="y" then
response.write WEEKDAY(now)
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")

aryvarcon=""
   	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_VPS where  ServerlistID="&dsserver("id")&" and MaxBak>0 and (lastbackuptime<'"&date&"' or lastbackuptime is null)"    
dsph.Open Sql,conn,1,3
'	response.write sql
while not dsph.Eof
vpsname=LCase(dsph("vpsname"))
'nowvhddir=dsph("vhdpath")
'tobackdir=dsserver("backupdir")
'	  If Right(dsphVPS("vhdpath"),5)=".vhdx" then
'		tobackdir=replace(tobackdir&"\"&vpsname&"-"&year(date)&right("00"&month(date),2)&right("00"&day(date),2)&".vhdx","\\","\")
'	  Else
'		tobackdir=replace(tobackdir&"\"&vpsname&"-"&year(date)&right("00"&month(date),2)&right("00"&day(date),2)&".vhd","\\","\")
'	  End If
dsph("lastbackuptime")=now
dsph.update
MaxBak=1
If isnull(dsph("MaxBak")) Then MaxBak=1
aryvarcon=aryvarcon&"$"&vpsname&"@"&dsph("MaxBak")
'aryvarcon=aryvarcon&"|"&vpsname&" "&nowvhddir&" "&tobackdir&" "&dsph("MaxBak")	  
'varcon="backvhdauto "&vpsname&" "&nowvhddir&" "&tobackdir&" "&dsph("MaxBak")
dsph.movenext
Wend
dsph.close

'7i24iislog4R2.exe backvhdp d:\备份保存目录 $VPS名@保留次数$vpsname2@3
varcon="backvhdp "&dsserver("backupdir")&" "&aryvarcon
'Response.Write varcon
temp=VPSOP(URL,FreeHostsharekey,varcon,1)'0=now
Response.Write temp
dsserver("lastBAKtime")=now
dsserver.update
End if
dsserver.movenext
Wend
End if



'Response.write Application("autodelvps")

'11.-2 开始执行自动删除超期的云服务器
todeldate=30
if not isnull(Application("todeldayvps")) then todeldate=Application("todeldayvps")
if Application("autodelvps") then
response.write "云服务器过期删除....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_VPS where endtime<'"&dateadd("d",-todeldate,now)&"' order by endtime desc"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
vhdpath=dsph("vhdpath")
Sql="update FreeHost.FreeHost_Product_VPS_IP set VPSID=0 where VPSID='"&dsph("id")&"'"
conn.Execute Sql
Sql="update FreeHost.FreeHost_Product_VPS_ADSL set VPSID=0 where VPSID='"&dsph("id")&"'"
conn.Execute Sql
username=dsph("username")
vpsname=dsph("vpsname")
Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")

action="turnoff"
varcon="action "&vpsname&" "&action&" now"
temp=VPSOP(URL,FreeHostsharekey,varcon,0)'0=now
FreeHost_oplog username,"信息","自动任务操管理员关机VPS:"&vpsname
Response.Write temp

If Not isnull(dsph("consoletime")) then
Response.Write OPIpsec(URL,FreeHostsharekey,"del",dsph("consoleip"),"2179")
varcon="DelconnectVM "&username&" "&vpsname&" "&dsph("VPSpassword")&" "&dsph("consoleip")
Response.Write VPSOP(URL,FreeHostsharekey,varcon,0)'0=now
End If

varcon="delvps "&vpsname&" "&vhdpath&" "&dsserver("backupdir")
If dsserver("IsCluster")=true Then varcon=varcon&" "&dsserver("ClusterName")&" "&vpsname
Response.Write varcon
temp=VPSOP(URL,FreeHostsharekey,varcon,0)'0=now
Response.Write temp
FreeHost_oplog username,"信息","自动任务操作管理员删除VPS:"&vpsname


dsph.delete
dsph.Update
Response.Write "云服务器信息已从数据库中删除。"
End If
if dsph("isagentpd")=true Then
dsph.delete
dsph.Update
Response.Write "云服务器(代理上级)信息已从数据库中删除。"
End if
dsph.movenext
Wend
End if


'开始执行自动删除超期---试用的云服务器
if Application("autodeltestvpsnow") then
response.write "试用云服务器过期删除....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_VPS where  endtime<'"&dateadd("d",-autodeltestdelay,now)&"' and istest='y' order by endtime desc"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
vhdpath=dsph("vhdpath")
Sql="update FreeHost.FreeHost_Product_VPS_IP set VPSID=0 where VPSID='"&dsph("id")&"'"
conn.Execute Sql
Sql="update FreeHost.FreeHost_Product_VPS_ADSL set VPSID=0 where VPSID='"&dsph("id")&"'"
conn.Execute Sql
username=dsph("username")
vpsname=dsph("vpsname")
Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")

action="turnoff"
varcon="action "&vpsname&" "&action&" now"
temp=VPSOP(URL,FreeHostsharekey,varcon,0)'0=now
FreeHost_oplog username,"信息","自动任务操管理员关机VPS:"&vpsname
Response.Write temp

If Not isnull(dsph("consoletime")) then
Response.Write OPIpsec(URL,FreeHostsharekey,"del",dsph("consoleip"),"2179")
varcon="DelconnectVM "&username&" "&vpsname&" "&dsph("VPSpassword")&" "&dsph("consoleip")
Response.Write VPSOP(URL,FreeHostsharekey,varcon,0)'0=now
End If

varcon="delvps "&vpsname&" "&vhdpath&" "&dsserver("backupdir")
If dsserver("IsCluster")=true Then varcon=varcon&" "&dsserver("ClusterName")&" "&vpsname
Response.Write varcon
temp=VPSOP(URL,FreeHostsharekey,varcon,0)'0=now
Response.Write temp
FreeHost_oplog username,"信息","自动任务操作管理员删除VPS:"&vpsname



dsph.delete
dsph.Update
Response.Write "云服务器信息已从数据库中删除。"
End If
if dsph("isagentpd")=true Then
dsph.delete
dsph.Update
Response.Write "云服务器(代理上级)信息已从数据库中删除。"
End if
dsph.movenext
Wend
end If


response.write "云服务器连接过期删除....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_VPS where  consoletime<'"&dateadd("h",-3,now)&"'"
'Response.Write sql
	dsph.Open Sql,conn,1,3
while not dsph.Eof
vhdpath=dsph("vhdpath")
username=dsph("username")
vpsname=dsph("vpsname")
consoleip=dsph("consoleip")
Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")

opport="2179"
opvar="del"
ret1=OPIpsec(URL,FreeHostsharekey,opvar,dsph("consoleip"),opport)

FreeHost_oplog username,"信息","自动任务操删除云服务器连接IP:"&ret1
Response.Write ret1

varcon="DelconnectVM "&username&" "&vpsname&" "&dsph("VPSpassword")&" "&dsph("consoleip")
temp1=VPSOP(URL,FreeHostsharekey,varcon,0)'0=now
If InStr(temp1,"用户不存在") Then temp1="原用户不存在不需要删除。"
Response.Write temp1
FreeHost_oplog username,"信息","自动任务操删除云服务器连接用户:"&temp1

dsph("consoletime")=null
dsph("consoleip")=null
dsph.Update
Response.Write "云服务器连接信息已从数据库中删除:"&vpsname&"。<br>"
Else 
Response.Write "云服务器定义不存在，信息已自动删除。<br>"
dsph("consoletime")=null
dsph("consoleip")=null
dsph.Update
End if
dsph.movenext
Wend
'final

response.write "云服务器光盘过期删除....<br>"
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_VPS where  CDTooltime<'"&dateadd("h",-6,now)&"'"
'Response.Write sql
	dsph.Open Sql,conn,1,3
while not dsph.Eof
username=dsph("username")
vpsname=dsph("vpsname")
Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if not dsserver.Eof then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
varcon="installcdout "&username&" "&vpsname
temp1=VPSOP(URL,FreeHostsharekey,varcon,0)'0=now
Response.Write temp1
FreeHost_oplog username,"信息","自动任务操删除光盘:"&temp1
dsph("CDTooltime")=null
dsph("CDTooldirID")=0
dsph.Update
Response.Write "云服务器光盘已从数据库中删除。"
End if
dsph.movenext
Wend





conn.close
set conn=nothing
%>完成
