<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If Request.Form("username")="" and Request.Form("sqlname")="" Then
	ef=True
	ec="SQL名/用户名没有填写！"
End if

If Request.Form("password")="" and Request.Form("sqlpassword")="" Then
	ef=True
	ec="密码没有填写！"
End if


If Request.Form ("sqlname")<>"" and RegExpTest("[^.A-Za-z0-9--]",Request.Form ("sqlname")) Then
	ef=True
	ec="sql用户名非法！"
End If

If Request.Form("username")<>"" and RegExpTest("[^A-Za-z0-9--]",Request.Form ("username")) Then
	ef=True
	ec="用户名非法！"
End If

If not IsNumeric(Request.Form("id"))  Then
	ef=True
	ec="ID应该是数字！"
End If


If not ef Then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
End If

If Request.Form("username")="" then
If not ef then
  Set dsph = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Sql where sqlname='"&Request.Form ("sqlname")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
outcon="非法字符！"
Response.End
end if
		dsph.Open Sql,conn,1,1
If dsph.Eof Then
		ef=True
		ec="数据库不存在！"
end if
end if

If not ef then
If dsph("sqlpassword")<>Request.Form ("sqlpassword") Then
		ef=True
		ec="密码出错了！"
end if
end if
Else'API登陆
'检查用户名密码

If not ef then
  Set dsreg = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&Request.Form ("username")&"'"
If Request.Form ("isagn")="yes" Then Sql="Select * from FreeHost.FreeHost_AGENT where username='"&Request.Form ("username")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
outcon="非法字符！"
Response.End
end if
		dsreg.Open Sql,conn,1,1
If dsreg.Eof Then
		ef=True
		ec="会员名不存在！"
end if
end If

If Request.Form ("isagn")="yes" Then '是代理

if not ef then
if md5(Request.Form ("password"))<>dsreg("password") then
		ef=True
		ec="密码不正确！"
else
session("username")=""
session("password")=""
session("AgnRunasUser")=False
haveclosehtml=dsreg("haveclosehtml")
end if
end if 
if not ef then
if dsreg("agenttype")="n" then
		ef=True
		ec="您的代理资格尚未被审批！"
end if
end If

if not ef then
If IsNull(dsreg("usermoney")) Then
		ef=True
		ec="此帐号金额为空,不允许登陆,请联系管理员处理！"
End if
end If

if not ef then
If dsreg("haveblock")=true Then
		ef=True
		ec="此帐号已锁定,不允许登陆,请联系管理员处理！"
End if
end If

If Not ef Then
session("agentusername")=dsreg("username")
session("agentusername_A")=dsreg("username")
session("atspace")="代理区"
session("agentpassword")=dsreg("password")
session("agentpasswordORI")=Request.Form ("password")
session("agenttype")=dsreg("agenttype")
session("agentusermoney")=dsreg("usermoney")
session("agentdegree")=dsreg("agentdegree")
if dsreg("cannextagn")="y" then session("cannextagn")=dsreg("cannextagn")
if dsreg("canmyserver")="y" then session("canmyserver")=dsreg("canmyserver")
session("awstoadmin")=dsreg("awstoadmin")
End if


else'不是代理
if not ef then
if Request.Form ("password")<>dsreg("password") then
		ef=True
		ec="会员密码不正确！"
Else
'处理登陆............
    session("agentusername")=""
	session("admau")=""
	session("agentname")="n"'200-11-30修改bug加上的。

if Application("emailau")=true then
if dsreg("emailau")="n" then 
		ef=True
		ec="此帐号尚未激活，请查收邮箱，激活帐号！"
end if
end If
If Not ef then
session("username")=dsreg("username")
session("password")=dsreg("password")
session("usermoney")=dsreg("usermoney")
session("atspace")="用户区"
if session("agentname")=session("username") then
session("AgnRunasUser")=True
else
session("AgnRunasUser")=false
end If
End if
if not ef then
If IsNull(dsreg("usermoney")) Then
		ef=True
		ec="此帐号金额为空,不允许登陆,请联系管理员处理！"
End if
end If

if not ef then
if dsreg("agent1")<>"n" then
 Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&dsreg("agent1")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dsagent.Open Sql,conn,1,1
If dsagent.Eof Then
		ef=True
		ec="代理会员名不存在或密码出错了！"
else
session("agenttype")=dsagent("agenttype")
session("agentname")=dsreg("agent1")
haveclosehtml=dsagent("haveclosehtml")
end If
End If
End If
End if'不是代理处理


'完成处理登陆
End If
'dsreg.close
'Set dsreg=nothing
end if

If not ef then
  Set dsph = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_SQL where id='"&Request.Form ("id")&"' and username='"&Request.Form ("username")&"'"
If Request.Form ("isagn")="yes" Then 	Sql="Select * from FreeHost.FreeHost_Product_SQL where (agent1='"&session("agentusername")&"' or agent2='"&session("agentusername")&"') and id='"&Request.Form ("id")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
outcon="非法字符！"
Response.End
end if
		dsph.Open Sql,conn,1,1
If dsph.Eof Then
		ef=True
		ec="SQL不存在！"
end if
end if

End If'完成API登陆


If not ef then
If Request.Form("username")<>"" Then
if Request.Form ("go")="a" Then
if not dsph("status")="正常" then
		ef=True
		ec="必须是处于正常状态的数据库才能管理！"
end if
End If
If not ef then
session("returl")=Request.Form ("returl")
session("SqlAUID")=dsph("id")
if Request.Form ("go")="a" then Response.Redirect "/sqladm/selfsqlmodify.asp?id="&dsph("id")
if Request.Form ("go")="c" then Response.Redirect "/sqladm/selfsqlmodifyrepay.asp?id="&dsph("id")
if Request.Form ("go")="d" then Response.Redirect "/sqladm/selfsqlmodifyup.asp?id="&dsph("id")
End If
End If
End if


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

if not ef then
session("returl")=""
session("SqlAUID")=dsph("id")
dsph.close
conn.Close
set conn=nothing
Response.Redirect "selfsqlmodify.asp"
end if

if ef then
Response.Redirect "e.asp?e="&ec
end if%>