]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/ddns.cgi
core87: remove grub2 config/image on xen.
[ipfire-2.x.git] / html / cgi-bin / ddns.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2014 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 use strict;
23
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31
32 #workaround to suppress a warning when a variable is used only once
33 my @dummy = ( ${Header::table2colour}, ${Header::colouryellow} );
34 undef (@dummy);
35
36 my %color = ();
37 my %mainsettings = ();
38 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
39 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
40
41 # Config file for basic configuration.
42 my $settingsfile = "${General::swroot}/ddns/settings";
43
44 # Config file to store the configured ddns providers.
45 my $datafile = "${General::swroot}/ddns/config";
46
47 # Dynamic ddns programm call.
48 my @ddnsprog = ("/usr/bin/ddns", "--config",
49 "/var/ipfire/ddns/ddns.conf",
50 "update-all");
51
52 my %settings=();
53 my $errormessage = '';
54
55 # DDNS General settings.
56 $settings{'BEHINDROUTER'} = 'RED_IP';
57
58 # Account settings.
59 $settings{'HOSTNAME'} = '';
60 $settings{'DOMAIN'} = '';
61 $settings{'LOGIN'} = '';
62 $settings{'PASSWORD'} = '';
63 $settings{'ENABLED'} = '';
64 $settings{'PROXY'} = '';
65 $settings{'SERVICE'} = '';
66
67 $settings{'ACTION'} = '';
68
69 # Get supported ddns providers.
70 my @providers = &GetProviders();
71
72 # Hook to regenerate the configuration files, if cgi got called from command line.
73 if ($ENV{"REMOTE_ADDR"} eq "") {
74 &GenerateDDNSConfigFile();
75 exit(0);
76 }
77
78 &Header::showhttpheaders();
79
80 #Get GUI values
81 &Header::getcgihash(\%settings);
82
83 # Read configuration file.
84 open(FILE, "$datafile") or die "Unable to open $datafile.";
85 my @current = <FILE>;
86 close (FILE);
87
88 #
89 # Save General Settings.
90 #
91 if ($settings{'ACTION'} eq $Lang::tr{'save'}) {
92 # Open /var/ipfire/ddns/settings for writing.
93 open(FILE, ">$settingsfile") or die "Unable to open $settingsfile.";
94
95 # Lock file for writing.
96 flock FILE, 2;
97
98 # Check if BEHINDROUTER has been configured.
99 if ($settings{'BEHINDROUTER'} ne '') {
100 print FILE "BEHINDROUTER=$settings{'BEHINDROUTER'}\n";
101 }
102
103 # Close file after writing.
104 close(FILE);
105
106 # Update ddns config file.
107 &GenerateDDNSConfigFile();
108 }
109
110 #
111 # Toggle enable/disable field. Field is in second position
112 #
113 if ($settings{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
114 # Open /var/ipfire/ddns/config for writing.
115 open(FILE, ">$datafile") or die "Unable to open $datafile.";
116
117 # Lock file for writing.
118 flock FILE, 2;
119
120 my @temp;
121 my $id = 0;
122
123 # Read file line by line.
124 foreach my $line (@current) {
125 # Remove newlines.
126 chomp($line);
127
128 if ($settings{'ID'} eq $id) {
129 # Splitt lines (splitting element is a single ",") and save values into temp array.
130 @temp = split(/\,/,$line);
131
132 # Check if we want to toggle ENABLED or WILDCARDS.
133 if ($settings{'ENABLED'} ne '') {
134 # Update ENABLED.
135 print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6],$settings{'ENABLED'}\n";
136 }
137 } else {
138 # Print unmodified line.
139 print FILE "$line\n";
140 }
141
142 # Increase $id.
143 $id++;
144 }
145 undef $settings{'ID'};
146
147 # Close file after writing.
148 close(FILE);
149
150 # Write out logging notice.
151 &General::log($Lang::tr{'ddns hostname modified'});
152
153 # Update ddns config file.
154 &GenerateDDNSConfigFile();
155 }
156
157 #
158 # Add new accounts, or edit existing ones.
159 #
160 if (($settings{'ACTION'} eq $Lang::tr{'add'}) || ($settings{'ACTION'} eq $Lang::tr{'update'})) {
161 # Check if a hostname has been given.
162 if ($settings{'HOSTNAME'} eq '') {
163 $errormessage = $Lang::tr{'hostname not set'};
164 }
165
166 # Check if a valid domainname has been provided.
167 if (!&General::validdomainname($settings{'HOSTNAME'})) {
168 $errormessage = $Lang::tr{'invalid domain name'};
169 }
170
171 # Check if a username has been sent.
172 if ($settings{'LOGIN'} eq '') {
173 $errormessage = $Lang::tr{'username not set'};
174 }
175
176 # Check if a password has been typed in.
177 # freedns.afraid.org does not require this field.
178 if (($settings{'PASSWORD'} eq '') && ($settings{'SERVICE'} ne 'freedns.afraid.org') && ($settings{'SERVICE'} ne 'regfish.com')) {
179 $errormessage = $Lang::tr{'password not set'};
180 }
181
182 # Go furter if there was no error.
183 if (!$errormessage) {
184 # Splitt hostname field into 2 parts for storrage.
185 my($hostname, $domain) = split(/\./, $settings{'HOSTNAME'}, 2);
186
187 # Handle enabled checkbox. When the checkbox is selected a "on" will be returned,
188 # if the checkbox is not checked nothing is returned in this case we set the value to "off".
189 if ($settings{'ENABLED'} ne 'on') {
190 $settings{'ENABLED'} = 'off';
191 }
192
193 # Handle adding new accounts.
194 if ($settings{'ACTION'} eq $Lang::tr{'add'}) {
195 # Open /var/ipfire/ddns/config for writing.
196 open(FILE, ">>$datafile") or die "Unable to open $datafile.";
197
198 # Lock file for writing.
199 flock FILE, 2;
200
201 # Add account data to the file.
202 print FILE "$settings{'SERVICE'},$hostname,$domain,$settings{'PROXY'},$settings{'WILDCARDS'},$settings{'LOGIN'},$settings{'PASSWORD'},$settings{'ENABLED'}\n";
203
204 # Close file after writing.
205 close(FILE);
206
207 # Write out notice to logfile.
208 &General::log($Lang::tr{'ddns hostname added'});
209
210 # Handle account edditing.
211 } elsif ($settings{'ACTION'} eq $Lang::tr{'update'}) {
212 # Open /var/ipfire/ddns/config for writing.
213 open(FILE, ">$datafile") or die "Unable to open $datafile.";
214
215 # Lock file for writing.
216 flock FILE, 2;
217
218 my $id = 0;
219
220 # Read file line by line.
221 foreach my $line (@current) {
222 if ($settings{'ID'} eq $id) {
223 print FILE "$settings{'SERVICE'},$hostname,$domain,$settings{'PROXY'},$settings{'WILDCARDS'},$settings{'LOGIN'},$settings{'PASSWORD'},$settings{'ENABLED'}\n";
224 } else {
225 print FILE "$line";
226 }
227
228 # Increase $id.
229 $id++;
230 }
231
232 # Close file after writing.
233 close(FILE);
234
235 # Write out notice to logfile.
236 &General::log($Lang::tr{'ddns hostname modified'});
237 }
238 undef $settings{'ID'};
239
240 # Update ddns config file.
241 &GenerateDDNSConfigFile();
242 }
243 }
244
245 #
246 # Remove existing accounts.
247 #
248 if ($settings{'ACTION'} eq $Lang::tr{'remove'}) {
249 # Open /var/ipfire/ddns/config for writing.
250 open(FILE, ">$datafile") or die "Unable to open $datafile.";
251
252 # Lock file for writing.
253 flock FILE, 2;
254
255 my $id = 0;
256
257 # Read file line by line.
258 foreach my $line (@current) {
259 # Write back every line, except the one we want to drop
260 # (identified by the ID)
261 unless ($settings{'ID'} eq $id) {
262 print FILE "$line";
263 }
264
265 # Increase id.
266 $id++;
267 }
268 undef $settings{'ID'};
269
270 # Close file after writing.
271 close(FILE);
272
273 # Write out notice to logfile.
274 &General::log($Lang::tr{'ddns hostname removed'});
275
276 # Update ddns config file.
277 &GenerateDDNSConfigFile();
278 }
279
280 #
281 # Read items for editing.
282 #
283 if ($settings{'ACTION'} eq $Lang::tr{'edit'}) {
284 my $id = 0;
285 my @temp;
286
287 # Read file line by line.
288 foreach my $line (@current) {
289 if ($settings{'ID'} eq $id) {
290 # Remove newlines.
291 chomp($line);
292
293 # Splitt lines (splitting element is a single ",") and save values into temp array.
294 @temp = split(/\,/,$line);
295
296 # Handle hostname details. Only connect the values with a dott if both are available.
297 my $hostname;
298
299 if (($temp[1]) && ($temp[2])) {
300 $hostname = "$temp[1].$temp[2]";
301 } else {
302 $hostname = "$temp[1]";
303 }
304
305 $settings{'SERVICE'} = $temp[0];
306 $settings{'HOSTNAME'} = $hostname;
307 $settings{'PROXY'} = $temp[3];
308 $settings{'WILDCARDS'} = $temp[4];
309 $settings{'LOGIN'} = $temp[5];
310 $settings{'PASSWORD'} = $temp[6];
311 $settings{'ENABLED'} = $temp[7];
312 }
313
314 # Increase $id.
315 $id++;
316 }
317
318 &GenerateDDNSConfigFile();
319 }
320
321 #
322 # Handle forced updates.
323 #
324 if ($settings{'ACTION'} eq $Lang::tr{'instant update'}) {
325 system(@ddnsprog) == 0 or die "@ddnsprog failed: $?\n";
326 }
327
328 #
329 # Set default values.
330 #
331 if (!$settings{'ACTION'}) {
332 $settings{'SERVICE'} = 'dyndns.org';
333 $settings{'ENABLED'} = 'on';
334 $settings{'ID'} = '';
335 }
336
337 &Header::openpage($Lang::tr{'dynamic dns'}, 1, '');
338 &Header::openbigbox('100%', 'left', '', $errormessage);
339
340 # Read file for general ddns settings.
341 &General::readhash($settingsfile, \%settings);
342
343 my %checked =();
344 $checked{'BEHINDROUTER'}{'RED_IP'} = '';
345 $checked{'BEHINDROUTER'}{'FETCH_IP'} = '';
346 $checked{'BEHINDROUTER'}{$settings{'BEHINDROUTER'}} = "checked='checked'";
347
348 $checked{'ENABLED'}{'on'} = '';
349 $checked{'ENABLED'}{'off'} = '';
350 $checked{'ENABLED'}{$settings{'ENABLED'}} = "checked='checked'";
351
352 # Show box for errormessages..
353 if ($errormessage) {
354 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
355 print "<font class='base'>$errormessage&nbsp;</font>";
356 &Header::closebox();
357 }
358
359 &Header::openbox('100%', 'left', $Lang::tr{'settings'});
360
361 ##
362 # Section for general ddns setup.
363 print <<END
364 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
365 <table width='100%'>
366 <tr>
367 <td class='base'>$Lang::tr{'dyn dns source choice'}</td>
368 </tr>
369 <tr>
370 <td class='base'><input type='radio' name='BEHINDROUTER' value='RED_IP' $checked{'BEHINDROUTER'}{'RED_IP'} />
371 $Lang::tr{'use ipfire red ip'}</td>
372 </tr>
373 <tr>
374 <td class='base'><input type='radio' name='BEHINDROUTER' value='FETCH_IP' $checked{'BEHINDROUTER'}{'FETCH_IP'} />
375 $Lang::tr{'fetch ip from'}</td>
376 </tr>
377 </table>
378 <br />
379 <hr />
380
381 <table width='100%'>
382 <tr>
383 <td align='right' valign='top' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
384 </tr>
385 </table>
386 </form>
387 END
388 ;
389
390 &Header::closebox();
391
392 ##
393 # Section to add or edit an existing entry.
394
395 # Default is add.
396 my $buttontext = $Lang::tr{'add'};
397
398 # Change buttontext and headline if we edit an account.
399 if ($settings{'ACTION'} eq $Lang::tr{'edit'}) {
400 # Rename button and print headline for updating.
401 $buttontext = $Lang::tr{'update'};
402 &Header::openbox('100%', 'left', $Lang::tr{'edit an existing host'});
403 } else {
404 # Otherwise use default button text and show headline for adding a new account.
405 &Header::openbox('100%', 'left', $Lang::tr{'add a host'});
406 }
407
408 print <<END
409 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
410 <input type='hidden' name='ID' value='$settings{'ID'}' />
411 <table width='100%'>
412 <tr>
413 <td width='25%' class='base'>$Lang::tr{'service'}:</td>
414 <td width='25%'>
415 END
416 ;
417 # Generate dropdown menu for service selection.
418 print"<select size='1' name='SERVICE'>\n";
419
420 my $selected;
421
422 # Loop to print the providerlist.
423 foreach my $provider (@providers) {
424 # Check if the current provider needs to be selected.
425 if ($provider eq $settings{'SERVICE'}) {
426 $selected = 'selected';
427 } else {
428 $selected = "";
429 }
430
431 # Print out the HTML option field.
432 print "<option value=\"$provider\" $selected>$provider</option>\n";
433 }
434
435 print"</select></td>\n";
436 print <<END
437 <td width='20%' class='base'>$Lang::tr{'hostname'}:</td>
438 <td width='30%'><input type='text' name='HOSTNAME' value='$settings{'HOSTNAME'}' /></td>
439 </tr>
440
441 <tr>
442 <td class='base'>$Lang::tr{'enabled'}</td>
443 <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>
444 <td class='base'>$Lang::tr{'username'}</td>
445 <td><input type='text' name='LOGIN' value='$settings{'LOGIN'}' /></td>
446 </tr>
447
448 <tr>
449 <td class='base'></td>
450 <td></td>
451 <td class='base'>$Lang::tr{'password'}</td>
452 <td><input type='password' name='PASSWORD' value='$settings{'PASSWORD'}' /></td>
453 </tr>
454 </table>
455 <br>
456 <hr>
457
458 <table width='100%'>
459 <tr>
460 <td width='30%' align='right' class='base'>
461 <input type='hidden' name='ACTION' value='$buttontext'>
462 <input type='submit' name='SUBMIT' value='$buttontext'></td>
463 </tr>
464 </table>
465 </form>
466 END
467 ;
468 &Header::closebox();
469
470 ##
471 # Third section, display all created ddns hosts.
472 # Re-open file to get changes.
473 open(FILE, $datafile) or die "Unable to open $datafile.";
474 @current = <FILE>;
475 close(FILE);
476
477 # Get IP address of the red interface.
478 my $ip = &General::GetDyndnsRedIP();
479 my $id = 0;
480 my $toggle_enabled;
481
482 if (@current) {
483 &Header::openbox('100%', 'left', $Lang::tr{'current hosts'});
484
485 print <<END;
486 <table width='100%' class='tbl'>
487 <tr>
488 <th width='30%' align='center' class='boldbase'><b>$Lang::tr{'service'}</b></th>
489 <th width='50%' align='center' class='boldbase'><b>$Lang::tr{'hostname'}</b></th>
490 <th width='20%' colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></th>
491 </tr>
492 END
493
494 foreach my $line (@current) {
495 # Remove newlines.
496 chomp(@current);
497 my @temp = split(/\,/,$line);
498
499 # Handle hostname details. Only connect the values with a dott if both are available.
500 my $hostname="";
501
502 if (($temp[1]) && ($temp[2])) {
503 $hostname="$temp[1].$temp[2]";
504 } else {
505 $hostname="$temp[1]";
506 }
507
508 # Generate value for enable/disable checkbox.
509 my $sync = '';
510 my $gif = '';
511 my $gdesc = '';
512
513 if ($temp[7] eq "on") {
514 $gif = 'on.gif';
515 $gdesc = $Lang::tr{'click to disable'};
516
517 # Check if the given hostname is a FQDN before doing a nslookup.
518 if (&General::validfqdn($hostname)) {
519 $sync = (&General::DyndnsServiceSync ($ip,$temp[1], $temp[2]) ? "<font color='green'>": "<font color='red'>") ;
520 }
521
522 $toggle_enabled = 'off';
523 } else {
524 $sync = "<font color='blue'>";
525 $gif = 'off.gif';
526 $gdesc = $Lang::tr{'click to enable'};
527 $toggle_enabled = 'on';
528 }
529
530 # Background color.
531 my $col="";
532
533 if ($settings{'ID'} eq $id) {
534 $col="bgcolor='${Header::colouryellow}'";
535 } elsif (!($temp[0] ~~ @providers)) {
536 $col="bgcolor='#FF4D4D'";
537 } elsif ($id % 2) {
538 $col="bgcolor='$color{'color20'}'";
539 } else {
540 $col="bgcolor='$color{'color22'}'";
541 }
542
543 # Handle hostname details. Only connect the values with a dott if both are available.
544 my $hostname="";
545
546 if (($temp[1]) && ($temp[2])) {
547 $hostname="$temp[1].$temp[2]";
548 } else {
549 $hostname="$temp[1]";
550 }
551
552 # The following HTML Code still is part of the loop.
553 print <<END;
554 <tr>
555 <td align='center' $col><a href='http://$temp[0]'>$temp[0]</a></td>
556 <td align='center' $col>$sync$hostname</td>
557
558 <td align='center' $col><form method='post' action='$ENV{'SCRIPT_NAME'}'>
559 <input type='hidden' name='ID' value='$id'>
560 <input type='hidden' name='ENABLED' value='$toggle_enabled'>
561 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
562 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
563 </form></td>
564
565 <td align='center' $col><form method='post' action='$ENV{'SCRIPT_NAME'}'>
566 <input type='hidden' name='ID' value='$id'>
567 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
568 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
569 </form></td>
570
571 <td align='center' $col><form method='post' action='$ENV{'SCRIPT_NAME'}'>
572 <input type='hidden' name='ID' value='$id'>
573 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
574 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
575 </form></td>
576 </tr>
577 END
578 $id++;
579 }
580
581 print <<END;
582 </table>
583 <table width='100%'>
584 <tr>
585 <td class='boldbase'>&nbsp;<b>$Lang::tr{'legend'}:&nbsp;</b></td>
586 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
587 <td class='base'>$Lang::tr{'click to disable'}</td>
588 <td>&nbsp;&nbsp;</td>
589 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
590 <td class='base'>$Lang::tr{'click to enable'}</td>
591 <td>&nbsp;&nbsp;</td>
592 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
593 <td class='base'>$Lang::tr{'edit'}</td>
594 <td>&nbsp;&nbsp;</td>
595 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
596 <td class='base'>$Lang::tr{'remove'}</td>
597 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
598 <td align='right' width='30%'><input type='submit' name='ACTION' value='$Lang::tr{'instant update'}' /></td>
599 </form>
600 </tr>
601 </table>
602 END
603
604 &Header::closebox();
605 }
606
607 &Header::closebigbox();
608 &Header::closepage();
609
610 # Function to generate the required configuration file for the DDNS tool.
611 sub GenerateDDNSConfigFile {
612 # Open datafile file
613 open(SETTINGS, "<$datafile") or die "Could not open $datafile.";
614
615 open(FILE, ">${General::swroot}/ddns/ddns.conf");
616
617 # Global configuration options.
618 print FILE "[config]\n";
619
620 # Check if we guess our IP address by an extranal server.
621 if ($settings{'BEHINDROUTER'} eq "FETCH_IP") {
622 print FILE "guess_external_ip = true\n";
623 } else {
624 print FILE "guess_external_ip = false\n";
625 }
626
627 # Use an upstream proxy and generate proxy url.
628 my %proxysettings;
629 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
630 if ($proxysettings{'UPSTREAM_PROXY'}) {
631 my $proxy_string = "http://";
632
633 if ($proxysettings{'UPSTREAM_USER'} && $proxysettings{'UPSTREAM_PASSWORD'}) {
634 $proxy_string .= "$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@";
635 }
636
637 $proxy_string .= $proxysettings{'UPSTREAM_PROXY'};
638
639 print FILE "proxy = $proxy_string\n";
640 }
641
642 print FILE "\n";
643
644 while (<SETTINGS>) {
645 my $line = $_;
646 chomp($line);
647
648 # Generate array based on the line content (seperator is a single or multiple space's)
649 my @settings = split(/,/, $line);
650 my ($provider, $hostname, $domain, $proxy, $wildcards, $username, $password, $enabled) = @settings;
651
652 # Skip entries if they are not (longer) supported.
653 next unless ($provider ~~ @providers);
654
655 # Skip disabled entries.
656 next unless ($enabled eq "on");
657
658 # Handle hostname details. Only connect the values with a dott if both are available.
659 if (($hostname) && ($domain)) {
660 print FILE "[$hostname.$domain]\n";
661 } else {
662 print FILE "[$hostname]\n";
663 }
664
665 print FILE "provider = $provider\n";
666
667 my $use_token = 0;
668
669 # Handle token based auth for various providers.
670 if ($provider ~~ ["dns.lightningwirelabs.com", "entrydns.net", "regfish.com"] && $username eq "token") {
671 $use_token = 1;
672
673 # Handle token auth for freedns.afraid.org and regfish.com.
674 } elsif ($provider ~~ ["freedns.afraid.org", "regfish.com"] && $password eq "") {
675 $use_token = 1;
676 $password = $username;
677
678 # Handle keys for nsupdate
679 } elsif (($provider eq "nsupdate") && $username && $password) {
680 print FILE "key = $username\n";
681 print FILE "secret = $password\n";
682
683 $username = "";
684 $password = "";
685
686 # Handle keys for nsupdate.info
687 } elsif (($provider eq "nsupdate.info") && $password) {
688 print FILE "secret = $password\n";
689
690 $username = "";
691 $password = "";
692 }
693
694 # Write auth details.
695 if ($use_token) {
696 print FILE "token = $password\n";
697 } elsif ($username && $password) {
698 print FILE "username = $username\n";
699 print FILE "password = $password\n";
700 }
701
702 # These providers need to be set to only use IPv4.
703 if ($provider ~~ ["freedns.afraid.org", "nsupdate.info", "opendns.com", "variomedia.de", "zoneedit.com"]) {
704 print FILE "proto = ipv4\n";
705 }
706
707 print FILE "\n";
708 }
709
710 close(SETTINGS);
711 close(FILE);
712 }
713
714 # Function which generates an array (@providers) which contains the supported providers.
715 sub GetProviders {
716 # Get supported providers.
717 open(PROVIDERS, "/usr/bin/ddns list-providers |");
718
719 # Create new array to store the providers.
720 my @providers = ();
721
722 while (<PROVIDERS>) {
723 my $provider = $_;
724
725 # Remove following newlines.
726 chomp($provider);
727
728 # Add provider to the array.
729 push(@providers, $provider);
730 }
731
732 close(PROVIDERS);
733
734 # Return our array.
735 return @providers;
736 }