home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / JCOUNT.CMD < prev    next >
OS/2 REXX Batch file  |  1996-07-15  |  3KB  |  114 lines

  1. /***************************************************************************
  2. JCOUNT.CMD == return count of file (just like XCOUNT), but as text.
  3. Meant for the #EXEC httpd server side includ
  4.  **************************************************************************/
  5. env = "OS2ENVIRONMENT"
  6. minLen = 7;           /* minimum number of digits in bitmap */
  7. isHigh = 1;           /* if 1, digits are 16 pixels high, to allow room for border */
  8. isInverse = 1;        /* if 1, digits are white on black */
  9. totalreads = 0;       /* number of total reads */
  10. bytes = '';
  11. bytecount = 0;
  12. AccessFile = 'access.cnt'
  13. Incr = 1        /* default is to auto-increment  */
  14.  
  15.  
  16. PathTranslated = translate(value( 'PATH_TRANSLATED',, env), '\', '/')
  17. if (right(PathTranslated,1) \= '\') then PathTranslated = PathTranslated'\'
  18. if (PathTranslated \= '\') then value( 'COUNT_FILENAME', PathTranslated || AccessFile, env)
  19.  
  20. parse arg ArgTxt
  21. ArgTxt = translate(ArgTxt, ' ', '+')    /* older server versions sometimes forget to do this... */
  22. parse var ArgTxt URI I L CLIENTADDR .
  23. if (I \= '') then isInverse = I
  24. if (L \= '') then minLen = L
  25. if (CLIENTADDR == '') then CLIENTADDR = value( REMOTE_ADDR,, env)
  26.  
  27.  
  28. /* get counter from file and increment it */
  29. totalreads = Count( URI, Incr, CLIENTADDR)
  30. SAY TOTALREADS
  31.  
  32. Exit (0)
  33.  
  34.  
  35. Count: procedure
  36. /* COUNT.RXX   - a function to track access counts of a given URL. */
  37. /*    Original work by V. Phaniraj,  phaniraj@plains.nodak.edu        */
  38. /*    Heavily modified by D.L. Meyer,   meyer@larch.ag.uiuc.edu    */
  39.  
  40.   env = 'OS2ENVIRONMENT'
  41.   crlf = '0d0a'x
  42.   open_mode = 'OPEN'
  43.   number = 1
  44.   count. = ''
  45.  
  46.   count.fn = value( 'COUNT_FILENAME',, env)
  47.   if (count.fn == '') then count.fn='access.cnt'  /* ASCII file that contains the counts */
  48.  
  49.   count.exclude_ips = value( 'COUNT_EXCLUDE_IPS',, env)
  50.  
  51.   parse arg URI, count.Incr, CLIENTADDR
  52.   if (count.Incr == '') | (count.Incr == 0) 
  53.     then count.Incr = 0
  54.     else count.Incr = 1
  55.  
  56.   if (CLIENTADDR == '') then CLIENTADDR = '#'
  57.  
  58.   URL=translate( URI)
  59.  
  60.   if (pos(CLIENTADDR, count.exclude_ips) > 0) then count.Incl = 0
  61.   if (count.Incl == 0) then open_mode = 'OPEN READ'
  62.  
  63. /* read the access file into result and close the file  */
  64.  
  65.   rc = ''
  66.   result = ''
  67.   rest = ''
  68.   do until (rc == 'READY:')
  69.     rc=stream(count.fn, 'C', 'OPEN')
  70.   end
  71.   result=charin(count.fn,,chars(count.fn))
  72.  
  73. /* look for the URL in the  string, and find the
  74.    number of accesses stored in the file. Try not to
  75.    use linein to avoid keeping the file open too long.
  76. */
  77.  
  78.   locate = pos(URL,result)
  79.  
  80.   if (locate \= 0) then do
  81.      locate = locate+length(URL)+2
  82.      number=substr(result,locate)
  83.      parse var number 'Accesses:' number 'here' (crlf) rest
  84.  
  85. /* This is the IP exclusion part... */
  86.      if (count.Incr) then do
  87.   
  88. /* increment the number of accesses */
  89.  
  90.         number=number+1
  91.  
  92. /*  This is the updating of the file, if URL is found */
  93.  
  94.         rc=stream(count.fn, 'C', 'SEEK ='||(locate))
  95.         rc=charout(count.fn, 'Accesses: ' number ' here'crlf || rest)
  96.      end
  97.   end
  98.  
  99.   else if (count.Incr) then do
  100. /*  This is the updating of the file, if URL is not found 
  101.     A new entry is created in the file */
  102.  
  103.      rc=stream(count.fn, 'C', 'SEEK +0')
  104.      rc=lineout(count.fn,URL)
  105.      rc=charout(count.fn, 'Accesses:  1  here'crlf || rest)
  106.   end /* end of locate if */
  107.  
  108.   rc=stream(count.fn, 'C', 'CLOSE')
  109.   number = strip(number)
  110.  
  111. return number
  112.  
  113.  
  114.