#!/usr/bin/perl -w -I/usr/sausalito/perl -I.
# $Id: regen_httpd_figlet,v 1.1.1.1 2003/07/17 15:15:48 will Exp $
#
# this handler is responsible for maintaining the per-Workgroup configuration
# files for Apache.
#
# Depends on:
#		System.hostname
#		System.domainname
#
# MPBug fixed.

my $confdir = '/etc/httpd/conf';

use strict;
use Sauce::Config;
use FileHandle;
use File::Copy;
use CCE;

my $cce = new CCE;
$cce->connectfd(\*STDIN,\*STDOUT);

my ($oid) = $cce->find("System");
my ($ok, $obj) = $cce->get($oid);

my $hostname = $obj->{hostname};
my $domain = $obj->{domainname};
$hostname =~ s/\.${domain}$//;
my $fqdn = $hostname . '.' . $domain;

umask(0077);
my $stage = "$confdir/httpd.conf~";
open(HTTPD, "$confdir/httpd.conf");
unlink($stage);
sysopen(STAGE, $stage, 1|O_CREAT|O_EXCL, 0600) || die;
while(<HTTPD>) {
  s/^ServerAdmin\s.+$/ServerAdmin admin\@$fqdn\n/;
  s/^ServerName\s.+$/ServerName $fqdn/;
  print STAGE;
}
close(STAGE);
close(HTTPD);

chmod(0644, $stage);
if(-s $stage) {
  move($stage,"$confdir/httpd.conf");
  chmod(0644, "$confdir/httpd.conf"); # paranoia
  $cce->bye("SUCCESS");
} else {
  $cce->bye("FAILURE");
}

exit(0);

