summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-03-06 13:31:27 +0500
committerDaniil Baturin <daniil@baturin.org>2015-03-06 13:31:27 +0500
commit347eaadaa4ea8629346d3e5dbd2752917c68579c (patch)
tree91685483e8e5d4c43b5889e6cc13212f5f2cd5d4
parent249e7e2b5792ffcc428546192b06b7120d5ccf5b (diff)
parentaf6f00be213aaa0a74977e58130c8aede7ad2f22 (diff)
downloadvyatta-cfg-system-347eaadaa4ea8629346d3e5dbd2752917c68579c.tar.gz
vyatta-cfg-system-347eaadaa4ea8629346d3e5dbd2752917c68579c.zip
Merge pull request #44 from kouak/dyndns
Add flexibility to dynamic dns configuration (#507) If this is proven problematic, we can revert and work more on it.
-rwxr-xr-xscripts/dynamic-dns/vyatta-dynamic-dns.pl116
-rw-r--r--templates/service/dns/dynamic/interface/node.tag/service/node.def22
-rw-r--r--templates/service/dns/dynamic/interface/node.tag/service/node.tag/protocol/node.def3
-rw-r--r--templates/service/dns/dynamic/interface/node.tag/service/node.tag/server/node.def2
4 files changed, 116 insertions, 27 deletions
diff --git a/scripts/dynamic-dns/vyatta-dynamic-dns.pl b/scripts/dynamic-dns/vyatta-dynamic-dns.pl
index 0b2119d4..cf9a0ae0 100755
--- a/scripts/dynamic-dns/vyatta-dynamic-dns.pl
+++ b/scripts/dynamic-dns/vyatta-dynamic-dns.pl
@@ -39,13 +39,47 @@ my $ddclient_config_dir = '/etc/ddclient';
# main
#
-my ($update_dynamicdns, $op_mode_update_dynamicdns, $stop_dynamicdns, $interface);
+my %_services_defaults = (
+ dyndns => {
+ protocol => "dyndns2",
+ },
+ afraid => {
+ protocol => "freedns",
+ server => "freedns.afraid.org"
+ },
+ dnspark => {
+ protocol => "dnspark"
+ },
+ dslreports => {
+ protocol => "dslreports"
+ },
+ easydns => {
+ protocol => "easydns"
+ },
+ namecheap => {
+ protocol => "namecheap"
+ },
+ zoneedit => {
+ protocol => "zoneedit1"
+ },
+ changeip => {
+ protocol => "changeip"
+ },
+ noip => {
+ protocol => "noip"
+ }
+);
+
+my ($update_dynamicdns, $op_mode_update_dynamicdns, $stop_dynamicdns, $interface, $get_services, $get_default_services, $check_nodes);
GetOptions(
"update-dynamicdns!" => \$update_dynamicdns,
"stop-dynamicdns!" => \$stop_dynamicdns,
"op-mode-update-dynamicdns!" => \$op_mode_update_dynamicdns,
- "interface=s" => \$interface
+ "interface=s" => \$interface,
+ "get-services!" => \$get_services,
+ "get-default-services!" => \$get_default_services,
+ "check-nodes!" => \$check_nodes
);
if (defined $update_dynamicdns) {
@@ -59,6 +93,11 @@ if (defined $update_dynamicdns) {
dynamicdns_restart() if (defined $op_mode_update_dynamicdns);
dynamicdns_stop() if (defined $stop_dynamicdns);
+dynamicdns_get_services() if (defined $get_services);
+dynamicdns_get_default_services() if (defined $get_default_services);
+
+dynamicdns_check_nodes() if (defined $check_nodes);
+
exit 0;
#
@@ -85,6 +124,64 @@ sub dynamicdns_stop {
system("rm -f $ddclient_cache_dir/ddclient_$interface.cache >&/dev/null");
}
+sub dynamicdns_check_nodes {
+ my $config = new Vyatta::Config;
+ $config->setLevel("service dns dynamic interface $interface");
+
+ my @services = $config->listNodes("service");
+ foreach my $service (@services) {
+ $config->setLevel("service dns dynamic interface $interface service $service");
+
+ # Check if we have a login, a password and host-name(s)
+ if(!defined($config->returnValue('login')) or $config->returnValue('login') eq '') {
+ print "A login must be set for dynamic dns service $service on interface $interface\n";
+ exit 1;
+ }
+ if(!defined($config->returnValue('password')) or $config->returnValue('password') eq '') {
+ print "A password must be set for dynamic dns service $service on interface $interface\n";
+ exit 1;
+ }
+ if(!defined($config->returnValues('host-name')) or $config->returnValues('host-name') eq 0) {
+ print "An host-name must be set for dynamic dns service $service on interface $interface\n";
+ exit 1;
+ }
+ # Check if we have a non-default service
+ if(!defined($_services_defaults{$service})) {
+ if(!defined($config->returnValue('protocol')) or $config->returnValue('protocol') eq '') {
+ print "A protocol must be set for custom dynamic dns service $service on interface $interface\n";
+ exit 1;
+ }
+ if(!defined($config->returnValue('server')) or $config->returnValue('server') eq '') {
+ print "A server must be set for custom dynamic dns service $service on interface $interface\n";
+ exit 1;
+ }
+ }
+ }
+ exit 0;
+}
+
+# Will return a string with default services only (those which don't need an explicit server or protocol value)
+sub dynamicdns_get_default_services {
+ print join(' ', keys(%_services_defaults));
+ print "\n";
+}
+
+# Will return a string with default services and set services, useful for CLI completion
+sub dynamicdns_get_services {
+ my @o_services = keys %_services_defaults;
+ my $output;
+ my $config = new Vyatta::Config;
+ $config->setLevel("service dns dynamic interface $interface");
+
+ my @services = $config->listNodes("service");
+ foreach my $service (@services) {
+ push(@o_services, $service);
+ }
+ my @unique_o_services = do { my %seen; grep { !$seen{$_}++ } @o_services };
+ print join(' ', @unique_o_services);
+ print "\n";
+}
+
sub dynamicdns_get_constants {
my $output;
@@ -117,18 +214,21 @@ sub dynamicdns_get_values {
my @services = $config->listNodes("service");
foreach my $service (@services) {
$config->setLevel("service dns dynamic interface $interface service $service");
- $service="freedns" if ($service eq "afraid");
- $service="dslreports1" if ($service eq "dslreports");
- $service="dyndns2" if ($service eq "dyndns");
- $service="zoneedit1" if ($service eq "zoneedit");
+ my ($protocol, $server);
+ $protocol = $_services_defaults{$service}{'protocol'} if defined $_services_defaults{$service}{'protocol'};
+ $protocol = $config->returnValue("protocol") if defined $config->returnValue("protocol");
+ $server = $_services_defaults{$service}{'server'} if defined $_services_defaults{$service}{'server'};
+ $server = $config->returnValue("server") if defined $config->returnValue("server");
+
my $login = $config->returnValue("login");
my $password = $config->returnValue("password");
my @hostnames = $config->returnValues("host-name");
- my $server = $config->returnValue("server");
+
+ $output .= "# Service : $service\n";
foreach my $hostname (@hostnames) {
$output .= "server=$server," if defined $server;
- $output .= "protocol=$service\n";
+ $output .= "protocol=$protocol\n";
$output .= "max-interval=28d\n";
$output .= "login=$login\n";
$output .= "password='$password'\n";
diff --git a/templates/service/dns/dynamic/interface/node.tag/service/node.def b/templates/service/dns/dynamic/interface/node.tag/service/node.def
index e5190a14..85208d2e 100644
--- a/templates/service/dns/dynamic/interface/node.tag/service/node.def
+++ b/templates/service/dns/dynamic/interface/node.tag/service/node.def
@@ -1,23 +1,9 @@
tag:
help: Service being used for Dynamic DNS [REQUIRED]
type: txt
-syntax:expression: exec "
- service_array=(afraid dnspark dslreports dyndns easydns namecheap noip sitelutions zoneedit)
- service_array_len=${#service_array[*]}
- i=0
- while [ $i -lt $service_array_len ]; do
- if [ \"${service_array[$i]}\" == \"$VAR(@)\" ] ; then
- exit 0
- fi
- let i++
- done
- echo Invalid service [$VAR(@)]
- exit 1 "
-allowed: local -a array ;
- array=(afraid dnspark dslreports dyndns easydns namecheap noip sitelutions zoneedit);
- echo -n ${array[@]}
+val_help: txt; Custom or predefined service
-commit:expression: $VAR(./@/login) != ""; "Set login for service $VAR(./@) to send DDNS updates for interface $VAR(../@)"
-commit:expression: $VAR(./@/password) != ""; "Set password for service $VAR(./@) to send DDNS updates for interface $VAR(../@)"
-commit:expression: $VAR(./@/host-name) != ""; "Set atleast one host-name registered with service $VAR(./@) to send DDNS updates for interface $VAR(../@)"
+allowed:/opt/vyatta/sbin/vyatta-dynamic-dns.pl --interface $VAR(../@) --get-services
+
+commit:expression: exec "/opt/vyatta/sbin/vyatta-dynamic-dns.pl --interface $VAR(../@) --check-nodes"
diff --git a/templates/service/dns/dynamic/interface/node.tag/service/node.tag/protocol/node.def b/templates/service/dns/dynamic/interface/node.tag/service/node.tag/protocol/node.def
new file mode 100644
index 00000000..0c216d8d
--- /dev/null
+++ b/templates/service/dns/dynamic/interface/node.tag/service/node.tag/protocol/node.def
@@ -0,0 +1,3 @@
+help: ddclient protocol to be used for dynamic dns service [REQUIRED FOR CUSTOM SERVICES]
+type: txt
+val_help: <protocol>; ddclient protocol (see ddclient manual)
diff --git a/templates/service/dns/dynamic/interface/node.tag/service/node.tag/server/node.def b/templates/service/dns/dynamic/interface/node.tag/service/node.tag/server/node.def
index 247755a1..b1bb8b87 100644
--- a/templates/service/dns/dynamic/interface/node.tag/service/node.tag/server/node.def
+++ b/templates/service/dns/dynamic/interface/node.tag/service/node.tag/server/node.def
@@ -1,4 +1,4 @@
-help: Server to send DDNS update to (IP address|hostname)
+help: Server to send DDNS update to (IP address|hostname) [REQUIRED FOR SERVICES]
type: txt
val_help: ipv4; IP address of DDNS server
val_help: <hostname>; Hostname of DDNS server