<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("SqlAUID")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request("id")="" Then
	ef=True
	ec="请输入产品ID！"
ElseIf Instr(1, Request("id"), "'", 1)>0 then
	ef=True
	ec="非法产品ID！"
ElseIf not IsNumeric(Request("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
ElseIf not IsNumeric(Request("backupid"))  Then
	ef=True
	ec="产品ID应该是数字！"
ElseIf Instr(1, session("username"), "'", 1)>0 then
	ef=True
	ec="非法用户名！"
ElseIf Request("ip"&Request("backupid"))<>"" and not IsNumeric(replace(Request("ip"&Request("backupid")),".","")) then
	ef=True
	ec="无效的IP地址！"
end if

if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Sql where id='"&session("SqlAUID")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,3
if dsph.Eof then
	ef=True
	ec="不存在的库ID！"
end if
end If

If not ef then
if not dsph("status")="正常" then
		ef=True
		ec="必须是处于正常状态的数据库才能管理！"
end if
end if

if not ef then
	Set dsHostpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_SQLProductlist where SQLtype='"&dsph("SQLtype")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsHostpdlist.Open Sql,conn,1,1
if dsHostpdlist.Eof then
	ef=True
	ec="产品不存在！"
end if
end if

if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerSQLlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="服务器不存在！"
end if
end if

if not ef then

if Request("Submit")="设置" then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
homedir=dsserver("homedir")
ip=dsserver("ip")
opport=dsserver("port")

opip=Request("ip"&Request("backupid"))

if isnull(dsph("ip"&Request("backupid"))) then
dsph("ip"&Request("backupid"))=Request("ip"&Request("backupid"))
dsph.update
end if

	Set dsphip = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Sql where (ip1='"&dsph("ip"&Request("backupid"))&"' or ip2='"&Request("ip"&Request("backupid"))&"') and (id<>'"&session("SqlAUID")&"' and serverlistid="&dsserver("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 sql &"<br>"
opvar="del"
ret2=OPIpsec(URL,FreeHostsharekey,opvar,dsph("ip"&Request("backupid")),opport)

end if

	Set dsphip = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Sql where (ip1='"&Request("ip"&Request("backupid"))&"' or ip2='"&Request("ip"&Request("backupid"))&"') and (id<>'"&session("SqlAUID")&"' and serverlistid="&dsserver("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 sql &"22<br>"
opvar="add"
ret2=ret2&OPIpsec(URL,FreeHostsharekey,opvar,opip,opport)
dsph("ip"&Request("backupid"))=opip
If opip="" Then dsph("ip"&Request("backupid"))=null
dsph.update
else
dsph("ip"&Request("backupid"))=opip
If opip="" Then dsph("ip"&Request("backupid"))=null
dsph.update
end if

end if
end if

if not ef then
%>
<!--#include virtual="/inc-freehost-function/template-sqladm-top.asp"-->
　数据库自助管理


(现在您上网使用的IP是：<%=Request.ServerVariables("REMOTE_ADDR")%>)<br>

<TABLE 
            width="100%" border=1 align=center cellPadding=0 cellSpacing=0 borderColorLight=#cccccc borderColorDark=#fbfbfb>
  <TBODY>
    <TR>
      <TD width="33%" align="center" vAlign=middle bgColor=#494949>&nbsp; <font color="#FFFFFF">允许远程访问数据库：</font></TD>
      <TD height="35" colspan="2" align="center" bgColor=#ffffff>数据库名：<strong><%=dsph("sqlname")%></strong>　数据库密码：<strong><%=dsph("sqlpassword")%></strong>　服务器IP：<%=dsserver("ip")%> </TD>
    </TR>
  <form action="setip.asp" method="post" name="form1">
    <TR>
      <TD width="33%" align="center" vAlign=middle bgColor=#EEEEEE>远程IP 1：</TD>
      <TD width="43%" height="35" align="center" bgColor=#ffffff><input name="ip1" type="text" id="ip1" value="<%=dsph("ip1")%>" size="15" maxlength="15">
        <input name="backupid" type="hidden" id="backupid" value="1">
        <input name="id" type="hidden" value="<%=Request("id")%>"></TD>
      <TD width="24%" height="35" align="center" bgColor=#ffffff><input name="Submit" type="submit" id="Submit" value="设置"></TD>
    </TR></form>
		<form action="setip.asp" method="post" name="form1">
    <TR>
      <TD width="33%" align="center" vAlign=middle bgColor=#EEEEEE>远程IP 2：</TD>
      <TD width="43%" height="35" align="center" bgColor=#ffffff><input name="ip2" type="text" id="ip1" value="<%=dsph("ip2")%>" size="15" maxlength="15">
        <input name="backupid" type="hidden" id="backupid" value="2">
        <input name="id" type="hidden" value="<%=Request("id")%>"></TD>
      <TD height="35" align="center" bgColor=#ffffff><input name="Submit" type="submit" id="Submit" value="设置"></TD>
    </TR></form>
  </TBODY>
</TABLE>
<br>
<br>
<br>
<%=ret2%><br><br><br>

　<a href="selfsqlmodify.asp?id=<%=Request("id")%>"><font color="#000000">[返回上一页]</font></a>
<!--#include virtual="/inc-freehost-function/template-sqladm-end.asp"-->
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>