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.

439 lines
10 KiB

  1. REM
  2. REM LOCALIZATION
  3. REM
  4. L_SWITCH_OPERATION = "-t"
  5. L_SWITCH_SERVER = "-s"
  6. L_SWITCH_INSTANCE_ID = "-v"
  7. L_SWITCH_EXPIRE_ID = "-i"
  8. L_SWITCH_TIME = "-h"
  9. L_SWITCH_NEWSGROUPS = "-n"
  10. L_SWITCH_NAME = "-p"
  11. L_SWITCH_ONETIME = "-o"
  12. L_OP_ADD = "a"
  13. L_OP_DELETE = "d"
  14. L_OP_GET = "g"
  15. L_OP_SET = "s"
  16. L_OP_ENUMERATE = "e"
  17. L_DESC_PROGRAM = "rexpire - Set server expiration policies"
  18. L_DESC_ADD = "add expiration policy"
  19. L_DESC_DELETE = "delete expiration policy"
  20. L_DESC_GET = "get expiration policy"
  21. L_DESC_SET = "set expiration policy"
  22. L_DESC_ENUMERATE = "enumerate expiration policies"
  23. L_DESC_OPERATIONS = "<operations>"
  24. L_DESC_SERVER = "<server> Specify computer to configure"
  25. L_DESC_INSTANCE_ID = "<virtual server id> Specify virtual server id"
  26. L_DESC_EXPIRE_ID = "<expire id> Specify expiration policy id"
  27. L_DESC_TIME = "<expire time> Specify number of hours until articles are expired"
  28. L_DESC_NEWSGROUPS = "<newsgroups> Specify newsgroup to which policy is applied"
  29. L_DESC_NAME = "<policy name> Expire policy name"
  30. L_DESC_ONETIME = "[true | false] One time expire policy?"
  31. L_DESC_EXAMPLES = "Examples:"
  32. L_DESC_EXAMPLE1 = "rexpire.vbs -t e -v 1"
  33. L_DESC_EXAMPLE2 = "rexpire.vbs -t a -n alt.binaries.* -h 24"
  34. L_DESC_EXAMPLE3 = "rexpire.vbs -t s -i 1 -h 24"
  35. L_DESC_EXAMPLE4 = "rexpire.vbs -t d -i 1"
  36. L_STR_EXPIRE_NAME = "Name:"
  37. L_STR_EXPIRE_ID = "Expire ID:"
  38. L_STR_EXPIRE_TIME = "Time horizon:"
  39. L_STR_NEWSGROUPS = "Newsgroups:"
  40. L_STR_OLD_POLICY = "Old Policy"
  41. L_STR_NEW_POLICY = "New Policy"
  42. L_ERR_MUST_ENTER_ID = "You must enter an expire policy ID"
  43. L_ERR_EXPIRE_ID_NOT_FOUND = "Error: There is no expiration policy with that ID"
  44. REM
  45. REM END LOCALIZATION
  46. REM
  47. REM
  48. REM --- Globals ---
  49. REM
  50. dim g_dictParms
  51. dim g_admin
  52. set g_dictParms = CreateObject ( "Scripting.Dictionary" )
  53. set g_admin = CreateObject ( "NntpAdm.Expiration" )
  54. REM
  55. REM --- Set argument defaults ---
  56. REM
  57. g_dictParms(L_SWITCH_OPERATION) = ""
  58. g_dictParms(L_SWITCH_SERVER) = ""
  59. g_dictParms(L_SWITCH_INSTANCE_ID) = "1"
  60. g_dictParms(L_SWITCH_EXPIRE_ID) = ""
  61. g_dictParms(L_SWITCH_TIME) = "-1"
  62. g_dictParms(L_SWITCH_NEWSGROUPS) = ""
  63. g_dictParms(L_SWITCH_NAME) = ""
  64. g_dictParms(L_SWITCH_ONETIME) = False
  65. REM
  66. REM --- Begin Main Program ---
  67. REM
  68. if NOT ParseCommandLine ( g_dictParms, WScript.Arguments ) then
  69. usage
  70. WScript.Quit ( 0 )
  71. end if
  72. dim cExpires
  73. dim i
  74. dim id
  75. dim index
  76. REM
  77. REM Debug: print out command line arguments:
  78. REM
  79. REM switches = g_dictParms.keys
  80. REM args = g_dictParms.items
  81. REM
  82. REM
  83. REM for i = 0 to g_dictParms.Count - 1
  84. REM WScript.echo switches(i) & " = " & args(i)
  85. REM next
  86. REM
  87. g_admin.Server = g_dictParms(L_SWITCH_SERVER)
  88. g_admin.ServiceInstance = g_dictParms(L_SWITCH_INSTANCE_ID)
  89. On Error Resume Next
  90. g_admin.Enumerate
  91. if ( Err.Number <> 0 ) then
  92. WScript.echo " Error enumerating Expiration: " & Err.Description & "(" & Err.Number & ")"
  93. end if
  94. id = g_dictParms ( L_SWITCH_EXPIRE_ID )
  95. select case g_dictParms(L_SWITCH_OPERATION)
  96. case L_OP_ENUMERATE
  97. REM
  98. REM List the existing expiration policies:
  99. REM
  100. cExpires = g_admin.Count
  101. for i = 0 to cExpires - 1
  102. On Error Resume Next
  103. g_admin.GetNth i
  104. if ( Err.Number <> 0 ) then
  105. WScript.echo " Error getting Expiration: " & Err.Description & "(" & Err.Number & ")"
  106. else
  107. PrintExpire g_admin
  108. end if
  109. next
  110. case L_OP_ADD
  111. REM
  112. REM Add a new expiration policy
  113. REM
  114. if ( g_dictParms ( L_SWITCH_NEWSGROUPS ) = "" ) then
  115. usage
  116. else
  117. dim strPolicyName
  118. strPolicyName = g_dictParms ( L_SWITCH_NAME )
  119. if ( g_dictParms ( L_SWITCH_ONETIME ) ) then
  120. strPolicyName = strPolicyName & "@EXPIRE:ROADKILL"
  121. end if
  122. g_admin.PolicyName = strPolicyName
  123. g_admin.ExpireTime = g_dictParms ( L_SWITCH_TIME )
  124. g_admin.ExpireSize = "-1"
  125. g_admin.NewsgroupsVariant = SemicolonListToArray ( g_dictParms ( L_SWITCH_NEWSGROUPS ) )
  126. g_admin.Add
  127. PrintExpire g_admin
  128. end if
  129. case L_OP_DELETE
  130. REM
  131. REM Delete an expiration policy
  132. REM
  133. if id = "" OR NOT IsNumeric ( id ) then
  134. WScript.Echo L_ERR_MUST_ENTER_ID
  135. WScript.Quit 0
  136. end if
  137. index = g_admin.FindID ( id )
  138. if index = -1 then
  139. WScript.Echo L_ERR_EXPIRE_ID_NOT_FOUND
  140. WScript.Quit 0
  141. end if
  142. On Error Resume Next
  143. g_admin.Remove id
  144. if ( Err.Number <> 0 ) then
  145. WScript.echo " Error Removing Expiration: " & Err.Description & "(" & Err.Number & ")"
  146. else
  147. PrintExpire g_admin
  148. end if
  149. case L_OP_GET
  150. REM
  151. REM Get a specific expiration policy:
  152. REM
  153. index = g_admin.FindID(id)
  154. if index = -1 then
  155. WScript.Echo L_ERR_EXPIRE_ID_NOT_FOUND
  156. WScript.Quit 0
  157. end if
  158. On Error Resume Next
  159. g_admin.GetNth index
  160. if ( Err.Number <> 0 ) then
  161. WScript.echo " Error getting Expiration: " & Err.Description & "(" & Err.Number & ")"
  162. else
  163. PrintExpire g_admin
  164. end if
  165. case L_OP_SET
  166. REM
  167. REM Change an existing expiration policy:
  168. REM
  169. dim strNewName
  170. dim nNewTime
  171. dim rgNewGroups
  172. index = g_admin.FindID(id)
  173. if index = -1 then
  174. WScript.Echo L_ERR_EXPIRE_ID_NOT_FOUND
  175. WScript.Quit 0
  176. end if
  177. On Error Resume Next
  178. g_admin.GetNth index
  179. if ( Err.Number <> 0 ) then
  180. WScript.echo " Error getting Expiration: " & Err.Description & "(" & Err.Number & ")"
  181. else
  182. WScript.echo L_STR_OLD_POLICY
  183. PrintExpire g_admin
  184. WScript.echo
  185. WScript.echo L_STR_NEW_POLICY
  186. end if
  187. strNewName = g_admin.PolicyName
  188. nNewTime = g_admin.ExpireTime
  189. rgNewGroups = g_admin.NewsgroupsVariant
  190. if g_dictParms ( L_SWITCH_NAME ) <> "" then
  191. strNewName = g_dictParms ( L_SWITCH_NAME )
  192. end if
  193. if g_dictParms ( L_SWITCH_TIME ) <> "" then
  194. nNewTime = g_dictParms ( L_SWITCH_TIME )
  195. end if
  196. if g_dictParms ( L_SWITCH_NEWSGROUPS ) <> "" then
  197. rgNewGroups = SemicolonListToArray ( g_dictParms ( L_SWITCH_NEWSGROUPS ) )
  198. end if
  199. if g_dictParms ( L_SWITCH_ONETIME ) then
  200. strNewName = strNewName & "@EXPIRE:ROADKILL"
  201. end if
  202. g_admin.PolicyName = strNewName
  203. g_admin.ExpireTime = nNewTime
  204. g_admin.NewsgroupsVariant = rgNewGroups
  205. On Error Resume Next
  206. g_admin.Set
  207. if ( Err.Number <> 0 ) then
  208. WScript.echo " Error setting Expiration: " & Err.Description & "(" & Err.Number & ")"
  209. else
  210. PrintExpire g_admin
  211. end if
  212. case else
  213. usage
  214. end select
  215. WScript.Quit 0
  216. REM
  217. REM --- End Main Program ---
  218. REM
  219. REM
  220. REM ParseCommandLine ( dictParameters, cmdline )
  221. REM Parses the command line parameters into the given dictionary
  222. REM
  223. REM Arguments:
  224. REM dictParameters - A dictionary containing the global parameters
  225. REM cmdline - Collection of command line arguments
  226. REM
  227. REM Returns - Success code
  228. REM
  229. Function ParseCommandLine ( dictParameters, cmdline )
  230. dim fRet
  231. dim cArgs
  232. dim i
  233. dim strSwitch
  234. dim strArgument
  235. fRet = TRUE
  236. cArgs = cmdline.Count
  237. i = 0
  238. do while (i < cArgs)
  239. REM
  240. REM Parse the switch and its argument
  241. REM
  242. if i + 1 >= cArgs then
  243. REM
  244. REM Not enough command line arguments - Fail
  245. REM
  246. fRet = FALSE
  247. exit do
  248. end if
  249. strSwitch = cmdline(i)
  250. i = i + 1
  251. strArgument = cmdline(i)
  252. i = i + 1
  253. REM
  254. REM Add the switch,argument pair to the dictionary
  255. REM
  256. if NOT dictParameters.Exists ( strSwitch ) then
  257. REM
  258. REM Bad switch - Fail
  259. REM
  260. fRet = FALSE
  261. exit do
  262. end if
  263. dictParameters(strSwitch) = strArgument
  264. loop
  265. ParseCommandLine = fRet
  266. end function
  267. REM
  268. REM SemicolonListToArray ( strList )
  269. REM Converts a semi colon delimited list to an array of strings
  270. REM
  271. REM eg. str1;str2;str3;str4 -> ["str1", "str2", "str3", "str4"]
  272. REM
  273. Function SemicolonListToArray ( strListIn )
  274. dim rgItems
  275. dim strItem
  276. dim strList
  277. dim index
  278. dim i
  279. ReDim rgItems ( 10 )
  280. strList = strListIn
  281. i = 0
  282. do until strList = ""
  283. REM
  284. REM Debug: print out newsgroup list as we go:
  285. REM WScript.Echo strList
  286. REM
  287. index = InStr ( strList, ";" )
  288. if index = 0 then
  289. REM No trailing ";", so use the whole string
  290. strItem = strList
  291. strList = ""
  292. else
  293. REM Use the string up to the ";"
  294. strItem = Left ( strList, index - 1 )
  295. strList = Right ( strList, Len ( strList ) - index )
  296. end if
  297. ReDim preserve rgItems ( i )
  298. rgItems ( i ) = strItem
  299. i = i + 1
  300. loop
  301. REM return the array
  302. SemicolonListToArray = rgItems
  303. end function
  304. REM
  305. REM Usage ()
  306. REM prints out the description of the command line arguments
  307. REM
  308. Sub Usage
  309. WScript.Echo L_DESC_PROGRAM
  310. WScript.Echo vbTab & L_SWITCH_OPERATION & " " & L_DESC_OPERATIONS
  311. WScript.Echo vbTab & vbTab & L_OP_ADD & vbTab & L_DESC_ADD
  312. WScript.Echo vbTab & vbTab & L_OP_DELETE & vbTab & L_DESC_DELETE
  313. WScript.Echo vbTab & vbTab & L_OP_GET & vbTab & L_DESC_GET
  314. WScript.Echo vbTab & vbTab & L_OP_SET & vbTab & L_DESC_SET
  315. WScript.Echo vbTab & vbTab & L_OP_ENUMERATE & vbTab & L_DESC_ENUMERATE
  316. WScript.Echo vbTab & L_SWITCH_SERVER & " " & L_DESC_SERVER
  317. WScript.Echo vbTab & L_SWITCH_INSTANCE_ID & " " & L_DESC_INSTANCE_ID
  318. WScript.Echo vbTab & L_SWITCH_EXPIRE_ID & " " & L_DESC_EXPIRE_ID
  319. WScript.Echo vbTab & L_SWITCH_TIME & " " & L_DESC_TIME
  320. WScript.Echo vbTab & L_SWITCH_NEWSGROUPS & " " & L_DESC_NEWSGROUPS
  321. WScript.Echo vbTab & L_SWITCH_NAME & " " & L_DESC_NAME
  322. WScript.Echo vbTab & L_SWITCH_ONETIME & " " & L_DESC_ONETIME
  323. WScript.Echo
  324. WScript.Echo L_DESC_EXAMPLES
  325. WScript.Echo L_DESC_EXAMPLE1
  326. WScript.Echo L_DESC_EXAMPLE2
  327. WScript.Echo L_DESC_EXAMPLE3
  328. WScript.Echo L_DESC_EXAMPLE4
  329. end sub
  330. Sub PrintExpire ( admobj )
  331. WScript.Echo L_STR_EXPIRE_ID & " " & admobj.ExpireId
  332. WScript.Echo L_STR_EXPIRE_NAME & " " & admobj.PolicyName
  333. WScript.Echo L_STR_EXPIRE_TIME & " " & admobj.ExpireTime
  334. dim newsgroups
  335. dim cGroups
  336. dim i
  337. newsgroups = admobj.NewsgroupsVariant
  338. cGroups = UBound ( newsgroups )
  339. for i = 0 to cGroups
  340. WScript.Echo L_STR_NEWSGROUPS & " " & newsgroups(i)
  341. next
  342. end sub