home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / inetlg71.zip / inetcfg.cmd < prev    next >
OS/2 REXX Batch file  |  2000-02-10  |  19KB  |  579 lines

  1. /*
  2. inetcfg.cmd
  3. Copyright 2000 by Chuck McKinnis,  Sandia Park, NM (USA) 04 Feb 2000
  4. mckinnis@attglobal.net
  5.  
  6. REXX Program to set parameter for the inetlog.cmd and ijoylog.cmd
  7. and convert existing an existing inetlog.ini file to inetcfg.cfg
  8. */
  9.  
  10. Trace 'N'
  11. version = '7.1'
  12. what_r_we = 'INETCFG  v'||version 'Copyright 2000 by Chuck McKinnis'
  13. Parse Upper Arg otherparms
  14.  
  15. /* Where are we ? */
  16. Parse Source . . install_path .
  17. inetlog_program = install_path
  18. install_path = Filespec('D',install_path) || Filespec('P',install_path)
  19. ini_file = install_path || 'inetlog.ini'
  20. cfg_file = install_path || 'inetcfg.cfg'
  21. cfg_save = install_path || 'inetcfg.sav'
  22. save_path = Directory()
  23. our_path = Strip(install_path, 'T', '\')
  24. our_path = Directory(our_path)
  25. pmrexx_obj = SysSearchPath('PATH', 'PMREXX.EXE')
  26.  
  27. pmrexx = 0
  28. If Wordpos('/PMREXX', otherparms) > 0 Then
  29.    Do
  30.       If pmrexx_obj <> '' Then
  31.          pmrexx = 1
  32.       Else
  33.          Do
  34.             Say 'PMREXX.EXE is not in your current PATH'
  35.             pmrexx = 0
  36.          End
  37.    End
  38. Else
  39.    Do
  40.       If Wordpos('/NOPMREXX', otherparms) = 0 Then
  41.          Do
  42.             If pmrexx_obj <> '' Then
  43.                Do
  44.                   Parse Source . . inetlog_program .
  45.                   Address cmd '@START "Internet Log Configuration" /PM /I' pmrexx_obj inetlog_program otherparms '/PMREXX'
  46.                   Exit 0
  47.                End
  48.             Else
  49.                Do
  50.                   Say 'PMREXX.EXE is not in your current PATH'
  51.                   pmrexx = 0
  52.                End
  53.          End
  54.       pmrexx = 0
  55.    End
  56.  
  57. /* Right to freely use, modify, distribute granted but please acknowledge
  58.    source as a courtesy if you build upon it.  Please pass on comments,
  59.    suggestions, problems to mckinnis@attglobal.net */
  60.  
  61. /* The following are acceptable command-line parameters for special runs.
  62.     Only one of these can be used in a run and case is ignored.
  63.  
  64.       /NOPMREXX run without using PMREXX
  65.  
  66.    The following are acceptable command-line parameters (case is ignored):
  67.  
  68.    These parameters can be overridden on a run by run basis only.
  69.  
  70.       /RESET ini file parameters to defaults and re-initialize
  71.  
  72. */
  73. If Rxfuncquery('SysDropFuncs') Then
  74.    Do
  75.       Call Rxfuncadd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  76.       Call SysLoadFuncs
  77.    End
  78. If Rxfuncquery('RxExtra') Then
  79.    Do
  80.       Call Rxfuncadd 'RxExtra', 'RxExtras', 'RxExtra'
  81.       Call RxExtra 'LOAD'
  82.    End
  83.  
  84. Signal On Failure Name errhandler
  85. Signal On Halt Name errhandler
  86. Signal On Syntax Name errhandler
  87.  
  88. Call SysCls
  89.  
  90. Call Read_config                              /* read the config file */
  91.  
  92. Call Reset_config otherparms           /* check for config file reset */
  93.  
  94. Call Check_config                    /* check for config file updates */
  95.  
  96. Call Write_config                            /* write the config file */
  97.  
  98. Call Cleanup                                   /* end of main program */
  99.  
  100. /* read the config file */
  101. Read_config:
  102. trace_save = Trace('N')
  103. Trace 'N'
  104. If RxFileExists(cfg_file) Then            /* do we have a config file */
  105.    input_file = cfg_file
  106. Else
  107.    Do
  108.       If RxFileExists(cfg_save) Then
  109.          input_file = cfg_save
  110.       Else
  111.          Do
  112.             Call Config_sample               /* use the sample values */
  113.             input_file = 'sample'
  114.          End
  115.    End
  116.  
  117. Say 'Using configuration file -' input_file
  118. If input_file <> 'sample' Then
  119.    Call RxRead 'data.', input_file
  120. Else
  121.    Call RxStemCopy 'cfg_sample.', 'data.'
  122. config. = ''
  123. config.0 = data.0
  124. Do i = 1 To data.0
  125.    config.i = data.i
  126.    If Abbrev(data.i, ';') | Abbrev(data.i, '[') Then
  127.       Nop
  128.    Else
  129.       Do
  130.          Parse Var data.i key_id '=' key_value
  131.          key_id = Strip(key_id)
  132.          key_value = "'" || Strip(key_value) || "'"
  133.          Interpret key_id '=' key_value
  134.       End
  135. End
  136. Call Convert_ini ini_file              /* update from an old ini file */
  137. Trace(trace_save)
  138. Return
  139.  
  140. /* convert or update config using an existing ini file */
  141. Convert_ini:
  142. trace_save = Trace('N')
  143. Trace 'N'
  144. Parse Arg ini_file
  145. If RxFileExists(ini_file) ,
  146.    & File_cmd(ini_file, 'D') > File_cmd(input_file, 'D') Then
  147.    Do
  148.       ini_key = 'IGN InJoy DataPath DisplayDailyReport PauseAsScreenFills' ,
  149.          'WarnPercent ConnectDigits MinuteDigits HourDigits'
  150.       key_key = 'ibm_dialer injoy_dialer data_path daily_report one_screen_at_a_time' ,
  151.          'warn_pct sig_x sig_min sig_hr'
  152.       /* get all keys */
  153.       xrc = SysIni(ini_file, 'COMMON', 'ALL:', 'keys.')
  154.       If keys.0 > 0 Then
  155.          Do i = 1 To keys.0                 /* get all the key values */
  156.             key_id = Word(key_key, Wordpos(keys.i, ini_key))
  157.             key_value = "'" || SysIni(ini_file, 'COMMON', keys.i) || "'"
  158.             Interpret key_id '=' key_value
  159.          End
  160.       ini_key = 'IniFileName OutputFileName SummaryFileName LastTimeStamp'
  161.       key_key = 'ibm_dialer_ini_file ibm_output_file ibm_summary_file ibm_last_time_stamp'
  162.       /* get all keys */
  163.       xrc = SysIni(ini_file, 'INETLOG', 'ALL:', 'keys.')
  164.       If keys.0 > 0 Then
  165.          Do i = 1 To keys.0                 /* get all the key values */
  166.             key_id = Word(key_key, Wordpos(keys.i, ini_key))
  167.             key_value = "'" || SysIni(ini_file, 'INETLOG', keys.i) || "'"
  168.             Interpret key_id '=' key_value
  169.          End
  170.       ini_key = 'InJoyOutput InJoySummary'
  171.       key_key = 'injoy_output_file injoy_summary_file'
  172.       /* get all keys */
  173.       xrc = SysIni(ini_file, 'IJOYLOG', 'ALL:', 'keys.')
  174.       If keys.0 > 0 Then
  175.          Do i = 1 To keys.0                 /* get all the key values */
  176.             key_id = keys.i
  177.             If Wordpos(key_id, ini_key) > 0 Then
  178.                Do
  179.                   key_id = Word(key_key, Wordpos(keys.i, ini_key))
  180.                   key_value = "'" || SysIni(ini_file, 'IJOYLOG', keys.i) || "'"
  181.                   Interpret key_id '=' key_value
  182.                End
  183.          End
  184.       injoy_total_logs = SysIni(ini_file, 'IJOYLOG', 'InJoyLogs')
  185.       log_value = ''
  186.       acct_value = ''
  187.       user_value = ''
  188.       time_value = ''
  189.       Do i = 1 To injoy_total_logs
  190.          key = 'InJoyLog_' || i
  191.          log_value = log_value SysIni(ini_file, 'IJOYLOG', key)
  192.          If log_value = 'ERROR:' Then
  193.             log_value = Word(SysIni(ini_file, 'IJOYLOG', 'InJoyLog'), i)
  194.          key = 'InJoyAcct_' || i
  195.          acct_value = acct_value SysIni(ini_file, 'IJOYLOG', key)
  196.          If acct_value = 'ERROR:' Then
  197.             acct_value = Word(SysIni(ini_file, 'IJOYLOG', 'InJoyAcct'), i)
  198.          key = 'InJoyUser_' || i
  199.          user_value = user_value SysIni(ini_file, 'IJOYLOG', key)
  200.          If user_value = 'ERROR:' Then
  201.             user_value = Word(SysIni(ini_file, 'IJOYLOG', 'InJoyUser'), i)
  202.          key = 'InJoyTimeStamp_' || i
  203.          time_value = time_value SysIni(ini_file, 'IIJOYLOG', key)
  204.          If time_value = 'ERROR:' Then
  205.             time_value = Word(SysIni(ini_file, 'IJOYLOG', 'InJoyTimeStamp'), i)
  206.       End
  207.       key_id = 'injoy_logs'
  208.       Interpret key_id '=' "'" || Strip(log_value) || "'"
  209.       key_id = 'injoy_accts'
  210.       Interpret key_id '=' "'" || Strip(acct_value) || "'"
  211.       key_id = 'injoy_users'
  212.       Interpret key_id '=' "'" || Strip(user_value) || "'"
  213.       key_id = 'injoy_times'
  214.       Interpret key_id '=' "'" || Strip(time_value) || "'"
  215.       Call Write_config
  216.       Address cmd '@rename' ini_file 'inetini.sav > nul'
  217.    End
  218. Trace(trace_save)
  219. Return
  220.  
  221. /* reset config file to defaults */
  222. Reset_config:
  223. trace_save = Trace('N')
  224. Trace 'N'
  225. Parse Upper Arg otherparms
  226. If Wordpos('/RESET', otherparms) > 0 Then
  227.    Do
  228.       /* load sample data */
  229.       Call Config_sample
  230.       /* find location of each application */
  231.       Call RxStemSearch '[COMMON]', 'cfg_sample.', 'found.', 'N'
  232.       Parse Var found.1 common_start .
  233.       order.1 = Right(common_start, 5)
  234.       Call RxStemSearch '[INETLOG]', 'cfg_sample.', 'found.', 'N'
  235.       Parse Var found.1 inetlog_start .
  236.       order.2 = Right(inetlog_start, 5)
  237.       Call RxStemSearch '[IJOYLOG]', 'cfg_sample.', 'found.', 'N'
  238.       Parse Var found.1 ijoylog_start .
  239.       order.3 = Right(ijoylog_start, 5)
  240.       order.4 = Right(cfg_sample.0, 5)
  241.       order.0 = 4
  242.       Call RxSort 'order.'
  243.       order = Space(order.1 order.2 order.3 order.4)
  244.       Say 'Reset all common data in -'
  245.       Say cfg_file '(y/N)'
  246.       Parse Upper Pull ans .
  247.       If Abbrev(ans, 'Y') Then
  248.          Do
  249.             start = common_start + 1
  250.             next = Word(order, Wordpos(common_start, order) + 1) - 1
  251.             appl_id = 'common'
  252.             Do i = start To next
  253.                If \Abbrev(cfg_sample.i, ';') Then
  254.                   Do
  255.                      Parse Var cfg_sample.i key_id '=' key_value
  256.                      key_id = Strip(key_id)
  257.                      key_value = "'" || Strip(key_value) || "'"
  258.                      Interpret key_id '=' key_value
  259.                   End
  260.             End
  261.             Call Write_config
  262.          End
  263.       Say 'Reset all IBM dialer data in -'
  264.       Say cfg_file '(y/N)'
  265.       Parse Upper Pull ans .
  266.       If Abbrev(ans, 'Y') Then
  267.          Do
  268.             start = inetlog_start + 1
  269.             next = Word(order, Wordpos(inetlog_start, order) + 1) - 1
  270.             appl_id = 'inetlog'
  271.             Do i = start To next
  272.                If \Abbrev(cfg_sample.i, ';') Then
  273.                   Do
  274.                      Parse Var cfg_sample.i key_id '=' key_value
  275.                      key_id = Strip(key_id)
  276.                      key_value = "'" || Strip(key_value) || "'"
  277.                      Interpret key_id '=' key_value
  278.                   End
  279.             End
  280.             ibm_dialer = ''
  281.             Call Write_config
  282.          End
  283.       Say 'Reset all InJoy dialer data in -'
  284.       Say cfg_file '(y/N)'
  285.       Parse Upper Pull ans .
  286.       If Abbrev(ans, 'Y') Then
  287.          Do
  288.             start = ijoylog_start + 1
  289.             next = Word(order, Wordpos(ijoylog_start, order) + 1) - 1
  290.             appl_id = 'ijoylog'
  291.             Do i = start To next
  292.                If \Abbrev(cfg_sample.i, ';') Then
  293.                   Do
  294.                      Parse Var cfg_sample.i key_id '=' key_value
  295.                      key_id = Strip(key_id)
  296.                      key_value = "'" || Strip(key_value) || "'"
  297.                      Interpret key_id '=' key_value
  298.                   End
  299.             End
  300.             injoy_dialer = ''
  301.             Call Write_config
  302.          End
  303.    End
  304. Trace(trace_save)
  305. Return
  306.  
  307. /* update the config file */
  308. Check_config:
  309. trace_save = Trace('N')
  310. Trace 'N'
  311. /* path to data files */
  312. If data_path = '' Then
  313.    Do
  314.       data_path = install_path || 'data\'
  315.       Call Write_config
  316.    End
  317. /* create the data path sub-directory if needed */
  318. If \RxFileExists(data_path || '*.*') Then
  319.    xrc = SysMkDir(Strip(data_path, , '\'))
  320. /* IBM dialer support */
  321. If ibm_dialer = '' Then
  322.    Do
  323.       Say 'Support the IBM dialer (y/N)?'
  324.       Parse Upper Pull ans .
  325.       key_value = Abbrev(ans, 'Y')
  326.       ibm_dialer = key_value
  327.       Call Write_config
  328.    End
  329. /* InJoy dialer support */
  330. If injoy_dialer = '' Then
  331.    Do
  332.       Say 'Support the InJoy dialer (y/N)?'
  333.       Parse Upper Pull ans .
  334.       key_value = Abbrev(ans, 'Y')
  335.       injoy_dialer = key_value
  336.       Call Write_config
  337.    End
  338.  
  339. /* process IBM dialer entries */
  340. If ibm_dialer Then
  341.    Do
  342.       /* dialer ini file */
  343.       If ibm_dialer_ini_file = '' Then
  344.          Do
  345.             Say 'Please select your IBM dialer by number'
  346.             Say '   1 - DIALER.EXE (1.67 and below)'
  347.             Say '   2 - TCPDIAL.EXE (1.69 and above)'
  348.             Parse Upper Pull ans .
  349.             Select
  350.                When ans = 1 Then
  351.                   key_value = 'dialer.ini'
  352.                When ans = 2 Then
  353.                   key_value = 'tcpdial.ini'
  354.                Otherwise Do
  355.                   Say 'You did not chose a supported dialer'
  356.                   key_value = ''
  357.                End
  358.             End
  359.             ibm_dialer_ini_file = key_value
  360.             Call Write_config
  361.          End
  362.    End
  363.  
  364. /* process InJoy dialer entries */
  365. If injoy_dialer Then
  366.    Do
  367.       If injoy_logs = '' Then
  368.          Do
  369.             /* get path to InJoy */
  370.             Say 'Enter the full path to the InJoy Dialer logs or hit enter to quit.'
  371.             Parse Upper Pull ans .
  372.             If ans <> '' Then
  373.                Do
  374.                   /* get all *.log file names */
  375.                   log_path = ans
  376.                   rc = SysFileTree(log_path || '\*.log', 'logs.', 'FO')
  377.                   /* loop through log file names to see the user wants them included */
  378.                   If rc = 0 & logs.0 > 0 Then
  379.                      Do i = 1 To logs.0
  380.                         Say 'Found InJoy log file -' logs.i
  381.                         Say 'Analyze this log (y/N)'
  382.                         Parse Upper Pull ans
  383.                         If Abbrev(ans, 'Y') Then
  384.                            Do
  385.                               injoy_logs = Space(injoy_logs logs.i)
  386.                            End
  387.                      End
  388.                   Else
  389.                      Do
  390.                         Say 'Unable to locate any logs in InJoy log path -' ans
  391.                         Say 'InJoy logs in' ans 'will not be processed.'
  392.                      End
  393.                End
  394.             Else
  395.                Say 'InJoy logs will not be processed'
  396.             injoy_accts = ''
  397.             injoy_users = ''
  398.             injoy_times = ''
  399.             Do i = 1 To Words(injoy_logs)
  400.                joylog = Word(injoy_logs, i)
  401.                joyacct = Word(injoy_accts, i)
  402.                joyuser = Word(injoy_users, i)
  403.                joytime = Word(injoy_times, i)
  404.                If joyacct = '' Then
  405.                   Do
  406.                      Say 'Enter an account id for InJoy log (enter = none)'
  407.                                                      say joylog
  408.                      Parse Pull joydata
  409.                      If joydata = '' Then
  410.                         joydata = 'none'
  411.                      injoy_accts = Strip(injoy_accts joydata)
  412.                   End
  413.                If joyuser = '' Then
  414.                   Do
  415.                      Say 'Enter an user id for InJoy log (enter = none)'
  416.                      Say joylog
  417.                      Say 'and account id -' joydata
  418.                      Parse Pull joydata
  419.                      If joydata = '' Then
  420.                         joydata = 'none'
  421.                      injoy_users = Strip(injoy_users joydata)
  422.                   End
  423.                If joytime = '' Then
  424.                   Do
  425.                      joydata = 'T00000000000000'
  426.                      injoy_times = Strip(injoy_times joydata)
  427.                   End
  428.             End
  429.             Call Write_config
  430.          End
  431.    End
  432. Trace(trace_save)
  433. Return
  434.  
  435. /* write the config file */
  436. Write_config:
  437. trace_save = Trace('N')
  438. Trace 'N'
  439. If RxFileExists(cfg_file) Then            /* do we have a config file */
  440.    Do
  441.       If RxFileExists(cfg_save) Then
  442.          Call SysFileDelete(cfg_save)
  443.       Address cmd '@rename' cfg_file Filespec('N', cfg_save) '> nul'
  444.    End
  445. Do i = 1 To config.0
  446.    If Abbrev(config.i, ';') | Abbrev(config.i, '[') Then
  447.       Nop
  448.    Else
  449.       Do
  450.          Parse Var config.i key_id '=' key_value
  451.          key_id = Strip(key_id)
  452.          config.i = key_id '=' Value(key_id)
  453.       End
  454. End
  455. Call RxWrite 'config.', cfg_file
  456. Trace(trace_save)
  457. Return
  458.  
  459. Errhandler:
  460. Call Beep 300, 500
  461. Say 'Rexx error' rc 'in line' sigl||':' Errortext(rc)
  462. Say Sourceline(sigl)
  463. Call Cleanup
  464. Return
  465.  
  466. Cleanup:                                                      /* Exit */
  467. If \pmrexx Then
  468.    answer = Say_message('Press any key to exit...')
  469. Else
  470.    Call SysSleep 2
  471. save_path = Directory(save_path)
  472. Exit
  473. Return                                                 /* for Cleanup */
  474.  
  475. /* performs common Stream commands and returns 1 or a date if successful */
  476. File_cmd: Procedure Expose result
  477. trace_save = Trace('N')
  478. Trace 'N'
  479. Parse Arg file_name, command
  480. command = Translate(command)
  481. Select
  482.    When command = 'X' Then
  483.       Do
  484.          result = Stream(file_name, 'C', 'QUERY EXISTS')
  485.          answer = (result <> '')
  486.       End
  487.    When command = 'C' Then
  488.       Do
  489.          result = Stream(file_name, 'C', 'CLOSE')
  490.          answer = Abbrev(result,'READY') | (result = '')
  491.       End
  492.    When command = 'W' Then
  493.       Do
  494.          result = Stream(file_name, 'C', 'OPEN WRITE')
  495.          answer = Abbrev(result,'READY')
  496.       End
  497.    When command = 'R' Then
  498.       Do
  499.          result = Stream(file_name, 'C', 'OPEN READ')
  500.          answer = Abbrev(result,'READY')
  501.       End
  502.    When command = 'D' Then
  503.       Do
  504.          result = Stream(file_name, 'C', 'QUERY DATETIME')
  505.          If result <> '' Then
  506.             Do
  507.                Parse Var result date time
  508.                date = Dateconv(Translate(date, '/', '-'), 'U', 'S')
  509.                Parse Var time hr ':' min ':' sec
  510.                answer = Strip(date) || Strip(hr) || Strip(min) || Strip(sec)
  511.             End
  512.          Else
  513.             answer = '00000000000000'
  514.       End
  515.    Otherwise answer = 0
  516. End
  517. Trace (trace_save)
  518. Return answer
  519.  
  520. Say_out:                             /* performs output to the screen */
  521. Procedure Expose quiet
  522. trace_save = Trace('N')
  523. If quiet Then
  524.    Return
  525. Parse Arg line
  526. Say line
  527. Trace (trace_save)
  528. Return
  529.  
  530. Say_message:       /* performs message output and returns key entered */
  531. Procedure Expose quiet
  532. trace_save = Trace('N')
  533. Parse Arg msg
  534. Say msg
  535. answer = SysGetKey('NOECHO')
  536. Trace (trace_save)
  537. Return answer
  538.  
  539. Log_file_parms: Procedure
  540. trace_save = Trace('N')
  541. Parse Arg dialer_ini_name, dialer_ini
  542. Select
  543.    When Translate(dialer_ini_name) = 'DIALER.INI' Then
  544.       Do
  545.          dlog_eparm = 'AdvLog'
  546.          dlog_nparm = 'Cfn'
  547.          dlog_sparm = 'Cfs'
  548.       End
  549.    When Translate(dialer_ini_name) = 'TCPDIAL.INI' Then
  550.       Do
  551.          dlog_eparm = 'Common'
  552.          dlog_nparm = 'LoggingCfn'
  553.          dlog_sparm = 'LoggingCfs'
  554.       End
  555.    Otherwise Do
  556.       Say 'Unable to recognize dialer ini file'
  557.       Call Cleanup
  558.       Exit
  559.    End
  560. End
  561. dialer_log_file = Strip(SysIni(dialer_ini, dlog_eparm, dlog_nparm),,'00'x)
  562. dialer_log_size = C2d(Left(SysIni(dialer_ini, dlog_eparm, dlog_sparm),3))
  563. Trace (trace_save)
  564. Return dialer_log_file dialer_log_size
  565.  
  566. /* set up config sample values */
  567. Config_sample: Procedure Expose cfg_sample.
  568. trace_save = Trace('N')
  569. Trace 'N'
  570. data_queue = INetSmp('config')
  571. old_queue = Rxqueue('Set', data_queue)
  572. cfg_sample.0 = Queued()
  573. Do i = 1 To cfg_sample.0
  574.    Parse Pull cfg_sample.i
  575. End
  576. rx_queue = Rxqueue('Delete', data_queue)
  577. Trace(trace_save)
  578. Return
  579.