home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2000 November / VPR0011B.ISO / nec98 / ins1.cab / nntp_rgroup.vbs < prev    next >
Text File  |  1999-12-29  |  12KB  |  441 lines

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