<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<%
If session("HOSTAUID")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
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_Host where id='"&session("HOSTAUID")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,1
if dsph.Eof then
	ef=True
	ec="不存在的虚拟主机ID！"
end if
end if

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


if not ef then
postallcount=0
Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where allowsubbyid='"&session("HOSTAUID")&"' order by id desc"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,1
if not dsph.Eof then
while not dsph.Eof
if IsNumeric(trim(Request.Form (""&dsph("id")&""))) then
postallcount=postallcount+Request.Form (""&dsph("id")&"")
'response.write postallcount
'response.end
if postallcount>98 then
	ef=True
	ec="所有可以分配的资源总和超出100%！"
end if
end if
dsph.movenext
wend
end if
end if

if not ef then
ALLMaxConnections=0
ALLMaxBandwidth=0
Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where id='"&session("HOSTAUID")&"' or allowsubbyid='"&session("HOSTAUID")&"' and useper>0"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,1
if not dsph.Eof then
while not dsph.Eof
if not dsph("Hosttype")="子目录绑定" then
returnstr = ShowUser2(URL,FreeHostsharekey,username)
if instr(1,returnstr,"用户不存在！")>0 or instr(1,returnstr,"出错！")>0 then 
Response.Write returnstr
Response.End 
end If
if Not instr(returnstr,"用户名：")>1 then 
Response.Write "这台受控服务器自检没有通过，请在站点管理，虚拟主机中自检来分析原因。"
Response.End 
end if 
ScriptMaps=GETvalue(returnstr,";应用程序影射：",";自定义出错信息：")
ScriptMaps=trim(replace(ScriptMaps,"||","|"))
else
IISID=dsph("IISID")
returnstr=ShowUserSub(URL,FreeHostsharekey,IISID)
if instr(1,returnstr,"用户不存在！")>0 or instr(1,returnstr,"出错！")>0 then 
Response.Write returnstr
Response.End 
end if
end if

ALLMaxConnectionsA=GETvalue(returnstr,";IIS连接数：",";带宽限制：")
ALLMaxBandwidthA=GETvalue(returnstr,";带宽限制：",";主机头名：")
if ALLMaxConnectionsA="-1" or ALLMaxConnectionsA="4294967295"  or ALLMaxConnections=-1 then
ALLMaxConnections=-1
else
ALLMaxConnections=ALLMaxConnections+ALLMaxConnectionsA
end if

if ALLMaxBandwidthA="4294967295" or ALLMaxBandwidthA="-1" or ALLMaxBandwidth=4294967295 then
ALLMaxBandwidth=4294967295
else
ALLMaxBandwidth=ALLMaxBandwidth+ALLMaxBandwidthA
end if

dsph.movenext
wend
end if
end if

'Response.Write ALLMaxConnections&"<br>"
'Response.Write ALLMaxBandwidth&"<br>"

'设置
if not ef then
Enduseper=100
ENDMaxConnections=ALLMaxConnections
ENDMaxBandwidth=ALLMaxBandwidth
Set dsph = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Product_Host where id='"&session("HOSTAUID")&"' or allowsubbyid='"&session("HOSTAUID")&"' order by id desc"
	dsph.Open Sql,conn,1,3
if not dsph.Eof then
while not dsph.Eof
useper=1
if IsNumeric(trim(Request.Form (""&dsph("id")&""))) then
useper=Clng(trim(Request.Form (""&dsph("id")&"")))
if useper<1 then useper=1
end if
Enduseper=Enduseper-useper
if not dsph("Hosttype")="子目录绑定" then useper=Enduseper
dsph("useper")=useper
if ALLMaxBandwidth<32727000 and ALLMaxBandwidth>0 then
MaxBandwidth=CLNG(ALLMaxBandwidth*useper/100)
else
MaxBandwidth=4294967295
end if
if ALLMaxConnections>-1 and ALLMaxConnections<500000 then
MaxConnections=CLNG(ALLMaxConnections*useper/100)
else
MaxConnections=-1
end if
'修改

if not dsph("Hosttype")="子目录绑定" then
MaxConnections=ENDMaxConnections
MaxBandwidth=ENDMaxBandwidth
temp=ModifyUser2(URL,FreeHostsharekey,username,comment,homedir,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth)
else
ENDMaxConnections=ENDMaxConnections-MaxConnections
ENDMaxBandwidth=ENDMaxBandwidth-MaxBandwidth
if ENDMaxBandwidth=0 then ENDMaxBandwidth=4294967295
if ENDMaxConnections=0 then ENDMaxConnections=4294967295
IISID=dsph("IISID")
temp=ModifyUserSub(URL,FreeHostsharekey,username,password,IISID,comment,homedir,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth)
end if

'Response.Write MaxConnections&"<br>"
'Response.Write MaxBandwidth&"<br>"

'Response.Write temp&"<br>"
dsph.update
dsph.movenext
wend
end if
end if


if not ef then
%>
<!--#include virtual="/inc-freehost-function/template-hostadm-top.asp"-->
　资源分配

<br>
<br>
<%
Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where id='"&session("HOSTAUID")&"' or allowsubbyid='"&session("HOSTAUID")&"' order by id desc"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,1
%>
<form name="form1" method="post" action="useper2.asp">
<TABLE 
            width="100%" border=1 align=center cellPadding=0 cellSpacing=0 borderColorLight=#cccccc borderColorDark=#fbfbfb>
  <tr bgcolor="#C1BFBF" align="center">
    <td width="31%" height="35" bgcolor="#7B7D7B"><font color="#FFFFFF">目录名</font></td>
    <td width="41%" bgcolor="#7B7D7B"><font color="#FFFFFF">已绑定域名</font></td>
    <td width="28%" bgcolor="#7B7D7B"><font color="#FFFFFF">占用资源</font></td>
    </tr>
<%
while not dsph.Eof
%><tr align="center" bgcolor="#FFFFFF">
    <td height="35"><%if dsph("Hosttype")="子目录绑定" then%><%=dsph("dirname")%><%else%>主网站<%end if%></td>
    <td><%=replace(replace(dsph("hostname"),":80:",""),",","<br>")%></td>
    <td><%if dsph("Hosttype")="子目录绑定" then%><%=dsph("useper")%>%<%else%>余下的所有资源<%end if%></td>
    </tr>
<%
dsph.movenext
wend%>
<tr align="center" bgcolor="#FFFFFF">
    <td height="35" colspan="3">修改资源分配成功完成</td>
    </tr>
</table>
        </form>
<%dsph.close
set dsph=nothing
%>
<br>
　<a href="/hostadm/selfhostaddsub.asp?id=<%=session("HOSTAUID")%>"><font color="#000000">[返回子目录管理]</font></a>
<!--#include virtual="/inc-freehost-function/template-hostadm-end.asp"-->
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>