]>
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 | ||
02391903 SS |
47 | # Call the ddnsctrl helper binary to perform the update. |
48 | my @ddnsprog = ("/usr/local/bin/ddnsctrl", "update-all"); | |
ac1cfefa MT |
49 | |
50 | my %settings=(); | |
1f8fccc5 SS |
51 | my $errormessage = ''; |
52 | ||
53 | # DDNS General settings. | |
ac1cfefa | 54 | $settings{'BEHINDROUTER'} = 'RED_IP'; |
ac1cfefa | 55 | |
1f8fccc5 | 56 | # Account settings. |
ac1cfefa MT |
57 | $settings{'HOSTNAME'} = ''; |
58 | $settings{'DOMAIN'} = ''; | |
59 | $settings{'LOGIN'} = ''; | |
60 | $settings{'PASSWORD'} = ''; | |
ac1cfefa MT |
61 | $settings{'ENABLED'} = ''; |
62 | $settings{'PROXY'} = ''; | |
ac1cfefa MT |
63 | $settings{'SERVICE'} = ''; |
64 | ||
1f8fccc5 | 65 | $settings{'ACTION'} = ''; |
ac1cfefa | 66 | |
e611222f AF |
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 | ||
ac1cfefa MT |
76 | &Header::showhttpheaders(); |
77 | ||
78 | #Get GUI values | |
79 | &Header::getcgihash(\%settings); | |
80 | ||
1f8fccc5 SS |
81 | # Read configuration file. |
82 | open(FILE, "$datafile") or die "Unable to open $datafile."; | |
83 | my @current = <FILE>; | |
84 | close (FILE); | |
85 | ||
ac1cfefa | 86 | # |
1f8fccc5 | 87 | # Save General Settings. |
ac1cfefa MT |
88 | # |
89 | if ($settings{'ACTION'} eq $Lang::tr{'save'}) { | |
1f8fccc5 SS |
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 | ||
1f8fccc5 SS |
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'}) { |
1f8fccc5 SS |
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) { | |
1f8fccc5 SS |
123 | # Remove newlines. |
124 | chomp($line); | |
125 | ||
126 | if ($settings{'ID'} eq $id) { | |
1f8fccc5 SS |
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 '') { | |
1f8fccc5 SS |
132 | # Update ENABLED. |
133 | print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6],$settings{'ENABLED'}\n"; | |
1f8fccc5 SS |
134 | } |
135 | } else { | |
1f8fccc5 SS |
136 | # Print unmodified line. |
137 | print FILE "$line\n"; | |
138 | } | |
139 | ||
140 | # Increase $id. | |
141 | $id++; | |
ac1cfefa | 142 | } |
a6df8026 | 143 | undef $settings{'ID'}; |
1f8fccc5 SS |
144 | |
145 | # Close file after writing. | |
146 | close(FILE); | |
147 | ||
1f8fccc5 SS |
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'})) { | |
1f8fccc5 SS |
159 | # Check if a hostname has been given. |
160 | if ($settings{'HOSTNAME'} eq '') { | |
161 | $errormessage = $Lang::tr{'hostname not set'}; | |
ac1cfefa | 162 | } |
1f8fccc5 SS |
163 | |
164 | # Check if a valid domainname has been provided. | |
165 | if (!&General::validdomainname($settings{'HOSTNAME'})) { | |
166 | $errormessage = $Lang::tr{'invalid domain name'}; | |
ac1cfefa | 167 | } |
ac1cfefa | 168 | |
1f8fccc5 SS |
169 | # Check if a username has been sent. |
170 | if ($settings{'LOGIN'} eq '') { | |
171 | $errormessage = $Lang::tr{'username not set'}; | |
ac1cfefa | 172 | } |
1f8fccc5 SS |
173 | |
174 | # Check if a password has been typed in. | |
175 | # freedns.afraid.org does not require this field. | |
5fe185f8 | 176 | if (($settings{'PASSWORD'} eq '') && ($settings{'SERVICE'} ne 'freedns.afraid.org') && ($settings{'SERVICE'} ne 'regfish.com')) { |
1f8fccc5 | 177 | $errormessage = $Lang::tr{'password not set'}; |
ac1cfefa | 178 | } |
1f8fccc5 SS |
179 | |
180 | # Go furter if there was no error. | |
c330d115 | 181 | if (!$errormessage) { |
1f8fccc5 SS |
182 | # Splitt hostname field into 2 parts for storrage. |
183 | my($hostname, $domain) = split(/\./, $settings{'HOSTNAME'}, 2); | |
184 | ||
c2f80e67 SS |
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 | ||
1f8fccc5 SS |
191 | # Handle adding new accounts. |
192 | if ($settings{'ACTION'} eq $Lang::tr{'add'}) { | |
1f8fccc5 SS |
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 | ||
1f8fccc5 SS |
208 | # Handle account edditing. |
209 | } elsif ($settings{'ACTION'} eq $Lang::tr{'update'}) { | |
1f8fccc5 SS |
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) { | |
1f8fccc5 SS |
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 | } | |
a6df8026 | 236 | undef $settings{'ID'}; |
1f8fccc5 SS |
237 | |
238 | # Update ddns config file. | |
239 | &GenerateDDNSConfigFile(); | |
ac1cfefa | 240 | } |
1f8fccc5 | 241 | } |
ac1cfefa | 242 | |
1f8fccc5 SS |
243 | # |
244 | # Remove existing accounts. | |
245 | # | |
246 | if ($settings{'ACTION'} eq $Lang::tr{'remove'}) { | |
1f8fccc5 SS |
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) { | |
1f8fccc5 SS |
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++; | |
ac1cfefa | 265 | } |
a6df8026 | 266 | undef $settings{'ID'}; |
1f8fccc5 SS |
267 | |
268 | # Close file after writing. | |
269 | close(FILE); | |
270 | ||
1f8fccc5 SS |
271 | # Write out notice to logfile. |
272 | &General::log($Lang::tr{'ddns hostname removed'}); | |
273 | ||
274 | # Update ddns config file. | |
275 | &GenerateDDNSConfigFile(); | |
ac1cfefa MT |
276 | } |
277 | ||
1f8fccc5 SS |
278 | # |
279 | # Read items for editing. | |
280 | # | |
ac1cfefa | 281 | if ($settings{'ACTION'} eq $Lang::tr{'edit'}) { |
1f8fccc5 SS |
282 | my $id = 0; |
283 | my @temp; | |
284 | ||
285 | # Read file line by line. | |
286 | foreach my $line (@current) { | |
1f8fccc5 | 287 | if ($settings{'ID'} eq $id) { |
1f8fccc5 SS |
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 | ||
4851bc81 SS |
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 | ||
1f8fccc5 | 303 | $settings{'SERVICE'} = $temp[0]; |
4851bc81 | 304 | $settings{'HOSTNAME'} = $hostname; |
1f8fccc5 SS |
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 | } | |
1f8fccc5 | 311 | |
c330d115 MT |
312 | # Increase $id. |
313 | $id++; | |
1f8fccc5 | 314 | } |
c330d115 MT |
315 | |
316 | &GenerateDDNSConfigFile(); | |
ac1cfefa MT |
317 | } |
318 | ||
1f8fccc5 SS |
319 | # |
320 | # Handle forced updates. | |
321 | # | |
ac1cfefa | 322 | if ($settings{'ACTION'} eq $Lang::tr{'instant update'}) { |
1f8fccc5 | 323 | system(@ddnsprog) == 0 or die "@ddnsprog failed: $?\n"; |
ac1cfefa MT |
324 | } |
325 | ||
1f8fccc5 SS |
326 | # |
327 | # Set default values. | |
328 | # | |
a6df8026 | 329 | if (!$settings{'ACTION'}) { |
1f8fccc5 SS |
330 | $settings{'SERVICE'} = 'dyndns.org'; |
331 | $settings{'ENABLED'} = 'on'; | |
a6df8026 | 332 | $settings{'ID'} = ''; |
ac1cfefa MT |
333 | } |
334 | ||
335 | &Header::openpage($Lang::tr{'dynamic dns'}, 1, ''); | |
336 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
337 | ||
1f8fccc5 SS |
338 | # Read file for general ddns settings. |
339 | &General::readhash($settingsfile, \%settings); | |
ac1cfefa | 340 | |
1f8fccc5 | 341 | my %checked =(); |
ac1cfefa MT |
342 | $checked{'BEHINDROUTER'}{'RED_IP'} = ''; |
343 | $checked{'BEHINDROUTER'}{'FETCH_IP'} = ''; | |
344 | $checked{'BEHINDROUTER'}{$settings{'BEHINDROUTER'}} = "checked='checked'"; | |
ac1cfefa | 345 | |
c2f80e67 SS |
346 | $checked{'ENABLED'}{'on'} = ''; |
347 | $checked{'ENABLED'}{'off'} = ''; | |
348 | $checked{'ENABLED'}{$settings{'ENABLED'}} = "checked='checked'"; | |
ac1cfefa | 349 | |
1f8fccc5 | 350 | # Show box for errormessages.. |
ac1cfefa MT |
351 | if ($errormessage) { |
352 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
353 | print "<font class='base'>$errormessage </font>"; | |
354 | &Header::closebox(); | |
355 | } | |
356 | ||
ac1cfefa | 357 | &Header::openbox('100%', 'left', $Lang::tr{'settings'}); |
1f8fccc5 SS |
358 | |
359 | ## | |
360 | # Section for general ddns setup. | |
ac1cfefa | 361 | print <<END |
1f8fccc5 | 362 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
ac1cfefa | 363 | <table width='100%'> |
1f8fccc5 SS |
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> | |
ac1cfefa | 375 | </table> |
1f8fccc5 SS |
376 | <br /> |
377 | <hr /> | |
ac1cfefa | 378 | |
ac1cfefa | 379 | <table width='100%'> |
1f8fccc5 SS |
380 | <tr> |
381 | <td align='right' valign='top' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td> | |
382 | </tr> | |
ac1cfefa MT |
383 | </table> |
384 | </form> | |
385 | END | |
386 | ; | |
ac1cfefa | 387 | |
1f8fccc5 SS |
388 | &Header::closebox(); |
389 | ||
390 | ## | |
391 | # Section to add or edit an existing entry. | |
ac1cfefa | 392 | |
1f8fccc5 | 393 | # Default is add. |
ac1cfefa | 394 | my $buttontext = $Lang::tr{'add'}; |
1f8fccc5 SS |
395 | |
396 | # Change buttontext and headline if we edit an account. | |
397 | if ($settings{'ACTION'} eq $Lang::tr{'edit'}) { | |
1f8fccc5 SS |
398 | # Rename button and print headline for updating. |
399 | $buttontext = $Lang::tr{'update'}; | |
400 | &Header::openbox('100%', 'left', $Lang::tr{'edit an existing host'}); | |
ac1cfefa | 401 | } else { |
1f8fccc5 SS |
402 | # Otherwise use default button text and show headline for adding a new account. |
403 | &Header::openbox('100%', 'left', $Lang::tr{'add a host'}); | |
ac1cfefa MT |
404 | } |
405 | ||
ac1cfefa MT |
406 | print <<END |
407 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
1f8fccc5 | 408 | <input type='hidden' name='ID' value='$settings{'ID'}' /> |
ac1cfefa | 409 | <table width='100%'> |
1f8fccc5 SS |
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) { | |
1f8fccc5 SS |
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> | |
c61ac6e8 | 440 | <td class='base'>$Lang::tr{'enabled'}</td> |
c2f80e67 | 441 | <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> |
4576afc5 | 442 | <td class='base'>$Lang::tr{'username'}</td> |
1f8fccc5 SS |
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> | |
ac1cfefa | 452 | </table> |
ec5a7d21 | 453 | <br> |
1f8fccc5 SS |
454 | <hr> |
455 | ||
ac1cfefa MT |
456 | <table width='100%'> |
457 | <tr> | |
ec5a7d21 | 458 | <td width='30%' align='right' class='base'> |
1f8fccc5 SS |
459 | <input type='hidden' name='ACTION' value='$buttontext'> |
460 | <input type='submit' name='SUBMIT' value='$buttontext'></td> | |
ac1cfefa MT |
461 | </tr> |
462 | </table> | |
463 | </form> | |
464 | END | |
465 | ; | |
466 | &Header::closebox(); | |
467 | ||
1f8fccc5 SS |
468 | ## |
469 | # Third section, display all created ddns hosts. | |
9a33b04f MT |
470 | # Re-open file to get changes. |
471 | open(FILE, $datafile) or die "Unable to open $datafile."; | |
472 | @current = <FILE>; | |
473 | close(FILE); | |
1f8fccc5 | 474 | |
9a33b04f MT |
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; | |
09eb51c9 | 484 | <table width='100%' class='tbl'> |
1f8fccc5 | 485 | <tr> |
4188fbf1 SS |
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> | |
1f8fccc5 SS |
488 | <th width='20%' colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></th> |
489 | </tr> | |
ac1cfefa | 490 | END |
1f8fccc5 | 491 | |
9a33b04f MT |
492 | foreach my $line (@current) { |
493 | # Remove newlines. | |
494 | chomp(@current); | |
495 | my @temp = split(/\,/,$line); | |
496 | ||
1f080b34 SS |
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 | ||
9a33b04f | 506 | # Generate value for enable/disable checkbox. |
1f080b34 | 507 | my $sync = ''; |
9a33b04f MT |
508 | my $gif = ''; |
509 | my $gdesc = ''; | |
510 | ||
511 | if ($temp[7] eq "on") { | |
512 | $gif = 'on.gif'; | |
513 | $gdesc = $Lang::tr{'click to disable'}; | |
1f080b34 SS |
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 | ||
9a33b04f MT |
520 | $toggle_enabled = 'off'; |
521 | } else { | |
1f080b34 | 522 | $sync = "<font color='blue'>"; |
9a33b04f MT |
523 | $gif = 'off.gif'; |
524 | $gdesc = $Lang::tr{'click to enable'}; | |
525 | $toggle_enabled = 'on'; | |
526 | } | |
1f8fccc5 | 527 | |
9a33b04f MT |
528 | # Background color. |
529 | my $col=""; | |
ac1cfefa | 530 | |
9a33b04f MT |
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 | } | |
1f8fccc5 | 540 | |
4851bc81 SS |
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 | ||
9a33b04f MT |
550 | # The following HTML Code still is part of the loop. |
551 | print <<END; | |
1f8fccc5 SS |
552 | <tr> |
553 | <td align='center' $col><a href='http://$temp[0]'>$temp[0]</a></td> | |
4851bc81 | 554 | <td align='center' $col>$sync$hostname</td> |
1f8fccc5 | 555 | |
1f8fccc5 SS |
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> | |
ac1cfefa MT |
574 | </tr> |
575 | END | |
9a33b04f MT |
576 | $id++; |
577 | } | |
ac1cfefa | 578 | |
9a33b04f MT |
579 | print <<END; |
580 | </table> | |
ac1cfefa | 581 | <table width='100%'> |
1f8fccc5 SS |
582 | <tr> |
583 | <td class='boldbase'> <b>$Lang::tr{'legend'}: </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> </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> </td> | |
590 | <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
591 | <td class='base'>$Lang::tr{'edit'}</td> | |
592 | <td> </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> | |
ac1cfefa MT |
599 | </table> |
600 | END | |
9a33b04f MT |
601 | |
602 | &Header::closebox(); | |
ac1cfefa MT |
603 | } |
604 | ||
ac1cfefa MT |
605 | &Header::closebigbox(); |
606 | &Header::closepage(); | |
607 | ||
1f8fccc5 SS |
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 = $_; | |
458064c5 | 644 | chomp($line); |
1f8fccc5 SS |
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. | |
06fb88bc | 651 | next unless ($provider ~~ @providers); |
1f8fccc5 SS |
652 | |
653 | # Skip disabled entries. | |
458064c5 | 654 | next unless ($enabled eq "on"); |
1f8fccc5 | 655 | |
4851bc81 SS |
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 | ||
1f8fccc5 SS |
663 | print FILE "provider = $provider\n"; |
664 | ||
665 | my $use_token = 0; | |
666 | ||
667 | # Handle token based auth for various providers. | |
6409aa7e SS |
668 | if ($provider ~~ ["dns.lightningwirelabs.com", "entrydns.net", "regfish.com", |
669 | "spdns.de", "zzzz.io"] && $username eq "token") { | |
1f8fccc5 SS |
670 | $use_token = 1; |
671 | ||
5fe185f8 SS |
672 | # Handle token auth for freedns.afraid.org and regfish.com. |
673 | } elsif ($provider ~~ ["freedns.afraid.org", "regfish.com"] && $password eq "") { | |
1f8fccc5 SS |
674 | $use_token = 1; |
675 | $password = $username; | |
3c781f63 MT |
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 = ""; | |
1f8fccc5 | 684 | |
f5770b46 SS |
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 | ||
1f8fccc5 SS |
693 | # Write auth details. |
694 | if ($use_token) { | |
695 | print FILE "token = $password\n"; | |
3c781f63 | 696 | } elsif ($username && $password) { |
1f8fccc5 SS |
697 | print FILE "username = $username\n"; |
698 | print FILE "password = $password\n"; | |
699 | } | |
700 | ||
1f8fccc5 SS |
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 | } | |
ac1cfefa | 725 | |
1f8fccc5 | 726 | close(PROVIDERS); |
ac1cfefa | 727 | |
1f8fccc5 SS |
728 | # Return our array. |
729 | return @providers; | |
ac1cfefa | 730 | } |