<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
Function strtobin(str, charset)
  With Server.CreateObject("ADODB.Stream")
      .Type = 2
      .Mode = 3
      .Open
      .Charset = charset
      .WriteText str
      .Flush
      .Position = 0
      .Type = 1
       strtobin = .Read()
      .Close
  End With
End Function
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.QueryString ("agent1")="" And Request.QueryString ("username")="" and Request.QueryString ("endtime2")=""  and Request.QueryString ("status")=""  and Request.QueryString ("starttime2")=""  and Request.QueryString ("hostname")="" and Request.QueryString ("IDCname")=""  and Request.QueryString ("ServerlistID")=""  and Request.QueryString ("ip")="" and Request.QueryString ("IDCtype")="" or Instr(Request.QueryString ("hostname"), "'")>0  or Instr(Request.QueryString ("ftpname"), "'")>0    or Instr(Request.QueryString ("IDCtype"), "'")>0    or Instr(Request.QueryString ("sqlname"), "'")>0  Then
	ef=True
	ec="必须输入一项内容或有非法字符！"
ElseIf Request.QueryString("ip")<>"" and not IsNumeric(Replace(Request.QueryString("ip"),".",""))  Then
	ef=True
	ec="IP不对！"
elseIf session("canadmuser")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if

if not ef Then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
If Request.QueryString("ip")<>""  Then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_IDCIP where ip='"&Request.QueryString ("ip")&"'"
	dsph.Open Sql,conn,1,1
if dsph.Eof Then
	ef=True
	ec="IP不存在！"
Else
IDCid=dsph("PDID")
dsph.close
End If
End if
End If

if not ef then
 
hostname=trim(replace(Request("hostname"),"http://",""))
if hostname<>"" then hostname=ComX.idntoac_7i24_com(cstr(hostname))
hostnamecheck=replace(hostname,".","")
hostnamecheck=replace(hostnamecheck,"xn--","")
If RegExpTest("[^A-Za-z0-9--]",hostnamecheck) Then
	ef=True
	ec="请输入合法的域名！"
end if
end if

if not ef then
	Set dsph = Server.CreateObject("ADODB.Recordset")
SQL="Select * from FreeHost.FreeHost_Product_IDC where "
if Request.QueryString ("username")<>"" then Sql=Sql+"username= '"&trim(Request.QueryString ("username"))&"' and "
if Request.QueryString ("agent1")<>"" then Sql=Sql+"agent1= '"&trim(Request.QueryString ("agent1"))&"' and "
if hostname<>"" then Sql=Sql+"hostname like '%"&replace(hostname,"http://","")&"%' and "
if Request.QueryString ("IDCname")<>"" then Sql=Sql+"IDCname like '%"&trim(Request.QueryString ("IDCname"))&"%' and "
if Request.QueryString ("ServerlistID")<>"" then Sql=Sql+"ServerlistID = '"&trim(Request.QueryString ("ServerlistID"))&"' and "
if Request.QueryString ("IDCtype")<>"" then Sql=Sql+"IDCtype = '"&trim(Request.QueryString ("IDCtype"))&"' and "

if Request.QueryString ("status")<>"" then
if Request.QueryString ("status")="过期暂停" then
Sql=Sql+"istest = 'n' and endtime < '"&now&"' and status = '暂停' and "
elseif Request.QueryString ("status")="过期未暂停" then
Sql=Sql+"istest = 'n' and endtime < '"&now&"' and status = '正常' and "
elseif Request.QueryString ("status")="试用过期未暂停" then
Sql=Sql+"endtime < '"&now&"' and istest = 'y' and status = '正常' and "
elseif Request.QueryString ("status")="试用过期已暂停" then
Sql=Sql+"endtime < '"&now&"' and istest = 'y' and status = '暂停' and "
elseif Request.QueryString ("status")="试用过期" then
Sql=Sql+"endtime < '"&now&"' and istest = 'y' and "
elseif Request.QueryString ("status")="试用" then
Sql=Sql+"endtime > '"&now&"' and istest = 'y' and "
elseif Request.QueryString ("status")="停止" then
Sql=Sql+"status = '停止' and "
else
Sql=Sql+"istest = 'n' and status = '"&trim(Request.QueryString ("status"))&"' and "
end if
end if


if Request.QueryString ("starttime2") <>"" then  Sql=Sql+" starttime>'"&Request.QUERYSTRING ("starttime1")&"' and starttime<'"&Request.QUERYSTRING ("starttime2")&"' and "
if Request.QueryString ("endtime2") <>"" then  Sql=Sql+" endtime>'"&Request.QUERYSTRING ("endtime1")&"' and endtime<'"&Request.QUERYSTRING ("endtime2")&"' and "
if right(sql,5)=" and " then sql=left(sql,len(sql)-5)&" order by id desc"

if Request.QueryString ("orderbybytes")="d" then Sql=replace(Sql," id desc"," (BytesSent+BytesReceived) desc")
if Request.QueryString ("orderbybytes")="m" then Sql=replace(Sql," id desc"," thismonbytes desc")
if Request.QueryString ("orderbybytes")="cpu" then Sql=replace(Sql," id desc"," TimeTaken desc")

if Request.QueryString ("orderbybytes")="CDNMBthismonth" then Sql=replace(Sql," id desc"," CDNMBthismonth desc")
txml=dateadd("y",-1,now)
if Request.QueryString ("orderbybytes")="CDNMB-d" then Sql=replace(Sql," id desc"," CDNMB"&day(txml)&" desc")
hournow=hour(now)
if Request.QueryString ("orderbybytes")="CDNMB-today" then Sql=replace(Sql," id desc"," TodayMB desc")
'if Request.QueryString ("orderbybytes")="CDNMB-today" then Sql=replace(Sql," id desc"," LastDayMb desc")
if Request.QueryString ("orderbybytes")="CDNMB-today-hour" then Sql=replace(Sql," id desc"," HourMB"&hournow&" desc")

if Request.QueryString ("orderbybytes")="CDNMB-today-IN" then Sql=replace(Sql," id desc"," TodayMBin desc")
'if Request.QueryString ("orderbybytes")="CDNMB-today" then Sql=replace(Sql," id desc"," LastDayMbin desc")
if Request.QueryString ("orderbybytes")="CDNMB-today-hour-IN" then Sql=replace(Sql," id desc"," HourMBin"&hournow&" desc")

if Request.QueryString ("orderbybytes")="CDNMB-cpulasty" then Sql=replace(Sql," id desc"," LastdayCpu desc")
if Request.QueryString ("orderbybytes")="CDNMB-cputoday" then Sql=replace(Sql," id desc"," TodayCpu desc")
if Request.QueryString ("orderbybytes")="CDNMB-cputodayhour" then Sql=replace(Sql," id desc"," HourCPU"&hournow&" desc")

if Request.QueryString ("orderbybytes")="CDNMB-iopslasty" then Sql=replace(Sql," id desc"," Lastdayiops desc")
if Request.QueryString ("orderbybytes")="CDNMB-iopstoday" then Sql=replace(Sql," id desc"," Todayiops desc")
if Request.QueryString ("orderbybytes")="CDNMB-iopstodayhour" then Sql=replace(Sql," id desc"," Houriops"&hournow&" desc")


if Request.QueryString ("ip") <>"" then Sql="Select * from FreeHost.FreeHost_Product_IDC where id='"&IDCid&"'"

if Request.QueryString ("top20")="y" then sql=Replace(sql," * "," top 20 * ")

'Response.Write sql
if Instr(1,sql, ";", 1)>0 or Instr(1,replace(sql,"xn--",""), "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
        dsph.Open Sql,conn,1,1
if dsph.Eof then
	ef=True
	ec="数据库中没有此类内容。"
else
allcount=dsph.recordcount	
end if
end if

if not ef then
txml=dateadd("y",-1,now)
hournow=hour(now)
cputotal=2800

If request.QueryString("csv")="yes" Then
con="#id,用户名,中文名,联系人,电话,手机,QQ,产品类型,机柜,IP,状态,购买时间,到期时间"&vbcrlf
while not dsph.Eof
IDCtype=dsph("IDCtype")
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
truename=ds("truename")
tel=ds("tel")
mobi=ds("mobi")
qq=ds("qq")
contact=ds("contact")
End If

	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_IDCJG where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
jgname=dsserver("jgname")
    dsserver.close
IP=""
Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_IDCIP where PDID="&dsph("id")
		dsX.Open Sql,conn,1,1
If dsX.Eof then
IP="IP尚未分配"
else
while not dsX.eof
IP=dsX("IP")&"|"&IP
dsX.movenext
Wend
End If
If Right(IP,1)="|" Then IP=Left(IP,Len(IP)-1)


con=con&dsph("id")&","&dsph("username")&","&ds("truename")&","&ds("tel")&","&ds("mobi")&","&ds("qq")&","&ds("contact")&","&dsph("IDCtype")&","&jgname&","&IP&","&dsph("status")&","&formatdatetime(dsph("starttime"),1)&","&formatdatetime(dsph("endtime"),1)&vbcrlf
dsph.movenext
Wend

conbyte=strtobin(con, "GBK")
Filesize=Lenb(conbyte)
'Response.write con
Response.AddHeader "Content-Disposition", "attachment; filename=host.csv"  '添加头信息，为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader "Content-Length", Filesize            'file.Length.ToString()    '添加头信息，指定文件大小，让浏览器能够显示下载进度
Response.ContentType = "application/csv"                '指定返回的是一个不能被客户端读取的流，必须被下载
Response.BinaryWrite conbyte
Response.Flush 
Response.end
End If

%>
<form action="sxaction.asp" method="post" name="formBT" target="_top" id="formBT">
<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center" bgcolor="#333333">
  <tr bgcolor="#C1BFBF" align="center">
    <td>产品类型</td>
    <td height="21">用户名</td>
    <td>机柜</td>
    <td>IP 地址</td>
    <td>开通日期</td>
    <td>到期日期</td>
    <td>状态</td>
    <td>操作</td>
    </tr>
<%while not dsph.Eof%>
<%

	IDCtype=dsph("IDCtype")
'	Set ori_host_name = Server.CreateObject("ADODB.Recordset")	
	'	Sql="Select * from FreeHost.FreeHost_HostProductlist where IDCtype='"&dsph("IDCtype")&"'"
		'ori_host_name.Open Sql,conn,1,1
'		if not ori_host_name.eof then
'Set newname_host = Server.CreateObject("ADODB.Recordset")	
'Sql="Select * from FreeHost.FreeHost_HostProductlist_AGN where agent1='"&dsph("agent1")&"' and id='"&ori_host_name("id")&"'"
	'	newname_host.Open Sql,conn,1,1
'if not newname_host.eof then
'IDCtype=newname_host("IDCtype")
'end if
'		end if


	%>
  <tr align="center" bgcolor="#FFFFFF" onmouseover=this.bgColor='#E4EAF2'; onmouseout=this.bgColor='#FFFFFF';>
    <td><%=IDCtype%></td>
    <td height="30"><a href="searchuser.asp?username=<%=dsph("username")%>"><%=dsph("username")%></a><br>
<%if dsph("agent1")<>"n" then%>
(<a href="searchagent.asp?username=<%=dsph("agent1")%>" target="_blank"><font color="#FF0000"><%=dsph("agent1")%></font></a>)
<%end if%>
<%if not isnull(dsph("kefu")) then%><br><a href="admkefu.asp?kefu=<%=dsph("kefu")%>">(<font color="#0000FF"><%=dsph("kefu")%>)</font></a>
      <%end if%>

<%If request("showuserinfo")="y" Then

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
%>
<br>
真名：<%=ds("truename")%>
电话：<%=ds("tel")%> 手机：<%=ds("mobi")%> 传真：<%=ds("fax")%> QQ:<%=ds("qq")%> 邮箱：<a href=mailto:<%=ds("email")%>><font color="#000000"><%=ds("email")%></font></a>
 地址：<%=ds("prv")%>/<%=ds("city")%>/<%=ds("address")%> 联系人：<%=ds("contact")%> 邮编：<%=ds("postid")%>
<%
End If
ds.close
End If
%>
	
	</td>
    <td><%
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_IDCJG where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
%>
      <%=dsserver("jgname")%>
      <%dsserver.close%></td>
    <td>
      
      <%
	Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_IDCIP where PDID="&dsph("id")
		dsX.Open Sql,conn,1,1
If dsX.Eof Then%>
IP尚未分配
<%else
while not dsX.eof
%>
<%=dsX("IP")%> <br>
<%
dsX.movenext
wend
end if%></td>
    <td><%=formatdatetime(dsph("starttime"),1)%><br>        </td>
    <td>    <%=formatdatetime(dsph("endtime"),1)%></td>
    <td><%if dsph("endtime")>NOW then%>
      <%if dsph("istest")="y" then%>
      <font color="#FF0000">试用</font><%else%>
      <%=dsph("status")%>
      <%end if%>
      <%else%>
      <font color="#FF0000">过期</font>
      <%if dsph("status")="暂停" then%>
      <br>
      <font color="#FF0000">暂停</font>
      <%end if%>
      <%end if%></td>
    <td><a href="handIDC1.asp?username=<%=dsph("username")%>&id=<%=dsph("id")%>"><font color="#000000">管理</font></a><a href="handhost1.asp?username=<%=dsph("username")%>&id=<%=dsph("id")%>"></a></td>
    </tr>
<%
dsph.movenext
wend%>
</table>

<br>


记录数：<%=allcount%>　<a href="sxIDC.asp?<%=Request.QueryString%>&csv=yes">导出CSV</a><br>


<%
dsph.close
set dsph=nothing
conn.Close 
set conn=nothing
%>
<br>
</form>
<a name="docend"></a>
<%end if
if ef then%>
<%=ec%>
<%end if%>
<script>
var partable=parent.document.getElementById("table0");
if (partable!=null)
partable.style.display='';
partable=parent.document.getElementById("outconM");
if (partable!=null)
partable.innerHTML = document.body.innerHTML;

function doselectall()
{
var   all=document.formBT
var   checks=all.getElementsByTagName("input"); 
 for(var   i=0;i<checks.length;i++)   
      {     


		if (checks[i].name=="dsphid")
			{

				checks[i].checked=true;

			}
      }   
}
function undoselectall()
{
var   all=document.formBT
var   checks=all.getElementsByTagName("input"); 
 for(var   i=0;i<checks.length;i++)   
      {     


		if (checks[i].name=="dsphid")
			{

				checks[i].checked=false;

			}
      }   
}
</script>
