Handle hostnames with upper-case letters
[webmin.git] / syslog / m4.cgi
1 #!/usr/local/bin/perl
2 # m4.cgi
3 # Pass the syslog config file though m4
4
5 require './syslog-lib.pl';
6 use Socket;
7
8 # is this loghost? Find out by sending a UDP packet to it
9 socket(UDP, PF_INET, SOCK_DGRAM, getprotobyname("udp"));
10 setsockopt(UDP, SOL_SOCKET, SO_BROADCAST, pack("l", 1));
11 $port = 45678;
12 while(!bind(UDP, pack_sockaddr_in($port, INADDR_ANY))) {
13         $port++;
14         }
15 send(UDP, "foo", 0, pack_sockaddr_in($port, inet_aton("loghost")));
16 vec($rin, fileno(UDP), 1) = 1;
17 if (select($rin, undef, undef, 1)) {
18         $args .= " -DLOGHOST";
19         }
20 close(UDP);
21
22 # Run m4
23 $oldslash = $/;
24 $/ = undef;
25 open(CONF, "$config{'m4_path'} $args $config{'syslog_conf'} |");
26 $conf = <CONF>;
27 close(CONF);
28 &open_tempfile(CONF, ">$config{'syslog_conf'}");
29 &print_tempfile(CONF, $conf);
30 &close_tempfile(CONF);
31 $/ = $oldslash;
32 &redirect("");
33