home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / comm / mail / ems / rexx / localareafix.ems < prev    next >
Encoding:
Text File  |  1993-08-29  |  12.0 KB  |  619 lines

  1. /****************************/
  2. /* Interactive area manager */
  3. /*****************************************/
  4. /* $VER: LocalAreaFix.ems 1.0 (29.07.93) */
  5. /*****************************************/
  6.  
  7. options results
  8. signal on error
  9. signal on syntax
  10.  
  11. if ~show( 'l', "rexxsupport.library" ) then
  12. do
  13.    if ~addlib( "rexxsupport.library", 0, -30, 0 ) then
  14.    do
  15.       say "Could not open rexxsupport.library"
  16.       exit 10
  17.    end
  18. end
  19.  
  20. if ~show( 'l', "ems_rexx.library" ) then
  21. do
  22.    if ~addlib( "ems_rexx.library", 0, -30, 0 ) then
  23.    do
  24.       say "Could not open ems_rexx.library"
  25.       exit 10
  26.    end
  27. end
  28.  
  29.  
  30. /****************************/
  31. /* Initialize some stuff... */
  32. /****************************/
  33. cmds.1 = 'Edit Links (using Node)'
  34. cmds.2 = 'Edit Links (using Area)'
  35. cmds.3 = 'Edit Groups (using a  Node)'
  36. cmds.4 = 'Edit Groups (using an Area)'
  37. cmds.5 = 'Rescan'
  38. cmds.6 = 'Delete Backup Config'
  39. cmds.7 = 'Restore Backup Config'
  40. cmds.0 = 7
  41.  
  42. cfg_names.1  = 'AKAs'      ; cfg_int.1  = 'cfg_aka_ems'
  43. cfg_names.2  = 'Archivers' ; cfg_int.2  = 'cfg_archiver_ems'
  44. cfg_names.3  = 'Areas'     ; cfg_int.3  = 'cfg_area_ems'
  45. cfg_names.4  = 'Domains'   ; cfg_int.4  = 'cfg_domain_ems'
  46. cfg_names.5  = 'Externals' ; cfg_int.5  = 'cfg_external_ems'
  47. cfg_names.6  = 'Links'     ; cfg_int.6  = 'cfg_link_ems'
  48. cfg_names.7  = 'Nodes'     ; cfg_int.7  = 'cfg_node_ems'
  49. cfg_names.8  = 'Routing'   ; cfg_int.8  = 'cfg_routing_ems'
  50. cfg_names.9  = 'Switches'  ; cfg_int.9  = 'cfg_switch_ems'
  51. cfg_names.10 = 'Userlist'  ; cfg_int.10 = 'cfg_userlist_ems'
  52. cfg_names.11 = 'Variables' ; cfg_int.11 = 'cfg_variable_ems'
  53. cfg_names.0  = 11
  54.  
  55.  
  56. call EMS_Nodes( 'nodes'         )
  57. call EMS_Areas( 'areas', 'SORT' )
  58.  
  59.  
  60. do forever
  61.  
  62.    sel = -1
  63.    res = EMS_Do_Choice_Single( 'Choose Section', 'cmds', 'sel' )
  64.  
  65.    if res ~= 'OK' then leave
  66.  
  67.    select
  68.       when sel = 1 then call Cmd_Edit_Links_Node()
  69.       when sel = 2 then call Cmd_Edit_Links_Area()
  70.       when sel = 3 then call Cmd_Edit_Groups_Node()
  71.       when sel = 4 then call Cmd_Edit_Groups_Area()
  72.       when sel = 5 then call Cmd_Rescan()
  73.       when sel = 6 then call Cmd_Delete_Backup_Config()
  74.       when sel = 7 then call Cmd_Restore_Backup_Config()
  75.       otherwise    nop
  76.    end
  77.  
  78. end
  79.  
  80. QuitScript:
  81.  
  82. call EMS_Cfg_Write( 'cfg_area_ems' )
  83. call EMS_Cfg_Write( 'cfg_link_ems' )
  84. call EMS_Cfg_Write( 'cfg_node_ems' )
  85.  
  86. call EMS_FreeScriptData()
  87. return 0
  88.  
  89.  
  90. error:
  91. syntax:
  92.  
  93. error_text = EMS_LastError()
  94.  
  95. if error_text = '' then error_text = rc ErrorText( rc )
  96.  
  97. say '| ***BREAK: error at' sigl error_text
  98.  
  99. call EMS_Cfg_Write( 'cfg_area_ems' )
  100. call EMS_Cfg_Write( 'cfg_link_ems' )
  101. call EMS_Cfg_Write( 'cfg_node_ems' )
  102.  
  103. call EMS_FreeScriptData()
  104. exit rc
  105.  
  106.  
  107.  
  108. Cmd_Edit_Links_Node: procedure EXPOSE areas. nodes.
  109.  
  110.    node = Choose_Node(); if node = '' then return 0
  111.  
  112.    usegroups = Ask_UseGroups()
  113.  
  114.  
  115.    call EMS_Areafix_Node_Links_Get( node, 'actives', 'passives' )
  116.  
  117.    work_areas.0  = 0
  118.    work_status.0 = 0
  119.  
  120.    do i=1 to areas.0
  121.  
  122.       do_add = 0
  123.  
  124.       if EMS_Search_In_Stem( 'actives', areas.i ) ~= 0 then
  125.       do
  126.          status = 'TRUE'
  127.          do_add = 1
  128.       end
  129.       else
  130.       do
  131.          status = 'FALSE'
  132.       end
  133.  
  134.       if usegroups = 0 | EMS_Areafix_Node_MatchGroup( node, areas.i ) = 'TRUE' then do_add = 1
  135.  
  136.       if do_add then
  137.       do
  138.          call EMS_Add_To_Stem( 'work_areas' , areas.i )
  139.          call EMS_Add_To_Stem( 'work_status', status  )
  140.       end
  141.  
  142.    end
  143.  
  144.    res = EMS_Do_Choice_Multi( 'Change Linked Areas For Node' node, 'work_areas', 'work_status' )
  145.  
  146.    if res ~= 'OK' then return 0
  147.  
  148.    actives.0  = 0
  149.  
  150.    do i=1 to work_areas.0
  151.  
  152.       if upper( EMS_Area_Type( areas.i ) ) = 'MAIL' then iterate
  153.  
  154.       if work_status.i = 'TRUE' then call EMS_Add_To_Stem( 'actives', work_areas.i, 'UNIQUE' )
  155.  
  156.    end
  157.  
  158.    call EMS_Areafix_Node_Links_Set( node, 'actives', 'passives' )
  159.  
  160.    return 0
  161.  
  162.  
  163.  
  164. Cmd_Edit_Links_Area: procedure EXPOSE areas. nodes.
  165.  
  166.    area = Choose_Area(); if area = '' then return 0
  167.  
  168.    usegroups = Ask_UseGroups()
  169.  
  170.  
  171.    call EMS_Areafix_Area_Links_Get( area, 'actives', 'passives' )
  172.  
  173.    work_nodes.0  = 0
  174.    work_status.0 = 0
  175.  
  176.    do i=1 to nodes.0
  177.  
  178.       do_add = 0
  179.  
  180.       if EMS_Search_In_Stem( 'actives', nodes.i ) ~= 0 then
  181.       do
  182.          status = 'TRUE'
  183.          do_add = 1
  184.       end
  185.       else
  186.       do
  187.          status = 'FALSE'
  188.       end
  189.  
  190.       if usegroups = 0 | EMS_Areafix_Node_MatchGroup( nodes.i, area ) = 'TRUE' then do_add = 1
  191.  
  192.       if do_add then
  193.       do
  194.          call EMS_Add_To_Stem( 'work_nodes' , nodes.i )
  195.          call EMS_Add_To_Stem( 'work_status', status  )
  196.       end
  197.  
  198.    end
  199.  
  200.    res = EMS_Do_Choice_Multi( 'Change Linked Nodes For Area' area, 'work_nodes', 'work_status' )
  201.  
  202.    if res ~= 'OK' then return 0
  203.  
  204.    actives.0  = 0
  205.  
  206.    do i=1 to work_nodes.0
  207.  
  208.       if work_status.i = 'TRUE' then call EMS_Add_To_Stem( 'actives', work_nodes.i, 'UNIQUE' )
  209.  
  210.    end
  211.  
  212.    call EMS_Areafix_Area_Links_Set( area, 'actives', 'passives' )
  213.  
  214.    return 0
  215.  
  216.  
  217.  
  218. Cmd_Edit_Groups_Node: procedure EXPOSE areas. nodes.
  219.  
  220.    node = Choose_Node(); if node = '' then return 0
  221.  
  222.    groups.0 = 0
  223.  
  224.    do i=1 to areas.0
  225.  
  226.       name  = EMS_Area_Group_Name(  areas.i ); if name = '' then iterate
  227.       level = EMS_Area_Group_Level( areas.i )
  228.  
  229.       call EMS_Add_To_Stem( 'groups', Group_Hash( name , level ), 'UNIQUE' )
  230.  
  231.    end
  232.  
  233.    call EMS_Node_Groups_Get( node, 'node_groups' )
  234.  
  235.    /*   
  236.    ** node_groups.x.0  = Name
  237.    ** node_groups.x.1  = Level
  238.    ** node_groups.x.2  = Flags
  239.    */
  240.    do i=1 to node_groups.0
  241.  
  242.       if node_groups.i.0 = '' then iterate
  243.  
  244.       call EMS_Add_To_Stem( 'groups', Group_Hash( node_groups.i.0, node_groups.i.1 ), 'UNIQUE' )
  245.  
  246.    end
  247.  
  248.  
  249.    call EMS_Sort_Stem( 'groups' )
  250.  
  251.    status.0 = 0
  252.  
  253.    do i=1 to groups.0
  254.  
  255.       status.i = 'FALSE'
  256.  
  257.    end
  258.  
  259.  
  260.    do i=1 to node_groups.0
  261.  
  262.       name = Group_Hash( node_groups.i.0, node_groups.i.1 )
  263.       num  = 0
  264.  
  265.       do forever
  266.  
  267.          num = EMS_Search_In_Stem( 'groups', name, num ); if num = 0 then leave
  268.  
  269.          status.num = 'TRUE'
  270.  
  271.       end
  272.  
  273.    end
  274.  
  275.  
  276.    work_names.0 = groups.0
  277.    do i=1 to groups.0
  278.  
  279.       parse var groups.i name '/' num
  280.  
  281.       num = Extract_Num( num )
  282.  
  283.       work_names.i = name
  284.       work_nums.i  = num
  285.       work_flags.i = ''
  286.  
  287.    end
  288.  
  289.    do i=1 to node_groups.0
  290.  
  291.       num = 0
  292.  
  293.       do forever
  294.  
  295.          num = EMS_Search_In_Stem( 'work_names', node_groups.i.0, num ); if num = 0 then leave
  296.  
  297.          if work_nums.num = node_groups.i.1 then work_flags.num = node_groups.i.2
  298.  
  299.       end
  300.  
  301.    end
  302.  
  303.  
  304.    call EMS_Calc_Stem_Width( 'work_names', 'ADAPT' )
  305.  
  306.    do i=1 to work_names.0
  307.  
  308.       groups.i = work_names.i '  ' work_nums.i
  309.  
  310.    end
  311.  
  312.    res = EMS_Do_Choice_Multi( 'Change Groups For Node' node, 'groups', 'status' )
  313.  
  314.    if res ~= 'OK' then return 0
  315.  
  316.    node_groups.0 = 0
  317.  
  318.    do i=1 to work_names.0
  319.  
  320.       if status.i = 'FALSE' then iterate
  321.  
  322.       j               = node_groups.0 + 1
  323.       node_groups.0   = j
  324.       node_groups.j.0 = work_names.i
  325.       node_groups.j.1 = work_nums.i
  326.       node_groups.j.2 = work_flags.i
  327.  
  328.    end
  329.  
  330.    call EMS_Node_Groups_Set( node, 'node_groups' )
  331.          
  332.    return 0
  333.  
  334.  
  335.  
  336. Cmd_Edit_Groups_Area: procedure EXPOSE areas. nodes.
  337.  
  338.    area = Choose_Area(); if area = '' then return 0
  339.  
  340.    name  = EMS_Area_Group_Name(  area )
  341.    level = EMS_Area_Group_Level( area )
  342.  
  343.    res = EMS_String_Select( 'Insert New Group Name For' area, 'name'   ); if res ~= 'OK' then return 0
  344.    res = EMS_String_Select( 'Insert New Group Level For' area, 'level' ); if res ~= 'OK' then return 0
  345.  
  346.    call EMS_Area_Group_Name(  area, name  )
  347.    call EMS_Area_Group_Level( area, level )
  348.    
  349.    return 0
  350.  
  351.  
  352.  
  353. Cmd_Rescan: procedure EXPOSE areas. nodes.
  354.  
  355.    area = Choose_Area(); if area = '' then return 0
  356.  
  357.    call EMS_Areafix_Area_Links_Get( area, 'actives' )
  358.  
  359.    if EMS_Do_Request( 'Rescan All?', 'Yes|No' ) = 'Yes' then mode = 'FORCE'
  360.    else                                                      mode = ''
  361.  
  362.    res = EMS_Do_Request( 'How Should I Rescan it?', 'To All|Only A Node' )
  363.  
  364.    if res = 'To All' then
  365.    do
  366.  
  367.       do i=1 to actives.0
  368.  
  369.          call EMS_Tosser_Rescan( area, actives.i, mode )
  370.  
  371.       end
  372.  
  373.    end
  374.    else
  375.    do
  376.  
  377.       sel = -1
  378.       res = EMS_Do_Choice_Single( 'Pick up a node', 'actives', 'sel' )
  379.  
  380.       if res ~= 'OK' then return 0
  381.  
  382.       call EMS_Tosser_Rescan( area, actives.sel, mode )
  383.  
  384.    end
  385.  
  386.    return 0
  387.  
  388.  
  389.  
  390. Cmd_Delete_Backup_Config: procedure EXPOSE cfg_names.
  391.  
  392.    /* Save Current Directory */
  393.    saved_CD = PRAGMA( 'D' )
  394.  
  395.    call PRAGMA( 'D', 'EMS:Config' )
  396.  
  397.    files = showdir( '', 'F' )
  398.  
  399.    do i=1 to cfg_names.0
  400.  
  401.       call Build_Cfg_List( cfg_names.i, files )
  402.  
  403.       if glob_stem.0 = 0 then iterate
  404.  
  405.       status.0 = glob_stem.0
  406.       do j=1 to glob_stem.0
  407.  
  408.          status.j = 'TRUE'
  409.  
  410.       end
  411.  
  412.       res = EMS_Do_Choice_Multi( 'Config "' || cfg_names.i || '"', 'glob_stem', 'status' )
  413.  
  414.       if res = 'OK' then
  415.       do
  416.  
  417.          do j=1 to glob_stem.0
  418.  
  419.             if status.j = 'TRUE' then call Delete( glob_stem.j )
  420.  
  421.          end
  422.  
  423.       end
  424.  
  425.    end
  426.  
  427.    /* Restore Current Directory */
  428.    call PRAGMA( 'D', saved_CD );
  429.  
  430.    return 0
  431.  
  432.  
  433.  
  434. Cmd_Restore_Backup_Config: procedure EXPOSE cfg_names. cfg_int. areas. nodes.
  435.  
  436.    sel = -1
  437.    res = EMS_Do_Choice_Single( 'Choose Config To Restore', 'cfg_names', 'sel' )
  438.  
  439.    if res ~= 'OK' then return 0
  440.  
  441.    /* Save Current Directory */
  442.    saved_CD = PRAGMA( 'D' )
  443.  
  444.    call PRAGMA( 'D', 'EMS:Config' )
  445.  
  446.    files = showdir( '', 'F' )
  447.  
  448.    call Build_Cfg_List( cfg_names.sel, files )
  449.  
  450.    if glob_stem.0 = 0 then
  451.    do
  452.  
  453.       call EMS_Do_Request( 'Nothing to restore', 'Ok' )
  454.  
  455.    end
  456.    else
  457.    do
  458.  
  459.       num = -1
  460.       res = EMS_Do_Choice_Single( 'Pick Up The Config To Restore', 'glob_stem', 'num' )
  461.  
  462.       if res = 'OK' then
  463.       do
  464.  
  465.          max = 0
  466.  
  467.          do i=1 to glob_stem.0
  468.  
  469.             parse var glob_stem.i pre '.' pos
  470.  
  471.             if max < pos then max = pos
  472.  
  473.          end
  474.  
  475.          max = max + 1
  476.  
  477.         call Rename( cfg_names.sel, cfg_names.sel || '.' || max )
  478.         call Rename( glob_stem.num, cfg_names.sel               )
  479.  
  480.         call EMS_Cfg_Read( cfg_int.sel )
  481.  
  482.         if cfg_stem.sel = 'Nodes' then call EMS_Nodes( 'nodes'         )
  483.         if cfg_stem.sel = 'Areas' then call EMS_Areas( 'areas', 'SORT' )
  484.  
  485.       end
  486.  
  487.    end
  488.  
  489.  
  490.  
  491.    files = showdir( '', 'F' )
  492.  
  493.    call Build_Cfg_List( cfg_names.sel, files )
  494.  
  495.    if glob_stem.0 ~= 0 then
  496.    do
  497.  
  498.       do i=1 to glob_stem.0
  499.  
  500.          if glob_stem.i ~= cfg_names.sel || '.' || i then leave
  501.  
  502.       end
  503.  
  504.       if i <= glob_stem.0 then
  505.       do
  506.  
  507.          res = EMS_Do_Request( 'Backup Files Not In Order' || 'A'X || '   Should I Renum Them?  ', 'YES|NO' )
  508.  
  509.          if res = 'YES' then
  510.          do
  511.  
  512.             do i=1 to glob_stem.0
  513.  
  514.                if glob_stem.i = cfg_names.sel || '.' || i then iterate
  515.  
  516.                call Rename( glob_stem.i, cfg_names.sel || '.' || i )
  517.  
  518.             end
  519.  
  520.          end
  521.  
  522.       end
  523.  
  524.    end
  525.  
  526.  
  527.  
  528.    /* Restore Current Directory */
  529.    call PRAGMA( 'D', saved_CD );
  530.  
  531.    return 0
  532.  
  533.  
  534.  
  535. Build_Cfg_List: procedure EXPOSE glob_stem.
  536.  
  537.    parse arg cfg_name, files
  538.  
  539.    glob_stem.0 = 0
  540.  
  541.    do while length( files ) ~= 0
  542.  
  543.       parse var files name files
  544.  
  545.       parse var name pre '.' num
  546.  
  547.       if pre                  ~= cfg_name then iterate
  548.       if datatype( num, 'N' ) ~= 1        then iterate
  549.  
  550.       call EMS_Add_To_Stem( 'glob_stem', copies( '0', 5 - length( num ) ) || num, 'UNIQUE' )
  551.  
  552.    end
  553.  
  554.    call EMS_Sort_Stem( 'glob_stem' )
  555.  
  556.    do i=1 to glob_stem.0
  557.  
  558.       glob_stem.i = cfg_name || '.' || Extract_Num( glob_stem.i )
  559.  
  560.    end
  561.  
  562.    return 0
  563.  
  564.  
  565.  
  566. Extract_Num: procedure
  567.  
  568.    parse arg num
  569.  
  570.    do while left( num, 1 ) = '0'
  571.  
  572.       num = delstr( num, 1, 1 )
  573.  
  574.    end
  575.  
  576.    if num = '' then num = 0
  577.  
  578.    return num
  579.  
  580.  
  581.  
  582. Group_Hash: procedure
  583.  
  584.    parse arg name , level
  585.  
  586.    return name || '/' || copies( '0', 5 - length( level ) ) || level
  587.  
  588.  
  589.  
  590. Choose_Node: procedure EXPOSE nodes.
  591.  
  592.    sel = -1
  593.    res = EMS_Do_Choice_Single( 'Pick up a node', 'nodes', 'sel' )
  594.  
  595.    if res ~= 'OK' then return ''
  596.  
  597.    return nodes.sel
  598.  
  599.  
  600.  
  601. Choose_Area: procedure EXPOSE areas.
  602.  
  603.    sel = -1
  604.    res = EMS_Do_Choice_Single( 'Pick up an area', 'areas', 'sel' )
  605.  
  606.    if res ~= 'OK' then return ''
  607.  
  608.    return areas.sel
  609.  
  610.  
  611.  
  612. Ask_UseGroups: procedure
  613.  
  614.    res = EMS_Do_Request( 'Should I Use Groups To Limit' || 'A'X || '    Visibility Of Areas?    ', 'YES|NO' )
  615.  
  616.    if res = 'YES' then return 1
  617.  
  618.    return 0
  619.