]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/ddns.cgi
2912b44217ffb1dde52a9cd3ec1ea9737e92f218
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 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
142 unless ($settings{'SERVICE'} eq 'zoneedit.com' || $settings{'SERVICE'} eq 'nsupdate' ||
143 $settings{'SERVICE'} eq 'dyndns-custom'|| $settings{'SERVICE'} eq 'regfish.com' ||
144 $settings{'SERVICE'} eq 'enom.com' || $settings{'SERVICE'} eq 'dnspark.com' ||
145 $settings{'SERVICE'} eq 'ovh.com' || $settings{'HOSTNAME'} ne '' ||
146 $settings{'SERVICE'} eq 'no-ip.com' || $settings{'SERVICE'} eq 'easydns.com' ) {
147 $errormessage = $Lang::tr
{'hostname not set'};
149 unless ($settings{'HOSTNAME'} eq '' || $settings{'HOSTNAME'} =~ /^[a-zA-Z_0-9-]+$/) {
150 $errormessage = $Lang::tr
{'invalid hostname'};
152 unless ($settings{'DOMAIN'} ne '') {
153 $errormessage = $Lang::tr
{'domain not set'};
155 unless ($settings{'DOMAIN'} =~ /^[a-zA-Z_0-9.-]+$/) {
156 $errormessage = $Lang::tr
{'invalid domain name'};
158 unless ($settings{'DOMAIN'} =~ /[.]/) {
159 $errormessage = $Lang::tr
{'invalid domain name'};
163 # recheck service wich don't need too much fields
164 if ($settings{'SERVICE'} eq 'cjb.net') {
165 $errormessage = ''; # clear previous error
166 unless ($settings{'LOGIN'} ne '') {
167 $errormessage = $Lang::tr
{'username not set'};
169 unless ($settings{'PASSWORD'} ne '') {
170 $errormessage = $Lang::tr
{'password not set'};
172 unless ($settings{'PASSWORD'} eq $settings{'PASSWORD2'}) {
173 $errormessage = $Lang::tr
{'passwords do not match'};
177 unless ($errormessage) {
178 if ($settings{'KEY1'} eq '') { #add or edit ?
179 unshift (@current, "$settings{'SERVICE'},$settings{'HOSTNAME'},$settings{'DOMAIN'},$settings{'PROXY'},$settings{'WILDCARDS'},$settings{'LOGIN'},$settings{'PASSWORD'},$settings{'ENABLED'}\n");
180 &General
::log($Lang::tr
{'ddns hostname added'});
182 @current[$settings{'KEY1'}] = "$settings{'SERVICE'},$settings{'HOSTNAME'},$settings{'DOMAIN'},$settings{'PROXY'},$settings{'WILDCARDS'},$settings{'LOGIN'},$settings{'PASSWORD'},$settings{'ENABLED'}\n";
183 $settings{'KEY1'} = ''; # End edit mode
184 &General
::log($Lang::tr
{'ddns hostname modified'});
186 map ($settings{$_}='' ,@nosaved); # Clear fields
187 # Write changes to config file.
188 &WriteDataFile
; # sort newly added/modified entry
192 if ($settings{'ACTION'} eq $Lang::tr
{'edit'}) {
194 my $line = @current[$settings{'KEY1'}]; # KEY1 is the index in current
196 my @temp = split(/\,/, $line);
197 $settings{'SERVICE'} = $temp[0];
198 $settings{'HOSTNAME'} = $temp[1];
199 $settings{'DOMAIN'} = $temp[2];
200 $settings{'PROXY'} = $temp[3];
201 $settings{'WILDCARDS'} = $temp[4];
202 $settings{'LOGIN'} = $temp[5];
203 $settings{'PASSWORD'} = $settings{'PASSWORD2'} = $temp[6];
204 $settings{'ENABLED'} = $temp[7];
207 if ($settings{'ACTION'} eq $Lang::tr
{'remove'}) {
208 splice (@current,$settings{'KEY1'},1); # Delete line
209 open(FILE
, ">$datafile") or die 'ddns datafile error';
212 $settings{'KEY1'} = ''; # End remove mode
213 &General
::log($Lang::tr
{'ddns hostname removed'});
214 # Write changes to config file.
218 if ($settings{'ACTION'} eq $Lang::tr
{'instant update'}) {
219 system('/usr/local/bin/setddns.pl', '-f');
223 if ($settings{'ACTION'} eq '')
225 $settings{'SERVICE'} = 'dyndns.org';
226 $settings{'ENABLED'} = 'on';
229 &Header
::openpage
($Lang::tr
{'dynamic dns'}, 1, '');
230 &Header
::openbigbox
('100%', 'left', '', $errormessage);
232 my %checked =(); # Checkbox manipulations
233 $checked{'SERVICE'}{'cjb.net'} = '';
234 $checked{'SERVICE'}{'dhs.org'} = '';
235 $checked{'SERVICE'}{'dnspark.com'} = '';
236 $checked{'SERVICE'}{'dtdns.com'} = '';
237 $checked{'SERVICE'}{'dyndns.org'} = '';
238 $checked{'SERVICE'}{'dyndns-custom'} = '';
239 $checked{'SERVICE'}{'dyndns-static'} = '';
240 $checked{'SERVICE'}{'dyns.cx'} = '';
241 $checked{'SERVICE'}{'dynu.ca'} = '';
242 $checked{'SERVICE'}{'easydns.com'} = '';
243 $checked{'SERVICE'}{'enom.com'} = '';
244 $checked{'SERVICE'}{'freedns.afraid.org'} = '';
245 $checked{'SERVICE'}{'hn.org'} = '';
246 $checked{'SERVICE'}{'mydyn.de'} = '';
247 $checked{'SERVICE'}{'no-ip.com'} = '';
248 $checked{'SERVICE'}{'nsupdate'} = '';
249 $checked{'SERVICE'}{'ovh.com'} = '';
250 $checked{'SERVICE'}{'regfish.com'} = '';
251 $checked{'SERVICE'}{'selfhost.de'} = '';
252 $checked{'SERVICE'}{'strato.com'} = '';
253 $checked{'SERVICE'}{'tzo.com'} = '';
254 $checked{'SERVICE'}{'zoneedit.com'} = '';
255 $checked{'SERVICE'}{$settings{'SERVICE'}} = "selected='selected'";
257 $checked{'BEHINDROUTER'}{'RED_IP'} = '';
258 $checked{'BEHINDROUTER'}{'FETCH_IP'} = '';
259 $checked{'BEHINDROUTER'}{$settings{'BEHINDROUTER'}} = "checked='checked'";
260 $checked{'MINIMIZEUPDATES'} = ($settings{'MINIMIZEUPDATES'} eq '' ) ?
'' : "checked='checked'";
262 $checked{'PROXY'}{'on'} = ($settings{'PROXY'} eq '') ?
'' : "checked='checked'";
263 $checked{'WILDCARDS'}{'on'} = ($settings{'WILDCARDS'} eq '') ?
'' : "checked='checked'";
264 $checked{'ENABLED'}{'on'} = ($settings{'ENABLED'} eq '' ) ?
'' : "checked='checked'";
267 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
268 print "<font class='base'>$errormessage </font>";
273 $warnmessage = "<font color=${Header::colourred}><b>$Lang::tr{'capswarning'}</b></font>: $warnmessage";
275 &Header
::openbox
('100%', 'left', $Lang::tr
{'settings'});
276 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>";
280 <td class='base'>$Lang::tr{'dyn dns source choice'}</td>
282 <td class='base'><input type='radio' name='BEHINDROUTER' value='RED_IP' $checked{'BEHINDROUTER'}{'RED_IP'} />
283 $Lang::tr{'use ipfire red ip'}</td>
285 <td class='base'><input type='radio' name='BEHINDROUTER' value='FETCH_IP' $checked{'BEHINDROUTER'}{'FETCH_IP'} />
286 $Lang::tr{'fetch ip from'} <img src='/blob.gif' alt='*' /></td>
289 <td class='base'><input type='checkbox' name='MINIMIZEUPDATES' $checked{'MINIMIZEUPDATES'} />
290 $Lang::tr{'ddns minimize updates'}</td>
300 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
301 <td width='70%' class='base'>$Lang::tr{'avoid dod'}</td>
302 <td width='30%' align='center' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
308 &Header
::closebox
(); # end of Settings1
311 my $buttontext = $Lang::tr
{'add'};
312 if ($settings{'KEY1'} ne '') {
313 $buttontext = $Lang::tr
{'update'};
314 &Header
::openbox
('100%', 'left', $Lang::tr
{'edit an existing host'});
316 &Header
::openbox
('100%', 'left', $Lang::tr
{'add a host'});
319 #Edited line number (KEY1) passed until cleared by 'save' or 'remove'
321 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
322 <input type='hidden' name='KEY1' value='$settings{'KEY1'}' />
325 <td width='25%' class='base'>$Lang::tr{'service'}:</td>
326 <td width='25%'><select size='1' name='SERVICE'>
327 <option $checked{'SERVICE'}{'cjb.net'}>cjb.net</option>
328 <option $checked{'SERVICE'}{'dhs.org'}>dhs.org</option>
329 <option $checked{'SERVICE'}{'dnspark.com'}>dnspark.com</option>
330 <option $checked{'SERVICE'}{'dtdns.com'}>dtdns.com</option>
331 <option $checked{'SERVICE'}{'dyndns.org'}>dyndns.org</option>
332 <option $checked{'SERVICE'}{'dyndns-custom'}>dyndns-custom</option>
333 <option $checked{'SERVICE'}{'dyndns-static'}>dyndns-static</option>
334 <option $checked{'SERVICE'}{'dyns.cx'}>dyns.cx</option>
335 <option $checked{'SERVICE'}{'dynu.ca'}>dynu.ca dyn.ee dynserv.(ca|org|net|com)</option>
336 <option $checked{'SERVICE'}{'easydns.com'}>easydns.com</option>
337 <option $checked{'SERVICE'}{'enom.com'}>enom.com</option>
338 <option $checked{'SERVICE'}{'freedns.afraid.org'}>freedns.afraid.org</option>
339 <option $checked{'SERVICE'}{'hn.org'}>hn.org</option>
340 <option $checked{'SERVICE'}{'mydyn.de'}>mydyn.de</option>
341 <option $checked{'SERVICE'}{'no-ip.com'}>no-ip.com</option>
342 <option $checked{'SERVICE'}{'nsupdate'}>nsupdate</option>
343 <option $checked{'SERVICE'}{'ovh.com'}>ovh.com</option>
344 <option $checked{'SERVICE'}{'regfish.com'}>regfish.com</option>
345 <option $checked{'SERVICE'}{'selfhost.de'}>selfhost.de</option>
346 <option $checked{'SERVICE'}{'strato.com'}>strato.com</option>
347 <!-- <option $checked{'SERVICE'}{'tzo.com'}>tzo.com</option> comment this service out until a working fix is developed -->
348 <option $checked{'SERVICE'}{'zoneedit.com'}>zoneedit.com</option>
350 <td width='20%' class='base'>$Lang::tr{'hostname'}: <img src='/blob.gif' alt='*' /></td>
351 <td width='30%'><input type='text' name='HOSTNAME' value='$settings{'HOSTNAME'}' /></td>
353 <td class='base'>$Lang::tr{'behind a proxy'}</td>
354 <td><input type='checkbox' name='PROXY' value='on' $checked{'PROXY'}{'on'} /></td>
355 <td class='base'>$Lang::tr{'domain'}:</td>
356 <td><input type='text' name='DOMAIN' value='$settings{'DOMAIN'}' /></td>
358 <td class='base'>$Lang::tr{'enable wildcards'}</td>
359 <td><input type='checkbox' name='WILDCARDS' value='on' $checked{'WILDCARDS'}{'on'} /></td>
360 <td class='base'>$Lang::tr{'username'}</td>
361 <td><input type='text' name='LOGIN' value='$settings{'LOGIN'}' /></td>
365 <td class='base'>$Lang::tr{'password'}</td>
366 <td><input type='password' name='PASSWORD' value='$settings{'PASSWORD'}' /></td>
368 <td class='base'>$Lang::tr{'enabled'}</td>
369 <td><input type='checkbox' name='ENABLED' value='on' $checked{'ENABLED'}{'on'} /></td>
370 <td class='base'>$Lang::tr{'again'}</td>
371 <td><input type='password' name='PASSWORD2' value='$settings{'PASSWORD2'}' /></td>
377 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
378 <td width='70%' class='base'>$ddnsprefix</td>
380 <td width='30%' align='center' class='base'>
381 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}' />
382 <input type='submit' name='SUBMIT' value='$buttontext' /> </td>
391 # Third box shows the list, in columns
393 &Header
::openbox
('100%', 'left', $Lang::tr
{'current hosts'});
397 <td width='15%' align='center' class='boldbase'><b>$Lang::tr{'service'}</b></td>
398 <td width='25%' align='center' class='boldbase'><b>$Lang::tr{'hostname'}</b></td>
399 <td width='30%' align='center' class='boldbase'><b>$Lang::tr{'domain'}</b></td>
400 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'proxy'}</b></td>
401 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'wildcards'}</b></td>
402 <td width='10%' colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></td>
406 my $ip = &General
::GetDyndnsRedIP
;
408 foreach my $line (@current) {
409 chomp($line); # remove newline
410 my @temp = split(/\,/,$line);
412 if ($temp[0] eq 'no-ip.com') {
413 $temp[1] =~ s!$General::noipprefix(.*)!<b>group:</b>$1 !;
416 #Choose icon for checkbox
420 if ($temp[3] eq "on") {
421 $gifproxy = 'on.gif';
422 $descproxy = $Lang::tr
{'click to disable'};
424 $gifproxy = 'off.gif';
425 $descproxy = $Lang::tr
{'click to enable'};
430 if ($temp[4] eq "on") {
431 $gifwildcard = 'on.gif';
432 $descwildcard = $Lang::tr
{'click to disable'};
434 $gifwildcard = 'off.gif';
435 $descwildcard = $Lang::tr
{'click to enable'};
438 my $sync = "<font color='blue'>";
441 if ($temp[7] eq "on") {
443 $gdesc = $Lang::tr
{'click to disable'};
444 $sync = (&General
::DyndnsServiceSync
($ip,$temp[1], $temp[2]) ?
"<font color='green'>": "<font color='red'>") ;
447 $gdesc = $Lang::tr
{'click to enable'};
451 if ($settings{'KEY1'} eq $key) {
452 print "<tr bgcolor='${Header::colouryellow}'>";
454 print "<tr bgcolor='$color{'color22'}'>";
456 print "<tr bgcolor='$color{'color20'}'>";
459 #if a field is empty, replace it with a '---' to see colorized info!
460 $temp[1] = '---' if (!$temp[1]);
461 $temp[2] = '---' if (!$temp[2]);
464 <td align='center'><a href='http://$temp[0]'>$temp[0]</a></td>
465 <td align='center'>$sync$temp[1]</td>
466 <td align='center'>$sync$temp[2]</td>
469 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
470 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
471 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gifproxy' alt='$descproxy' title='$descproxy' />
472 <input type='hidden' name='KEY1' value='$key' />
473 <input type='hidden' name='KEY2' value='3' />
478 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
479 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
480 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gifwildcard' alt='$descwildcard' title='$descwildcard' />
481 <input type='hidden' name='KEY1' value='$key' />
482 <input type='hidden' name='KEY2' value='4' />
487 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
488 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
489 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
490 <input type='hidden' name='KEY1' value='$key' />
491 <input type='hidden' name='KEY2' value='7' />
496 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
497 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
498 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
499 <input type='hidden' name='KEY1' value='$key' />
504 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
505 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
506 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
507 <input type='hidden' name='KEY1' value='$key' />
517 # If table contains entries, print 'Key to action icons'
522 <td class='boldbase'> <b>$Lang::tr{'legend'}: </b></td>
523 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
524 <td class='base'>$Lang::tr{'click to disable'}</td>
525 <td> </td>
526 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
527 <td class='base'>$Lang::tr{'click to enable'}</td>
528 <td> </td>
529 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
530 <td class='base'>$Lang::tr{'edit'}</td>
531 <td> </td>
532 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
533 <td class='base'>$Lang::tr{'remove'}</td>
534 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
535 <td align='center' width='30%'><input type='submit' name='ACTION' value='$Lang::tr{'instant update'}' /></td>
544 &Header
::closebigbox
();
545 &Header
::closepage
();
547 ## Ouf it's the end !
550 # write the "current" array
553 open(FILE
, ">$datafile") or die 'ddns datafile error';