home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ac-grenoble.fr
/
2015.02.ftp.ac-grenoble.fr.tar
/
ftp.ac-grenoble.fr
/
pub
/
slis
/
updates_rsync
/
mknamedconf
< prev
next >
Wrap
Text File
|
2003-06-18
|
5KB
|
260 lines
#!/usr/bin/perl
# $Id: mknamedconf,v 3.3 2003/06/17 18:23:37 bzizou Exp $ #
# Named automatic configuration
# Load SLIS variables
do '/home/hadmin/slis.conf.pl';
$hostname=`cat /etc/HOSTNAME`;
chomp($hostname);
# If DNS is given by DHCP, try to get it from /etc/resolv.conf
if ($DNS_PRIMARY eq "auto" || $DNS_PRIMARY eq "") {
$nameserver=`grep nameserver /etc/resolv.conf|awk '{print \$2}'|head -1`;
chomp($nameserver);
# If resolv.conf contains 127.0.0.1, then we took the default value
if ($nameserver eq "127.0.0.1") {
$DNS_PRIMARY=$DNS_DEFAULT;
$DNS_SECONDARY=$DNS_DEFAULT;
}
else {
$DNS_PRIMARY=$nameserver;
$DNS_SECONDARY=$DNS_DEFAULT;
}
}
# Local zone guessing
$ip=`/sbin/ifconfig eth1 2> /dev/null|grep inet |awk '{print \$2}'|awk -F: '{print \$2}' 2>/dev/null`;
if ($ip !~ /.*\..*\..*\..*/) {
$ip="$INTRANET_NET";
}
chomp $ip;
($a,$b,$c,$d)=split(/\./,$ip);
$zone="$b.$a";
if ($zone == "") {
$zone="16.172";
}
# Mask conversion
$INTRANET_PREFIX=`/bin/ipcalc --prefix 0.0.0.0 $INTRANET_MASK|cut -f2 -d=`;
chomp($INTRANET_PREFIX);
$INTERNET_PREFIX=`/bin/ipcalc --prefix 0.0.0.0 $INTERNET_MASK|cut -f2 -d=`;
chomp($INTERNET_PREFIX);
# See if we have 2 network cards
$ETH1_ONBOOT=`grep ONBOOT /etc/sysconfig/network-scripts/ifcfg-eth1 | cut -c8-`;chomp ($ETH1_ONBOOT);
# File creation
if ($DNS_SECONDARY ne "") {
$DNS_SECONDARY .= " ;";
}
# OPTIONS
print "
include \"/etc/named.acls\";
options {
directory \"/var/named\";
allow-query { reseaux_slis; };
//forward only;
//forwarders { $DNS_PRIMARY ; $DNS_SECONDARY };
query-source address * port 53;
};
";
# INTERNAL VIEW
print "
view \"internal\" {
match-clients { $INTRANET_NET/$INTRANET_PREFIX;};
recursion yes;
zone \".\" {
type forward;
forward only;
forwarders { $DNS_PRIMARY ; $DNS_SECONDARY };
};
zone \"0.0.127.in-addr.arpa\" {
type master;
file \"named.local\";
};
zone \"$hostname\" {
type master;
file \"zone.internal\";
allow-query { any; };
};
";
if ($ETH1_ONBOOT eq "yes") {
print "
zone \"$zone.in-addr.arpa\" {
type master;
file \"named.private\";
};";}
# MAJ DNS, FC, rΘcupΘration du nom de la zone
use DBI;
use Sys::Syslog qw(:DEFAULT setlogsock);
use MIME::Base64;
#do '/usr/local/sbin/slis-sys.inc.pl';
# Connection variables
do '/home/hadmin/cgi-bin/base/config_pgsql.inc.pl';
$DRIVER="Pg";
$PORT="5432";
# Connection to SQL server
$dsn = "DBI:$DRIVER:dbname=$BASE_HADMIN;host=$PGSQL_SERVER;port=$PORT";
$dbh = DBI->connect($dsn,$ADMINUSER,$ADMINPASS);
# Language file
if (not defined($LANGUAGE)) {
$LANGUAGE="french";
#syslog('warning',"WARN: Variable \$LANGUAGE not found in slis.conf.pl");
#syslog('warning',"WARN: using \"$LANGUAGE\" as the language for reports");
}
$sth = $dbh->prepare("SELECT nomzone from DNSzone where nomzone <> '$hostname'");
$sth->execute;
@zone=$sth->fetchrow_array;
$z = $zone[0];
if ($z ne '') {
print "
zone \"$zone[0]\"{
type master;
file \"intranet.local\";
allow-query {any;};
};
";
}
print "\n};";
# KNOWN EXTERNAL VIEW
if ("$ROUTER_TYPE" ne "9") {
print "
view \"known-external\" {
match-clients { $INTERNET_NET/$INTERNET_PREFIX;};
recursion yes;
zone \".\" {
type forward;
forward only;
forwarders { $DNS_PRIMARY ; $DNS_SECONDARY };
};
zone \"0.0.127.in-addr.arpa\" {
type master;
file \"named.local\";
};
zone \"$hostname\" {
type master;
file \"zone.external\";
allow-query { any; };
};
";
if ($ETH1_ONBOOT eq "yes") {
print "
zone \"$zone.in-addr.arpa\" {
type master;
file \"named.private\";
};
};";
}
}
# LOCALHOST VIEW
print "
view \"local\" {
match-clients { 127.0.0.1; };
recursion yes;
zone \".\" {
type forward;
forward only;
forwarders { $DNS_PRIMARY ; $DNS_SECONDARY };
};
zone \"0.0.127.in-addr.arpa\" {
type master;
file \"named.local\";
};
zone \"$hostname\" {
type master;
file \"zone.local\";
allow-query { any; };
};
";
if ($z ne '') {
print "
zone \"$zone[0]\"{
type master;
file \"intranet.local\";
allow-query {any;};
};
";
}
if ($ETH1_ONBOOT eq "yes") {
print "
zone \"$zone.in-addr.arpa\" {
type master;
file \"named.private\";
};
};";
}
# EXTERNAL VIEW
print "
view \"external\" {
match-clients { any; };
recursion no;
zone \".\" {
type forward;
forward only;
forwarders { $DNS_PRIMARY ; $DNS_SECONDARY };
};
zone \"0.0.127.in-addr.arpa\" {
type master;
file \"named.local\";
};
zone \"$hostname\" {
type master;
file \"zone.external\";
allow-query { any; };
};
";
if ($ETH1_ONBOOT eq "yes") {
print "
zone \"$zone.in-addr.arpa\" {
type master;
file \"named.private\";
};
};
";
}
# Logging is minimized
print "
logging {
//category statistics { null;};
category security { default_syslog; default_debug;};
category default { null;};
};
";