]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/ddns.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2011 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
24 # enable only the following on debugging purpose
26 #use CGI::Carp 'fatalsToBrowser';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
32 #workaround to suppress a warning when a variable is used only once
33 my @dummy = ( ${Header
::table2colour
}, ${Header
::colouryellow
} );
36 my $ddnsprefix = $Lang::tr
{'ddns noip prefix'};
37 $ddnsprefix =~ s/%/$General::noipprefix/;
40 my %mainsettings = ();
41 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
42 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
45 my $setting = "${General::swroot}/ddns/settings";
46 our $datafile = "${General::swroot}/ddns/config";
50 $settings{'BEHINDROUTER'} = 'RED_IP';
51 $settings{'MINIMIZEUPDATES'} = '';
53 #Settings2 for editing the multi-line list
55 $settings{'HOSTNAME'} = '';
56 $settings{'DOMAIN'} = '';
57 $settings{'LOGIN'} = '';
58 $settings{'PASSWORD'} = '';
59 $settings{'PASSWORD2'} = '';
60 $settings{'ENABLED'} = '';
61 $settings{'PROXY'} = '';
62 $settings{'WILDCARDS'} = '';
63 $settings{'SERVICE'} = '';
65 my @nosaved=('HOSTNAME','DOMAIN','LOGIN','PASSWORD','PASSWORD2',
66 'ENABLED','PROXY','WILDCARDS','SERVICE'); # List here ALL setting2 fields. Mandatory
68 $settings{'ACTION'} = ''; # add/edit/remove
69 $settings{'KEY1'} = ''; # point record for ACTION
70 $settings{'KEY2'} = ''; # point record for ACTION
72 my $errormessage = '';
75 &Header
::showhttpheaders
();
78 &Header
::getcgihash
(\
%settings);
82 if (open(FILE
, "$datafile")) {
88 # Check Settings1 first because they are needed before working on @current
90 if ($settings{'ACTION'} eq $Lang::tr
{'save'}) {
91 # No user input to check. !
92 #unless ($errormessage) { # Everything is ok, save settings
93 $settings{'BEHINDROUTERWAITLOOP'} = '-1'; # init & will update on next setddns.pl call
94 map (delete ($settings{$_}) ,(@nosaved,'ACTION','KEY1','KEY2'));# Must never be saved
95 &General
::writehash
($setting, \
%settings); # Save good settings
96 $settings{'ACTION'} = $Lang::tr
{'save'}; # Recreate 'ACTION'
97 map ($settings{$_}= '',(@nosaved,'KEY1','KEY2')); # and reinit var to empty
100 &General
::readhash
($setting, \
%settings); # Get saved settings and reset to good if needed
104 # Now manipulate the multi-line list with Settings2
106 # Toggle enable/disable field. Field is in second position
107 if ($settings{'ACTION'} eq $Lang::tr
{'toggle enable disable'}) {
109 chomp(@current[$settings{'KEY1'}]);
110 my @temp = split(/\,/,@current[$settings{'KEY1'}]);
111 my $K2=$settings{'KEY2'};
112 $temp[ $K2 ] = ( $temp[ $K2 ] eq 'on') ?
'' : 'on'; # Toggle the field
113 @current[$settings{'KEY1'}] = join (',',@temp)."\n";
114 $settings{'KEY1'} = ''; # End edit mode
115 &General
::log($Lang::tr
{'ddns hostname modified'});
117 # Write changes to config file.
118 &WriteDataFile
; # sort newly added/modified entry
121 if ($settings{'ACTION'} eq $Lang::tr
{'add'}) {
124 unless ($settings{'LOGIN'} ne '') {
125 $errormessage = $Lang::tr
{'username not set'};
128 # list box returns 'service optional synonyms'
129 # keep only first name
130 $settings{'SERVICE'} =~ s/ .*$//;
132 # for freedns.afraid.org, only 'connect string' is mandatory
133 if ($settings{'SERVICE'} ne 'freedns.afraid.org') {
134 unless ($settings{'SERVICE'} eq 'regfish.com' || $settings{'PASSWORD'} ne '') {
135 $errormessage = $Lang::tr
{'password not set'};
137 unless ($settings{'PASSWORD'} eq $settings{'PASSWORD2'}) {
138 $errormessage = $Lang::tr
{'passwords do not match'};
141 # Permit an empty HOSTNAME for the nsupdate, regfish, dyndns, enom, ovh, zoneedit, no-ip, easydns
143 unless ($settings{'SERVICE'} eq 'zoneedit.com' || $settings{'SERVICE'} eq 'nsupdate' ||
144 $settings{'SERVICE'} eq 'dyndns-custom'|| $settings{'SERVICE'} eq 'regfish.com' ||
145 $settings{'SERVICE'} eq 'enom.com' || $settings{'SERVICE'} eq 'dnspark.com' ||
146 $settings{'SERVICE'} eq 'ovh.com' || $settings{'HOSTNAME'} ne '' ||
147 $settings{'SERVICE'} eq 'no-ip.com' || $settings{'SERVICE'} eq 'easydns.com' ||
148 $settings{'SERVICE'} eq 'namecheap.com' ) {
149 $errormessage = $Lang::tr
{'hostname not set'};
151 unless ($settings{'HOSTNAME'} eq '' || $settings{'HOSTNAME'} =~ /^[a-zA-Z_0-9-]+$/) {
152 $errormessage = $Lang::tr
{'invalid hostname'};
154 unless ($settings{'DOMAIN'} ne '') {
155 $errormessage = $Lang::tr
{'domain not set'};
157 unless ($settings{'DOMAIN'} =~ /^[a-zA-Z_0-9.-]+$/) {
158 $errormessage = $Lang::tr
{'invalid domain name'};
160 unless ($settings{'DOMAIN'} =~ /[.]/) {
161 $errormessage = $Lang::tr
{'invalid domain name'};
165 # recheck service wich don't need too much fields
166 if ($settings{'SERVICE'} eq 'cjb.net') {
167 $errormessage = ''; # clear previous error
168 unless ($settings{'LOGIN'} ne '') {
169 $errormessage = $Lang::tr
{'username not set'};
171 unless ($settings{'PASSWORD'} ne '') {
172 $errormessage = $Lang::tr
{'password not set'};
174 unless ($settings{'PASSWORD'} eq $settings{'PASSWORD2'}) {
175 $errormessage = $Lang::tr
{'passwords do not match'};
179 unless ($errormessage) {
180 if ($settings{'KEY1'} eq '') { #add or edit ?
181 unshift (@current, "$settings{'SERVICE'},$settings{'HOSTNAME'},$settings{'DOMAIN'},$settings{'PROXY'},$settings{'WILDCARDS'},$settings{'LOGIN'},$settings{'PASSWORD'},$settings{'ENABLED'}\n");
182 &General
::log($Lang::tr
{'ddns hostname added'});
184 @current[$settings{'KEY1'}] = "$settings{'SERVICE'},$settings{'HOSTNAME'},$settings{'DOMAIN'},$settings{'PROXY'},$settings{'WILDCARDS'},$settings{'LOGIN'},$settings{'PASSWORD'},$settings{'ENABLED'}\n";
185 $settings{'KEY1'} = ''; # End edit mode
186 &General
::log($Lang::tr
{'ddns hostname modified'});
188 map ($settings{$_}='' ,@nosaved); # Clear fields
189 # Write changes to config file.
190 &WriteDataFile
; # sort newly added/modified entry
194 if ($settings{'ACTION'} eq $Lang::tr
{'edit'}) {
196 my $line = @current[$settings{'KEY1'}]; # KEY1 is the index in current
198 my @temp = split(/\,/, $line);
199 $settings{'SERVICE'} = $temp[0];
200 $settings{'HOSTNAME'} = $temp[1];
201 $settings{'DOMAIN'} = $temp[2];
202 $settings{'PROXY'} = $temp[3];
203 $settings{'WILDCARDS'} = $temp[4];
204 $settings{'LOGIN'} = $temp[5];
205 $settings{'PASSWORD'} = $settings{'PASSWORD2'} = $temp[6];
206 $settings{'ENABLED'} = $temp[7];
209 if ($settings{'ACTION'} eq $Lang::tr
{'remove'}) {
210 splice (@current,$settings{'KEY1'},1); # Delete line
211 open(FILE
, ">$datafile") or die 'ddns datafile error';
214 $settings{'KEY1'} = ''; # End remove mode
215 &General
::log($Lang::tr
{'ddns hostname removed'});
216 # Write changes to config file.
220 if ($settings{'ACTION'} eq $Lang::tr
{'instant update'}) {
221 system('/usr/local/bin/setddns.pl', '-f');
225 if ($settings{'ACTION'} eq '')
227 $settings{'SERVICE'} = 'dyndns.org';
228 $settings{'ENABLED'} = 'on';
231 &Header
::openpage
($Lang::tr
{'dynamic dns'}, 1, '');
232 &Header
::openbigbox
('100%', 'left', '', $errormessage);
234 my %checked =(); # Checkbox manipulations
235 $checked{'SERVICE'}{'all-inkl.com'} = '';
236 $checked{'SERVICE'}{'cjb.net'} = '';
237 $checked{'SERVICE'}{'dhs.org'} = '';
238 $checked{'SERVICE'}{'dnspark.com'} = '';
239 $checked{'SERVICE'}{'dns.lightningwirelabs.com'} = '';
240 $checked{'SERVICE'}{'dtdns.com'} = '';
241 $checked{'SERVICE'}{'dyndns.org'} = '';
242 $checked{'SERVICE'}{'dyndns-custom'} = '';
243 $checked{'SERVICE'}{'dyndns-static'} = '';
244 $checked{'SERVICE'}{'dyns.cx'} = '';
245 $checked{'SERVICE'}{'dynu.ca'} = '';
246 $checked{'SERVICE'}{'easydns.com'} = '';
247 $checked{'SERVICE'}{'enom.com'} = '';
248 $checked{'SERVICE'}{'freedns.afraid.org'} = '';
249 $checked{'SERVICE'}{'hn.org'} = '';
250 $checked{'SERVICE'}{'namecheap.com'} = '';
251 $checked{'SERVICE'}{'no-ip.com'} = '';
252 $checked{'SERVICE'}{'nsupdate'} = '';
253 $checked{'SERVICE'}{'ovh.com'} = '';
254 $checked{'SERVICE'}{'regfish.com'} = '';
255 $checked{'SERVICE'}{'selfhost.de'} = '';
256 $checked{'SERVICE'}{'strato.com'} = '';
257 $checked{'SERVICE'}{'tzo.com'} = '';
258 $checked{'SERVICE'}{'zoneedit.com'} = '';
259 $checked{'SERVICE'}{$settings{'SERVICE'}} = "selected='selected'";
261 $checked{'BEHINDROUTER'}{'RED_IP'} = '';
262 $checked{'BEHINDROUTER'}{'FETCH_IP'} = '';
263 $checked{'BEHINDROUTER'}{$settings{'BEHINDROUTER'}} = "checked='checked'";
264 $checked{'MINIMIZEUPDATES'} = ($settings{'MINIMIZEUPDATES'} eq '' ) ?
'' : "checked='checked'";
266 $checked{'PROXY'}{'on'} = ($settings{'PROXY'} eq '') ?
'' : "checked='checked'";
267 $checked{'WILDCARDS'}{'on'} = ($settings{'WILDCARDS'} eq '') ?
'' : "checked='checked'";
268 $checked{'ENABLED'}{'on'} = ($settings{'ENABLED'} eq '' ) ?
'' : "checked='checked'";
271 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
272 print "<font class='base'>$errormessage </font>";
277 $warnmessage = "<font color=${Header::colourred}><b>$Lang::tr{'capswarning'}</b></font>: $warnmessage";
279 &Header
::openbox
('100%', 'left', $Lang::tr
{'settings'});
280 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>";
284 <td class='base'>$Lang::tr{'dyn dns source choice'}</td>
286 <td class='base'><input type='radio' name='BEHINDROUTER' value='RED_IP' $checked{'BEHINDROUTER'}{'RED_IP'} />
287 $Lang::tr{'use ipfire red ip'}</td>
289 <td class='base'><input type='radio' name='BEHINDROUTER' value='FETCH_IP' $checked{'BEHINDROUTER'}{'FETCH_IP'} />
290 $Lang::tr{'fetch ip from'} <img src='/blob.gif' alt='*' /></td>
293 <td class='base'><input type='checkbox' name='MINIMIZEUPDATES' $checked{'MINIMIZEUPDATES'} />
294 $Lang::tr{'ddns minimize updates'}</td>
304 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
305 <td width='70%' class='base'>$Lang::tr{'avoid dod'}</td>
306 <td width='30%' align='center' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
312 &Header
::closebox
(); # end of Settings1
315 my $buttontext = $Lang::tr
{'add'};
316 if ($settings{'KEY1'} ne '') {
317 $buttontext = $Lang::tr
{'update'};
318 &Header
::openbox
('100%', 'left', $Lang::tr
{'edit an existing host'});
320 &Header
::openbox
('100%', 'left', $Lang::tr
{'add a host'});
323 #Edited line number (KEY1) passed until cleared by 'save' or 'remove'
325 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
326 <input type='hidden' name='KEY1' value='$settings{'KEY1'}' />
329 <td width='25%' class='base'>$Lang::tr{'service'}:</td>
330 <td width='25%'><select size='1' name='SERVICE'>
331 <option $checked{'SERVICE'}{'all-inkl.com'}>all-inkl.com</option>
332 <option $checked{'SERVICE'}{'cjb.net'}>cjb.net</option>
333 <option $checked{'SERVICE'}{'dhs.org'}>dhs.org</option>
334 <option $checked{'SERVICE'}{'dnspark.com'}>dnspark.com</option>
335 <option $checked{'SERVICE'}{'dns.lightningwirelabs.com'}>dns.lightningwirelabs.com</option>
336 <option $checked{'SERVICE'}{'dtdns.com'}>dtdns.com</option>
337 <option $checked{'SERVICE'}{'dyndns.org'}>dyndns.org</option>
338 <option $checked{'SERVICE'}{'dyndns-custom'}>dyndns-custom</option>
339 <option $checked{'SERVICE'}{'dyndns-static'}>dyndns-static</option>
340 <option $checked{'SERVICE'}{'dyns.cx'}>dyns.cx</option>
341 <option $checked{'SERVICE'}{'dynu.ca'}>dynu.ca dyn.ee dynserv.(ca|org|net|com)</option>
342 <option $checked{'SERVICE'}{'easydns.com'}>easydns.com</option>
343 <option $checked{'SERVICE'}{'enom.com'}>enom.com</option>
344 <option $checked{'SERVICE'}{'freedns.afraid.org'}>freedns.afraid.org</option>
345 <option $checked{'SERVICE'}{'hn.org'}>hn.org</option>
346 <option $checked{'SERVICE'}{'namecheap.com'}>namecheap.com</option>
347 <option $checked{'SERVICE'}{'no-ip.com'}>no-ip.com</option>
348 <option $checked{'SERVICE'}{'nsupdate'}>nsupdate</option>
349 <option $checked{'SERVICE'}{'ovh.com'}>ovh.com</option>
350 <option $checked{'SERVICE'}{'regfish.com'}>regfish.com</option>
351 <option $checked{'SERVICE'}{'selfhost.de'}>selfhost.de</option>
352 <option $checked{'SERVICE'}{'strato.com'}>strato.com</option>
353 <!-- <option $checked{'SERVICE'}{'tzo.com'}>tzo.com</option> comment this service out until a working fix is developed -->
354 <option $checked{'SERVICE'}{'zoneedit.com'}>zoneedit.com</option>
356 <td width='20%' class='base'>$Lang::tr{'hostname'}: <img src='/blob.gif' alt='*' /></td>
357 <td width='30%'><input type='text' name='HOSTNAME' value='$settings{'HOSTNAME'}' /></td>
359 <td class='base'>$Lang::tr{'behind a proxy'}</td>
360 <td><input type='checkbox' name='PROXY' value='on' $checked{'PROXY'}{'on'} /></td>
361 <td class='base'>$Lang::tr{'domain'}:</td>
362 <td><input type='text' name='DOMAIN' value='$settings{'DOMAIN'}' /></td>
364 <td class='base'>$Lang::tr{'enable wildcards'}</td>
365 <td><input type='checkbox' name='WILDCARDS' value='on' $checked{'WILDCARDS'}{'on'} /></td>
366 <td class='base'>$Lang::tr{'username'}</td>
367 <td><input type='text' name='LOGIN' value='$settings{'LOGIN'}' /></td>
371 <td class='base'>$Lang::tr{'password'}</td>
372 <td><input type='password' name='PASSWORD' value='$settings{'PASSWORD'}' /></td>
374 <td class='base'>$Lang::tr{'enabled'}</td>
375 <td><input type='checkbox' name='ENABLED' value='on' $checked{'ENABLED'}{'on'} /></td>
376 <td class='base'>$Lang::tr{'again'}</td>
377 <td><input type='password' name='PASSWORD2' value='$settings{'PASSWORD2'}' /></td>
383 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
384 <td width='70%' class='base'>$ddnsprefix</td>
386 <td width='30%' align='center' class='base'>
387 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}' />
388 <input type='submit' name='SUBMIT' value='$buttontext' /> </td>
397 # Third box shows the list, in columns
399 &Header
::openbox
('100%', 'left', $Lang::tr
{'current hosts'});
403 <td width='15%' align='center' class='boldbase'><b>$Lang::tr{'service'}</b></td>
404 <td width='25%' align='center' class='boldbase'><b>$Lang::tr{'hostname'}</b></td>
405 <td width='30%' align='center' class='boldbase'><b>$Lang::tr{'domain'}</b></td>
406 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'proxy'}</b></td>
407 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'wildcards'}</b></td>
408 <td width='10%' colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></td>
412 my $ip = &General
::GetDyndnsRedIP
;
414 foreach my $line (@current) {
415 chomp($line); # remove newline
416 my @temp = split(/\,/,$line);
418 if ($temp[0] eq 'no-ip.com') {
419 $temp[1] =~ s!$General::noipprefix(.*)!<b>group:</b>$1 !;
422 #Choose icon for checkbox
426 if ($temp[3] eq "on") {
427 $gifproxy = 'on.gif';
428 $descproxy = $Lang::tr
{'click to disable'};
430 $gifproxy = 'off.gif';
431 $descproxy = $Lang::tr
{'click to enable'};
436 if ($temp[4] eq "on") {
437 $gifwildcard = 'on.gif';
438 $descwildcard = $Lang::tr
{'click to disable'};
440 $gifwildcard = 'off.gif';
441 $descwildcard = $Lang::tr
{'click to enable'};
444 my $sync = "<font color='blue'>";
447 if ($temp[7] eq "on") {
449 $gdesc = $Lang::tr
{'click to disable'};
450 $sync = (&General
::DyndnsServiceSync
($ip,$temp[1], $temp[2]) ?
"<font color='green'>": "<font color='red'>") ;
453 $gdesc = $Lang::tr
{'click to enable'};
457 if ($settings{'KEY1'} eq $key) {
458 print "<tr bgcolor='${Header::colouryellow}'>";
460 print "<tr bgcolor='$color{'color22'}'>";
462 print "<tr bgcolor='$color{'color20'}'>";
465 #if a field is empty, replace it with a '---' to see colorized info!
466 $temp[1] = '---' if (!$temp[1]);
467 $temp[2] = '---' if (!$temp[2]);
470 <td align='center'><a href='http://$temp[0]'>$temp[0]</a></td>
471 <td align='center'>$sync$temp[1]</td>
472 <td align='center'>$sync$temp[2]</td>
475 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
476 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
477 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gifproxy' alt='$descproxy' title='$descproxy' />
478 <input type='hidden' name='KEY1' value='$key' />
479 <input type='hidden' name='KEY2' value='3' />
484 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
485 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
486 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gifwildcard' alt='$descwildcard' title='$descwildcard' />
487 <input type='hidden' name='KEY1' value='$key' />
488 <input type='hidden' name='KEY2' value='4' />
493 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
494 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
495 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
496 <input type='hidden' name='KEY1' value='$key' />
497 <input type='hidden' name='KEY2' value='7' />
502 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
503 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
504 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
505 <input type='hidden' name='KEY1' value='$key' />
510 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
511 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
512 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
513 <input type='hidden' name='KEY1' value='$key' />
523 # If table contains entries, print 'Key to action icons'
528 <td class='boldbase'> <b>$Lang::tr{'legend'}: </b></td>
529 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
530 <td class='base'>$Lang::tr{'click to disable'}</td>
531 <td> </td>
532 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
533 <td class='base'>$Lang::tr{'click to enable'}</td>
534 <td> </td>
535 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
536 <td class='base'>$Lang::tr{'edit'}</td>
537 <td> </td>
538 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
539 <td class='base'>$Lang::tr{'remove'}</td>
540 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
541 <td align='center' width='30%'><input type='submit' name='ACTION' value='$Lang::tr{'instant update'}' /></td>
550 &Header
::closebigbox
();
551 &Header
::closepage
();
553 ## Ouf it's the end !
556 # write the "current" array
559 open(FILE
, ">$datafile") or die 'ddns datafile error';