]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/gui.cgi
Merge remote-tracking branch 'dweismueller/vdr_vnsiserver5_new' into next
[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{'REFRESHINDEX'} = 'off';
42 $cgiparams{'ACTION'} = '';
43 &Header::getcgihash(\%cgiparams);
44
45 &Header::showhttpheaders();
46 &General::readhash("${General::swroot}/main/settings",\%mainsettings);
47 if ($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'}</p>";
67 goto SAVE_ERROR;
68 }
69
70 # Set flag if index page is to refresh whilst ppp is up.
71 # Default is NO refresh.
72 if ($cgiparams{'REFRESHINDEX'} ne 'off') {
73 system ('/usr/bin/touch', "${General::swroot}/main/refreshindex");
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';
81 system ('/usr/bin/touch', "${General::swroot}/ppp/nobeeps");
82 } else {
83 unlink "${General::swroot}/ppp/nobeeps";
84 }
85
86 # write cgi vars to the file.
87 $mainsettings{'LANGUAGE'} = $cgiparams{'lang'};
88 $mainsettings{'WINDOWWITHHOSTNAME'} = $cgiparams{'WINDOWWITHHOSTNAME'};
89 $mainsettings{'PPPUPDOWNBEEP'} = $cgiparams{'PPPUPDOWNBEEP'};
90 $mainsettings{'SPEED'} = $cgiparams{'SPEED'};
91 $mainsettings{'THEME'} = $cgiparams{'theme'};
92 $mainsettings{'REFRESHINDEX'} = $cgiparams{'REFRESHINDEX'};
93 &General::writehash("${General::swroot}/main/settings", \%mainsettings);
94 &Lang::reload($cgiparams{'lang'});
95 SAVE_ERROR:
96 } else {
97 if ($mainsettings{'WINDOWWITHHOSTNAME'}) {
98 $cgiparams{'WINDOWWITHHOSTNAME'} = $mainsettings{'WINDOWWITHHOSTNAME'};
99 } else {
100 $cgiparams{'WINDOWWITHHOSTNAME'} = 'on';
101 }
102
103 if ($mainsettings{'PPPUPDOWNBEEP'}) {
104 $cgiparams{'PPPUPDOWNBEEP'} = $mainsettings{'PPPUPDOWNBEEP'};
105 } else {
106 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
107 }
108
109 if ($mainsettings{'THEME'}) {
110 $cgiparams{'THEME'} = $mainsettings{'THEME'};
111 } else {
112 $cgiparams{'THEME'} = 'ipfire';
113 }
114
115 if($mainsettings{'REFRESHINDEX'}) {
116 $cgiparams{'REFRESHINDEX'} = $mainsettings{'REFRESHINDEX'};
117 } else {
118 $cgiparams{'REFRESHINDEX'} = 'off';
119 }
120 if($mainsettings{'SPEED'}) {
121 $cgiparams{'SPEED'} = $mainsettings{'SPEED'};
122 } else {
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';
127 }
128 }
129
130 # Default settings
131 if ($cgiparams{'ACTION'} eq "$Lang::tr{'restore defaults'}")
132 {
133 $cgiparams{'WINDOWWITHHOSTNAME'} = 'on';
134 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
135 $cgiparams{'REFRESHINDEX'} = 'off';
136 $cgiparams{'SPEED'} = 'on';
137 $cgiparams{'THEME'} = 'ipfire';
138 }
139
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
152 $checked{'SPEED'}{'off'} = '';
153 $checked{'SPEED'}{'on'} = '';
154 $checked{'SPEED'}{$cgiparams{'SPEED'}} = "checked='checked'";
155
156 &Header::openpage($Lang::tr{'gui settings'}, 1, '');
157 &Header::openbigbox('100%', 'left', '', $errormessage);
158
159 if ($errormessage) {
160 &Header::openbox('100%','left',$Lang::tr{'error messages'});
161 print "<font class='base'>${errormessage}&nbsp;</font>\n";
162 &Header::closebox();
163 }
164
165 &Header::openbox('100%','left',$Lang::tr{'display'});
166
167 print <<END
168 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
169 <table width='100%'>
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>
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>
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'>
189 END
190 ;
191
192 my $id=0;
193 open(FILE,"${General::swroot}/langs/list");
194 while (<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>
209 END
210 ;
211 }
212
213 print <<END
214 </select></td></tr>
215 </table>
216 END
217 ;
218 &Header::closebox();
219 &Header::openbox('100%','left',$Lang::tr{'theme'});
220 print<<END;
221 <table>
222 <tr>
223 <td>&nbsp;</td>
224 <td><select name='theme'>
225 END
226 ;
227
228 my $dir = "/srv/web/ipfire/html/themes";
229 local *DH;
230 my ($item, $file);
231 my @files;
232
233 # Foreach directory create am theme entry to be selected by user
234
235 opendir (DH, $dir);
236 while ($file = readdir (DH)) {
237 next if ( $file =~ /^\./ );
238 push (@files, $file);
239 }
240 closedir (DH);
241
242 foreach $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
250 print <<END
251 </select></td></tr>
252 </table>
253 END
254 ;
255 &Header::closebox();
256 &Header::openbox('100%','left',$Lang::tr{'sound'});
257 print <<END
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>
263 <td colspan='2'></td>
264 </tr>
265 </table>
266 <div align='right'>
267 <br>
268 <table width='100%'>
269 <tr>
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>
272 </tr>
273 </table>
274 </div>
275 </form>
276 END
277 ;
278 &Header::closebox();
279 &Header::closebigbox();
280 &Header::closepage();
281
282
283