Vous êtes sur la page 1sur 8

<!-- #include file="shop$db.

asp" -->
<!-- #include file="shopmail.asp" -->
<%
'****************************************************************************
' Diagnostic Tool for VP-ASP Shopping Cart
' Can be used to test database access and mail access
' Version 5.50
' June 28, 2004
'*****************************************************************************
Const LangTestHeader="VP-ASP Diagnostics 6.00"
const LangDatabaseTest="Test Database"
const LangMailTest="Test Mail"
Const LangTestConfig="Test your current or new configuration"
Const LangTestChanges="Changes are not automatically updated in shop$config.asp"
Const LangTestMailfail=" is probably not installed on this system"
Const LangTestMailInfo="This is test from VP-ASP using "
Const LangTestWriteFail="Database cannot be written"
Const LangTestReadFail="Database cannot be read"
Const LangTestWriteOK="Database can be written"
Const LangTestVerify="Verify that the database is at the physical location in the
open message"
Const LangTestPerFail="Database Permissions are not correct"
Const LangTestRead="Database Read"
Const LangTestWrite="Database Write"
Const LangTestReadOK="Database can be read"
Const LangTestDirectory="Verify that the database is in a folder that has both read
and write access"
Const LangTestPer="Database Permissions"
Const LangTestPerOK="Database permissions tested OK"
Const LangTestReadFAQ="Read the FAQ on our web site regarding permission for the
anonymous user IUSR"
Const LangTestSummary="No problems reading or writing database "
Const LangTestFileRead="Test file read"
'
dim sAction
Dim strbody
Dim strSubject
Dim strFrom
dim strFromemail
dim currentURL
Dim Fieldnames(30)
Dim Fieldvalues(30)
Dim fieldname
Dim Fieldvalue
Dim Fieldcount
Dim Serrors
Dim curTest
Dim PrevTest
Dim errorCount
dim my_system
dim my_from
dim my_fromAddress
dim my_subject
dim my_to
dim my_toAddress
dim body
dim htmlformat
Dim Msg
Dim mailtype
Dim mailer
Dim Emailformat
dim tablerowcolor
dim initapp
'
If Getconfig("init")="No" then
SetConfig "init",""
end if
sAction=request("database")
if saction<>"" then
saction="DATABASE"
else
saction=request("mail")
if saction<>"" then
sACTION="MAIL"
else
saction=request("Fileread")
if saction<>"" then
sACTION="READFILE"
end if
end if
end if
currentURL="diag_dbtest.asp"
dbtable="tbluser"
dbfield="flddatabase"
GetFieldNames
GetFieldvalues
if saction="" then
specPageHeader
DisplayForm
specPageTrailer
else
ProcessForm
WriteDiagnosticHeader
RunTests
WriteDiagnosticTrailer
end if
Sub DisplayForm
response.write "<form name=editform action=" & currenturl & " method=POST>"
Response.Write(largeinfofont & LangTestHeader & "<br>" & LangTestConfig &
"<br>")
Response.Write(LangTestChanges & "<br>")
Response.Write(Largeinfoend)
Response.write errorfontstart & sError & errorfontend & "<br>"
Response.Write(tabledef)
for i=0 to fieldcount
fieldname = fieldnames(i)
fieldvalue = fieldvalues(i)
FormatRow fieldname,fieldvalue,sRowColor

next
Response.Write(tableDefEnd)
Response.Write("<input class=""submitbtn"" type=submit name=database
value='" & LangDataBaseTest & "'><br><br>")
Response.Write("<input class=""submitbtn"" type=submit name=mail value='" &
LangMailTest & "'>")
Response.Write("<br><input class=""submitbtn"" type=submit name=fileread
value='" & LangTestfileRead & "'>")
Response.Write("</form>")
response.write "<hr>"
end sub
Sub FormatRow (fieldname,fieldvalue, sRowColor)
If Fieldname<>"xFont" then
Response.Write(tablerow & tablecolumn & trim(fieldname) & tablecolumnend &
tablecolumn & "<input size=50 name=" & fieldname & " value=" & Chr(34) & fieldvalue
& Chr(34) & ">" & tablecolumnend & tablerowend)
else
Response.Write(tablerow & tablecolumn & trim(fieldname) & tablecolumnend &
tablecolumn & Fieldvalue & tablecolumnend & tablerowend)
end if
end sub
Sub ProcessForm
dim strname
dim strvalue
For Each key in Request.Form
strname = key
strvalue = Request.Form(key)
SetSess strname, strvalue
'debugwrite key & "=" & strvalue
Next
end sub
'

Sub GetFieldnames
Fieldnames(0)="xDatabase"
Fieldnames(1)="xDblocation"
Fieldnames(2)="xdatabasetype"
Fieldnames(3)="xEmail"
Fieldnames(4)="xEmailName"
Fieldnames(5)="xEmailSubject"
Fieldnames(6)="xEmailSystem"
Fieldnames(7)="xEmailType"
Fieldnames(8)="xOrdernumber"
fieldcount=8
end sub
'
Sub GetFieldvalues
Dim strvalue
strvalue=GetSess(fieldnames(0))
if strvalue="" then
SetDefaultValues
else
for i = 0 to fieldcount
fieldvalues(i)=Getsess(fieldnames(i))
next
strbody=GetSess("body")
end if
end sub
Sub SetDefaultValues
Fieldvalues(0)=xdatabase
Fieldvalues(1)=xdblocation
Fieldvalues(2)=xdatabasetype
Fieldvalues(3)=getconfig("xemail")
Fieldvalues(4)=getconfig("xemailname")
Fieldvalues(5)=getconfig("xemailsubject")
Fieldvalues(6)=getconfig("xEmailsystem")
Fieldvalues(7)=getconfig("xEmailType")
Fieldvalues(8)=xordernumber
end sub
Sub RunTests
ErrorCount=0
if saction="MAIL" then
RunMailtests
exit sub
end if
if saction="DATABASE" then
RunDatabaseTests
exit sub
end if
if saction="READFILE" then
RunFileReadTests
exit sub
end if
end sub
Sub RunDatabaseTests
dim dbc
dim testsql
dim testrs
dim rstemp
Serrors=""
Shopinit
SetSess "db",request("xdatabase")
SetSess "dblocation",request("xdblocation")
SetSess "xdatabasetype", request("xdatabasetype")
databasetype=GetSess("xdatabasetype")
database=GetSess("db")
curTest="Database Open"
setsess "diagnostic","Yes"
DiagnosticOpen dbc, database, databasetype
setsess "diagnostic",""
on error resume next
curTest=LangTestRead
testsql = "select * from " & dbtable
Set testrs = dbc.Execute(Testsql)
fieldvalue=testrs(dbfield)
if err.number > 0 then
addError "<b>" & LangTestReadFail & "</b>"
addError LangTestVerify
CheckMicrosoftError dbc
Adderror GetSess("dbc")
AddError "Microsoft Message<br>" & GetSess("Openerror")
else
addInfo LangTestReadOk
end if
testrs.close
curTest=LangTestWrite
if Getconfig("xmysql")="Yes" or ucase("xdatabasetype")="MYSQL" then
Testsql="Update " & dbtable & " set " & dbfield & "='shopdbtest'"
dbc.execute(testsql)
else
Set rstemp = Server.CreateObject("ADODB.Recordset")
rstemp.open dbtable, dbc, 1, 3
rstemp.update
rstemp(dbfield)="shopdbtest"
rstemp.update
end if
If err.number > 0 then
addError "<b>" & LangTestWriteFail & "</b>"
addError LangTestDirectory
AddError "Microsoft Message<br>" & GetSess("Openerror")
else
If dbc.errors.count> 0 then
addError "<b>" & langtestwritefail & "</b>"
addError LangTestDirectory
AddError "Microsoft Message<br>" & GetSess("Openerror")
CheckMicrosoftError dbc
else
addInfo LangTestwriteOK
end if
end if
'
curTest=LangTestPer
dim mysql
mysql="select * from configuration"
Set rstemp = Server.CreateObject("ADODB.RecordSet")
rstemp.cursorlocation=aduseclient
If Getconfig("xmysql")="Yes" or ucase("xdatabasetype")="MYSQL" then
else
rstemp.cachesize=5
end if
rstemp.Open MYSQL,dbc,adOpenKeyset,adLockReadOnly, adCmdText
If err.number > 0 then
addError "<b>" & LangTestPerFail & "</b>"
addError LangTestReadFAQ
else
If dbc.errors.count> 0 then
addError "<b>" & LangTestWriteFail & "</b>"
addError LangTestVerify
CheckMicrosoftError dbc
else
addInfo LangTestPerOK
end if
end if

dbc.close
set dbc=nothing
curTest="Summary"
if Errorcount=0 Then
addinfo errorinfostart & LangTestSummary & errorinfoend
end if
end sub
'
Sub addError (msg)
if curtest<>PrevTest then
Response.write "<tr><td>" & curtest & "</td>" & vbcrlf
else
Response.write "<tr><td></td>" & vbcrlf
end if
Response.write "<td>" & msg & "</td></tr>" & vbcrlf
errorcount=errorCount+1
PrevTest=CurTest
end sub

Sub addInfo (msg)


if curtest<>PrevTest then
Response.write "<tr><td>" & curtest & "</td>" & vbcrlf
else
Response.write "<tr><td></td>" & vbcrlf
end if
Response.write "<td>" & msg & "</td></tr>" & vbcrlf
PrevTest=CurTest
end sub

Sub WriteDiagnosticHeader
specPageHeader
Response.Write("<center><br>")
Response.write largeinfofont & LangTestHeader & largeinfoend & "<br>"
'Response.Write(errorfontstart & sErrors & errorfontend & "<br>")
response.write ("<table border=2 cellspacing=0 width=""80%""
bordercolor=""#0000FF"">")

End Sub
'
Sub WriteDiagnosticTrailer
Response.Write("</table>")
specPageTrailer
End Sub
'
Sub RunMailTests
'****************************************************
' Run tests with user supplied mail, if it fails try CDONTS
'****************************************************
Dim description
dim acount
htmlformat=getsess("Xemailformat")
htmlformat=ucase(htmlformat)
my_toaddress = GetSess("xEmail")
my_to=GetSess("xEmailName")
my_from="VP-ASP Diagnostic Test"
my_Fromaddress=GetSess("xEmail")
my_system=GetSess("xEmailSystem") ' imail2.innerhost.com'
mailtype=Request("xEmailType") ' ASPmail, CDONTS, JMail, ASPEMAIL
my_subject=GetSess("xEmailsubject")
body=LangTestMailInfo & mailtype & " at " & date & " " & Time()
If htmlformat="HTML" then
addhtml body
end if
'debugwrite server.htmlencode(body)
CurTest="Mailing using " & mailtype
SetSess "mailerror",""
acount=0
ExecuteMail
mailtype,My_from,my_fromaddress,my_to,my_toaddress,my_subject,body,htmlformat,my_at
tachment,acount
If GeTsess("mailerror")="" then
AddInfo "<b>Mail OK</b>"
exit sub
end if
AddError "<b>" & mailtype & LangTestMailFail & "</b><br>" & Getsess("Mailerror")
end sub
'************
Sub CheckMicrosoftError (dbc)
dim counter
If dbc.errors.count> 0 then
AddError "Error count=" & dbc.errors.count
For counter= 0 to dbc.errors.count-1
AddError "Error #" & dbc.errors(counter).number
addError "Error desc. -> " & dbc.errors(counter).description
next
End If
end sub

Sub AddHtml(body)
dim htmlstuff
htmlstuff="<html><head><title>" & langTestHeader & "</title></head><body>"
htmlstuff=htmlstuff & "<p align='center'><font size='4' face='Arial'>"
body=htmlstuff & htmlformat & "<br>" & Body & "</p></font>"
body=body & "</body></html>"
end sub

Sub RunFileReadTests
on error resume next
dim whichfile, fsobj, recordobj
whichfile=server.mappath("$license.txt")
CurTest="Reading " & whichfile
set fsObj = Server.CreateObject("Scripting.FileSystemObject")
set RecordObj= fsObj.OpenTextFile(whichfile, 1, False)
If Err.number=0 then
AddError "<b>Read successful</b>"
else
adderror err.description
end if
recordobj.close
set recordobj=nothing
set fsobj=nothing
end sub
sub Specpageheader
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>VP-ASP Shopping Cart 6.00 Diagnostic</title>
<link href="stylesheets/shop.css" rel="stylesheet" type="text/css">
</head>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="70%"><img src="images/header/hdr_logo.jpg" width="288"
height="72"></td>
</tr>
</table>
<!-- Start: Main display-->
<center><br>
<%
end sub

Sub SpecpageTrailer
%>
</center>
</body>
</html>
<%
end sub
%>

Vous aimerez peut-être aussi