<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<%
 
id=session("DNSAUID")
Aid=Request("Aid")
If session("DNSAUID")="" Then
	ef=True
	ec="授权非法，请您先登陆。"
ElseIf not IsNumeric(id)  Then
	ef=True
	ec="ID应该是数字！"
ElseIf not IsNumeric(Aid)  Then
	ef=True
	ec="ID应该是数字！"
ElseIf Request("RRType")<>"A" and Request("RRType")<>"MX" and Request("RRType")<>"CNAME" and Request("RRType")<>"TXT"  then
	ef=True
	ec="非法类型！"
ElseIf Request.Form ("netby")<>"" and not (Request.Form ("netby")="全部" or Request.Form ("netby")="电信" or Request.Form ("netby")="网通") then
	ef=True
	ec="解析区域不正确！"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set dsdm = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Domain where id='"&id&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
outcon="非法字符！"
Response.End
end if
	dsdm.Open Sql,conn,1,1
if dsdm.Eof then
	ef=True
	ec="不存在的域名！"
end if
end if

if not ef then
 	Set dsALLDNS = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_ALLDNS where PdDID='"&id&"' and id='"&Aid&"' and RRType='"&Request("RRType")&"'"
If Request.Form ("netby")<>"" and Request.Form ("netby")<>"全部" then Sql=sql+" and netby='"&Request.Form ("netby")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
outcon="非法字符！"
Response.End
end if
	dsALLDNS.Open Sql,conn,1,3
if dsALLDNS.Eof then
	ef=True
	ec="不存在的记录！"
end if
end if

if not ef then
'dsALLDNS.addnew
'dsALLDNS("username")=dsdm("username")
'dsALLDNS("PdDID")=dsdm("id")
'dsALLDNS("RRType")="A"
'dsALLDNS("RRData")=Request.Form ("RRData")
'dsALLDNS("NodeName")=Request.Form ("NodeName")
'dsALLDNS("TTL")=Request.Form ("TTL")
NodeName=dsALLDNS("NodeName")

OriDomain=dsdm("domain")
OriDomain=replace(OriDomain,".中国",".cn")
OriDomain=replace(OriDomain,".公司",".com.cn")
OriDomain=replace(OriDomain,".网络",".net.cn")
newdomain=ComX.idntoac_7i24_com(Cstr(OriDomain))


If dsdm("DNS_API")=0 And dsdm("api7select")=2 then'是1api
dsALLDNS.delete
dsALLDNS.update
dsALLDNS.close
'删除原域
vsendStr = "command=DeleteDNSZone"
vsendStr = vsendStr &"&s_login="&Application("Domain_Agent_username_7")
vsendStr = vsendStr &"&s_pw="&Application("Domain_Agent_password_7")
vsendStr = vsendStr &"&dnszone="&newdomain&"."
	retdns=HexonetAPI(vsendStr)		
If Not Instr(UCase(Replace(retdns," ","")),"CODE=200")>0 And Not Instr(UCase(Replace(retdns," ","")),"CODE=545")>0 Then
	ef=True
	ec="连接原始注册商API失败!详细内容为:"&server.URLEncode (retdns)
End if

if not ef Then
'增加记录
vsendStr = "command=CreateDNSZone"
vsendStr = vsendStr &"&s_login="&Application("Domain_Agent_username_7")
vsendStr = vsendStr &"&s_pw="&Application("Domain_Agent_password_7")
vsendStr = vsendStr &"&dnszone="&newdomain&"."
vsendStr = vsendStr &"&soattl=3600"
vsendStr = vsendStr &"&soamname=pridns."&newdomain&"."
vsendStr = vsendStr &"&soarname=hostmaster."&newdomain&"."
vsendStr = vsendStr &"&soaserial="& Right(year(now)&month(now)&day(now)&hour(now)&Minute(now),10)
vsendStr = vsendStr &"&soarefresh=86400"
vsendStr = vsendStr &"&soaretry=7200"
vsendStr = vsendStr &"&soaexpire=3600000"
vsendStr = vsendStr &"&soaminttl=172800"
set dsALLDNS=conn.execute("Select * from FreeHost.FreeHost_Product_ALLDNS where PdDID='"&id&"'")
dnsrrI=0
do while not dsALLDNS.eof
	if dsALLDNS("NodeName")="@" then
		endNodeName=newdomain&"."
	else
		endNodeName = dsALLDNS("NodeName") & "." &newdomain&"."
	end if
	
	if dsALLDNS("RRType")="A" then
		vsendStr = vsendStr &"&rr"&dnsrrI&"="&endNodeName&" "&dsALLDNS("TTL")&" IN "&dsALLDNS("RRType")&" "&dsALLDNS("RRData")
	elseif dsALLDNS("RRType")="MX" then
		vsendStr = vsendStr &"&rr"&dnsrrI&"="&endNodeName&" "&dsALLDNS("TTL")&" IN "&dsALLDNS("RRType")&" "&dsALLDNS("mxper")&" " & Replace((dsALLDNS("RRData")& "."),"..",".")
	elseif dsALLDNS("RRType")="CNAME" then
		vsendStr = vsendStr &"&rr"&dnsrrI&"="&endNodeName&" "&dsALLDNS("TTL")&" IN "&dsALLDNS("RRType")&" " & Replace((dsALLDNS("RRData")& "."),"..",".")
	elseif dsALLDNS("RRType")="TXT" then
		vsendStr = vsendStr &"&rr"&dnsrrI&"="&endNodeName&" "&dsALLDNS("TTL")&" IN "&dsALLDNS("RRType")&" "&dsALLDNS("RRData")
	end If
	dnsrrI = dnsrrI + 1
dsALLDNS.movenext
loop
dsALLDNS.close
	retdns=HexonetAPI(vsendStr)
'response.write vsendStr&"<br>"&retdns
'response.end
If Not Instr(UCase(Replace(retdns," ","")),"CODE=200")>0 Then
	ef=True
	ec="连接原始注册商API失败!详细内容为:"&server.URLEncode (retdns)
End If
'response.write retdns
End if'完成添加1api记录



else'默认用自己的DNS
Set dnsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerDNSlist"
If Request.Form ("netby")<>"" and Request.Form ("netby")<>"全部" then Sql=sql+" where netby='"&Request.Form ("netby")&"'"
	dnsserver.Open Sql,conn,1,1
while not dnsserver.eof
outcon=DNSOP(dnsserver("site"),"/RecordDelete "&newdomain&" "&dsALLDNS("NodeName")&" "&dsALLDNS("RRType"),dnsserver("FreeHostsharekey"))
dnsserver.movenext
wend
dnsserver.close

dsALLDNS.delete
dsALLDNS.update
dsALLDNS.close


Set dsALLDNS = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_ALLDNS where PdDID='"&id&"' and NodeName='"&NodeName&"' and RRType='"&Request("RRType")&"'"
If Request.Form ("netby")<>"" and Request.Form ("netby")<>"全部" then Sql=sql+" and netby='"&Request.Form ("netby")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
outcon="非法字符！"
Response.End
end if
	dsALLDNS.Open Sql,conn,1,1
while not dsALLDNS.eof

Set dnsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerDNSlist"
If Request.Form ("netby")<>"" and Request.Form ("netby")<>"全部" then Sql=sql+" where netby='"&Request.Form ("netby")&"'"
	dnsserver.Open Sql,conn,1,1
while not dnsserver.eof
if dsALLDNS("RRType")="A" Or dsALLDNS("RRType")="TXT" then
outcon=DNSOP(dnsserver("site"),"/RecordAdd "&newdomain&" "&dsALLDNS("NodeName")&" "&dsALLDNS("TTL")&"  "&dsALLDNS("RRType")&" "&dsALLDNS("RRData"),dnsserver("FreeHostsharekey"))
elseif dsALLDNS("RRType")="MX" then
outcon=DNSOP(dnsserver("site"),"/RecordAdd "&newdomain&" "&dsALLDNS("NodeName")&" "&dsALLDNS("TTL")&"  "&dsALLDNS("RRType")&" "&dsALLDNS("mxper")&" "&dsALLDNS("RRData"),dnsserver("FreeHostsharekey"))
elseif dsALLDNS("RRType")="CNAME" then
outcon=DNSOP(dnsserver("site"),"/RecordAdd "&newdomain&" "&dsALLDNS("NodeName")&" "&dsALLDNS("RRType")&" "&dsALLDNS("RRData"),dnsserver("FreeHostsharekey"))
end if
dnsserver.movenext
wend
dnsserver.close


dsALLDNS.movenext
wend
dsALLDNS.close



 	Set dsALLDNS = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_ALLDNS where PdDID='"&id&"'"
If Request.Form ("netby")<>"" and Request.Form ("netby")<>"全部" then Sql=sql+" and netby='"&Request.Form ("netby")&"'"
	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"
If Request.Form ("netby")<>"" and Request.Form ("netby")<>"全部" then Sql=sql+" where netby='"&Request.Form ("netby")&"'"
	dnsserver.Open Sql,conn,1,1
while not dnsserver.eof
outcon=DNSOP(dnsserver("site"),"/zonedelete "&newdomain,dnsserver("FreeHostsharekey"))
dnsserver.movenext
wend
dnsserver.close
end if
End if

%>
<HTML><HEAD><TITLE>Mydns</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<style type="text/css">
<!--
BODY {
	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px
}
TABLE {
	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px
}
TR {
	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px
}
TD {
	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px
}
P {
	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px
}
INPUT {
	COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px
}
SELECT {
	COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px
}
TEXTAREA {
	COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px
}
BODY {
	BACKGROUND: #ffffff; COLOR: #000000
}
.inputText {
	BACKGROUND: #ffffff; BORDER-BOTTOM: #c0c0c0 1px solid; BORDER-LEFT: #c0c0c0 1px solid; BORDER-RIGHT: #c0c0c0 1px solid; BORDER-TOP: #c0c0c0 1px solid
}
.inputRadio {
	BACKGROUND: #e8e8e8
}
.formHeader {
	BACKGROUND: #d0d0d0; COLOR: #000000; FONT-WEIGHT: bold
}
.formSubHeader {
	BACKGROUND: #e0e0e0; COLOR: #000000; FONT-WEIGHT: bold
}
.formItem {
	BACKGROUND: #e8e8e8; COLOR: #000000
}
.formText {
	BACKGROUND: #f0f0f0; COLOR: #000000
}
.formError {
	COLOR: #ff0000
}
.mainBorder {
	BACKGROUND: #666666
}
.mainHeader {
	BACKGROUND: #ffffff
}
.mainBody {
	BACKGROUND: #ffffff
}
.mainItem {
	BACKGROUND: #cccccc; FONT-WEIGHT: bold
}
.mainFooter {
	BACKGROUND: #ffffff
}
.mboxBorder {
	BORDER-BOTTOM: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid
}
A {
	COLOR: #ff9900; TEXT-DECORATION: none
}
A:link {
	COLOR: #ff9900
}
A:visited {
	COLOR: #ff9900
}
A:active {
	COLOR: #ff9900; TEXT-DECORATION: underline
}
PRE {
	FONT-FAMILY: Lucida Console, Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px
}
-->
</style>
</head>
<BODY onload="" topmargin="0">
<TABLE border=0 align="center" cellPadding=0 cellSpacing=0 class=mainBorder>
  <TBODY>
  <TR>
     <TD>
        <table border="0" cellspacing="0" cellpadding="0" align="center" height="46">
                <tr>
                  <td height="46" width="84%" rowspan="2">&nbsp;</td>
                  <td height="30" width="16%">&nbsp;</td>
                </tr>
                <tr>
                  <td height="16" width="16%">&nbsp;</td>
                </tr>
       </table>
     </TD>
  </TR>
  <TR>
    <TD>
 <table align="center" bgcolor="#cccccc" border="0" cellpadding="3" cellspacing="1" class="content" width="700">
        <tbody> 
        <tr bgcolor="#e8e8e8"> 
          <td class="content" height="28"> 
            <div align="center"> <font color="#000000" size=12px><span style="letter-spacing: 2"><font size="2"><b> 
                  MYDNS </b></font></span></font></div>
          </td>
        </tr>
        <tr> 
              <td bgcolor="#ffffff" height="81" class="unnamed1"><font face="宋体" size="2"><span style="letter-spacing: 2">
              　　操作成功<span class="unnamed1"><br>
              <br>　　
              <a href="mydns.asp?id=<%=dsdm("id")%>">[返回]</a></span></span></font></td>
        </tr>
        <tr> 
              <td bgcolor="#ffffff" class="unnamed1"><span style="letter-spacing: 2"></span></td>
        </tr>
        </tbody> 
      </table>
  
            </TD>
</TR></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
</BODY></HTML>
<%
dsdm.close
end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
