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.

1521 lines
59 KiB

  1. '
  2. ' Copyright (c) Microsoft Corporation. All rights reserved.
  3. '
  4. ' VBScript Source File
  5. '
  6. ' Script Name: IIsFtp.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_BindingConflict_ErrorMessage = "(ERROR: BINDING CONFLICT)"
  16. Const L_SitesNotFound_ErrorMessage = "Site(s) not found."
  17. Const L_IsAlready_Message = "Server %1 is already %2"
  18. Const L_HasBeen_Message = "Server %1 has been %2"
  19. Const L_GetAD_Message = "The value of %1 for user %2 is:"
  20. Const L_SetAD_Message = "The value of %1 for user %2 has been set to %3"
  21. Const L_All_Text = "ALL"
  22. Const L_AllUnassigned_Text = "ALL UNASSIGNED"
  23. Const L_NotSpecified_Text = "NOT SPECIFIED"
  24. Const L_NoISO_Text = "None"
  25. Const L_Server_Text = "Server"
  26. Const L_SiteName_Text = "Site Name"
  27. Const L_MetabasePath_Message = "Metabase Path"
  28. Const L_IP_Text = "IP"
  29. Const L_Port_Text = "Port"
  30. Const L_Root_Text = "Root"
  31. Const L_ISO_Text = "IsoMode"
  32. Const L_Status_Text = "Status"
  33. Const L_NA_Text = "N/A"
  34. Const L_UnexpectedState_ErrorMessage = "Unexpected state"
  35. Const L_Error_ErrorMessage = "Error &H%1: %2"
  36. Const L_GetRoot_ErrorMessage = "Could not obtaing ROOT virtual dir of site"
  37. Const L_SiteGet_ErrorMessage = "Could not obtain ftp site %1"
  38. Const L_Stop_ErrorMessage = "Could not stop ftp site %1"
  39. Const L_SiteDel_ErrorMessage = "Could not delete ftp site %1"
  40. Const L_GetFtpServer_ErrorMessage = "Error trying to obtain FtpServer object."
  41. Const L_CannotCreateDir_ErrorMessage = "Could not create root directory"
  42. Const L_CmdLib_ErrorMessage = "Could not create an instance of the CmdLib object."
  43. Const L_ChkCmdLibReg_ErrorMessage = "Please register the Microsoft.CmdLib component."
  44. Const L_DirFormat_ErrorMessage = "Root directory format unknown. Please use the"
  45. Const L_DirFormat2_ErrorMessage = "'<drive>:\<path>' format."
  46. Const L_CannotStart_Message = "%1: Server cannot be started in its current state"
  47. Const L_CannotStart2_Message = "(%1 server is %2)"
  48. Const L_CannotStop_Message = "Server cannot be stopped in its current state"
  49. Const L_CannotStop2_Message = "(%1 server is %2)"
  50. Const L_CannotPause_Message = "Server cannot be paused in its current state"
  51. Const L_CannotPause2_Message = "(%1 server is %2)"
  52. Const L_CannotControl_ErrorMessage = "Server cannot be controled in its current state"
  53. Const L_FailChange_ErrorMessage = "Failed to change status of server %1"
  54. Const L_OperationRequired_ErrorMessage = "Please specify an operation before the arguments."
  55. Const L_MinInfoNeeded_ErrorMessage = "Need at least <root> to create a site."
  56. Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
  57. Const L_Query_ErrorMessage = "Error occurred while querying WMI provider."
  58. Const L_OnlyOneOper_ErrorMessage = "Please specify only one operation at a time."
  59. Const L_ServerInstance_ErrorMessage = "Error trying to create a new ftp server instance."
  60. Const L_ServerPut_ErrorMessage = "Error trying to save new ftp server instance."
  61. Const L_VDirInstance_ErrorMessage = "Error trying to create a new virtual directory instance."
  62. Const L_VDirPut_ErrorMessage = "Error trying to save new virtual directory instance."
  63. Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the IIsScriptHelper object."
  64. Const L_ChkScpHelperReg_ErrorMessage = "Please register the Microsoft.IIsScriptHelper component."
  65. Const L_InvalidIP_ErrorMessage = "Invalid IP Address. Please check if it is well formated and"
  66. Const L_InvalidIP2_ErrorMessage = "belongs to this machine."
  67. Const L_InvalidPort_ErrorMessage = "Invalid port number."
  68. Const L_InvalidArg_ErrorMessage = "Invalid argument: %1"
  69. Const L_MapDrive_ErrorMessage = "Could not map network drive."
  70. Const L_PassWithoutUser_ErrorMessage = "Please specify /u switch before using /p."
  71. Const L_WMIConnect_ErrorMessage = "Could not connect to WMI provider."
  72. Const L_InvalidSwitch_ErrorMessage = "Invalid switch: %1"
  73. Const L_Admin_ErrorMessage = "You cannot run this command because you are not an"
  74. Const L_Admin2_ErrorMessage = "administrator on the server you are trying to configure."
  75. Const L_ADUserNotFound_ErrorMessage = "User %1 was not found in Active Directory."
  76. '''''''''''''''''''''
  77. ' Help
  78. ' General help messages
  79. Const L_SeeHelp_Message = "Type IIsFtp /? for help."
  80. Const L_SeeStartHelp_Message = "Type IIsFtp /start /? for help."
  81. Const L_SeeStopHelp_Message = "Type IIsFtp /stop /? for help."
  82. Const L_SeePauseHelp_Message = "Type IIsFtp /pause /? for help."
  83. Const L_SeeCreateHelp_Message = "Type IIsFtp /create /? for help."
  84. Const L_SeeDeleteHelp_Message = "Type IIsFtp /delete /? for help."
  85. Const L_SeeGetADPropHelp_Message = "Type IIsFtp /getadprop /? for help."
  86. Const L_SeeSetADPropHelp_Message = "Type IIsFtp /setadprop /? for help."
  87. Const L_SeeQueryHelp_Message = "Type IIsFtp /query /? for help."
  88. Const L_Help_HELP_General01_Text = "Description: Start, Stop, Pause, Delete, Query, or Create"
  89. Const L_Help_HELP_General01a_Text = " a Ftp Site"
  90. Const L_Help_HELP_General02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]]"
  91. Const L_Help_HELP_General03_Text = " /<operation> [arguments]"
  92. Const L_Help_HELP_General04_Text = "Parameters:"
  93. Const L_Help_HELP_General05_Text = ""
  94. Const L_Help_HELP_General06_Text = "Value Description"
  95. Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server>"
  96. Const L_Help_HELP_General07a_Text = " [Default: this system]"
  97. Const L_Help_HELP_General08_Text = "/u <username> Connect as <domain>\<username> or"
  98. Const L_Help_HELP_General09_Text = " <username> [Default: current user]"
  99. Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user"
  100. Const L_Help_HELP_General11_Text = "<operation> /start Starts a site(s) on"
  101. Const L_Help_HELP_General11a_Text = " given IIS Server."
  102. Const L_Help_HELP_General12_Text = " /stop Stops a site(s) from"
  103. Const L_Help_HELP_General13_Text = " running on a given IIS"
  104. Const L_Help_HELP_General13a_Text = " Server."
  105. Const L_Help_HELP_General14_Text = " /pause Pauses a site(s) that is"
  106. Const L_Help_HELP_General15_Text = " running on a given IIS"
  107. Const L_Help_HELP_General15a_Text = " Server."
  108. Const L_Help_HELP_General18_Text = " /delete Deletes IIS configuration"
  109. Const L_Help_HELP_General19_Text = " from an existing Ftp Site."
  110. Const L_Help_HELP_General19a_Text = " Content will not be"
  111. Const L_Help_HELP_General19b_Text = " deleted."
  112. Const L_Help_HELP_General20_Text = " /create Creates a Ftp Site."
  113. Const L_Help_HELP_General21_Text = " /query Queries existing Ftp Sites."
  114. Const L_Help_HELP_General21a_Text = " /SetADProp Sets FTPRoot and FTPDir"
  115. Const L_Help_HELP_General21b_Text = " values in Active Directory."
  116. Const L_Help_HELP_General21c_Text = " /GetADProp Queries FTPRoot and FTPDir"
  117. Const L_Help_HELP_General21d_Text = " values from Active Directory."
  118. Const L_Help_HELP_General22_Text = "For detailed usage:"
  119. Const L_Help_HELP_General23_Text = "IIsFtp /start /?"
  120. Const L_Help_HELP_General24_Text = "IIsFtp /stop /?"
  121. Const L_Help_HELP_General25_Text = "IIsFtp /pause /?"
  122. Const L_Help_HELP_General27_Text = "IIsFtp /delete /?"
  123. Const L_Help_HELP_General28_Text = "IIsFtp /create /?"
  124. Const L_Help_HELP_General29_Text = "IIsFtp /query /?"
  125. Const L_Help_HELP_General30_Text = "IIsFtp /SetADProp /?"
  126. Const L_Help_HELP_General31_Text = "IIsFtp /GetADProp /?"
  127. ' Common to all status change commands
  128. Const L_Help_HELP_Status03_Text = "Parameters:"
  129. Const L_Help_HELP_Status09_Text = "<ftpsite> Use either the site name or metabase"
  130. Const L_Help_HELP_Status09p1_Text = " path to specify the site"
  131. Const L_Help_HELP_Status10_Text = "Examples:"
  132. ' Start help messages
  133. Const L_Help_HELP_Start01_Text = "Description: Starts a site(s) on a given IIS Server."
  134. Const L_Help_HELP_Start02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]]"
  135. Const L_Help_HELP_Start02p1_Text = " /start <ftpsite> [<ftpsite> ...]"
  136. Const L_Help_HELP_Start11_Text = "IIsFtp /start ""Default Ftp Site"""
  137. Const L_Help_HELP_Start12_Text = "IIsFtp /start msftpsvc/1"
  138. Const L_Help_HELP_Start13_Text = "IIsFtp /start w3svc/2 ""Default Ftp Site"" w3svc/10"
  139. Const L_Help_HELP_Start14_Text = "IIsFtp /s Server1 /u Administrator /p p@ssWOrd /start msftpsvc/4"
  140. ' Stop help messages
  141. Const L_Help_HELP_Stop01_Text = "Description: Stops a site(s) on a given IIS Server."
  142. Const L_Help_HELP_Stop02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]] /stop"
  143. Const L_Help_HELP_Stop02p1_Text = " <ftpsite> [<ftpsite> ...]"
  144. Const L_Help_HELP_Stop11_Text = "IIsFtp /stop ""Default Ftp Site"""
  145. Const L_Help_HELP_Stop12_Text = "IIsFtp /stop msftpsvc/1"
  146. Const L_Help_HELP_Stop13_Text = "IIsFtp /stop w3svc/2 ""Default Ftp Site"" w3svc/10"
  147. Const L_Help_HELP_Stop14_Text = "IIsFtp /s Server1 /u Administrator /p p@ssWOrd /stop msftpsvc/4"
  148. ' GetADProp help messages
  149. Const L_Help_HELP_GetADProp01_Text = "Description: Queries properties from Active Directory."
  150. Const L_Help_HELP_GetADProp02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]]"
  151. Const L_Help_HELP_GetADProp02p1_Text = " /GetADProp <UserID> FTPDir | FTPRoot"
  152. Const L_Help_HELP_GetADProp10_Text = "<UserID> The logon id of the Active Directory"
  153. Const L_Help_HELP_GetADProp10a_Text = " user to grab the property from."
  154. Const L_Help_HELP_GetADProp11_Text = "IIsFtp /GetADProp billsmith FTPDir"
  155. Const L_Help_HELP_GetADProp12_Text = "IIsFtp /GetADProp marysmith FTPRoot"
  156. ' SetADProp help messages
  157. Const L_Help_HELP_SetADProp01_Text = "Description: Sets properties in Active Directory."
  158. Const L_Help_HELP_SetADProp02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]]"
  159. Const L_Help_HELP_SetADProp02p1_Text = " /SetADProp <UserID> FTPDir | FTPRoot <propval>"
  160. Const L_Help_HELP_SetADProp10_Text = "<UserID> The logon id of the Active Directory"
  161. Const L_Help_HELP_SetADProp10a_Text = " user to set the property at."
  162. Const L_Help_HELP_SetADProp11_Text = "IIsFtp /SetADProp billsmith FTPDir billsdir"
  163. Const L_Help_HELP_SetADProp12_Text = "IIsFtp /SetADProp marysmith FTPRoot c:\foo"
  164. ' Pause help messages
  165. Const L_Help_HELP_Pause01_Text = "Description: Pauses a site(s) on a given IIS Server."
  166. Const L_Help_HELP_Pause02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]]"
  167. Const L_Help_HELP_Pause02p1_Text = " /pause <ftpsite> [<ftpsite> ...]"
  168. Const L_Help_HELP_Pause11_Text = "IIsFtp /pause ""Default Ftp Site"""
  169. Const L_Help_HELP_Pause12_Text = "IIsFtp /pause msftpsvc/1"
  170. Const L_Help_HELP_Pause13_Text = "IIsFtp /pause w3svc/2 ""Default Ftp Site"" w3svc/10"
  171. Const L_Help_HELP_Pause14_Text = "IIsFtp /s Server1 /u Administrator /p p@ssWOrd /pause msftpsvc/4"
  172. ' Delete help messages
  173. Const L_Help_HELP_Delete01_Text = "Description: Deletes IIS configuration for an existing ftp"
  174. Const L_Help_HELP_Delete01p1_Text = " site. Content will not be deleted."
  175. Const L_Help_HELP_Delete02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]]"
  176. Const L_Help_HELP_Delete02p1_Text = " /delete <ftpsite> [<ftpsite> ...]"
  177. Const L_Help_HELP_Delete11_Text = "IIsFtp /delete ""Default Ftp Site"""
  178. Const L_Help_HELP_Delete12_Text = "IIsFtp /delete msftpsvc/1"
  179. Const L_Help_HELP_Delete13_Text = "IIsFtp /delete w3svc/2 ""Default Ftp Site"" w3svc/10"
  180. Const L_Help_HELP_Delete14_Text = "IIsFtp /s Server1 /u Administrator /p p@ssWOrd /delete msftpsvc/4"
  181. ' Create help messages
  182. Const L_Help_HELP_Create01_Text = "Description: Creates a ftp site."
  183. Const L_Help_HELP_Create02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]]"
  184. Const L_Help_HELP_Create02p1_Text = " /create <root> <name> [/b <port>] [/i <ip>] [/dontstart]"
  185. Const L_Help_HELP_Create03_Text = " [/isolation <isomode> [/ADDomain <domain>"
  186. Const L_Help_HELP_Create03a_Text = " /ADAdmin <admin> /ADPass <password>]]"
  187. Const L_Help_HELP_Create09_Text = "<root> Root directory for the new server."
  188. Const L_Help_HELP_Create09p1_Text = " If this directory does not exist, it"
  189. Const L_Help_HELP_Create09p2_Text = " will be created."
  190. Const L_Help_HELP_Create10_Text = "<name> The name that appears in the Microsoft"
  191. Const L_Help_HELP_Create10p1_Text = " Management Console (MMC)."
  192. Const L_Help_HELP_Create12_Text = "/b <port> The number of the port to which the"
  193. Const L_Help_HELP_Create12p1_Text = " new server should bind. [Default: 21]"
  194. Const L_Help_HELP_Create13_Text = "/i <ip> The IP address to assign to the new"
  195. Const L_Help_HELP_Create13p1_Text = " server. [Default: All Unassigned]"
  196. Const L_Help_HELP_Create15_Text = "/dontstart Don't start this site after it is created."
  197. Const L_Help_HELP_Create16_Text = "/isolation Set isolation mode to either Local or AD."
  198. Const L_Help_HELP_Create17_Text = "/AD* Set ActiveDirectory credentials for"
  199. Const L_Help_HELP_Create17a_Text = " AD isolation mode."
  200. Const L_Help_HELP_Create22_Text = "IIsFtp /create c:\inetpub\ftproot ""My Site"" /b 21"
  201. Const L_Help_HELP_Create23_Text = "IIsFtp /s Server1 /u Administrator /p p@assWOrd /create c:\inetpub\ftproot"
  202. Const L_Help_HELP_Create23p1_Text = " ""My Site"""
  203. Const L_Help_HELP_Create24_Text = "IIsFtp /create c:\inetpub\ftproot ""My Site"" /i 172.30.163.244 /b 21"
  204. ' Query help messages
  205. Const L_Help_HELP_Query01_Text = "Description: Queries existing ftp sites."
  206. Const L_Help_HELP_Query02_Text = "Syntax: IIsFtp [/s <server> [/u <username> [/p <password>]]]"
  207. Const L_Help_HELP_Query02p1_Text = " /query [<ftpsite> ...]"
  208. Const L_Help_HELP_Query11_Text = "IIsFtp /query ""Default Ftp Site"""
  209. Const L_Help_HELP_Query12_Text = "IIsFtp /query msftpsvc/1"
  210. Const L_Help_HELP_Query13_Text = "IIsFtp /query"
  211. Const L_Help_HELP_Query14_Text = "IIsFtp /query ""Default Ftp Site"" ""Sample Site"" msftpsvc/1"
  212. Const L_Help_HELP_Query15_Text = "IIsFtp /s Server1 /u Administrator /p p@ssW0rd /query ""Default Ftp Site"""
  213. ' Status
  214. Const L_Started_Text = "started"
  215. Const L_Stopped_Text = "stopped"
  216. Const L_Paused_Text = "paused"
  217. Const L_Continued_Text = "continued"
  218. Const L_Deleted_Text = "deleted"
  219. ''''''''''''''''''''''''
  220. Dim SiteStatus
  221. SiteStatus = Array("", "", L_Started_Text, "", L_Stopped_Text, "", L_Paused_Text, L_Continued_Text, L_Deleted_Text)
  222. ' Operation codes
  223. Const OPER_START = 1
  224. Const OPER_STOP = 2
  225. Const OPER_PAUSE = 3
  226. Const OPER_DELETE = 4
  227. Const OPER_CREATE = 5
  228. Const OPER_QUERY = 6
  229. Const OPER_GETADPROP= 7
  230. Const OPER_SETADPROP= 8
  231. ' ServerState codes
  232. Const SERVER_STARTING = 1
  233. Const SERVER_STARTED = 2
  234. Const SERVER_STOPPING = 3
  235. Const SERVER_STOPPED = 4
  236. Const SERVER_PAUSING = 5
  237. Const SERVER_PAUSED = 6
  238. Const SERVER_CONTINUING = 7
  239. '
  240. ' Main block
  241. '
  242. Dim oScriptHelper, oCmdLib
  243. Dim strServer, strUser, strPassword, strSite
  244. Dim intOperation, intResult
  245. Dim strRoot, strName, strPort, strIP, strISO, strADDomain, strADAdmin, strADPass
  246. Dim bDontStart
  247. Dim aArgs, arg
  248. Dim strCmdLineOptions
  249. Dim oError
  250. ' Default values
  251. strServer = "."
  252. strUser = ""
  253. strPassword = ""
  254. intOperation = 0
  255. strSite = ""
  256. strName = ""
  257. bDontStart = False
  258. ' Instantiate the CmdLib for output string formatting
  259. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  260. If Err.Number <> 0 Then
  261. WScript.Echo L_CmdLib_ErrorMessage
  262. WScript.Echo L_ChkCmdLibReg_ErrorMessage
  263. WScript.Quit(ERR_GENERAL_FAILURE)
  264. End If
  265. Set oCmdLib.ScriptingHost = WScript.Application
  266. ' Instantiate script helper object
  267. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  268. If Err.Number <> 0 Then
  269. WScript.Echo L_ScriptHelper_ErrorMessage
  270. WScript.Echo L_ChkScpHelperReg_ErrorMessage
  271. WScript.Quit(ERR_GENERAL_FAILURE)
  272. End If
  273. Set oScriptHelper.ScriptHost = WScript
  274. ' Check if we are being run with cscript.exe instead of wscript.exe
  275. oScriptHelper.CheckScriptEngine
  276. ' Minimum number of parameters must exist
  277. If WScript.Arguments.Count < 1 Then
  278. WScript.Echo L_NotEnoughParams_ErrorMessage
  279. WScript.Echo L_SeeHelp_Message
  280. WScript.Quit(ERR_GENERAL_FAILURE)
  281. End If
  282. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];start::n;stop::n;pause::n;delete::n;" & _
  283. "[create:c:1;port:b:1;ip:i:1;dontstart::0;isolation::1;addomain::1;adadmin::1;adpass::1];query:q:n;" & _
  284. "getadprop::n;setadprop::n"
  285. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  286. If Not oError Is Nothing Then
  287. If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  288. ' Not enough arguments for a specified switch
  289. WScript.Echo L_NotEnoughParams_ErrorMessage
  290. If oError.SwitchName = "create" Then
  291. WScript.Echo L_SeeCreateHelp_Message
  292. Else
  293. WScript.Echo L_SeeHelp_Message
  294. End If
  295. Else
  296. ' Invalid switch
  297. oCmdLib.vbPrintf L_InvalidSwitch_ErrorMessage, Array(oError.SwitchName)
  298. WScript.Echo L_SeeHelp_Message
  299. End If
  300. WScript.Quit(ERR_GENERAL_FAILURE)
  301. End If
  302. If oScriptHelper.GlobalHelpRequested Then
  303. DisplayHelpMessage
  304. WScript.Quit(ERR_OK)
  305. End If
  306. For Each arg In oScriptHelper.Switches
  307. Select Case arg
  308. Case "server"
  309. ' Server information
  310. strServer = oScriptHelper.GetSwitch(arg)
  311. Case "user"
  312. ' User information
  313. strUser = oScriptHelper.GetSwitch(arg)
  314. Case "password"
  315. ' Password information
  316. strPassword = oScriptHelper.GetSwitch(arg)
  317. Case "start"
  318. If (intOperation <> 0) Then
  319. WScript.Echo L_OnlyOneOper_ErrorMessage
  320. WScript.Echo L_SeeHelp_Message
  321. WScript.Quit(ERR_GENERAL_FAILURE)
  322. End If
  323. intOperation = OPER_START
  324. If oScriptHelper.IsHelpRequested(arg) Then
  325. DisplayStartHelpMessage
  326. WScript.Quit(ERR_OK)
  327. End If
  328. aArgs = oScriptHelper.GetSwitch(arg)
  329. If UBound(aArgs) = -1 Then
  330. WScript.Echo L_NotEnoughParams_ErrorMessage
  331. WScript.Echo L_SeeStartHelp_Message
  332. WScript.Quit(ERR_GENERAL_FAILURE)
  333. End If
  334. Case "stop"
  335. If (intOperation <> 0) Then
  336. WScript.Echo L_OnlyOneOper_ErrorMessage
  337. WScript.Echo L_SeeHelp_Message
  338. WScript.Quit(ERR_GENERAL_FAILURE)
  339. End If
  340. intOperation = OPER_STOP
  341. If oScriptHelper.IsHelpRequested(arg) Then
  342. DisplayStopHelpMessage
  343. WScript.Quit(ERR_OK)
  344. End If
  345. aArgs = oScriptHelper.GetSwitch(arg)
  346. If UBound(aArgs) = -1 Then
  347. WScript.Echo L_NotEnoughParams_ErrorMessage
  348. WScript.Echo L_SeeStopHelp_Message
  349. WScript.Quit(ERR_GENERAL_FAILURE)
  350. End If
  351. Case "pause"
  352. If (intOperation <> 0) Then
  353. WScript.Echo L_OnlyOneOper_ErrorMessage
  354. WScript.Echo L_SeeHelp_Message
  355. WScript.Quit(ERR_GENERAL_FAILURE)
  356. End If
  357. intOperation = OPER_PAUSE
  358. If oScriptHelper.IsHelpRequested(arg) Then
  359. DisplayPauseHelpMessage
  360. WScript.Quit(ERR_OK)
  361. End If
  362. aArgs = oScriptHelper.GetSwitch(arg)
  363. If UBound(aArgs) = -1 Then
  364. WScript.Echo L_NotEnoughParams_ErrorMessage
  365. WScript.Echo L_SeePauseHelp_Message
  366. WScript.Quit(ERR_GENERAL_FAILURE)
  367. End If
  368. Case "create"
  369. If (intOperation <> 0) Then
  370. WScript.Echo L_OnlyOneOper_ErrorMessage
  371. WScript.Echo L_SeeHelp_Message
  372. WScript.Quit(ERR_GENERAL_FAILURE)
  373. End If
  374. intOperation = OPER_CREATE
  375. If oScriptHelper.IsHelpRequested(arg) Then
  376. DisplayCreateHelpMessage
  377. WScript.Quit(ERR_OK)
  378. End If
  379. strRoot = oScriptHelper.GetSwitch(arg)
  380. aArgs = oScriptHelper.NamedArguments
  381. If strRoot = "" Or UBound(aArgs) = -1 Then
  382. WScript.Echo L_NotEnoughParams_ErrorMessage
  383. WScript.Echo L_SeeCreateHelp_Message
  384. WScript.Quit(ERR_GENERAL_FAILURE)
  385. End If
  386. strName = aArgs(0)
  387. strPort = oScriptHelper.GetSwitch("port")
  388. strIP = oScriptHelper.GetSwitch("ip")
  389. If oScriptHelper.Switches.Exists("dontstart") Then
  390. bDontStart = True
  391. End If
  392. strISO = oScriptHelper.GetSwitch("isolation")
  393. strADDomain= oScriptHelper.GetSwitch("addomain")
  394. strADAdmin = oScriptHelper.GetSwitch("adadmin")
  395. strADPass = oScriptHelper.GetSwitch("adpass")
  396. If UCase(strISO) = "AD" Then
  397. strRoot = ""
  398. End If
  399. Case "delete"
  400. If (intOperation <> 0) Then
  401. WScript.Echo L_OnlyOneOper_ErrorMessage
  402. WScript.Echo L_SeeHelp_Message
  403. WScript.Quit(ERR_GENERAL_FAILURE)
  404. End If
  405. intOperation = OPER_DELETE
  406. If oScriptHelper.IsHelpRequested(arg) Then
  407. DisplayDeleteHelpMessage
  408. WScript.Quit(ERR_OK)
  409. End If
  410. aArgs = oScriptHelper.GetSwitch(arg)
  411. If UBound(aArgs) = -1 Then
  412. WScript.Echo L_NotEnoughParams_ErrorMessage
  413. WScript.Echo L_SeeDeleteHelp_Message
  414. WScript.Quit(ERR_GENERAL_FAILURE)
  415. End If
  416. Case "query"
  417. If (intOperation <> 0) Then
  418. WScript.Echo L_OnlyOneOper_ErrorMessage
  419. WScript.Echo L_SeeHelp_Message
  420. WScript.Quit(ERR_GENERAL_FAILURE)
  421. End If
  422. intOperation = OPER_QUERY
  423. If oScriptHelper.IsHelpRequested(arg) Then
  424. DisplayQueryHelpMessage
  425. WScript.Quit(ERR_OK)
  426. End If
  427. aArgs = oScriptHelper.GetSwitch(arg)
  428. Case "getadprop"
  429. If (intOperation <> 0) Then
  430. WScript.Echo L_OnlyOneOper_ErrorMessage
  431. WScript.Echo L_SeeHelp_Message
  432. WScript.Quit(ERR_GENERAL_FAILURE)
  433. End If
  434. intOperation = OPER_GETADPROP
  435. If oScriptHelper.IsHelpRequested(arg) Then
  436. DisplayGetADPropHelpMessage
  437. WScript.Quit(ERR_OK)
  438. End If
  439. aArgs = oScriptHelper.GetSwitch(arg)
  440. If UBound(aArgs) = -1 Then
  441. WScript.Echo L_NotEnoughParams_ErrorMessage
  442. WScript.Echo L_SeeGetADPropHelp_Message
  443. WScript.Quit(ERR_GENERAL_FAILURE)
  444. End If
  445. Case "setadprop"
  446. If (intOperation <> 0) Then
  447. WScript.Echo L_OnlyOneOper_ErrorMessage
  448. WScript.Echo L_SeeHelp_Message
  449. WScript.Quit(ERR_GENERAL_FAILURE)
  450. End If
  451. intOperation = OPER_SETADPROP
  452. If oScriptHelper.IsHelpRequested(arg) Then
  453. DisplaySetADPropHelpMessage
  454. WScript.Quit(ERR_OK)
  455. End If
  456. aArgs = oScriptHelper.GetSwitch(arg)
  457. If UBound(aArgs) = -1 Then
  458. WScript.Echo L_NotEnoughParams_ErrorMessage
  459. WScript.Echo L_SeeSetADPropHelp_Message
  460. WScript.Quit(ERR_GENERAL_FAILURE)
  461. End If
  462. End Select
  463. Next
  464. ' Check Parameters
  465. If intOperation = 0 Then
  466. WScript.Echo L_OperationRequired_ErrorMessage
  467. WScript.Echo L_SeeHelp_Message
  468. WScript.Quit(ERR_GENERAL_FAILURE)
  469. End If
  470. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  471. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  472. WScript.Echo L_PassWithoutUser_ErrorMessage
  473. WScript.Quit(ERR_GENERAL_FAILURE)
  474. End If
  475. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  476. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  477. strPassword = oCmdLib.GetPassword
  478. End If
  479. ' Initializes authentication with remote machine
  480. ' This initialization applies only for IIS operations. We skip it for AD operations
  481. If intOperation <> OPER_GETADPROP And intOperation <> OPER_SETADPROP Then
  482. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  483. If intResult <> 0 Then
  484. WScript.Quit(intResult)
  485. End If
  486. End If
  487. ' Choose operation
  488. Select Case intOperation
  489. Case OPER_START
  490. intResult = ChangeFtpSiteStatus(aArgs, SERVER_STARTED)
  491. Case OPER_STOP
  492. intResult = ChangeFtpSiteStatus(aArgs, SERVER_STOPPED)
  493. Case OPER_PAUSE
  494. intResult = ChangeFtpSiteStatus(aArgs, SERVER_PAUSED)
  495. Case OPER_DELETE
  496. intResult = DeleteFtpSite(aArgs)
  497. Case OPER_CREATE
  498. intResult = CreateFtpSite(strRoot, strName, strPort, strIP, bDontStart, strISO, strADDomain, strADAdmin, strADPass)
  499. Case OPER_QUERY
  500. intResult = QueryFtpSite(aArgs)
  501. Case OPER_GETADPROP
  502. intResult = GetADProp(strServer, strUser, strPassword, aArgs)
  503. Case OPER_SETADPROP
  504. intResult = SetADProp(strServer, strUser, strPassword, aArgs)
  505. End Select
  506. ' Return value to command processor
  507. WScript.Quit(intResult)
  508. '''''''''''''''''''''''''
  509. ' End Of Main Block
  510. '''''''''''''''''''''
  511. '''''''''''''''''''''''''''
  512. ' DisplayHelpMessage
  513. '''''''''''''''''''''''''''
  514. Sub DisplayHelpMessage()
  515. WScript.Echo L_Help_HELP_General01_Text
  516. WScript.Echo L_Help_HELP_General01a_Text
  517. WScript.Echo
  518. WScript.Echo L_Help_HELP_General02_Text
  519. WScript.Echo L_Help_HELP_General03_Text
  520. WScript.Echo
  521. WScript.Echo L_Help_HELP_General04_Text
  522. WScript.Echo L_Help_HELP_General05_Text
  523. WScript.Echo L_Help_HELP_General06_Text
  524. WScript.Echo L_Help_HELP_General07_Text
  525. WScript.Echo L_Help_HELP_General07a_Text
  526. WScript.Echo L_Help_HELP_General08_Text
  527. WScript.Echo L_Help_HELP_General09_Text
  528. WScript.Echo L_Help_HELP_General10_Text
  529. WScript.Echo L_Help_HELP_General11_Text
  530. WScript.Echo L_Help_HELP_General11a_Text
  531. WScript.Echo L_Help_HELP_General12_Text
  532. WScript.Echo L_Help_HELP_General13_Text
  533. WScript.Echo L_Help_HELP_General13a_Text
  534. WScript.Echo L_Help_HELP_General14_Text
  535. WScript.Echo L_Help_HELP_General15_Text
  536. WScript.Echo L_Help_HELP_General15a_Text
  537. WScript.Echo L_Help_HELP_General18_Text
  538. WScript.Echo L_Help_HELP_General19_Text
  539. WScript.Echo L_Help_HELP_General19a_Text
  540. WScript.Echo L_Help_HELP_General19b_Text
  541. WScript.Echo L_Help_HELP_General20_Text
  542. WScript.Echo L_Help_HELP_General21_Text
  543. WScript.Echo L_Help_HELP_General21a_Text
  544. WScript.Echo L_Help_HELP_General21b_Text
  545. WScript.Echo L_Help_HELP_General21c_Text
  546. WScript.Echo L_Help_HELP_General21d_Text
  547. WScript.Echo
  548. WScript.Echo L_Help_HELP_General22_Text
  549. WScript.Echo
  550. WScript.Echo L_Help_HELP_General23_Text
  551. WScript.Echo L_Help_HELP_General24_Text
  552. WScript.Echo L_Help_HELP_General25_Text
  553. WScript.Echo L_Help_HELP_General27_Text
  554. WScript.Echo L_Help_HELP_General28_Text
  555. WScript.Echo L_Help_HELP_General29_Text
  556. WScript.Echo L_Help_HELP_General30_Text
  557. WScript.Echo L_Help_HELP_General31_Text
  558. End Sub
  559. Sub DisplayStartHelpMessage()
  560. WScript.Echo L_Help_HELP_Start01_Text
  561. WScript.Echo
  562. WScript.Echo L_Help_HELP_Start02_Text
  563. WScript.Echo L_Help_HELP_Start02p1_Text
  564. WScript.Echo
  565. WScript.Echo L_Help_HELP_Status03_Text
  566. WScript.Echo
  567. WScript.Echo L_Help_HELP_General06_Text
  568. WScript.Echo L_Help_HELP_General07_Text
  569. WScript.Echo L_Help_HELP_General07a_Text
  570. WScript.Echo L_Help_HELP_General08_Text
  571. WScript.Echo L_Help_HELP_General09_Text
  572. WScript.Echo L_Help_HELP_General10_Text
  573. WScript.Echo L_Help_HELP_Status09_Text
  574. WScript.Echo L_Help_HELP_Status09p1_Text
  575. WScript.Echo
  576. WScript.Echo
  577. WScript.Echo L_Help_HELP_Status10_Text
  578. WScript.Echo
  579. WScript.Echo L_Help_HELP_Start11_Text
  580. WScript.Echo L_Help_HELP_Start12_Text
  581. WScript.Echo L_Help_HELP_Start13_Text
  582. WScript.Echo L_Help_HELP_Start14_Text
  583. End Sub
  584. Sub DisplayStopHelpMessage()
  585. WScript.Echo L_Help_HELP_Stop01_Text
  586. WScript.Echo
  587. WScript.Echo L_Help_HELP_Stop02_Text
  588. WScript.Echo L_Help_HELP_Stop02p1_Text
  589. WScript.Echo
  590. WScript.Echo L_Help_HELP_Status03_Text
  591. WScript.Echo
  592. WScript.Echo L_Help_HELP_General06_Text
  593. WScript.Echo L_Help_HELP_General07_Text
  594. WScript.Echo L_Help_HELP_General07a_Text
  595. WScript.Echo L_Help_HELP_General08_Text
  596. WScript.Echo L_Help_HELP_General09_Text
  597. WScript.Echo L_Help_HELP_General10_Text
  598. WScript.Echo L_Help_HELP_Status09_Text
  599. WScript.Echo L_Help_HELP_Status09p1_Text
  600. WScript.Echo
  601. WScript.Echo
  602. WScript.Echo L_Help_HELP_Status10_Text
  603. WScript.Echo
  604. WScript.Echo L_Help_HELP_Stop11_Text
  605. WScript.Echo L_Help_HELP_Stop12_Text
  606. WScript.Echo L_Help_HELP_Stop13_Text
  607. WScript.Echo L_Help_HELP_Stop14_Text
  608. End Sub
  609. Sub DisplayGetADPropHelpMessage()
  610. WScript.Echo L_Help_HELP_GetADProp01_Text
  611. WScript.Echo
  612. WScript.Echo L_Help_HELP_GetADProp02_Text
  613. WScript.Echo L_Help_HELP_GetADProp02p1_Text
  614. WScript.Echo
  615. WScript.Echo L_Help_HELP_Status03_Text
  616. WScript.Echo
  617. WScript.Echo L_Help_HELP_General06_Text
  618. WScript.Echo L_Help_HELP_General07_Text
  619. WScript.Echo L_Help_HELP_General07a_Text
  620. WScript.Echo L_Help_HELP_General08_Text
  621. WScript.Echo L_Help_HELP_General09_Text
  622. WScript.Echo L_Help_HELP_General10_Text
  623. WScript.Echo L_Help_HELP_GetADProp10_Text
  624. WScript.Echo L_Help_HELP_GetADProp10a_Text
  625. WScript.Echo
  626. WScript.Echo
  627. WScript.Echo L_Help_HELP_Status10_Text
  628. WScript.Echo
  629. WScript.Echo L_Help_HELP_GetADProp11_Text
  630. WScript.Echo L_Help_HELP_GetADProp12_Text
  631. End Sub
  632. Sub DisplaySetADPropHelpMessage()
  633. WScript.Echo L_Help_HELP_SetADProp01_Text
  634. WScript.Echo
  635. WScript.Echo L_Help_HELP_SetADProp02_Text
  636. WScript.Echo L_Help_HELP_SetADProp02p1_Text
  637. WScript.Echo
  638. WScript.Echo L_Help_HELP_Status03_Text
  639. WScript.Echo
  640. WScript.Echo L_Help_HELP_General06_Text
  641. WScript.Echo L_Help_HELP_General07_Text
  642. WScript.Echo L_Help_HELP_General07a_Text
  643. WScript.Echo L_Help_HELP_General08_Text
  644. WScript.Echo L_Help_HELP_General09_Text
  645. WScript.Echo L_Help_HELP_General10_Text
  646. WScript.Echo L_Help_HELP_SetADProp10_Text
  647. WScript.Echo L_Help_HELP_SetADProp10a_Text
  648. WScript.Echo
  649. WScript.Echo
  650. WScript.Echo L_Help_HELP_Status10_Text
  651. WScript.Echo
  652. WScript.Echo L_Help_HELP_SetADProp11_Text
  653. WScript.Echo L_Help_HELP_SetADProp12_Text
  654. End Sub
  655. Sub DisplayPauseHelpMessage()
  656. WScript.Echo L_Help_HELP_Pause01_Text
  657. WScript.Echo
  658. WScript.Echo L_Help_HELP_Pause02_Text
  659. WScript.Echo L_Help_HELP_Pause02p1_Text
  660. WScript.Echo
  661. WScript.Echo L_Help_HELP_Status03_Text
  662. WScript.Echo
  663. WScript.Echo L_Help_HELP_General06_Text
  664. WScript.Echo L_Help_HELP_General07_Text
  665. WScript.Echo L_Help_HELP_General07a_Text
  666. WScript.Echo L_Help_HELP_General08_Text
  667. WScript.Echo L_Help_HELP_General09_Text
  668. WScript.Echo L_Help_HELP_General10_Text
  669. WScript.Echo L_Help_HELP_Status09_Text
  670. WScript.Echo L_Help_HELP_Status09p1_Text
  671. WScript.Echo
  672. WScript.Echo
  673. WScript.Echo L_Help_HELP_Status10_Text
  674. WScript.Echo
  675. WScript.Echo L_Help_HELP_Pause11_Text
  676. WScript.Echo L_Help_HELP_Pause12_Text
  677. WScript.Echo L_Help_HELP_Pause13_Text
  678. WScript.Echo L_Help_HELP_Pause14_Text
  679. End Sub
  680. Sub DisplayDeleteHelpMessage()
  681. WScript.Echo L_Help_HELP_Delete01_Text
  682. WScript.Echo L_Help_HELP_Delete01p1_Text
  683. WScript.Echo
  684. WScript.Echo L_Help_HELP_Delete02_Text
  685. WScript.Echo L_Help_HELP_Delete02p1_Text
  686. WScript.Echo
  687. WScript.Echo L_Help_HELP_Status03_Text
  688. WScript.Echo
  689. WScript.Echo L_Help_HELP_General06_Text
  690. WScript.Echo L_Help_HELP_General07_Text
  691. WScript.Echo L_Help_HELP_General07a_Text
  692. WScript.Echo L_Help_HELP_General08_Text
  693. WScript.Echo L_Help_HELP_General09_Text
  694. WScript.Echo L_Help_HELP_General10_Text
  695. WScript.Echo L_Help_HELP_Status09_Text
  696. WScript.Echo L_Help_HELP_Status09p1_Text
  697. WScript.Echo
  698. WScript.Echo
  699. WScript.Echo L_Help_HELP_Status10_Text
  700. WScript.Echo
  701. WScript.Echo L_Help_HELP_Delete11_Text
  702. WScript.Echo L_Help_HELP_Delete12_Text
  703. WScript.Echo L_Help_HELP_Delete13_Text
  704. WScript.Echo L_Help_HELP_Delete14_Text
  705. End Sub
  706. Sub DisplayCreateHelpMessage()
  707. WScript.Echo L_Help_HELP_Create01_Text
  708. WScript.Echo
  709. WScript.Echo L_Help_HELP_Create02_Text
  710. WScript.Echo L_Help_HELP_Create02p1_Text
  711. WScript.Echo L_Help_HELP_Create03_Text
  712. WScript.Echo L_Help_HELP_Create03a_Text
  713. WScript.Echo
  714. WScript.Echo L_Help_HELP_Status03_Text
  715. WScript.Echo
  716. WScript.Echo L_Help_HELP_General06_Text
  717. WScript.Echo L_Help_HELP_General07_Text
  718. WScript.Echo L_Help_HELP_General07a_Text
  719. WScript.Echo L_Help_HELP_General08_Text
  720. WScript.Echo L_Help_HELP_General09_Text
  721. WScript.Echo L_Help_HELP_General10_Text
  722. WScript.Echo L_Help_HELP_Create09_Text
  723. WScript.Echo L_Help_HELP_Create09p1_Text
  724. WScript.Echo L_Help_HELP_Create09p2_Text
  725. WScript.Echo L_Help_HELP_Create10_Text
  726. WScript.Echo L_Help_HELP_Create10p1_Text
  727. WScript.Echo L_Help_HELP_Create12_Text
  728. WScript.Echo L_Help_HELP_Create12p1_Text
  729. WScript.Echo L_Help_HELP_Create13_Text
  730. WScript.Echo L_Help_HELP_Create13p1_Text
  731. WScript.Echo L_Help_HELP_Create15_Text
  732. WScript.Echo L_Help_HELP_Create16_Text
  733. WScript.Echo L_Help_HELP_Create17_Text
  734. WScript.Echo L_Help_HELP_Create17a_Text
  735. WScript.Echo
  736. WScript.Echo L_Help_HELP_Status10_Text
  737. WScript.Echo
  738. WScript.Echo L_Help_HELP_Create22_Text
  739. WScript.Echo L_Help_HELP_Create23_Text
  740. WScript.Echo L_Help_HELP_Create23p1_Text
  741. WScript.Echo L_Help_HELP_Create24_Text
  742. End Sub
  743. Sub DisplayQueryHelpMessage()
  744. WScript.Echo L_Help_HELP_Query01_Text
  745. WScript.Echo
  746. WScript.Echo L_Help_HELP_Query02_Text
  747. WScript.Echo L_Help_HELP_Query02p1_Text
  748. WScript.Echo
  749. WScript.Echo L_Help_HELP_Status03_Text
  750. WScript.Echo
  751. WScript.Echo L_Help_HELP_General06_Text
  752. WScript.Echo L_Help_HELP_General07_Text
  753. WScript.Echo L_Help_HELP_General07a_Text
  754. WScript.Echo L_Help_HELP_General08_Text
  755. WScript.Echo L_Help_HELP_General09_Text
  756. WScript.Echo L_Help_HELP_General10_Text
  757. WScript.Echo L_Help_HELP_Status09_Text
  758. WScript.Echo L_Help_HELP_Status09p1_Text
  759. WScript.Echo
  760. WScript.Echo
  761. WScript.Echo L_Help_HELP_Status10_Text
  762. WScript.Echo
  763. WScript.Echo L_Help_HELP_Query11_Text
  764. WScript.Echo L_Help_HELP_Query12_Text
  765. WScript.Echo L_Help_HELP_Query13_Text
  766. WScript.Echo L_Help_HELP_Query14_Text
  767. WScript.Echo L_Help_HELP_Query15_Text
  768. End Sub
  769. '''''''''''''''''''''''''''
  770. ' ChangeFtpSiteStatus
  771. '
  772. ' Try to change the status of a site
  773. ' to the one specified
  774. '''''''''''''''''''''''''''
  775. Function ChangeFtpSiteStatus(aArgs, newStatus)
  776. Dim Server, strSiteName
  777. Dim intResult, i, intNewStatus
  778. Dim aSites
  779. Dim providerObj, ServiceObj
  780. Dim bNonFatalError
  781. On Error Resume Next
  782. bNonFatalError = False
  783. oScriptHelper.WMIConnect
  784. If Err.Number Then
  785. WScript.Echo L_WMIConnect_ErrorMessage
  786. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  787. ChangeFtpSiteStatus = Err.Number
  788. Exit Function
  789. End If
  790. Set providerObj = oScriptHelper.ProviderObj
  791. intResult = 0
  792. ' Quick check to see if we have permission
  793. Set ServiceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  794. If Err.Number Then
  795. Select Case Err.Number
  796. Case &H80070005
  797. WScript.Echo L_Admin_ErrorMessage
  798. WScript.Echo L_Admin2_ErrorMessage
  799. Case Else
  800. WScript.Echo Err.Description
  801. End Select
  802. ChangeFtpSiteStatus = Err.Number
  803. Exit Function
  804. End If
  805. aSites = oScriptHelper.FindSite("Ftp", aArgs)
  806. If IsArray(aSites) Then
  807. If UBound(aSites) = -1 Then
  808. WScript.Echo L_SitesNotFound_ErrorMessage
  809. intResult = ERR_GENERAL_FAILURE
  810. End If
  811. Else
  812. ' Got duplicate sites. We should quit.
  813. ChangeFtpSiteStatus = intResult
  814. Exit Function
  815. End If
  816. For i = LBound(aSites) to UBound(aSites)
  817. bNonFatalError = False
  818. strSiteName = aSites(i)
  819. ' Grab site state before trying to start it
  820. Set Server = providerObj.Get("IIsFtpServer='" & strSiteName & "'")
  821. If (Err.Number <> 0) Then
  822. WScript.Echo L_GetFtpServer_ErrorMessage
  823. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  824. intResult = Err.Number
  825. End If
  826. If (Server.ServerState = newStatus) Then
  827. oCmdLib.vbPrintf L_IsAlready_Message, Array(strSiteName, UCase(SiteStatus(newStatus)))
  828. Else
  829. If (Server.ServerState = SERVER_STARTING or Server.ServerState = SERVER_STOPPING or _
  830. Server.ServerState = SERVER_PAUSING or Server.ServerState = SERVER_CONTINUING) Then
  831. WScript.Echo L_CannotControl_ErrorMessage
  832. intResult = ERR_GENERAL_FAILURE
  833. Else
  834. Select Case newStatus
  835. Case SERVER_STARTED
  836. If (Server.ServerState = SERVER_STOPPED) Then
  837. intNewStatus = SERVER_STARTED
  838. Server.Start
  839. Else
  840. If (Server.ServerState = SERVER_PAUSED) Then
  841. intNewStatus = SERVER_CONTINUING
  842. Server.Continue
  843. Else
  844. oCmdLib.vbPrintf L_CannotStart_Message, Array(strSiteName)
  845. oCmdLib.vbPrintf L_CannotStart2_Message, Array(strSiteName, SiteStatus(Server.ServerState))
  846. bNonFatalError = True
  847. End If
  848. End If
  849. Case SERVER_STOPPED
  850. If (Server.ServerState = SERVER_STARTED) Then
  851. intNewStatus = SERVER_STOPPED
  852. Server.Stop
  853. Else
  854. WScript.Echo L_CannotStop_Message
  855. oCmdLib.vbPrintf L_CannotStop2_Message, Array(strSiteName, SiteStatus(Server.ServerState))
  856. bNonFatalError = True
  857. End If
  858. Case SERVER_PAUSED
  859. If (Server.ServerState = SERVER_STARTED) Then
  860. intNewStatus = SERVER_PAUSED
  861. Server.Pause
  862. Else
  863. WScript.Echo L_CannotPause_Message
  864. oCmdLib.vbPrintf L_CannotPause2_Message, Array(strSiteName, SiteStatus(Server.ServerState))
  865. bNonFatalError = True
  866. End If
  867. Case Else
  868. WScript.Echo L_UnexpectedState_ErrorMessage
  869. WScript.Quit(ERR_GENERAL_FAILURE)
  870. End Select
  871. ' Error checking
  872. If (Err.Number <> 0) Then
  873. oCmdLib.vbPrintf L_FailChange_ErrorMessage, Array(strSite)
  874. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  875. intResult = Err.Number
  876. Else
  877. If (bNonFatalError = False) Then
  878. oCmdLib.vbPrintf L_HasBeen_Message, Array(strSiteName, UCase(SiteStatus(intNewStatus)))
  879. End If
  880. End If
  881. End If
  882. End If
  883. Next
  884. Set Server = Nothing
  885. ChangeFtpSiteStatus = intResult
  886. End Function
  887. '''''''''''''''''''''''''''
  888. ' DeleteFtpSite
  889. '''''''''''''''''''''''''''
  890. Function DeleteFtpSite(aArgs)
  891. Dim strSiteName
  892. Dim RootVDirObj, FtpServerObj
  893. Dim aSites
  894. Dim providerObj, ServiceObj
  895. On Error Resume Next
  896. oScriptHelper.WMIConnect
  897. If Err.Number Then
  898. WScript.Echo L_WMIConnect_ErrorMessage
  899. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  900. DeleteFtpSite = Err.Number
  901. Exit Function
  902. End If
  903. Set providerObj = oScriptHelper.ProviderObj
  904. ' Quick check to see if we have permission
  905. Set ServiceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  906. If Err.Number Then
  907. Select Case Err.Number
  908. Case &H80070005
  909. WScript.Echo L_Admin_ErrorMessage
  910. WScript.Echo L_Admin2_ErrorMessage
  911. Case Else
  912. WScript.Echo Err.Description
  913. End Select
  914. DeleteFtpSite = Err.Number
  915. Exit Function
  916. End If
  917. aSites = oScriptHelper.FindSite("Ftp", aArgs)
  918. If IsArray(aSites) Then
  919. If UBound(aSites) = -1 Then
  920. WScript.Echo L_SitesNotFound_ErrorMessage
  921. intResult = ERR_GENERAL_FAILURE
  922. End If
  923. Else
  924. ' Got duplicate sites. We should quit.
  925. ChangeFtpSiteStatus = intResult
  926. Exit Function
  927. End If
  928. For Each strSiteName in aSites
  929. ' Stop and delete the ftp site
  930. Set FtpServerObj = providerObj.Get("IIsFtpServer='" & strSiteName & "'")
  931. If (Err.Number <> 0) Then
  932. oCmdLib.vbPrintf L_SiteGet_ErrorMessage, Array(strSiteName)
  933. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  934. DeleteFtpSite = Err.Number
  935. Exit Function
  936. End If
  937. FtpServerObj.Stop
  938. If (Err.Number <> 0) Then
  939. oCmdLib.vbPrintf L_Stop_ErrorMessage, Array(strSiteName)
  940. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  941. DeleteFtpSite = Err.Number
  942. Exit Function
  943. End If
  944. FtpServerObj.Delete_
  945. If (Err.Number <> 0) Then
  946. oCmdLib.vbPrintf L_SiteDel_ErrorMessage, Array(strSiteName)
  947. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  948. DeleteFtpSite = Err.Number
  949. Exit Function
  950. End If
  951. oCmdLib.vbPrintf L_HasBeen_Message, Array(strSiteName, UCase(SiteStatus(8)))
  952. Next
  953. DeleteFtpSite = ERR_OK
  954. End Function
  955. '''''''''''''''''''''''''''
  956. ' GetADProp
  957. '''''''''''''''''''''''''''
  958. Function GetADProp(strServer, strUser, strPassword, aArgs)
  959. Dim objLocator
  960. Dim objService
  961. Dim collObj, userObj
  962. On Error Resume Next
  963. Set objLocator = CreateObject("WbemScripting.SWbemLocator")
  964. ' Set the impersonation level
  965. objLocator.Security_.ImpersonationLevel = 3
  966. If strUser <> "" And strPassword <> "" Then
  967. Set objService = objLocator.ConnectServer(strServer, "root\directory\LDAP", strUser, strPassword)
  968. Else
  969. Set objService = objLocator.ConnectServer(strServer, "root\directory\LDAP")
  970. End If
  971. If Err.Number Then
  972. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  973. GetADProp = Err.Number
  974. Exit Function
  975. End If
  976. ' Set the impersonation level
  977. objService.Security_.ImpersonationLevel = 3
  978. Set collObj = objService.ExecQuery("select * from ds_user where DS_sAMAccountName='" & aArgs(0) & "'")
  979. If Err.Number Then
  980. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  981. GetADProp = Err.Number
  982. Else
  983. If collObj.Count = 0 Then
  984. oCmdLib.vbPrintf L_ADUserNotFound_ErrorMessage, Array(aArgs(0))
  985. ' Returns "element not found" error
  986. GetADProp = &H80070490
  987. Else
  988. oCmdLib.vbPrintf L_GetAD_Message, Array(aArgs(1), aArgs(0))
  989. For Each userObj in collObj
  990. If UCase(aArgs(1)) = "FTPDIR" Then
  991. WScript.Echo userObj.DS_msIIS_FTPDir
  992. ElseIf UCase(aArgs(1)) = "FTPROOT" Then
  993. WScript.Echo userObj.DS_msIIS_FTPRoot
  994. Else
  995. oCmdLib.vbPrintf L_InvalidArg_ErrorMessage, Array(aArgs(1))
  996. GetADProp = ERR_GENERAL_FAILURE
  997. Exit Function
  998. End If
  999. Next
  1000. GetADProp = ERR_OK
  1001. End If
  1002. End If
  1003. End Function
  1004. '''''''''''''''''''''''''''
  1005. ' SetADProp
  1006. '''''''''''''''''''''''''''
  1007. Function SetADProp(strServer, strUser, strPassword, aArgs)
  1008. Dim objLocator
  1009. Dim objService
  1010. Dim collObj, userObj
  1011. Dim octx
  1012. Dim propName
  1013. On Error Resume Next
  1014. Set objLocator = CreateObject("WbemScripting.SWbemLocator")
  1015. ' Set the impersonation level
  1016. objLocator.Security_.ImpersonationLevel = 3
  1017. If strUser <> "" And strPassword <> "" Then
  1018. Set objService = objLocator.ConnectServer(strServer, "root\directory\LDAP", strUser, strPassword)
  1019. Else
  1020. Set objService = objLocator.ConnectServer(strServer, "root\directory\LDAP")
  1021. End If
  1022. If Err.Number Then
  1023. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1024. SetADProp = Err.Number
  1025. Exit Function
  1026. End If
  1027. ' Set the impersonation level
  1028. objService.Security_.ImpersonationLevel = 3
  1029. Set collObj = objService.ExecQuery("select * from ds_user where DS_sAMAccountName='" & aArgs(0) & "'")
  1030. If Err.Number Then
  1031. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1032. SetADProp = Err.Number
  1033. Else
  1034. If collObj.Count = 0 Then
  1035. oCmdLib.vbPrintf L_ADUserNotFound_ErrorMessage, Array(aArgs(0))
  1036. ' Returns "element not found" error
  1037. SetADProp = &H80070490
  1038. Else
  1039. Set octx = CreateObject("WbemScripting.SWbemNamedValueSet")
  1040. octx.Add "__PUT_EXT_PROPERTIES", Array("DS_msIIS_FTPDir","DS_msIIS_FTPRoot")
  1041. octx.Add "__PUT_EXTENSIONS", True
  1042. octx.Add "__PUT_EXT_CLIENT_REQUEST", True
  1043. For Each userObj in collObj
  1044. If UCase(aArgs(1)) = "FTPROOT" Then
  1045. userObj.DS_msIIS_FTPRoot = aArgs(2)
  1046. Elseif UCase(aArgs(1)) = "FTPDIR" Then
  1047. userObj.DS_msIIS_FTPDir = aArgs(2)
  1048. Else
  1049. oCmdLib.vbPrintf L_InvalidArg_ErrorMessage, Array(aArgs(1))
  1050. SetADProp = ERR_GENERAL_FAILURE
  1051. Exit Function
  1052. End If
  1053. userObj.Put_ 1, octx
  1054. If Err.Number Then
  1055. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1056. SetADProp = Err.Number
  1057. Exit Function
  1058. End If
  1059. Next
  1060. oCmdLib.vbPrintf L_SetAD_Message, Array(aArgs(1), aArgs(0), aArgs(2))
  1061. SetADProp = ERR_OK
  1062. End If
  1063. End If
  1064. End Function
  1065. '''''''''''''''''''''''''''
  1066. ' CreateFtpSite
  1067. '''''''''''''''''''''''''''
  1068. Function CreateFtpSite(strRoot, strName, strPort, strIP, bDontStart, strISO, strADDomain, strADAdmin, strADPass)
  1069. Dim strSitePath
  1070. Dim strSiteObjPath
  1071. Dim Bindings
  1072. Dim objPath, serviceObj
  1073. Dim serverObj, vdirObj, settingObj
  1074. Dim strStatus
  1075. Dim providerObj
  1076. On Error Resume Next
  1077. ' Default port
  1078. If (strPort = "") Then strPort = "21"
  1079. ' Verify port number
  1080. If Not oScriptHelper.IsValidPortNumber(strPort) Then
  1081. WScript.Echo L_InvalidPort_ErrorMessage
  1082. CreateFtpSite = ERR_GENERAL_FAILURE
  1083. Exit Function
  1084. End If
  1085. ' Verify IP Address
  1086. If strIP <> "" Then
  1087. If Not oScriptHelper.IsValidIPAddress(strIP) Then
  1088. WScript.Echo L_InvalidIP_ErrorMessage
  1089. WScript.Echo L_InvalidIP2_ErrorMessage
  1090. CreateFtpSite = ERR_GENERAL_FAILURE
  1091. Exit Function
  1092. End If
  1093. End If
  1094. ' Create physical directory
  1095. If strRoot <> "" Then
  1096. oScriptHelper.CreateFSDir strRoot
  1097. If Err.Number Then
  1098. Select Case Err.Number
  1099. Case &H8007000C
  1100. WScript.Echo L_DirFormat_ErrorMessage
  1101. WScript.Echo L_DirFormat2_ErrorMessage
  1102. WScript.Echo L_SeeCreateHelp_Message
  1103. CreateFtpSite = Err.Number
  1104. Exit Function
  1105. Case &H8007000F
  1106. WScript.Echo L_MapDrive_ErrorMessage
  1107. CreateFtpSite = Err.Number
  1108. Exit Function
  1109. Case Else
  1110. WScript.Echo L_CannotCreateDir_ErrorMessage
  1111. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1112. CreateFtpSite = Err.Number
  1113. Exit Function
  1114. End Select
  1115. End If
  1116. End If
  1117. ' Time to connect to the IIS namespace
  1118. oScriptHelper.WMIConnect
  1119. If Err.Number Then
  1120. WScript.Echo L_WMIConnect_ErrorMessage
  1121. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1122. CreateFtpSite = Err.Number
  1123. Exit Function
  1124. End If
  1125. Set providerObj = oScriptHelper.ProviderObj
  1126. ' Build binding object
  1127. Bindings = Array(0)
  1128. Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_()
  1129. Bindings(0).IP = strIP
  1130. Bindings(0).Port = strPort
  1131. Set serviceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  1132. If Err.Number Then
  1133. Select Case Err.Number
  1134. Case &H80070005
  1135. WScript.Echo L_Admin_ErrorMessage
  1136. WScript.Echo L_Admin2_ErrorMessage
  1137. Case Else
  1138. WScript.Echo Err.Description
  1139. End Select
  1140. CreateFtpSite = Err.Number
  1141. Exit Function
  1142. End If
  1143. strSiteObjPath = serviceObj.CreateNewSite(strName, Bindings, strRoot)
  1144. If Err Then
  1145. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1146. CreateWebSite = Err.Number
  1147. Exit Function
  1148. End If
  1149. ' Parse site ID out of WMI object path
  1150. Set objPath = CreateObject("WbemScripting.SWbemObjectPath")
  1151. objPath.Path = strSiteObjPath
  1152. strSitePath = objPath.Keys.Item("")
  1153. ' Set ftp virtual directory properties
  1154. Set vdirObj = providerObj.Get("IIsFtpVirtualDirSetting='" & strSitePath & "/ROOT'")
  1155. vdirObj.AccessFlags = 1 ' read
  1156. If UCase(strISO) = "AD" Then
  1157. vdirObj.AccessFlags = 32769 ' read, AccessNoPhysicalDir
  1158. End If
  1159. vdirObj.Put_()
  1160. If Err Then
  1161. WScript.Echo L_VDirPut_ErrorMessage
  1162. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1163. providerObj.Delete(strSiteObjPath)
  1164. CreateWebSite = Err.Number
  1165. Exit Function
  1166. End If
  1167. ' Site is stopped - CreateNewSite stops it by default
  1168. Set serverObj = providerObj.Get("IIsFtpServer='" & strSitePath & "'")
  1169. Set settingObj = providerObj.Get("IIsFtpServerSetting='" & strSitePath & "'")
  1170. ' set UserIsolationMode
  1171. If strISO <> "" Then
  1172. If UCase(strISO) = "LOCAL" Then
  1173. settingObj.UserIsolationMode = 1
  1174. settingObj.Put_()
  1175. End If
  1176. If UCase(strISO) = "AD" Then
  1177. settingObj.UserIsolationMode = 2
  1178. settingObj.DefaultLogonDomain = strADDomain
  1179. settingObj.ADConnectionsUserName = strADAdmin
  1180. settingObj.ADConnectionsPassword = strADPass
  1181. settingObj.AllowAnonymous = False
  1182. settingObj.Put_()
  1183. End If
  1184. End If
  1185. ' Should we start the site?
  1186. If Not bDontStart Then
  1187. serverObj.Start
  1188. ' If we cannot start the server, check for error stating the port is already in use
  1189. If Err.Number = &H80070034 Or Err.Number = &H80070020 Or Err.Number = &H80070057 Then
  1190. strStatus = UCase(SiteStatus(4)) & " " & L_BindingConflict_ErrorMessage
  1191. Else
  1192. strStatus = UCase(SiteStatus(2))
  1193. End If
  1194. Else
  1195. strStatus = UCase(SiteStatus(4))
  1196. End If
  1197. If (strServer = ".") Then
  1198. strServer = oScriptHelper.GetEnvironmentVar("%COMPUTERNAME%")
  1199. End If
  1200. If (strIP = "") Then strIP = L_AllUnassigned_Text
  1201. If (strISO = "") Then strISO = L_NoISO_Text
  1202. ' Post summary
  1203. WScript.Echo L_Server_Text & Space(14 - Len(L_Server_Text)) & "= " & UCase(strServer)
  1204. WScript.Echo L_SiteName_Text & Space(14 - Len(L_SiteName_Text)) & "= " & strName
  1205. WScript.Echo L_MetabasePath_Message & Space(14 - Len(L_MetabasePath_Message)) & "= " & strSitePath
  1206. WScript.Echo L_IP_Text & Space(14 - Len(L_IP_Text)) & "= " & strIP
  1207. WScript.Echo L_Port_Text & Space(14 - Len(L_Port_Text)) & "= " & strPort
  1208. WScript.Echo L_Root_Text & Space(14 - Len(L_Root_Text)) & "= " & strRoot
  1209. WScript.Echo L_ISO_Text & Space(14 - Len(L_ISO_Text)) & "= " & strISO
  1210. WScript.Echo L_Status_Text& Space(14 - Len(L_Status_Text)) & "= " & strStatus
  1211. CreateFtpSite = intResult
  1212. End Function
  1213. '''''''''''''''''''''''''''
  1214. ' QueryFtpSite
  1215. '''''''''''''''''''''''''''
  1216. Function QueryFtpSite(aArgs)
  1217. Dim Servers, Server, strQuery
  1218. Dim ServerObj, ServiceObj
  1219. Dim i, intResult, firstLen
  1220. Dim bindings, binding
  1221. Dim line, strIP, strPort, strState
  1222. Dim providerObj
  1223. Dim bFirstIteration
  1224. On Error Resume Next
  1225. oScriptHelper.WMIConnect
  1226. If Err.Number Then
  1227. WScript.Echo L_WMIConnect_ErrorMessage
  1228. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1229. QueryFtpSiteStatus = Err.Number
  1230. Exit Function
  1231. End If
  1232. Set providerObj = oScriptHelper.ProviderObj
  1233. intResult = 0
  1234. ' Quick check to see if we have permission
  1235. Set ServiceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  1236. If Err.Number Then
  1237. Select Case Err.Number
  1238. Case &H80070005
  1239. WScript.Echo L_Admin_ErrorMessage
  1240. WScript.Echo L_Admin2_ErrorMessage
  1241. Case Else
  1242. WScript.Echo Err.Description
  1243. End Select
  1244. QueryFtpSite = Err.Number
  1245. Exit Function
  1246. End If
  1247. If (UBound(aArgs) = -1) Then
  1248. strQuery = "select Name, ServerComment, ServerBindings from IIsFtpServerSetting"
  1249. Else
  1250. strQuery = "select Name, ServerComment, ServerBindings from IIsFtpServerSetting where "
  1251. For i = LBound(aArgs) to UBound(aArgs)
  1252. strQuery = strQuery & "(Name='" & aArgs(i) & "' or ServerComment='" & aArgs(i) & "')"
  1253. If (i <> UBound(aArgs)) Then
  1254. strQuery = strQuery & " or "
  1255. End If
  1256. Next
  1257. End If
  1258. ' Semi-sync query. (flags = ForwardOnly Or ReturnImediately = &H30)
  1259. Set Servers = providerObj.ExecQuery(strQuery, , &H30)
  1260. If (Err.Number <> 0) Then
  1261. WScript.Echo L_Query_ErrorMessage
  1262. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  1263. WScript.Quit(Err.Number)
  1264. End If
  1265. bFirstIteration = True
  1266. For Each Server in Servers
  1267. bindings = Server.ServerBindings
  1268. If bFirstIteration Then
  1269. WScript.Echo L_SiteName_Text & " (" & L_MetabasePath_Message & ")" & _
  1270. Space(40 - Len(L_SiteName_Text & L_MetabasePath_Message) + 3) & _
  1271. L_Status_Text & Space(4) & L_IP_Text & Space(14) & L_Port_Text
  1272. WScript.Echo "=============================================================================="
  1273. End If
  1274. ' Get server status from the element instance
  1275. Set ServerObj = providerObj.Get("IIsFtpServer='" & Server.Name & "'")
  1276. strState = UCase(SiteStatus(ServerObj.ServerState))
  1277. If (IsArray(bindings)) Then
  1278. For i = LBound(bindings) to UBound(bindings)
  1279. If (bindings(i).IP = "") Then
  1280. strIP = L_All_Text
  1281. Else
  1282. strIP = bindings(i)
  1283. End If
  1284. strPort = bindings(i).Port
  1285. ' If this is the first binding list, print server comment and server name
  1286. If (i = LBound(bindings)) Then
  1287. firstLen = 40 - Len(Server.ServerComment & Server.Name) + 3
  1288. If (firstLen < 1) Then
  1289. firstLen = 1
  1290. End If
  1291. line = Server.ServerComment & " (" & Server.Name & ")" & _
  1292. Space(firstLen) & strState & _
  1293. Space(10 - Len(strState)) & strIP & Space(16 - Len(strIP)) & strPort
  1294. Else
  1295. line = Space(56) & strIP & Space(16 - Len(strIP)) & strPort
  1296. End If
  1297. WScript.Echo line
  1298. Next
  1299. End If
  1300. bFirstIteration = False
  1301. Next
  1302. If bFirstIteration Then
  1303. WScript.Echo L_SitesNotFound_ErrorMessage
  1304. End If
  1305. End Function