<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%

response.Buffer = true
Server.ScriptTimeOut = 90
Session.CodePage = 65001
Session.LCID = 2057

function getdomains(ByVal str)
	Dim domain,tmpDomain,max,cnDomainList
		cnDomainList = ".com.cn|.net.cn|.org.cn|.gov.cn|.ac.cn|.bj.cn|.sh.cn|.tj.cn|.cq.cn|.he.cn|.sx.cn|.nm.cn|.ln.cn|.jl.cn|.hl.cn|.js.cn|.zj.cn|.ah.cn|.fj.cn|.jx.cn|.sd.cn|.ha.cn|.hb.cn|.hn.cn|.gd.cn|.gx.cn|.hi.cn|.sc.cn|.gz.cn|.yn.cn|.xz.cn|.sn.cn|.gs.cn|.qh.cn|.nx.cn|.xj.cn|.tw.cn|.hk.cn|.mo.cn"
		domain=str
		tmpDomain=Split(domain,".")
		max= UBound(tmpdomain)

		If tmpDomain(max)="cn" Then
			If InStr(cnDomainList,"." & tmpDomain(max-1) & ".cn") > 0 Then
				domain=tmpDomain(max-2) & "." & tmpDomain(max-1) & "." & tmpDomain(max) '取CN 的2级玉米
			Else
				domain=tmpDomain(max-1) & "." & tmpDomain(max)  '取CN玉米
			End if
		Else
			domain=tmpDomain(max-1) & "." & tmpDomain(max)  '取国际玉米
		End If 
		getdomains = domain
End Function
'-----------------'Bytestobstr by evio----------------
	Function Bytestobstr(Body, char)
   		Dim Objstream
   		Set Objstream = Server.Createobject("Adodb.Stream")
   			Objstream.Type = 1
   			Objstream.Mode =3
   			Objstream.Open
   			Objstream.Write Body
   			Objstream.Position = 0
   			Objstream.Type = 2
   			Objstream.Charset = char
   			Bytestobstr = Objstream.Readtext 
   			Objstream.Close
   		Set Objstream = Nothing
	End Function
	
	function getxmlpage(Url, htmlstart, htmlend, char)
	Dim XMLHTTP, CreateXMLHTTP
	set CreateXMLHTTP = createobject("Microsoft.XMLHTTP")
		XMLHTTP = CreateXMLHTTP.open ("GET",Url,false)
	    CreateXMLHTTP.send()
	    If err then
			err.clear()
		Else
		    XMLHTTP = Bytestobstr((CreateXMLHTTP.responseBody), char)
			if len(htmlstart) = 0 or len(htmlend) = 0 or htmlstart = "" or htmlend = "" then
				getxmlpage = XMLHTTP
			else
				XMLHTTP = Split(XMLHTTP, htmlstart)(1)
				XMLHTTP = Split(XMLHTTP, htmlend)(0)
				getxmlpage = XMLHTTP
			end if
		End If
	set CreateXMLHTTP = nothing
	end function
	'===============================验证==========================
function checkdomains(domainArea)
	checkdomains = false
 	dim i, defaulturl, localurl, t
	defaulturl = "http://www.eb.com.cn/services/domain/whoise.aspx?domain="
	localurl = Trim(getdomains(request.ServerVariables("HTTP_HOST")))
	if Instr(localurl, "www.") > 0 then localurl = replace(localurl, "www.", "")
	if len(domainArea) > 0 then
		if instr(domainArea, ";") > 0 then
			t = Split(domainArea, ";")
			for i = 0 to UBound(t)
				if instr(getxmlpage(defaulturl&localurl, "", "", "gb2312"), t(i)) > 0 then
					checkdomains = true
					exit function
				end if
			Next
		elseif instr(domainArea, ";") = 0 then
'			response.write Trim(domainArea)&instr(getxmlpage(defaulturl&localurl, "", "", "gb2312"), Trim(domainArea))
'			response.End()
			if instr(getxmlpage(defaulturl&localurl, "", "", "gb2312"), Trim(domainArea)) <> 0 then
				checkdomains = true
				exit function
			end if
		end if
	end if
end function

function checkips(ipArea)
	dim serverip
	serverip = Request.ServerVariables("LOCAL_ADDR")
	if CheckIp(serverip,ipArea) = true then
		checkips = true
	else
		checkips = false
	end if
end function
'******************************
'Function CheckIp(cInput_Ip,cBound_Ip)
'Created by qqdao, qqdao@263.net 2001/11/28
'说明：首先需要根据;号循环，然后判断是否含有"-"，如果有则进行拆分处理，最后判断是否在范围内
'参数： cInput_Ip,代检查的ip
'cBound_Ip,给定的范围格式为,单个ip,和范围ip，范围ip最后使用”-“分割，如果是“*”则必须放到最后一位
'每个范围后添加":ALLOW"表示允许登陆，添加":REFUSE"表示拒绝登陆。多个范围用”;“隔开
'例如192.168.1*.*:ALLOW;192.168.1.1:ALLOW;192.168.1.1-10:REFUSE"
'返回值: true/false
'更新：2001/12/05 支持ALLOW,REFUSE支持’*‘,不想对？支持，因为和*差不多
'******************************
function CheckIp(cInput_Ip,cBound_Ip)
dim cSingle_Ip,cTemp_IP,cStart_IP,cEnd_Ip
CheckIp = false
cSingle_Ip=split(cBound_Ip,";")

for i=0 to ubound(cSingle_Ip)
	if Instr(cSingle_Ip(i),"REFUSE") <> 0 then '就是拒绝了
		cTemp_IP = left(cSingle_Ip(i),instr(cSingle_Ip(i),":")-1)

		if Instr(cTemp_IP,"*") <> 0 then '是宽范围
			cStart_IP = left(cTemp_IP,instr(cTemp_IP,"*")-1)
				if left(cInput_Ip,len(cStart_IP))=cStart_IP then
					CheckIp = false
					exit function
				end if
		end if

		if Instr(cTemp_IP,"-") = 0 then
			cStart_IP = cTemp_IP
			cEnd_Ip = cTemp_IP
		else
			cStart_IP = left(cTemp_IP,instr(cTemp_IP,"-")-1)
			cEnd_Ip = left(cStart_IP,InStrRev(cStart_IP,".")-1)+"."+mid(cTemp_IP,instr(cTemp_IP,"-")+1)
		end if

		if Ip2Str(cInput_Ip)>=Ip2Str(cStart_IP) and Ip2Str(cInput_Ip)<=Ip2Str(cEnd_Ip) then
			CheckIp = false
			exit function
		end if

	elseif Instr(cSingle_Ip(i),"ALLOW") <> 0 then '允许

		cTemp_IP = left(cSingle_Ip(i),instr(cSingle_Ip(i),":")-1)

		if Instr(cTemp_IP,"*") <> 0 then '是宽范围
			cStart_IP = left(cTemp_IP,instr(cTemp_IP,"*")-1)
			if left(cInput_Ip,len(cStart_IP))=cStart_IP then
				CheckIp = true
				exit function
			end if
		end if

		if Instr(cTemp_IP,"-") = 0 then
			cStart_IP = cTemp_IP
			cEnd_Ip = cTemp_IP
		else
			cStart_IP = left(cTemp_IP,instr(cTemp_IP,"-")-1)
			cEnd_Ip = left(cStart_IP,InStrRev(cStart_IP,".")-1)+"."+mid(cTemp_IP,instr(cTemp_IP,"-")+1)
		end if

		if Ip2Str(cInput_Ip)>=Ip2Str(cStart_IP) and Ip2Str(cInput_Ip)<=Ip2Str(cEnd_Ip) then
			CheckIp =true
			exit function
		else
			CheckIp =false
		end if
	end if
next

end function
'******************************
'Function Ip2Str(cIp)
'Created by qqdao, qqdao@263.net 2001/11/28
'参考动网ip算法
'参数：cIp ip地址
'返回值: 转换后数值
'******************************
function Ip2Str(cIp)
Dim str1,str2,str3,str4
Dim cIp_Temp
if cIp="127.0.0.1" then cIp="192.168.0.1"
str1=left(cIp,instr(cIp,".")-1)
cIp_Temp=mid(cIp,instr(cIp,".")+1)
str2=left(cIp_Temp,instr(cIp_Temp,".")-1)
cIp_Temp=mid(cIp_Temp,instr(cIp_Temp,".")+1)
str3=left(cIp_Temp,instr(cIp_Temp,".")-1)
str4=mid(cIp_Temp,instr(cIp_Temp,".")+1)

if isNumeric(str1)=0 or isNumeric(str2)=0 or isNumeric(str3)=0 or isNumeric(str4)=0 then

else
Ip2Str=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1
end if

end function
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="UTF-8">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="Content-Language" content="UTF-8" />
	<title>建站宝自助建站系统安装程序</title>
	<style>
	 body{font-size:12px;font-family:verdana;text-align:center;background:#e9f1f8;}
	 .tBody{margin:auto;width:604px;padding:4px;border:2px solid #45749e;background:#c8dbec url(bg.png);}
	 .ins{height:auto;border:1px solid #000;padding:3px;margin:3px;background:#fff}
	 .ins div{margin:0px;padding:2px;font-size:12px;text-align:left}
	 .info{padding:4px;padding-left:0px;margin:3px;text-align:left;background:url(logo.gif) no-repeat right}
	 .more{height:20px;padding:4px;padding-left:0px;margin:3px;text-align:left;}
	 .per{height:20px;border:1px solid #000;padding:1px;margin:3px;text-align:left;background:#fff}
	 .copyRight{border:1px solid #000;padding:4px;padding-left:0px;margin:3px;text-align:left}
	 h4{margin:0px;margin-bottom:6px;font-size:18px}
	 #per{height:20px;overflow:hidden;background:#0080ff url(per.png);text-align:left;}
	 #per span{color:#fff;font-weight:bold;margin:3px;display:block}
	 #ListF{height:24px;overflow:hidden}
	 .alert{color:#f00}
	 .red{ color:#F00}
	 .info_div{ width:564px;min-height:100px;max-height:100%; border:2px solid #5C9BD6; background:#E4F7F7; text-align:left; padding:20px; overflow:auto; position: relative}
	 .info_table{ width:604px; height:100%; color:#000000}
	 blockquote{ color:#333}
	 .yellow{ color:#D19B1B}
	</style>
    <script>
	var colorleft = "<font color='#333333'>";
	var colorright = "</font>";
	function $(el){return document.getElementById(el);}
	function displayjs(){
		document.getElementById("vejs").style.display = "";
	}
	function gored(obj){
		var c = obj.split("_");
		if (c[0] == "obj" || c[0] == "Unobj"){
			$(obj).className = "red";
		}
	}
	function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
			}
			else{
				strTemp = VALUE.substring(iTemp,v_length);
				break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function
	</script>
</head>
<body onload="displayjs();">
<br/>
<div id="tBody" class="tBody">
	<div class="info">
	<h4>建站宝自助建站系统安装程序</h4>
	<div id="ListF"><b>安装进度:</b>
    <%
	if len(request.QueryString("s")) = 0 then
		response.write("<span class='yellow'> 准备安装</span> |")
	else
		response.write(" 准备安装 |")
	end if
	%>
    <%
	if request.QueryString("s") = "CheckObjInstalled" then
		response.write("<span class='yellow'> 环境检测</span> |")
	else
		response.write(" 环境检测 |")
	end if
	%>
    解压文件 | 
    基本设置 | 
    登入后台
    </div>
	</div>
	<div id="perDiv" class="per"><div id="per" style="width:0%;"></div></div>
    <input type="hidden" id="CanInstall" value="0">
    <input type="hidden" id="IsAllowed" value="0">
    <%
	If Request.QueryString("s") = "CheckObjInstalled" Then
	%>
    <div id="fileList" class="ins">
        	<ol style="width:100%; padding:10px 5px 20px 5px;">
            	<b>必须的组件和环境</b>
                <table width="90%">
                <tr><td><strong>※</strong></td><td colspan="2" align="left"><div><strong>检测IIS版本:</strong></div></td></tr>
                <tr><td>&nbsp;&nbsp;1.&nbsp;</td><td align="left"><span>IIS5.1或者IIS5.1以上</span></td><td align="center"><%=CheckIIS(Request.ServerVariables("SERVER_SOFTWARE"))%></td></tr>
                <%=CheckObject()%>
                </table>
                <br /><br />
                <b>正版权限检测(如果出现两个红色的"否",表示你的程序不是正版,请去<a href="http://www.eb.com.cn" target="_blank">第一商务</a>理解正版配置信息!)</b>
                <%
				Dim l : l = getxmlpage("http://ebdiy.cn/CheckDoMain.htm", "{", "}", "utf-8")
				dim domainArea, ipArea
				domainArea = Split(l, "|$|")(0)
				ipArea = Split(l, "|$|")(1)
				%>
                <table width="90%">
                <tr><td><strong>※</strong></td><td colspan="2" align="left"><div><strong>检测域名的权限:</strong></div></td></tr>
                <tr><td>&nbsp;</td><td align="left"><span>是否为第一商务下的域名:</span></td><td align="center">
				<%
'				response.Write(checkdomains(domainArea))
'				response.End()
				if checkdomains(domainArea) then
					response.Write("<font color=green>是</font><script>$('IsAllowed').value='1';</script>")
				else
					response.Write("<font color=red>否</font>")
				end if
				%>
                </td></tr>
                <tr><td><strong>※</strong></td><td colspan="2" align="left"><div><strong>检测服务器IP地址的权限:</strong></div></td></tr>
                <tr><td>&nbsp;</td><td align="left"><span>是否为第一商务下的主机:</span></td><td align="center">
				<%
				if checkips(ipArea) then
					response.Write("<font color=green>是</font><script>$('IsAllowed').value='1';</script>")
				else
					response.Write("<font color=red>否</font>")
				end if
				%>
                </td></tr>
                </table>
            </ol>
    </div>
    <div id="vejs" style=" text-align:right; display:none"><input type="button" value="下一步" onclick=" if ($('CanInstall').value=='1'){showMask(0);}else{if ($('IsAllowed').value == '1'){location.href='default.asp?e=install'}else{showMask(1);}}"></div>
    <%
	'alert('由于缺少必要组件,系统不允许您安装本程序,请联系空间管理员安装必要的组件后再次尝试安装本程序!')
	Else
	%>
		<div style=" text-align:center"><input type="button" value="开始检测环境" onclick=" location.href='install.asp?s=CheckObjInstalled'"></div>
    <%
	End If
	%>
</div>
</body>
</html>
<script Language="JScript" runat="server">
//*************************************
//检测系统组件是否安装
//*************************************
	function CheckObjInstalled(strClassString){
		try{
			var TmpObj = Server.CreateObject(strClassString);
			return true
		}catch(e){
			return false
		}
	}
</script>
<script language="javascript" type="text/javascript">
	var m = document.getElementById("fileList");
	m.scrollTop=parseInt(m.scrollHeight);
	var xhtml;
	function showMask(i){
	var mask = $("webMask");
	if (!mask){
		mask = document.createElement("div");
		mask.id = "webMask";
		mask.style.cssText = "position:absolute;width:100%;left:0px;top:0px;background:#666;filter:Alpha(opacity=50);-moz-opacity:0.5";
		document.body.appendChild(mask);
	}
	var h = document.documentElement.scrollHeight;
	var w = document.documentElement.scrollWidth;
	mask.style.display = "";
	mask.style.height = h + "px";	
	mask.style.width = w + "px";
	if (i == 0){
		xhtml = GetHtml();	
	}else if(i == 1){
		xhtml = ShowCanNotInstall();
	}
	InstallwebMask(xhtml);
}

function hideMask(){
	var mask = $("webMask");
	if (mask) mask.style.display = "none";
	var newid = $("newid");
	if (newid) newid.style.display = "none";
}

function InstallwebMask(html){
	if ($("newid")){
		if ($("newid").style.display == "none") $("newid").style.display = "";
		$("newid").innerHTML = html;
	}else{
		var NewBlock = document.createElement("div");
		NewBlock.id = "newid";
		NewBlock.style.cssText = "position:absolute;width:100%;left:0px;top:0px;text-align:center;height:" + document.documentElement.scrollHeight + "px";
		document.body.appendChild(NewBlock);
		NewBlock.innerHTML = html;
	}
}

function GetHtml(){
	var tags = document.getElementsByTagName("span");
	var html = "";
	var chtml = "";
	var z = "";
	for (var i = 0; i < tags.length; i++ ){
		if (tags[i].className == "red"){
			html += (colorleft + tags[i].innerHTML + colorright + "|$|");
		}
	}
	html += "end";
	var splithtml = html.split("|$|");
	for (var e = 0 ; (e < splithtml.length - 1) ; e++){
		z += "<li><table width='100%'><tr><td width='75%'><a href='" + Trim(SelectURL(splithtml[e])) + "'>" + splithtml[e] + "</a></td><td><a href='" + Trim(SelectURL(splithtml[e])) + "'>点击下载</a></td></tr></table></li>";
	}
	chtml += "<blockquote><table class='info_table'><tr valign='middle'><td align='center'><div class='info_div'>"
	chtml += "<h5 style='text-align:right'><span style='float:left'>抱歉,您将无法正常使用本程序!</span> <a href='javascript:void(0)' onclick='hideMask();'>关闭</a></h5>"
	chtml += "<dd><p style='color:green'>由于缺少必要组件,系统不允许您安装本程序,请联系空间管理员安装必要的组件后再次尝试安装本程序!如果你强行安装,将无法使用部分功能!</p></dd>"
	if ($("IsAllowed").value == "0"){
		chtml += "<dd><p style='color:#ff0000'><b>我们的建议: 您的站点既不是第一商务旗下注册的域名也不是第一商务的服务器,我们建议您去 <a href='http://www.eb.com.cn' target='_blank'>第一商务</a> 主站注册域名或者购买服务器.</b></p></dd>"
	}
	chtml += "<dd style='border:1px solid #fff'><p><ol>以下为未注册组件的下载地址,请下载后安装至服务器:<br />&nbsp;"+z+"</ol></p></dd>"
	chtml += "<div style='text-align:center'><input type='button' value='继续安装' onclick=location.href='default.asp?e=install'></div>"
	chtml += "<dd style='text-align:left'><blockquote>本程序最终解释权归 <a href='http://www.eb.com.cn'>第一商务</a> 所有.</blockquote></dd>"
	chtml += "</div></td></tr></table></blockquote>"
	
	return chtml;
}

function ShowCanNotInstall(){
	var chtml = "";
	chtml += "<blockquote><table class='info_table'><tr valign='middle'><td align='center'><div class='info_div'>"
	chtml += "<h5 style='text-align:right'><span style='float:left'>抱歉,您将无法正常使用本程序!</span> <a href='javascript:void(0)' onclick='hideMask();'>关闭</a></h5>"
	chtml += "<dd><p style='color:#ff0000'><b>我们的建议: 您的站点既不是第一商务旗下注册的域名也不是第一商务的服务器,我们建议您去 <a href='http://www.eb.com.cn' target='_blank'>第一商务</a> 主站注册域名或者购买服务器!</b></p></dd>"
	chtml += "<dd style='text-align:left'><blockquote>本程序最终解释权归 <a href='http://www.eb.com.cn'>第一商务</a> 所有.</blockquote></dd><br /><input type='button' value='安装' onclick=location.href='default.asp?e=install'>"
	chtml += "</div></td></tr></table></blockquote>"
	return chtml;
}

function SelectURL(str){
	var c;
	str = Trim(str).replace(colorleft, "").replace(colorright,"");
	switch (str){
		case "Persits.UploadProgress" :
		{
			c = "123";
			break;
		}
		case "JMail.Message" :
		{
			c = "456";
			break;
		}
		default :
		{
			c = "javascript:;";
			break;
		}
	}
	return c;
}
</script>
<%
	Function CheckIIS(str)
		Dim t : t = Lcase(Trim(str))
		Dim a
		if Instr(t, "microsoft-iis/") <> 0 then
			a = replace(t, "microsoft-iis/", "")
			if isnumeric(a) <> true then
				CheckIIS = "<b><font color='red'>无法识别服务器IIS版本</font></b>"
			else
				if a - 5.1 > 0 then
					CheckIIS = "<b><font color='green'>√</font></b>"
				else
					CheckIIS = "<b><font color='red'>抱歉,您的IIS版本太低.请更换服务器</font></b>"
				end if
			end if
		else
			CheckIIS = "<b><font color='red'>×</font></b>"
			exit function
		end if
		response.Flush()
	End Function
	
	Function CheckObject()
		Dim str, i
		Dim b : b = Array("Adodb.Stream","Microsoft.XMLHTTP","Adodb.Recordset","Scripting.FileSystemObject","Microsoft.XMLDOM","Scripting.Dictionary", "Persits.UploadProgress")
		Dim o : o = Array("JMail.Message")
		str = ""
		str = str & "<tr><td><strong>※</strong></td><td colspan=""2"" align=""left""><div><strong>以下是必要组件,如果缺少,对系统的运行将产生很大的影响:</strong></div></td></tr>"
		For i = 0 to UBound(b)
			str = str & "<tr><td>&nbsp;&nbsp;"&(i+1)&".&nbsp;</td><td align=""left""><span id=""obj_"&(i+1)&""" class=""11"">"&b(i)&"</span></td><td align=""center"">"&ReturnAnswer(b(i),1,"obj_"&(i+1)&"")&"</td></tr>"	
			response.Flush()
		Next
		i = 0
		str = str & "<tr><td><strong>※</strong></td><td colspan=""2"" align=""left""><div><strong>以下是非必要组件,如果缺少,对系统的影响不大:</strong></div></td></tr>"
		For i = 0 to UBound(o)
			str = str & "<tr><td>&nbsp;&nbsp;"&(i+1)&".&nbsp;</td><td align=""left""><span id=""Unobj_"&(i+1)&""" class=""black"">"&o(i)&"</span></td><td align=""center"">"&ReturnAnswer(o(i),0,"Unobj_"&(i+1)&"")&"</td></tr>"
			response.Flush()
		Next
		CheckObject = str
	End Function
	
	function ReturnAnswer(strClassString, i, obj)
		Dim c , e
		c = CheckObjInstalled(strClassString)
		if c = true then
			e = "<b><font color='green'>√</font></b>"
		else
			if i = 1 then
				e = "<b><font color='red'>×</font></b><script>document.getElementById('CanInstall').value='1';gored('"&obj&"')</script>"
			else
				e = "<b><font color='red'>×</font></b><script>gored('"&obj&"');</script>"
			end if
		end if
		ReturnAnswer = e
	End function
	
%>