]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/pakfire.cgi
pakfire.cgi: Add new translations
[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 38
db9ee62e
LAH
39# Load general settings
40&General::readhash("${General::swroot}/main/settings", \%mainsettings);
41&General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
3ea75603 42
db9ee62e 43# Get CGI request data
131f163c
MT
44$cgiparams{'ACTION'} = '';
45$cgiparams{'VALID'} = '';
3ea75603 46
131f163c
MT
47$cgiparams{'INSPAKS'} = '';
48$cgiparams{'DELPAKS'} = '';
3ea75603 49
131f163c 50&Header::getcgihash(\%cgiparams);
d40aff35 51
db9ee62e
LAH
52### Process AJAX/JSON request ###
53if($cgiparams{'ACTION'} eq 'json-getstatus') {
54 # Send HTTP headers
55 _start_json_output();
56
57 # Collect Pakfire status and log messages
58 my %status = (
59 'running' => &_is_pakfire_busy() || "0",
60 'running_since' => &General::age("$Pakfire::lockfile") || "0s",
61 'reboot' => (-e "/var/run/need_reboot") || "0"
62 );
63 my @messages = `tac /var/log/messages | sed -n '/pakfire:/{p;/Pakfire.*started/q}'`;
64
65 # Start JSON file
66 print "{\n";
67
68 foreach my $key (keys %status) {
69 my $value = $status{$key};
70 print qq{\t"$key": "$value",\n};
71 }
72
73 # Print sanitized messages in reverse order to undo previous "tac"
74 print qq{\t"messages": [\n};
75 for my $index (reverse (0 .. $#messages)) {
76 my $line = $messages[$index];
77 $line =~ s/[[:cntrl:]<>&\\]+//g;
78
79 print qq{\t\t"$line"};
80 print ",\n" unless $index < 1;
81 }
82 print "\n\t]\n";
83
84 # Finalize JSON file & stop
85 print "}";
86 exit;
87}
88
89### Start pakfire page ###
90&Header::showhttpheaders();
91
92###--- HTML HEAD ---###
93my $extraHead = <<END
94<style>
95 /* Pakfire log viewer */
96 section#pflog-header {
97 width: 100%;
98 display: flex;
99 text-align: left;
100 align-items: center;
101 column-gap: 20px;
102 }
103 #pflog-header > div:last-child {
104 margin-left: auto;
105 margin-right: 20px;
106 }
107 #pflog-header span {
108 line-height: 1.3em;
109 }
110 #pflog-header span:empty::before {
111 content: "\\200b"; /* zero width space */
112 }
113
114 pre#pflog-messages {
115 margin-top: 0.7em;
116 padding-top: 0.7em;
117 border-top: 0.5px solid $Header::bordercolour;
3ea75603 118
db9ee62e
LAH
119 text-align: left;
120 min-height: 15em;
121 overflow-x: auto;
122 }
123</style>
124
125<script src="/include/pakfire.js"></script>
126<script>
127 // Translations
128 pakfire.i18n.load({
129 'working': '$Lang::tr{'pakfire working'}',
524bbe32 130 'finished': '$Lang::tr{'pakfire finished'}',
db9ee62e
LAH
131 'since': '$Lang::tr{'since'} ', //(space is intentional)
132
524bbe32 133 'link_return': '<a href="$ENV{'SCRIPT_NAME'}">$Lang::tr{'pakfire return'}</a>',
db9ee62e
LAH
134 'link_reboot': '<a href="/cgi-bin/shutdown.cgi">$Lang::tr{'needreboot'}</a>'
135 });
136
137 // AJAX auto refresh interval
138 pakfire.refreshInterval = 1000;
139</script>
140END
141;
142###--- END HTML HEAD ---###
143
144&Header::openpage($Lang::tr{'pakfire configuration'}, 1, $extraHead);
1bd42c89 145&Header::openbigbox('100%', 'left', '', $errormessage);
3ea75603 146
db9ee62e 147# Process Pakfire commands
d255e2d1 148if (($cgiparams{'ACTION'} eq 'install') && (! &_is_pakfire_busy())) {
75ee0279 149 my @pkgs = split(/\|/, $cgiparams{'INSPAKS'});
131f163c 150 if ("$cgiparams{'FORCE'}" eq "on") {
75ee0279 151 &General::system_background("/usr/local/bin/pakfire", "install", "--non-interactive", "--no-colors", @pkgs);
b4c9d299 152 sleep(1);
5b2a12ff 153 } else {
40228ef4 154 &Header::openbox("100%", "center", $Lang::tr{'request'});
75ee0279 155 my @output = &General::system_output("/usr/local/bin/pakfire", "resolvedeps", "--no-colors", @pkgs);
5b2a12ff 156 print <<END;
124926ee 157 <table><tr><td colspan='2'>$Lang::tr{'pakfire install package'} @pkgs $Lang::tr{'pakfire possible dependency'}
fee5c6b7 158 <pre>
5b2a12ff
MT
159END
160 foreach (@output) {
fee5c6b7 161 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
5b2a12ff
MT
162 print "$_\n";
163 }
164 print <<END;
165 </pre>
bac7231b 166 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
5b2a12ff
MT
167 <tr><td colspan='2'>&nbsp;
168 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
131f163c 169 <input type='hidden' name='INSPAKS' value='$cgiparams{'INSPAKS'}' />
5b2a12ff
MT
170 <input type='hidden' name='FORCE' value='on' />
171 <input type='hidden' name='ACTION' value='install' />
f8aa0679 172 <input type='image' alt='$Lang::tr{'install'}' title='$Lang::tr{'install'}' src='/images/go-next.png' />
5b2a12ff
MT
173 </form>
174 <td align='left'>
175 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
176 <input type='hidden' name='ACTION' value='' />
f8aa0679 177 <input type='image' alt='$Lang::tr{'abort'}' title='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
5b2a12ff
MT
178 </form>
179 </table>
180END
181 &Header::closebox();
182 &Header::closebigbox();
183 &Header::closepage();
184 exit;
185 }
d255e2d1 186} elsif (($cgiparams{'ACTION'} eq 'remove') && (! &_is_pakfire_busy())) {
75ee0279 187 my @pkgs = split(/\|/, $cgiparams{'DELPAKS'});
131f163c 188 if ("$cgiparams{'FORCE'}" eq "on") {
75ee0279 189 &General::system_background("/usr/local/bin/pakfire", "remove", "--non-interactive", "--no-colors", @pkgs);
b4c9d299 190 sleep(1);
74693811 191 } else {
40228ef4 192 &Header::openbox("100%", "center", $Lang::tr{'request'});
75ee0279 193 my @output = &General::system_output("/usr/local/bin/pakfire", "resolvedeps", "--no-colors", @pkgs);
74693811 194 print <<END;
124926ee 195 <table><tr><td colspan='2'>$Lang::tr{'pakfire uninstall package'} @pkgs $Lang::tr{'pakfire possible dependency'}
fee5c6b7 196 <pre>
74693811
CS
197END
198 foreach (@output) {
fee5c6b7 199 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
74693811
CS
200 print "$_\n";
201 }
202 print <<END;
203 </pre>
c8915626 204 <tr><td colspan='2'>$Lang::tr{'pakfire uninstall all'}
74693811
CS
205 <tr><td colspan='2'>&nbsp;
206 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
131f163c 207 <input type='hidden' name='DELPAKS' value='$cgiparams{'DELPAKS'}' />
74693811
CS
208 <input type='hidden' name='FORCE' value='on' />
209 <input type='hidden' name='ACTION' value='remove' />
f8aa0679 210 <input type='image' alt='$Lang::tr{'uninstall'}' title='$Lang::tr{'uninstall'}' src='/images/go-next.png' />
74693811
CS
211 </form>
212 <td align='left'>
213 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
214 <input type='hidden' name='ACTION' value='' />
f8aa0679 215 <input type='image' alt='$Lang::tr{'abort'}' title='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
74693811
CS
216 </form>
217 </table>
218END
219 &Header::closebox();
220 &Header::closebigbox();
221 &Header::closepage();
222 exit;
223 }
224
d255e2d1 225} elsif (($cgiparams{'ACTION'} eq 'update') && (! &_is_pakfire_busy())) {
bce85943 226 &General::system_background("/usr/local/bin/pakfire", "update", "--force", "--no-colors");
b4c9d299 227 sleep(1);
d255e2d1 228} elsif (($cgiparams{'ACTION'} eq 'upgrade') && (! &_is_pakfire_busy())) {
bce85943 229 &General::system_background("/usr/local/bin/pakfire", "upgrade", "-y", "--no-colors");
b4c9d299 230 sleep(1);
131f163c 231} elsif ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}") {
f61be862
MT
232 $pakfiresettings{"TREE"} = $cgiparams{"TREE"};
233
234 # Check for valid input
235 if ($pakfiresettings{"TREE"} !~ m/^(stable|testing|unstable)$/) {
236 $errormessage .= $Lang::tr{'pakfire invalid tree'};
237 }
238
239 unless ($errormessage) {
240 &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings);
241
242 # Update lists
bce85943 243 &General::system_background("/usr/local/bin/pakfire", "update", "--force", "--no-colors");
b4c9d299 244 sleep(1);
f61be862 245 }
3ea75603
MT
246}
247
248&General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
249
3ea75603
MT
250my %selected=();
251my %checked=();
252
f61be862
MT
253$selected{"TREE"} = ();
254$selected{"TREE"}{"stable"} = "";
255$selected{"TREE"}{"testing"} = "";
256$selected{"TREE"}{"unstable"} = "";
257$selected{"TREE"}{$pakfiresettings{"TREE"}} = "selected";
258
3ea75603
MT
259# DPC move error message to top so it is seen!
260if ($errormessage) {
261 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
262 print "<font class='base'>$errormessage&nbsp;</font>\n";
263 &Header::closebox();
5b2a12ff
MT
264}
265
db9ee62e
LAH
266# Show log output while Pakfire is running
267if(&_is_pakfire_busy()) {
268 &Header::openbox("100%", "center", "Pakfire");
269
270 print <<END
271<section id="pflog-header">
272 <div><img src="/images/indicator.gif" alt="$Lang::tr{'active'}" title="$Lang::tr{'pagerefresh'}"></div>
273 <div>
274 <span id="pflog-status">$Lang::tr{'pakfire working'}</span><br>
275 <span id="pflog-time"></span><br>
276 <span id="pflog-action"></span>
277 </div>
278 <div><a href="$ENV{'SCRIPT_NAME'}"><img src="/images/view-refresh.png" alt="$Lang::tr{'refresh'}" title="$Lang::tr{'refresh'}"></a></div>
279</section>
280
281<!-- Pakfire log messages -->
282<pre id="pflog-messages"></pre>
283<script>
284 pakfire.running = true;
285</script>
286
5b2a12ff 287END
db9ee62e
LAH
288;
289
5b2a12ff
MT
290 &Header::closebox();
291 &Header::closebigbox();
292 &Header::closepage();
293 exit;
294}
3ea75603 295
91a08eac 296my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`;
377560fb
MT
297chomp($core_release);
298my $core_update_age = &General::age("/opt/pakfire/db/core/mine");
299my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db");
300my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db");
301my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db");
302
1bd42c89
MT
303&Header::openbox("100%", "center", "Pakfire");
304
305print <<END;
6666b93d 306 <table width='95%' cellpadding='5'>
337305ef 307END
324bb888 308if ( -e "/var/run/need_reboot") {
337305ef
JPT
309 print "<tr><td align='center' colspan='2'><font color='red'>$Lang::tr{'needreboot'}!</font></td></tr>";
310 print "<tr><td colspan='2'>&nbsp;</font></td></tr>"
311}
312print <<END;
c5d106c1 313 <tr><td width="50%" bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire system state'}:</b>
6666b93d
MF
314
315 <td width="50%" bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'available updates'}:</b></tr>
316
c5d106c1 317 <tr><td align="center">$Lang::tr{'pakfire core update level'}: $core_release<hr />
1e908471
JPT
318 $Lang::tr{'pakfire last update'} $core_update_age $Lang::tr{'pakfire ago'}<br />
319 $Lang::tr{'pakfire last serverlist update'} $server_update_age $Lang::tr{'pakfire ago'}<br />
320 $Lang::tr{'pakfire last core list update'} $corelist_update_age $Lang::tr{'pakfire ago'}<br />
321 $Lang::tr{'pakfire last package update'} $packages_update_age $Lang::tr{'pakfire ago'}
377560fb 322 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
6666b93d 323 <input type='hidden' name='ACTION' value='update' /><br />
1dd22be2 324 <input type='submit' value='$Lang::tr{'calamaris refresh list'}' /><br />
377560fb 325 </form>
6666b93d 326<br />
377560fb 327 <td align="center">
6666b93d 328 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
377560fb
MT
329 <select name="UPDPAKS" size="5" disabled>
330END
331 &Pakfire::dblist("upgrade", "forweb");
332 print <<END;
333 </select>
334 <br />
335 <input type='hidden' name='ACTION' value='upgrade' />
f8aa0679 336 <input type='image' alt='$Lang::tr{'upgrade'}' title='$Lang::tr{'upgrade'}' src='/images/document-save.png' />
377560fb 337 </form>
fee5c6b7 338
377560fb
MT
339 <tr><td colspan="2"><!-- Just an empty line -->&nbsp;
340 <tr><td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire available addons'}</b>
341 <td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire installed addons'}</b>
6666b93d 342 <tr><td style="padding:5px 10px 20px 20px" align="center">
5d22ef4e 343 <p>$Lang::tr{'pakfire install description'}</p>
fee5c6b7 344 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1bd42c89
MT
345 <select name="INSPAKS" size="10" multiple>
346END
347 &Pakfire::dblist("notinstalled", "forweb");
fee5c6b7 348
1bd42c89
MT
349print <<END;
350 </select>
377560fb 351 <br />
1bd42c89 352 <input type='hidden' name='ACTION' value='install' />
f8aa0679 353 <input type='image' alt='$Lang::tr{'install'}' title='$Lang::tr{'install'}' src='/images/list-add.png' />
1bd42c89 354 </form>
377560fb 355
6666b93d 356 <td style="padding:5px 10px 20px 20px" align="center">
5d22ef4e 357 <p>$Lang::tr{'pakfire uninstall description'}</p>
377560fb 358 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1bd42c89 359 <select name="DELPAKS" size="10" multiple>
957363eb 360END
5b2a12ff
MT
361
362 &Pakfire::dblist("installed", "forweb");
363
364print <<END;
377560fb
MT
365 </select>
366 <br />
367 <input type='hidden' name='ACTION' value='remove' />
f8aa0679 368 <input type='image' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' src='/images/list-remove.png' />
377560fb
MT
369 </form>
370 </table>
4b122800
MT
371END
372
f61be862
MT
373&Header::closebox();
374&Header::openbox("100%", "center", "$Lang::tr{'settings'}");
375
376print <<END;
377 <form method='POST' action='$ENV{'SCRIPT_NAME'}'>
378 <table width='95%'>
379 <tr>
380 <td align='left' width='45%'>$Lang::tr{'pakfire tree'}</td>
381 <td width="55%" align="left">
382 <select name="TREE">
383 <option value="stable" $selected{"TREE"}{"stable"}>$Lang::tr{'pakfire tree stable'}</option>
384 <option value="testing" $selected{"TREE"}{"testing"}>$Lang::tr{'pakfire tree testing'}</option>
385 <option value="unstable" $selected{"TREE"}{"unstable"}>$Lang::tr{'pakfire tree unstable'}</option>
386 </select>
387 </td>
388 </tr>
389 <tr>
390 <td colspan="2">&nbsp;</td>
391 </tr>
392 <tr>
393 <td colspan="2" align="center">
394 <input type="submit" name="ACTION" value="$Lang::tr{'save'}" />
395 </td>
396 </tr>
397 </table>
398 </form>
399END
400
3ea75603 401&Header::closebox();
3ea75603 402&Header::closebigbox();
3ea75603 403&Header::closepage();
d255e2d1
LAH
404
405###--- Internal functions ---###
406
407# Check if pakfire is already running (extend test here if necessary)
408sub _is_pakfire_busy {
409 # Get PID of a running pakfire instance
410 # (The system backpipe command is safe, because no user input is computed.)
411 my $pakfire_pid = `pidof -s /usr/local/bin/pakfire`;
412 chomp($pakfire_pid);
413
414 # Test presence of PID or lockfile
415 return (($pakfire_pid) || (-e "$Pakfire::lockfile"));
416}
db9ee62e
LAH
417
418# Send HTTP headers
419sub _start_json_output {
420 print "Cache-Control: no-cache, no-store\n";
421 print "Content-Type: application/json\n";
422 print "\n"; # End of HTTP headers
423}