Ajax Speedmeter ist ueber Guioptions deaktivierbar -> friss gut CPU
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / gui.cgi
CommitLineData
ac1cfefa
MT
1#!/usr/bin/perl
2#
78331e30 3# IPFire CGIs
ac1cfefa
MT
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) Bill Ward
8#
9# $Id: gui.cgi,v 1.2.2.17 2005/07/06 09:21:22 franck78 Exp $
10#
11
12use strict;
13
14# enable only the following on debugging purpose
15#use warnings;
16#use CGI::Carp 'fatalsToBrowser';
17
986e08d9 18require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
19require "${General::swroot}/lang.pl";
20require "${General::swroot}/header.pl";
21
22my %cgiparams=();
23my %mainsettings=();
24my %checked=();
25my $errormessage='';
26
27
bd365f3a 28$cgiparams{'FX'} = 'off';
18322edf 29$cgiparams{'SPEED'} = 'off';
ac1cfefa
MT
30$cgiparams{'WINDOWWITHHOSTNAME'} = 'off';
31$cgiparams{'REFRESHINDEX'} = 'off';
32$cgiparams{'ACTION'} = '';
33&Header::getcgihash(\%cgiparams);
34
35&Header::showhttpheaders();
36&General::readhash("${General::swroot}/main/settings",\%mainsettings);
37if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}")
38{
39 open(FILE,"${General::swroot}/langs/list");
40 my $found=0;
41 while (<FILE>)
42 {
43 my $lang='';
44 my $engname='';
45 my $natname='';
46 chomp;
47 ($lang,$engname,$natname) = split (/:/, $_,3);
48 if ($cgiparams{'lang'} eq $lang)
49 {
50 $found=1;
51 }
52 }
53 close (FILE);
54 if ( $found == 0 )
55 {
56 $errormessage="$errormessage<P>$Lang::tr{'invalid input'}";
57 goto SAVE_ERROR;
58 }
59
ac1cfefa
MT
60 # Set flag if index page is to refresh whilst ppp is up.
61 # Default is NO refresh.
62 if ($cgiparams{'REFRESHINDEX'} ne 'off') {
9833e7d8 63 system ('/usr/bin/touch', "${General::swroot}/main/refreshindex");
ac1cfefa
MT
64 } else {
65 unlink "${General::swroot}/main/refreshindex";
66 }
67
68 # Beep on ip-up or ip-down. Default is ON.
69 if ($cgiparams{'PPPUPDOWNBEEP'} ne 'on') {
70 $cgiparams{'PPPUPDOWNBEEP'} = 'off';
9833e7d8 71 system ('/usr/bin/touch', "${General::swroot}/ppp/nobeeps");
ac1cfefa
MT
72 } else {
73 unlink "${General::swroot}/ppp/nobeeps";
74 }
75
76 # write cgi vars to the file.
77 $mainsettings{'LANGUAGE'} = $cgiparams{'lang'};
ac1cfefa
MT
78 $mainsettings{'WINDOWWITHHOSTNAME'} = $cgiparams{'WINDOWWITHHOSTNAME'};
79 $mainsettings{'PPPUPDOWNBEEP'} = $cgiparams{'PPPUPDOWNBEEP'};
bd365f3a 80 $mainsettings{'FX'} = $cgiparams{'FX'};
18322edf 81 $mainsettings{'SPEED'} = $cgiparams{'SPEED'};
f8e080ef 82 $mainsettings{'THEME'} = $cgiparams{'theme'};
ac1cfefa
MT
83 $mainsettings{'REFRESHINDEX'} = $cgiparams{'REFRESHINDEX'};
84 &General::writehash("${General::swroot}/main/settings", \%mainsettings);
85 &Lang::reload($cgiparams{'lang'});
86 SAVE_ERROR:
87} else {
ac1cfefa
MT
88 if ($mainsettings{'WINDOWWITHHOSTNAME'}) {
89 $cgiparams{'WINDOWWITHHOSTNAME'} = $mainsettings{'WINDOWWITHHOSTNAME'};
90 } else {
91 $cgiparams{'WINDOWWITHHOSTNAME'} = 'off';
92 }
93
94 if ($mainsettings{'PPPUPDOWNBEEP'}) {
95 $cgiparams{'PPPUPDOWNBEEP'} = $mainsettings{'PPPUPDOWNBEEP'};
96 } else {
97 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
98 }
99
bd365f3a
MT
100 if ($mainsettings{'FX'}) {
101 $cgiparams{'FX'} = $mainsettings{'FX'};
102 } else {
103 $cgiparams{'FX'} = 'on';
104 }
105
f8e080ef
MT
106 if ($mainsettings{'THEME'}) {
107 $cgiparams{'THEME'} = $mainsettings{'THEME'};
108 } else {
109 $cgiparams{'THEME'} = 'ipfire';
110 }
111
ac1cfefa
MT
112 if($mainsettings{'REFRESHINDEX'}) {
113 $cgiparams{'REFRESHINDEX'} = $mainsettings{'REFRESHINDEX'};
114 } else {
115 $cgiparams{'REFRESHINDEX'} = 'off';
116 }
18322edf
CS
117 if($mainsettings{'SPEED'}) {
118 $cgiparams{'SPEED'} = $mainsettings{'SPEED'};
119 } else {
120 $cgiparams{'SPEED'} = 'off';
121 }
ac1cfefa
MT
122}
123
124# Default settings
125if ($cgiparams{'ACTION'} eq "$Lang::tr{'restore defaults'}")
126{
ac1cfefa
MT
127 $cgiparams{'WINDOWWITHHOSTNAME'} = 'off';
128 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
129 $cgiparams{'REFRESHINDEX'} = 'off';
bd365f3a 130 $cgiparams{'FX'} = 'on';
18322edf 131 $cgiparams{'SPEED'} = 'on';
f8e080ef 132 $cgiparams{'THEME'} = 'ipfire';
ac1cfefa
MT
133}
134
ac1cfefa
MT
135$checked{'WINDOWWITHHOSTNAME'}{'off'} = '';
136$checked{'WINDOWWITHHOSTNAME'}{'on'} = '';
137$checked{'WINDOWWITHHOSTNAME'}{$cgiparams{'WINDOWWITHHOSTNAME'}} = "checked='checked'";
138
139$checked{'PPPUPDOWNBEEP'}{'off'} = '';
140$checked{'PPPUPDOWNBEEP'}{'on'} = '';
141$checked{'PPPUPDOWNBEEP'}{$cgiparams{'PPPUPDOWNBEEP'}} = "checked='checked'";
142
143$checked{'REFRESHINDEX'}{'off'} = '';
144$checked{'REFRESHINDEX'}{'on'} = '';
145$checked{'REFRESHINDEX'}{$cgiparams{'REFRESHINDEX'}} = "checked='checked'";
146
bd365f3a
MT
147$checked{'FX'}{'off'} = '';
148$checked{'FX'}{'on'} = '';
149$checked{'FX'}{$cgiparams{'FX'}} = "checked='checked'";
150
18322edf
CS
151$checked{'SPEED'}{'off'} = '';
152$checked{'SPEED'}{'on'} = '';
153$checked{'SPEED'}{$cgiparams{'SPEED'}} = "checked='checked'";
154
ac1cfefa
MT
155&Header::openpage($Lang::tr{'gui settings'}, 1, '');
156&Header::openbigbox('100%', 'left', '', $errormessage);
157
158if ($errormessage) {
159 &Header::openbox('100%','left',$Lang::tr{'error messages'});
160 print "<font class='base'>${errormessage}&nbsp;</font>\n";
161 &Header::closebox();
162}
163
164&Header::openbox('100%','left',$Lang::tr{'gui settings'});
165
166print <<END
167<form method='post' action='$ENV{'SCRIPT_NAME'}'>
168<table width='100%'>
169<tr>
170 <td colspan='2'><p><b>$Lang::tr{'display'}</b></td>
171</tr>
bd365f3a
MT
172<tr>
173 <td><input type='checkbox' name='FX' $checked{'FX'}{'on'} /></td>
174 <td>$Lang::tr{'display webinterface effects'}</td>
175</tr>
ac1cfefa
MT
176<tr>
177 <td><input type='checkbox' name='WINDOWWITHHOSTNAME' $checked{'WINDOWWITHHOSTNAME'}{'on'} /></td>
178 <td>$Lang::tr{'display hostname in window title'}</td>
179</tr>
180<tr>
181 <td><input type='checkbox' name='REFRESHINDEX' $checked{'REFRESHINDEX'}{'on'} /></td>
182 <td>$Lang::tr{'refresh index page while connected'}</td>
183</tr>
18322edf
CS
184<tr>
185 <td><input type='checkbox' name='SPEED' $checked{'SPEED'}{'on'} /></td>
186 <td>$Lang::tr{'show ajax speedmeter in footer'}</td>
187</tr>
ac1cfefa
MT
188<tr>
189 <td>&nbsp;</td>
190 <td>$Lang::tr{'languagepurpose'}</td>
191</tr>
192<tr>
193 <td>&nbsp;</td>
194 <td><select name='lang'>
195END
196;
197
198my $id=0;
199open(FILE,"${General::swroot}/langs/list");
200while (<FILE>)
201{
202 my $lang='';
203 my $engname='';
204 my $natname='';
205 $id++;
206 chomp;
207 ($lang,$engname,$natname) = split (/:/, $_, 3);
208 print "<option value='$lang' ";
209 if ($lang =~ /$mainsettings{'LANGUAGE'}/)
210 {
211 print " selected='selected'";
212 }
213 print <<END
214>$engname ($natname)</option>
215END
216 ;
217}
218
f8e080ef
MT
219print <<END
220</select></td></tr>
221<tr>
222 <td colspan='2'><hr /><p><b>$Lang::tr{'theme'}</b></td>
223</tr>
224<tr>
225 <td>&nbsp;</td>
226 <td><select name='theme'>
227END
228;
229
230my $dir = "/srv/web/ipfire/html/themes";
231local *DH;
232my ($item, $file);
233my @files;
234
235opendir (DH, $dir);
236while ($file = readdir (DH)) {
237 next if ( $file =~ /^\./ );
238 push (@files, $file);
239}
240closedir (DH);
241
242foreach $item (sort (@files)) {
243 if ( "$mainsettings{'THEME'}" eq "$item" ) {
244 print "<option value='$item' selected='selected'>$item</option>\n";
245 } else {
246 print "<option value='$item'>$item</option>\n";
247 }
248}
249
ac1cfefa
MT
250print <<END
251</select></td></tr>
252<tr>
253 <td colspan='2'><hr /><p><b>$Lang::tr{'sound'}</b></td>
254</tr>
255<tr>
256 <td><input type ='checkbox' name='PPPUPDOWNBEEP' $checked{'PPPUPDOWNBEEP'}{'on'} /></td>
257 <td>$Lang::tr{'beep when ppp connects or disconnects'}</td>
258</tr>
259<tr>
260 <td colspan='2'><hr /></td>
261</tr>
262</table>
263<div align='center'>
264<table width='80%'>
265<tr>
266 <td width='50%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'restore defaults'}' /></td>
267 <td width='50%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
268</tr>
269</table>
270</div>
271</form>
272END
273;
274&Header::closebox();
275&Header::closebigbox();
276&Header::closepage();
277
278
279