Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
7.5 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <% Response.Buffer = TRUE %>
  4. <% '-------------------------------------------------------------------------
  5. ' File Upload Template Example code
  6. ' Copyright (c) Microsoft Corporation. All rights reserved.
  7. '---------------------------------------------------------------
  8. %>
  9. <!-- #include file="inc_base.asp" -->
  10. <%
  11. Dim bIsPost
  12. Dim F_FileName
  13. Server.ScriptTimeout = 3600
  14. bIsPost = CInt(Request.QueryString("IsPost"))
  15. If bIsPost Then
  16. '
  17. ' Perform file post processing.
  18. '
  19. OnPostFile()
  20. Else
  21. '
  22. ' Perform first time processing. File is not being posted
  23. ' during first time processing.
  24. '
  25. OnFirstTime()
  26. End If
  27. Function OnFirstTime()
  28. WriteLine("<HTML>")
  29. WriteLine("<SCRIPT language='JavaScript'>")
  30. WriteLine("function Init()")
  31. WriteLine("{")
  32. WriteLine(" setTimeout('DelayedInit()', 2000);")
  33. WriteLine("}")
  34. WriteLine("function DelayedInit()")
  35. WriteLine("{")
  36. WriteLine(" //alert('Entering Init()');")
  37. WriteLine(" parent.DisableNext();")
  38. WriteLine("}")
  39. WriteLine("function SA_GetUploadedFileName()")
  40. WriteLine("{")
  41. WriteLine(" return '';")
  42. WriteLine("}")
  43. WriteLine("function SA_GetFullyQualifiedUploadFileName()")
  44. WriteLine("{")
  45. WriteLine(" return '';")
  46. WriteLine("}")
  47. WriteLine("function CheckFile()")
  48. WriteLine("{")
  49. WriteLine(" var file;")
  50. WriteLine(" file = document.formUploadFile.fileSoftwareUpdate.value;")
  51. WriteLine(" if ( file.length <= 0 )")
  52. WriteLine(" {")
  53. WriteLine(" parent.DisableNext();")
  54. WriteLine(" parent.DisplayErr('Please select a file.');")
  55. WriteLine(" return false;")
  56. WriteLine(" }")
  57. WriteLine(" else")
  58. WriteLine(" {")
  59. WriteLine(" parent.DisableNext();")
  60. WriteLine(" document.formUploadFile.frmSubmit.disabled = true;")
  61. WriteLine(" //parent.StartAnimation();")
  62. WriteLine(" return true;")
  63. WriteLine(" }")
  64. WriteLine("}")
  65. WriteLine("</SCRIPT>")
  66. WriteLine("<BODY onLoad='Init();'>")
  67. Call EmitFileSelectionForm()
  68. WriteLine("</BODY>")
  69. WriteLine("</HTML>")
  70. End Function
  71. Function OnPostFile()
  72. Dim sFileName
  73. Dim sUploadPath
  74. Dim iFileSize
  75. WriteLine("<HTML>")
  76. WriteLine("<SCRIPT language='JavaScript'>")
  77. WriteLine("function SA_GetUploadedFileName()")
  78. WriteLine("{")
  79. WriteLine(" return document.frmFileUpload.txtFileName.value;")
  80. WriteLine("}")
  81. WriteLine("function SA_GetFullyQualifiedUploadFileName()")
  82. WriteLine("{")
  83. WriteLine(" return document.frmFileUpload.txtFullyQualifiedFileName.value;")
  84. WriteLine("}")
  85. WriteLine("function Init()")
  86. WriteLine("{")
  87. WriteLine(" //parent.StopAnimation();")
  88. WriteLine(" if ( document.frmFileUpload.txtFileName.value != '' )")
  89. WriteLine(" {")
  90. WriteLine(" parent.EnableNext();")
  91. WriteLine(" document.formUploadFile.frmSubmit.disabled = true;")
  92. WriteLine(" }")
  93. WriteLine(" else")
  94. WriteLine(" {")
  95. WriteLine(" parent.DisableNext();")
  96. WriteLine(" document.formUploadFile.frmSubmit.disabled = false;")
  97. WriteLine(" }")
  98. WriteLine("}")
  99. WriteLine("function CheckFile()")
  100. WriteLine("{")
  101. WriteLine(" var file;")
  102. WriteLine(" file = document.frmFileUpload.txtFileName.value;")
  103. WriteLine(" if ( file.length <= 0 )")
  104. WriteLine(" {")
  105. WriteLine(" parent.DisableNext();")
  106. WriteLine(" parent.DisplayErr('Please select a file.');")
  107. WriteLine(" return false;")
  108. WriteLine(" }")
  109. WriteLine(" else")
  110. WriteLine(" {")
  111. WriteLine(" parent.DisableNext();")
  112. WriteLine(" document.formUploadFile.frmSubmit.disabled = true;")
  113. WriteLine(" //parent.StartAnimation();")
  114. WriteLine(" return true;")
  115. WriteLine(" }")
  116. WriteLine("}")
  117. WriteLine("</SCRIPT>")
  118. WriteLine("<BODY onLoad='Init();' >")
  119. Call EmitFileSelectionForm()
  120. WriteLine("<BR>")
  121. If ( Post_UploadFile(sFileName, iFileSize) ) Then
  122. sUploadPath = Post_GetUploadPath()
  123. WriteLine("<table width=100% class='TasksBody'>")
  124. WriteLine("<tr>")
  125. WriteLine("<td>")
  126. WriteLine("You selected file: "+ Server.HTMLEncode(sUploadPath + sFileName))
  127. WriteLine("</td>")
  128. WriteLine("</tr>")
  129. WriteLine("</table>")
  130. Else
  131. sFileName = ""
  132. End If
  133. WriteLine("<FORM name=frmFileUpload>")
  134. WriteLine("<INPUT type=hidden name=txtFullyQualifiedFileName value='"+CStr(sUploadPath + sFileName) + "' >" )
  135. WriteLine("<INPUT type=hidden name=txtFileName value='"+CStr(sFileName) + "' >" )
  136. WriteLine("<INPUT type=hidden name=txtFileSize value='"+CStr(iFileSize) + "' >" )
  137. WriteLine("</FORM>")
  138. WriteLine("</BODY>")
  139. WriteLine("</HTML>")
  140. End Function
  141. Function Post_UploadFile(ByRef sFileName, ByRef iFileSize)
  142. Post_UploadFile = TRUE
  143. Err.Clear
  144. On Error Resume Next
  145. Dim oFileUpload
  146. Set oFileUpload = Server.CreateObject("Microsoft.FileUpload")
  147. If ( Err.Number <> 0 ) Then
  148. Post_UploadFile = FALSE
  149. Set oFileUpload = nothing
  150. SA_TraceOut "TEMPLATE_FILE_POST", "Error posting file: " + CStr(Hex(Err.Number))
  151. WriteLine("<DIV class=ErrMsg>")
  152. WriteLine("File upload did not complete, unexpected error during upload.")
  153. WriteLine("<BR>")
  154. WriteLine("Error code: " + CStr(Hex(Err.Number)) + " " + CStr(Err.Description))
  155. WriteLine("</DIV>")
  156. Exit Function
  157. End If
  158. sFileName = oFileUpload.FileName
  159. If ( Err.Number <> 0 ) Then
  160. Post_UploadFile = FALSE
  161. Set oFileUpload = nothing
  162. SA_TraceOut "TEMPLATE_FILE_POST", "Unexpected error getting filename, error: " + CStr(Hex(Err.Number))
  163. WriteLine("<DIV class=ErrMsg>")
  164. WriteLine("File upload did not complete, unable to query file name.")
  165. WriteLine("<BR>")
  166. WriteLine("Error code: " + CStr(Hex(Err.Number)) + " " + CStr(Err.Description))
  167. WriteLine("</DIV>")
  168. Exit Function
  169. End If
  170. iFileSize = oFileUpload.FileSize
  171. If ( Err.Number <> 0 ) Then
  172. Post_UploadFile = FALSE
  173. Set oFileUpload = nothing
  174. SA_TraceOut "TEMPLATE_FILE_POST", "Unexpected error getting file size, error: " + CStr(Hex(Err.Number))
  175. WriteLine("<DIV class=ErrMsg>")
  176. WriteLine("File upload did not complete, unable to query file size.")
  177. WriteLine("<BR>")
  178. WriteLine("Error code: " + CStr(Hex(Err.Number)) + " " + CStr(Err.Description))
  179. WriteLine("</DIV>")
  180. Exit Function
  181. End If
  182. Set oFileUpload = nothing
  183. End Function
  184. Function EmitFileSelectionForm()
  185. WriteLine("<FORM enctype='multipart/form-data'")
  186. WriteLine(" onSubmit='return CheckFile();'")
  187. WriteLine(" method=post")
  188. WriteLine(" id=formUploadFile")
  189. WriteLine(" name=formUploadFile")
  190. WriteLine(" target=_self")
  191. WriteLine(" action='sh_fileupload.asp?IsPost=1' >")
  192. WriteLine("<input type='file' name=fileSoftwareUpdate id=fileSoftwareUpdate value='"+F_FileName+"' >")
  193. WriteLine("<input type='submit' name=frmSubmit id=frmSubmit value='Select'>")
  194. WriteLine("<input type='hidden' name=TargetURL value='Submit'>")
  195. WriteLine("<input type='hidden' name=ReturnURL value='Submit'>")
  196. WriteLine("</form>")
  197. End Function
  198. Function Post_GetUploadPath()
  199. on error resume next
  200. Dim objRegistry
  201. Set objRegistry = RegConnection()
  202. Post_GetUploadPath = GetRegKeyValue( objRegistry, _
  203. "SOFTWARE\Microsoft\ServerAppliance\SoftwareUpdate", _
  204. "UploadFileDirectory", _
  205. CONST_STRING )
  206. If ( Len(Trim(Post_GetUploadPath)) <= 0 ) Then
  207. SA_TraceOut "SW_UPDATE", "UploadFileDirectory registry entry missing"
  208. Post_GetUploadPath = "Z:\OS_DATA\Software Update"
  209. End If
  210. if ( Right(Post_GetUploadPath,1) <> "\") Then
  211. Post_GetUploadPath = Post_GetUploadPath + "\"
  212. End If
  213. Set objRegistry = nothing
  214. End Function
  215. Function WriteLine(ByVal sLine)
  216. Response.Write(sLine+vbCrLf)
  217. End Function
  218. %>