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