Add delay to pakfire.cgi to prevent pakfire run's twice.
[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
957363eb 60if ($pakfiresettings{'ACTION'} eq 'install'){
908a3eb7 61 $pakfiresettings{'INSPAKS'} =~ s/\|/\ /g;
5b2a12ff 62 if ("$pakfiresettings{'FORCE'}" eq "on") {
750c1528 63 my $command = "/usr/local/bin/pakfire install --non-interactive --no-colors $pakfiresettings{'INSPAKS'} &>/dev/null &";
908a3eb7 64 system("$command");
25dea62a 65 system("/bin/sleep 1");
5b2a12ff
MT
66 } else {
67 &Header::openbox("100%", "center", "Abfrage");
74693811 68 my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $pakfiresettings{'INSPAKS'}`;
5b2a12ff 69 print <<END;
bac7231b 70 <table><tr><td colspan='2'>$Lang::tr{'pakfire install package'}.$pakfiresettings{'INSPAKS'}.$Lang::tr{'pakfire possible dependency'}
fee5c6b7 71 <pre>
5b2a12ff
MT
72END
73 foreach (@output) {
fee5c6b7 74 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
5b2a12ff
MT
75 print "$_\n";
76 }
77 print <<END;
78 </pre>
bac7231b 79 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
5b2a12ff
MT
80 <tr><td colspan='2'>&nbsp;
81 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
82 <input type='hidden' name='INSPAKS' value='$pakfiresettings{'INSPAKS'}' />
83 <input type='hidden' name='FORCE' value='on' />
84 <input type='hidden' name='ACTION' value='install' />
85 <input type='image' alt='$Lang::tr{'install'}' src='/images/go-next.png' />
86 </form>
87 <td align='left'>
88 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
89 <input type='hidden' name='ACTION' value='' />
90 <input type='image' alt='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
91 </form>
92 </table>
93END
94 &Header::closebox();
95 &Header::closebigbox();
96 &Header::closepage();
97 exit;
98 }
99} elsif ($pakfiresettings{'ACTION'} eq 'remove') {
100
74693811
CS
101 $pakfiresettings{'DELPAKS'} =~ s/\|/\ /g;
102 if ("$pakfiresettings{'FORCE'}" eq "on") {
103 my $command = "/usr/local/bin/pakfire remove --non-interactive --no-colors $pakfiresettings{'DELPAKS'} &>/dev/null &";
104 system("$command");
25dea62a 105 system("/bin/sleep 1");
74693811
CS
106 } else {
107 &Header::openbox("100%", "center", "Abfrage");
108 my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $pakfiresettings{'DELPAKS'}`;
109 print <<END;
110 <table><tr><td colspan='2'>$Lang::tr{'pakfire uninstall package'}.$pakfiresettings{'DELPAKS'}.$Lang::tr{'pakfire possible dependency'}
fee5c6b7 111 <pre>
74693811
CS
112END
113 foreach (@output) {
fee5c6b7 114 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
74693811
CS
115 print "$_\n";
116 }
117 print <<END;
118 </pre>
119 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
120 <tr><td colspan='2'>&nbsp;
121 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
122 <input type='hidden' name='DELPAKS' value='$pakfiresettings{'DELPAKS'}' />
123 <input type='hidden' name='FORCE' value='on' />
124 <input type='hidden' name='ACTION' value='remove' />
125 <input type='image' alt='$Lang::tr{'uninstall'}' src='/images/go-next.png' />
126 </form>
127 <td align='left'>
128 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
129 <input type='hidden' name='ACTION' value='' />
130 <input type='image' alt='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
131 </form>
132 </table>
133END
134 &Header::closebox();
135 &Header::closebigbox();
136 &Header::closepage();
137 exit;
138 }
139
5b2a12ff 140} elsif ($pakfiresettings{'ACTION'} eq 'update') {
fee5c6b7 141
28593a79 142 system("/usr/local/bin/pakfire update --force --no-colors &>/dev/null &");
25dea62a 143 system("/bin/sleep 1");
186e3d2c 144} elsif ($pakfiresettings{'ACTION'} eq 'upgrade') {
28593a79 145 my $command = "/usr/local/bin/pakfire upgrade -y --no-colors &>/dev/null &";
c506cad0 146 system("$command");
25dea62a 147 system("/bin/sleep 1");
5b2a12ff
MT
148} elsif ($pakfiresettings{'ACTION'} eq "$Lang::tr{'save'}") {
149
d2414ee7 150 if ($pakfiresettings{'AUTOUPDATE'} eq 'on') {
91a08eac 151 system("/usr/local/bin/pakfire enable updates >/dev/null 2>&1");
377560fb 152 } else {
91a08eac 153 system("/usr/local/bin/pakfire disable updates >/dev/null 2>&1");
377560fb 154 }
fee5c6b7 155
d2414ee7 156 if ($pakfiresettings{'AUTOUPGRADE'} eq 'on') {
91a08eac 157 system("/usr/local/bin/pakfire enable upgrades >/dev/null 2>&1");
377560fb 158 } else {
91a08eac 159 system("/usr/local/bin/pakfire disable upgrades >/dev/null 2>&1");
377560fb 160 }
4b122800 161
377560fb 162 &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings);
3ea75603
MT
163}
164
165&General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
166
3ea75603
MT
167my %selected=();
168my %checked=();
169
1bd42c89
MT
170$checked{'AUTOUPDATE'}{'off'} = '';
171$checked{'AUTOUPDATE'}{'on'} = '';
172$checked{'AUTOUPDATE'}{$pakfiresettings{'AUTOUPDATE'}} = "checked='checked'";
377560fb
MT
173$checked{'AUTOUPGRADE'}{'off'} = '';
174$checked{'AUTOUPGRADE'}{'on'} = '';
175$checked{'AUTOUPGRADE'}{$pakfiresettings{'AUTOUPGRADE'}} = "checked='checked'";
d59b02f1
CS
176$checked{'HEALTHCHECK'}{'off'} = '';
177$checked{'HEALTHCHECK'}{'on'} = '';
178$checked{'HEALTHCHECK'}{$pakfiresettings{'HEALTHCHECK'}} = "checked='checked'";
4b122800
MT
179$checked{'UUID'}{'off'} = '';
180$checked{'UUID'}{'on'} = '';
181$checked{'UUID'}{$pakfiresettings{'UUID'}} = "checked='checked'";
3ea75603
MT
182
183# DPC move error message to top so it is seen!
184if ($errormessage) {
185 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
186 print "<font class='base'>$errormessage&nbsp;</font>\n";
187 &Header::closebox();
5b2a12ff
MT
188}
189
186e3d2c
MT
190my $return = `pidof pakfire`;
191chomp($return);
192if ($return) {
ca4c317c 193 &Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='10;'>" );
5b2a12ff
MT
194 print <<END;
195 <table>
196 <tr><td>
186e3d2c 197 <img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' />&nbsp;
5b2a12ff 198 <td>
bac7231b 199 $Lang::tr{'pakfire working'}
5b2a12ff
MT
200 <tr><td colspan='2' align='center'>
201 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
202 <input type='image' alt='$Lang::tr{'reload'}' src='/images/view-refresh.png' />
203 </form>
186e3d2c
MT
204 <tr><td colspan='2' align='left'><pre>
205END
28593a79 206 my @output = `grep pakfire /var/log/messages | tail -20`;
750c1528
MT
207 foreach (@output) {
208 print "$_";
209 }
210 print <<END;
211 </pre>
212 </table>
5b2a12ff
MT
213END
214 &Header::closebox();
215 &Header::closebigbox();
216 &Header::closepage();
217 exit;
28593a79 218 refreshpage();
5b2a12ff 219}
3ea75603 220
91a08eac 221my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`;
377560fb
MT
222chomp($core_release);
223my $core_update_age = &General::age("/opt/pakfire/db/core/mine");
224my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db");
225my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db");
226my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db");
227
1bd42c89
MT
228&Header::openbox("100%", "center", "Pakfire");
229
230print <<END;
d40aff35 231 <table width='95%' cellpadding='5' >
c5d106c1 232 <tr><td width="50%" bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire system state'}:</b>
377560fb 233 <td width="50%">
c5d106c1
CS
234 <tr><td align="center">$Lang::tr{'pakfire core update level'}: $core_release<hr />
235 $Lang::tr{'pakfire last update'} $core_update_age ago<br />
236 $Lang::tr{'pakfire last serverlist update'} $server_update_age ago<br />
237 $Lang::tr{'pakfire last core list update'} $corelist_update_age ago<br />
238 $Lang::tr{'pakfire last package update'} $packages_update_age ago
377560fb
MT
239 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
240 <input type='hidden' name='ACTION' value='update' />
1dd22be2 241 <input type='submit' value='$Lang::tr{'calamaris refresh list'}' /><br />
377560fb
MT
242 </form>
243 <td align="center">
244 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
245 <select name="UPDPAKS" size="5" disabled>
246END
247 &Pakfire::dblist("upgrade", "forweb");
248 print <<END;
249 </select>
250 <br />
251 <input type='hidden' name='ACTION' value='upgrade' />
252 <input type='image' alt='$Lang::tr{'upgrade'}' src='/images/document-save.png' />
253 </form>
fee5c6b7 254
377560fb
MT
255 <tr><td colspan="2"><!-- Just an empty line -->&nbsp;
256 <tr><td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire available addons'}</b>
257 <td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire installed addons'}</b>
258 <tr><td align="center">
5d22ef4e 259 <p>$Lang::tr{'pakfire install description'}</p>
fee5c6b7 260 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1bd42c89
MT
261 <select name="INSPAKS" size="10" multiple>
262END
263 &Pakfire::dblist("notinstalled", "forweb");
fee5c6b7 264
1bd42c89
MT
265print <<END;
266 </select>
377560fb 267 <br />
1bd42c89
MT
268 <input type='hidden' name='ACTION' value='install' />
269 <input type='image' alt='$Lang::tr{'install'}' src='/images/list-add.png' />
1bd42c89 270 </form>
377560fb
MT
271
272 <td align="center">
5d22ef4e 273 <p>$Lang::tr{'pakfire uninstall description'}</p>
377560fb 274 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1bd42c89 275 <select name="DELPAKS" size="10" multiple>
957363eb 276END
5b2a12ff
MT
277
278 &Pakfire::dblist("installed", "forweb");
279
280print <<END;
377560fb
MT
281 </select>
282 <br />
283 <input type='hidden' name='ACTION' value='remove' />
284 <input type='image' alt='$Lang::tr{'remove'}' src='/images/list-remove.png' />
285 </form>
286 </table>
4b122800
MT
287END
288
377560fb
MT
289&Header::closebox();
290&Header::openbox("100%", "center", "$Lang::tr{'settings'}");
4b122800
MT
291
292print <<END;
1bd42c89 293 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
d40aff35
CS
294 <table width='95%'>
295 <tr><td colspan='2' bgcolor='$color{'color20'}'><b>$Lang::tr{'basic options'}</b></td></tr>
c6614883
JPT
296 <tr><td align='left' width='45%'>$Lang::tr{'pakfire update daily'}</td><td width="55%" align="left">
297 on <input type='radio' name='AUTOUPDATE' value='on' $checked{'AUTOUPDATE'}{'on'} /> |
d40aff35 298 <input type='radio' name='AUTOUPDATE' value='off' $checked{'AUTOUPDATE'}{'off'} /> off </td></tr>
c6614883
JPT
299 <tr><td align='left' width='45%'>$Lang::tr{'pakfire core update auto'}</td><td align="left">
300 on <input type='radio' name='AUTOUPGRADE' value='on' $checked{'AUTOUPGRADE'}{'on'} /> |
d40aff35 301 <input type='radio' name='AUTOUPGRADE' value='off' $checked{'AUTOUPGRADE'}{'off'} /> off </td></tr>
d59b02f1
CS
302 <tr><td align='left' width='45%'>$Lang::tr{'pakfire health check'}</td><td align="left">
303 on <input type='radio' name='HEALTHCHECK' value='on' $checked{'HEALTHCHECK'}{'on'} /> |
304 <input type='radio' name='HEALTHCHECK' value='off' $checked{'HEALTHCHECK'}{'off'} /> off </td></tr>
c6614883
JPT
305 <tr><td align='left' width='45%'>$Lang::tr{'pakfire register'}</td><td align="left">
306 on <input type='radio' name='UUID' value='on' $checked{'UUID'}{'on'} /> |
d40aff35 307 <input type='radio' name='UUID' value='off' $checked{'UUID'}{'off'} /> off </td></tr>
c6614883 308 <tr><td colspan="2" align="center"><input type="submit" name="ACTION" value="$Lang::tr{'save'}" /></td></tr>
1bd42c89
MT
309 </table>
310 </form>
311END
312
3ea75603 313&Header::closebox();
3ea75603 314&Header::closebigbox();
3ea75603 315&Header::closepage();