<%
''' EYCMS common
''' ==================================================================
dim ajaxUrl:ajaxUrl="http://cdn.eycms.cn"
dim hackstr
function chkhack(byval t0)
	dim ishack:ishack=False
	dim t1:t1=t0
	t1=Replace(t1,"eval(rsshow[piclist])","")
	t1=Replace(t1,"eval($rs[piclist])","")
	t1=Replace(t1,"request.servervariables","")
	t1=Replace(t1,"addCookie","")
    If Instr(Lcase(t1), Lcase("clsid:")) then ishack=true:hackstr="clsid:"
	If instr(Lcase(t1), Lcase(".loadfile")) then ishack=true:hackstr="eycms.loadfile"
	If instr(Lcase(t1), Lcase(".copyfile")) then ishack=true:hackstr="eycms.copyfile"
	If instr(Lcase(t1), Lcase(".newfile")) then ishack=true:hackstr="eycms.newfile"
	If instr(Lcase(t1), Lcase(".editfile")) then ishack=true:hackstr="eycms.editfile"
	If instr(Lcase(t1), Lcase(".copyfolder")) then ishack=true:hackstr="eycms.copyfolder"
	If instr(Lcase(t1), Lcase(".editfolder")) then ishack=true:hackstr="eycms.editfolder"
	If instr(Lcase(t1), Lcase(".newfolder")) then ishack=true:hackstr="eycms.newfolder"
	If instr(Lcase(t1), Lcase(".delfolder")) then ishack=true:hackstr="eycms.delfolder"
	If instr(Lcase(t1), Lcase(".delfile")) then ishack=true:hackstr="eycms.delfile"
	If instr(Lcase(t1), Lcase(".save_outfile")) then ishack=true:hackstr="eycms.save_outfile"
	If instr(Lcase(t1), Lcase(".newavatar")) then ishack=true:hackstr="eycms.newavatar"
	If instr(Lcase(t1), Lcase(".gethttp")) then ishack=true:hackstr="eycms.gethttp"
	If instr(Lcase(t1), Lcase(".save_outfile")) then ishack=true:hackstr="eycms.save_outfile"
	If instr(Lcase(t1), Lcase(".sendhttp")) then ishack=true:hackstr="eycms.sendhttp"
	If instr(Lcase(t1), Lcase(".sethttp")) then ishack=true:hackstr="eycms.sethttp"
	If instr(Lcase(t1), Lcase(".fget")) then ishack=true:hackstr="eycms.fget"
	If instr(Lcase(t1), Lcase(".fpost")) then ishack=true:hackstr="eycms.fpost"
	If instr(Lcase(t1), Lcase(".ffpost")) then ishack=true:hackstr="eycms.ffpost"
	If instr(Lcase(t1), Lcase(".fquery")) then ishack=true:hackstr="eycms.fquery"
	If instr(Lcase(t1), Lcase("runat=server")) then ishack=true:hackstr="runat=server"
	If instr(Lcase(t1), Lcase("eycms_function")) then ishack=true:hackstr="eycms_function"
	If instr(Lcase(t1), Lcase("eycms_upload")) then ishack=true:hackstr="eycms_upload"
	If instr(Lcase(t1), Lcase("eycms_template")) then ishack=true:hackstr="eycms_template"
	If instr(Lcase(t1), Lcase("cookie")) then ishack=true:hackstr="cookie"
	If instr(Lcase(t1), Lcase("session")) then ishack=true:hackstr="session"
	If instr(Lcase(t1), Lcase(".shell")) then ishack=true:hackstr="wscript.shell"
	dim regEx,Matches,Match,FileExt
	set regEx = New RegExp
	regEx.IgnoreCase = true
	regEx.Global = True
	FileExt="gif|jpg|jpeg|png|doc|docx|xls|xlsx|ppt|pptx|rar|zip|7z|pdf|txt|flv|mp4|rm|rmvb|wmv|3gp|avi|mpeg|swf|css|js|bak"
	regEx.pattern="eycms:include\(['""](.+?)[.]{1}(" & FileExt & ")['""]\)"
	If regEx.Test(t1) Then ishack=true:hackstr="eycms:include(非法文件)"
	regEx.pattern="<" & "!--#include file=""(../)*(.+?)[.]{1}(" & FileExt & ")""-->"
	If regEx.Test(t1) Then ishack=true:hackstr="eycms:include(非法文件)"
	regEx.pattern="runat[\s]*=[\s]*(?:""|')server(?:""|')"
	If regEx.Test(t1) Then ishack=true:hackstr="runat=server"
	regEx.Pattern = "rsshow\[piclist\]"
	If regEx.Test(t1) Then ishack=true:hackstr="rsshow[piclist]"
	regEx.Pattern = "\bRequest\b"
	If regEx.Test(t1) Then ishack=true:hackstr="request"
	regEx.Pattern = "\bExecute\b"
	If regEx.Test(t1) Then ishack=true:hackstr="execute"
	regEx.Pattern = "\bEv"&"al\b"
	If regEx.Test(t1) Then ishack=true:hackstr="eval"
	regEx.Pattern = "Server.(Exec"&"ute|Transfer)([ \t]*|\()[^""]\)"
	If regEx.Test(t1) then ishack=true:hackstr="transfer"
	regEx.Pattern = "CreateO"&"bject[ |\t]*\(.*\)"
	If regEx.Test(t1) then ishack=true:hackstr="createobject"
	set matches = nothing
	set regex = nothing
	chkhack = ishack
end Function

sub getbasexml(byval t0)
	Dim t1,t2
	If InStr(t0,"/")>0 Then 
		t1=Split(t0,"/")(0)&"/"  
		t2=Replace(t0,t1,"")&"/" 
	Else
		t1=t0
		t2=""
	End if
	dim fso,fsofolder,fsocontent,fsocount
	set fso=createobject("scripting.filesystemobject")
	set fsofolder=fso.getfolder(server.mappath(""&webroot&"theme/"&t0))  
	If t2<>"model/" then
		set fsocontent=fsofolder.files
		dim fsoitem
		for each fsoitem in fsocontent
			If Right(LCase(fsoitem.Name), 4) = ".asp" Then
				dim name:name=fsoitem.name
				get_basexml=get_basexml & "<item><settag>"&get_tag(t2&fsoitem.name)&"</settag><seturl>"&t2&fsoitem.name&"</seturl><setname>"&getblockname(replace(t0&"/"&fsoitem.name,theme_root&"/",""))&"</setname></item>" & vbcrlf
			end If
		Next
	End if
	for each fsocount in fsofolder.subfolders
		If InStr(LCase(fsocount.Name), "common") > 0 Or InStr(LCase(fsocount.Name), "block") > 0 Or InStr(LCase(fsocount.Name), "user") > 0 Or InStr(LCase(fsocount.Name), "model") > 0 Or InStr(LCase(t0), "model") > 0 Then
			getbasexml(t0&"/"&fsocount.name)
		end if
	Next
	set fso=nothing
	set fsofolder=nothing
	set fsocontent=nothing
end Sub

sub updateBaseXml(t0,t1)
	dim fname,fpath,xml,i,item,settag,seturl,setname,haveitem,node
	if InStr(t0,"/")>0 then
		fpath=split(t0,"/")(0)&"/"
		fname=Replace(t0,fpath,"")
	else
		fpath=""
		fname=t0
	end If
	haveitem=False
	If InStr(fname,"mobile/")<=0 then
		if eycms.isfile("../theme/"&fpath&"base.xml") Then
			set xml=server.createobject("microsoft.xmldom")
			xml.async=false
			xml.load(server.mappath("../theme/"&fpath&"base.xml"))
			set item=xml.getElementsByTagName("item")
			for i=0 to (item.length-1)
				set settag=item.item(i).getElementsByTagName("settag")
				set seturl=item.item(i).getElementsByTagName("seturl")
				set setname=item.item(i).getElementsByTagName("setname")
				if seturl.item(0).Text=fname then 
					item.item(i).getElementsByTagName("setname").item(0).text=t1
					haveitem=true
				end if
			Next
			If haveitem=False Then
				Set node=xml.createNode(1,"item","")
				set settag = xml.createNode(1,"settag","")
				set seturl = xml.createNode(1,"seturl","")
				set setname = xml.createNode(1,"setname","")
				settag.text=get_tag(fname)
				seturl.text=fname
				setname.text=t1
				node.appendChild(settag)
				node.appendChild(seturl)
				node.appendChild(setname)
				xml.documentElement.appendChild(node)
			End if
			xml.save(server.mappath("../theme/"&fpath&"base.xml")) 
			set xml=nothing
			set item=nothing
		End If
	End if
end sub

function getxmlhttp(byval t0)
	on error resume next
	dim http
	set http=server.createobject("MSXML2.ServerXMLHTTP")
		http.SetTimeOuts 20000, 20000, 30000, 30000
		http.open "GET",t0,false
		http.setRequestHeader "If-Modified-Since","0"
		http.send()
		if http.readyState=4 Then
			if http.status=200 then
				getxmlhttp=http.responsetext
			else
				getxmlhttp="ERR"
			end if
		else
			getxmlhttp="ERR"
		end if
	set http=nothing
	If Err Then
		err.Clear
		getxmlhttp="ERR"
	End If
end function

function sendhttp(byval t0,byval t1)
	on error resume next
	dim http
	set http=server.createobject("MSXML2.ServerXMLHTTP")
		http.SetTimeOuts 20000, 20000, 30000, 30000
		http.open "POST",t0,False
		http.setrequestheader "Referer",t0
		http.setrequestheader "User-Agent", "Mozilla/4.0"
		http.setrequestheader "Connection", "Keep-Alive"
		http.setrequestheader "Content-Length",len(t1)
		http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"			
		http.send(t1)
		If http.Readystate<>4 then
			Set http=nothing
			sendhttp="ERR"
			Exit function
		End if
		if http.status=200 then
			sendhttp=http.responsetext
		else
			sendhttp="ERR"
			Set http=nothing
			Exit function
		end if
	set http=nothing
	if err then 
		sendhttp="ERR"
		eycms.errlog "网址："&t0&"<br>函数：sendhttp<br>详情："&err.description,1
		err.clear
	end if
end Function

function getRemoteTheme(t0,t1)
	dim url
	url=ajaxUrl&"/plug/checksite/gettheme.asp?file="&t0&"&theme="&t1&"&url="&http_host
	getRemoteTheme=getxmlhttp(url)
end function

function getRemoteEncry(t0,t1)
	dim url
	url=ajaxUrl&"/plug/checksite/getencry.asp?file="&t0&"&theme="&t1&"&url="&http_host
	getRemoteEncry=getxmlhttp(url)
end function

function getRemoteEncry_site(t0,t1)
	dim url
	url=ajaxUrl&"/plug/checksite/getencry_site.asp?file="&t0&"&theme="&t1&"&url="&http_host
	getRemoteEncry_site=getxmlhttp(url)
end function

function getRemoteEncry_new(t0,t1,t2)
	dim url,mtheme
	mtheme=webroot&"theme/"&t1
	url=ajaxUrl&"/plug/checksite/getencry_new.asp?file="&get_adminfolder&"&theme="&mtheme&"&folder="&t2&"&url="&http_host
	getRemoteEncry_new=sendhttp(url,t0)
end function

function remoteSaveTheme(t0,t1,t2)
	dim url
	url=ajaxUrl&"/plug/checksite/savetheme.asp?file="&t0&"&theme="&t1&"&url="&http_host
	remoteSaveTheme=sendhttp(url,t2)
end function

%>
