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.

520 lines
16 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_CL_POSTS = "-c"
  8. L_SWITCH_CL_SOFT = "-l"
  9. L_SWITCH_CL_HARD = "-h"
  10. L_SWITCH_FD_POSTS = "-f"
  11. L_SWITCH_FD_SOFT = "-i"
  12. L_SWITCH_FD_HARD = "-j"
  13. L_SWITCH_SMTP_SERVER = "-m"
  14. L_SWITCH_MODERATOR_DOMAIN = "-d"
  15. L_SWITCH_UUCP_NAME = "-u"
  16. L_SWITCH_CTRL_MSGS = "-x"
  17. L_SWITCH_NNTPFILE = "-n"
  18. L_SWITCH_ADMIN_EMAIL = "-a"
  19. L_SWITCH_PICKUP = "-p"
  20. L_SWITCH_FAILED_PICKUP = "-q"
  21. L_SWITCH_DROP = "-e"
  22. L_SWITCH_NEWNEWS = "-b"
  23. L_SWITCH_HONOR_MSGIDS = "-r"
  24. L_SWITCH_PORT = "-o"
  25. L_OP_GET = "g"
  26. L_OP_SET = "s"
  27. L_OP_CREATE = "c"
  28. L_OP_DELETE = "d"
  29. L_DESC_PROGRAM = "rserver - Manipulate NNTP virtual servers"
  30. L_DESC_GET = "Get NNTP virtual server properties"
  31. L_DESC_SET = "Set NNTP virtual server properties"
  32. L_DESC_CREATE = "Create a new NNTP virtual server"
  33. L_DESC_DELETE = "Delete an NNTP virtual server"
  34. L_DESC_OPERATIONS = "<operations>"
  35. L_DESC_SERVER = "<server> Specify computer to configure"
  36. L_DESC_INSTANCE_ID = "<virtual server id> Specify virtual server id"
  37. L_DESC_CL_POSTS = "<true/false> Allow client posts"
  38. L_DESC_CL_SOFT = "soft client post limit in bytes"
  39. L_DESC_CL_HARD = "hard client post limit in bytes"
  40. L_DESC_FD_POSTS = "<true/false> Allow feed posts"
  41. L_DESC_FD_SOFT = "soft feed post limit in bytes"
  42. L_DESC_FD_HARD = "hard feed post limit in bytes"
  43. L_DESC_SMTP_SERVER = "SMTP address for moderated posts"
  44. L_DESC_MODERATOR_DOMAIN = "Domain name for default moderators"
  45. L_DESC_UUCP_NAME = "UUCP name of this server"
  46. L_DESC_CTRL_MSGS = "<true/false> Process control messages"
  47. L_DESC_NNTPFILE = "Internal Nntp server files location"
  48. L_DESC_ADMIN_EMAIL = "Administrator email account"
  49. L_DESC_PICKUP = "Pickup directory"
  50. L_DESC_FAILED_PICKUP = "Failed pickup directory"
  51. L_DESC_DROP = "Drop directory"
  52. L_DESC_NEWNEWS = "<true/false> Disable NEWNEWS command"
  53. L_DESC_HONOR_MSGIDS = "<true/false> Honor client msg IDs"
  54. L_DESC_PORT = "TCP Port for client connections"
  55. L_DESC_EXAMPLES = "Examples:"
  56. L_DESC_EXAMPLE1 = "rserver.vbs -t g -v 1"
  57. L_DESC_EXAMPLE2 = "rserver.vbs -t s -v 1 -c true -l 1000000 -a [email protected]"
  58. L_DESC_EXAMPLE3 = "rserver.vbs -t d -v 3"
  59. L_DESC_EXAMPLE4 = "rserver.vbs -t c -v 2 -n c:\news_content"
  60. L_STR_SERVER_ID = "Virtual server ID:"
  61. L_STR_CL_POSTS = "Allow client posting?"
  62. L_STR_CL_SOFT = "Client soft posting limit:"
  63. L_STR_CL_HARD = "Client hard posting limit:"
  64. L_STR_FD_POSTS = "Allow feed posting?"
  65. L_STR_FD_SOFT = "Feed soft posting limit:"
  66. L_STR_FD_HARD = "Feed hard posting limit:"
  67. L_STR_SMTP_SERVER = "Smtp server:"
  68. L_STR_MODERATOR_DOMAIN = "Default moderator domain:"
  69. L_STR_UUCP_NAME = "UUCP name:"
  70. L_STR_CTRL_MSGS = "Process control messages?"
  71. L_STR_NNTPFILE = "Nntp file location:"
  72. L_STR_ADMIN_EMAIL = "Administrator email address:"
  73. L_STR_PICKUP = "Pickup directory:"
  74. L_STR_FAILED_PICKUP = "Failed pickup directory:"
  75. L_STR_DROP = "Drop directory:"
  76. L_STR_NEWNEWS = "Disable NEWNEWS command?"
  77. L_STR_HONOR_MSGIDS = "Honor client message IDs?"
  78. L_STR_PORT = "TCP Port:"
  79. L_STR_CREATED_VS = "Successfully created the following virtual server:"
  80. L_ERR_INVALID_INSTANCE_ID = "Invalid instance identifier."
  81. L_ERR_CANT_DELETE_INSTANCE_ONE = "You can't delete the default virtual server."
  82. L_ERR_MUST_SPECIFY_NNTPFILE = "You must specify the nntp file location."
  83. L_ERR_INVALID_PORT = "Invalid port number."
  84. REM
  85. REM END LOCALIZATION
  86. REM
  87. REM
  88. REM --- Globals ---
  89. REM
  90. dim g_dictParms
  91. dim g_admin
  92. set g_dictParms = CreateObject ( "Scripting.Dictionary" )
  93. REM
  94. REM --- Set argument defaults ---
  95. REM
  96. g_dictParms(L_SWITCH_OPERATION) = ""
  97. g_dictParms(L_SWITCH_SERVER) = "localhost"
  98. g_dictParms(L_SWITCH_INSTANCE_ID) = "1"
  99. g_dictParms(L_SWITCH_CL_POSTS) = ""
  100. g_dictParms(L_SWITCH_CL_SOFT) = ""
  101. g_dictParms(L_SWITCH_CL_HARD) = ""
  102. g_dictParms(L_SWITCH_FD_POSTS) = ""
  103. g_dictParms(L_SWITCH_FD_SOFT) = ""
  104. g_dictParms(L_SWITCH_FD_HARD) = ""
  105. g_dictParms(L_SWITCH_SMTP_SERVER) = ""
  106. g_dictParms(L_SWITCH_MODERATOR_DOMAIN) = ""
  107. g_dictParms(L_SWITCH_UUCP_NAME) = ""
  108. g_dictParms(L_SWITCH_CTRL_MSGS) = ""
  109. g_dictParms(L_SWITCH_NNTPFILE) = ""
  110. g_dictParms(L_SWITCH_ADMIN_EMAIL) = ""
  111. g_dictParms(L_SWITCH_PICKUP) = ""
  112. g_dictParms(L_SWITCH_FAILED_PICKUP) = ""
  113. g_dictParms(L_SWITCH_DROP) = ""
  114. g_dictParms(L_SWITCH_NEWNEWS) = ""
  115. g_dictParms(L_SWITCH_HONOR_MSGIDS) = ""
  116. g_dictParms(L_SWITCH_PORT) = ""
  117. REM
  118. REM --- Begin Main Program ---
  119. REM
  120. if NOT ParseCommandLine ( g_dictParms, WScript.Arguments ) then
  121. usage
  122. WScript.Quit ( 0 )
  123. end if
  124. REM
  125. REM Debug: print out command line arguments:
  126. REM
  127. REM switches = g_dictParms.keys
  128. REM args = g_dictParms.items
  129. REM
  130. REM
  131. REM for i = 0 to g_dictParms.Count - 1
  132. REM WScript.echo switches(i) & " = " & args(i)
  133. REM next
  134. REM
  135. server = g_dictParms(L_SWITCH_SERVER)
  136. instance = g_dictParms(L_SWITCH_INSTANCE_ID)
  137. if NOT IsNumeric (instance) then
  138. WScript.Echo L_ERR_INVALID_INSTANCE_ID
  139. WScript.Quit 0
  140. end if
  141. select case g_dictParms(L_SWITCH_OPERATION)
  142. case L_OP_GET
  143. On Error Resume Next
  144. set g_admin = CreateAdsiObject ( server, instance )
  145. if ( Err.Number <> 0 ) then
  146. Wscript.echo Err.Number
  147. WScript.echo "Error Getting Instance"
  148. else
  149. PrintVirtualServer g_admin
  150. end if
  151. case L_OP_SET
  152. On Error Resume Next
  153. set g_admin = CreateAdsiObject ( server, instance )
  154. if ( Err.Number <> 0 ) then
  155. Wscript.echo Err.Number
  156. WScript.echo "Error Setting Instance"
  157. else
  158. SetProperties ( g_admin )
  159. end if
  160. On Error Resume Next
  161. g_admin.SetInfo
  162. if ( Err.Number <> 0 ) then
  163. WScript.echo " Error Setting Info: " & Err.Description & "(" & Err.Number & ")"
  164. else
  165. PrintVirtualServer g_admin
  166. end if
  167. On Error Resume Next
  168. g_admin.GetInfo
  169. if ( Err.Number <> 0 ) then
  170. WScript.echo " Error Getting Info: " & Err.Description & "(" & Err.Number & ")"
  171. else
  172. PrintVirtualServer g_admin
  173. end if
  174. case L_OP_CREATE
  175. dim strNntpFile
  176. strNntpFile = g_dictParms ( L_SWITCH_NNTPFILE )
  177. if strNntpFile = "" then
  178. WScript.Echo L_ERR_MUST_SPECIFY_NNTPFILE
  179. WScript.Quit 0
  180. end if
  181. set g_admin = CreateAdsiObject ( server, "" )
  182. On Error Resume Next
  183. set newinst = g_admin.Create ( "IIsNntpServer", instance )
  184. if ( Err.Number <> 0 ) then
  185. Wscript.echo Err.Number
  186. WScript.echo "Error Setting New Instance"
  187. else
  188. PrintVirtualServer g_admin
  189. newinst.Put "ServerBindings", ":119:"
  190. newinst.Put "NewsPickupDirectory", strNntpFile & "\Pickup"
  191. newinst.Put "NewsFailedPickupDirectory", strNntpFile & "\FailedPickup"
  192. newinst.Put "NewsDropDirectory", strNntpFile & "\Drop"
  193. SetProperties ( newinst )
  194. newinst.SetInfo
  195. set newvroot = newinst.Create ( "IIsNntpVirtualDir", "Root" )
  196. newvroot.SetInfo
  197. newvroot.Put "Path", strNntpFile & "\root"
  198. newvroot.Put "AccessFlags", 3
  199. newvroot.SetInfo
  200. WScript.Echo L_STR_CREATED_VS
  201. PrintVirtualServer newinst
  202. end if
  203. case L_OP_DELETE
  204. set g_admin = CreateAdsiObject ( server, "" )
  205. if instance = 1 then
  206. WScript.Echo L_ERR_CANT_DELETE_INSTANCE_ONE
  207. WScript.Quit 0
  208. end if
  209. On Error Resume Next
  210. g_admin.Delete "IIsNntpServer", instance
  211. if ( Err.Number <> 0 ) then
  212. WScript.echo " Error Deleting Info: " & Err.Description & "(" & Err.Number & ")"
  213. else
  214. PrintVirtualServer g_admin
  215. end if
  216. case else
  217. usage
  218. end select
  219. WScript.Quit 0
  220. REM
  221. REM --- End Main Program ---
  222. REM
  223. REM
  224. REM ParseCommandLine ( dictParameters, cmdline )
  225. REM Parses the command line parameters into the given dictionary
  226. REM
  227. REM Arguments:
  228. REM dictParameters - A dictionary containing the global parameters
  229. REM cmdline - Collection of command line arguments
  230. REM
  231. REM Returns - Success code
  232. REM
  233. Function ParseCommandLine ( dictParameters, cmdline )
  234. dim fRet
  235. dim cArgs
  236. dim i
  237. dim strSwitch
  238. dim strArgument
  239. fRet = TRUE
  240. cArgs = cmdline.Count
  241. i = 0
  242. do while (i < cArgs)
  243. REM
  244. REM Parse the switch and its argument
  245. REM
  246. if i + 1 >= cArgs then
  247. REM
  248. REM Not enough command line arguments - Fail
  249. REM
  250. fRet = FALSE
  251. exit do
  252. end if
  253. strSwitch = cmdline(i)
  254. i = i + 1
  255. strArgument = cmdline(i)
  256. i = i + 1
  257. REM
  258. REM Add the switch,argument pair to the dictionary
  259. REM
  260. if NOT dictParameters.Exists ( strSwitch ) then
  261. REM
  262. REM Bad switch - Fail
  263. REM
  264. fRet = FALSE
  265. exit do
  266. end if
  267. dictParameters(strSwitch) = strArgument
  268. loop
  269. ParseCommandLine = fRet
  270. end function
  271. REM
  272. REM Usage ()
  273. REM prints out the description of the command line arguments
  274. REM
  275. Sub Usage
  276. WScript.Echo L_DESC_PROGRAM
  277. WScript.Echo vbTab & L_SWITCH_OPERATION & " " & L_DESC_OPERATIONS
  278. WScript.Echo vbTab & vbTab & L_OP_GET & vbTab & L_DESC_GET
  279. WScript.Echo vbTab & vbTab & L_OP_SET & vbTab & L_DESC_SET
  280. WScript.Echo vbTab & vbTab & L_OP_CREATE & vbTab & L_DESC_CREATE
  281. WScript.Echo vbTab & vbTab & L_OP_DELETE & vbTab & L_DESC_DELETE
  282. WScript.Echo vbTab & L_SWITCH_SERVER & " " & L_DESC_SERVER
  283. WScript.Echo vbTab & L_SWITCH_INSTANCE_ID & " " & L_DESC_INSTANCE_ID
  284. WScript.Echo vbTab & L_SWITCH_CL_POSTS & " " & L_DESC_CL_POSTS
  285. WScript.Echo vbTab & L_SWITCH_CL_SOFT & " " & L_DESC_CL_SOFT
  286. WScript.Echo vbTab & L_SWITCH_CL_HARD & " " & L_DESC_CL_HARD
  287. WScript.Echo vbTab & L_SWITCH_FD_POSTS & " " & L_DESC_FD_POSTS
  288. WScript.Echo vbTab & L_SWITCH_FD_SOFT & " " & L_DESC_FD_SOFT
  289. WScript.Echo vbTab & L_SWITCH_FD_HARD & " " & L_DESC_FD_HARD
  290. WScript.Echo vbTab & L_SWITCH_SMTP_SERVER & " " & L_DESC_SMTP_SERVER
  291. WScript.Echo vbTab & L_SWITCH_MODERATOR_DOMAIN & " " & L_DESC_MODERATOR_DOMAIN
  292. WScript.Echo vbTab & L_SWITCH_UUCP_NAME & " " & L_DESC_UUCP_NAME
  293. WScript.Echo vbTab & L_SWITCH_CTRL_MSGS & " " & L_DESC_CTRL_MSGS
  294. WScript.Echo vbTab & L_SWITCH_NNTPFILE & " " & L_DESC_NNTPFILE
  295. WScript.Echo vbTab & L_SWITCH_ADMIN_EMAIL & " " & L_DESC_ADMIN_EMAIL
  296. WScript.Echo vbTab & L_SWITCH_PICKUP & " " & L_DESC_PICKUP
  297. WScript.Echo vbTab & L_SWITCH_FAILED_PICKUP & " " & L_DESC_FAILED_PICKUP
  298. WScript.Echo vbTab & L_SWITCH_DROP & " " & L_DESC_DROP
  299. WScript.Echo vbTab & L_SWITCH_NEWNEWS & " " & L_DESC_NEWNEWS
  300. WScript.Echo vbTab & L_SWITCH_HONOR_MSGIDS & " " & L_DESC_HONOR_MSGIDS
  301. WScript.Echo vbTab & L_SWITCH_PORT & " " & L_DESC_PORT
  302. WScript.Echo
  303. WScript.Echo L_DESC_EXAMPLES
  304. WScript.Echo L_DESC_EXAMPLE1
  305. WScript.Echo L_DESC_EXAMPLE2
  306. WScript.Echo L_DESC_EXAMPLE3
  307. end sub
  308. Sub PrintVirtualServer ( admobj )
  309. dim strNntpFile
  310. strNntpFile = admobj.Get ( "ArticleTableFile" )
  311. WScript.Echo L_STR_SERVER_ID & " " & admobj.Name
  312. WScript.Echo L_STR_CL_POSTS & " " & admobj.Get ( "AllowClientPosts" )
  313. WScript.Echo L_STR_CL_SOFT & " " & admobj.Get ( "ClientPostSoftLimit" )
  314. WScript.Echo L_STR_CL_HARD & " " & admobj.Get ( "ClientPostHardLimit" )
  315. WScript.Echo L_STR_FD_POSTS & " " & admobj.Get ( "AllowFeedPosts" )
  316. WScript.Echo L_STR_FD_SOFT & " " & admobj.Get ( "FeedPostSoftLimit" )
  317. WScript.Echo L_STR_FD_HARD & " " & admobj.Get ( "FeedPostHardLimit" )
  318. WScript.Echo L_STR_SMTP_SERVER & " " & admobj.Get ( "SmtpServer" )
  319. WScript.Echo L_STR_MODERATOR_DOMAIN & " " & admobj.Get ( "DefaultModeratorDomain" )
  320. WScript.Echo L_STR_UUCP_NAME & " " & admobj.Get ( "NntpUucpName" )
  321. WScript.Echo L_STR_CTRL_MSGS & " " & admobj.Get ( "AllowControlMsgs" )
  322. WScript.Echo L_STR_ADMIN_EMAIL & " " & admobj.Get ( "AdminEmail" )
  323. WScript.Echo L_STR_PICKUP & " " & admobj.Get ( "NewsPickupDirectory" )
  324. WScript.Echo L_STR_FAILED_PICKUP & " " & admobj.Get ( "NewsFailedPickupDirectory" )
  325. WScript.Echo L_STR_DROP & " " & admobj.Get ( "NewsDropDirectory" )
  326. WScript.Echo L_STR_NEWNEWS & " " & admobj.Get ( "DisableNewnews" )
  327. WScript.Echo L_STR_HONOR_MSGIDS & " " & admobj.Get ( "HonorClientMsgIds" )
  328. WScript.Echo L_STR_NNTPFILE & " " & StripFileNameFromPath ( strNntpFile )
  329. WScript.Echo L_STR_PORT & " " & ExtractPortFromBinding ( admobj.Get ( "ServerBindings") ( 0 ) )
  330. end sub
  331. Sub SetProperties ( admobj )
  332. SetProp admobj, g_dictParms(L_SWITCH_CL_POSTS), "AllowClientPosts", TRUE
  333. SetProp admobj, g_dictParms(L_SWITCH_CL_SOFT), "ClientPostSoftLimit", FALSE
  334. SetProp admobj, g_dictParms(L_SWITCH_CL_HARD), "ClientPostHardLimit", FALSE
  335. SetProp admobj, g_dictParms(L_SWITCH_FD_POSTS), "AllowFeedPosts", TRUE
  336. SetProp admobj, g_dictParms(L_SWITCH_FD_SOFT), "FeedPostSoftLimit", FALSE
  337. SetProp admobj, g_dictParms(L_SWITCH_FD_HARD), "FeedPostHardLimit", FALSE
  338. SetProp admobj, g_dictParms(L_SWITCH_SMTP_SERVER), "SmtpServer", FALSE
  339. SetProp admobj, g_dictParms(L_SWITCH_MODERATOR_DOMAIN), "DefaultModeratorDomain", FALSE
  340. SetProp admobj, g_dictParms(L_SWITCH_UUCP_NAME), "NntpUucpName", FALSE
  341. SetProp admobj, g_dictParms(L_SWITCH_CTRL_MSGS), "AllowControlMsgs", TRUE
  342. SetProp admobj, g_dictParms(L_SWITCH_ADMIN_EMAIL), "AdminEmail", FALSE
  343. SetProp admobj, g_dictParms(L_SWITCH_PICKUP), "NewsPickupDirectory", FALSE
  344. SetProp admobj, g_dictParms(L_SWITCH_FAILED_PICKUP), "NewsFailedPickupDirectory", FALSE
  345. SetProp admobj, g_dictParms(L_SWITCH_DROP), "NewsDropDirectory", FALSE
  346. SetProp admobj, g_dictParms(L_SWITCH_NEWNEWS), "DisableNewnews", TRUE
  347. SetProp admobj, g_dictParms(L_SWITCH_HONOR_MSGIDS), "HonorClientMsgIds", TRUE
  348. dim port
  349. dim bindings
  350. dim IpAddress
  351. port = g_dictParms(L_SWITCH_PORT)
  352. if port <> "" then
  353. if NOT IsNumeric ( port ) then
  354. WScript.Echo L_ERR_INVALID_PORT
  355. WScript.Quit 0
  356. end if
  357. bindings = admobj.GetEx ( "ServerBindings" )
  358. if IsEmpty ( bindings ) then
  359. bindings = Array ( "" )
  360. IpAddress = ""
  361. else
  362. IpAddress = ExtractIpAddressFromBinding ( bindings(0) )
  363. end if
  364. bindings(0) = IpAddress & ":" & port & ":"
  365. admobj.PutEx 2, "ServerBindings", bindings
  366. end if
  367. dim strNntpFile
  368. strNntpFile = g_dictParms ( L_SWITCH_NNTPFILE )
  369. if strNntpFile <> "" then
  370. SetProp admobj, strNntpFile & "\descrip.txt", "GroupHelpFile", FALSE
  371. SetProp admobj, strNntpFile & "\group.lst", "GroupListFile", FALSE
  372. SetProp admobj, strNntpFile & "\article.hsh", "ArticleTableFile", FALSE
  373. SetProp admobj, strNntpFile & "\history.hsh", "HistoryTableFile", FALSE
  374. SetProp admobj, strNntpFile & "\moderatr.txt", "ModeratorFile", FALSE
  375. SetProp admobj, strNntpFile & "\xover.hsh", "XoverTableFile", FALSE
  376. SetProp admobj, strNntpFile & "\prettynm.txt", "PrettyNamesFile", FALSE
  377. end if
  378. end sub
  379. sub SetProp ( admobj, value, prop, isbool )
  380. REM
  381. REM Debug code: print out the setting of values:
  382. REM
  383. REM WScript.Echo "Setting " & prop & " = " & value
  384. REM
  385. if value <> "" then
  386. if isbool then
  387. admobj.Put prop, CBool (value)
  388. else
  389. admobj.Put prop, (value)
  390. end if
  391. end if
  392. end sub
  393. Function CreateAdsiObject ( strMachine, dwInstance )
  394. dim strObject
  395. dim obj
  396. if dwInstance <> "" then
  397. strObject = "IIS://" & strMachine & "/NntpSvc/" & dwInstance
  398. else
  399. strObject = "IIS://" & strMachine & "/NntpSvc"
  400. end if
  401. On Error Resume Next
  402. set CreateAdsiObject = GetObject ( strObject )
  403. if ( Err.Number <> 0 ) then
  404. WScript.echo " Error Getting Info: " & Err.Description & "(" & Err.Number & ")"
  405. else
  406. REM PrintVirtualServer g_admin
  407. end if
  408. end function
  409. Function StripFileNameFromPath ( strPath )
  410. dim i
  411. i = InStrRev ( strPath, "\" )
  412. StripFileNameFromPath = Left ( strPath, i - 1 )
  413. end function
  414. Function ExtractPortFromBinding ( strBinding )
  415. dim SplitArray
  416. SplitArray = split ( strBinding, ":" )
  417. ExtractPortFromBinding = SplitArray ( 1 )
  418. end function
  419. Function ExtractIpAddressFromBinding ( strBinding )
  420. dim SplitArray
  421. SplitArray = split ( strBinding, ":" )
  422. ExtractIpAddressFromBinding = SplitArray ( 0 )
  423. end function