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.

475 lines
13 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_VROOT_NAME = "-n"
  8. L_SWITCH_VROOT_PATH = "-p"
  9. L_SWITCH_ALLOW_CLIENT_POSTING = "-c"
  10. L_SWITCH_RESTRICT_VISIBILITY = "-r"
  11. L_SWITCH_LOG_ACCESS = "-a"
  12. L_SWITCH_INDEX_NEWS_CONTENT = "-i"
  13. L_SWITCH_TYPE_OF_SYSTEM = "-x"
  14. REM L_OP_FIND = "f"
  15. L_OP_ADD = "a"
  16. L_OP_DELETE = "d"
  17. L_OP_GET = "g"
  18. L_OP_SET = "s"
  19. L_DESC_PROGRAM = "rvirdir - Manipulate NNTP Virtual Directories"
  20. L_DESC_ADD = "Add a Virtual Directory"
  21. L_DESC_DELETE = "Delete a Virtual Directory"
  22. L_DESC_GET = "Get a Virtual Directory's properties"
  23. L_DESC_SET = "Set a Virtual Directory's properties"
  24. REM L_DESC_FIND = "Find a Virtual Directory"
  25. L_DESC_OPERATIONS = "<operations>"
  26. L_DESC_SERVER = "<server> Specify computer to configure"
  27. L_DESC_INSTANCE_ID = "<virtual server id> Specify virtual server id"
  28. L_DESC_VROOT_NAME = "<virtual directory name> name of newsgroup(s) virtual directory includes"
  29. L_DESC_VROOT_PATH = "<virtual directory path>"
  30. L_DESC_ALLOW_CLIENT_POSTING = "<true/false> allow client posting"
  31. L_DESC_RESTRICT_VISIBILITY = "<false/true> restrict newsgroup visibility"
  32. L_DESC_LOG_ACCESS = "<true/false> log access"
  33. L_DESC_INDEX_NEWS_CONTENT = "<true/false> index news content"
  34. L_DESC_TYPE_OF_SYSTEM = "<fs/ex> Specify File System (fs) or Exchange Store (ex)"
  35. L_DESC_EXAMPLES = "Examples:"
  36. L_DESC_EXAMPLE1 = "rvirdir.vbs -t g -n rec.sports"
  37. L_DESC_EXAMPLE2 = "rvirdir.vbs -t a -n rec.sports -p c:\vroot\rec\sports"
  38. L_DESC_EXAMPLE3 = "rvirdir.vbs -t d -d my.old.vroot"
  39. L_STR_VROOT_NAME = "Virtual Directory:"
  40. L_STR_VROOT_PATH = "Path:"
  41. L_STR_VROOT_ALLOW_CLIENT_POSTING = "Allow Client Posting:"
  42. L_STR_VROOT_RESTRICT_VISIBILITY = "Restrict Newsgroup Visibility:"
  43. L_STR_VROOT_LOG_ACCESS = "Log Access:"
  44. L_STR_VROOT_INDEX_NEWS_CONTENT = "Index News Content:"
  45. L_STR_NUM_MATCHING_VIRTUAL_DIRETORY = "The Number of matching Virtual Roots is:"
  46. L_STR_TYPE_OF_VROOT_SYSTEM = "The Vroot is:"
  47. L_ERR_MUST_ENTER_VIRTUAL_DIRECTORY = "You must enter a virtual directory name"
  48. REM
  49. REM END LOCALIZATION
  50. REM
  51. REM
  52. REM --- Globals ---
  53. REM
  54. dim g_dictParms
  55. dim g_admin
  56. dim g_vroot
  57. set g_dictParms = CreateObject ( "Scripting.Dictionary" )
  58. set g_admin = CreateObject ( "NntpAdm.VirtualServer" )
  59. set g_vroot = CreateObject ( "NntpAdm.VirtualRoot" )
  60. REM
  61. REM --- Set argument defaults ---
  62. REM
  63. g_dictParms(L_SWITCH_OPERATION) = ""
  64. g_dictParms(L_SWITCH_SERVER) = ""
  65. g_dictParms(L_SWITCH_INSTANCE_ID) = "1"
  66. g_dictParms(L_SWITCH_VROOT_NAME) = ""
  67. g_dictParms(L_SWITCH_VROOT_PATH) = ""
  68. g_dictParms(L_SWITCH_ALLOW_CLIENT_POSTING) = TRUE
  69. g_dictParms(L_SWITCH_RESTRICT_VISIBILITY) = FALSE
  70. g_dictParms(L_SWITCH_LOG_ACCESS ) = TRUE
  71. g_dictParms(L_SWITCH_INDEX_NEWS_CONTENT) = TRUE
  72. g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "fs"
  73. REM
  74. REM --- Begin Main Program ---
  75. REM
  76. if NOT ParseCommandLine ( g_dictParms, WScript.Arguments ) then
  77. usage
  78. WScript.Quit ( 0 )
  79. end if
  80. dim vroot
  81. dim vparm
  82. dim strVirDir
  83. dim i
  84. dim id
  85. dim index
  86. dim g_vroots
  87. dim g_vrootitem
  88. REM
  89. REM
  90. REM Debug: print out command line arguments:
  91. REM
  92. REM switches = g_dictParms.keys
  93. REM args = g_dictParms.items
  94. REM
  95. REM
  96. REM for i = 0 to g_dictParms.Count - 1
  97. REM WScript.echo switches(i) & " = " & args(i)
  98. REM next
  99. REM
  100. g_admin.Server = g_dictParms(L_SWITCH_SERVER)
  101. g_admin.ServiceInstance = g_dictParms(L_SWITCH_INSTANCE_ID)
  102. strVirDir = g_dictParms(L_SWITCH_VROOT_NAME)
  103. set g_vroots = g_admin.VirtualRoots
  104. g_vroots.Enumerate
  105. REM WScript.echo g_vroots.Count
  106. REM WScript.echo g_vroots.Find
  107. select case g_dictParms(L_SWITCH_OPERATION)
  108. REM case L_OP_FIND
  109. REM REM
  110. REM REM Find virtual directory:
  111. REM REM
  112. REM
  113. REM if strVirDir = "" then
  114. REM WScript.Echo L_ERR_MUST_ENTER_VIRTUAL_DIRECTORY
  115. REM WScript.Quit 0
  116. REM end if
  117. REM
  118. REM vparm = g_vroots.Find (strVirDir)
  119. REM Wscript.Echo vparm
  120. REM vroot = g_vroots.Item (vparm)
  121. REM WScript.Echo vroot
  122. REM g_vroot.Directory
  123. REM
  124. REM cVroots = g_vroots.Count
  125. REM
  126. REM WScript.Echo L_STR_NUM_MATCHING_VIRTUAL_DIRETORY & " " & cVroots - 1
  127. REM
  128. REM for i = 0 to cVroots - 1
  129. REM
  130. REM WScript.Echo g_voots.Enumerate
  131. REM
  132. REM next
  133. REM
  134. case L_OP_ADD
  135. if strVirDir = "" then
  136. WScript.Echo L_ERR_MUST_ENTER_VIRTUAL_DIRECTORY
  137. WScript.Quit 0
  138. end if
  139. if g_dictParms(L_SWITCH_ALLOW_CLIENT_POSTING) = "" then
  140. g_dictParms(L_SWITCH_ALLOW_CLIENT_POSTING) = TRUE
  141. end if
  142. if g_dictParms(L_SWITCH_RESTRICT_VISIBILITY) = "" then
  143. g_dictParms(L_SWITCH_RESTRICT_VISIBILITY) = FALSE
  144. end if
  145. if g_dictParms(L_SWITCH_LOG_ACCESS) = "" then
  146. g_dictParms(L_SWITCH_LOG_ACCESS) = TRUE
  147. end if
  148. if g_dictParms(L_SWITCH_INDEX_NEWS_CONTENT) = "" then
  149. g_dictParms(L_SWITCH_INDEX_NEWS_CONTENT) = TRUE
  150. end if
  151. if g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "" then
  152. g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "NNTP.FSPrepare"
  153. elseif g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "fs" then
  154. g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "NNTP.FSPrepare"
  155. elseif g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "ex" then
  156. g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "NNTP.ExDriverPrepare"
  157. else
  158. Wscript.Echo "Enter either [fs] or [ex] with the -x option"
  159. end if
  160. g_vroot.NewsgroupSubtree = strVirDir
  161. g_vroot.Directory = g_dictParms (L_SWITCH_VROOT_PATH)
  162. g_vroot.GroupPropFile = g_dictParms (L_SWITCH_VROOT_PATH)
  163. g_vroot.AllowPosting = BooleanToBOOL (g_dictParms(L_SWITCH_ALLOW_CLIENT_POSTING))
  164. g_vroot.RestrictGroupVisibility = BooleanToBOOL (g_dictParms(L_SWITCH_RESTRICT_VISIBILITY))
  165. g_vroot.LogAccess = BooleanToBOOL (g_dictParms(L_SWITCH_LOG_ACCESS))
  166. g_vroot.IndexContent = BooleanToBOOL (g_dictParms(L_SWITCH_INDEX_NEWS_CONTENT))
  167. g_vroot.GroupPropFile = g_dictParms (L_SWITCH_VROOT_PATH)
  168. g_vroot.DriverProgId = g_dictParms(L_SWITCH_TYPE_OF_SYSTEM)
  169. On Error Resume Next
  170. g_vroots.Add g_vroot
  171. if ( Err.Number <> 0 ) then
  172. WScript.echo " Error creating group: " & Err.Description & "(" & Err.Number & ")"
  173. else
  174. PrintVirturalDirectory (g_vroot)
  175. end if
  176. case L_OP_DELETE
  177. if strVirDir = "" then
  178. WScript.Echo L_ERR_MUST_ENTER_VIRTUAL_DIRECTORY
  179. WScript.Quit 0
  180. end if
  181. On Error Resume Next
  182. vparm = g_vroots.Find (strVirDir)
  183. g_vroots.Remove vparm
  184. if ( Err.Number <> 0 ) then
  185. WScript.echo " Error deleting group: " & Err.Description & "(" & Err.Number & ")"
  186. else
  187. Wscript.Echo "Virtual Root " & strVirDir & " has been removed."
  188. end if
  189. case L_OP_GET
  190. if strVirDir = "" then
  191. WScript.Echo L_ERR_MUST_ENTER_VIRTUAL_DIRECTORY
  192. WScript.Quit 0
  193. end if
  194. On Error Resume Next
  195. i = g_vroots.Find (strVirDir)
  196. set g_vroot = g_vroots.Item (i)
  197. if ( Err.Number <> 0 ) then
  198. WScript.echo " Error getting group: " & Err.Description & "(" & Err.Number & ")"
  199. else
  200. PrintVirturalDirectory (g_vroot)
  201. end if
  202. case L_OP_SET
  203. if strVirDir = "" then
  204. WScript.Echo L_ERR_MUST_ENTER_VIRTUAL_DIRECTORY
  205. WScript.Quit 0
  206. end if
  207. On Error Resume Next
  208. WScript.Echo "I'm Changing the " & g_dictParms(L_SWITCH_VROOT_NAME) & " Vroot to:"
  209. WScript.Echo
  210. i = g_vroots.Find (strVirDir)
  211. set g_vroot = g_vroots.Item (i)
  212. if ( Err.Number <> 0 ) then
  213. WScript.echo "Error setting group: " & Err.Description & "(" & Err.Number & ")"
  214. else
  215. if g_dictParms(L_SWITCH_VROOT_NAME) = "" then
  216. g_dictParms(L_SWITCH_VROOT_NAME) = g_vroot.NewsgroupSubtree
  217. end if
  218. if g_dictParms(L_SWITCH_VROOT_PATH) = "" then
  219. g_dictParms(L_SWITCH_VROOT_PATH) = g_vroot.Directory
  220. g_dictParms(L_SWITCH_VROOT_PATH) = g_vroot.GroupPropFile
  221. end if
  222. if g_dictParms(L_SWITCH_ALLOW_CLIENT_POSTING) = "" then
  223. g_dictParms(L_SWITCH_ALLOW_CLIENT_POSTING) = g_vroot.AllowPosting
  224. end if
  225. if g_dictParms(L_SWITCH_RESTRICT_VISIBILITY) = "" then
  226. g_dictParms(L_SWITCH_RESTRICT_VISIBILITY) = g_vroot.RestrictGroupVisibility
  227. end if
  228. if g_dictParms(L_SWITCH_LOG_ACCESS) = "" then
  229. g_dictParms(L_SWITCH_LOG_ACCESS) = g_vroot.LogAccess
  230. end if
  231. if g_dictParms(L_SWITCH_INDEX_NEWS_CONTENT) = "" then
  232. g_dictParms(L_SWITCH_INDEX_NEWS_CONTENT) = g_vroot.IndexContent
  233. end if
  234. if g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "" then
  235. g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = g_vroot.DriverProgId
  236. elseif g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "fs" then
  237. g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "NNTP.FSPrepare"
  238. elseif g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "ex" then
  239. g_dictParms(L_SWITCH_TYPE_OF_SYSTEM) = "NNTP.ExDriverPrepare"
  240. end if
  241. g_vroot.NewsgroupSubtree = g_dictParms(L_SWITCH_VROOT_NAME)
  242. g_vroot.Directory = g_dictParms(L_SWITCH_VROOT_PATH)
  243. g_vroot.GroupPropFile = g_dictParms(L_SWITCH_VROOT_PATH)
  244. g_vroot.AllowPosting = BooleanToBOOL (g_dictParms(L_SWITCH_ALLOW_CLIENT_POSTING))
  245. g_vroot.RestrictGroupVisibility = BooleanToBOOL (g_dictParms(L_SWITCH_RESTRICT_VISIBILITY))
  246. g_vroot.LogAccess = BooleanToBOOL (g_dictParms(L_SWITCH_LOG_ACCESS))
  247. g_vroot.IndexContent = BooleanToBOOL (g_dictParms(L_SWITCH_INDEX_NEWS_CONTENT))
  248. g_vroot.DriverProgId = g_dictParms(L_SWITCH_TYPE_OF_SYSTEM)
  249. end if
  250. On Error Resume Next
  251. g_vroots.Set i, g_vroot
  252. if ( Err.Number <> 0 ) then
  253. WScript.echo "You probably entered an invalid Virtual Root."
  254. else
  255. PrintVirturalDirectory g_vroot
  256. end if
  257. case else
  258. usage
  259. end select
  260. WScript.Quit 0
  261. REM
  262. REM --- End Main Program ---
  263. REM
  264. REM
  265. REM ParseCommandLine ( dictParameters, cmdline )
  266. REM Parses the command line parameters into the given dictionary
  267. REM
  268. REM Arguments:
  269. REM dictParameters - A dictionary containing the global parameters
  270. REM cmdline - Collection of command line arguments
  271. REM
  272. REM Returns - Success code
  273. REM
  274. Function ParseCommandLine ( dictParameters, cmdline )
  275. dim fRet
  276. dim cArgs
  277. dim i
  278. dim strSwitch
  279. dim strArgument
  280. fRet = TRUE
  281. cArgs = cmdline.Count
  282. i = 0
  283. do while (i < cArgs)
  284. REM
  285. REM Parse the switch and its argument
  286. REM
  287. if i + 1 >= cArgs then
  288. REM
  289. REM Not enough command line arguments - Fail
  290. REM
  291. fRet = FALSE
  292. exit do
  293. end if
  294. strSwitch = cmdline(i)
  295. i = i + 1
  296. strArgument = cmdline(i)
  297. i = i + 1
  298. REM
  299. REM Add the switch,argument pair to the dictionary
  300. REM
  301. if NOT dictParameters.Exists ( strSwitch ) then
  302. REM
  303. REM Bad switch - Fail
  304. REM
  305. fRet = FALSE
  306. exit do
  307. end if
  308. dictParameters(strSwitch) = strArgument
  309. loop
  310. ParseCommandLine = fRet
  311. end function
  312. REM
  313. REM Usage ()
  314. REM prints out the description of the command line arguments
  315. REM
  316. Sub Usage
  317. WScript.Echo L_DESC_PROGRAM
  318. WScript.Echo vbTab & L_SWITCH_OPERATION & " " & L_DESC_OPERATIONS
  319. REM WScript.Echo vbTab & vbTab & L_OP_FIND & vbTab & L_DESC_FIND
  320. WScript.Echo vbTab & vbTab & L_OP_ADD & vbTab & L_DESC_ADD
  321. WScript.Echo vbTab & vbTab & L_OP_DELETE & vbTab & L_DESC_DELETE
  322. WScript.Echo vbTab & vbTab & L_OP_GET & vbTab & L_DESC_GET
  323. WScript.Echo vbTab & vbTab & L_OP_SET & vbTab & L_DESC_SET
  324. WScript.Echo vbTab & L_SWITCH_SERVER & " " & L_DESC_SERVER
  325. WScript.Echo vbTab & L_SWITCH_INSTANCE_ID & " " & L_DESC_INSTANCE_ID
  326. WScript.Echo vbTab & L_SWITCH_VROOT_NAME & " " & L_DESC_VROOT_NAME
  327. WScript.Echo vbTab & L_SWITCH_VROOT_PATH & " " & L_DESC_VROOT_PATH
  328. WScript.Echo vbTab & L_SWITCH_ALLOW_CLIENT_POSTING & " " & L_DESC_ALLOW_CLIENT_POSTING
  329. WScript.Echo vbTab & L_SWITCH_RESTRICT_VISIBILITY & " " & L_DESC_RESTRICT_VISIBILITY
  330. WScript.Echo vbTab & L_SWITCH_LOG_ACCESS & " " & L_DESC_LOG_ACCESS
  331. WScript.Echo vbTab & L_SWITCH_INDEX_NEWS_CONTENT & " " & L_DESC_INDEX_NEWS_CONTENT
  332. WScript.Echo vbTab & L_SWITCH_TYPE_OF_SYSTEM & " " & L_DESC_TYPE_OF_SYSTEM
  333. WScript.Echo
  334. WScript.Echo L_DESC_EXAMPLES
  335. WScript.Echo L_DESC_EXAMPLE1
  336. WScript.Echo L_DESC_EXAMPLE2
  337. WScript.Echo L_DESC_EXAMPLE3
  338. end sub
  339. Sub PrintVirturalDirectory ( g_vroot )
  340. WScript.Echo L_STR_VROOT_NAME & " " & g_vroot.NewsgroupSubtree
  341. WScript.Echo L_STR_VROOT_PATH & " " & g_vroot.Directory
  342. WScript.Echo L_STR_TYPE_OF_VROOT_SYSTEM & " " & g_vroot.DriverProgId
  343. if ( g_vroot.AllowPosting = 1) then
  344. WScript.Echo L_STR_VROOT_ALLOW_CLIENT_POSTING & " = TRUE"
  345. else
  346. WScript.Echo L_STR_VROOT_ALLOW_CLIENT_POSTING & " = FALSE"
  347. end if
  348. if ( g_vroot.RestrictGroupVisibility = 1) then
  349. WScript.Echo L_STR_VROOT_RESTRICT_VISIBILITY & " = TRUE"
  350. else
  351. WScript.Echo L_STR_VROOT_RESTRICT_VISIBILITY & " = FALSE"
  352. end if
  353. if ( g_vroot.LogAccess = 1) then
  354. WScript.Echo L_STR_VROOT_LOG_ACCESS & " = TRUE"
  355. else
  356. WScript.Echo L_STR_VROOT_LOG_ACCESS & " = FALSE"
  357. end if
  358. if ( g_vroot.IndexContent = 1) then
  359. WScript.Echo L_STR_VROOT_INDEX_NEWS_CONTENT & " = TRUE"
  360. else
  361. WScript.Echo L_STR_VROOT_INDEX_NEWS_CONTENT & " = FALSE"
  362. end if
  363. end sub
  364. Function BooleanToBOOL ( b )
  365. if b then
  366. BooleanToBOOL = 1
  367. else
  368. BooleanToBOOL = 0
  369. end if
  370. end function
  371. Function BOOLToBoolean ( b )
  372. BOOLToBoolean = (b = 1)
  373. end function