+# Function to generate the required configuration file for the DDNS tool.
+sub GenerateDDNSConfigFile {
+ # Open datafile file
+ open(SETTINGS, "<$datafile") or die "Could not open $datafile.";
+
+ open(FILE, ">${General::swroot}/ddns/ddns.conf");
+
+ # Global configuration options.
+ print FILE "[config]\n";
+
+ # Check if we guess our IP address by an extranal server.
+ if ($settings{'BEHINDROUTER'} eq "FETCH_IP") {
+ print FILE "guess_external_ip = true\n";
+ } else {
+ print FILE "guess_external_ip = false\n";
+ }
+
+ # Use an upstream proxy and generate proxy url.
+ my %proxysettings;
+ &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
+ if ($proxysettings{'UPSTREAM_PROXY'}) {
+ my $proxy_string = "http://";
+
+ if ($proxysettings{'UPSTREAM_USER'} && $proxysettings{'UPSTREAM_PASSWORD'}) {
+ $proxy_string .= "$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@";
+ }
+
+ $proxy_string .= $proxysettings{'UPSTREAM_PROXY'};
+
+ print FILE "proxy = $proxy_string\n";
+ }
+
+ print FILE "\n";
+
+ while (<SETTINGS>) {
+ my $line = $_;
+
+ # Generate array based on the line content (seperator is a single or multiple space's)
+ my @settings = split(/,/, $line);
+ my ($provider, $hostname, $domain, $proxy, $wildcards, $username, $password, $enabled) = @settings;
+
+ # Skip entries if they are not (longer) supported.
+ next if (!&General::is_part_of("$provider", @providers));
+
+ # Skip disabled entries.
+ next if ($enabled eq "off");
+
+ print FILE "[$hostname.$domain]\n";
+ print FILE "provider = $provider\n";
+
+ my $use_token = 0;
+
+ # Handle token based auth for various providers.
+ if ($provider ~~ ["dns.lightningwirelabs.com", "regfish.com"] && $username eq "token") {
+ $use_token = 1;
+
+ # Handle token auth for freedns.afraid.org.
+ } elsif ($provider eq "freedns.afraid.org" && $password eq "") {
+ $use_token = 1;
+ $password = $username;
+
+ # Handle keys for nsupdate
+ } elsif (($provider eq "nsupdate") && $username && $password) {
+ print FILE "key = $username\n";
+ print FILE "secret = $password\n";
+
+ $username = "";
+ $password = "";
+
+ # Handle keys for nsupdate.info
+ } elsif (($provider eq "nsupdate.info") && $password) {
+ print FILE "secret = $password\n";
+
+ $username = "";
+ $password = "";
+ }
+
+ # Write auth details.
+ if ($use_token) {
+ print FILE "token = $password\n";
+ } elsif ($username && $password) {
+ print FILE "username = $username\n";
+ print FILE "password = $password\n";
+ }
+
+ # These providers need to be set to only use IPv4.
+ if ($provider ~~ ["freedns.afraid.org", "nsupdate.info", "variomedia.de", "zoneedit.com"]) {
+ print FILE "proto = ipv4\n";
+ }
+
+ print FILE "\n";
+ }
+
+ close(SETTINGS);
+ close(FILE);
+}
+
+# Function which generates an array (@providers) which contains the supported providers.
+sub GetProviders {
+ # Get supported providers.
+ open(PROVIDERS, "/usr/bin/ddns list-providers |");
+
+ # Create new array to store the providers.
+ my @providers = ();
+
+ while (<PROVIDERS>) {
+ my $provider = $_;
+
+ # Remove following newlines.
+ chomp($provider);
+
+ # Add provider to the array.
+ push(@providers, $provider);
+ }