#!/usr/bin/perl

# $Id: apply_rr.pl,v 1.1 1996/01/21 09:42:25 hoagland Exp $

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

# this program takes the updated routing rule list for a working set,
# sends it to the various host in the working set for replacement,
# then invokes &draw_rr to return the HTML for the page.
#
# Input is CGI, fields on a form,  Output is HTML to STDOUT.

require '/pkg/www/arpa/secret/cgi-bin/gui-helper.pl';
require '/pkg/www/arpa/secret/cgi-bin/draw_rr.pl';

require CGI;

$input= new CGI;

foreach (@ARGV) {  # simulate field input
  $input->param(split('=',$_,2));
}

$state= State->new(&get_statefile);

#------------

sub send_rules {
  my($state,$ws,@rules)= @_;
  
  my($reply_port)= &get_responce_port; # but port not actually listened to

  &setup_udp_socket($reply_port);
  foreach $host ($state->hosts_in_set($ws)) {
    &send_logd_query($host,$reply_port,'RESET',@rules);    
  }
}

#-------------

$ws= $input->param('ws_name');
$state->{'last_ws'}= $ws;
$input->delete('ws_name');
@rules= map($state->routing_rule_for_id($_),$input->param());
&send_rules($state,$ws,@rules);
$state->store;

&draw_rr($state,$ws);
1;
