6d7c1010e739c7413e62798d7f052eecc867c174
[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{'JAVASCRIPT'} = '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{'REFRESHINDEX'} = $cgiparams{'REFRESHINDEX'};
80 &General::writehash("${General::swroot}/main/settings", \%mainsettings);
81 &Lang::reload($cgiparams{'lang'});
82 SAVE_ERROR:
83 } else {
84 if ($mainsettings{'WINDOWWITHHOSTNAME'}) {
85 $cgiparams{'WINDOWWITHHOSTNAME'} = $mainsettings{'WINDOWWITHHOSTNAME'};
86 } else {
87 $cgiparams{'WINDOWWITHHOSTNAME'} = 'off';
88 }
89
90 if ($mainsettings{'PPPUPDOWNBEEP'}) {
91 $cgiparams{'PPPUPDOWNBEEP'} = $mainsettings{'PPPUPDOWNBEEP'};
92 } else {
93 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
94 }
95
96 if($mainsettings{'REFRESHINDEX'}) {
97 $cgiparams{'REFRESHINDEX'} = $mainsettings{'REFRESHINDEX'};
98 } else {
99 $cgiparams{'REFRESHINDEX'} = 'off';
100 }
101 }
102
103 # Default settings
104 if ($cgiparams{'ACTION'} eq "$Lang::tr{'restore defaults'}")
105 {
106 $cgiparams{'WINDOWWITHHOSTNAME'} = 'off';
107 $cgiparams{'PPPUPDOWNBEEP'} = 'on';
108 $cgiparams{'REFRESHINDEX'} = 'off';
109 }
110
111 $checked{'WINDOWWITHHOSTNAME'}{'off'} = '';
112 $checked{'WINDOWWITHHOSTNAME'}{'on'} = '';
113 $checked{'WINDOWWITHHOSTNAME'}{$cgiparams{'WINDOWWITHHOSTNAME'}} = "checked='checked'";
114
115 $checked{'PPPUPDOWNBEEP'}{'off'} = '';
116 $checked{'PPPUPDOWNBEEP'}{'on'} = '';
117 $checked{'PPPUPDOWNBEEP'}{$cgiparams{'PPPUPDOWNBEEP'}} = "checked='checked'";
118
119 $checked{'REFRESHINDEX'}{'off'} = '';
120 $checked{'REFRESHINDEX'}{'on'} = '';
121 $checked{'REFRESHINDEX'}{$cgiparams{'REFRESHINDEX'}} = "checked='checked'";
122
123 &Header::openpage($Lang::tr{'gui settings'}, 1, '');
124 &Header::openbigbox('100%', 'left', '', $errormessage);
125
126 if ($errormessage) {
127 &Header::openbox('100%','left',$Lang::tr{'error messages'});
128 print "<font class='base'>${errormessage}&nbsp;</font>\n";
129 &Header::closebox();
130 }
131
132 &Header::openbox('100%','left',$Lang::tr{'gui settings'});
133
134 print <<END
135 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
136 <table width='100%'>
137 <tr>
138 <td colspan='2'><p><b>$Lang::tr{'display'}</b></td>
139 </tr>
140 <tr>
141 <td><input type='checkbox' name='WINDOWWITHHOSTNAME' $checked{'WINDOWWITHHOSTNAME'}{'on'} /></td>
142 <td>$Lang::tr{'display hostname in window title'}</td>
143 </tr>
144 <tr>
145 <td><input type='checkbox' name='REFRESHINDEX' $checked{'REFRESHINDEX'}{'on'} /></td>
146 <td>$Lang::tr{'refresh index page while connected'}</td>
147 </tr>
148 <tr>
149 <td>&nbsp;</td>
150 <td>$Lang::tr{'languagepurpose'}</td>
151 </tr>
152 <tr>
153 <td>&nbsp;</td>
154 <td><select name='lang'>
155 END
156 ;
157
158 my $id=0;
159 open(FILE,"${General::swroot}/langs/list");
160 while (<FILE>)
161 {
162 my $lang='';
163 my $engname='';
164 my $natname='';
165 $id++;
166 chomp;
167 ($lang,$engname,$natname) = split (/:/, $_, 3);
168 print "<option value='$lang' ";
169 if ($lang =~ /$mainsettings{'LANGUAGE'}/)
170 {
171 print " selected='selected'";
172 }
173 print <<END
174 >$engname ($natname)</option>
175 END
176 ;
177 }
178
179 print <<END
180 </select></td></tr>
181 <tr>
182 <td colspan='2'><hr /><p><b>$Lang::tr{'sound'}</b></td>
183 </tr>
184 <tr>
185 <td><input type ='checkbox' name='PPPUPDOWNBEEP' $checked{'PPPUPDOWNBEEP'}{'on'} /></td>
186 <td>$Lang::tr{'beep when ppp connects or disconnects'}</td>
187 </tr>
188 <tr>
189 <td colspan='2'><hr /></td>
190 </tr>
191 </table>
192 <div align='center'>
193 <table width='80%'>
194 <tr>
195 <td width='50%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'restore defaults'}' /></td>
196 <td width='50%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
197 </tr>
198 </table>
199 </div>
200 </form>
201 END
202 ;
203 &Header::closebox();
204 &Header::closebigbox();
205 &Header::closepage();
206
207
208