Fixed language string on pakfire.cgi.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / pakfire.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 use strict;
23
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "/opt/pakfire/lib/functions.pl";
32
33 my %pakfiresettings=();
34 my $errormessage = '';
35 my %color = ();
36 my %mainsettings = ();
37
38 &Header::showhttpheaders();
39
40 $pakfiresettings{'ACTION'} = '';
41 $pakfiresettings{'VALID'} = '';
42
43 $pakfiresettings{'INSPAKS'} = '';
44 $pakfiresettings{'DELPAKS'} = '';
45 $pakfiresettings{'AUTOUPDATE'} = 'off';
46 $pakfiresettings{'AUTOUPGRADE'} = 'off';
47 $pakfiresettings{'HEALTHCHECK'} = 'on';
48 $pakfiresettings{'UUID'} = 'on';
49
50 sub refreshpage{&Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='1;'>" );print "<center><img src='/images/clock.gif' alt='' /><br/><font color='red'>$Lang::tr{'pagerefresh'}</font></center>";&Header::closebox();}
51
52 &Header::getcgihash(\%pakfiresettings);
53
54 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
55 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
56
57 &Header::openpage($Lang::tr{'pakfire configuration'}, 1);
58 &Header::openbigbox('100%', 'left', '', $errormessage);
59
60 # check if reboot is necessary
61 my $reboot = 0;
62 if (`find /var/run/need_reboot 2>/dev/null`) {
63 $reboot = 1;
64 }
65
66 if ($pakfiresettings{'ACTION'} eq 'install'){
67 $pakfiresettings{'INSPAKS'} =~ s/\|/\ /g;
68 if ("$pakfiresettings{'FORCE'}" eq "on") {
69 my $command = "/usr/local/bin/pakfire install --non-interactive --no-colors $pakfiresettings{'INSPAKS'} &>/dev/null &";
70 system("$command");
71 system("/bin/sleep 1");
72 } else {
73 &Header::openbox("100%", "center", $Lang::tr{'request'});
74 my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $pakfiresettings{'INSPAKS'}`;
75 print <<END;
76 <table><tr><td colspan='2'>$Lang::tr{'pakfire install package'}.$pakfiresettings{'INSPAKS'}.$Lang::tr{'pakfire possible dependency'}
77 <pre>
78 END
79 foreach (@output) {
80 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
81 print "$_\n";
82 }
83 print <<END;
84 </pre>
85 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
86 <tr><td colspan='2'>&nbsp;
87 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
88 <input type='hidden' name='INSPAKS' value='$pakfiresettings{'INSPAKS'}' />
89 <input type='hidden' name='FORCE' value='on' />
90 <input type='hidden' name='ACTION' value='install' />
91 <input type='image' alt='$Lang::tr{'install'}' src='/images/go-next.png' />
92 </form>
93 <td align='left'>
94 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
95 <input type='hidden' name='ACTION' value='' />
96 <input type='image' alt='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
97 </form>
98 </table>
99 END
100 &Header::closebox();
101 &Header::closebigbox();
102 &Header::closepage();
103 exit;
104 }
105 } elsif ($pakfiresettings{'ACTION'} eq 'remove') {
106
107 $pakfiresettings{'DELPAKS'} =~ s/\|/\ /g;
108 if ("$pakfiresettings{'FORCE'}" eq "on") {
109 my $command = "/usr/local/bin/pakfire remove --non-interactive --no-colors $pakfiresettings{'DELPAKS'} &>/dev/null &";
110 system("$command");
111 system("/bin/sleep 1");
112 } else {
113 &Header::openbox("100%", "center", $Lang::tr{'request'});
114 my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $pakfiresettings{'DELPAKS'}`;
115 print <<END;
116 <table><tr><td colspan='2'>$Lang::tr{'pakfire uninstall package'}.$pakfiresettings{'DELPAKS'}.$Lang::tr{'pakfire possible dependency'}
117 <pre>
118 END
119 foreach (@output) {
120 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
121 print "$_\n";
122 }
123 print <<END;
124 </pre>
125 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
126 <tr><td colspan='2'>&nbsp;
127 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
128 <input type='hidden' name='DELPAKS' value='$pakfiresettings{'DELPAKS'}' />
129 <input type='hidden' name='FORCE' value='on' />
130 <input type='hidden' name='ACTION' value='remove' />
131 <input type='image' alt='$Lang::tr{'uninstall'}' src='/images/go-next.png' />
132 </form>
133 <td align='left'>
134 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
135 <input type='hidden' name='ACTION' value='' />
136 <input type='image' alt='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
137 </form>
138 </table>
139 END
140 &Header::closebox();
141 &Header::closebigbox();
142 &Header::closepage();
143 exit;
144 }
145
146 } elsif ($pakfiresettings{'ACTION'} eq 'update') {
147
148 system("/usr/local/bin/pakfire update --force --no-colors &>/dev/null &");
149 system("/bin/sleep 1");
150 } elsif ($pakfiresettings{'ACTION'} eq 'upgrade') {
151 my $command = "/usr/local/bin/pakfire upgrade -y --no-colors &>/dev/null &";
152 system("$command");
153 system("/bin/sleep 1");
154 } elsif ($pakfiresettings{'ACTION'} eq "$Lang::tr{'save'}") {
155
156 if ($pakfiresettings{'AUTOUPDATE'} eq 'on') {
157 system("/usr/local/bin/pakfire enable updates >/dev/null 2>&1");
158 } else {
159 system("/usr/local/bin/pakfire disable updates >/dev/null 2>&1");
160 }
161
162 if ($pakfiresettings{'AUTOUPGRADE'} eq 'on') {
163 system("/usr/local/bin/pakfire enable upgrades >/dev/null 2>&1");
164 } else {
165 system("/usr/local/bin/pakfire disable upgrades >/dev/null 2>&1");
166 }
167
168 &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings);
169 }
170
171 &General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
172
173 my %selected=();
174 my %checked=();
175
176 $checked{'AUTOUPDATE'}{'off'} = '';
177 $checked{'AUTOUPDATE'}{'on'} = '';
178 $checked{'AUTOUPDATE'}{$pakfiresettings{'AUTOUPDATE'}} = "checked='checked'";
179 $checked{'AUTOUPGRADE'}{'off'} = '';
180 $checked{'AUTOUPGRADE'}{'on'} = '';
181 $checked{'AUTOUPGRADE'}{$pakfiresettings{'AUTOUPGRADE'}} = "checked='checked'";
182 $checked{'HEALTHCHECK'}{'off'} = '';
183 $checked{'HEALTHCHECK'}{'on'} = '';
184 $checked{'HEALTHCHECK'}{$pakfiresettings{'HEALTHCHECK'}} = "checked='checked'";
185 $checked{'UUID'}{'off'} = '';
186 $checked{'UUID'}{'on'} = '';
187 $checked{'UUID'}{$pakfiresettings{'UUID'}} = "checked='checked'";
188
189 # DPC move error message to top so it is seen!
190 if ($errormessage) {
191 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
192 print "<font class='base'>$errormessage&nbsp;</font>\n";
193 &Header::closebox();
194 }
195
196 my $return = `pidof pakfire`;
197 chomp($return);
198 if ($return) {
199 &Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='10;'>" );
200 print <<END;
201 <table>
202 <tr><td>
203 <img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' />&nbsp;
204 <td>
205 $Lang::tr{'pakfire working'}
206 <tr><td colspan='2' align='center'>
207 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
208 <input type='image' alt='$Lang::tr{'reload'}' src='/images/view-refresh.png' />
209 </form>
210 <tr><td colspan='2' align='left'><pre>
211 END
212 my @output = `grep pakfire /var/log/messages | tail -20`;
213 foreach (@output) {
214 print "$_";
215 }
216 print <<END;
217 </pre>
218 </table>
219 END
220 &Header::closebox();
221 &Header::closebigbox();
222 &Header::closepage();
223 exit;
224 refreshpage();
225 }
226
227 my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`;
228 chomp($core_release);
229 my $core_update_age = &General::age("/opt/pakfire/db/core/mine");
230 my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db");
231 my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db");
232 my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db");
233
234 &Header::openbox("100%", "center", "Pakfire");
235
236 print <<END;
237 <table width='95%' cellpadding='5' >
238 END
239 if ($reboot == 1) {
240 print "<tr><td align='center' colspan='2'><font color='red'>$Lang::tr{'needreboot'}!</font></td></tr>";
241 print "<tr><td colspan='2'>&nbsp;</font></td></tr>"
242 }
243 print <<END;
244 <tr><td width="50%" bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire system state'}:</b>
245 <td width="50%">
246 <tr><td align="center">$Lang::tr{'pakfire core update level'}: $core_release<hr />
247 $Lang::tr{'pakfire last update'} $core_update_age $Lang::tr{'pakfire ago'}<br />
248 $Lang::tr{'pakfire last serverlist update'} $server_update_age $Lang::tr{'pakfire ago'}<br />
249 $Lang::tr{'pakfire last core list update'} $corelist_update_age $Lang::tr{'pakfire ago'}<br />
250 $Lang::tr{'pakfire last package update'} $packages_update_age $Lang::tr{'pakfire ago'}
251 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
252 <input type='hidden' name='ACTION' value='update' />
253 <input type='submit' value='$Lang::tr{'calamaris refresh list'}' /><br />
254 </form>
255 <td align="center">
256 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
257 <select name="UPDPAKS" size="5" disabled>
258 END
259 &Pakfire::dblist("upgrade", "forweb");
260 print <<END;
261 </select>
262 <br />
263 <input type='hidden' name='ACTION' value='upgrade' />
264 <input type='image' alt='$Lang::tr{'upgrade'}' src='/images/document-save.png' />
265 </form>
266
267 <tr><td colspan="2"><!-- Just an empty line -->&nbsp;
268 <tr><td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire available addons'}</b>
269 <td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire installed addons'}</b>
270 <tr><td align="center">
271 <p>$Lang::tr{'pakfire install description'}</p>
272 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
273 <select name="INSPAKS" size="10" multiple>
274 END
275 &Pakfire::dblist("notinstalled", "forweb");
276
277 print <<END;
278 </select>
279 <br />
280 <input type='hidden' name='ACTION' value='install' />
281 <input type='image' alt='$Lang::tr{'install'}' src='/images/list-add.png' />
282 </form>
283
284 <td align="center">
285 <p>$Lang::tr{'pakfire uninstall description'}</p>
286 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
287 <select name="DELPAKS" size="10" multiple>
288 END
289
290 &Pakfire::dblist("installed", "forweb");
291
292 print <<END;
293 </select>
294 <br />
295 <input type='hidden' name='ACTION' value='remove' />
296 <input type='image' alt='$Lang::tr{'remove'}' src='/images/list-remove.png' />
297 </form>
298 </table>
299 END
300
301 &Header::closebox();
302 &Header::openbox("100%", "center", "$Lang::tr{'settings'}");
303
304 print <<END;
305 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
306 <table width='95%'>
307 <tr><td colspan='2' bgcolor='$color{'color20'}'><b>$Lang::tr{'basic options'}</b></td></tr>
308 <tr><td align='left' width='45%'>$Lang::tr{'pakfire update daily'}</td><td width="55%" align="left">
309 on <input type='radio' name='AUTOUPDATE' value='on' $checked{'AUTOUPDATE'}{'on'} /> |
310 <input type='radio' name='AUTOUPDATE' value='off' $checked{'AUTOUPDATE'}{'off'} /> off </td></tr>
311 <tr><td align='left' width='45%'>$Lang::tr{'pakfire core update auto'}</td><td align="left">
312 on <input type='radio' name='AUTOUPGRADE' value='on' $checked{'AUTOUPGRADE'}{'on'} /> |
313 <input type='radio' name='AUTOUPGRADE' value='off' $checked{'AUTOUPGRADE'}{'off'} /> off </td></tr>
314 <tr><td align='left' width='45%'>$Lang::tr{'pakfire health check'}</td><td align="left">
315 on <input type='radio' name='HEALTHCHECK' value='on' $checked{'HEALTHCHECK'}{'on'} /> |
316 <input type='radio' name='HEALTHCHECK' value='off' $checked{'HEALTHCHECK'}{'off'} /> off </td></tr>
317 <tr><td align='left' width='45%'>$Lang::tr{'pakfire register'}</td><td align="left">
318 on <input type='radio' name='UUID' value='on' $checked{'UUID'}{'on'} /> |
319 <input type='radio' name='UUID' value='off' $checked{'UUID'}{'off'} /> off </td></tr>
320 <tr><td colspan="2" align="center"><input type="submit" name="ACTION" value="$Lang::tr{'save'}" /></td></tr>
321 </table>
322 </form>
323 END
324
325 &Header::closebox();
326 &Header::closebigbox();
327 &Header::closepage();