package Conf;

use strict;

use Errors;

BEGIN {
    @Conf::Ids = (@Conf::Ids, '$Header: /afs/sipb.mit.edu/project/zoned/src/RCS/Conf.pm,v 1.7 2018/10/10 23:57:20 jweiss Exp $ ');
};

# Configuration variables

# Location of the master list of zones to be managed, the locations of 
#   the source files, and the source file maintainer email addresses
$Conf::zonelist = '/afs/sipb/project/zoned/zoned.zones';

# Mail and zephyr recipients for different kinds of messages
#   fatal errors are errors that entirely block operation of zoned, such 
#     as difficulties creating a named.conf or syntax errors in zoned.zones
#   zone errors are errors that block the generation of one particular
#     zone's zone file but do not interfere with other zones.  Zone 
#     errors will also be mailed to the zone's maintainer/RP
$Conf::fatal_mailto = 'ingolia@mit.edu';
$Conf::zone_err_mailto = 'ingolia@mit.edu';
$Conf::zone_reload_mailto = '';
$Conf::debug_mailto = '';
$Conf::fatal_zephyrto = '-c sipb-auto -i zoned';
$Conf::zone_err_zephyrto = '-c sipb-auto -i zoned';
$Conf::zone_reload_zephyrto = '-c sipb-auto -i zoned';
$Conf::debug_zephyrto = '-c ingolia -i zoned';

# Programs to use for mail and zephyr notification
#   $Conf::mail should be an ordinary mail, that can do,
#     $Conf::mail -s <subject> <recipient> 
#   and then take a message to mail on standard input.
#   $Conf::zwrite shoudl be a zwrite that can take,
#     $Conf::zwrite -n -d -s <sig> <recipient>
#   and then take a zephyr on standard input.
$Conf::mail = '/usr/bin/mh/mhmail';
$Conf::zwrite = '/usr/bin/zwrite';

# A directory where zoned can write various files it uses
$Conf::basedir = '/etc/bind/zoned';

# The location of various files for bind:
#   The actual named.conf it reads
#   The manually-generated top of the named.conf file that zoned does not
#     manage
#   The cache directory named should use for slave domains
#   The pid file so it can be HUP'd after changes
$Conf::named_conf = '/etc/bind/named.conf.local';
$Conf::named_manual = '/etc/bind/named.conf.manual';
$Conf::named_cache_dir = '/var/lib/bind';
$Conf::named_pidfile = '/run/named/named.pid';

# Our name as a nameserver
$Conf::ns_name = 'ns1.sipb.org';

# TTL and timing for secondaries
$Conf::ttl = 10800;
$Conf::refresh = 3600;
$Conf::retry = 300;
$Conf::expire = 605000;
$Conf::negttl = 43200;

#
# Routines to manage zoned's scratch directory, $Conf::basedir
#

# Ensure that our base directory exists or create it if it does not
sub ensure_basedir {
    if (-d $Conf::basedir) {
	if (-r $Conf::basedir and -x $Conf::basedir and -o $Conf::basedir) {
	    return;
	} else {
	    die("Scratch directory $Conf::basedir must be readable, writeable, and searchable\n");
	}
    } elsif (-e $Conf::basedir) {
	die("Scratch directory $Conf::basedir exists but is not a directory\n");
    } else {
	mkdir($Conf::basdir, 0755)
	    or die("Could not create $Conf::basedir: $!\n");
    }
};

# Construct a full pathname for a file that lives in our scratch directory
sub filepath {
    my $filename = shift;
    return "$Conf::basedir/$filename";
}
