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.

888 lines
32 KiB

  1. '
  2. ' Copyright (c) Microsoft Corporation. All rights reserved.
  3. '
  4. ' VBScript Source File
  5. '
  6. ' Script Name: IIsFtpDr.vbs
  7. '
  8. Option Explicit
  9. On Error Resume Next
  10. ' Error codes
  11. Const ERR_OK = 0
  12. Const ERR_GENERAL_FAILURE = 1
  13. '''''''''''''''''''''
  14. ' Messages
  15. Const L_FtpDir_Message = "Ftp directory %1 has been DELETED"
  16. Const L_InvalidPath_ErrorMessage = "Invalid site path."
  17. Const L_VPath_Message = "Virtual Path"
  18. Const L_Root_Message = "ROOT"
  19. Const L_MetabasePath_Message = "Metabase Path"
  20. Const L_AliasName_Text = "Alias"
  21. Const L_Path_Text = "Physical Root"
  22. Const L_Error_ErrorMessage = "Error &H%1: %2"
  23. Const L_VDirDel_ErrorMessage = "Could not delete ftp directory."
  24. Const L_CannotCreateDir_ErrorMessage = "Could not create root directory."
  25. Const L_DirFormat_ErrorMessage = "Root directory format unknown. Please use the"
  26. Const L_DirFormat2_ErrorMessage = "'<drive>:\<path>' format."
  27. Const L_OperationRequired_ErrorMessage = "Please specify an operation before the arguments."
  28. Const L_NotEnoughParam_ErrorMessage = "Not enough parameters."
  29. Const L_Query_ErrorMessage = "Error occurred while querying WMI provider."
  30. Const L_CmdLib_ErrorMessage = "Could not create an instance of the CmdLib object."
  31. Const L_ChkCmdLibReg_ErrorMessage = "Please register the Microsoft.CmdLib component."
  32. Const L_VDirExists1_ErrorMessage = "The FTP virtual directory %1 does not exist."
  33. Const L_VDirExists2_ErrorMessage = "The FTP virtual directory %1 already exists."
  34. Const L_VDirDoesntExist_ErrorMessage = "Virtual directory doesn't exist (%1)"
  35. Const L_OnlyOneOper_ErrorMessage = "Please specify only one operation at a time."
  36. Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the IIsScriptHelper object."
  37. Const L_ChkScpHelperReg_ErrorMessage = "Please register the Microsoft.IIsScriptHelper component."
  38. Const L_VDirsNotFound_ErrorMessage = "No virtual sub-directories available."
  39. Const L_SiteNotFound_ErrorMessage = "Could not find ftpsite %1"
  40. Const L_PassWithoutUser_ErrorMessage = "Please specify /u switch before using /p."
  41. Const L_WMIConnect_ErrorMessage = "Could not connect to WMI provider."
  42. Const L_MapDrive_ErrorMessage = "Could not map network drive."
  43. Const L_GetSetting_ErrorMessage = "Unable to get Setting class from IIS namespace."
  44. Const L_CannotDelRoot_ErrorMessage = "Cannot delete the ROOT virtual directory. Please specify"
  45. Const L_CannotDelRoot2_ErrorMessage = "another one."
  46. Const L_KeyIsntVDir_ErrorMessage = "Specified metabase path is not a virtual directory."
  47. Const L_CannotGetVDir_ErrorMessage = "Either the path specified does not exist or it is not an"
  48. Const L_CannotGetVDir2_ErrorMessage = "FTP virtual directory. Please make sure the path specified"
  49. Const L_CannotGetVDir3_ErrorMessage = "is valid."
  50. Const L_InvalidAlias_ErrorMessage = "Alias contains invalid character(s)."
  51. Const L_CannotGetParentVDir_ErrorMessage = "Error getting parent virtual directory."
  52. Const L_ParentVDirNotPresent_ErrorMessage = "Parent virtual directory doesn't exist."
  53. Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
  54. Const L_InvalidSwitch_ErrorMessage = "Invalid switch: %1"
  55. Const L_Admin_ErrorMessage = "You cannot run this command because you are not an"
  56. Const L_Admin2_ErrorMessage = "administrator on the server you are trying to configure."
  57. '''''''''''''''''''''
  58. ' Help
  59. ' General help messages
  60. Const L_SeeHelp_Message = "Type IIsFtpDr /? for help."
  61. Const L_SeeCreateHelp_Message = "Type IIsFtpDr /create /? for help."
  62. Const L_SeeDeleteHelp_Message = "Type IIsFtpDr /delete /? for help."
  63. Const L_SeeQueryHelp_Message = "Type IIsFtpDr /query /? for help."
  64. Const L_Help_HELP_General01_Text = "Description: Create, delete, or query a ftp directory"
  65. Const L_Help_HELP_General02_Text = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]]"
  66. Const L_Help_HELP_General03_Text = " /<operation> [arguments]"
  67. Const L_Help_HELP_General04_Text = "Parameters:"
  68. Const L_Help_HELP_General06_Text = "Value Description"
  69. Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server>"
  70. Const L_Help_HELP_General07a_Text = " [Default: this system]"
  71. Const L_Help_HELP_General08_Text = "/u <username> Connect as <domain>\<username> or"
  72. Const L_Help_HELP_General09_Text = " <username> [Default: current user]"
  73. Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user"
  74. Const L_Help_HELP_General11_Text = "<operation> /create Creates a ftp virtual directory"
  75. Const L_Help_HELP_General12_Text = " on a specified ftp site."
  76. Const L_Help_HELP_General13_Text = " /delete Deletes a ftp virtual directory"
  77. Const L_Help_HELP_General14_Text = " from a specified ftp site."
  78. Const L_Help_HELP_General15_Text = " /query Lists all virtual directories"
  79. Const L_Help_HELP_General16_Text = " under the specified path."
  80. Const L_Help_HELP_General17_Text = "For detailed usage:"
  81. Const L_Help_HELP_General18_Text = "IIsFtpDr /create /?"
  82. Const L_Help_HELP_General19_Text = "IIsFtpDr /delete /?"
  83. Const L_Help_HELP_General20_Text = "IIsFtpDr /query /?"
  84. ' Common to all status change commands
  85. Const L_Help_HELP_Common03_Text = "Parameters:"
  86. Const L_Help_HELP_Common09_Text = "<ftpsite> Use either the site name or metabase"
  87. Const L_Help_HELP_Common09p1_Text = " path to specify the site. (""Default"
  88. Const L_Help_HELP_Common09p2_Text = " Ftp Site"" or msftpsvc/1)"
  89. Const L_Help_HELP_Common10_Text = "<path> Virtual path for the new virtual"
  90. Const L_Help_HELP_Common10p1_Text = " directory's parent. This virtual"
  91. Const L_Help_HELP_Common10p2_Text = " path must already exist."
  92. Const L_Help_HELP_Common11_Text = "Examples:"
  93. ' Delete help messages
  94. Const L_Help_HELP_Delete01_Text = "Description: Deletes a ftp virtual directory from a"
  95. Const L_Help_HELP_Delete01p1_Text = " specified ftp site."
  96. Const L_Help_HELP_Delete02_Text = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]]"
  97. Const L_Help_HELP_Delete02p1_Text = " /delete <ftpsite>[/path]<alias>"
  98. Const L_Help_HELP_Delete11_Text = "IIsFtpDr /delete ""My Site""/Mydir"
  99. Const L_Help_HELP_Delete12_Text = "IIsFtpDr /delete msftpsvc/1/ROOT/Users/Public/Mydir"
  100. Const L_Help_HELP_Delete13_Text = "IIsFtpDr /s Server1 /u Administrator /p p@ssWOrd /delete ""My Site""/Mydir"
  101. ' Query help messages
  102. Const L_Help_HELP_Query01_Text = "Description: Lists all virtual directories under a given"
  103. Const L_Help_HELP_Query01p1_Text = " path."
  104. Const L_Help_HELP_Query02_Text = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]] /query"
  105. Const L_Help_HELP_Query02p1_Text = " <ftpsite>[/path]"
  106. Const L_Help_HELP_Query11_Text = "IIsFtpDr /query ""My Site"""
  107. Const L_Help_HELP_Query12_Text = "IIsFtpDr /query msftpsvc/1/ROOT"
  108. Const L_Help_HELP_Query13_Text = "IIsFtpDr /query ""My Site""/Users/Public"
  109. Const L_Help_HELP_Query14_Text = "IIsFtpDr /s Server1 /u Administrator /p p@ssWOrd /query ""My Site""/Users"
  110. ' Create help messages
  111. Const L_Help_HELP_Create01_Text = "Description: Creates a ftp virtual directory on a specified"
  112. Const L_Help_HELP_Create01p1_Text = " ftp site."
  113. Const L_Help_HELP_Create02_Text = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]]"
  114. Const L_Help_HELP_Create02p1_Text = " /create <ftpsite>[/path] <alias> <root>"
  115. Const L_Help_HELP_Create11_Text = "<alias> The name of the virtual directory"
  116. Const L_Help_HELP_Create12_Text = "<root> Physical path of the virtual"
  117. Const L_Help_HELP_Create12p1_Text = " directory. If the physical path does"
  118. Const L_Help_HELP_Create12p2_Text = " not exist, it will be created."
  119. Const L_Help_HELP_Create15_Text = "IIsFtpDr /create ""My Site"" Mydir c:\mydir"
  120. Const L_Help_HELP_Create16_Text = "IIsFtpDr /create msftpsvc/1/ROOT MyDir c:\mydir"
  121. Const L_Help_HELP_Create17_Text = "IIsFtpDr /create ""My Site""/Users/Public Mydir c:\mydir"
  122. Const L_Help_HELP_Create18_Text = "IIsFtpDr /s Server1 /u Administrator /p p@assWOrd /create ""My Site"" Mydir"
  123. Const L_Help_HELP_Create19_Text = " c:\mydir"
  124. ''''''''''''''''''''''''
  125. ' Operation codes
  126. Const OPER_DELETE = 1
  127. Const OPER_CREATE = 2
  128. Const OPER_QUERY = 3
  129. '
  130. ' Main block
  131. '
  132. Dim oScriptHelper, oCmdLib
  133. Dim strServer, strUser, strPassword, strSite
  134. Dim strPath, strVPath, strAlias, strRoot
  135. Dim intOperation, intResult
  136. Dim aArgs, arg
  137. Dim strCmdLineOptions
  138. Dim oError
  139. ' Default values
  140. strServer = "."
  141. strUser = ""
  142. strPassword = ""
  143. intOperation = 0
  144. strSite = ""
  145. strPath = ""
  146. ' Instantiate the CmdLib for output string formatting
  147. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  148. If Err.Number <> 0 Then
  149. WScript.Echo L_CmdLib_ErrorMessage
  150. WScript.Echo L_ChkCmdLibReg_ErrorMessage
  151. WScript.Quit(ERR_GENERAL_FAILURE)
  152. End If
  153. Set oCmdLib.ScriptingHost = WScript.Application
  154. ' Instantiate script helper object
  155. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  156. If Err.Number <> 0 Then
  157. WScript.Echo L_ScriptHelper_ErrorMessage
  158. WScript.Echo L_ChkScpHelperReg_ErrorMessage
  159. WScript.Quit(ERR_GENERAL_FAILURE)
  160. End If
  161. Set oScriptHelper.ScriptHost = WScript
  162. ' Check if we are being run with cscript.exe instead of wscript.exe
  163. oScriptHelper.CheckScriptEngine
  164. ' Minimum number of parameters must exist
  165. If WScript.Arguments.Count < 1 Then
  166. WScript.Echo L_NotEnoughParam_ErrorMessage
  167. WScript.Echo L_SeeHelp_Message
  168. WScript.Quit(ERR_GENERAL_FAILURE)
  169. End If
  170. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];delete:d:1;create:c:3;query:q:1"
  171. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  172. If Not oError Is Nothing Then
  173. If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  174. ' Not enough arguments for a specified switch
  175. WScript.Echo L_NotEnoughParams_ErrorMessage
  176. Select Case LCase(oError.SwitchName)
  177. Case "create"
  178. WScript.Echo L_SeeCreateHelp_Message
  179. Case "delete"
  180. WScript.Echo L_SeeDeleteHelp_Message
  181. Case "query"
  182. WScript.Echo L_SeeQueryHelp_Message
  183. Case Else
  184. WScript.Echo L_SeeHelp_Message
  185. End Select
  186. Else
  187. ' Invalid switch
  188. oCmdLib.vbPrintf L_InvalidSwitch_ErrorMessage, Array(oError.SwitchName)
  189. WScript.Echo L_SeeHelp_Message
  190. End If
  191. WScript.Quit(ERR_GENERAL_FAILURE)
  192. End If
  193. If oScriptHelper.GlobalHelpRequested Then
  194. DisplayHelpMessage
  195. WScript.Quit(ERR_OK)
  196. End If
  197. For Each arg In oScriptHelper.Switches
  198. Select Case arg
  199. Case "server"
  200. ' Server information
  201. strServer = oScriptHelper.GetSwitch(arg)
  202. Case "user"
  203. ' User information
  204. strUser = oScriptHelper.GetSwitch(arg)
  205. Case "password"
  206. ' Password information
  207. strPassword = oScriptHelper.GetSwitch(arg)
  208. Case "create"
  209. If (intOperation <> 0) Then
  210. WScript.Echo L_OnlyOneOper_ErrorMessage
  211. WScript.Echo L_SeeHelp_Message
  212. WScript.Quit(ERR_GENERAL_FAILURE)
  213. End If
  214. intOperation = OPER_CREATE
  215. If oScriptHelper.IsHelpRequested(arg) Then
  216. DisplayCreateHelpMessage
  217. WScript.Quit(ERR_OK)
  218. End If
  219. aArgs = oScriptHelper.GetSwitch(arg)
  220. strVPath = aArgs(0)
  221. strAlias = aArgs(1)
  222. strRoot = aArgs(2)
  223. Case "delete"
  224. If (intOperation <> 0) Then
  225. WScript.Echo L_OnlyOneOper_ErrorMessage
  226. WScript.Echo L_SeeHelp_Message
  227. WScript.Quit(ERR_GENERAL_FAILURE)
  228. End If
  229. intOperation = OPER_DELETE
  230. If oScriptHelper.IsHelpRequested(arg) Then
  231. DisplayDeleteHelpMessage
  232. WScript.Quit(ERR_OK)
  233. End If
  234. strPath = oScriptHelper.GetSwitch(arg)
  235. Case "query"
  236. If (intOperation <> 0) Then
  237. WScript.Echo L_OnlyOneOper_ErrorMessage
  238. WScript.Echo L_SeeHelp_Message
  239. WScript.Quit(ERR_GENERAL_FAILURE)
  240. End If
  241. intOperation = OPER_QUERY
  242. If oScriptHelper.IsHelpRequested(arg) Then
  243. DisplayQueryHelpMessage
  244. WScript.Quit(ERR_OK)
  245. End If
  246. strPath = oScriptHelper.GetSwitch(arg)
  247. End Select
  248. Next
  249. ' Check Parameters
  250. If (intOperation = 0) Then
  251. WScript.Echo L_OperationRequired_ErrorMessage
  252. WScript.Echo L_SeeHelp_Message
  253. WScript.Quit(ERR_GENERAL_FAILURE)
  254. End If
  255. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  256. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  257. WScript.Echo L_PassWithoutUser_ErrorMessage
  258. WScript.Quit(ERR_GENERAL_FAILURE)
  259. End If
  260. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  261. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  262. strPassword = oCmdLib.GetPassword
  263. End If
  264. ' Initializes authentication with remote machine
  265. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  266. If intResult <> 0 Then
  267. WScript.Quit(intResult)
  268. End If
  269. ' Choose operation
  270. Select Case intOperation
  271. Case OPER_CREATE
  272. intResult = CreateFtpVDir(strVPath, strAlias, strRoot)
  273. Case OPER_DELETE
  274. intResult = DeleteFtpVDir(strPath)
  275. Case OPER_QUERY
  276. intResult = QueryFtpVDir(strPath)
  277. End Select
  278. ' Return value to command processor
  279. WScript.Quit(intResult)
  280. '''''''''''''''''''''''''
  281. ' End Of Main Block
  282. '''''''''''''''''''''
  283. '''''''''''''''''''''''''''
  284. ' ParseSitePath
  285. '''''''''''''''''''''''''''
  286. Function ParseSitePath(strSitePath)
  287. Dim iFirstSlash, iSecondSlash, iIndex
  288. Dim strSite, strPath
  289. Dim aPath, aFtpSites
  290. On Error Resume Next
  291. ' Replace any existing back-slashes with forward-slashes
  292. strSitePath = Replace(strSitePath, "\", "/")
  293. aPath = Split(strSitePath, "/", -1)
  294. ' Fills strPath
  295. If (UCase(aPath(0)) = "MSFTPSVC") Then
  296. ' First argument is a metabase path
  297. If (UBound(aPath) < 1) Then
  298. WScript.Echo L_InvalidPath_ErrorMessage
  299. WScript.Quit(ERR_GENERAL_FAILURE)
  300. End If
  301. ' Second array element must be a number (site ID)
  302. If Not IsNumeric(aPath(1)) Then
  303. WScript.Echo L_InvalidPath_ErrorMessage
  304. WScript.Quit(ERR_GENERAL_FAILURE)
  305. End If
  306. ' Second element of aPath should be the site number so ...
  307. strPath = "MSFTPSVC/" & aPath(1)
  308. ' Call FindFtpSite to make sure ftp site exists
  309. aFtpSites = oScriptHelper.FindSite("Ftp", Array(strPath))
  310. If IsArray(aFtpSites) Then
  311. If UBound(aFtpSites) = -1 Then
  312. oCmdLib.vbPrintf L_SiteNotFound_ErrorMessage, Array(strPath)
  313. ParseSitePath = Empty
  314. Exit Function
  315. End If
  316. End If
  317. strPath = strPath & "/ROOT"
  318. strSitePath = strPath
  319. ' Check for ROOT string and grab the rest for strPath
  320. iIndex = 1
  321. If (UBound(aPath) > 1) Then
  322. If (UCase(aPath(2)) = "ROOT") Then
  323. iIndex = 2
  324. End If
  325. End If
  326. Else
  327. ' First argument is a site name (server comment property)
  328. ' Call FindFtpSite to resolve site name to metabase path
  329. aFtpSites = oScriptHelper.FindSite("Ftp", Array(aPath(0)))
  330. If IsArray(aFtpSites) Then
  331. If UBound(aFtpSites) = -1 Then
  332. oCmdLib.vbPrintf L_SiteNotFound_ErrorMessage, Array(aPath(0))
  333. ParseSitePath = Empty
  334. Exit Function
  335. Else
  336. strPath = aFtpSites(0)
  337. End If
  338. Else
  339. ' Got duplicate sites. We should quit.
  340. ParseSitePath = Empty
  341. Exit Function
  342. End If
  343. strPath = strPath & "/ROOT"
  344. strSitePath = aPath(0) & "/ROOT"
  345. ' Check for ROOT string and grab the rest for strPath
  346. iIndex = 0
  347. If (UBound(aPath) > 0) Then
  348. If (UCase(aPath(1)) = "ROOT") Then
  349. iIndex = 1
  350. End If
  351. End If
  352. End If
  353. ' Build strPath
  354. iIndex = iIndex + 1
  355. Do While iIndex <= UBound(aPath)
  356. If (aPath(iIndex) = "") Then
  357. Exit Do
  358. End If
  359. strPath = strPath & "/" & aPath(iIndex)
  360. strSitePath = strSitePath & "/" & aPath(iIndex)
  361. iIndex = iIndex + 1
  362. Loop
  363. ParseSitePath = strPath
  364. End Function
  365. '''''''''''''''''''''''''''
  366. ' DisplayHelpMessage
  367. '''''''''''''''''''''''''''
  368. Sub DisplayHelpMessage()
  369. WScript.Echo L_Help_HELP_General01_Text
  370. WScript.Echo
  371. WScript.Echo L_Help_HELP_General02_Text
  372. WScript.Echo L_Help_HELP_General03_Text
  373. WScript.Echo
  374. WScript.Echo L_Help_HELP_General04_Text
  375. WScript.Echo
  376. WScript.Echo L_Help_HELP_General06_Text
  377. WScript.Echo L_Help_HELP_General07_Text
  378. WScript.Echo L_Help_HELP_General07a_Text
  379. WScript.Echo L_Help_HELP_General08_Text
  380. WScript.Echo L_Help_HELP_General09_Text
  381. WScript.Echo L_Help_HELP_General10_Text
  382. WScript.Echo L_Help_HELP_General11_Text
  383. WScript.Echo L_Help_HELP_General12_Text
  384. WScript.Echo L_Help_HELP_General13_Text
  385. WScript.Echo L_Help_HELP_General14_Text
  386. WScript.Echo L_Help_HELP_General15_Text
  387. WScript.Echo L_Help_HELP_General16_Text
  388. WScript.Echo
  389. WScript.Echo L_Help_HELP_General17_Text
  390. WScript.Echo
  391. WScript.Echo L_Help_HELP_General18_Text
  392. WScript.Echo L_Help_HELP_General19_Text
  393. WScript.Echo L_Help_HELP_General20_Text
  394. End Sub
  395. Sub DisplayDeleteHelpMessage()
  396. WScript.Echo L_Help_HELP_Delete01_Text
  397. WScript.Echo L_Help_HELP_Delete01p1_Text
  398. WScript.Echo
  399. WScript.Echo L_Help_HELP_Delete02_Text
  400. WScript.Echo L_Help_HELP_Delete02p1_Text
  401. WScript.Echo
  402. WScript.Echo L_Help_HELP_Common03_Text
  403. WScript.Echo
  404. WScript.Echo L_Help_HELP_General06_Text
  405. WScript.Echo L_Help_HELP_General07_Text
  406. WScript.Echo L_Help_HELP_General07a_Text
  407. WScript.Echo L_Help_HELP_General08_Text
  408. WScript.Echo L_Help_HELP_General09_Text
  409. WScript.Echo L_Help_HELP_General10_Text
  410. WScript.Echo L_Help_HELP_Common09_Text
  411. WScript.Echo L_Help_HELP_Common09p1_Text
  412. WScript.Echo L_Help_HELP_Common09p2_Text
  413. WScript.Echo L_Help_HELP_Common10_Text
  414. WScript.Echo L_Help_HELP_Common10p1_Text
  415. WScript.Echo L_Help_HELP_Common10p2_Text
  416. WScript.Echo
  417. WScript.Echo L_Help_HELP_Common11_Text
  418. WScript.Echo
  419. WScript.Echo L_Help_HELP_Delete11_Text
  420. WScript.Echo L_Help_HELP_Delete12_Text
  421. WScript.Echo L_Help_HELP_Delete13_Text
  422. End Sub
  423. Sub DisplayCreateHelpMessage()
  424. WScript.Echo L_Help_HELP_Create01_Text
  425. WScript.Echo L_Help_HELP_Create01p1_Text
  426. WScript.Echo
  427. WScript.Echo L_Help_HELP_Create02_Text
  428. WScript.Echo L_Help_HELP_Create02p1_Text
  429. WScript.Echo
  430. WScript.Echo L_Help_HELP_Common03_Text
  431. WScript.Echo
  432. WScript.Echo L_Help_HELP_General06_Text
  433. WScript.Echo L_Help_HELP_General07_Text
  434. WScript.Echo L_Help_HELP_General07a_Text
  435. WScript.Echo L_Help_HELP_General08_Text
  436. WScript.Echo L_Help_HELP_General09_Text
  437. WScript.Echo L_Help_HELP_General10_Text
  438. WScript.Echo L_Help_HELP_Common09_Text
  439. WScript.Echo L_Help_HELP_Common09p1_Text
  440. WScript.Echo L_Help_HELP_Common09p2_Text
  441. WScript.Echo L_Help_HELP_Common10_Text
  442. WScript.Echo L_Help_HELP_Common10p1_Text
  443. WScript.Echo L_Help_HELP_Common10p2_Text
  444. WScript.Echo L_Help_HELP_Create11_Text
  445. WScript.Echo L_Help_HELP_Create12_Text
  446. WScript.Echo L_Help_HELP_Create12p1_Text
  447. WScript.Echo L_Help_HELP_Create12p2_Text
  448. WScript.Echo
  449. WScript.Echo L_Help_HELP_Common11_Text
  450. WScript.Echo
  451. WScript.Echo L_Help_HELP_Create15_Text
  452. WScript.Echo L_Help_HELP_Create16_Text
  453. WScript.Echo L_Help_HELP_Create17_Text
  454. WScript.Echo L_Help_HELP_Create18_Text
  455. WScript.Echo L_Help_HELP_Create19_Text
  456. End Sub
  457. Sub DisplayQueryHelpMessage()
  458. WScript.Echo L_Help_HELP_Query01_Text
  459. WScript.Echo L_Help_HELP_Query01p1_Text
  460. WScript.Echo
  461. WScript.Echo L_Help_HELP_Query02_Text
  462. WScript.Echo L_Help_HELP_Query02p1_Text
  463. WScript.Echo
  464. WScript.Echo L_Help_HELP_Common03_Text
  465. WScript.Echo
  466. WScript.Echo L_Help_HELP_General06_Text
  467. WScript.Echo L_Help_HELP_General07_Text
  468. WScript.Echo L_Help_HELP_General07a_Text
  469. WScript.Echo L_Help_HELP_General08_Text
  470. WScript.Echo L_Help_HELP_General09_Text
  471. WScript.Echo L_Help_HELP_General10_Text
  472. WScript.Echo L_Help_HELP_Common09_Text
  473. WScript.Echo L_Help_HELP_Common09p1_Text
  474. WScript.Echo L_Help_HELP_Common09p2_Text
  475. WScript.Echo L_Help_HELP_Common10_Text
  476. WScript.Echo L_Help_HELP_Common10p1_Text
  477. WScript.Echo L_Help_HELP_Common10p2_Text
  478. WScript.Echo
  479. WScript.Echo L_Help_HELP_Common11_Text
  480. WScript.Echo
  481. WScript.Echo L_Help_HELP_Query11_Text
  482. WScript.Echo L_Help_HELP_Query12_Text
  483. WScript.Echo L_Help_HELP_Query13_Text
  484. WScript.Echo L_Help_HELP_Query14_Text
  485. End Sub
  486. '''''''''''''''''''''''''''
  487. ' DeleteFtpVDir
  488. '''''''''''''''''''''''''''
  489. Function DeleteFtpVDir(strVPath)
  490. Dim strPath, ServiceObj
  491. Dim rootVDirObj, providerObj
  492. On Error Resume Next
  493. oScriptHelper.WMIConnect
  494. If Err.Number Then
  495. WScript.Echo L_WMIConnect_ErrorMessage
  496. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  497. ChangeFtpSiteStatus = Err.Number
  498. Exit Function
  499. End If
  500. Set providerObj = oScriptHelper.ProviderObj
  501. ' Quick check to see if we have permission
  502. Set ServiceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  503. If Err.Number Then
  504. Select Case Err.Number
  505. Case &H80070005
  506. WScript.Echo L_Admin_ErrorMessage
  507. WScript.Echo L_Admin2_ErrorMessage
  508. Case Else
  509. WScript.Echo Err.Description
  510. End Select
  511. DeleteFtpVDir = Err.Number
  512. Exit Function
  513. End If
  514. strPath = ParseSitePath(strVPath)
  515. If IsEmpty(strPath) Then
  516. ' Got problems parsing the path
  517. WScript.Echo L_SeeDeleteHelp_Message
  518. DeleteFtpVDir = ERR_GENERAL_FAILURE
  519. Exit Function
  520. End If
  521. ' Don't delete ROOT Vdir
  522. If UCase(Right(strPath, 5)) = "/ROOT" Then
  523. WScript.Echo L_CannotDelRoot_ErrorMessage
  524. WScript.Echo L_CannotDelRoot2_ErrorMessage
  525. DeleteFtpVDir = ERR_GENERAL_FAILURE
  526. Exit Function
  527. End If
  528. ' Check vdir existance
  529. Set rootVDirObj = providerObj.Get("IIsFtpVirtualDir='" & strPath & "'")
  530. If Err.Number Then
  531. Select Case Err.Number
  532. Case &H80041002
  533. oCmdLib.vbPrintf L_VDirDoesntExist_ErrorMessage, Array(strVPath)
  534. Case &H8004103A
  535. WScript.Echo L_KeyIsntVDir_ErrorMessage
  536. Case Else
  537. oCmdLib.vbPrintf L_VDirExists1_ErrorMessage, Array(strVPath)
  538. WScript.Echo L_CannotGetVDir_ErrorMessage
  539. WScript.Echo L_CannotGetVDir2_ErrorMessage
  540. WScript.Echo L_CannotGetVDir3_ErrorMessage
  541. End Select
  542. DeleteFtpVDir = Err.Number
  543. Exit Function
  544. End If
  545. rootVDirObj.Delete_()
  546. If Err.Number Then
  547. WScript.Echo L_VDirDel_ErrorMessage
  548. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  549. DeleteFtpVDir = Err.Number
  550. Exit Function
  551. End If
  552. oCmdLib.vbPrintf L_FtpDir_Message, Array(strVPath)
  553. DeleteFtpVDir = ERR_OK
  554. End Function
  555. '''''''''''''''''''''''''''
  556. ' CreateFtpVDir
  557. '''''''''''''''''''''''''''
  558. Function CreateFtpVDir(strVPath, strAlias, strRoot)
  559. Dim strPath, strStatus, strNewVdir, strRootVDir
  560. Dim vdirClassObj, serverObj, vdirObj, providerObj
  561. Dim intResult, ServiceObj
  562. On Error Resume Next
  563. ' Parse Alias for correctness
  564. If InStr(strAlias, "/") <> 0 Or InStr(strAlias, "\") <> 0 Then
  565. WScript.Echo L_InvalidAlias_ErrorMessage
  566. WScript.Echo L_SeeCreateHelp_Message
  567. CreateWebVDir = ERR_GENERAL_FAILURE
  568. Exit Function
  569. End If
  570. oScriptHelper.WMIConnect
  571. If Err.Number Then
  572. WScript.Echo L_WMIConnect_ErrorMessage
  573. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  574. CreateFtpVDir = Err.Number
  575. Exit Function
  576. End If
  577. Set providerObj = oScriptHelper.ProviderObj
  578. ' Quick check to see if we have permission
  579. Set ServiceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  580. If Err.Number Then
  581. Select Case Err.Number
  582. Case &H80070005
  583. WScript.Echo L_Admin_ErrorMessage
  584. WScript.Echo L_Admin2_ErrorMessage
  585. Case Else
  586. WScript.Echo Err.Description
  587. End Select
  588. CreateFtpVDir = Err.Number
  589. Exit Function
  590. End If
  591. ' Extract options from array to the correspondent variables
  592. strPath = ParseSitePath(strVPath)
  593. If IsEmpty(strPath) Then
  594. ' Got problems parsing the path
  595. WScript.Echo L_SeeCreateHelp_Message
  596. CreateFtpVDir = ERR_GENERAL_FAILURE
  597. Exit Function
  598. End If
  599. ' Build new vdir name
  600. strNewVdir = strPath & "/" & strAlias
  601. ' Check if vdir already exists
  602. Set vdirObj = providerObj.Get("IIsFtpVirtualDirSetting='" & strNewVdir & "'")
  603. If Err.Number = 0 Then
  604. oCmdLib.vbPrintf L_VDirExists2_ErrorMessage, Array(strNewVdir)
  605. CreateFtpVDir = ERR_GENERAL_FAILURE
  606. Exit Function
  607. End If
  608. Err.Clear
  609. ' Check if parent vdir exists
  610. ' We need to do this because FTP doesn't have the concept similar to a WebDirectory
  611. Set vdirObj = providerObj.Get("IIsFtpVirtualDirSetting='" & strPath & "'")
  612. If Err.Number Then
  613. Select Case Err.Number
  614. Case &H80041002
  615. WScript.Echo L_ParentVDirNotPresent_ErrorMessage
  616. Case Else
  617. WScript.Echo L_CannotGetParentVDir_ErrorMessage
  618. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  619. End Select
  620. CreateFtpVDir = Err.Number
  621. Exit Function
  622. End If
  623. ' Create physical directory
  624. oScriptHelper.CreateFSDir strRoot
  625. If Err.Number Then
  626. Select Case Err.Number
  627. Case &H8007000C
  628. WScript.Echo L_DirFormat_ErrorMessage
  629. WScript.Echo L_DirFormat2_ErrorMessage
  630. WScript.Echo L_SeeCreateHelp_Message
  631. Case &H8007000F
  632. WScript.Echo L_MapDrive_ErrorMessage
  633. Case Else
  634. WScript.Echo L_CannotCreateDir_ErrorMessage
  635. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  636. End Select
  637. CreateFtpVDir = Err.Number
  638. Exit Function
  639. End If
  640. ' Remove trailing slash (if present)
  641. If (Right(strRoot, 1) = "\") Then
  642. strRoot = Left(strRoot, Len(strRoot) - 1)
  643. End If
  644. ' Create new ftp virtual directory
  645. Set vdirClassObj = providerObj.Get("IIsFtpVirtualDirSetting")
  646. Set vdirObj = vdirClassObj.SpawnInstance_()
  647. vdirObj.Name = strNewVdir
  648. vdirObj.Path = strRoot
  649. ' Set ftp virtual directory properties
  650. vdirObj.AccessFlags = 1 ' read access
  651. vdirObj.Put_()
  652. ' Remove trailing slash (if present)
  653. If (Right(strVPath, 1) = "/") Then
  654. strVPath = Left(strVPath, Len(strVPath) - 1)
  655. End If
  656. If (strServer = ".") Then
  657. strServer = oScriptHelper.GetEnvironmentVar("%COMPUTERNAME%")
  658. End If
  659. ' Post summary
  660. WScript.Echo L_Server_Message & Space(14 - Len(L_Server_Message)) & "= " & UCase(strServer)
  661. WScript.Echo L_VPath_Message & Space(14 - Len(L_VPath_Message)) & "= " & strVPath & "/" & strAlias
  662. WScript.Echo L_Root_Message & Space(14 - Len(L_Root_Message)) & "= " & strRoot
  663. WScript.Echo L_MetabasePath_Message & Space(14 - Len(L_MetabasePath_Message)) & "= " & strNewVdir
  664. CreateFtpVDir = intResult
  665. End Function
  666. '''''''''''''''''''''''''''
  667. ' Helper Functions
  668. '''''''''''''''''''''''''''
  669. '''''''''''''''''''''''''''
  670. ' QueryFtpVDir
  671. '''''''''''''''''''''''''''
  672. Function QueryFtpVDir(strVDir)
  673. Dim Servers, Server, strQuery
  674. Dim bFirstIteration, ServiceObj
  675. Dim vdirObj, providerObj
  676. Dim strServer, strPath, strVDirName
  677. Dim firstLen
  678. On Error Resume Next
  679. oScriptHelper.WMIConnect
  680. If Err.Number Then
  681. WScript.Echo L_WMIConnect_ErrorMessage
  682. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  683. QueryFtpVDir = Err.Number
  684. Exit Function
  685. End If
  686. Set providerObj = oScriptHelper.ProviderObj
  687. ' Quick check to see if we have permission
  688. Set ServiceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  689. If Err.Number Then
  690. Select Case Err.Number
  691. Case &H80070005
  692. WScript.Echo L_Admin_ErrorMessage
  693. WScript.Echo L_Admin2_ErrorMessage
  694. Case Else
  695. WScript.Echo Err.Description
  696. End Select
  697. QueryFtpVDir = Err.Number
  698. Exit Function
  699. End If
  700. strPath = ParseSitePath(strVDir)
  701. If IsEmpty(strPath) Then
  702. ' Got problems parsing the path
  703. WScript.Echo L_SeeQueryHelp_Message
  704. QueryFtpVDir = ERR_GENERAL_FAILURE
  705. Exit Function
  706. End If
  707. ' Semi-sync query. (flags = ForwardOnly Or ReturnImediately = &H30)
  708. strQuery = "ASSOCIATORS OF {IIsFtpVirtualDir=""" & strPath & """} WHERE ResultClass = IIsFtpVirtualDir " & _
  709. "ResultRole = PartComponent"
  710. Set Servers = providerObj.ExecQuery(strQuery, , &H30)
  711. If (Err.Number <> 0) Then
  712. WScript.Echo L_Query_ErrorMessage
  713. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  714. QueryFtpVDir = Err.Number
  715. Exit Function
  716. End If
  717. bFirstIteration = True
  718. For Each Server in Servers
  719. If Server.Name = "" Then
  720. WScript.Echo L_CannotGetVDir_ErrorMessage
  721. WScript.Echo L_CannotGetVDir2_ErrorMessage
  722. WScript.Echo L_CannotGetVDir3_ErrorMessage
  723. Exit Function
  724. End If
  725. If bFirstIteration Then
  726. WScript.Echo L_AliasName_Text & Space(25 - Len(L_AliasName_Text)) & L_Path_Text
  727. WScript.Echo "=============================================================================="
  728. End If
  729. Set vdirObj = providerObj.get("IIsFtpVirtualDirSetting=""" & Server.Name & """")
  730. If (Err.Number <> 0) Then
  731. WScript.Echo L_GetSetting_ErrorMessage
  732. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  733. QueryFtpVDir = Err.Number
  734. Exit Function
  735. End If
  736. ' If this is the first binding list, print server comment and server name
  737. strVDirName = Replace(vdirObj.Name, strPath, "") ', , , vbTextCompare)
  738. firstLen = 25 - Len(strVDirName)
  739. If (firstLen < 1) Then
  740. firstLen = 1
  741. End If
  742. WScript.Echo strVDirName & Space(firstLen) & vdirObj.Path
  743. bFirstIteration = False
  744. Next
  745. If bFirstIteration Then
  746. WScript.Echo L_VDirsNotFound_ErrorMessage
  747. End If
  748. QueryFtpVDir = ERR_OK
  749. End Function