<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf lcase(Request.Form ("servername"))="" Then
	ef=True
	ec="服务器名没填！"
ElseIf lcase(Request.Form ("site"))="" Then
	ef=True
	ec="受控网址没填！"
elseIf session("canmyserver")="" Then
	ef=True
	ec="您没有此操作的权限。"
ElseIf not IsNumeric(Request("id"))  Then
	ef=True
	ec="ID应该是数字！"
elseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("FreeHostsharekey")) Then
	ef=True
	ec="共享密码不能有特殊字符！"
elseIf Request.Form ("FreeHostsharekey")="" Then
	ef=True
	ec="共享密码不能为空。"
elseIf checkscript(Request.Form ("servername")) Then
	ef=True
	ec="名字有非法字符！如<>script"
elseIf checkscript(Replace(Request.Form ("site"),"http://","")) Then
	ef=True
	ec="受控域名有非法字符！如<>script"
elseIf checkscript(Request.Form ("ip")) Then
	ef=True
	ec="IP有非法字符！如<>script"
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_Serversqllist where id='"&Request("id")&"' and (agent1='"&session("agentusername")&"' or agent2='"&session("agentusername")&"')"
		ds.Open Sql,conn,1,3
if not ds.Eof and Request.Form ("Submit")<>"修改" and Request.Form ("delit")<>"删除" then
	ef=True
	ec="没找到要修改的服务器！"
end if

if not ef then

if Request.Form ("delit")<>"删除" then
if Request.Form ("Submit")<>"修改" then ds.AddNew 
ds("servername")=trim(lcase(Request.Form ("servername")))
ds("site")=trim(lcase(Request.Form ("site")))
ds("site")="http://"&replace(ds("site"),"http://","")
ds("ip")=trim(lcase(Request.Form ("ip")))
ds("port")=trim(request.Form ("port"))

ds("softtype")="SQL2000"

If request.Form ("softtype")="2000" Or request.Form ("softtype")="2005" Or request.Form ("softtype")="2008" Or request.Form ("softtype")="2012" then
ds("softtype")="SQL2000"
ds("MSSQLver")=request.Form ("softtype")
End If
If request.Form ("softtype")="5.0" Or request.Form ("softtype")="5.1" Or request.Form ("softtype")="5.5" then
ds("softtype")="MySQL"
ds("MySQLver")=request.Form ("softtype")
End if

if ds("softtype")="MySQL" Then ds("port")="3306"
if ds("softtype")="SQL2000" Then ds("port")="1433"

if ds("softtype")="MySQL" Then ds("admname")="root"
if ds("softtype")="SQL2000" Then ds("admname")="sa"


ds("admname")=trim(request.Form ("admname"))
ds("admpass")=trim(request.Form ("admpass"))
ds("homedir")=trim(request.Form ("homedir"))
ds("agent1")=session("agentusername")
ds("agent2")="n"
ds("FreeHostsharekey")=trim(request.Form ("FreeHostsharekey"))
ds("admurl")=replace(trim(request.Form ("admurl")),"无","")
ds("admurl")="http://"&replace(ds("admurl"),"http://","")
else
ds.delete
end if

on error resume next
ds.Update
if err then
Response.write "存在同名的服务器，请另用一个名字，也可能是字段超过了允许的长度"
Response.end
end if

ds.Close
set ds=nothing
conn.Close 
set conn=nothing
Response.Redirect "serversqllist.asp"
end if

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