dfdf7cdf90491e87686caddcc38fd08b4606e394
[people/teissler/ipfire-2.x.git] / html / cgi-bin / gui.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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 ###############################################################################
21
22
23 use strict;
24
25 # enable only the following on debugging purpose
26 #use warnings;
27 #use CGI::Carp 'fatalsToBrowser';
28
29 require '/var/ipfire/general-functions.pl';
30 require "${General::swroot}/lang.pl";
31 require "${General::swroot}/header.pl";
32
33 my %cgiparams=();
34 my %mainsettings=();
35 my %checked=();
36 my $errormessage='';
37
38
39 $cgiparams{'SPEED'} = 'off';
40 $cgiparams{'WINDOWWITHHOSTNAME'} = 'off';
41 $cgiparams{'REBOOTQUESTION'} = 'off';
42 $cgiparams{'REFRESHINDEX'} = 'off';
43 $cgiparams{'ACTION'} = '';
44 &Header::getcgihash(\%cgiparams);
45
46 &Header::showhttpheaders();
47 &General::readhash("${General::swroot}/main/settings",\%mainsettings);
48 if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}")
49 {
50 open(FILE,"${General::swroot}/langs/list");
51 my $found=0;
52 while (<FILE>)
53 {
54 my $lang='';
55 my $engname='';
56 my $natname='';
57 chomp;
58 ($lang,$engname,$natname) = split (/:/, $_,3);
59 if ($cgiparams{'lang'} eq $lang)
60 {
61 $found=1;
62 }
63 }
64 close (FILE);
65 if ( $found == 0 )
66 {
67 $errormessage="$errormessage<P>$Lang::tr{'invalid input'}";
68 goto SAVE_ERROR;
69 }
70
71 # Set flag if index page is to refresh whilst ppp is up.
72 # Default is NO refresh.
73 if ($cgiparams{'REFRESHINDEX'} ne 'off') {
74 system ('/usr/bin/touch', "${General::swroot}/main/refreshindex");
75 } else {
76 unlink "${General::swroot}/main/refreshindex";
77 }
78
79 # Beep on ip-up or ip-down. Default is ON.
80 if ($cgiparams{'PPPUPDOWNBEEP'} ne 'on') {
81 $cgiparams{'PPPUPDOWNBEEP'} = 'off';
82 system ('/usr/bin/touch', "${General::swroot}/ppp/nobeeps");
83 } else {
84 unlink "${General::swroot}/ppp/nobeeps";
85 }
86
87 # write cgi vars to the file.
88 $mainsettings{'LANGUAGE'} = $cgiparams{'lang'};
89 $mainsettings{'WINDOWWITHHOSTNAME'} = $cgiparams{'WINDOWWITHHOSTNAME'};
90 $mainsettings{'REBOOTQUESTION'} = $cgiparams{'REBOOTQUESTION'};
91 $mainsettings{'PPPUPDOWNBEEP'} = $cgiparams{'PPPUPDOWNBEEP'};
92 $mainsettings{'SPEED'} = $cgiparams{'SPEED'};
93 $mainsettings{'THEME'} = $cgiparams{'theme'};
94 $mainsettings{'REFRESHINDEX'} = $cgiparams{'REFRESHINDEX'};
95 &General::writehash("${General::swroot}/main/settings", \%mainsettings);
96 &Lang::reload($cgiparams{'lang'});
97 SAVE_ERROR:
98 } else {
99 if ($mainsettings{'WINDOWWITHHOSTNAME'}) {
100 $cgiparams{'WINDOWWITHHOSTNAME'} = $mainsettings{'WINDOWWITHHOSTNAME'};
101 } else {
102 $cgiparams{'WINDOWWITHHOSTNAME'} = 'on';
103 }
104
105 if ($mainsettings{'REBOOTQUESTION'}) {
106 $cgiparams{'REBOOTQUESTION'} = $mainsettings{'REBOOTQUESTION'};
107 } else {
108 $cgiparams{'REBOOTQUESTION'} = 'on';
109 }
110
111 if ($mainsettings{'PPPUPDOWNBEEP'}) {
112 $cgiparams{'PPPUPDOWNBEEP'} = $mainsettings{'PPPUPDOWNBEEP'};
113 } else {
114 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
115 }
116
117 if ($mainsettings{'THEME'}) {
118 $cgiparams{'THEME'} = $mainsettings{'THEME'};
119 } else {
120 $cgiparams{'THEME'} = 'ipfire';
121 }
122
123 if($mainsettings{'REFRESHINDEX'}) {
124 $cgiparams{'REFRESHINDEX'} = $mainsettings{'REFRESHINDEX'};
125 } else {
126 $cgiparams{'REFRESHINDEX'} = 'off';
127 }
128 if($mainsettings{'SPEED'}) {
129 $cgiparams{'SPEED'} = $mainsettings{'SPEED'};
130 } else {
131 # if var is not defined it will be set to on because after installation var
132 # is not set and the speedmeter should be displayed, it can only be deactivated
133 # by manually setting the var to off
134 $cgiparams{'SPEED'} = 'on';
135 }
136 }
137
138 # Default settings
139 if ($cgiparams{'ACTION'} eq "$Lang::tr{'restore defaults'}")
140 {
141 $cgiparams{'WINDOWWITHHOSTNAME'} = 'on';
142 $cgiparams{'REBOOTQUESTION'} = 'on';
143 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
144 $cgiparams{'REFRESHINDEX'} = 'off';
145 $cgiparams{'SPEED'} = 'on';
146 $cgiparams{'THEME'} = 'ipfire';
147 }
148
149 $checked{'WINDOWWITHHOSTNAME'}{'off'} = '';
150 $checked{'WINDOWWITHHOSTNAME'}{'on'} = '';
151 $checked{'WINDOWWITHHOSTNAME'}{$cgiparams{'WINDOWWITHHOSTNAME'}} = "checked='checked'";
152
153 $checked{'REBOOTQUESTION'}{'off'} = '';
154 $checked{'REBOOTQUESTION'}{'on'} = '';
155 $checked{'REBOOTQUESTION'}{$cgiparams{'REBOOTQUESTION'}} = "checked='checked'";
156
157 $checked{'PPPUPDOWNBEEP'}{'off'} = '';
158 $checked{'PPPUPDOWNBEEP'}{'on'} = '';
159 $checked{'PPPUPDOWNBEEP'}{$cgiparams{'PPPUPDOWNBEEP'}} = "checked='checked'";
160
161 $checked{'REFRESHINDEX'}{'off'} = '';
162 $checked{'REFRESHINDEX'}{'on'} = '';
163 $checked{'REFRESHINDEX'}{$cgiparams{'REFRESHINDEX'}} = "checked='checked'";
164
165 $checked{'SPEED'}{'off'} = '';
166 $checked{'SPEED'}{'on'} = '';
167 $checked{'SPEED'}{$cgiparams{'SPEED'}} = "checked='checked'";
168
169 &Header::openpage($Lang::tr{'gui settings'}, 1, '');
170 &Header::openbigbox('100%', 'left', '', $errormessage);
171
172 if ($errormessage) {
173 &Header::openbox('100%','left',$Lang::tr{'error messages'});
174 print "<font class='base'>${errormessage}&nbsp;</font>\n";
175 &Header::closebox();
176 }
177
178 &Header::openbox('100%','left',$Lang::tr{'display'});
179
180 print <<END
181 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
182 <table width='100%'>
183 <tr>
184 <td><input type='checkbox' name='WINDOWWITHHOSTNAME' $checked{'WINDOWWITHHOSTNAME'}{'on'} /></td>
185 <td>$Lang::tr{'display hostname in window title'}</td>
186 </tr>
187 <tr>
188 <td><input type='checkbox' name='REBOOTQUESTION' $checked{'REBOOTQUESTION'}{'on'} /></td>
189 <td>$Lang::tr{'reboot question'}</td>
190 </tr>
191 <tr>
192 <td><input type='checkbox' name='REFRESHINDEX' $checked{'REFRESHINDEX'}{'on'} /></td>
193 <td>$Lang::tr{'refresh index page while connected'}</td>
194 </tr>
195 <tr>
196 <td><input type='checkbox' name='SPEED' $checked{'SPEED'}{'on'} /></td>
197 <td>$Lang::tr{'show ajax speedmeter in footer'}</td>
198 </tr>
199 <tr>
200 <td>&nbsp;</td>
201 <td>$Lang::tr{'languagepurpose'}</td>
202 </tr>
203 <tr>
204 <td>&nbsp;</td>
205 <td><select name='lang'>
206 END
207 ;
208
209 my $id=0;
210 open(FILE,"${General::swroot}/langs/list");
211 while (<FILE>)
212 {
213 my $lang='';
214 my $engname='';
215 my $natname='';
216 $id++;
217 chomp;
218 ($lang,$engname,$natname) = split (/:/, $_, 3);
219 print "<option value='$lang' ";
220 if ($lang =~ /$mainsettings{'LANGUAGE'}/)
221 {
222 print " selected='selected'";
223 }
224 print <<END
225 >$engname ($natname)</option>
226 END
227 ;
228 }
229
230 print <<END
231 </select></td></tr>
232 </table>
233 END
234 ;
235 &Header::closebox();
236 &Header::openbox('100%','left',$Lang::tr{'theme'});
237 print<<END;
238 <table>
239 <tr>
240 <td>&nbsp;</td>
241 <td><select name='theme'>
242 END
243 ;
244
245 my $dir = "/srv/web/ipfire/html/themes";
246 local *DH;
247 my ($item, $file);
248 my @files;
249
250 # Foreach directory create am theme entry to be selected by user
251
252 opendir (DH, $dir);
253 while ($file = readdir (DH)) {
254 next if ( $file =~ /^\./ );
255 push (@files, $file);
256 }
257 closedir (DH);
258
259 foreach $item (sort (@files)) {
260 if ( "$mainsettings{'THEME'}" eq "$item" ) {
261 print "<option value='$item' selected='selected'>$item</option>\n";
262 } else {
263 print "<option value='$item'>$item</option>\n";
264 }
265 }
266
267 print <<END
268 </select></td></tr>
269 </table>
270 END
271 ;
272 &Header::closebox();
273 &Header::openbox('100%','left',$Lang::tr{'sound'});
274 print <<END
275 <tr>
276 <td><input type ='checkbox' name='PPPUPDOWNBEEP' $checked{'PPPUPDOWNBEEP'}{'on'} /></td>
277 <td>$Lang::tr{'beep when ppp connects or disconnects'}</td>
278 </tr>
279 <tr>
280 <td colspan='2'></td>
281 </tr>
282 </table>
283 <div align='right'>
284 <br>
285 <table width='100%'>
286 <tr>
287 <td width='90%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'restore defaults'}' /></td>
288 <td width='10%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
289 </tr>
290 </table>
291 </div>
292 </form>
293 END
294 ;
295 &Header::closebox();
296 &Header::closebigbox();
297 &Header::closepage();
298
299
300