<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.Form ("ip")=""  or Instr(Request.Form ("ip"), "'")>1  Then
	ef=True
	ec="IP没填或有特殊字符！"
ElseIf not IsNumeric(Request("ipid"))  Then
	ef=True
	ec="ID应该是数字！"
ElseIf not IsNumeric(Request("HostID"))  Then
	ef=True
	ec="服务器ID应该是数字！"
elseIf session("cansetserver")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Host_IP where ip='"&Request.Form ("ip")&"'"
		ds.Open Sql,conn,1,3
if not ds.Eof and Request.Form ("modify")<>"修改" and Request.Form ("delit")<>"删除" then
'	ef=True
'	ec="已存在同样的IP！"
end if

if Request.Form ("modify")="修改" Then
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Host_IP where id='"&Request.Form ("ipid")&"'"
		ds.Open Sql,conn,1,3
if ds.Eof then
	ef=True
	ec="没找到要修改的IP！"
end if
End If

if Request.Form ("delit")="删除" And Not ef and not ds.Eof then
Set dsph = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Product_Host_IP where id='"&Request.Form ("HostID")&"'"
	dsph.Open Sql,conn,1,1
if not dsph.Eof then
	ef=True
	ec="此IP有服务器正在用，只能修改，不能删除！"
end if
dsph.close
set dsph=nothing
end if

if not ef then
if Request.Form ("delit")<>"删除" Then

If InStr(Request.Form ("IP"),"-") Then

IPARY=Split(Trim(Request.Form ("IP")),"-")
IPARY2=Split(IPARY(0),".")
IPHEAD=Left(IPARY(0),Len(IPARY(0))-Len(IPARY2(UBound(IPARY2))))

For i=IPARY2(UBound(IPARY2)) To IPARY(1)
ds.addnew
If Request.Form ("orderbyid")<>"" then ds("orderbyid")=Request.Form("orderbyid")
ds("ip")=IPHEAD&i
ds("ServerlistID")=Request.Form("ServerlistID")
ds.Update
next

else
if Request.Form ("modify")<>"修改" then ds.addnew
If Request.Form ("orderbyid")<>"" then ds("orderbyid")=Request.Form("orderbyid")
If Request.Form ("IP")<>"" then ds("ip")=Trim(Request.Form("ip"))
If Request.Form ("HostID")<>"" then ds("HostID")=Request.Form("HostID")
If Request.Form ("ServerlistID")<>"" then ds("ServerlistID")=Request.Form("ServerlistID")
End If

else
ds.delete
end if
ds.Update

ds.Close
set ds=nothing
conn.Close 
set conn=nothing
Response.Redirect "serverlist.asp?id="&Request.Form("ServerlistID")&"&op=ip"
end if

end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>