<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.Form ("servername")="" or Instr(Request.Form ("servername"), "'")>1 Then
	ef=True
	ec="服务器名没填或有非法字符！"
ElseIf Request.Form ("site")="" 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 session("cansetserver")="" Then
	ef=True
	ec="您没有此操作的权限。"
elseIf Request.Form ("FreeHostsharekey")="" 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_ServerCDNlist where id='"&Request("id")&"'"
		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 ds("cdntype")="多点分布CDN加速用" then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_CDN where (Bindserverid1='"&ds ("Bindserverid1")&"' or Bindserverid1='"&ds ("Bindserverid2")&"' or Bindserverid2='"&ds ("Bindserverid1")&"' or Bindserverid2='"&ds ("Bindserverid2")&"')"
	dsph.Open Sql,conn,1,3
if not dsph.Eof then
	ef=True
	ec="还有CDN产品正在使用此服务器，因此不能删除！"
end if
	Set dshost = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_CDNProductlist where (Bindserverid1='"&ds ("Bindserverid1")&"' or Bindserverid1='"&ds ("Bindserverid2")&"' or Bindserverid2='"&ds ("Bindserverid1")&"' or Bindserverid2='"&ds ("Bindserverid2")&"')"
	dshost.Open Sql,conn,1,1
if not dshost.Eof then
	ef=True
	ec="还有CDN的[产品定义]正在使用此服务器，因此不能删除！产品名："&dshost("CDNtype")
end if
End If
end if
end If


if not ef Then
if Request.Form ("delit")="删除" then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where usecdn1='"&ds ("id")&"'"
	dsserver.Open Sql,conn,1,1
if Not dsserver.Eof then
	ef=True
	ec="有云服务器正在用这个CDN服务器,不能删除！"
end if
end If
end If

if not ef Then
if Request.Form ("delit")="删除" then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where usecdn1='"&ds ("id")&"'"
	dsserver.Open Sql,conn,1,1
if Not dsserver.Eof then
	ef=True
	ec="有虚拟主机服务器正在用这个CDN服务器,不能删除！"
end if
end If
end If

if not ef then

if Request.Form ("delit")<>"删除" then
if Request.Form ("Submit")<>"修改" then
ds.AddNew 
ds("cachemgrHead")="localhost"&vbcrlf
ds("mimeHead")=""
ds("squid_radius_authHead")=""
'ds("hostsHead")="127.0.0.1       localhost"&vbcrlf
'ds("hostsHead")=ds("hostsHead")+"::1             localhost"&vbcrlf
ds("squidHead")="acl all src 0.0.0.0/0.0.0.0"&vbcrlf
ds("squidHead")=ds("squidHead")+"cache_mem 1024 MB"&vbcrlf
ds("squidHead")=ds("squidHead")+"cache_dir ufs C:\squid\var\cache 30000 16 256"&vbcrlf
ds("squidHead")=ds("squidHead")+"http_access allow all"&vbcrlf
ds("squidHead")=ds("squidHead")+"http_port 80 vhost"&vbcrlf
ds("squidHead")=ds("squidHead")+"visible_hostname 7i24_CDN_FreeHost_System"&vbcrlf
ds("squidHead")=ds("squidHead")+"logformat combined %{20%y%m%d %H:%M:%S}tl,%"+Chr(62)+"a,%{host}>h,%<st,HTTP/%rv,%03Hs,%rm,%ru,%{Referer}>h,%{User-Agent}>h,%Ss:%Sh"&vbcrlf

ds("squidHead")=ds("squidHead")+"acl localhost src 127.0.0.1"&vbcrlf
ds("squidHead")=ds("squidHead")+"acl purge method PURGE"&vbcrlf
ds("squidHead")=ds("squidHead")+"http_access allow purge localhost"&vbcrlf
ds("squidHead")=ds("squidHead")+"http_access deny purge"&vbcrlf





'
'access_log C:\squid\var\logs\access.log combined


'hosts_file c:/squid/etc/hosts.conf #设置hosts文件进行方向代理的域名解析的文件位置。
'#icp_port 3130 #多台squid通信使用UDP3130在防火墙上是开的(供icp_port通讯使用，多台Squid集群才会用到)
'cache_peer 127.0.0.1 parent 80 0 no-query originserver no-digest name=server_2
'cache_peer_domain server_2 www.abc.com .abc.com
'#dns_nameservers 8.8.8.8
'#cache_peer "内网web服务器的地址" parent 80 0 no-query originserver no-digest name=cache0 #设置源Web服务器群的ip和端口
'#cache_peer_domain cache0 www.abc.com
'# .abc.com
'#附：Squid如何限制最大连接数(最大进程) 
'#acl clinent 192.168.1.101
'#acl conn5 maxconn 5       //名为conn5的ACL类型o maxconn单一IP的最大连接数
'#http_access deny client conn5


ds("cachemgr")=""
ds("mime")=""
ds("squid_radius_auth")=""
ds("hosts")=""
ds("squid")=""

Else

ds("cachemgrHead")=Replace(trim(request.Form ("cachemgrHead"))&vbcrlf,vbcrlf&vbcrlf,vbcrlf)
ds("mimeHead")=Replace(trim(request.Form ("mimeHead"))&vbcrlf,vbcrlf&vbcrlf,vbcrlf)
ds("squid_radius_authHead")=Replace(trim(request.Form ("squid_radius_authHead"))&vbcrlf,vbcrlf&vbcrlf,vbcrlf)
ds("hostsHead")=Replace(trim(request.Form ("hostsHead"))&vbcrlf,vbcrlf&vbcrlf,vbcrlf)
ds("squidHead")=Replace(trim(request.Form ("squidHead"))&vbcrlf,vbcrlf&vbcrlf,vbcrlf)


end If

ds("cname")=trim(request.Form ("cname"))

ds("cdntype")=trim(request.Form ("cdntype"))
ds("logpath")=Replace(trim(request.Form ("logpath")+"\"),"\\","\")

ds("servername")=trim(request.Form ("servername"))
ds("site")=trim(request.Form ("site"))
ds("site")="http://"&replace(ds("site"),"http://","")

ds("openmustre")=request.Form ("openmustre")
ds("autodelicp")=request.Form ("autodelicp")
ds("useisp")=request.Form ("useisp")

ds("iserr")=request.Form ("iserr")
ds("backupCDNid")=request.Form ("backupCDNid")
If IsNumeric(request.Form ("syntime")) Then ds("syntime")=request.Form ("syntime")


ds("nettype")=trim(request.Form ("nettype"))


ds("ip")=trim(request.Form ("ip"))
ds("FreeHostsharekey")=trim(request.Form ("FreeHostsharekey"))
ds("netby")=trim(request.Form ("netby"))

If IsNumeric(request.Form ("orderbyid")) Then ds("orderbyid")=request.Form ("orderbyid")

If IsNumeric(request.Form ("Bindserverid1")) Then ds("Bindserverid1")=request.Form ("Bindserverid1")
If IsNumeric(request.Form ("Bindserverid2")) Then ds("Bindserverid2")=request.Form ("Bindserverid2")
ds("IpAry")=trim(request.Form ("IpAry"))

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 "serverCDNlist.asp"
end if

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