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