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