]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/ddns.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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'}{'no-ip.com'} = '';
247 $checked{'SERVICE'}{'nsupdate'} = '';
248 $checked{'SERVICE'}{'ovh.com'} = '';
249 $checked{'SERVICE'}{'regfish.com'} = '';
250 $checked{'SERVICE'}{'selfhost.de'} = '';
251 $checked{'SERVICE'}{'tzo.com'} = '';
252 $checked{'SERVICE'}{'zoneedit.com'} = '';
253 $checked{'SERVICE'}{$settings{'SERVICE'}} = "selected='selected'";
255 $checked{'BEHINDROUTER'}{'RED_IP'} = '';
256 $checked{'BEHINDROUTER'}{'FETCH_IP'} = '';
257 $checked{'BEHINDROUTER'}{$settings{'BEHINDROUTER'}} = "checked='checked'";
258 $checked{'MINIMIZEUPDATES'} = ($settings{'MINIMIZEUPDATES'} eq '' ) ?
'' : "checked='checked'";
260 $checked{'PROXY'}{'on'} = ($settings{'PROXY'} eq '') ?
'' : "checked='checked'";
261 $checked{'WILDCARDS'}{'on'} = ($settings{'WILDCARDS'} eq '') ?
'' : "checked='checked'";
262 $checked{'ENABLED'}{'on'} = ($settings{'ENABLED'} eq '' ) ?
'' : "checked='checked'";
265 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
266 print "<font class='base'>$errormessage </font>";
271 $warnmessage = "<font color=${Header::colourred}><b>$Lang::tr{'capswarning'}</b></font>: $warnmessage";
273 &Header
::openbox
('100%', 'left', $Lang::tr
{'settings'});
274 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>";
278 <td class='base'>$Lang::tr{'dyn dns source choice'}</td>
280 <td class='base'><input type='radio' name='BEHINDROUTER' value='RED_IP' $checked{'BEHINDROUTER'}{'RED_IP'} />
281 $Lang::tr{'use ipfire red ip'}</td>
283 <td class='base'><input type='radio' name='BEHINDROUTER' value='FETCH_IP' $checked{'BEHINDROUTER'}{'FETCH_IP'} />
284 $Lang::tr{'fetch ip from'} <img src='/blob.gif' alt='*' /></td>
287 <td class='base'><input type='checkbox' name='MINIMIZEUPDATES' $checked{'MINIMIZEUPDATES'} />
288 $Lang::tr{'ddns minimize updates'}</td>
298 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
299 <td width='70%' class='base'>$Lang::tr{'avoid dod'}</td>
300 <td width='30%' align='center' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
306 &Header
::closebox
(); # end of Settings1
309 my $buttontext = $Lang::tr
{'add'};
310 if ($settings{'KEY1'} ne '') {
311 $buttontext = $Lang::tr
{'update'};
312 &Header
::openbox
('100%', 'left', $Lang::tr
{'edit an existing host'});
314 &Header
::openbox
('100%', 'left', $Lang::tr
{'add a host'});
317 #Edited line number (KEY1) passed until cleared by 'save' or 'remove'
319 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
320 <input type='hidden' name='KEY1' value='$settings{'KEY1'}' />
323 <td width='25%' class='base'>$Lang::tr{'service'}:</td>
324 <td width='25%'><select size='1' name='SERVICE'>
325 <option $checked{'SERVICE'}{'cjb.net'}>cjb.net</option>
326 <option $checked{'SERVICE'}{'dhs.org'}>dhs.org</option>
327 <option $checked{'SERVICE'}{'dnspark.com'}>dnspark.com</option>
328 <option $checked{'SERVICE'}{'dtdns.com'}>dtdns.com</option>
329 <option $checked{'SERVICE'}{'dyndns.org'}>dyndns.org</option>
330 <option $checked{'SERVICE'}{'dyndns-custom'}>dyndns-custom</option>
331 <option $checked{'SERVICE'}{'dyndns-static'}>dyndns-static</option>
332 <option $checked{'SERVICE'}{'dyns.cx'}>dyns.cx</option>
333 <option $checked{'SERVICE'}{'dynu.ca'}>dynu.ca dyn.ee dynserv.(ca|org|net|com)</option>
334 <option $checked{'SERVICE'}{'easydns.com'}>easydns.com</option>
335 <option $checked{'SERVICE'}{'enom.com'}>enom.com</option>
336 <option $checked{'SERVICE'}{'freedns.afraid.org'}>freedns.afraid.org</option>
337 <option $checked{'SERVICE'}{'hn.org'}>hn.org</option>
338 <option $checked{'SERVICE'}{'no-ip.com'}>no-ip.com</option>
339 <option $checked{'SERVICE'}{'nsupdate'}>nsupdate</option>
340 <option $checked{'SERVICE'}{'ovh.com'}>ovh.com</option>
341 <option $checked{'SERVICE'}{'regfish.com'}>regfish.com</option>
342 <option $checked{'SERVICE'}{'selfhost.de'}>selfhost.de</option>
343 <!-- <option $checked{'SERVICE'}{'tzo.com'}>tzo.com</option> comment this service out until a working fix is developed -->
344 <option $checked{'SERVICE'}{'zoneedit.com'}>zoneedit.com</option>
346 <td width='20%' class='base'>$Lang::tr{'hostname'}: <img src='/blob.gif' alt='*' /></td>
347 <td width='30%'><input type='text' name='HOSTNAME' value='$settings{'HOSTNAME'}' /></td>
349 <td class='base'>$Lang::tr{'behind a proxy'}</td>
350 <td><input type='checkbox' name='PROXY' value='on' $checked{'PROXY'}{'on'} /></td>
351 <td class='base'>$Lang::tr{'domain'}:</td>
352 <td><input type='text' name='DOMAIN' value='$settings{'DOMAIN'}' /></td>
354 <td class='base'>$Lang::tr{'enable wildcards'}</td>
355 <td><input type='checkbox' name='WILDCARDS' value='on' $checked{'WILDCARDS'}{'on'} /></td>
356 <td class='base'>$Lang::tr{'username'}</td>
357 <td><input type='text' name='LOGIN' value='$settings{'LOGIN'}' /></td>
361 <td class='base'>$Lang::tr{'password'}</td>
362 <td><input type='password' name='PASSWORD' value='$settings{'PASSWORD'}' /></td>
364 <td class='base'>$Lang::tr{'enabled'}</td>
365 <td><input type='checkbox' name='ENABLED' value='on' $checked{'ENABLED'}{'on'} /></td>
366 <td class='base'>$Lang::tr{'again'}</td>
367 <td><input type='password' name='PASSWORD2' value='$settings{'PASSWORD2'}' /></td>
373 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
374 <td width='70%' class='base'>$ddnsprefix</td>
376 <td width='30%' align='center' class='base'>
377 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}' />
378 <input type='submit' name='SUBMIT' value='$buttontext' /> </td>
387 # Third box shows the list, in columns
389 &Header
::openbox
('100%', 'left', $Lang::tr
{'current hosts'});
393 <td width='15%' align='center' class='boldbase'><b>$Lang::tr{'service'}</b></td>
394 <td width='25%' align='center' class='boldbase'><b>$Lang::tr{'hostname'}</b></td>
395 <td width='30%' align='center' class='boldbase'><b>$Lang::tr{'domain'}</b></td>
396 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'proxy'}</b></td>
397 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'wildcards'}</b></td>
398 <td width='10%' colspan='3' class='boldbase' align='center'><b>$Lang::tr{'action'}</b></td>
402 my $ip = &General
::GetDyndnsRedIP
;
404 foreach my $line (@current) {
405 chomp($line); # remove newline
406 my @temp = split(/\,/,$line);
408 if ($temp[0] eq 'no-ip.com') {
409 $temp[1] =~ s!$General::noipprefix(.*)!<b>group:</b>$1 !;
412 #Choose icon for checkbox
416 if ($temp[3] eq "on") {
417 $gifproxy = 'on.gif';
418 $descproxy = $Lang::tr
{'click to disable'};
420 $gifproxy = 'off.gif';
421 $descproxy = $Lang::tr
{'click to enable'};
426 if ($temp[4] eq "on") {
427 $gifwildcard = 'on.gif';
428 $descwildcard = $Lang::tr
{'click to disable'};
430 $gifwildcard = 'off.gif';
431 $descwildcard = $Lang::tr
{'click to enable'};
434 my $sync = "<font color='blue'>";
437 if ($temp[7] eq "on") {
439 $gdesc = $Lang::tr
{'click to disable'};
440 $sync = (&General
::DyndnsServiceSync
($ip,$temp[1], $temp[2]) ?
"<font color='green'>": "<font color='red'>") ;
443 $gdesc = $Lang::tr
{'click to enable'};
447 if ($settings{'KEY1'} eq $key) {
448 print "<tr bgcolor='${Header::colouryellow}'>";
450 print "<tr bgcolor='$color{'color22'}'>";
452 print "<tr bgcolor='$color{'color20'}'>";
455 #if a field is empty, replace it with a '---' to see colorized info!
456 $temp[1] = '---' if (!$temp[1]);
457 $temp[2] = '---' if (!$temp[2]);
460 <td align='center'><a href='http://$temp[0]'>$temp[0]</a></td>
461 <td align='center'>$sync$temp[1]</td>
462 <td align='center'>$sync$temp[2]</td>
465 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
466 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
467 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gifproxy' alt='$descproxy' title='$descproxy' />
468 <input type='hidden' name='KEY1' value='$key' />
469 <input type='hidden' name='KEY2' value='3' />
474 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
475 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
476 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gifwildcard' alt='$descwildcard' title='$descwildcard' />
477 <input type='hidden' name='KEY1' value='$key' />
478 <input type='hidden' name='KEY2' value='4' />
483 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
484 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
485 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc' />
486 <input type='hidden' name='KEY1' value='$key' />
487 <input type='hidden' name='KEY2' value='7' />
492 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
493 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
494 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
495 <input type='hidden' name='KEY1' value='$key' />
500 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
501 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
502 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
503 <input type='hidden' name='KEY1' value='$key' />
513 # If table contains entries, print 'Key to action icons'
518 <td class='boldbase'> <b>$Lang::tr{'legend'}: </b></td>
519 <td><img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
520 <td class='base'>$Lang::tr{'click to disable'}</td>
521 <td> </td>
522 <td><img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
523 <td class='base'>$Lang::tr{'click to enable'}</td>
524 <td> </td>
525 <td><img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
526 <td class='base'>$Lang::tr{'edit'}</td>
527 <td> </td>
528 <td><img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
529 <td class='base'>$Lang::tr{'remove'}</td>
530 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
531 <td align='center' width='30%'><input type='submit' name='ACTION' value='$Lang::tr{'instant update'}' /></td>
540 &Header
::closebigbox
();
541 &Header
::closepage
();
543 ## Ouf it's the end !
546 # write the "current" array
549 open(FILE
, ">$datafile") or die 'ddns datafile error';