GeƤndert:
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / gui.cgi
1 #!/usr/bin/perl
2 #
3 # IPFire CGIs
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
12 use strict;
13
14 # enable only the following on debugging purpose
15 #use warnings;
16 #use CGI::Carp 'fatalsToBrowser';
17
18 require '/var/ipfire/general-functions.pl';
19 require "${General::swroot}/lang.pl";
20 require "${General::swroot}/header.pl";
21
22 my %cgiparams=();
23 my %mainsettings=();
24 my %checked=();
25 my $errormessage='';
26
27
28 $cgiparams{'FX'} = 'off';
29 $cgiparams{'WINDOWWITHHOSTNAME'} = 'off';
30 $cgiparams{'REFRESHINDEX'} = 'off';
31 $cgiparams{'ACTION'} = '';
32 &Header::getcgihash(\%cgiparams);
33
34 &Header::showhttpheaders();
35 &General::readhash("${General::swroot}/main/settings",\%mainsettings);
36 if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}")
37 {
38 open(FILE,"${General::swroot}/langs/list");
39 my $found=0;
40 while (<FILE>)
41 {
42 my $lang='';
43 my $engname='';
44 my $natname='';
45 chomp;
46 ($lang,$engname,$natname) = split (/:/, $_,3);
47 if ($cgiparams{'lang'} eq $lang)
48 {
49 $found=1;
50 }
51 }
52 close (FILE);
53 if ( $found == 0 )
54 {
55 $errormessage="$errormessage<P>$Lang::tr{'invalid input'}";
56 goto SAVE_ERROR;
57 }
58
59 # Set flag if index page is to refresh whilst ppp is up.
60 # Default is NO refresh.
61 if ($cgiparams{'REFRESHINDEX'} ne 'off') {
62 system ('/bin/touch', "${General::swroot}/main/refreshindex");
63 } else {
64 unlink "${General::swroot}/main/refreshindex";
65 }
66
67 # Beep on ip-up or ip-down. Default is ON.
68 if ($cgiparams{'PPPUPDOWNBEEP'} ne 'on') {
69 $cgiparams{'PPPUPDOWNBEEP'} = 'off';
70 system ('/bin/touch', "${General::swroot}/ppp/nobeeps");
71 } else {
72 unlink "${General::swroot}/ppp/nobeeps";
73 }
74
75 # write cgi vars to the file.
76 $mainsettings{'LANGUAGE'} = $cgiparams{'lang'};
77 $mainsettings{'WINDOWWITHHOSTNAME'} = $cgiparams{'WINDOWWITHHOSTNAME'};
78 $mainsettings{'PPPUPDOWNBEEP'} = $cgiparams{'PPPUPDOWNBEEP'};
79 $mainsettings{'FX'} = $cgiparams{'FX'};
80 $mainsettings{'REFRESHINDEX'} = $cgiparams{'REFRESHINDEX'};
81 &General::writehash("${General::swroot}/main/settings", \%mainsettings);
82 &Lang::reload($cgiparams{'lang'});
83 SAVE_ERROR:
84 } else {
85 if ($mainsettings{'WINDOWWITHHOSTNAME'}) {
86 $cgiparams{'WINDOWWITHHOSTNAME'} = $mainsettings{'WINDOWWITHHOSTNAME'};
87 } else {
88 $cgiparams{'WINDOWWITHHOSTNAME'} = 'off';
89 }
90
91 if ($mainsettings{'PPPUPDOWNBEEP'}) {
92 $cgiparams{'PPPUPDOWNBEEP'} = $mainsettings{'PPPUPDOWNBEEP'};
93 } else {
94 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
95 }
96
97 if ($mainsettings{'FX'}) {
98 $cgiparams{'FX'} = $mainsettings{'FX'};
99 } else {
100 $cgiparams{'FX'} = 'on';
101 }
102
103 if($mainsettings{'REFRESHINDEX'}) {
104 $cgiparams{'REFRESHINDEX'} = $mainsettings{'REFRESHINDEX'};
105 } else {
106 $cgiparams{'REFRESHINDEX'} = 'off';
107 }
108 }
109
110 # Default settings
111 if ($cgiparams{'ACTION'} eq "$Lang::tr{'restore defaults'}")
112 {
113 $cgiparams{'WINDOWWITHHOSTNAME'} = 'off';
114 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
115 $cgiparams{'REFRESHINDEX'} = 'off';
116 $cgiparams{'FX'} = 'on';
117 }
118
119 $checked{'WINDOWWITHHOSTNAME'}{'off'} = '';
120 $checked{'WINDOWWITHHOSTNAME'}{'on'} = '';
121 $checked{'WINDOWWITHHOSTNAME'}{$cgiparams{'WINDOWWITHHOSTNAME'}} = "checked='checked'";
122
123 $checked{'PPPUPDOWNBEEP'}{'off'} = '';
124 $checked{'PPPUPDOWNBEEP'}{'on'} = '';
125 $checked{'PPPUPDOWNBEEP'}{$cgiparams{'PPPUPDOWNBEEP'}} = "checked='checked'";
126
127 $checked{'REFRESHINDEX'}{'off'} = '';
128 $checked{'REFRESHINDEX'}{'on'} = '';
129 $checked{'REFRESHINDEX'}{$cgiparams{'REFRESHINDEX'}} = "checked='checked'";
130
131 $checked{'FX'}{'off'} = '';
132 $checked{'FX'}{'on'} = '';
133 $checked{'FX'}{$cgiparams{'FX'}} = "checked='checked'";
134
135 &Header::openpage($Lang::tr{'gui settings'}, 1, '');
136 &Header::openbigbox('100%', 'left', '', $errormessage);
137
138 if ($errormessage) {
139 &Header::openbox('100%','left',$Lang::tr{'error messages'});
140 print "<font class='base'>${errormessage}&nbsp;</font>\n";
141 &Header::closebox();
142 }
143
144 &Header::openbox('100%','left',$Lang::tr{'gui settings'});
145
146 print <<END
147 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
148 <table width='100%'>
149 <tr>
150 <td colspan='2'><p><b>$Lang::tr{'display'}</b></td>
151 </tr>
152 <tr>
153 <td><input type='checkbox' name='FX' $checked{'FX'}{'on'} /></td>
154 <td>$Lang::tr{'display webinterface effects'}</td>
155 </tr>
156 <tr>
157 <td><input type='checkbox' name='WINDOWWITHHOSTNAME' $checked{'WINDOWWITHHOSTNAME'}{'on'} /></td>
158 <td>$Lang::tr{'display hostname in window title'}</td>
159 </tr>
160 <tr>
161 <td><input type='checkbox' name='REFRESHINDEX' $checked{'REFRESHINDEX'}{'on'} /></td>
162 <td>$Lang::tr{'refresh index page while connected'}</td>
163 </tr>
164 <tr>
165 <td>&nbsp;</td>
166 <td>$Lang::tr{'languagepurpose'}</td>
167 </tr>
168 <tr>
169 <td>&nbsp;</td>
170 <td><select name='lang'>
171 END
172 ;
173
174 my $id=0;
175 open(FILE,"${General::swroot}/langs/list");
176 while (<FILE>)
177 {
178 my $lang='';
179 my $engname='';
180 my $natname='';
181 $id++;
182 chomp;
183 ($lang,$engname,$natname) = split (/:/, $_, 3);
184 print "<option value='$lang' ";
185 if ($lang =~ /$mainsettings{'LANGUAGE'}/)
186 {
187 print " selected='selected'";
188 }
189 print <<END
190 >$engname ($natname)</option>
191 END
192 ;
193 }
194
195 print <<END
196 </select></td></tr>
197 <tr>
198 <td colspan='2'><hr /><p><b>$Lang::tr{'sound'}</b></td>
199 </tr>
200 <tr>
201 <td><input type ='checkbox' name='PPPUPDOWNBEEP' $checked{'PPPUPDOWNBEEP'}{'on'} /></td>
202 <td>$Lang::tr{'beep when ppp connects or disconnects'}</td>
203 </tr>
204 <tr>
205 <td colspan='2'><hr /></td>
206 </tr>
207 </table>
208 <div align='center'>
209 <table width='80%'>
210 <tr>
211 <td width='50%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'restore defaults'}' /></td>
212 <td width='50%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
213 </tr>
214 </table>
215 </div>
216 </form>
217 END
218 ;
219 &Header::closebox();
220 &Header::closebigbox();
221 &Header::closepage();
222
223
224