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.

440 lines
12 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_NEWSGROUP = "-g"
  8. L_SWITCH_MAX_RESULTS = "-n"
  9. L_SWITCH_MODERATOR = "-m"
  10. L_SWITCH_DESCRIPTION = "-d"
  11. L_SWITCH_READ_ONLY = "-r"
  12. L_SWITCH_DEFAULT_MODERATOR = "-u"
  13. L_SWITCH_PRETTY_NAME = "-p"
  14. L_SWITCH_CREATION_TIME = "-c"
  15. L_SWITCH_LOADACTIVE = "-a"
  16. L_OP_FIND = "f"
  17. L_OP_ADD = "a"
  18. L_OP_DELETE = "d"
  19. L_OP_GET = "g"
  20. L_OP_SET = "s"
  21. L_OP_LOAD = "l"
  22. L_DESC_PROGRAM = "rgroup - Manipulate NNTP newsgroups"
  23. L_DESC_ADD = "Add a newsgroup"
  24. L_DESC_DELETE = "Delete a newsgroup"
  25. L_DESC_GET = "Get a newsgroup's properties"
  26. L_DESC_SET = "Set a newsgroup's properties"
  27. L_DESC_FIND = "Find newsgroups"
  28. L_DESC_LOAD = "Load groups from active file"
  29. L_DESC_OPERATIONS = "<operations>"
  30. L_DESC_SERVER = "<server> Specify computer to configure"
  31. L_DESC_INSTANCE_ID = "<virtual server id> Specify virtual server id"
  32. L_DESC_NEWSGROUP = "<newsgroup name>"
  33. L_DESC_MAX_RESULTS = "<number of results>"
  34. L_DESC_MODERATOR = "<moderator email address>"
  35. L_DESC_DESCRIPTION = "<newsgroup description>"
  36. L_DESC_READ_ONLY = "<true/false> read-only newsgroup?"
  37. L_DESC_DEFAULT_MODERATOR = "<true/false> moderated by default moderator?"
  38. L_DESC_PRETTY_NAME = "<prettyname> response to LIST PRETTYNAMES"
  39. L_DESC_CREATION_TIME = "<date> Newsgroup creation time"
  40. L_DESC_LOADACTIVE = "<filename> name of active file"
  41. L_DESC_EXAMPLES = "Examples:"
  42. L_DESC_EXAMPLE1 = "rgroup.vbs -t f -g alt.*"
  43. L_DESC_EXAMPLE2 = "rgroup.vbs -t a -g my.new.group"
  44. L_DESC_EXAMPLE3 = "rgroup.vbs -t d -g my.old.group"
  45. L_DESC_EXAMPLE4 = "rgroup.vbs -t s -g my.old.group -p GreatGroup -m [email protected]"
  46. L_DESC_EXAMPLE5 = "rgroup.vbs -t l -a active.txt"
  47. L_STR_GROUP_NAME = "Newsgroup:"
  48. L_STR_GROUP_DESCRIPTION = "Description:"
  49. L_STR_GROUP_MODERATOR = "Moderator:"
  50. L_STR_GROUP_READ_ONLY = "Read only:"
  51. L_STR_GROUP_PRETTY_NAME = "Prettyname:"
  52. L_STR_GROUP_CREATION_TIME = "Creation time:"
  53. L_STR_NUM_MATCHING_GROUPS = "Number of matching groups:"
  54. L_ERR_MUST_ENTER_NEWSGROUP = "You must enter a newsgroup name"
  55. REM
  56. REM END LOCALIZATION
  57. REM
  58. REM
  59. REM --- Globals ---
  60. REM
  61. dim g_dictParms
  62. dim g_admin
  63. set g_dictParms = CreateObject ( "Scripting.Dictionary" )
  64. set g_admin = CreateObject ( "NntpAdm.Groups" )
  65. REM
  66. REM --- Set argument defaults ---
  67. REM
  68. g_dictParms(L_SWITCH_OPERATION) = ""
  69. g_dictParms(L_SWITCH_SERVER) = ""
  70. g_dictParms(L_SWITCH_INSTANCE_ID) = "1"
  71. g_dictParms(L_SWITCH_NEWSGROUP) = ""
  72. g_dictParms(L_SWITCH_MAX_RESULTS) = "1000000"
  73. g_dictParms(L_SWITCH_MODERATOR) = ""
  74. g_dictParms(L_SWITCH_DESCRIPTION) = ""
  75. g_dictParms(L_SWITCH_READ_ONLY) = ""
  76. g_dictParms(L_SWITCH_DEFAULT_MODERATOR) = ""
  77. g_dictParms(L_SWITCH_PRETTY_NAME) = ""
  78. g_dictParms(L_SWITCH_CREATION_TIME) = ""
  79. g_dictParms(L_SWITCH_LOADACTIVE) = ""
  80. REM
  81. REM --- Begin Main Program ---
  82. REM
  83. if NOT ParseCommandLine ( g_dictParms, WScript.Arguments ) then
  84. usage
  85. WScript.Quit ( 0 )
  86. end if
  87. dim strNewsgroup
  88. dim i
  89. dim id
  90. dim index
  91. REM
  92. REM Debug: print out command line arguments:
  93. REM
  94. REM switches = g_dictParms.keys
  95. REM args = g_dictParms.items
  96. REM
  97. REM
  98. REM for i = 0 to g_dictParms.Count - 1
  99. REM WScript.echo switches(i) & " = " & args(i)
  100. REM next
  101. REM
  102. g_admin.Server = g_dictParms(L_SWITCH_SERVER)
  103. g_admin.ServiceInstance = g_dictParms(L_SWITCH_INSTANCE_ID)
  104. strNewsgroup = g_dictParms(L_SWITCH_NEWSGROUP)
  105. strActiveFile = g_dictParms(L_SWITCH_LOADACTIVE)
  106. select case g_dictParms(L_SWITCH_OPERATION)
  107. case L_OP_FIND
  108. REM
  109. REM Find newsgroups:
  110. REM
  111. if strNewsgroup = "" then
  112. WScript.Echo L_ERR_MUST_ENTER_NEWSGROUP
  113. WScript.Quit 0
  114. end if
  115. g_admin.Find strNewsgroup, g_dictParms(L_SWITCH_MAX_RESULTS)
  116. cGroups = g_admin.Count
  117. WScript.Echo L_STR_NUM_MATCHING_GROUPS & " " & cGroups
  118. for i = 0 to cGroups - 1
  119. WScript.Echo g_admin.MatchingGroup ( i )
  120. next
  121. case L_OP_ADD
  122. if strNewsgroup = "" then
  123. WScript.Echo L_ERR_MUST_ENTER_NEWSGROUP
  124. WScript.Quit 0
  125. end if
  126. g_admin.Default
  127. if g_dictParms(L_SWITCH_READ_ONLY) = "" then
  128. g_dictParms(L_SWITCH_READ_ONLY) = FALSE
  129. end if
  130. if g_dictParms(L_SWITCH_DEFAULT_MODERATOR) = "" then
  131. g_dictParms(L_SWITCH_DEFAULT_MODERATOR) = FALSE
  132. end if
  133. if g_dictParms(L_SWITCH_DEFAULT_MODERATOR) then
  134. g_admin.IsModerated = BooleanToBOOL ( TRUE )
  135. elseif g_dictParms(L_SWITCH_MODERATOR) <> "" then
  136. g_admin.IsModerated = BooleanToBOOL ( TRUE )
  137. g_admin.Moderator = g_dictParms(L_SWITCH_MODERATOR)
  138. else
  139. g_admin.IsModerated = BooleanToBOOL ( FALSE )
  140. g_admin.Moderator = ""
  141. end if
  142. g_admin.Newsgroup = strNewsgroup
  143. g_admin.ReadOnly = BooleanToBOOL (g_dictParms (L_SWITCH_READ_ONLY))
  144. g_admin.Description = g_dictParms(L_SWITCH_DESCRIPTION)
  145. g_admin.PrettyName = g_dictParms(L_SWITCH_PRETTY_NAME)
  146. On Error Resume Next
  147. g_admin.Add
  148. if ( Err.Number <> 0 ) then
  149. WScript.echo " Error creating group: " & Err.Description & "(" & Err.Number & ")"
  150. else
  151. PrintNewsgroup g_admin
  152. end if
  153. case L_OP_LOAD
  154. if strActiveFile = "" then
  155. WScript.Echo L_ERR_MUST_ENTER_ACTIVEFILE
  156. WScript.Quit 0
  157. end if
  158. set pFS = WScript.CreateObject("Scripting.FileSystemObject")
  159. set pActiveFile = pFS.GetFile(strActiveFile)
  160. set pActiveFileStream = pActiveFile.OpenAsTextStream()
  161. fInList = 0
  162. WScript.echo "Creating groups:"
  163. while not pActiveFileStream.AtEndOfStream
  164. szLine = pActiveFileStream.ReadLine
  165. Dim rgLine
  166. rgLine = Split(szLine)
  167. if (szLine = ".") then fInList = 0
  168. if (fInList) then
  169. WScript.echo " " & rgLine(0)
  170. g_admin.Default
  171. g_admin.Newsgroup = rgLine(0)
  172. On Error Resume Next
  173. g_admin.Add
  174. if (Err.Number <> 0) then
  175. WScript.echo " Error creating " & rgLine(0) & ": " & Err.Description & "(" & Err.Number & ")"
  176. end if
  177. end if
  178. if (rgLine(0) = "215") then fInList = 1
  179. wend
  180. WScript.echo "Done"
  181. case L_OP_DELETE
  182. if strNewsgroup = "" then
  183. WScript.Echo L_ERR_MUST_ENTER_NEWSGROUP
  184. WScript.Quit 0
  185. end if
  186. On Error Resume Next
  187. g_admin.Remove strNewsgroup
  188. if ( Err.Number <> 0 ) then
  189. WScript.echo " Error deleting group: " & Err.Description & "(" & Err.Number & ")"
  190. end if
  191. case L_OP_GET
  192. if strNewsgroup = "" then
  193. WScript.Echo L_ERR_MUST_ENTER_NEWSGROUP
  194. WScript.Quit 0
  195. end if
  196. On Error Resume Next
  197. g_admin.Get strNewsgroup
  198. if ( Err.Number <> 0 ) then
  199. WScript.echo " Error getting group: " & Err.Descriptino & "(" & Err.Number & ")"
  200. else
  201. PrintNewsgroup g_admin
  202. end if
  203. case L_OP_SET
  204. if strNewsgroup = "" then
  205. WScript.Echo L_ERR_MUST_ENTER_NEWSGROUP
  206. WScript.Quit 0
  207. end if
  208. On Error Resume Next
  209. g_admin.Get strNewsgroup
  210. if ( Err.Number <> 0 ) then
  211. if g_dictParms(L_SWITCH_MODERATOR) = "" then
  212. g_dictParms(L_SWITCH_MODERATOR) = g_admin.Moderator
  213. end if
  214. if g_dictParms(L_SWITCH_DESCRIPTION) = "" then
  215. g_dictParms(L_SWITCH_DESCRIPTION) = g_admin.Description
  216. end if
  217. if g_dictParms(L_SWITCH_READ_ONLY) = "" then
  218. g_dictParms(L_SWITCH_READ_ONLY) = BOOLToBoolean (g_admin.ReadOnly)
  219. end if
  220. if g_dictParms(L_SWITCH_DEFAULT_MODERATOR) = "" then
  221. g_dictParms(L_SWITCH_DEFAULT_MODERATOR) = FALSE
  222. end if
  223. if g_dictParms(L_SWITCH_PRETTY_NAME) = "" then
  224. g_dictParms(L_SWITCH_PRETTY_NAME) = g_admin.PrettyName
  225. end if
  226. if g_dictParms(L_SWITCH_CREATION_TIME) = "" then
  227. g_dictParms(L_SWITCH_CREATION_TIME) = g_admin.CreationTime
  228. end if
  229. if ( g_dictParms(L_SWITCH_DEFAULT_MODERATOR) ) then
  230. g_admin.IsModerated = BooleanToBOOL ( TRUE )
  231. g_admin.Moderator = ""
  232. elseif g_dictParms(L_SWITCH_MODERATOR) <> "" then
  233. g_admin.IsModerated = BooleanToBOOL ( TRUE )
  234. g_admin.Moderator = g_dictParms(L_SWITCH_MODERATOR)
  235. else
  236. g_admin.IsModerated = BooleanToBOOL ( FALSE )
  237. g_admin.Moderator = ""
  238. end if
  239. g_admin.ReadOnly = BooleanToBOOL (g_dictParms (L_SWITCH_READ_ONLY))
  240. g_admin.Description = g_dictParms(L_SWITCH_DESCRIPTION)
  241. g_admin.PrettyName = g_dictParms(L_SWITCH_PRETTY_NAME)
  242. g_admin.CreationTime = g_dictParms(L_SWITCH_CREATION_TIME)
  243. g_admin.Set
  244. PrintNewsgroup g_admin
  245. else
  246. WScript.echo "Error setting group: " & Err.Description & "(" & Err.Number & ")"
  247. end if
  248. case else
  249. usage
  250. end select
  251. WScript.Quit 0
  252. REM
  253. REM --- End Main Program ---
  254. REM
  255. REM
  256. REM ParseCommandLine ( dictParameters, cmdline )
  257. REM Parses the command line parameters into the given dictionary
  258. REM
  259. REM Arguments:
  260. REM dictParameters - A dictionary containing the global parameters
  261. REM cmdline - Collection of command line arguments
  262. REM
  263. REM Returns - Success code
  264. REM
  265. Function ParseCommandLine ( dictParameters, cmdline )
  266. dim fRet
  267. dim cArgs
  268. dim i
  269. dim strSwitch
  270. dim strArgument
  271. fRet = TRUE
  272. cArgs = cmdline.Count
  273. i = 0
  274. do while (i < cArgs)
  275. REM
  276. REM Parse the switch and its argument
  277. REM
  278. if i + 1 >= cArgs then
  279. REM
  280. REM Not enough command line arguments - Fail
  281. REM
  282. fRet = FALSE
  283. exit do
  284. end if
  285. strSwitch = cmdline(i)
  286. i = i + 1
  287. strArgument = cmdline(i)
  288. i = i + 1
  289. REM
  290. REM Add the switch,argument pair to the dictionary
  291. REM
  292. if NOT dictParameters.Exists ( strSwitch ) then
  293. REM
  294. REM Bad switch - Fail
  295. REM
  296. fRet = FALSE
  297. exit do
  298. end if
  299. dictParameters(strSwitch) = strArgument
  300. loop
  301. ParseCommandLine = fRet
  302. end function
  303. REM
  304. REM Usage ()
  305. REM prints out the description of the command line arguments
  306. REM
  307. Sub Usage
  308. WScript.Echo L_DESC_PROGRAM
  309. WScript.Echo vbTab & L_SWITCH_OPERATION & " " & L_DESC_OPERATIONS
  310. WScript.Echo vbTab & vbTab & L_OP_FIND & vbTab & L_DESC_FIND
  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_LOAD & vbTab & L_DESC_LOAD
  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_NEWSGROUP & " " & L_DESC_NEWSGROUP
  319. WScript.Echo vbTab & L_SWITCH_MAX_RESULTS & " " & L_DESC_MAX_RESULTS
  320. WScript.Echo vbTab & L_SWITCH_MODERATOR & " " & L_DESC_MODERATOR
  321. WScript.Echo vbTab & L_SWITCH_DESCRIPTION & " " & L_DESC_DESCRIPTION
  322. WScript.Echo vbTab & L_SWITCH_READ_ONLY & " " & L_DESC_READ_ONLY
  323. WScript.Echo vbTab & L_SWITCH_DEFAULT_MODERATOR & " " & L_DESC_DEFAULT_MODERATOR
  324. WScript.Echo vbTab & L_SWITCH_PRETTY_NAME & " " & L_DESC_PRETTY_NAME
  325. WScript.Echo vbTab & L_SWITCH_CREATION_TIME & " " & L_DESC_CREATION_TIME
  326. WScript.Echo vbTab & L_SWITCH_LOADACTIVE & " " & L_DESC_LOADACTIVE
  327. WScript.Echo
  328. WScript.Echo L_DESC_EXAMPLES
  329. WScript.Echo L_DESC_EXAMPLE1
  330. WScript.Echo L_DESC_EXAMPLE2
  331. WScript.Echo L_DESC_EXAMPLE3
  332. WScript.Echo L_DESC_EXAMPLE4
  333. WScript.Echo L_DESC_EXAMPLE5
  334. end sub
  335. Sub PrintNewsgroup ( admobj )
  336. WScript.Echo L_STR_GROUP_NAME & " " & admobj.Newsgroup
  337. WScript.Echo L_STR_GROUP_DESCRIPTION & " " & admobj.Description
  338. WScript.Echo L_STR_GROUP_MODERATOR & " " & admobj.Moderator
  339. WScript.Echo L_STR_GROUP_READ_ONLY & " " & BOOLToBoolean (admobj.ReadOnly)
  340. WScript.Echo L_STR_GROUP_PRETTY_NAME & " " & admobj.PrettyName
  341. WScript.Echo L_STR_GROUP_CREATION_TIME & " " & admobj.CreationTime
  342. end sub
  343. Function BooleanToBOOL ( b )
  344. if b then
  345. BooleanToBOOL = 1
  346. else
  347. BooleanToBOOL = 0
  348. end if
  349. end function
  350. Function BOOLToBoolean ( b )
  351. BOOLToBoolean = (b = 1)
  352. end function