#!/usr/bin/perl -w

# $Id: draw_tw_request.pl,v 1.6 1996/02/14 20:52:05 hoagland Exp $

# draw_tw_request.pl, by Jim Hoagland (hoagland@cs) 1/96

# this routine generates the tripwire request page for the ARPA IDS
# demo GUI.
# The first argument is the host name.
# outputs HTML to STDOUT

require 5.000;

require '/pkg/www/arpa/secret/cgi-bin/gui-helper.pl';
require '/pkg/www/arpa/secret/cgi-bin/network-help.pl';
require '/pkg/arpa/demo.0/require.pl';

sub get_tw_files {
  my $host= shift;
  my (@files);
  my $hostname= $myhostname; # from require.pl
  my $port= &get_responce_port;
  &setup_rcv_tcp_connection($port);
  &send_scl_message($host,'dtyp' => 'to_trip_stdin', 'request' => 'protected_list','respond_to_host' => $hostname,'respond_to_port' => $port, 'time' => time);

  &accept_tcp_connection;
  @mess= &read_tcp_connection;
  &close_tcp_connection;

  while ($_=pop(@mess)) { # read in reverse order
    last if /^----/;
    chop;
    unshift(@files,$_);
  }
#  @files= grep(!/^\s*$/,@files);
  return (@files);
}

sub draw_tw_request {
  my ($state,$host)= @_;
  @files= &get_tw_files($host);
  my($file_list)= '';
  foreach $file (sort @files) {
    $file_list.= "<OPTION>$file";
  }
  $file_list.= "</SELECT>";
  $file_pullup= '<SELECT NAME="file">'.$file_list;
#  $file_list= '<SELECT NAME="files" MULTIPLE SIZE='.(@files < 20 ? @files+1 : 21).'><OPTION VALUE=all SELECTED>all protected files'.$file_list;
  $file_list= '<SELECT NAME="files"><OPTION VALUE=all SELECTED>all protected files'.$file_list;

  print "Content-type:  text/html\nPragma: no-cache\n\n";
  &output_instantiated_file('/pkg/www/arpa/secret/gui/html-src/tw_request.html',*STDOUT,
			    '<!!! Insert Host Here !!!>',$host,
			    '<!!! Insert protected file list here !!!>',$file_list,
			    '<!!! Insert protected file pullup here !!!>',$file_pullup);

}
1;
