]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/gui.cgi
remote.cgi: Fix splitting output from ssh-keygen.
[people/pmueller/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 &General::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 &General::system('/usr/bin/touch', "${General::swroot}/red/nobeeps");
82 } else {
83 unlink "${General::swroot}/red/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{'REFRESHINDEX'} = $cgiparams{'REFRESHINDEX'};
92 &General::writehash("${General::swroot}/main/settings", \%mainsettings);
93 &Lang::reload($cgiparams{'lang'});
94 SAVE_ERROR:
95 } else {
96 if ($mainsettings{'WINDOWWITHHOSTNAME'}) {
97 $cgiparams{'WINDOWWITHHOSTNAME'} = $mainsettings{'WINDOWWITHHOSTNAME'};
98 } else {
99 $cgiparams{'WINDOWWITHHOSTNAME'} = 'on';
100 }
101
102 if ($mainsettings{'PPPUPDOWNBEEP'}) {
103 $cgiparams{'PPPUPDOWNBEEP'} = $mainsettings{'PPPUPDOWNBEEP'};
104 } else {
105 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
106 }
107
108 if($mainsettings{'REFRESHINDEX'}) {
109 $cgiparams{'REFRESHINDEX'} = $mainsettings{'REFRESHINDEX'};
110 } else {
111 $cgiparams{'REFRESHINDEX'} = 'off';
112 }
113 if($mainsettings{'SPEED'}) {
114 $cgiparams{'SPEED'} = $mainsettings{'SPEED'};
115 } else {
116 # if var is not defined it will be set to on because after installation var
117 # is not set and the speedmeter should be displayed, it can only be deactivated
118 # by manually setting the var to off
119 $cgiparams{'SPEED'} = 'on';
120 }
121 }
122
123 # Default settings
124 if ($cgiparams{'ACTION'} eq "$Lang::tr{'restore defaults'}")
125 {
126 $cgiparams{'WINDOWWITHHOSTNAME'} = 'on';
127 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
128 $cgiparams{'REFRESHINDEX'} = 'off';
129 $cgiparams{'SPEED'} = 'on';
130 }
131
132 $checked{'WINDOWWITHHOSTNAME'}{'off'} = '';
133 $checked{'WINDOWWITHHOSTNAME'}{'on'} = '';
134 $checked{'WINDOWWITHHOSTNAME'}{$cgiparams{'WINDOWWITHHOSTNAME'}} = "checked='checked'";
135
136 $checked{'PPPUPDOWNBEEP'}{'off'} = '';
137 $checked{'PPPUPDOWNBEEP'}{'on'} = '';
138 $checked{'PPPUPDOWNBEEP'}{$cgiparams{'PPPUPDOWNBEEP'}} = "checked='checked'";
139
140 $checked{'REFRESHINDEX'}{'off'} = '';
141 $checked{'REFRESHINDEX'}{'on'} = '';
142 $checked{'REFRESHINDEX'}{$cgiparams{'REFRESHINDEX'}} = "checked='checked'";
143
144 $checked{'SPEED'}{'off'} = '';
145 $checked{'SPEED'}{'on'} = '';
146 $checked{'SPEED'}{$cgiparams{'SPEED'}} = "checked='checked'";
147
148 &Header::openpage($Lang::tr{'gui settings'}, 1, '');
149 &Header::openbigbox('100%', 'left', '', $errormessage);
150
151 if ($errormessage) {
152 &Header::openbox('100%','left',$Lang::tr{'error messages'});
153 print "<font class='base'>${errormessage}&nbsp;</font>\n";
154 &Header::closebox();
155 }
156
157 &Header::openbox('100%','left',$Lang::tr{'display'});
158
159 print <<END
160 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
161 <table width='100%'>
162 <tr>
163 <td><input type='checkbox' name='WINDOWWITHHOSTNAME' $checked{'WINDOWWITHHOSTNAME'}{'on'} /></td>
164 <td>$Lang::tr{'display hostname in window title'}</td>
165 </tr>
166 <tr>
167 <td><input type='checkbox' name='REFRESHINDEX' $checked{'REFRESHINDEX'}{'on'} /></td>
168 <td>$Lang::tr{'refresh index page while connected'}</td>
169 </tr>
170 <tr>
171 <td><input type='checkbox' name='SPEED' $checked{'SPEED'}{'on'} /></td>
172 <td>$Lang::tr{'show ajax speedmeter in footer'}</td>
173 </tr>
174 <tr>
175 <td>&nbsp;</td>
176 <td>$Lang::tr{'languagepurpose'}</td>
177 </tr>
178 <tr>
179 <td>&nbsp;</td>
180 <td><select name='lang'>
181 END
182 ;
183
184 my $id=0;
185 open(FILE,"${General::swroot}/langs/list");
186 while (<FILE>)
187 {
188 my $lang='';
189 my $engname='';
190 my $natname='';
191 $id++;
192 chomp;
193 ($lang,$engname,$natname) = split (/:/, $_, 3);
194 print "<option value='$lang' ";
195 if ($lang =~ /$mainsettings{'LANGUAGE'}/)
196 {
197 print " selected='selected'";
198 }
199 print <<END
200 >$engname ($natname)</option>
201 END
202 ;
203 }
204
205 print <<END
206 </select></td></tr>
207 </table>
208 END
209 ;
210 &Header::closebox();
211 &Header::openbox('100%','left',$Lang::tr{'sound'});
212 print <<END
213 <tr>
214 <td><input type ='checkbox' name='PPPUPDOWNBEEP' $checked{'PPPUPDOWNBEEP'}{'on'} /></td>
215 <td>$Lang::tr{'beep when ppp connects or disconnects'}</td>
216 </tr>
217 <tr>
218 <td colspan='2'></td>
219 </tr>
220 </table>
221 <div align='right'>
222 <br>
223 <table width='100%'>
224 <tr>
225 <td width='90%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'restore defaults'}' /></td>
226 <td width='10%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
227 </tr>
228 </table>
229 </div>
230 </form>
231 END
232 ;
233 &Header::closebox();
234 &Header::closebigbox();
235 &Header::closepage();
236
237
238