# History
# (1) Created, pulled out of www-spong program (Ed 07-28-97)
#
-# $Id: www-spong-ack.pl,v 1.9 2001/04/17 02:58:12 sljohnson Exp $
+# $Id: www-spong-ack.pl,v 1.10 2003/01/29 23:01:51 sljohnson Exp $
+
+use lib "@@LIBDIR@@";
use CGI;
use Sys::Hostname;
use Socket;
use POSIX;
use Time::Local;
+use Spong::Host;
# Load our configuration variables, including the user specified configuration
# information (spong.conf, spong.hosts, and spong.groups files).
$cmd = $ENV{'PATH_INFO'};
-if( $cmd =~ m!^/delete/(.+?)-(\w+)-(\d+)$! ) { &remove( $1, $2, $3 ); exit; }
+if( $cmd =~ m!^/delete/(.+?)-(.+?)-(\d+)$! ) { &remove( $1, $2, $3 ); exit; }
if( $cmd =~ m!^/help$! ) { &help(); exit; }
if( $cmd =~ m!^/ack-doit$! ) { &ack_doit(); exit; }
sub ack {
my( $group, $service ) = @_;
my( @hostlist ) = hostlist( $group );
+ my $cgi = new CGI;
my $host;
$group = "all" unless $group;
if( $#hostlist >= 1 ) {
print "<select name=\"host\">\n";
- foreach $host ( @hostlist ) { print "<option>$host\n";}
+ foreach $host ( sort @hostlist ) { print "<option>$host\n";}
print "</select></td></tr><tr>\n";
} else {
print "<input type=text name=host size=30 value=\"$hostlist[0]\">\n";
print "</td></tr><tr>\n";
}
- print "<p><b>Service:</b> <font size=-1>(The service you are acknowledging";
+ print "<p><b>Service:</b> <font size=-1>(The services you are acknowledging";
print ", or \"<i>all</i>\" to signify all services)</font><br>\n";
- print "<input type=text name=services size=30 value=\"$service\">";
+ if( $#hostlist >= 1 ) {
+ print "<input type=text name=services size=30 value=\"$service\">";
+ } else {
+ my ($h) = new Spong::Host($hostlist[0]);
+ $service = 'all' unless defined $service;
+
+ print "<select name=services multiple>\n";
+ print " <option";
+ print " selected" if $service eq 'all';
+ print ">all\n";
+ foreach $serv (sort $h->service_names()) {
+ print "<option";
+ print " selected" if $service eq $serv;
+ print ">$serv\n";
+ }
+ print "</select>\n";
+ }
print "<p><b>Duration:</b> <font size=-1>(When service will be ";
print "available, +5h, +2d, 18:00, 7/28/97)</font><br>\n";
+ print "<select name=duration_select>\n";
+ print " <option selected>custom\n";
+ print " <option>+5m\n";
+ print " <option>+15m\n";
+ print " <option>+30m\n";
+ print " <option>+1h\n";
+ print " <option>+4h\n";
+ print " <option>+8h\n";
+ print " <option>+1d\n";
+ print " <option>+1w\n";
+ print " <option>+2w\n";
+ print "</select><br>\n";
+ print " If custom:\n";
print "<input type=text name=duration size=30>\n";
print "<p><b>Email:</b> <font size=-1>(Email address of the contact person";
print ")</font><br>\n";
- print "<input type=text name=user size=30>\n";
+
+ if (defined $cgi->remote_user() && defined $HUMANS{$cgi->remote_user()}{'email'}) {
+ print "<input type=text name=user size=30 value=\"" . $HUMANS{$cgi->remote_user()}{'email'} . "\">\n";
+ } else {
+ print "<input type=text name=user size=30>\n";
+ }
print "<p><b>Message:</b> <font size=-1>(Description of the ";
print "problem, details about the solution)</font><br>\n";
sub ack_doit {
my $cgi = new CGI;
my $host = $cgi->param( 'host' );
- my $services = $cgi->param( 'services' );
+ my (@serv) = $cgi->param( 'services' );
my $date = $cgi->param( 'duration' );
my $user = $cgi->param( 'user' );
my $message = $cgi->param( 'message' );
my $group = $cgi->param( 'group' );
+ my ($services) = join(',', @serv);
+ $services =~ s/ //g; # Make sure there aren't any spaces...
+
+ my $date = $cgi->param( 'duration' );
+ if ($cgi->param('duration_select') ne 'custom') {
+ $date = $cgi->param('duration_select');
+ }
+
if( $services eq "" ) { &error( "Service name not supplied." ); }
if( $host eq "" ) { &error( "Host name not supplied." ); }
if( $date eq "" ) { &error( "Duration not supplied." ); }
if( $date =~ /^\+\s*(\d+)\s*([mhdw])$/ ) {
$time = time() + ( $1 * $secs{$2} ); $ok = 1; }
+ # Check for a duration in the format HH:MM...
+ if( $date =~ /\b(\d+):(\d+)\b/ ) {
+ ( $hour, $min, $sec ) = ( $1, $2, 0 ); $ok = 1; }
+
# Check for a duration in the format HH:MM:SS...
if( $date =~ /\b(\d+):(\d+):(\d+)\b/ ) {
( $hour, $min, $sec ) = ( $1, $2, $3 ); $ok = 1; }
if( $ok ) {
$time = timelocal( $sec, $min, $hour, $mday, $mon, $year) unless $time;
} else {
- &error( "Invalid duration specifier, view the " .
+ &error( "Invalid duration ($date) specifier, view the " .
"<a href=\"$main::WWWACK/help\">Help</a> screen for more " .
"information on valid formats." );
}
&header();
print "<font size=+2><b>Acknowledge Problems - Success</b></font><hr>\n";
print "Your acknowledgment has been successfully registered. Please ";
- print "press <a href=\"$main::WWWSPONG/group/$group\" target=_top>here";
+
+ if ($group eq 'all' && $main::WWW_DEFAULT_VIEW eq 'GROUPS') {
+ print "press <a href=\"$main::WWWSPONG/bygroup/\" target=_parent>here";
+ } else {
+ print "press <a href=\"$main::WWWSPONG/group/$group\" target=_parent>here";
+ }
+
print "</a> to refresh the spong display.<p>\n";
}
}
# their acknowledgment.
if( $r ne "ok" ) {
- &error( "Could not acknowledge $host/$service!<p>Message: $r");
+ &error( "Could not remove acknowledgement for $host/$service!<p>Message: $r");
} else {
# If we can tell where they came from, then just redirect them back,
if( $results =~ /^\s*$/ ) { return "No current acknowledgments."; }
my $str = "<table width=100% border=0 cellspacing=0 cellpadding=0>";
- foreach $ack ( split( /\n/, $results ) ) {
+ foreach $ack ( sort split( /\n/, $results ) ) {
($host, $service, $time) = (split( /:/, $ack ));
my $id = "$host-$service-$time";