| 4477 |
dpurdie |
1 |
<%@LANGUAGE="VBSCRIPT"%>
|
|
|
2 |
<%
|
|
|
3 |
'=====================================================
|
|
|
4 |
' Release Manager Admin Tests
|
|
|
5 |
' Designed to be called via AJAX and to return
|
|
|
6 |
' JSON formatted data to dynamic page
|
|
|
7 |
'=====================================================
|
|
|
8 |
%>
|
|
|
9 |
<%
|
|
|
10 |
Option explicit
|
|
|
11 |
' Good idea to set when using redirect
|
|
|
12 |
Response.Expires = 0 ' always load the page, dont store
|
|
|
13 |
%>
|
|
|
14 |
<!--#include file="common/conf.asp"-->
|
|
|
15 |
<!--#include file="common/globals.asp"-->
|
|
|
16 |
<!--#include file="common/qstr.asp"-->
|
|
|
17 |
<!--#include file="common/common_subs.asp"-->
|
|
|
18 |
<!--#include file="common/formating.asp"-->
|
|
|
19 |
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="common/base64encode.vbs"></SCRIPT>
|
|
|
20 |
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT>
|
|
|
21 |
<%
|
|
|
22 |
'------------ Variable Definition -------------
|
|
|
23 |
Dim parOpr, newitem
|
|
|
24 |
Dim result
|
|
|
25 |
|
|
|
26 |
' Basic Parameters
|
|
|
27 |
parOpr = QStrPar("Opr")
|
|
|
28 |
result = -1
|
|
|
29 |
|
|
|
30 |
' Init the output JSON class
|
|
|
31 |
' Operations can add data
|
|
|
32 |
' Default data will be added at the end
|
|
|
33 |
Dim oJSON
|
|
|
34 |
Set oJSON = New aspJSON
|
|
|
35 |
|
|
|
36 |
'
|
|
|
37 |
' Determine the operation to be performed
|
| 4482 |
dpurdie |
38 |
' Invoke target routine
|
|
|
39 |
' Expect:
|
|
|
40 |
' result - test result
|
|
|
41 |
' oJSON.data("emsgSummary") - Error detail
|
| 4477 |
dpurdie |
42 |
'
|
| 4482 |
dpurdie |
43 |
'
|
| 4477 |
dpurdie |
44 |
If (parOpr = "zipTest") Then
|
| 4482 |
dpurdie |
45 |
Call zipFile
|
|
|
46 |
ElseIf (parOpr = "eventTest") Then
|
|
|
47 |
Call sendEvent
|
|
|
48 |
ElseIf (parOpr = "emailTest") Then
|
|
|
49 |
Call sendEmail
|
|
|
50 |
ElseIf (parOpr = "emailWshTest") Then
|
|
|
51 |
Call sendWshEmail
|
|
|
52 |
ElseIf (parOpr = "remExecTest") Then
|
|
|
53 |
Call remExec
|
|
|
54 |
ElseIf (parOpr = "pkgAccessTest") Then
|
|
|
55 |
Call pkgAccess
|
|
|
56 |
Else
|
|
|
57 |
oJSON.data("emsgSummary") = "Unknown operation requested:" & parOpr
|
|
|
58 |
End If
|
| 4477 |
dpurdie |
59 |
|
| 4482 |
dpurdie |
60 |
'
|
|
|
61 |
' Create JSON data for the user
|
|
|
62 |
' Important fields
|
|
|
63 |
' result
|
|
|
64 |
'
|
|
|
65 |
' Debug fields
|
|
|
66 |
' Request (Array)
|
|
|
67 |
'
|
|
|
68 |
'Write single value
|
|
|
69 |
oJSON.data("result") = result
|
|
|
70 |
|
|
|
71 |
' DEBUG: An array of the user provided requests
|
|
|
72 |
Set oJSON.data("Request") = oJSON.Collection()
|
|
|
73 |
Set newitem = oJSON.AddToCollection(oJSON.data("Request"))
|
|
|
74 |
Dim variableName
|
|
|
75 |
for each variableName in Request.QueryString
|
|
|
76 |
newitem.add variableName, Request.QueryString(variableName)
|
|
|
77 |
next
|
|
|
78 |
|
|
|
79 |
'Return the object
|
|
|
80 |
Response.Write oJSON.JSONoutput()
|
|
|
81 |
|
|
|
82 |
'-------------------------------------------------
|
|
|
83 |
' Function: zipFile
|
|
|
84 |
' Description: Test the File Zipping process
|
|
|
85 |
Sub zipFile
|
| 4477 |
dpurdie |
86 |
'
|
|
|
87 |
' Create a test file in a known directory
|
|
|
88 |
'
|
|
|
89 |
Dim objZIPObject, ZipFile
|
|
|
90 |
Dim outFile, objFSO, LocalDir, objFile
|
|
|
91 |
Set objFSO=CreateObject("Scripting.FileSystemObject")
|
|
|
92 |
LocalDir = Request.ServerVariables("APPL_PHYSICAL_PATH") & "release_manager\temp\"
|
|
|
93 |
|
|
|
94 |
If NOT objFSO.FolderExists( LocalDir ) Then
|
|
|
95 |
result = 1
|
|
|
96 |
oJSON.data("emsgSummary") = "Folder not found:" & LocalDir
|
|
|
97 |
Else
|
|
|
98 |
' Create a known file to zip up
|
|
|
99 |
'
|
|
|
100 |
outFile = LocalDir & "zipTestFile.txt"
|
|
|
101 |
Set objFile = objFSO.CreateTextFile(outFile,True)
|
|
|
102 |
objFile.Write "test string" & vbCrLf
|
|
|
103 |
objFile.Close
|
|
|
104 |
|
|
|
105 |
' Zip up a test file
|
|
|
106 |
'
|
|
|
107 |
ZipFile = LocalDir & "zipTest.zip"
|
|
|
108 |
If objFSO.FileExists(ZipFile) Then
|
|
|
109 |
objFSO.DeleteFile ZipFile, TRUE
|
|
|
110 |
End If
|
|
|
111 |
|
|
|
112 |
On Error Resume Next
|
|
|
113 |
Set objZIPObject = Server.CreateObject("XStandard.Zip")
|
|
|
114 |
If Err.Number <> 0 then
|
|
|
115 |
result = 1
|
|
|
116 |
oJSON.data("emsgSummary") = "Create XStandard.Zip:" & Err.Description
|
|
|
117 |
Else
|
|
|
118 |
objZIPObject.Pack outFile, ZipFile
|
|
|
119 |
|
|
|
120 |
If objZIPObject.ErrorCode <> 0 then
|
|
|
121 |
result = 1
|
|
|
122 |
oJSON.data("emsgSummary") = "Zip Error XStandard:" & objZIPObject.ErrorCode & ":" & objZIPObject.ErrorDescription
|
|
|
123 |
Else
|
|
|
124 |
' All done - must have passed
|
|
|
125 |
result = 0
|
|
|
126 |
|
|
|
127 |
End If
|
|
|
128 |
End If
|
|
|
129 |
|
|
|
130 |
'
|
|
|
131 |
' Clean up
|
|
|
132 |
If objFSO.FileExists(outFile) Then
|
|
|
133 |
objFSO.DeleteFile outFile, TRUE
|
|
|
134 |
End If
|
|
|
135 |
|
|
|
136 |
If objFSO.FileExists(ZipFile) Then
|
|
|
137 |
objFSO.DeleteFile ZipFile, TRUE
|
|
|
138 |
End If
|
|
|
139 |
|
|
|
140 |
objZIPObject = Nothing
|
|
|
141 |
|
|
|
142 |
End If
|
|
|
143 |
set objFSO = Nothing
|
| 4482 |
dpurdie |
144 |
End Sub
|
| 4477 |
dpurdie |
145 |
|
| 4482 |
dpurdie |
146 |
'-------------------------------------------------
|
|
|
147 |
' Function: sendEvent
|
|
|
148 |
' Description: Send an Event to the Windows Log
|
|
|
149 |
Sub sendEvent
|
|
|
150 |
Dim objWSH, rv
|
|
|
151 |
Set objWSH = Server.CreateObject("WScript.Shell")
|
|
|
152 |
rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onRaiseEvent", 0, TRUE)
|
|
|
153 |
Set objWSH = Nothing
|
|
|
154 |
If rv = 0 Then
|
|
|
155 |
result = 0
|
|
|
156 |
Else
|
|
|
157 |
result = 1
|
|
|
158 |
oJSON.data("emsgSummary") = "Error:("&rv&")"
|
|
|
159 |
End If
|
|
|
160 |
End Sub
|
| 4477 |
dpurdie |
161 |
|
| 4482 |
dpurdie |
162 |
'-------------------------------------------------
|
|
|
163 |
' Function: sendEmail
|
|
|
164 |
' Description: Send an email
|
|
|
165 |
Sub sendEmail
|
|
|
166 |
Dim Mode, Attachment, Message
|
|
|
167 |
|
|
|
168 |
Attachment = Null
|
|
|
169 |
Message = "This is a Test Email generated by the Release Manager Test."
|
|
|
170 |
Mode = QStrPar("Mode")
|
|
|
171 |
|
|
|
172 |
If Mode = "Attach" Then
|
|
|
173 |
Attachment = Server.MapPath("images\img_reports_admin.jpg")
|
|
|
174 |
Message = Message & " This message should have an attachment"
|
|
|
175 |
End If
|
|
|
176 |
|
|
|
177 |
Call Send_Email ( "Release Manager Notification", _
|
|
|
178 |
adminEmail, _
|
|
|
179 |
objAccessControl.UserEmail, _
|
|
|
180 |
"Test Email", _
|
|
|
181 |
Message, _
|
|
|
182 |
Attachment )
|
|
|
183 |
result = Err.Number
|
|
|
184 |
oJSON.data("emsgSummary") = Err.Description
|
|
|
185 |
'oJSON.data("Info1") = Mode
|
|
|
186 |
'oJSON.data("Info2") = Attachment
|
|
|
187 |
End Sub
|
|
|
188 |
|
|
|
189 |
'-------------------------------------------------
|
|
|
190 |
' Function: sendWshEmail
|
|
|
191 |
' Description: Send an email from a Wsh Script
|
|
|
192 |
Sub sendWshEmail
|
|
|
193 |
Dim objWSH, rv
|
|
|
194 |
|
|
|
195 |
Set objWSH = Server.CreateObject("WScript.Shell")
|
|
|
196 |
rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestMail", 0, TRUE)
|
|
|
197 |
Set objWSH = Nothing
|
|
|
198 |
If rv = 0 Then
|
|
|
199 |
result = 0
|
|
|
200 |
Else
|
|
|
201 |
result = 1
|
|
|
202 |
oJSON.data("emsgSummary") = "Error:("&rv&")"
|
|
|
203 |
End If
|
|
|
204 |
End Sub
|
|
|
205 |
|
|
|
206 |
'-------------------------------------------------
|
|
|
207 |
' Function: remExec
|
|
|
208 |
' Description: Test Release Manager Remote cmd Execution
|
|
|
209 |
Sub remExec
|
|
|
210 |
Dim objWSH, rv
|
|
|
211 |
|
|
|
212 |
Set objWSH = Server.CreateObject("WScript.Shell")
|
|
|
213 |
rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestArchiveAccess", 0, TRUE)
|
|
|
214 |
Set objWSH = Nothing
|
|
|
215 |
If rv = 0 Then
|
|
|
216 |
result = 0
|
|
|
217 |
Else
|
|
|
218 |
result = 1
|
|
|
219 |
oJSON.data("emsgSummary") = "Error:("&rv&")"
|
|
|
220 |
End If
|
|
|
221 |
End Sub
|
|
|
222 |
|
|
|
223 |
'-------------------------------------------------
|
|
|
224 |
' Function: pkgAccess
|
|
|
225 |
' Description: Test dpkg_archive access - can we map it
|
| 4477 |
dpurdie |
226 |
'
|
| 4482 |
dpurdie |
227 |
Sub pkgAccess
|
|
|
228 |
Dim objWSH, rv
|
| 4477 |
dpurdie |
229 |
|
| 4482 |
dpurdie |
230 |
Set objWSH = Server.CreateObject("WScript.Shell")
|
|
|
231 |
rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestMapArchive", 0, TRUE)
|
|
|
232 |
Set objWSH = Nothing
|
|
|
233 |
If rv = 0 Then
|
|
|
234 |
result = 0
|
|
|
235 |
Else
|
|
|
236 |
result = 1
|
|
|
237 |
oJSON.data("emsgSummary") = "Error:("&rv&")"
|
|
|
238 |
End If
|
|
|
239 |
End Sub
|
| 4477 |
dpurdie |
240 |
|
|
|
241 |
%>
|