diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | scripts/dns-forwarding/vyatta-dns-forwarding.pl | 126 | ||||
-rw-r--r-- | templates/service/dns-forwarding/node.def | 10 |
3 files changed, 137 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 742f9025..057252dd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,6 +29,7 @@ sbin_SCRIPTS += scripts/keepalived/vyatta-vrrp-state.pl sbin_SCRIPTS += scripts/telnetd.init sbin_SCRIPTS += scripts/add_bootfile_eth_hwid sbin_SCRIPTS += scripts/mod_bootfile_eth_hwid +sbin_SCRIPTS += scripts/dns-forwarding/vyatta-dns-forwarding.pl noinst_DATA = test_bootfile diff --git a/scripts/dns-forwarding/vyatta-dns-forwarding.pl b/scripts/dns-forwarding/vyatta-dns-forwarding.pl new file mode 100644 index 00000000..01111d4a --- /dev/null +++ b/scripts/dns-forwarding/vyatta-dns-forwarding.pl @@ -0,0 +1,126 @@ +#!/usr/bin/perl +# +# Module: vyatta-dns-forwarding.pl +# +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2008 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Mohit Mehta +# Date: August 2008 +# Description: Script to glue Vyatta CLI to dnsmasq daemon +# +# **** End License **** +# + +use lib "/opt/vyatta/share/perl5/"; +use VyattaConfig; +use VyattaMisc; +use Getopt::Long; + +use strict; +use warnings; + +my $dnsforwarding_init = '/etc/init.d/dnsmasq'; +my $dnsforwarding_conf = '/etc/dnsmasq.conf'; + +sub dnsforwarding_init { + +} + +sub dnsforwarding_restart { + system("$dnsforwarding_init restart 2&>1 /dev/null"); + print "Setting up DNS forwarding.\n"; +} + +sub dnsforwarding_stop { + system("$dnsforwarding_init stop 2&>1 /dev/null"); + print "Stopping DNS forwarding.\n"; +} + +sub dnsforwarding_get_constants { + my $output; + + my $date = `date`; + chomp $date; + $output = "#\n# autogenerated by vyatta-dns-forwarding.pl on $date\n#\n"; + return $output; +} + +sub dnsforwarding_get_values { + my $output = ''; + my $config = new VyattaConfig; + + $config->setLevel("service dns-forwarding"); + + return $output; +} + +sub dnsforwarding_write_file { + my ($config) = @_; + + open(my $fh, '>', $dnsforwarding_conf) || die "Couldn't open $dnsforwarding_conf - $!"; + print $fh $config; + close $fh; +} + +sub check_nameserver { + + my $cmd = `grep nameserver /etc/resolv.conf|wc -l`; + return $cmd; +} + +# +# main +# +my $init_dnsforwarding; +my $update_dnsforwarding; +my $stop_dnsforwarding; +my $nameserver; + +GetOptions("init-dnsforwarding!" => \$init_dnsforwarding, + "update-dnsforwarding!" => \$update_dnsforwarding, + "stop-dnsforwarding!" => \$stop_dnsforwarding, + "nameserver!" => \$nameserver); + +if (defined $nameserver) { + my $nameserver_exists = check_nameserver(); + if ($nameserver_exists < 1){ + exit 1; + } else { + exit 0; + } +} + + +if (defined $init_dnsforwarding) { + dnsforwarding_init(); +} + +if (defined $update_dnsforwarding) { + my $config; + + $config = dnsforwarding_get_constants(); + $config .= dnsforwarding_get_values(); + dnsforwarding_write_file($config); + dnsforwarding_restart(); +} + +if (defined $stop_dnsforwarding) { + dnsforwarding_stop(); +} + +exit 0; + +# end of file + diff --git a/templates/service/dns-forwarding/node.def b/templates/service/dns-forwarding/node.def new file mode 100644 index 00000000..f84e4f02 --- /dev/null +++ b/templates/service/dns-forwarding/node.def @@ -0,0 +1,10 @@ +help: Configure Domain Name Server (DNS) forwarding +syntax:expression: exec "/opt/vyatta/sbin/vyatta-dns-forwarding.pl --nameserver"; "No nameserver exists to forward DNS queries" +create:expression: "/opt/vyatta/sbin/vyatta-dns-forwarding.pl --init-dnsforwarding" +delete:expression: "touch /tmp/dnsmasq.$PPID" +end:expression: "if [ -f \"/tmp/dnsmasq.$PPID\" ]; then \ + sudo /opt/vyatta/sbin/vyatta-dns-forwarding.pl --stop-dnsforwarding \ + rm /tmp/dnsmasq.$PPID; \ + else \ + sudo /opt/vyatta/sbin/vyatta-dns-forwarding.pl --update-dnsforwarding; \ + fi; " |