<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
server.ScriptTimeout =2400
If session("SqlAUID")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request("id")="" Then
	ef=True
	ec="请输入产品ID！"
ElseIf Instr(1, Request("id"), "'", 1)>0 then
	ef=True
	ec="非法产品ID！"
ElseIf not IsNumeric(Request("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
ElseIf not IsNumeric(Request("backupid"))  Then
	ef=True
	ec="产品ID应该是数字！"
ElseIf Instr(1, session("username"), "'", 1)>0 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_Sql where id='"&session("SqlAUID")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,3
if dsph.Eof then
	ef=True
	ec="不存在的D！"
end if
end If

If not ef then
if not dsph("status")="正常" then
		ef=True
		ec="必须是处于正常状态的数据库才能管理！"
end if
end if

if not ef then
	Set dsHostpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_SQLProductlist where SQLtype='"&dsph("SQLtype")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsHostpdlist.Open Sql,conn,1,1
if dsHostpdlist.Eof then
	ef=True
	ec="产品不存在！"
end if
end if

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

if not ef then

if isnull(dsph("randir")) then
Randomize
id=Int((99900000 - 0 + 1) * Rnd + 0)
dsph("randir")=id
dsph.update
end if

URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
userid=dsserver ("admname")
pwd=dsserver("admpass")
homedir=dsserver("homedir")
ip=dsserver("ip")
port=dsserver("port")
sqlname=dsph("sqlname")
sqlpassword=dsph("sqlpassword")

'backuptime=year(now)&month(now)&day(now)&hour(now)&Minute(now)&Second(now)
backuptime=Request("backupid")


dim softtype,MySQLver,MSSQLver
softtype=dsserver("softtype")
MySQLver=dsserver("MySQLver")
MSSQLver=dsserver("MSSQLver")

if Request("Submit")="建立备份用的FTP" then
if isnull(dsph("ftpendtime")) then
Randomize
idnew=Int((9999 - 0 + 1) * Rnd + 0)
username=sqlname&"-"&idnew
Randomize
idnew2=Int((999207770 - 0 + 1) * Rnd + 0)
ftppass=idnew2
ftpdir=replace(dsserver("homedir")&"\backup\"&sqlname&"_"&dsph("randir"),"\\","\")
createuser=1
addacl=1
ftptype=1'默认1有读写的权限，改成2只读，改成3只写。
varcon=" /E /T /G "&username&":R"
ret=CreateDir(URL,FreeHostsharekey,replace(dsserver("homedir")&"\backup\"&sqlname&"_"&dsph("randir"),"\\","\"))
ret2=CreateFTP(URL,FreeHostsharekey,username,ftppass,ftpdir,varcon,createuser,addacl, ftptype)
'ret2=CreateFTP(URL,FreeHostsharekey,username,ftppass,ftpdir,varcon,createuser,addacl, ftptype)
dsph("ftpname")=username
dsph("ftppassword")=ftppass
dsph("ftpendtime")=dateadd("d",3,now)'now
dsph.update
end if
end if

if Request("Submit")="删除备份用的FTP" then
if not isnull(dsph("ftpendtime")) then
username=dsph("ftpname")
ftpdir=replace(dsserver("homedir")&"\backup\"&sqlname&"_"&dsph("randir"),"\\","\")
varcon=" /E /T /R "&username
todeluser=1
delacl=1
todelftp=1
ret2=DelFTP(URL,FreeHostsharekey,username,ftpdir,varcon,todeluser,delacl,todelftp)
dsph("ftpname")=null
dsph("ftppassword")=null
dsph("ftpendtime")=null
dsph.update
dsph.update
end if
end if

if Request("Submit")="建立备份" then
if softtype="SQL2000" then
backupdir=dsserver("homedir")&"\backup\"&sqlname&"_"&dsph("randir")&"\"&backuptime&".bak"
ret=CreateDir(URL,FreeHostsharekey,dsserver("homedir")&"\backup\"&sqlname&"_"&dsph("randir"))
ret2="备份返回信息："&SqlBACKUP(URL,FreeHostsharekey,userid,pwd,sqlname,backupdir)
else
backupdir=dsserver("homedir")&"\backup\"&sqlname&"_"&dsph("randir")&"\"&backuptime&".sql"
varcon="--opt "&sqlname&" --user="&userid&" --password="&pwd&" -r """&backupdir&""""
ret=CreateDir(URL,FreeHostsharekey,dsserver("homedir")&"\backup\"&sqlname&"_"&dsph("randir"))
ret2="MYQL备份返回信息："&Mysqldump(URL,FreeHostsharekey,varcon)&" 请您注意，您要求的备份操作会在1分钟后执行。为了能可靠地备份，建议您先停止您的网站。"
end if
dsph("backuptime"&Request("backupid"))=now
dsph.update
end if

if Request("Submit")="从备份中还原" then
if softtype="SQL2000" then
backupdir=dsserver("homedir")&"\backup\"&sqlname&"_"&dsph("randir")&"\"&backuptime&".bak"
 sql="RESTORE FILELISTONLY FROM DISK = '"&backupdir&"'"
Cname="LogicalName"
recon=SqlGetName(URL,FreeHostsharekey,userid,pwd,backupdir,Cname,sql)
arrystr=split(recon,"@|freehost|@")
'arrystr(0)=Replace(Trim(arrystr(0)),vbcrlf,"")
'arrystr(1)=Replace(Trim(arrystr(1)),vbcrlf,"")
'response.write arrystr(0)&"<br>"
'response.write arrystr(1)&"<br>"
if ubound(arrystr)<>2 then Response.Redirect "e.asp?e=没有找到要还原的"&backuptime&".bak 文件，请检查这个文件是否存在，也有可能是受控端的版本不支持此项操作："&recon
ret2="还原返回信息："&SqlRESTORE(URL,FreeHostsharekey,userid,pwd,sqlname,backupdir,homedir,arrystr(0),arrystr(1))
userspacelimt=dsph("userspacelimt")
logspacelimt=dsph("logspacelimt")
ret2=ret2&SqlModify(URL,FreeHostsharekey,userid,pwd,userspacelimt,logspacelimt,sqlname)
else
userid=sqlname
pwd=sqlpassword
backupdir=dsserver("homedir")&"\backup\"&sqlname&"_"&dsph("randir")&"\"&backuptime&".sql"
varcon=" --user="&userid&" --password="&pwd&" -e ""source "&backupdir&""" "&sqlname
ret2="MYSQL还原返回信息："&MysqlRestore(URL,FreeHostsharekey,varcon)&" 请您注意，您要求的还原操作会在1分钟后执行。为了能可靠地还原，请您先停止您的网站。"
end if
end if


if Request("Submit")="截断数据库日志" then
if softtype="SQL2000" then
userid=sqlname
pwd=sqlpassword
ret2="<font color=blue><b>"&SqlDelLog(URL,FreeHostsharekey,userid,pwd,sqlname,backupdir)&"</b></font>"
end if
end if

end if

if not ef then
%>
<!--#include virtual="/inc-freehost-function/template-sqladm-top.asp"-->
　数据库自助管理


<br>
<TABLE 
            width="100%" border=1 align=center cellPadding=0 cellSpacing=0 borderColorLight=#cccccc borderColorDark=#fbfbfb>
  <TBODY>
    <TR>
      <TD height="35" colspan="3" align="center" bgColor=#ffffff>清空数据库日志说明</TD>
    </TR>
    <TR>
      <TD height="91" colspan="3" align="left" bgColor=#ffffff>　数据库不断被访问时会产生日志，日志会不断增加，直到用光所有可用空间，造成网站不能访问，因此您可以定期清空日志来防止这种情况发生。</TD>
    </TR>
</TABLE>
<br>

  <%if softtype="SQL2000" then%>
<form action="sqldellog2.asp" method="post" name="form1">
<TABLE 
            width="100%" border=1 align=center cellPadding=0 cellSpacing=0 borderColorLight=#cccccc borderColorDark=#fbfbfb>
  <TBODY>
    <TR>
      <TD width="22%" align="center" vAlign=middle bgColor=#494949>&nbsp; <font color="#FFFFFF">删除日志：</font></TD>
      <TD height="35" colspan="3" align="center" bgColor=#ffffff>截断日志可以收缩数据库，减少占用的空间。</TD>
    </TR>
    <TR>
      <TD width="22%" align="center" vAlign=middle bgColor=#EEEEEE>&nbsp;</TD>
      <TD height="35" colspan="3" align="center" bgColor=#ffffff> <input name="id" type="hidden" value="<%=Request("id")%>">
        <input name="Submit" type="submit" id="Submit" value="截断数据库日志"></TD>
    </TR>
</TABLE>  
</form>
<%else%>
很抱歉，您使用的是Mysql，没有清空日志功能。
<%end if%>
<font color=red><%=ret2%></font><br><br><br>

　<a href="selfsqlmodify.asp?id=<%=Request("id")%>"><font color="#000000">[返回上一页]</font></a><br><br>
<!--#include virtual="/inc-freehost-function/template-sqladm-end.asp"-->
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>