Fixed language string on pakfire.cgi.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / pakfire.cgi
CommitLineData
3ea75603 1#!/usr/bin/perl
70df8302
MT
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###############################################################################
3ea75603
MT
21
22use strict;
23
24# enable only the following on debugging purpose
cb5e9c6c
CS
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
3ea75603 27
986e08d9 28require '/var/ipfire/general-functions.pl';
3ea75603
MT
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
1bd42c89 31require "/opt/pakfire/lib/functions.pl";
3ea75603
MT
32
33my %pakfiresettings=();
34my $errormessage = '';
cb5e9c6c
CS
35my %color = ();
36my %mainsettings = ();
3ea75603
MT
37
38&Header::showhttpheaders();
39
40$pakfiresettings{'ACTION'} = '';
41$pakfiresettings{'VALID'} = '';
42
1bd42c89
MT
43$pakfiresettings{'INSPAKS'} = '';
44$pakfiresettings{'DELPAKS'} = '';
99e6df8e 45$pakfiresettings{'AUTOUPDATE'} = 'off';
377560fb 46$pakfiresettings{'AUTOUPGRADE'} = 'off';
d59b02f1 47$pakfiresettings{'HEALTHCHECK'} = 'on';
99e6df8e 48$pakfiresettings{'UUID'} = 'on';
3ea75603 49
5595bc03
CS
50sub 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
3ea75603 52&Header::getcgihash(\%pakfiresettings);
d40aff35 53
cb5e9c6c
CS
54&General::readhash("${General::swroot}/main/settings", \%mainsettings);
55&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
3ea75603 56
1bd42c89
MT
57&Header::openpage($Lang::tr{'pakfire configuration'}, 1);
58&Header::openbigbox('100%', 'left', '', $errormessage);
3ea75603 59
337305ef
JPT
60# check if reboot is necessary
61my $reboot = 0;
62if (`find /var/run/need_reboot 2>/dev/null`) {
63 $reboot = 1;
64}
65
957363eb 66if ($pakfiresettings{'ACTION'} eq 'install'){
908a3eb7 67 $pakfiresettings{'INSPAKS'} =~ s/\|/\ /g;
5b2a12ff 68 if ("$pakfiresettings{'FORCE'}" eq "on") {
750c1528 69 my $command = "/usr/local/bin/pakfire install --non-interactive --no-colors $pakfiresettings{'INSPAKS'} &>/dev/null &";
908a3eb7 70 system("$command");
25dea62a 71 system("/bin/sleep 1");
5b2a12ff 72 } else {
40228ef4 73 &Header::openbox("100%", "center", $Lang::tr{'request'});
74693811 74 my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $pakfiresettings{'INSPAKS'}`;
5b2a12ff 75 print <<END;
bac7231b 76 <table><tr><td colspan='2'>$Lang::tr{'pakfire install package'}.$pakfiresettings{'INSPAKS'}.$Lang::tr{'pakfire possible dependency'}
fee5c6b7 77 <pre>
5b2a12ff
MT
78END
79 foreach (@output) {
fee5c6b7 80 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
5b2a12ff
MT
81 print "$_\n";
82 }
83 print <<END;
84 </pre>
bac7231b 85 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
5b2a12ff
MT
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>
99END
100 &Header::closebox();
101 &Header::closebigbox();
102 &Header::closepage();
103 exit;
104 }
105} elsif ($pakfiresettings{'ACTION'} eq 'remove') {
106
74693811
CS
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");
25dea62a 111 system("/bin/sleep 1");
74693811 112 } else {
40228ef4 113 &Header::openbox("100%", "center", $Lang::tr{'request'});
74693811
CS
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'}
fee5c6b7 117 <pre>
74693811
CS
118END
119 foreach (@output) {
fee5c6b7 120 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
74693811
CS
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>
139END
140 &Header::closebox();
141 &Header::closebigbox();
142 &Header::closepage();
143 exit;
144 }
145
5b2a12ff 146} elsif ($pakfiresettings{'ACTION'} eq 'update') {
fee5c6b7 147
28593a79 148 system("/usr/local/bin/pakfire update --force --no-colors &>/dev/null &");
25dea62a 149 system("/bin/sleep 1");
186e3d2c 150} elsif ($pakfiresettings{'ACTION'} eq 'upgrade') {
28593a79 151 my $command = "/usr/local/bin/pakfire upgrade -y --no-colors &>/dev/null &";
c506cad0 152 system("$command");
25dea62a 153 system("/bin/sleep 1");
5b2a12ff
MT
154} elsif ($pakfiresettings{'ACTION'} eq "$Lang::tr{'save'}") {
155
d2414ee7 156 if ($pakfiresettings{'AUTOUPDATE'} eq 'on') {
91a08eac 157 system("/usr/local/bin/pakfire enable updates >/dev/null 2>&1");
377560fb 158 } else {
91a08eac 159 system("/usr/local/bin/pakfire disable updates >/dev/null 2>&1");
377560fb 160 }
fee5c6b7 161
d2414ee7 162 if ($pakfiresettings{'AUTOUPGRADE'} eq 'on') {
91a08eac 163 system("/usr/local/bin/pakfire enable upgrades >/dev/null 2>&1");
377560fb 164 } else {
91a08eac 165 system("/usr/local/bin/pakfire disable upgrades >/dev/null 2>&1");
377560fb 166 }
4b122800 167
377560fb 168 &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings);
3ea75603
MT
169}
170
171&General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
172
3ea75603
MT
173my %selected=();
174my %checked=();
175
1bd42c89
MT
176$checked{'AUTOUPDATE'}{'off'} = '';
177$checked{'AUTOUPDATE'}{'on'} = '';
178$checked{'AUTOUPDATE'}{$pakfiresettings{'AUTOUPDATE'}} = "checked='checked'";
377560fb
MT
179$checked{'AUTOUPGRADE'}{'off'} = '';
180$checked{'AUTOUPGRADE'}{'on'} = '';
181$checked{'AUTOUPGRADE'}{$pakfiresettings{'AUTOUPGRADE'}} = "checked='checked'";
d59b02f1
CS
182$checked{'HEALTHCHECK'}{'off'} = '';
183$checked{'HEALTHCHECK'}{'on'} = '';
184$checked{'HEALTHCHECK'}{$pakfiresettings{'HEALTHCHECK'}} = "checked='checked'";
4b122800
MT
185$checked{'UUID'}{'off'} = '';
186$checked{'UUID'}{'on'} = '';
187$checked{'UUID'}{$pakfiresettings{'UUID'}} = "checked='checked'";
3ea75603
MT
188
189# DPC move error message to top so it is seen!
190if ($errormessage) {
191 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
192 print "<font class='base'>$errormessage&nbsp;</font>\n";
193 &Header::closebox();
5b2a12ff
MT
194}
195
186e3d2c
MT
196my $return = `pidof pakfire`;
197chomp($return);
198if ($return) {
ca4c317c 199 &Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='10;'>" );
5b2a12ff
MT
200 print <<END;
201 <table>
202 <tr><td>
186e3d2c 203 <img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' />&nbsp;
5b2a12ff 204 <td>
bac7231b 205 $Lang::tr{'pakfire working'}
5b2a12ff
MT
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>
186e3d2c
MT
210 <tr><td colspan='2' align='left'><pre>
211END
28593a79 212 my @output = `grep pakfire /var/log/messages | tail -20`;
750c1528
MT
213 foreach (@output) {
214 print "$_";
215 }
216 print <<END;
217 </pre>
218 </table>
5b2a12ff
MT
219END
220 &Header::closebox();
221 &Header::closebigbox();
222 &Header::closepage();
223 exit;
28593a79 224 refreshpage();
5b2a12ff 225}
3ea75603 226
91a08eac 227my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`;
377560fb
MT
228chomp($core_release);
229my $core_update_age = &General::age("/opt/pakfire/db/core/mine");
230my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db");
231my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db");
232my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db");
233
1bd42c89
MT
234&Header::openbox("100%", "center", "Pakfire");
235
236print <<END;
d40aff35 237 <table width='95%' cellpadding='5' >
337305ef
JPT
238END
239if ($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}
243print <<END;
c5d106c1 244 <tr><td width="50%" bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire system state'}:</b>
377560fb 245 <td width="50%">
c5d106c1 246 <tr><td align="center">$Lang::tr{'pakfire core update level'}: $core_release<hr />
1e908471
JPT
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'}
377560fb
MT
251 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
252 <input type='hidden' name='ACTION' value='update' />
1dd22be2 253 <input type='submit' value='$Lang::tr{'calamaris refresh list'}' /><br />
377560fb
MT
254 </form>
255 <td align="center">
256 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
257 <select name="UPDPAKS" size="5" disabled>
258END
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>
fee5c6b7 266
377560fb
MT
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">
5d22ef4e 271 <p>$Lang::tr{'pakfire install description'}</p>
fee5c6b7 272 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1bd42c89
MT
273 <select name="INSPAKS" size="10" multiple>
274END
275 &Pakfire::dblist("notinstalled", "forweb");
fee5c6b7 276
1bd42c89
MT
277print <<END;
278 </select>
377560fb 279 <br />
1bd42c89
MT
280 <input type='hidden' name='ACTION' value='install' />
281 <input type='image' alt='$Lang::tr{'install'}' src='/images/list-add.png' />
1bd42c89 282 </form>
377560fb
MT
283
284 <td align="center">
5d22ef4e 285 <p>$Lang::tr{'pakfire uninstall description'}</p>
377560fb 286 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1bd42c89 287 <select name="DELPAKS" size="10" multiple>
957363eb 288END
5b2a12ff
MT
289
290 &Pakfire::dblist("installed", "forweb");
291
292print <<END;
377560fb
MT
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>
4b122800
MT
299END
300
377560fb
MT
301&Header::closebox();
302&Header::openbox("100%", "center", "$Lang::tr{'settings'}");
4b122800
MT
303
304print <<END;
1bd42c89 305 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
d40aff35
CS
306 <table width='95%'>
307 <tr><td colspan='2' bgcolor='$color{'color20'}'><b>$Lang::tr{'basic options'}</b></td></tr>
c6614883
JPT
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'} /> |
d40aff35 310 <input type='radio' name='AUTOUPDATE' value='off' $checked{'AUTOUPDATE'}{'off'} /> off </td></tr>
c6614883
JPT
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'} /> |
d40aff35 313 <input type='radio' name='AUTOUPGRADE' value='off' $checked{'AUTOUPGRADE'}{'off'} /> off </td></tr>
d59b02f1
CS
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>
c6614883
JPT
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'} /> |
d40aff35 319 <input type='radio' name='UUID' value='off' $checked{'UUID'}{'off'} /> off </td></tr>
c6614883 320 <tr><td colspan="2" align="center"><input type="submit" name="ACTION" value="$Lang::tr{'save'}" /></td></tr>
1bd42c89
MT
321 </table>
322 </form>
323END
324
3ea75603 325&Header::closebox();
3ea75603 326&Header::closebigbox();
3ea75603 327&Header::closepage();