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