]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/pakfire.cgi
pakfire.cgi: Rename %pakfiresettings to %cgiparams
[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 #
324bb888 5# Copyright (C) 2007-2011 Michael Tremer & Christian Schmidt #
70df8302
MT
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 32
131f163c 33my %cgiparams=();
3ea75603 34my $errormessage = '';
cb5e9c6c 35my %color = ();
131f163c 36my %pakfiresettings = ();
cb5e9c6c 37my %mainsettings = ();
3ea75603
MT
38
39&Header::showhttpheaders();
40
131f163c
MT
41$cgiparams{'ACTION'} = '';
42$cgiparams{'VALID'} = '';
3ea75603 43
131f163c
MT
44$cgiparams{'INSPAKS'} = '';
45$cgiparams{'DELPAKS'} = '';
3ea75603 46
5595bc03
CS
47sub 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();}
48
131f163c 49&Header::getcgihash(\%cgiparams);
d40aff35 50
cb5e9c6c
CS
51&General::readhash("${General::swroot}/main/settings", \%mainsettings);
52&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
3ea75603 53
1bd42c89
MT
54&Header::openpage($Lang::tr{'pakfire configuration'}, 1);
55&Header::openbigbox('100%', 'left', '', $errormessage);
3ea75603 56
131f163c
MT
57if ($cgiparams{'ACTION'} eq 'install'){
58 $cgiparams{'INSPAKS'} =~ s/\|/\ /g;
59 if ("$cgiparams{'FORCE'}" eq "on") {
60 my $command = "/usr/local/bin/pakfire install --non-interactive --no-colors $cgiparams{'INSPAKS'} &>/dev/null &";
908a3eb7 61 system("$command");
25dea62a 62 system("/bin/sleep 1");
5b2a12ff 63 } else {
40228ef4 64 &Header::openbox("100%", "center", $Lang::tr{'request'});
131f163c 65 my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $cgiparams{'INSPAKS'}`;
5b2a12ff 66 print <<END;
131f163c 67 <table><tr><td colspan='2'>$Lang::tr{'pakfire install package'}.$cgiparams{'INSPAKS'}.$Lang::tr{'pakfire possible dependency'}
fee5c6b7 68 <pre>
5b2a12ff
MT
69END
70 foreach (@output) {
fee5c6b7 71 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
5b2a12ff
MT
72 print "$_\n";
73 }
74 print <<END;
75 </pre>
bac7231b 76 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
5b2a12ff
MT
77 <tr><td colspan='2'>&nbsp;
78 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
131f163c 79 <input type='hidden' name='INSPAKS' value='$cgiparams{'INSPAKS'}' />
5b2a12ff
MT
80 <input type='hidden' name='FORCE' value='on' />
81 <input type='hidden' name='ACTION' value='install' />
f8aa0679 82 <input type='image' alt='$Lang::tr{'install'}' title='$Lang::tr{'install'}' src='/images/go-next.png' />
5b2a12ff
MT
83 </form>
84 <td align='left'>
85 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
86 <input type='hidden' name='ACTION' value='' />
f8aa0679 87 <input type='image' alt='$Lang::tr{'abort'}' title='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
5b2a12ff
MT
88 </form>
89 </table>
90END
91 &Header::closebox();
92 &Header::closebigbox();
93 &Header::closepage();
94 exit;
95 }
131f163c 96} elsif ($cgiparams{'ACTION'} eq 'remove') {
5b2a12ff 97
131f163c
MT
98 $cgiparams{'DELPAKS'} =~ s/\|/\ /g;
99 if ("$cgiparams{'FORCE'}" eq "on") {
100 my $command = "/usr/local/bin/pakfire remove --non-interactive --no-colors $cgiparams{'DELPAKS'} &>/dev/null &";
74693811 101 system("$command");
25dea62a 102 system("/bin/sleep 1");
74693811 103 } else {
40228ef4 104 &Header::openbox("100%", "center", $Lang::tr{'request'});
131f163c 105 my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $cgiparams{'DELPAKS'}`;
74693811 106 print <<END;
131f163c 107 <table><tr><td colspan='2'>$Lang::tr{'pakfire uninstall package'}.$cgiparams{'DELPAKS'}.$Lang::tr{'pakfire possible dependency'}
fee5c6b7 108 <pre>
74693811
CS
109END
110 foreach (@output) {
fee5c6b7 111 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
74693811
CS
112 print "$_\n";
113 }
114 print <<END;
115 </pre>
116 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
117 <tr><td colspan='2'>&nbsp;
118 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
131f163c 119 <input type='hidden' name='DELPAKS' value='$cgiparams{'DELPAKS'}' />
74693811
CS
120 <input type='hidden' name='FORCE' value='on' />
121 <input type='hidden' name='ACTION' value='remove' />
f8aa0679 122 <input type='image' alt='$Lang::tr{'uninstall'}' title='$Lang::tr{'uninstall'}' src='/images/go-next.png' />
74693811
CS
123 </form>
124 <td align='left'>
125 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
126 <input type='hidden' name='ACTION' value='' />
f8aa0679 127 <input type='image' alt='$Lang::tr{'abort'}' title='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
74693811
CS
128 </form>
129 </table>
130END
131 &Header::closebox();
132 &Header::closebigbox();
133 &Header::closepage();
134 exit;
135 }
136
131f163c 137} elsif ($cgiparams{'ACTION'} eq 'update') {
fee5c6b7 138
28593a79 139 system("/usr/local/bin/pakfire update --force --no-colors &>/dev/null &");
25dea62a 140 system("/bin/sleep 1");
131f163c 141} elsif ($cgiparams{'ACTION'} eq 'upgrade') {
28593a79 142 my $command = "/usr/local/bin/pakfire upgrade -y --no-colors &>/dev/null &";
c506cad0 143 system("$command");
25dea62a 144 system("/bin/sleep 1");
131f163c 145} elsif ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}") {
377560fb 146 &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings);
3ea75603
MT
147}
148
149&General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
150
3ea75603
MT
151my %selected=();
152my %checked=();
153
3ea75603
MT
154# DPC move error message to top so it is seen!
155if ($errormessage) {
156 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
157 print "<font class='base'>$errormessage&nbsp;</font>\n";
158 &Header::closebox();
5b2a12ff
MT
159}
160
186e3d2c
MT
161my $return = `pidof pakfire`;
162chomp($return);
163if ($return) {
ca4c317c 164 &Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='10;'>" );
5b2a12ff
MT
165 print <<END;
166 <table>
167 <tr><td>
f8aa0679 168 <img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' title='$Lang::tr{'aktiv'}' />&nbsp;
5b2a12ff 169 <td>
bac7231b 170 $Lang::tr{'pakfire working'}
5b2a12ff
MT
171 <tr><td colspan='2' align='center'>
172 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
f8aa0679 173 <input type='image' alt='$Lang::tr{'reload'}' title='$Lang::tr{'reload'}' src='/images/view-refresh.png' />
5b2a12ff 174 </form>
212fd689 175 <tr><td colspan='2' align='left'><code>
186e3d2c 176END
28593a79 177 my @output = `grep pakfire /var/log/messages | tail -20`;
750c1528 178 foreach (@output) {
212fd689 179 print "$_<br>";
750c1528
MT
180 }
181 print <<END;
212fd689 182 </code>
750c1528 183 </table>
5b2a12ff
MT
184END
185 &Header::closebox();
186 &Header::closebigbox();
187 &Header::closepage();
188 exit;
28593a79 189 refreshpage();
5b2a12ff 190}
3ea75603 191
91a08eac 192my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`;
377560fb
MT
193chomp($core_release);
194my $core_update_age = &General::age("/opt/pakfire/db/core/mine");
195my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db");
196my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db");
197my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db");
198
1bd42c89
MT
199&Header::openbox("100%", "center", "Pakfire");
200
201print <<END;
d40aff35 202 <table width='95%' cellpadding='5' >
337305ef 203END
324bb888 204if ( -e "/var/run/need_reboot") {
337305ef
JPT
205 print "<tr><td align='center' colspan='2'><font color='red'>$Lang::tr{'needreboot'}!</font></td></tr>";
206 print "<tr><td colspan='2'>&nbsp;</font></td></tr>"
207}
208print <<END;
c5d106c1 209 <tr><td width="50%" bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire system state'}:</b>
377560fb 210 <td width="50%">
c5d106c1 211 <tr><td align="center">$Lang::tr{'pakfire core update level'}: $core_release<hr />
1e908471
JPT
212 $Lang::tr{'pakfire last update'} $core_update_age $Lang::tr{'pakfire ago'}<br />
213 $Lang::tr{'pakfire last serverlist update'} $server_update_age $Lang::tr{'pakfire ago'}<br />
214 $Lang::tr{'pakfire last core list update'} $corelist_update_age $Lang::tr{'pakfire ago'}<br />
215 $Lang::tr{'pakfire last package update'} $packages_update_age $Lang::tr{'pakfire ago'}
377560fb
MT
216 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
217 <input type='hidden' name='ACTION' value='update' />
1dd22be2 218 <input type='submit' value='$Lang::tr{'calamaris refresh list'}' /><br />
377560fb
MT
219 </form>
220 <td align="center">
221 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
222 <select name="UPDPAKS" size="5" disabled>
223END
224 &Pakfire::dblist("upgrade", "forweb");
225 print <<END;
226 </select>
227 <br />
228 <input type='hidden' name='ACTION' value='upgrade' />
f8aa0679 229 <input type='image' alt='$Lang::tr{'upgrade'}' title='$Lang::tr{'upgrade'}' src='/images/document-save.png' />
377560fb 230 </form>
fee5c6b7 231
377560fb
MT
232 <tr><td colspan="2"><!-- Just an empty line -->&nbsp;
233 <tr><td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire available addons'}</b>
234 <td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire installed addons'}</b>
235 <tr><td align="center">
5d22ef4e 236 <p>$Lang::tr{'pakfire install description'}</p>
fee5c6b7 237 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1bd42c89
MT
238 <select name="INSPAKS" size="10" multiple>
239END
240 &Pakfire::dblist("notinstalled", "forweb");
fee5c6b7 241
1bd42c89
MT
242print <<END;
243 </select>
377560fb 244 <br />
1bd42c89 245 <input type='hidden' name='ACTION' value='install' />
f8aa0679 246 <input type='image' alt='$Lang::tr{'install'}' title='$Lang::tr{'install'}' src='/images/list-add.png' />
1bd42c89 247 </form>
377560fb
MT
248
249 <td align="center">
5d22ef4e 250 <p>$Lang::tr{'pakfire uninstall description'}</p>
377560fb 251 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1bd42c89 252 <select name="DELPAKS" size="10" multiple>
957363eb 253END
5b2a12ff
MT
254
255 &Pakfire::dblist("installed", "forweb");
256
257print <<END;
377560fb
MT
258 </select>
259 <br />
260 <input type='hidden' name='ACTION' value='remove' />
f8aa0679 261 <input type='image' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' src='/images/list-remove.png' />
377560fb
MT
262 </form>
263 </table>
4b122800
MT
264END
265
3ea75603 266&Header::closebox();
3ea75603 267&Header::closebigbox();
3ea75603 268&Header::closepage();