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