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