利用ASP全自动安装JumbotCMS数据库
上一篇 / 下一篇 2007-10-16 01:24:58 / 个人分类:asp源码
部分代码:
<%
Dim DatabaseName, UserID, Password
Dim Connstr, Conn
Dim adoRS, strSQL
Dim xmldoc, xmlroot, xmlselection
If Request.QueryString("step") = "1" Then
''===========================================
''测试连接Sql Server
''===========================================
Password = Request("Password")
ConnStr = "Provider=Sqloledb;" & _
"User ID=sa;" & _
"Password=" & Password & ";" & _
"Initial Catalog=master;" & _
"Data Source=(local);"
On Error Resume Next
Set Conn = Server.CreateObject(obj_conn)
Conn.cursorLocation = 3
Conn.Open ConnStr
If Err Then
Response.Write "对不起,Sql Server身份验证错误!"
Response.End()
Err.Clear
End If
Response.Write Replace(Read1File("v", "114_install/Step1.htm"), "<$=sapass$>", Password)
Conn.Close
Set Conn = Nothing
ElseIf Request.QueryString("step") = "2" Then
Dim step2
step2 = Request.QueryString("step2")
Select Case step2
Case "1"
DatabaseName = Request("DatabaseName")
UserID = Request("UserID")
Password = Request("Password")
''===========================================
''开始创建数据库
''===========================================
ConnStr = "Provider=Sqloledb;" & _
"User ID=sa;" & _
"Password=" & Request("sapass") & ";" & _
"Initial Catalog=master;" & _
"Data Source=(local);"
On Error Resume Next
Set Conn = Server.CreateObject(obj_conn)
Conn.cursorLocation = 3
Conn.Open ConnStr
If Err Then
Response.Write "对不起,Sql Server身份验证错误!"
Response.End()
Err.Clear
End If
strSQL = "CREATE DATABASE [" & DatabaseName & "] COLLATE Chinese_PRC_CI_AS"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'autoclose', N'true'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'bulkcopy', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'trunc. log', N'true'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'torn page detection', N'true'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'read only', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'dbo use', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'single', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'autoshrink', N'true'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'ANSI null default', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'recursive triggers', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'ANSI nulls', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'concat null yields null', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'cursor close on commit', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'default to local cursor', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'quoted identifier', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'ANSI warnings', N'false'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'auto create statistics', N'true'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_dboption N'" & DatabaseName & "', N'auto update statistics', N'true'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "if( (@@microsoftversion / power(2, 24) = 8) and (@@microsoftversion & 0xffff >= 724) ) exec sp_dboption N'" & DatabaseName & "', N'db chaining', N'false'"
Set adoRS = Conn.Execute(strSQL)
Conn.Close
Set Conn = Nothing
''===========================================
''开始创建访问用户
''===========================================
ConnStr = "Provider=Sqloledb;" & _
"User ID=sa;" & _
"Password=" & Request("sapass") & ";" & _
"Initial Catalog=" & DatabaseName & ";" & _
"Data Source=(local);"
On Error Resume Next
Set Conn = Server.CreateObject(obj_conn)
Conn.cursorLocation = 3
Conn.Open ConnStr
If Err Then
Response.Write "对不起,数据库登陆错误!"
Response.End()
Err.Clear
End If
strSQL = "if not exists (select * from master.dbo.syslogins where loginname = N'" & UserID & "')" & vbCrLf & _
"BEGIN" & vbCrLf & _
"declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'master', @loginlang = N'简体中文'" & vbCrLf & _
"if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)" & vbCrLf & _
"select @logindb = N'master'" & vbCrLf & _
"if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')" & vbCrLf & _
"select @loginlang = @@language" & vbCrLf & _
"exec sp_addlogin N'" & UserID & "', '" & Password & "', @logindb, @loginlang" & vbCrLf & _
"END" & vbCrLf
Set adoRS = Conn.Execute(strSQL)
strSQL = "if not exists (select * from dbo.sysusers where name = N'" & UserID & "') EXEC sp_grantdbaccess N'" & UserID & "', N'" & UserID & "'"
Set adoRS = Conn.Execute(strSQL)
strSQL = "exec sp_addrolemember N'db_owner', N'" & UserID & "'"
Set adoRS = Conn.Execute(strSQL)
Conn.Close
Set Conn = Nothing
Set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
xmldoc.Load(Server.MapPath(SqlConfigXml))
Set xmlroot = xmldoc.documentElement
Set xmlselection = xmlroot.selectNodes("Order")
xmlselection.Item(0).Attributes.getNamedItem("ServerName").Text = "(local)"
xmlselection.Item(0).Attributes.getNamedItem("DatabaseName").Text = DatabaseName
xmlselection.Item(0).Attributes.getNamedItem("UserID").Text = UserID
xmlselection.Item(0).Attributes.getNamedItem("Password").Text = EncryptStr(Password)
xmldoc.save(Server.MapPath(SqlConfigXml))
Set xmlselection = Nothing
Set xmlroot = Nothing
Set xmldoc = Nothing
Application.Lock
Application(jumbotsn&"ServerName") = "(local)"
Application(jumbotsn&"DatabaseName") = DatabaseName
Application(jumbotsn&"UserID") = UserID
Application(jumbotsn&"Password") = Password
Application.UnLock
Response.Write "数据表和访问用户创建成功<br />" & vbCrLf
Response.Write "<script>window.setTimeout(""location.href='install.asp?step=2&step2=2'"",500);</script>"
Response.End()
Case "2"
Call OpenConn()
''===========================================
''创建频道表
''===========================================
On Error Resume Next
strSQL = "CREATE TABLE [" & prefix_db & "channel] (" & _
"[channel_id] [int] IDENTITY (1, 1) NOT NULL ," & _
"[channel_name] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[channel_Root] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[channel_Master] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[channel_Running] [int] NOT NULL ," & _
"[template_I_id] [int] NOT NULL ," & _
"[template_C_id] [int] NOT NULL ," & _
"[template_A_id] [int] NOT NULL " & _
") ON [PRIMARY]"
Set adoRS = Conn.Execute(strSQL)
strSQL = "ALTER TABLE [" & prefix_db & "channel] WITH NOCHECK ADD CONSTRAINT [PK_" & prefix_db & "channel] PRIMARY KEY CLUSTERED ([channel_id]) ON [PRIMARY] "
Set adoRS = Conn.Execute(strSQL)
If Err Then
Response.Write "数据表[" & prefix_db & "channel]已经存在<br />" & vbCrLf
Err.Clear
Else
Response.Write "数据表[" & prefix_db & "channel]创建成功<br />" & vbCrLf
End If
Response.Write "<script>window.setTimeout(""location.href='install.asp?step=2&step2=3'"",500);</script>"
Response.End()
Call CloseConn()
Case "3"
OpenConn()
On Error Resume Next
strSQL = "CREATE TABLE [" & prefix_db & "rssunip] ( " & _
"[id] [int] IDENTITY (1, 1) NOT NULL , " & _
"[sip] [bigint] NULL , " & _
"[eip] [bigint] NULL , " & _
"[remark] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL , " & _
"[endtime] [datetime] NULL " & _
") ON [PRIMARY]"
Set adoRS = Conn.Execute(strSQL)
strSQL = "ALTER TABLE [" & prefix_db & "rssunip] WITH NOCHECK ADD CONSTRAINT [PK_" & prefix_db & "rssunip] PRIMARY KEY CLUSTERED ([id]) ON [PRIMARY] "
Set adoRS = Conn.Execute(strSQL)
If Err Then
Response.Write "数据表[" & prefix_db & "rssunip]已经存在<br />" & vbCrLf
Err.Clear
Else
Response.Write "数据表[" & prefix_db & "rssunip]创建成功<br />" & vbCrLf
End If
Response.Write "<script>window.setTimeout(""parent.location.href='install.asp?step=2&step2=4'"",500);</script>"
Response.End()
CloseConn()
Case "4"
Response.Write Read1File("v", "114_install/Step2.htm")
End Select
ElseIf Request.QueryString("step") = "3" Then
OpenConn()
Dim Str, i, site_config
Str = "<" & "%'此文件自动生成,请勿修改" & vbCrLf
Str = Str & "Dim site_config(10)" & vbCrLf
For i = 0 To 9
Str = Str & "site_config(" & i & ") = """ & Request("setting" & i) & """" & vbCrLf
Next
Str = Str & "%" & ">"
Call Save2File("v", Str, script_path & "114_include/pub.inc.config.asp")
Response.Write Read1File("v", "114_install/Step3.htm")
CloseConn()
ElseIf Request.QueryString("step") = "4" Then
OpenConn()
''===========================================
''创建用户表
''===========================================
If IsExistsTable("[" & prefix_db & "user]") = False Then
strSQL = "CREATE TABLE [" & prefix_db & "user] (" & _
"[id] [int] IDENTITY (1, 1) NOT NULL , " & _
"[user_name] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL , " & _
"[user_pass] [nvarchar] (32) COLLATE Chinese_PRC_CI_AS NULL , " & _
"[user_key] [int] NULL , " & _
"[loginkey] [nvarchar] (32) COLLATE Chinese_PRC_CI_AS NULL , " & _
"[regtime] [datetime] NULL , " & _
"[question] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL , " & _
"[answer] [nvarchar] (32) COLLATE Chinese_PRC_CI_AS NULL , " & _
"[logintime] [datetime] NULL , " & _
"[loginip] [bigint] NULL , " & _
"[lasttime] [datetime] NULL , " & _
"[usersetting] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL , " & _
"[locktype] [tinyint] NULL " & _
") ON [PRIMARY]"
Set adoRS = Conn.Execute(strSQL)
strSQL = "ALTER TABLE [" & prefix_db & "user] WITH NOCHECK ADD CONSTRAINT [PK_" & prefix_db & "user] PRIMARY KEY CLUSTERED ([id]) ON [PRIMARY] "
Set adoRS = Conn.Execute(strSQL)
strSQL = "INSERT INTO [" & prefix_db & "user] (user_name, user_pass, user_key, usersetting, question, answer) VALUES ('admin', '469e80d32c0559f8', 6, '1', '初始答案为111', '111')"
Set adoRS = Conn.Execute(strSQL)
End If
Set adoRS = Conn.Execute("UPDATE [" & prefix_db & "user] Set [user_name]='" & Request("user_name") & "',[user_pass]='" & Md5(Request("user_pass"), 16) & "' where [id]=1")
Response.Write Read1File("v", "114_install/Step4.htm")
CloseConn()
Else
Response.Write Read1File("v", "114_install/Step0.htm")
End If
''===========================================
''功能:是否存在字段名
''===========================================
Public Function IsExistsField(fieldName, tableName)
On Error Resume Next
IsExistsField = True
Conn.Execute ("select [" & fieldName & "] from [" & tableName & "]")
If Err Then
IsExistsField = False
Err.Clear
End If
End Function
''===========================================
''功能:是否存在数据表
''===========================================
Public Function IsExistsTable(tableName)
On Error Resume Next
IsExistsTable = True
Conn.Execute ("Select * From [" & tableName & "]")
If Err Then
IsExistsTable = False
Err.Clear
End If
End Function
Public Function OpenConn()
ConnStr = "Provider=Sqloledb;" & _
"User ID=" & Application(jumbotsn&"UserID") & ";" & _
"Password=" & Application(jumbotsn&"Password") & ";" & _
"Initial Catalog=" & Application(jumbotsn&"DatabaseName") & ";" & _
"Data Source=(local);"
On Error Resume Next
Set Conn = Server.CreateObject(obj_conn)
Conn.cursorLocation = 3
Conn.Open ConnStr
If Err Then
Response.Write "对不起,数据连接错误!"
Response.End()
Err.Clear
End If
End Function
Public Function CloseConn()
Conn.Close
Set Conn = Nothing
End Function
%>
TAG:
