home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / XCOUNT.CMD < prev    next >
OS/2 REXX Batch file  |  1998-12-09  |  7KB  |  213 lines

  1. /***************************************************************************
  2.  *  XCOUNT.CMD - a REXX script to send count users hitting the home-page
  3.  *
  4.  *  Author:  Patrick Erley, Wolfram Fassbender, FU-Berlin WRZ
  5.  *           18.8.1995
  6.  *
  7.  *   Modified by: Donald L. Meyer,  28.9.1995
  8.  *   Modified again, by: Donald L. Meyer,  4.10.1995
  9.  *     (Reworked XBM output to use LF instead of CRLF,
  10.  *       now compatible with Netscape, et.al.  )
  11.  *
  12.  **************************************************************************/
  13. env = "OS2ENVIRONMENT"
  14. minLen = 7;           /* minimum number of digits in bitmap */
  15. isHigh = 1;           /* if 1, digits are 16 pixels high, to allow room for border */
  16. isInverse = 1;        /* if 1, digits are white on black */
  17. totalreads = 0;       /* number of total reads */
  18. bytes = '';
  19. bytecount = 0;
  20. AccessFile = 'access.cnt'
  21. Incr = 1        /* default is to auto-increment  */
  22.  
  23. PathTranslated = translate(value( 'PATH_TRANSLATED',, env), '\', '/')
  24. if (right(PathTranslated,1) \= '\') then PathTranslated = PathTranslated'\'
  25. if (PathTranslated \= '\') then value( 'COUNT_FILENAME', PathTranslated || AccessFile, env)
  26.  
  27. parse arg ArgTxt
  28. ArgTxt = translate(ArgTxt, ' ', '+')    /* older server versions sometimes forget to do this... */
  29. parse var ArgTxt URI I L CLIENTADDR .
  30. if (I \= '') then isInverse = I
  31. if (L \= '') then minLen = L
  32. if (CLIENTADDR == '') then CLIENTADDR = value( REMOTE_ADDR,, env)
  33.  
  34.    /* bitmap for each digit
  35.       Each digit is 8 pixels wide, 10 high
  36.       invdigits.x are white on black, digits.x black on white */
  37.    invdigits.0 = "c3 99 99 99 99 99 99 99 99 c3";   /* 0 */
  38.    invdigits.1 = "cf c7 cf cf cf cf cf cf cf c7";   /* 1 */
  39.    invdigits.2 = "c3 99 9f 9f cf e7 f3 f9 f9 81";   /* 2 */
  40.    invdigits.3 = "c3 99 9f 9f c7 9f 9f 9f 99 c3";   /* 3 */
  41.    invdigits.4 = "cf cf c7 c7 cb cb cd 81 cf 87";   /* 4 */
  42.    invdigits.5 = "81 f9 f9 f9 c1 9f 9f 9f 99 c3";   /* 5 */
  43.    invdigits.6 = "c7 f3 f9 f9 c1 99 99 99 99 c3";   /* 6 */
  44.    invdigits.7 = "81 99 9f 9f cf cf e7 e7 f3 f3";   /* 7 */
  45.    invdigits.8 = "c3 99 99 99 c3 99 99 99 99 c3";   /* 8 */
  46.    invdigits.9 = "c3 99 99 99 99 83 9f 9f cf e3";   /* 9 */
  47.    
  48.    
  49.       digits.0 = "3c 66 66 66 66 66 66 66 66 3c";   /* 0 */
  50.       digits.1 = "30 38 30 30 30 30 30 30 30 30";   /* 1 */
  51.       digits.2 = "3c 66 60 60 30 18 0c 06 06 7e";   /* 2 */
  52.       digits.3 = "3c 66 60 60 38 60 60 60 66 3c";   /* 3 */
  53.       digits.4 = "30 30 38 38 34 34 32 7e 30 78";   /* 4 */
  54.       digits.5 = "7e 06 06 06 3e 60 60 60 66 3c";   /* 5 */
  55.       digits.6 = "38 0c 06 06 3e 66 66 66 66 3c";   /* 6 */
  56.       digits.7 = "7e 66 60 60 30 30 18 18 0c 0c";   /* 7 */
  57.       digits.8 = "3c 66 66 66 3c 66 66 66 66 3c";   /* 8 */
  58.       digits.9 = "3c 66 66 66 66 7c 60 60 30 1c";   /* 9 */
  59.  
  60. /* get counter from file and increment it */
  61. totalreads = Count( URI, Incr, CLIENTADDR)
  62.  
  63. /* now generate the Bitmap
  64.                     minLen contains minimum number of digits to display
  65.                     isHigh is one for 16 bit high numbers (else 10)
  66.                     isInverse is one for reverse video (white on black) */
  67. /* Stuff 0 to length of counter */
  68. len = Length(totalreads);
  69. crlf = '0a'x        /* image/x-xbitmap format depends on only having a LF char... */
  70. if len < minLen Then len = minlen;
  71.   formattedcount = right(totalreads, len, '0');
  72.  
  73. if isHigh then do 
  74.    do i = 0 to len * 3 - 1 
  75.       if isInverse then
  76.          bytes = bytes"0xff";       /* add three blank rows to each digit */
  77.       else 
  78.          bytes = bytes"0x00";
  79.       bytecount = bytecount + 1;
  80.       if bytecount//len <> 0
  81.       then bytes=bytes','
  82.       else bytes=bytes',' || crlf
  83.    end
  84. end         
  85.       
  86. /* make the digits */
  87. do y = 0 to 9 
  88.    do x = 1 to len
  89.       digit = substr(formattedCount,x,1);
  90.       if isInverse then               /* $inv = 1 for inverted text */
  91.          byte = substr(invdigits.digit, y*3+1,2);
  92.        else 
  93.          byte = substr(digits.digit,y*3+1,2);
  94.          bytes = bytes'0x'byte;
  95.       bytecount = bytecount + 1;
  96.       if bytecount//len <> 0
  97.       then bytes=bytes','
  98.       else bytes=bytes',' || crlf
  99.    end    
  100. end
  101. if isHigh then do
  102.    do i = 0 to len*3 - 1
  103.       if isInverse then
  104.          bytes = bytes"0xff";       /* add three blank rows to each digit */
  105.       else 
  106.          bytes = bytes"0x00";
  107.       bytecount = bytecount + 1;
  108.       if bytecount//len <> 0
  109.       then bytes=bytes','
  110.       else bytes=bytes',' || crlf
  111.    end
  112. end
  113.  
  114. Say "Content-type: image/x-xbitmap";
  115. /*Say "Content-type: text/plain";*/
  116. Say;
  117. out_text = "#define count_width "len*8 || crlf
  118. if isHigh then
  119.    out_text = out_text || "#define count_height 16" || crlf
  120. else
  121.    out_text = out_text || "#define count_height 10" || crlf
  122. out_text = out_text || "static char count_bits[] = {" || crlf
  123. out_text = out_text || reverse(substr(reverse(bytes), (2 + length(crlf))))'};' || crlf
  124. call lineout, out_text
  125.  
  126. Exit (0)
  127.  
  128.  
  129. Count: procedure
  130. /* COUNT.RXX   - a function to track access counts of a given URL. */
  131. /*    Original work by V. Phaniraj,  phaniraj@plains.nodak.edu        */
  132. /*    Heavily modified by D.L. Meyer,   meyer@larch.ag.uiuc.edu    */
  133.  
  134.   env = 'OS2ENVIRONMENT'
  135.   crlf = '0d0a'x
  136.   open_mode = 'OPEN'
  137.   number = 1
  138.   count. = ''
  139.  
  140.   count.fn = value( 'COUNT_FILENAME',, env)
  141.   if (count.fn == '') then count.fn='access.cnt'  /* ASCII file that contains the counts */
  142.  
  143.   count.exclude_ips = value( 'COUNT_EXCLUDE_IPS',, env)
  144.  
  145.   parse arg URI, count.Incr, CLIENTADDR
  146.   if (count.Incr == '') | (count.Incr == 0) 
  147.     then count.Incr = 0
  148.     else count.Incr = 1
  149.  
  150.   if (CLIENTADDR == '') then CLIENTADDR = '#'
  151.  
  152.   URL=translate( URI)
  153.  
  154.   if (pos(CLIENTADDR, count.exclude_ips) > 0) then count.Incl = 0
  155.   if (count.Incl == 0) then open_mode = 'OPEN READ'
  156.  
  157. /* read the access file into result and close the file  */
  158.  
  159.   rc = ''
  160.   result = ''
  161.   rest = ''
  162.   do until (rc == 'READY:')
  163.     rc=stream(count.fn, 'C', 'OPEN')
  164.   end
  165.   result=charin(count.fn,,chars(count.fn))
  166.  
  167. /* look for the URL in the  string, and find the
  168.    number of accesses stored in the file. Try not to
  169.    use linein to avoid keeping the file open too long.
  170. */
  171.  
  172.   locate = pos(URL,result)
  173.  
  174.   if (locate \= 0) then do
  175.      locate = locate+length(URL)+2
  176.      number=substr(result,locate)
  177.      parse var number 'Accesses:' number 'here' (crlf) rest
  178.  
  179. /* This is the IP exclusion part... */
  180.      if (count.Incr) then do
  181.   
  182. /* increment the number of accesses */
  183.  
  184.         number=number+1
  185.  
  186. /*  This is the updating of the file, if URL is found */
  187.         parse upper version rver .
  188.         aad=' '
  189.         if abbrev(rver,'OBJ')=1 then aad=' WRITE'
  190.         rc=stream(count.fn, 'C', 'SEEK ='||(locate)||aad)
  191.         rc=charout(count.fn, 'Accesses: ' number ' here'crlf || rest)
  192.      end
  193.   end
  194.  
  195.   else if (count.Incr) then do
  196. /*  This is the updating of the file, if URL is not found 
  197.     A new entry is created in the file */
  198.  
  199.      parse upper version rver .
  200.      aad=' '
  201.      if abbrev(rver,'OBJ')=1 then aad=' WRITE'
  202.      rc=stream(count.fn, 'C', 'SEEK +0'||aad)
  203.      rc=lineout(count.fn,URL)
  204.      rc=charout(count.fn, 'Accesses:  1  here'crlf || rest)
  205.   end /* end of locate if */
  206.  
  207.   rc=stream(count.fn, 'C', 'CLOSE')
  208.   number = strip(number)
  209.  
  210. return number
  211.  
  212.  
  213.