diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | scripts/vyatta-op-dynamic-dns.pl | 119 | ||||
-rw-r--r-- | templates/show/dns/dynamic/node.def | 1 | ||||
-rw-r--r-- | templates/show/dns/dynamic/status/node.def | 3 | ||||
-rw-r--r-- | templates/update/dns/dynamic/interface/node.def | 1 | ||||
-rw-r--r-- | templates/update/dns/dynamic/interface/node.tag/node.def | 6 | ||||
-rw-r--r-- | templates/update/dns/dynamic/node.def | 1 | ||||
-rw-r--r-- | templates/update/dns/node.def | 1 |
8 files changed, 133 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 1063b78..627ed32 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,7 @@ bin_sudo_users_SCRIPTS = scripts/vyatta-identify-interface.pl bin_sudo_users_SCRIPTS += scripts/vyatta-delete-log-file.sh bin_sudo_users_SCRIPTS += scripts/vyatta-reboot.pl bin_sudo_users_SCRIPTS += scripts/vyatta-op-dns-forwarding.pl +bin_sudo_users_SCRIPTS += scripts/vyatta-op-dynamic-dns.pl cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \ cpio -0pd diff --git a/scripts/vyatta-op-dynamic-dns.pl b/scripts/vyatta-op-dynamic-dns.pl new file mode 100644 index 0000000..b6460f5 --- /dev/null +++ b/scripts/vyatta-op-dynamic-dns.pl @@ -0,0 +1,119 @@ +#!/usr/bin/perl +# +# Module: vyatta-op-dynamic-dns.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: September 2008 +# Description: Script to execute op-mode commands for Dynamic DNS +# +# **** End License **** +# + +use lib "/opt/vyatta/share/perl5/"; +use Getopt::Long; +use VyattaConfig; +use strict; +use warnings; + +sub print_ddns_stats { + my $ddclient_cache_files = '/var/cache/ddclient/*'; + my @all_cached_entries = `grep "^atime" $ddclient_cache_files 2>/dev/null`; + if (@all_cached_entries > 0){ + foreach my $each_entry (@all_cached_entries) { + my $interface = undef; + if (`ls $ddclient_cache_files | wc -l` == 1) { + my $interface_file = `ls $ddclient_cache_files`; + my @split_on_cache = split(/.cache/, $interface_file); + my @interface_split = split(/_/, $split_on_cache[1]); + $interface = $interface_split[1]; + } else { + my @split_on_cache = split(/.cache:/, $each_entry); + my @interface_split = split(/_/, $split_on_cache[0]); + $interface=$interface_split[1]; + } + print "interface : $interface\n"; + my @split_on_ip = split(/ip=/, $each_entry); + if (@split_on_ip > 1){ + my @ip = split(/,/, $split_on_ip[1]); + print "ip address : $ip[0]\n"; + } + my @split_on_host = split(/host=/, $each_entry); + my @host = split(/,/, $split_on_host[1]); + print "host-name : $host[0]\n"; + my @split_on_atime = split(/atime=/, $each_entry); + my @atime = split(/,/, $split_on_atime[1]); + my $prettytime = scalar(localtime($atime[0])); + print "last update : $prettytime\n"; + my @split_on_status = split(/status=/, $each_entry); + my @status = split(/,/, $split_on_status[1]); + print "update-status: $status[0]\n"; + print "\n"; + } + } else { + print "Dynamic DNS not configured\n"; + } +} + +sub get_ddns_interfaces { + + my $vyatta_config = new VyattaConfig; + $vyatta_config->setLevel("service dns dynamic"); + $vyatta_config->{_active_dir_base} = "/opt/vyatta/config/active/"; + my @ddns_interfaces = $vyatta_config->listOrigNodes("interface"); + @ddns_interfaces = sort(@ddns_interfaces); + return (@ddns_interfaces); + +} + +# +# main +# + +my ($show_status, $update_ddns, $interface, $show_interfaces); + +GetOptions("show-status!" => \$show_status, + "update-ddns!" => \$update_ddns, + "interface=s" => \$interface, + "show-interfaces!" => \$show_interfaces); + +if (defined $show_status) { + print_ddns_stats; +} + +if (defined $update_ddns && defined $interface) { + my @ddns_interfaces = get_ddns_interfaces(); + my $interface_configured = 0; + foreach my $ddns_interface (@ddns_interfaces) { + if ($ddns_interface eq $interface) { + $interface_configured = 1; + } + } + if ($interface_configured == 1) { + system("sudo /opt/vyatta/sbin/vyatta-dynamic-dns.pl --op-mode-update-dynamicdns --interface $interface"); + } else { + print "$interface has not been configured to send Dynamic DNS updates\n"; + } +} + +if (defined $show_interfaces) { + my @ddns_interfaces = get_ddns_interfaces(); + print "@ddns_interfaces\n"; +} + +exit 0; + +# end of file diff --git a/templates/show/dns/dynamic/node.def b/templates/show/dns/dynamic/node.def new file mode 100644 index 0000000..9a06b38 --- /dev/null +++ b/templates/show/dns/dynamic/node.def @@ -0,0 +1 @@ +help: Show Dynamic DNS information diff --git a/templates/show/dns/dynamic/status/node.def b/templates/show/dns/dynamic/status/node.def new file mode 100644 index 0000000..870c883 --- /dev/null +++ b/templates/show/dns/dynamic/status/node.def @@ -0,0 +1,3 @@ +help: Show Dynamic DNS status +run: + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dynamic-dns.pl --show-status diff --git a/templates/update/dns/dynamic/interface/node.def b/templates/update/dns/dynamic/interface/node.def new file mode 100644 index 0000000..c0ef660 --- /dev/null +++ b/templates/update/dns/dynamic/interface/node.def @@ -0,0 +1 @@ +help: Update Dynamic DNS for specified interface diff --git a/templates/update/dns/dynamic/interface/node.tag/node.def b/templates/update/dns/dynamic/interface/node.tag/node.def new file mode 100644 index 0000000..60fb67d --- /dev/null +++ b/templates/update/dns/dynamic/interface/node.tag/node.def @@ -0,0 +1,6 @@ +help: Update Dynamic DNS for specified interface +allowed: + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dynamic-dns.pl --show-interfaces +run: + IFNAME=${5} + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dynamic-dns.pl --update-ddns --interface "$IFNAME" diff --git a/templates/update/dns/dynamic/node.def b/templates/update/dns/dynamic/node.def new file mode 100644 index 0000000..447fcb5 --- /dev/null +++ b/templates/update/dns/dynamic/node.def @@ -0,0 +1 @@ +help: Update Dynamic DNS information diff --git a/templates/update/dns/node.def b/templates/update/dns/node.def new file mode 100644 index 0000000..b8217f6 --- /dev/null +++ b/templates/update/dns/node.def @@ -0,0 +1 @@ +help: Update DNS information |