// Copyright Andy Deck 2002, GNU Public License 2
// With the notable provision that any commercial use
// must be approved by the copyright holder.
import java.awt.*;
import java.awt.*;
import java.io.*;
import java.net.URL;

public class hits extends Module
    implements Runnable
{

    public hits()
    {
        speed = 1;
    }

    public void init(lexicon lexicon1, String s)
    {
        super.lex = lexicon1;
        start();
    }

    public void stop()
    {
        t = null;
    }

    public void start()
    {
        t = new Thread(this, "hits");
        t.start();
    }

    public void run()
    {
        try
        {
            URL url = new URL(Module.documentBase + "hits.php");
            Graphics g = super.lex.img.getGraphics();
            setRenderMode(g);
            for(int i = 0; i < 10; i++)
            {
                DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(url.openStream()));
                String s;
                while((s = datainputstream.readLine()) != null) 
                {
                    g.setColor(Color.white);
                    g.drawLine(0, Module.HEIGHT - 72, Module.WIDTH, Module.HEIGHT - 72);
                    g.drawLine(0, Module.HEIGHT - 60, Module.WIDTH, Module.HEIGHT - 60);
                    g.drawLine(0, Module.HEIGHT - 48, Module.WIDTH, Module.HEIGHT - 48);
                    g.drawLine(0, Module.HEIGHT - 36, Module.WIDTH, Module.HEIGHT - 36);
                    g.drawLine(0, Module.HEIGHT - 24, Module.WIDTH, Module.HEIGHT - 24);
                    g.drawLine(0, Module.HEIGHT - 12, Module.WIDTH, Module.HEIGHT - 12);
                    g.setColor(Color.black);
                    g.drawString(s, 5, Module.HEIGHT - 24);
                    g.copyArea(0, 0, Module.WIDTH, Module.HEIGHT, 0, -12);
                    repaint();
                    hits _tmp = this;
                    Thread.sleep(speed * 1000);
                    if(super.abort)
                    {
                        i = 10;
                        break;
                    }
                }
                if(datainputstream != null)
                    datainputstream.close();
            }

        }
        catch(Exception exception)
        {
            System.out.println(exception);
        }
    }

    private volatile Thread t;
    int speed;
}
/*
<?php
  ### hits.php
  $logdir = "/var/log/httpd";
  header("Content-type: text/plain");
  $p = popen("/usr/bin/tail $logdir/access_log","r");
  if($p){
     while(!feof($p)) print(fgets($p,128));
     pclose($p);
  }
?>
*/ 
