<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><%
'--------------------------------------
'Power By 580Web @2010-2014 f02
'URL:http://www.580web.cn/
'EMail:wsok85@qq.com
'QQ:253819801
'版权所有 未经允许不得去除本版权信息
'--------------------------------------

Option Explicit
On Error Resume Next
Session.CodePage=65001
Response.ContentType = "text/html"
Response.Charset = "utf-8"
Response.Expires=-999
Session.Timeout=999
Dim SiteDir,SiteDBDir,SiteData
Dim Setup,Fso,F,objAdoStream
Dim FKFun
Dim TempArr,Temp
Dim SystemName,SystemVersion
Setup=Request.QueryString("Setup")
If Setup<>"" Then
	Setup=Clng(Setup)
Else
	Setup=1
End If
%>
<!--#Include file="../Inc/Conn.asp"-->
<!--#Include file="../Inc/Md5.asp"-->
<!--#Include file="../Inc/System.asp"-->
<!--#Include file="../Class/Cls_Fun.asp"-->
<%
Set Fso=Server.CreateObject("scripting.FileSystemObject")
Call ShowErr()
If Fso.FileExists(Server.MapPath("../Inc/Install.lock")) And Setup>0 Then
	Response.Redirect("Index.asp?Setup=0")
	Response.End
ElseIf Not Fso.FileExists(Server.MapPath("../Inc/Install.lock")) And Setup=0 Then
	Response.Redirect("Index.asp")
	Response.End
End If
Set Fso=Nothing
Set FKFun=New Cls_Fun
Select Case Setup
	Case 2
		Call d_Set()
End Select
%><!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>欢迎使用<%=SystemName&SystemVersion%>！</title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link href="Style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<%
Select Case Setup
	Case 0
		Call s_IsInstall()
	Case 1
		Call s_SetForm()
	Case 2
		Call s_Succeed()
End Select

Function s_SetForm()
	Dim f1,f2,f3,f4,f5,f6
	Dim CheckFso
	CheckFso="0"
	SiteDir=FKFun.GetDir()
	Call FsoLineWrite("../Inc/Conn.asp",2,"'--------------------------------------")
	If Err Then
		f1="<img src=""cross_circle.png"" alt=""不支持"" />"
		CheckFso="1"
		Err.Clear
	Else
		f1="<img src=""tick_circle.png"" alt=""支持"" />"
	End If
	Call DelFolder("../istest")
	Call DelFolder("../istest2")
	Call DelFile("../Inc/Install2.lock")
	Call CreateFolder("../istest")
	If Err Then
		f2="<img src=""cross_circle.png"" alt=""不支持"" />"
		CheckFso="1"
		Err.Clear
	Else
		f2="<img src=""tick_circle.png"" alt=""支持"" />"
	End If
	If CheckFso="0" Then
		Call ReNameFolder("../istest","../istest2")
		If Err Then
			f3="<img src=""cross_circle.png"" alt=""不支持"" />"
			CheckFso="1"
			Err.Clear
		Else
			f3="<img src=""tick_circle.png"" alt=""支持"" />"
		End If
		Call DelFolder("../istest2")
		If Err Then
			f4="<img src=""cross_circle.png"" alt=""不支持"" />"
			CheckFso="1"
			Err.Clear
		Else
			f4="<img src=""tick_circle.png"" alt=""支持"" />"
		End If
	Else
		f3="<img src=""cross_circle.png"" alt=""不支持"" />"
		f4="<img src=""cross_circle.png"" alt=""不支持"" />"
	End If
	Call CreateFile("../Inc/Install2.lock",Now())
	If Err Then
		f5="<img src=""cross_circle.png"" alt=""不支持"" />"
		CheckFso="1"
		Err.Clear
	Else
		f5="<img src=""tick_circle.png"" alt=""支持"" />"
	End If
	Call DelFile("../Inc/Install2.lock")
	If Err Then
		f6="<img src=""cross_circle.png"" alt=""不支持"" />"
		CheckFso="1"
		Err.Clear
	Else
		f6="<img src=""tick_circle.png"" alt=""支持"" />"
	End If
%>
<form name="install" id="install" method="post" action="Index.asp?Setup=2"<%If CheckFso="1" Then%> onSubmit="return false;"<%End If%>>
<div id="box">
	<table width="730" bordercolor="#CCCCCC" border="1" align="center" cellpadding="0" cellspacing="0">
	    <tr>
	        <td height="25" width="300" align="right">Inc/Conn.asp文件修改测试：</td>
	        <td width="430">&nbsp;<%=f1%></td>
	    </tr>
	    <tr>
	        <td height="25" align="right">istest目录创建测试：</td>
	        <td>&nbsp;<%=f2%></td>
        </tr>
	    <tr>
	        <td height="25" align="right">istest目录改名测试：</td>
	        <td>&nbsp;<%=f3%></td>
        </tr>
	    <tr>
	        <td height="25" align="right">istest目录删除测试：</td>
	        <td>&nbsp;<%=f4%></td>
        </tr>
	    <tr>
	        <td height="25" align="right">Inc/Install2.lock创建测试：</td>
	        <td>&nbsp;<%=f5%></td>
        </tr>
	    <tr>
	        <td height="25" align="right">Inc/Install2.lock删除测试：</td>
	        <td>&nbsp;<%=f6%></td>
        </tr>
	    <tr>
	        <td height="25" align="right">安装路径：</td>
	        <td>&nbsp;<%=SiteDir%></td>
        </tr>
	    <tr>
	        <td height="25" align="right">授权协议：</td>
	        <td>&nbsp;<a href="admin/license.html" target="_blank">580Web企业建站系统授权协议</a></td>
        </tr>
    </table>
<%
	If CheckFso="1" Then
%>
    <div class="center" id="errstr">
    	<p><a href="" target="_blank">权限检测未通过，请进行权限配置，配置好后点浏览器上的刷新按钮”</a></p>
    </div>
<%
	Else
%>
    <div class="center"><input type="submit" value=" 安装 " name="enter" id="enter" class="button subutton" /></div>
<%
	End If
%>
</div>
</form>
<%
End Function

Function s_Succeed()
%>
<div id="box">
    <div id="license">
        <h4>您已经成功安装了<%=SystemName&SystemVersion%>！</h4>
        <p>您现在可以进行以下操作：</p> 
        <p>1、<a href="../Admin/" target="_blank">访问系统后台</a></p> 
        <p>2、<a href="http://www./" target="_blank">访问580Web企业建站系统专题网站</a></p> 
        <p>3、<a href="http://www.580web.cn/" target="_blank">访问580Web官方网站</a></p> 
        <p>4、<a href="http://www./" target="_blank">访问580Web官方论坛</a></p> 
    </div>
</div>
<%
End Function

Function d_Set()
	Dim NewFolder
	SiteDir=FKFun.GetDir()
	SiteDBDir="../"&SiteDBDir
	NewFolder="Data%2f"&Md5(Now(),16)
	Call ReNameFolder(SiteDBDir,"../"&NewFolder) 
	If Not FKFun.IsFolder("../"&NewFolder) Then
		Response.Write("<Script>alert('数据库目录未正常重命名，请检查权限配置！');location.href='javascript:history.go(-1)';</Script>")
		Response.End()
	End If
	Call FKFun.FsoLineWrite("../Inc/Conn.asp",10,"SiteDir="""&SiteDir&"""")
	Call FKFun.FsoLineWrite("../Inc/Conn.asp",11,"SiteDBDir="""&NewFolder&"""")
	Call FKFun.CreateFile("../Inc/Install.lock",Now())
End Function

Function s_IsInstall()
%>
<div id="box">
    <div id="license">
        <h4>您已经安装过了，如需重新安装请删除程序目录下Inc/Install.lock文件！</h4>
    </div>
</div>
<%
End Function

Function ShowErr()
	If Err Then
		Response.Write "<meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" />"
		Response.Write "<body style='font-size:12px'>"
		Response.Write "错 误 号：" & Err.Number & "<br />"
		Response.Write "错误描述：" & Err.Description & "<br />"
		Response.Write "错误来源：" & Err.Source & "<br />"
		Response.Write "请根据错误提示解决问题！<br />"
		Response.Write "</body>"
		Response.End()
	End If
End Function
%>
</body>
</html>
<%
Session.CodePage=936

	
'==============================
'函 数 名：FsoLineWrite
'作    用：按行写入文件
'==============================
Function FsoLineWrite(FilePath,LineNum,LineContent)
	Dim FsoTemp,FsoTempArr
	If LineNum<1 Then Exit Function
	Set Fso=Server.CreateObject("Scri"&"pting.File"&"Sys"&"temObject")
	If Not Fso.FileExists(Server.MapPath(FilePath)) Then Exit Function
	FsoTemp=FsoFileRead(FilePath)
	FsoTempArr=Split(FsoTemp,Chr(13)&Chr(10))
	FsoTempArr(LineNum-1)=LineContent
	FsoTemp=Join(FsoTempArr,Chr(13)&Chr(10))
	Call CreateFile(FilePath,FsoTemp)
	Set Fso=Nothing
End Function
	
'==============================
'函 数 名：FsoFileRead
'作    用：读取文件
'==============================
Function FsoFileRead(FilePath)
	Set objAdoStream=Server.CreateObject("A"&"dod"&"b.St"&"r"&"eam")
	objAdoStream.Type=2
	objAdoStream.mode=3  
	objAdoStream.charset="utf-8"
	objAdoStream.open 
	objAdoStream.LoadFromFile Server.MapPath(FilePath) 
	FsoFileRead=objAdoStream.ReadText 
	objAdoStream.Close
	Set objAdoStream=Nothing
End Function

'==============================
'函 数 名：ReNameFolder
'作    用：重命名文件夹
'==============================
Function ReNameFolder(FolderName,NewFolderName)
	Set Fso=Server.CreateObject("Scri"&"pting.File"&"Sys"&"temObject")
	Fso.MoveFolder Server.MapPath(FolderName),Server.MapPath(NewFolderName)
	Set Fso=Nothing
End Function 

'==============================
'函 数 名：CreateFolder
'作    用：创建文件夹
'==============================
Function CreateFolder(FolderPath)
	If FolderPath<>"" Then
		Set Fso=Server.CreateObject("Scri"&"pting.File"&"Sys"&"temObject")
		Set F=Fso.CreateFolder(Server.MapPath(FolderPath))
		CreateFolder=F.Path
		Set F=Nothing
		Set Fso=Nothing
	End If
End Function

'==============================
'函 数 名：CreateFile
'作    用：创建文件
'==============================
Function CreateFile(FilePath,FileContent)
	Set objAdoStream=Server.CreateObject("A"&"dod"&"b.St"&"r"&"eam")
	objAdoStream.Type=2
	objAdoStream.Charset="utf-8" 
	objAdoStream.Open
	objAdoStream.WriteText=FileContent
	objAdoStream.SaveToFile Server.MapPath(FilePath),2
	objAdoStream.Close()
	Set objAdoStream=Nothing
End Function
	
'==============================
'函 数 名：ReNameFolder
'作    用：重命名文件夹
'==============================
Function ReNameFolder(FolderName,NewFolderName)
	Set Fso=Server.CreateObject("Scri"&"pting.File"&"Sys"&"temObject")
	Fso.MoveFolder Server.MapPath(FolderName),Server.MapPath(NewFolderName)
	Set Fso=Nothing
End Function

'==============================
'函 数 名：IsFolder
'作    用：检测文件夹是否存在
'==============================
Function IsFolder(FolderPath)
	If FolderPath<>"" Then
		Set Fso=Server.CreateObject("Scri"&"pting.File"&"Sys"&"temObject")
		If Fso.FolderExists(Server.MapPath(FolderPath)) Then  
			IsFolder=True
		Else
			IsFolder=False
		End If
		Set Fso=Nothing
	End If
End Function

'==============================
'函 数 名：IsFile
'作    用：检测文件是否存在
'==============================
Function IsFile(FilePath)
	Set Fso=Server.CreateObject("Scri"&"pting.File"&"Sys"&"temObject")
	If (Fso.FileExists(Server.MapPath(FilePath))) Then
		IsFile=True
	Else
		IsFile=False
	End If
	Set Fso=Nothing
End Function

'==============================
'函 数 名：DelFolder
'作    用：删除文件夹
'==============================
Function DelFolder(FolderPath)
	If IsFolder(FolderPath)=True Then
		Set Fso=Server.CreateObject("Scri"&"pting.File"&"Sys"&"temObject")
		Fso.DeleteFolder(Server.MapPath(FolderPath))
		Set Fso=Nothing
	End If 
End Function 

'==============================
'函 数 名：DelFile
'作    用：删除文件
'==============================
Function DelFile(FilePath)
	If IsFile(FilePath)=True Then 
		Set Fso=Server.CreateObject("Scri"&"pting.File"&"Sys"&"temObject")
		Fso.DeleteFile(Server.MapPath(FilePath))
		Set Fso=Nothing
	End If
End Function 
%>