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