home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / gostools.zip / gostat.cmd < prev    next >
OS/2 REXX Batch file  |  1995-06-27  |  10KB  |  281 lines

  1. /* REXX script for extended GoServe filter.                         */
  2. /* This script moves GoServe audit file to the archive and creates  */
  3. /* a server statistic in HTML format.                               */
  4. /* (Uses goremote.cmd, rxSock.dll)                                  */
  5. /* ================================================================ */
  6. /* Syntax: gostat <configuration file>                              */
  7. /* Where:  configuration file...full filename of configuration      */
  8. /*                              file for gostat.cmd                 */
  9. /* ================================================================ */
  10. /* Written by Michael Warmuth for OS/2 Forum Austria.               */
  11. /* (E-mail: Michael.Warmuth@wu-wien.ac.at).                         */
  12. /* For using and copiing see the file copyright.doc.                */
  13.  
  14. /* Load REXX utility functions */
  15. if RxFuncQuery('SysLoadFuncs') then do
  16.    CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  17.    CALL SysLoadFuncs
  18. end  /* Do */
  19.  
  20. /* Load REXX TCP-SOCKET functions */
  21. if RxFuncQuery("SockLoadFuncs") then do
  22.    call RxFuncAdd "SockLoadFuncs","rxSock","SockLoadFuncs"
  23.    call SockLoadFuncs
  24. end  /* Do */
  25.  
  26. /* Get arguments */
  27. parse arg conffile .
  28. do while lines(conffile)\=0
  29.    parse value linein(conffile) with line '#' .
  30.    parse var line key '=' value
  31.    if key\='' then do
  32.       k = key "= '"strip(value)"'"
  33.       interpret k
  34.    end  /* Do */
  35. end /* do */
  36.  
  37. /* Set global variables */
  38. env = "OS2ENVIRONMENT"                       /* For environment access */
  39. parse source . . def_path                    /* Path of this procedure */
  40. def_path = substr(def_path,1,lastpos('\',def_path))
  41. transfile = def_path'transtbl.txt'           /* Table for char translation */
  42. temppath = value('TEMP',,env)                /* Get path for temp files */
  43. tempfile = SysTempFileName(temppath'\WWW?????.TMP')   /* Get unique filename */
  44. etc = value('ETC',,env)                      /* Get path for tcpip's etc directory */
  45.  
  46. crlf='0d0a'x                                 /* often useful */
  47.  
  48. /* Change to directory where this code resides */
  49. call directory left(def_path,length(def_path)-1)
  50.  
  51. /* Move GoServe archive */
  52. if goremote(server command username password)\=0 then exit
  53.  
  54. /* Check if audfile exists */
  55. if stream(audfile,'c','query exists')='' then exit 1
  56.  
  57. m = 0                                        /* Counter for months */
  58. d = 0                                        /* Counter for days */
  59. i = 0
  60. n = 0
  61. month = '00/0000'
  62. old_date = ''
  63. do until lines(audfile)=0
  64.    parse value linein(audfile) with ltime ltyp lnum linfo
  65.  
  66.    select
  67.       /* New date */
  68.       when ltyp='D' then do
  69.          linfo = word(linfo,1)               /* Get date */
  70.          if linfo\=old_date then do
  71.             old_date = linfo
  72.             if d_count.d\=0 then do
  73.                d = d+1                       /* Increment day */
  74.                d_count.d = 0                 /* Connections counter */
  75.             end  /* Do */
  76.             /* Check for new month */
  77.             if month\=substr(linfo,5,2)'/'left(linfo,4) then do
  78.                if m_count.m\=0 then do
  79.                   m = m+1                    /* Increment month */
  80.                   m_count.m  = 0             /* Connections counter */
  81.                end  /* Do */
  82.                month = substr(linfo,5,2)'/'left(linfo,4)
  83.                m_month.m = month
  84.             end  /* Do */
  85.             d_date.d = right(linfo,2) || '.' || translate(m_month.m,'.','/')
  86.          end  /* Do */
  87.       end  /* Do */
  88.  
  89.       /* Next address */
  90.       when ltyp='A' then do
  91.          i = i+1
  92.  
  93.          a_time.i = ltime                    /* Build stem item */
  94.          a_typ.i  = ltyp
  95.          a_num.i  = lnum
  96.          parse var linfo linfo .
  97.          a_info.i = linfo
  98.          a_date.i = d_date.d
  99.  
  100.          d_count.d = d_count.d+1             /* Increment counters */
  101.          m_count.m = m_count.m+1
  102.  
  103.          if symbol('i_count.'linfo)='LIT' then do
  104.             n = n+1
  105.             i_count.linfo = 1
  106.             i_ips.n = linfo
  107.          end  /* Do */
  108.          else do
  109.             i_count.linfo = i_count.linfo+1
  110.          end  /* Do */
  111.  
  112.       end  /* Do */
  113.    otherwise
  114.       nop
  115.    end  /* select */
  116. end /* do */
  117.  
  118. a_time.0 = i                                 /* Get numbers */
  119. a_typ.0  = i
  120. a_num.0  = i
  121. a_info.0 = i
  122. a_date.0 = i
  123. d_count.0 = d
  124. d_date.0  = d
  125. m_count.0 = m
  126. m_month.0 = m
  127. i_ips.0 = n
  128.  
  129. '@copy' stathead htmlfile '> nul'
  130.  
  131. call lineout htmlfile, '<CENTER><H5>Erstellt/Created:' translate(date('e'),'.','/')
  132. call lineout htmlfile, '('date('u')') um/at' time('N') '</H5></CENTER><HR>'
  133. call lineout htmlfile, 'Bitte beachten: Hier wird jeder Zugriff gezählt. (Beispiel:'
  134. call lineout htmlfile, 'Eine Seite mit fünf Graphiken sind somit sechs Zugriffe)<P>'
  135. call lineout htmlfile, 'Keep in mind: Every access counts. (Example: A page with five'
  136. call lineout htmlfile, 'images counts for 6 accesses)'
  137.  
  138. call lineout htmlfile, '<HR>'
  139. call lineout htmlfile, '<H4>Per Monat/Month:</H4><BR><PRE>'
  140. call lineout htmlfile, ' Monat      Anzahl der Zugriffe'
  141. call lineout htmlfile, ' Month      Number of accesses'
  142. call lineout htmlfile, '-------------------------------'
  143. summ = 0
  144. do i=1 to m_count.0
  145.    call lineout htmlfile, m_month.i right(m_count.i,15)
  146.    summ = summ+m_count.i
  147. end /* do */
  148. call lineout htmlfile, '-------------------------------'
  149. call lineout htmlfile, right(summ,23)
  150. call lineout htmlfile, '</PRE>'
  151.  
  152. call lineout htmlfile, '<HR>'
  153. call lineout htmlfile, '<H4>Per Tag/Day:</H4><BR><PRE>'
  154. call lineout htmlfile, '   Date           Number of accesses'
  155. call lineout htmlfile, '   Datum          Anzahl der Zugriffe'
  156. call lineout htmlfile, '-------------------------------------'
  157. summ = 0
  158. do i=1 to d_count.0
  159.    call lineout htmlfile, d_date.i right(d_count.i,20)
  160.    summ = summ+d_count.i
  161. end /* do */
  162. call lineout htmlfile, '-------------------------------------'
  163. call lineout htmlfile, right(summ,31)
  164. call lineout htmlfile, '</PRE>'
  165.  
  166. /* Make short statistics file */
  167. if htmlshort\='' then
  168.    '@type' htmlfile '>' htmlshort
  169.  
  170. /* Get host names and build string for order */
  171. i_nams.0 = i_ips.0
  172. i_srtnams.0 = i_ips.0
  173. i_ctries.0 = i_ips.0
  174. do i=1 to i_ips.0
  175.    ipno = i_ips.i
  176.    if \SockGetHostByAddr(ipno,'addrstr.') then do
  177.       i_nams.i = ipno
  178.       i_ctries.i = ''
  179.       parse var ipno a '.' b '.' c '.' d .
  180.       i_srtnams.i = right(a,3,'0')'.'right(b,3,'0')'.'||,
  181.          right(c,3,'0')'.'right(d,3,'0')
  182.    end  /* Do */
  183.    else do
  184.       i_nams.i = addrstr.name
  185.       i_ctries.i = translate(substr(addrstr.name,lastpos('.',addrstr.name)+1))
  186.       tmp_addr = addrstr.name
  187.       i_srtnams.i = ''
  188.       do while pos('.',tmp_addr)\=0
  189.          parse var tmp_addr next_word '.' tmp_addr
  190.          i_srtnams.i = '.'next_word||i_srtnams.i
  191.       end /* do */
  192.       i_srtnams.i = translate(tmp_addr||i_srtnams.i)
  193.    end  /* Do */
  194. end /* do */
  195.  
  196. /* Order host names */
  197. sort.0 = i_srtnams.0
  198. do i=1 to sort.0
  199.    sort.i = i
  200. end /* do */
  201. /* One of Knuth's sort algorithms */
  202. /* define M for passes */
  203. M = 1
  204. DO WHILE (9 * M + 4) < i_srtnams.0
  205.    M = M * 3 + 1
  206. END
  207. /* sort stem */
  208. DO WHILE M > 0
  209.    K = i_srtnams.0 - M
  210.    DO J = 1 TO K
  211.       Q = J
  212.       DO WHILE Q > 0
  213.          L = Q + M
  214.          IF i_srtnams.Q <= i_srtnams.L THEN LEAVE
  215.  
  216.          /* switch elements */
  217.          tmp               = i_srtnams.Q
  218.          i_srtnams.Q       = i_srtnams.L
  219.          i_srtnams.L       = tmp
  220.          tmp               = sort.Q
  221.          sort.Q            = sort.L
  222.          sort.L            = tmp
  223.          Q = Q - M
  224.       END
  225.    END
  226.    M = M % 3
  227. END
  228.  
  229. /* Write out statistics */
  230. call lineout htmlfile, '<HR>'
  231. call lineout htmlfile, '<H4>Per Rechner/Client:</H4><PRE>'
  232. call lineout htmlfile, 'Land/'
  233. call lineout htmlfile, 'Typ      Name/IP-Adresse             Anzahl der Zugriffe'
  234. call lineout htmlfile, 'Country/'
  235. call lineout htmlfile, 'Type     Name/IP-Address             Number of accesses'
  236. call lineout htmlfile, '--------------------------------------------------------'
  237. sum = 0
  238. sum_ctry = 0
  239. ind = sort.1
  240. cntr = ''
  241. do i=1 to sort.0
  242.    ind = sort.i
  243.    ip = i_ips.ind
  244.    if i_ctries.ind=cntr then do
  245.       sum_ctry = sum_ctry + i_count.ip
  246.    end  /* Do */
  247.    else do
  248.       if i\=1 then do
  249.          call lineout htmlfile, left('',50,'-')
  250.          call lineout htmlfile, left(cntr,39) right(sum_ctry,10)
  251.          call lineout htmlfile, left('',39) left('',10,'-')
  252.          call lineout htmlfile, ''
  253.       end  /* Do */
  254.       cntr = i_ctries.ind
  255.       sum_ctry = i_count.ip
  256.       if ctry\='' then do
  257.          call lineout htmlfile, left(cntr,3)':'
  258.          call lineout htmlfile, '----'
  259.       end  /* Do */
  260.    end  /* Do */
  261.    call lineout htmlfile, '         'left(i_nams.ind,30) right(i_count.ip,10)
  262.    sum = sum + i_count.ip
  263. end /* do */
  264. call lineout htmlfile, left('',50,'-')
  265. call lineout htmlfile, left(cntr,39) right(sum_ctry,10)
  266. call lineout htmlfile, '--------------------------------------------------------'
  267. call lineout htmlfile, right(sum,50)
  268. call lineout htmlfile, '</PRE>'
  269.  
  270. do while lines(statfoot)\=0
  271.    call lineout htmlfile, linein(statfoot)
  272. end /* do */
  273.  
  274. if htmlshort\='' then do
  275.    do while lines(shortfoot)\=0
  276.       call lineout htmlshort, linein(shortfoot)
  277.    end /* do */
  278. end  /* Do */
  279.  
  280. return
  281.