Xml_Upload.asp
上传用户:saigedz
上传日期:2019-10-14
资源大小:997k
文件大小:15k
源码类别:

中间件编程

开发平台:

HTML/CSS

  1. <%@ CODEPAGE=65001 %>
  2. <%
  3. '///////////////////////////////////////////////////////////////////////////////
  4. '// 插件应用:    1.8 Pre Terminator 及以上版本, 其它版本的Z-blog未知
  5. '// 插件制作:    haphic(http://haphic.com/)
  6. '// 备    注:    插件管理插件
  7. '// 最后修改:   2008-6-28
  8. '// 最后版本:    1.2
  9. '///////////////////////////////////////////////////////////////////////////////
  10. %>
  11. <% Option Explicit %>
  12. <% On Error Resume Next %>
  13. <% Response.Charset="UTF-8" %>
  14. <% Response.Buffer=True %>
  15. <% Server.ScriptTimeout=99999999 %>
  16. <!-- #include file="../../c_option.asp" -->
  17. <!-- #include file="../../function/c_function.asp" -->
  18. <!-- #include file="../../function/c_system_lib.asp" -->
  19. <!-- #include file="../../function/c_system_base.asp" -->
  20. <!-- #include file="../../function/c_system_plugin.asp" -->
  21. <!-- #include file="c_sapper.asp" -->
  22. <!-- #include file="../p_config.asp" -->
  23. <%
  24. Call System_Initialize()
  25. '检查非法链接
  26. Call CheckReference("")
  27. '检查权限
  28. If BlogUser.Level>1 Then Call ShowError(6)
  29. If CheckPluginState("PluginSapper")=False Then Call ShowError(48)
  30. BlogTitle = "从本地导入插件"
  31. %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  32. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%=ZC_BLOG_LANGUAGE%>" lang="<%=ZC_BLOG_LANGUAGE%>">
  33. <head>
  34. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  35. <meta http-equiv="Content-Language" content="<%=ZC_BLOG_LANGUAGE%>" />
  36. <meta name="robots" content="noindex,nofollow"/>
  37. <link rel="stylesheet" rev="stylesheet" href="../../CSS/admin.css" type="text/css" media="screen" />
  38. <link rel="stylesheet" rev="stylesheet" href="images/style.css" type="text/css" media="screen" />
  39. <title><%=BlogTitle%></title>
  40. </head>
  41. <body>
  42. <div id="divMain">
  43. <div class="Header">Plugin Sapper - 从本地上传 ZPI 文件并导入插件到 Blog. <a href="help.asp#importzpi"  title="关于导入插件">[页面帮助]</a></div>
  44. <%Call SapperMenu("3")%>
  45. <div id="divMain2">
  46. <%
  47. '*********************************************************
  48. ' 目的:    定义TUpLoadFile类
  49. ' 输入:    无
  50. ' 返回:    无
  51. '*********************************************************
  52. Class TUpLoadFile2
  53. Public ID
  54. Public AuthorID
  55. Public FileSize
  56. Public FileName
  57. Public PostTime
  58. Public Stream
  59. Private FUploadType
  60. Public Property Let UploadType(strUploadType)
  61. If (strUploadType="Stream") Then
  62. FUploadType=strUploadType
  63. Else
  64. FUploadType="Form"
  65. End If
  66. End Property
  67. Public Property Get UploadType
  68. If IsEmpty(FUploadType)=True Then
  69. UploadType="Form"
  70. Else
  71. UploadType = FUploadType
  72. End If
  73. End Property
  74. Function UpLoad_Form()
  75. Dim i,j
  76. Dim x,y,z
  77. Dim intFormSize
  78. Dim binFormData
  79. Dim strFileName
  80. intFormSize = Request.TotalBytes
  81. binFormData = Request.BinaryRead(intFormSize)
  82. If Instr(CStr(Request.ServerVariables("HTTP_USER_AGENT")),"Opera")>0 Then
  83. i=0
  84. i=InstrB(binFormData,ChrB(13)&ChrB(10)&ChrB(13)&ChrB(10))
  85. If i>0 Then i=i+3
  86. j=InstrB(binFormData,ChrB(13)&ChrB(10)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45))
  87. ElseIf  Instr(CStr(Request.ServerVariables("HTTP_USER_AGENT")),"AppleWebKit")>0 Then
  88. i=0
  89. i=InstrB(binFormData,ChrB(13)&ChrB(10)&ChrB(13)&ChrB(10))
  90. If i>0 Then i=i+3
  91. j=InstrB(binFormData,ChrB(13)&ChrB(10)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45))
  92. Else
  93. i=InstrB(binFormData,ChrB(13)&ChrB(10)&ChrB(13)&ChrB(10))
  94. i=i+3
  95. j=InStrB(binFormData,ChrB(13)&ChrB(10)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45)&ChrB(45))
  96. End If 
  97. If Len(Request.QueryString("filename"))>0 Then
  98. strFileName=Request.QueryString("filename")
  99. Else
  100. x=InstrB(binFormData,ChrB(&H66)&ChrB(&H69)&ChrB(&H6C)&ChrB(&H65)&ChrB(&H6E)&ChrB(&H61)&ChrB(&H6D)&ChrB(&H65)&ChrB(&H3D)&ChrB(&H22))
  101. y=InstrB(x+11,binFormData,ChrB(&H22))
  102. For z=1 to y-x-10
  103. strFileName=strFileName & Chr(AscB(MidB(binFormData,x+z+9,1)))
  104. Next
  105. End If
  106. Dim objStreamUp
  107. Set objStreamUp = Server.CreateObject("ADODB.Stream")
  108. With objStreamUp
  109. .Type = adTypeBinary
  110. .Mode = adModeReadWrite
  111. .Open
  112. .Position = 0
  113. .Write binFormData
  114. .Position = i
  115. Stream=.Read(j-i-1)
  116. .Close
  117. End With
  118. FileSize=LenB(Stream)
  119. End Function
  120. Function UpLoad_Stream()
  121. FileSize=LenB(Stream)
  122. End Function
  123. Public Function UpLoad(bolAutoName)
  124. If UploadType="Form" Then
  125. Call UpLoad_Form()
  126. ElseIf UploadType="Stream" Then
  127. Call UpLoad_Stream()
  128. End If
  129. If bolAutoName=True Then
  130. End If
  131. Dim objStreamFile
  132. Set objStreamFile = Server.CreateObject("ADODB.Stream")
  133. objStreamFile.Type = adTypeBinary
  134. objStreamFile.Mode = adModeReadWrite
  135. objStreamFile.Open
  136. objStreamFile.Write Stream
  137. objStreamFile.SaveToFile FileName,adSaveCreateOverWrite
  138. objStreamFile.Close
  139. UpLoad=True
  140. End Function
  141. Public Function Del()
  142. Dim fso
  143. Set fso = CreateObject("Scripting.FileSystemObject")
  144. If fso.FileExists(FileName) Then
  145. fso.DeleteFile(FileName)
  146. End If
  147. Del=True
  148. End Function
  149. End Class
  150. '*********************************************************
  151. %>
  152. <!--以下是显示页面-->
  153. <%
  154. Action=Request.QueryString("act")
  155. SelectedPlugin=Request.QueryString("Plugin")
  156. SelectedPluginName=Request.QueryString("Pluginname")
  157. If SelectedPluginName = "" Then SelectedPluginName = SelectedPlugin
  158. If Action="" Then
  159. Call GetBlogHint()
  160. Response.Write "<div>"
  161. %>
  162. <form border="1" name="edit" id="edit" method="post" enctype="multipart/form-data" action="Xml_Upload.asp?act=FileUpload"><p>选择本地的 ZPI 插件安装包文件,TS 将从该文件导入插件并安装到 PLUGIN 目录下: </p><p><input type="file" id="edtFileLoad" name="edtFileLoad" size="25">  <input type="submit" class="button" value="提交" name="B1" /> <input class="button" type="reset" value="重置" name="B2" /> <input onclick="self.location.href='PluginList.asp'" type="button" class="button" value="返回插件管理" title="返回插件管理页" /></p>
  163. <br />
  164. </form>
  165. <p><a href="help.asp#aboutzpi" title="什么是 ZPI 插件安装包文件?">[什么是 ZPI 插件安装包文件?]</a></p>
  166. <%
  167. Response.Write "</div>"
  168. End If
  169. Dim Install_Error
  170. Install_Error=0
  171. Dim Install_Pack,Install_Path
  172. Install_Pack = BlogPath & "PLUGIN/Install.zpi"
  173. Install_Path = BlogPath & "PLUGIN/"
  174. '从本地上传
  175. If Action="FileUpload" Then
  176. Response.Write "<p id=""loading"">正在导入插件, 请稍候... 如果长时间停止响应, 请 <a href=""javascript:window.location.reload();"" title=""点此重试"">[点此重试]</a></p>"
  177. Response.Flush
  178. Response.Write "<p class=""status-box"">正在上传 ZPI 插件安装包文件... <img id=""status"" align=""absmiddle"" src=""images/loading.gif"" /></p>"
  179. Response.Flush
  180. Dim objUpLoadFile
  181. Set objUpLoadFile=New TUpLoadFile2
  182. objUpLoadFile.FileName=Install_Pack
  183. objUpLoadFile.Del
  184. If objUpLoadFile.Upload(false)=False Then
  185. Response.Write "<p><font color=""red""> × ZPI 文件上传失败.</font></p>"
  186. Response.Write "<script language=""JavaScript"" type=""text/javascript"">document.getElementById('status').style.display = 'none';</script>"
  187. Install_Error=Install_Error+1
  188. Else
  189. Response.Write "<p><font color=""green""> √ ZPI 文件 ""PluginS/Install.ZPI"" 已被保存到您的空间内.</font></p>"
  190. Response.Write "<script language=""JavaScript"" type=""text/javascript"">document.getElementById('status').style.display = 'none';</script>"
  191. Response.Flush
  192. End If
  193. Response.Write "<script language=""JavaScript"" type=""text/javascript"">try{document.getElementById('loading').style.display = 'none';}catch(e){};</script>"
  194. Set objUpLoadFile=Nothing
  195. Call Check_Install()
  196. Call Install_Plugin()
  197. End If
  198. If Action="continue" Then
  199. Call Install_Plugin()
  200. End If
  201. If Action="cancel" Then
  202. Call DeleteFile(Install_Pack)
  203. Response.Write "<p class=""status-box"">插件安装已取消. 如果您的浏览器没能自动跳转, 请 <a href=""xml_Upload.asp"">[点击这里]</a>.</p>"
  204. Response.Write "<script>setTimeout(""self.location.href='xml_Upload.asp'"",1000);</script>"
  205. End If
  206. '*********************************************************
  207. Sub Check_Install()
  208. On Error Resume Next
  209. Dim Alert
  210. Alert=False
  211. Response.Write "<p id=""loading2"">正在校验插件, 请稍候... 如果长时间停止响应, 请 <a href=""javascript:window.location.reload();"" title=""点此重试"">[点此重试]</a></p>"
  212. Response.Flush
  213. Set objXmlVerChk=New PluginSapper_CheckVersionViaXML
  214. objXmlVerChk.XmlDataWeb=(LoadFromFile(Install_Pack,"utf-8"))
  215. objXmlVerChk.XmlDataLocal=(LoadFromFile(BlogPath & "/PLUGIN/"& objXmlVerChk.Item_ID_Web &"/plugin.xml","utf-8"))
  216. If LCase(objXmlVerChk.Item_ID_Web)=LCase(objXmlVerChk.Item_ID_Local) Then
  217. Response.Write "<p class=""status-box"">您已安装了这个插件 <b>("& objXmlVerChk.Item_Name_Local &")</b>, 是否用 ZPI 文件里的插件 <b>("& objXmlVerChk.Item_Name_Web &")</b> <b>完全覆盖</b>已安装的插件?<br/><br/>"
  218. Response.Write "您当前插件版本为: <b>"& objXmlVerChk.Item_Version_Local &"</b>. 发布日期为: <b>"& objXmlVerChk.Item_PubDate_Local &"</b>. 最后修改日期为: <b>"& objXmlVerChk.Item_Modified_Local &"</b>.<br/>"
  219. Response.Write "将要覆盖的版本为: <b>"& objXmlVerChk.Item_Version_Web &"</b>. 发布日期为: <b>"& objXmlVerChk.Item_PubDate_Web &"</b>. 最后修改日期为: <b>"& objXmlVerChk.Item_Modified_Web &"</b><br/><br/>"
  220. If objXmlVerChk.Item_Url_Web<>Empty Then
  221. Response.Write "<a href="""& objXmlVerChk.Item_Url_Web &""" target=""_blank"" title=""查看插件的发布页面"">点此查看插件的发布信息!</a><br/><br/>"
  222. End If
  223. Response.Write objXmlVerChk.OutputResults & "<br/><br/>"
  224. Response.Write "<a href=""Xml_upload.asp?confirm=yes&amp;act=continue"" title=""确认安装"">[确认覆盖]</a> 或 <a href=""Xml_upload.asp?confirm=yes&amp;act=cancel"" title=""取消安装"">[取消]</a><p>"
  225. Alert=True
  226. End If
  227. Response.Write "<script language=""JavaScript"" type=""text/javascript"">try{document.getElementById('loading2').style.display = 'none';}catch(e){};</script>"
  228. Set objXmlVerChk=Nothing
  229. If Alert=True Then Response.End
  230. End Sub
  231. Sub Install_Plugin()
  232. On Error Resume Next
  233. Response.Write "<p id=""loading3"">正在解包插件, 请稍候... 如果长时间停止响应, 请 <a href=""javascript:window.location.reload();"" title=""点此重试"">[点此重试]</a></p>"
  234. Response.Flush
  235. Response.Write "<p class=""status-box"">ZPI 文件 ""PLUGIN/Install.zpi"" 正在解包安装...<p>"
  236. Response.Flush
  237. Dim objXmlFile
  238. Dim objNodeList
  239. Dim objFSO
  240. Dim objStream
  241. Dim i,j
  242. Set objXmlFile = Server.CreateObject("Microsoft.XMLDOM")
  243. objXmlFile.async = False
  244. objXmlFile.ValidateOnParse=False
  245. objXmlFile.load(Install_Pack)
  246. If objXmlFile.readyState<>4 Then
  247. Response.Write "<p><font color=""red""> × ZPI 文件未准备就绪, 无法解包.</font></p>"
  248. Install_Error=Install_Error+1
  249. Else
  250. If objXmlFile.parseError.errorCode <> 0 Then
  251. Response.Write "<p><font color=""red""> × ZPI 文件有错误, 无法解包.</font></p>"
  252. Install_Error=Install_Error+1
  253. Else
  254. Dim Pack_ver,Pack_Type,Pack_For,Pack_ID,Pack_Name
  255. Pack_Ver = objXmlFile.documentElement.SelectSingleNode("//root").getAttributeNode("version").value
  256. Pack_Type = objXmlFile.documentElement.selectSingleNode("//root").getAttributeNode("type").value
  257. Pack_For = objXmlFile.documentElement.selectSingleNode("//root").getAttributeNode("for").value
  258. Pack_ID = objXmlFile.documentElement.selectSingleNode("id").text
  259. Pack_Name = objXmlFile.documentElement.selectSingleNode("name").text
  260. If (CDbl(Pack_Ver) > CDbl(XML_Pack_Ver)) Then
  261. Response.Write "<p><font color=""red""> × ZPI 文件的 XML 版本为 "& Pack_Ver &", 而你的解包器版本为 "& XML_Pack_Ver &", 请升级您的 PluginSapper, 安装被中止.</font></p>"
  262. Install_Error=Install_Error+1
  263. ElseIf (LCase(Pack_Type) <> LCase(XML_Pack_Type)) Then
  264. Response.Write "<p><font color=""red""> × 不是 ZPI 文件, 而可能是 "& Pack_Type &", 安装被中止.</font></p>"
  265. Install_Error=Install_Error+1
  266. ElseIf (LCase(Pack_For) <> LCase(XML_Pack_Version)) Then
  267. Response.Write "<p><font color=""red""> × ZPI 文件版本不符合, 该版本可能是 "& Pack_For &", 安装被中止.</font></p>"
  268. Install_Error=Install_Error+1
  269. Else
  270. Response.Write "<blockquote><font color=""Teal"">"
  271. Set objNodeList = objXmlFile.documentElement.selectNodes("//folder/path")
  272. Set objFSO = CreateObject("Scripting.FileSystemObject")
  273. j=objNodeList.length-1
  274. For i=0 To j
  275. If objFSO.FolderExists(Install_Path & objNodeList(i).text)=False Then
  276. objFSO.CreateFolder(Install_Path & objNodeList(i).text)
  277. End If
  278. Response.Write "创建目录" & objNodeList(i).text & "<br/>"
  279. Response.Flush
  280. Next
  281. Set objFSO = Nothing
  282. Set objNodeList = Nothing
  283. Set objNodeList = objXmlFile.documentElement.selectNodes("//file/path")
  284. j=objNodeList.length-1
  285. For i=0 To j
  286. Set objStream = CreateObject("ADODB.Stream")
  287. With objStream
  288. .Type = 1
  289. .Open
  290. .Write objNodeList(i).nextSibling.nodeTypedvalue
  291. .SaveToFile Install_Path & objNodeList(i).text,2
  292. Response.Write "释放文件" & objNodeList(i).text & "<br/>"
  293. Response.Flush
  294. .Close
  295. End With
  296. Set objStream = Nothing
  297. Next
  298. Set objNodeList = Nothing
  299. Response.Write "</font></blockquote>"
  300. End If
  301. End If
  302. End If
  303. Set objXmlFile = Nothing
  304. If Err.Number<>0 Then Install_Error=Install_Error+1
  305. Err.Clear
  306. Response.Write "<p>"
  307. Install_Error = Install_Error + DeleteFile(Install_Pack)
  308. Response.Write "</p>"
  309. If Install_Error = 0 Then
  310. Response.Write "<p>"
  311. Install_Error = Install_Error + DeleteFile(BlogPath & "PLUGIN/" & Pack_ID & "/verchk.xml")
  312. Response.Write "</p>"
  313. End If
  314. Response.Flush
  315. If Install_Error = 0 Then
  316. Response.Write "<p class=""status-box""> √ 插件导入完成. 如果您的浏览器没能自动跳转, 请 <a href=""PluginDetail.asp?plugin=" & Server.URLEncode(Pack_ID) & "&amp;pluginname=" & Server.URLEncode(Pack_Name) & """>[点击这里]</a>.</p>"
  317. Response.Write "<script>setTimeout(""self.location.href='PluginDetail.asp?plugin=" & Server.URLEncode(Pack_ID) & "&pluginname=" & Server.URLEncode(Pack_Name) & "'"",3000);</script>"
  318. Else
  319. Response.Write "<p class=""status-box""><font color=""red""> × 插件导入失败. "
  320. Response.Write "请 <a href=""javascript:window.location.reload();"" title=""刷新此页""><span>[点此重试]</span></a> 或 <a href=""xml_Upload.asp"" title=""重新上传""><span>[重新上传]</span></a></font></p>"
  321. End If
  322. Response.Write "<script language=""JavaScript"" type=""text/javascript"">try{document.getElementById('loading3').style.display = 'none';}catch(e){};</script>"
  323. End Sub
  324. '*********************************************************
  325. %>
  326. </div>
  327. <script>
  328. </script>
  329. </body>
  330. </html>
  331. <%
  332. Call System_Terminate()
  333. If Err.Number<>0 then
  334.   Call ShowError(0)
  335. End If
  336. %>