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 >
Text File  |  2003-06-18  |  5KB  |  260 lines

  1. #!/usr/bin/perl
  2. # $Id: mknamedconf,v 3.3 2003/06/17 18:23:37 bzizou Exp $ #
  3.  
  4. # Named automatic configuration
  5.  
  6. # Load SLIS variables
  7. do '/home/hadmin/slis.conf.pl';
  8. $hostname=`cat /etc/HOSTNAME`;
  9. chomp($hostname);
  10.  
  11. # If DNS is given by DHCP, try to get it from /etc/resolv.conf
  12. if ($DNS_PRIMARY eq "auto" || $DNS_PRIMARY eq "") {
  13.   $nameserver=`grep nameserver /etc/resolv.conf|awk '{print \$2}'|head -1`;
  14.   chomp($nameserver);
  15.  
  16.   # If resolv.conf contains 127.0.0.1, then we took the default value
  17.   if ($nameserver eq "127.0.0.1") {
  18.     $DNS_PRIMARY=$DNS_DEFAULT;
  19.     $DNS_SECONDARY=$DNS_DEFAULT;
  20.   }
  21.   else {
  22.     $DNS_PRIMARY=$nameserver;
  23.     $DNS_SECONDARY=$DNS_DEFAULT;
  24.   }
  25. }
  26.  
  27. # Local zone guessing
  28. $ip=`/sbin/ifconfig eth1 2> /dev/null|grep inet |awk '{print \$2}'|awk -F: '{print \$2}' 2>/dev/null`;
  29. if ($ip !~ /.*\..*\..*\..*/) {
  30.   $ip="$INTRANET_NET";
  31. }
  32. chomp $ip;
  33. ($a,$b,$c,$d)=split(/\./,$ip);
  34. $zone="$b.$a";
  35. if ($zone == "") {
  36.   $zone="16.172";
  37. }
  38.  
  39. # Mask conversion
  40. $INTRANET_PREFIX=`/bin/ipcalc --prefix 0.0.0.0 $INTRANET_MASK|cut -f2 -d=`;
  41. chomp($INTRANET_PREFIX);
  42. $INTERNET_PREFIX=`/bin/ipcalc --prefix 0.0.0.0 $INTERNET_MASK|cut -f2 -d=`;
  43. chomp($INTERNET_PREFIX);
  44.  
  45. # See if we have 2 network cards
  46. $ETH1_ONBOOT=`grep ONBOOT /etc/sysconfig/network-scripts/ifcfg-eth1 | cut -c8-`;chomp ($ETH1_ONBOOT);
  47.  
  48. # File creation
  49. if ($DNS_SECONDARY ne "") {
  50.   $DNS_SECONDARY .= " ;";
  51. }
  52.  
  53. # OPTIONS
  54. print "
  55. include \"/etc/named.acls\";
  56.  
  57. options {
  58.     directory \"/var/named\";
  59.     allow-query { reseaux_slis; };
  60.     //forward only;
  61.     //forwarders { $DNS_PRIMARY ; $DNS_SECONDARY };
  62.     query-source address * port 53;
  63. };
  64. ";
  65.  
  66. # INTERNAL VIEW
  67. print "
  68. view \"internal\" {
  69.   match-clients { $INTRANET_NET/$INTRANET_PREFIX;};
  70.   recursion yes;
  71.  
  72.   zone \".\" {
  73.     type forward;
  74.     forward only;
  75.     forwarders { $DNS_PRIMARY ; $DNS_SECONDARY };
  76.   };
  77.  
  78.   zone \"0.0.127.in-addr.arpa\" {
  79.     type master;
  80.     file \"named.local\";
  81.   };
  82.  
  83.   zone \"$hostname\" {
  84.     type master;
  85.     file \"zone.internal\";
  86.     allow-query { any; };
  87.   };
  88. ";
  89.  
  90. if ($ETH1_ONBOOT eq "yes") {
  91.   print "
  92.  
  93.   zone \"$zone.in-addr.arpa\" {
  94.     type master;
  95.     file \"named.private\";
  96.   };";}
  97.  
  98. # MAJ DNS, FC, rΘcupΘration du nom de la zone
  99. use DBI;
  100. use Sys::Syslog qw(:DEFAULT setlogsock);
  101. use MIME::Base64;
  102.  
  103. #do '/usr/local/sbin/slis-sys.inc.pl';
  104.  
  105. # Connection variables
  106. do '/home/hadmin/cgi-bin/base/config_pgsql.inc.pl';
  107. $DRIVER="Pg";
  108. $PORT="5432";
  109.  
  110. # Connection to SQL server
  111. $dsn = "DBI:$DRIVER:dbname=$BASE_HADMIN;host=$PGSQL_SERVER;port=$PORT";
  112. $dbh = DBI->connect($dsn,$ADMINUSER,$ADMINPASS);
  113.  
  114. # Language file
  115. if (not defined($LANGUAGE)) {
  116.   $LANGUAGE="french";
  117.   #syslog('warning',"WARN: Variable \$LANGUAGE not found in slis.conf.pl");
  118.   #syslog('warning',"WARN: using \"$LANGUAGE\" as the language for reports");
  119. }
  120. $sth = $dbh->prepare("SELECT nomzone from DNSzone where nomzone <> '$hostname'");
  121. $sth->execute;
  122. @zone=$sth->fetchrow_array;
  123. $z = $zone[0];
  124. if ($z ne '') {
  125.   print "
  126.   zone \"$zone[0]\"{
  127.       type master;
  128.       file \"intranet.local\";
  129.       allow-query {any;};
  130.   };
  131. ";
  132. }
  133.  
  134. print "\n};";
  135.  
  136. # KNOWN EXTERNAL VIEW
  137. if ("$ROUTER_TYPE" ne "9") {
  138.   print "
  139.  
  140. view \"known-external\" {
  141.   match-clients { $INTERNET_NET/$INTERNET_PREFIX;};
  142.   recursion yes;
  143.  
  144.   zone \".\" {
  145.         type forward;
  146.         forward only;
  147.         forwarders { $DNS_PRIMARY ; $DNS_SECONDARY };
  148.   };
  149.  
  150.   zone \"0.0.127.in-addr.arpa\" {
  151.         type master;
  152.         file \"named.local\";
  153.   };
  154.  
  155.   zone \"$hostname\" {
  156.         type master;
  157.         file \"zone.external\";
  158.         allow-query { any; };
  159.   };
  160. ";
  161.  
  162. if ($ETH1_ONBOOT eq "yes") {
  163.   print "
  164.   zone \"$zone.in-addr.arpa\" {
  165.     type master;
  166.     file \"named.private\";
  167.   };
  168. };";
  169.   }
  170. }
  171.  
  172. # LOCALHOST VIEW
  173. print "
  174.  
  175. view \"local\" {
  176.   match-clients { 127.0.0.1; };
  177.   recursion yes;
  178.  
  179.   zone \".\" {
  180.         type forward;
  181.         forward only;
  182.         forwarders { $DNS_PRIMARY ; $DNS_SECONDARY };
  183.   };
  184.  
  185.   zone \"0.0.127.in-addr.arpa\" {
  186.         type master;
  187.         file \"named.local\";
  188.   };
  189.  
  190.   zone \"$hostname\" {
  191.         type master;
  192.         file \"zone.local\";
  193.         allow-query { any; };
  194.   };
  195. ";
  196.  
  197. if ($z ne '') {
  198. print "
  199.   zone \"$zone[0]\"{
  200.       type master;
  201.       file \"intranet.local\";
  202.       allow-query {any;};
  203.       };
  204. ";
  205. }
  206. if ($ETH1_ONBOOT eq "yes") {
  207.   print "
  208.   zone \"$zone.in-addr.arpa\" {
  209.     type master;
  210.     file \"named.private\";
  211.   };
  212. };";
  213. }
  214.  
  215.  
  216. # EXTERNAL VIEW
  217. print "
  218.  
  219. view \"external\" {
  220.   match-clients { any; };
  221.   recursion no;
  222.  
  223.   zone \".\" {
  224.         type forward;
  225.         forward only;
  226.         forwarders { $DNS_PRIMARY ; $DNS_SECONDARY };
  227.   };
  228.  
  229.   zone \"0.0.127.in-addr.arpa\" {
  230.         type master;
  231.         file \"named.local\";
  232.   };
  233.  
  234.   zone \"$hostname\" {
  235.         type master;
  236.         file \"zone.external\";
  237.         allow-query { any; };
  238.   };
  239. ";
  240.  
  241. if ($ETH1_ONBOOT eq "yes") {
  242.   print "
  243.   zone \"$zone.in-addr.arpa\" {
  244.     type master;
  245.     file \"named.private\";
  246.   };
  247. };
  248. ";
  249. }
  250.  
  251. # Logging is minimized
  252. print "
  253. logging {
  254.         //category statistics { null;};
  255.         category security { default_syslog; default_debug;};
  256.         category default { null;};
  257. };
  258.  
  259. ";
  260.