Rev 4477 | Blame | Last modification | View Log | RSS feed
<%@LANGUAGE="VBSCRIPT"%><%'=====================================================' Release Manager Admin Tests' Designed to be called via AJAX and to return' JSON formatted data to dynamic page'=====================================================%><%Option explicit' Good idea to set when using redirectResponse.Expires = 0 ' always load the page, dont store%><!--#include file="common/conf.asp"--><!--#include file="common/globals.asp"--><!--#include file="common/qstr.asp"--><!--#include file="common/common_subs.asp"--><!--#include file="common/formating.asp"--><SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="common/base64encode.vbs"></SCRIPT><SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT><%'------------ Variable Definition -------------Dim parOpr, newitemDim result' Basic ParametersparOpr = QStrPar("Opr")result = -1' Init the output JSON class' Operations can add data' Default data will be added at the endDim oJSONSet oJSON = New aspJSON'' Determine the operation to be performed' Invoke target routine' Expect:' result - test result' oJSON.data("emsgSummary") - Error detail''If (parOpr = "zipTest") ThenCall zipFileElseIf (parOpr = "eventTest") ThenCall sendEventElseIf (parOpr = "emailTest") ThenCall sendEmailElseIf (parOpr = "emailWshTest") ThenCall sendWshEmailElseIf (parOpr = "remExecTest") ThenCall remExecElseIf (parOpr = "pkgAccessTest") ThenCall pkgAccessElseoJSON.data("emsgSummary") = "Unknown operation requested:" & parOprEnd If'' Create JSON data for the user' Important fields' result'' Debug fields' Request (Array)''Write single valueoJSON.data("result") = result' DEBUG: An array of the user provided requestsSet oJSON.data("Request") = oJSON.Collection()Set newitem = oJSON.AddToCollection(oJSON.data("Request"))Dim variableNamefor each variableName in Request.QueryStringnewitem.add variableName, Request.QueryString(variableName)next'Return the objectResponse.Write oJSON.JSONoutput()'-------------------------------------------------' Function: zipFile' Description: Test the File Zipping processSub zipFile'' Create a test file in a known directory'Dim objZIPObject, ZipFileDim outFile, objFSO, LocalDir, objFileSet objFSO=CreateObject("Scripting.FileSystemObject")LocalDir = Request.ServerVariables("APPL_PHYSICAL_PATH") & "release_manager\temp\"If NOT objFSO.FolderExists( LocalDir ) Thenresult = 1oJSON.data("emsgSummary") = "Folder not found:" & LocalDirElse' Create a known file to zip up'outFile = LocalDir & "zipTestFile.txt"Set objFile = objFSO.CreateTextFile(outFile,True)objFile.Write "test string" & vbCrLfobjFile.Close' Zip up a test file'ZipFile = LocalDir & "zipTest.zip"If objFSO.FileExists(ZipFile) ThenobjFSO.DeleteFile ZipFile, TRUEEnd IfOn Error Resume NextSet objZIPObject = Server.CreateObject("XStandard.Zip")If Err.Number <> 0 thenresult = 1oJSON.data("emsgSummary") = "Create XStandard.Zip:" & Err.DescriptionElseobjZIPObject.Pack outFile, ZipFileIf objZIPObject.ErrorCode <> 0 thenresult = 1oJSON.data("emsgSummary") = "Zip Error XStandard:" & objZIPObject.ErrorCode & ":" & objZIPObject.ErrorDescriptionElse' All done - must have passedresult = 0End IfEnd If'' Clean upIf objFSO.FileExists(outFile) ThenobjFSO.DeleteFile outFile, TRUEEnd IfIf objFSO.FileExists(ZipFile) ThenobjFSO.DeleteFile ZipFile, TRUEEnd IfobjZIPObject = NothingEnd Ifset objFSO = NothingEnd Sub'-------------------------------------------------' Function: sendEvent' Description: Send an Event to the Windows LogSub sendEventDim objWSH, rvSet objWSH = Server.CreateObject("WScript.Shell")rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onRaiseEvent", 0, TRUE)Set objWSH = NothingIf rv = 0 Thenresult = 0Elseresult = 1oJSON.data("emsgSummary") = "Error:("&rv&")"End IfEnd Sub'-------------------------------------------------' Function: sendEmail' Description: Send an emailSub sendEmailDim Mode, Attachment, MessageAttachment = NullMessage = "This is a Test Email generated by the Release Manager Test."Mode = QStrPar("Mode")If Mode = "Attach" ThenAttachment = Server.MapPath("images\img_reports_admin.jpg")Message = Message & " This message should have an attachment"End IfCall Send_Email ( "Release Manager Notification", _adminEmail, _objAccessControl.UserEmail, _"Test Email", _Message, _Attachment )result = Err.NumberoJSON.data("emsgSummary") = Err.Description'oJSON.data("Info1") = Mode'oJSON.data("Info2") = AttachmentEnd Sub'-------------------------------------------------' Function: sendWshEmail' Description: Send an email from a Wsh ScriptSub sendWshEmailDim objWSH, rvSet objWSH = Server.CreateObject("WScript.Shell")rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestMail", 0, TRUE)Set objWSH = NothingIf rv = 0 Thenresult = 0Elseresult = 1oJSON.data("emsgSummary") = "Error:("&rv&")"End IfEnd Sub'-------------------------------------------------' Function: remExec' Description: Test Release Manager Remote cmd ExecutionSub remExecDim objWSH, rvSet objWSH = Server.CreateObject("WScript.Shell")rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestArchiveAccess", 0, TRUE)Set objWSH = NothingIf rv = 0 Thenresult = 0Elseresult = 1oJSON.data("emsgSummary") = "Error:("&rv&")"End IfEnd Sub'-------------------------------------------------' Function: pkgAccess' Description: Test dpkg_archive access - can we map it'Sub pkgAccessDim objWSH, rvSet objWSH = Server.CreateObject("WScript.Shell")rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestMapArchive", 0, TRUE)Set objWSH = NothingIf rv = 0 Thenresult = 0Elseresult = 1oJSON.data("emsgSummary") = "Error:("&rv&")"End IfEnd Sub%>