]>
Commit | Line | Data |
---|---|---|
3ea75603 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
b81c77b9 | 5 | # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> # |
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 | |
22 | use strict; | |
4d70f591 | 23 | use List::Util qw(any); |
85d57084 | 24 | use URI; |
3ea75603 MT |
25 | |
26 | # enable only the following on debugging purpose | |
cb5e9c6c CS |
27 | #use warnings; |
28 | #use CGI::Carp 'fatalsToBrowser'; | |
3ea75603 | 29 | |
986e08d9 | 30 | require '/var/ipfire/general-functions.pl'; |
3ea75603 MT |
31 | require "${General::swroot}/lang.pl"; |
32 | require "${General::swroot}/header.pl"; | |
1bd42c89 | 33 | require "/opt/pakfire/lib/functions.pl"; |
3ea75603 | 34 | |
131f163c | 35 | my %cgiparams=(); |
3ea75603 | 36 | my $errormessage = ''; |
cb5e9c6c | 37 | my %color = (); |
131f163c | 38 | my %pakfiresettings = (); |
cb5e9c6c | 39 | my %mainsettings = (); |
3ea75603 | 40 | |
85d57084 LAH |
41 | # The page mode is used to explictly switch between user interface functions: |
42 | my $PM_DEFAULT = 'default'; # Default user interface with command processing | |
43 | my $PM_LOGREAD = 'logread'; # Log messages viewer (ignores all commands) | |
44 | my $pagemode = $PM_DEFAULT; | |
45 | ||
db9ee62e LAH |
46 | # Load general settings |
47 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
cd521e78 | 48 | &General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings); |
db9ee62e | 49 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
3ea75603 | 50 | |
85d57084 | 51 | # Get CGI POST request data |
131f163c | 52 | $cgiparams{'ACTION'} = ''; |
cd521e78 | 53 | $cgiparams{'FORCE'} = ''; |
3ea75603 | 54 | |
131f163c MT |
55 | $cgiparams{'INSPAKS'} = ''; |
56 | $cgiparams{'DELPAKS'} = ''; | |
3ea75603 | 57 | |
131f163c | 58 | &Header::getcgihash(\%cgiparams); |
d40aff35 | 59 | |
85d57084 LAH |
60 | # Get CGI GET request data (if available) |
61 | if($ENV{'QUERY_STRING'}) { | |
62 | my $uri = URI->new($ENV{'REQUEST_URI'}); | |
63 | my %query = $uri->query_form; | |
64 | ||
65 | my $mode = lc($query{'mode'} // ''); | |
66 | if(($mode eq $PM_DEFAULT) || ($mode eq $PM_LOGREAD)) { | |
67 | $pagemode = $mode; # Limit to existing modes | |
68 | } | |
69 | } | |
70 | ||
db9ee62e LAH |
71 | ### Process AJAX/JSON request ### |
72 | if($cgiparams{'ACTION'} eq 'json-getstatus') { | |
73 | # Send HTTP headers | |
74 | _start_json_output(); | |
75 | ||
4d70f591 LAH |
76 | # Read /var/log/messages backwards until a "Pakfire started" header is found, |
77 | # to capture all messages of the last (i.e. current) Pakfire run | |
3706e0a5 | 78 | my @messages = `tac /var/log/messages 2>/dev/null | sed -n '/pakfire:/{p;/Pakfire.*started/q}'`; |
4d70f591 LAH |
79 | |
80 | # Test if the log contains an error message (fastest implementation, stops at first match) | |
81 | my $failure = any{ index($_, 'ERROR') != -1 } @messages; | |
82 | ||
83 | # Collect Pakfire status | |
db9ee62e LAH |
84 | my %status = ( |
85 | 'running' => &_is_pakfire_busy() || "0", | |
86 | 'running_since' => &General::age("$Pakfire::lockfile") || "0s", | |
4d70f591 LAH |
87 | 'reboot' => (-e "/var/run/need_reboot") || "0", |
88 | 'failure' => $failure || "0" | |
db9ee62e | 89 | ); |
db9ee62e LAH |
90 | |
91 | # Start JSON file | |
92 | print "{\n"; | |
93 | ||
94 | foreach my $key (keys %status) { | |
95 | my $value = $status{$key}; | |
96 | print qq{\t"$key": "$value",\n}; | |
97 | } | |
98 | ||
99 | # Print sanitized messages in reverse order to undo previous "tac" | |
100 | print qq{\t"messages": [\n}; | |
101 | for my $index (reverse (0 .. $#messages)) { | |
102 | my $line = $messages[$index]; | |
103 | $line =~ s/[[:cntrl:]<>&\\]+//g; | |
104 | ||
105 | print qq{\t\t"$line"}; | |
106 | print ",\n" unless $index < 1; | |
107 | } | |
108 | print "\n\t]\n"; | |
109 | ||
110 | # Finalize JSON file & stop | |
111 | print "}"; | |
112 | exit; | |
113 | } | |
114 | ||
cd521e78 | 115 | ### Process Pakfire install/update commands ### |
85d57084 | 116 | if(($cgiparams{'ACTION'} ne '') && ($pagemode eq $PM_DEFAULT)) { |
3cdb8393 LAH |
117 | if(&_is_pakfire_busy()) { |
118 | $errormessage = $Lang::tr{'pakfire already busy'}; | |
85d57084 | 119 | $pagemode = $PM_LOGREAD; # Running Pakfire instance found, switch to log viewer mode |
3cdb8393 | 120 | } elsif(($cgiparams{'ACTION'} eq 'install') && ($cgiparams{'FORCE'} eq 'on')) { |
cd521e78 LAH |
121 | my @pkgs = split(/\|/, $cgiparams{'INSPAKS'}); |
122 | &General::system_background("/usr/local/bin/pakfire", "install", "--non-interactive", "--no-colors", @pkgs); | |
85d57084 | 123 | &_http_pagemode_redirect($PM_LOGREAD, 1); |
cd521e78 LAH |
124 | } elsif(($cgiparams{'ACTION'} eq 'remove') && ($cgiparams{'FORCE'} eq 'on')) { |
125 | my @pkgs = split(/\|/, $cgiparams{'DELPAKS'}); | |
126 | &General::system_background("/usr/local/bin/pakfire", "remove", "--non-interactive", "--no-colors", @pkgs); | |
85d57084 | 127 | &_http_pagemode_redirect($PM_LOGREAD, 1); |
cd521e78 LAH |
128 | } elsif($cgiparams{'ACTION'} eq 'update') { |
129 | &General::system_background("/usr/local/bin/pakfire", "update", "--force", "--no-colors"); | |
85d57084 | 130 | &_http_pagemode_redirect($PM_LOGREAD, 1); |
cd521e78 LAH |
131 | } elsif($cgiparams{'ACTION'} eq 'upgrade') { |
132 | &General::system_background("/usr/local/bin/pakfire", "upgrade", "-y", "--no-colors"); | |
85d57084 | 133 | &_http_pagemode_redirect($PM_LOGREAD, 1); |
cd521e78 LAH |
134 | } elsif($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
135 | $pakfiresettings{"TREE"} = $cgiparams{"TREE"}; | |
136 | ||
137 | # Check for valid input | |
138 | if ($pakfiresettings{"TREE"} !~ m/^(stable|testing|unstable)$/) { | |
139 | $errormessage .= $Lang::tr{'pakfire invalid tree'}; | |
140 | } | |
141 | ||
142 | unless ($errormessage) { | |
143 | &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings); | |
144 | ||
145 | # Update lists | |
146 | &General::system_background("/usr/local/bin/pakfire", "update", "--force", "--no-colors"); | |
85d57084 | 147 | &_http_pagemode_redirect($PM_LOGREAD, 1); |
cd521e78 LAH |
148 | } |
149 | } | |
150 | } | |
151 | ||
db9ee62e LAH |
152 | ### Start pakfire page ### |
153 | &Header::showhttpheaders(); | |
154 | ||
155 | ###--- HTML HEAD ---### | |
156 | my $extraHead = <<END | |
157 | <style> | |
219dacef LAH |
158 | /* Main screen */ |
159 | table#pfmain { | |
160 | width: 100%; | |
161 | border-style: hidden; | |
162 | table-layout: fixed; | |
163 | } | |
164 | ||
165 | #pfmain td { | |
166 | padding: 5px 20px 0; | |
167 | text-align: center; | |
168 | } | |
169 | #pfmain tr:not(:last-child) > td { | |
170 | padding-bottom: 1.5em; | |
171 | } | |
172 | #pfmain tr > td.heading { | |
173 | padding: 0; | |
174 | font-weight: bold; | |
175 | background-color: $color{'color20'}; | |
176 | } | |
177 | ||
178 | .pflist { | |
179 | width: 100%; | |
180 | text-align: left; | |
181 | margin-bottom: 0.8em; | |
182 | } | |
183 | ||
db9ee62e LAH |
184 | /* Pakfire log viewer */ |
185 | section#pflog-header { | |
186 | width: 100%; | |
187 | display: flex; | |
188 | text-align: left; | |
189 | align-items: center; | |
190 | column-gap: 20px; | |
191 | } | |
192 | #pflog-header > div:last-child { | |
193 | margin-left: auto; | |
194 | margin-right: 20px; | |
195 | } | |
196 | #pflog-header span { | |
197 | line-height: 1.3em; | |
198 | } | |
199 | #pflog-header span:empty::before { | |
200 | content: "\\200b"; /* zero width space */ | |
201 | } | |
202 | ||
203 | pre#pflog-messages { | |
204 | margin-top: 0.7em; | |
205 | padding-top: 0.7em; | |
206 | border-top: 0.5px solid $Header::bordercolour; | |
3ea75603 | 207 | |
db9ee62e LAH |
208 | text-align: left; |
209 | min-height: 15em; | |
210 | overflow-x: auto; | |
211 | } | |
212 | </style> | |
213 | ||
214 | <script src="/include/pakfire.js"></script> | |
215 | <script> | |
216 | // Translations | |
217 | pakfire.i18n.load({ | |
218 | 'working': '$Lang::tr{'pakfire working'}', | |
524bbe32 | 219 | 'finished': '$Lang::tr{'pakfire finished'}', |
4d70f591 LAH |
220 | 'finished error': '$Lang::tr{'pakfire finished error'}', |
221 | 'since': '$Lang::tr{'since'}', | |
db9ee62e | 222 | |
524bbe32 | 223 | 'link_return': '<a href="$ENV{'SCRIPT_NAME'}">$Lang::tr{'pakfire return'}</a>', |
db9ee62e LAH |
224 | 'link_reboot': '<a href="/cgi-bin/shutdown.cgi">$Lang::tr{'needreboot'}</a>' |
225 | }); | |
4d70f591 LAH |
226 | |
227 | // AJAX auto refresh interval (in ms, default: 1000) | |
228 | //pakfire.refreshInterval = 1000; | |
229 | ||
230 | // Enable returning to main screen (delay in ms) | |
231 | pakfire.setupPageReload(true, 3000); | |
db9ee62e LAH |
232 | </script> |
233 | END | |
234 | ; | |
235 | ###--- END HTML HEAD ---### | |
236 | ||
237 | &Header::openpage($Lang::tr{'pakfire configuration'}, 1, $extraHead); | |
1bd42c89 | 238 | &Header::openbigbox('100%', 'left', '', $errormessage); |
3ea75603 | 239 | |
4b5d1f30 LAH |
240 | # Show error message |
241 | if ($errormessage) { | |
242 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
243 | print "<font class='base'>$errormessage </font>\n"; | |
244 | &Header::closebox(); | |
245 | } | |
246 | ||
85d57084 LAH |
247 | # Show only log output while Pakfire is running and stop afterwards |
248 | if(($pagemode eq $PM_LOGREAD) || (&_is_pakfire_busy())) { | |
4b5d1f30 LAH |
249 | &Header::openbox("100%", "center", "Pakfire"); |
250 | ||
251 | print <<END | |
252 | <section id="pflog-header"> | |
253 | <div><img src="/images/indicator.gif" alt="$Lang::tr{'active'}" title="$Lang::tr{'pagerefresh'}"></div> | |
254 | <div> | |
255 | <span id="pflog-status">$Lang::tr{'pakfire working'}</span><br> | |
256 | <span id="pflog-time"></span><br> | |
257 | <span id="pflog-action"></span> | |
258 | </div> | |
259 | <div><a href="$ENV{'SCRIPT_NAME'}"><img src="/images/view-refresh.png" alt="$Lang::tr{'refresh'}" title="$Lang::tr{'refresh'}"></a></div> | |
260 | </section> | |
261 | ||
262 | <!-- Pakfire log messages --> | |
263 | <pre id="pflog-messages"></pre> | |
264 | <script> | |
265 | // Start automatic log refresh | |
266 | pakfire.running = true; | |
267 | </script> | |
268 | ||
269 | END | |
270 | ; | |
271 | ||
272 | &Header::closebox(); | |
273 | &Header::closebigbox(); | |
274 | &Header::closepage(); | |
275 | exit; | |
276 | } | |
277 | ||
278 | # Show Pakfire install/remove dependencies and confirm form | |
85d57084 LAH |
279 | # (_is_pakfire_busy status was checked before and can be omitted) |
280 | if (($cgiparams{'ACTION'} eq 'install') && ($pagemode eq $PM_DEFAULT)) { | |
0f506a13 LAH |
281 | &Header::openbox("100%", "center", $Lang::tr{'request'}); |
282 | ||
75ee0279 | 283 | my @pkgs = split(/\|/, $cgiparams{'INSPAKS'}); |
0f506a13 LAH |
284 | my @output = &General::system_output("/usr/local/bin/pakfire", "resolvedeps", "--no-colors", @pkgs); |
285 | print <<END; | |
286 | <table><tr><td colspan='2'>$Lang::tr{'pakfire install package'} @pkgs $Lang::tr{'pakfire possible dependency'} | |
fee5c6b7 | 287 | <pre> |
5b2a12ff | 288 | END |
0f506a13 LAH |
289 | foreach (@output) { |
290 | $_ =~ s/\\e\[[0-1]\;[0-9]+m//g; | |
291 | print "$_\n"; | |
292 | } | |
293 | print <<END; | |
219dacef LAH |
294 | </pre></td></tr> |
295 | <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}</td></tr> | |
296 | <tr><td colspan='2'> </td></tr> | |
5b2a12ff | 297 | <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'> |
0f506a13 LAH |
298 | <input type='hidden' name='INSPAKS' value='$cgiparams{'INSPAKS'}' /> |
299 | <input type='hidden' name='FORCE' value='on' /> | |
300 | <input type='hidden' name='ACTION' value='install' /> | |
301 | <input type='image' alt='$Lang::tr{'install'}' title='$Lang::tr{'install'}' src='/images/go-next.png' /> | |
302 | </form> | |
303 | </td> | |
304 | <td align='left'> | |
305 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
306 | <input type='hidden' name='ACTION' value='' /> | |
307 | <input type='image' alt='$Lang::tr{'abort'}' title='$Lang::tr{'abort'}' src='/images/dialog-error.png' /> | |
308 | </form> | |
309 | </td> | |
310 | </tr> | |
311 | </table> | |
5b2a12ff | 312 | END |
0f506a13 LAH |
313 | &Header::closebox(); |
314 | &Header::closebigbox(); | |
315 | &Header::closepage(); | |
316 | exit; | |
cd521e78 | 317 | |
85d57084 | 318 | } elsif (($cgiparams{'ACTION'} eq 'remove') && ($pagemode eq $PM_DEFAULT)) { |
0f506a13 LAH |
319 | &Header::openbox("100%", "center", $Lang::tr{'request'}); |
320 | ||
75ee0279 | 321 | my @pkgs = split(/\|/, $cgiparams{'DELPAKS'}); |
0f506a13 LAH |
322 | my @output = &General::system_output("/usr/local/bin/pakfire", "resolvedeps", "--no-colors", @pkgs); |
323 | print <<END; | |
324 | <table><tr><td colspan='2'>$Lang::tr{'pakfire uninstall package'} @pkgs $Lang::tr{'pakfire possible dependency'} | |
fee5c6b7 | 325 | <pre> |
74693811 | 326 | END |
0f506a13 LAH |
327 | foreach (@output) { |
328 | $_ =~ s/\\e\[[0-1]\;[0-9]+m//g; | |
329 | print "$_\n"; | |
330 | } | |
331 | print <<END; | |
219dacef LAH |
332 | </pre></td></tr> |
333 | <tr><td colspan='2'>$Lang::tr{'pakfire uninstall all'}</td></tr> | |
334 | <tr><td colspan='2'> </td></tr> | |
74693811 | 335 | <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'> |
0f506a13 LAH |
336 | <input type='hidden' name='DELPAKS' value='$cgiparams{'DELPAKS'}' /> |
337 | <input type='hidden' name='FORCE' value='on' /> | |
338 | <input type='hidden' name='ACTION' value='remove' /> | |
339 | <input type='image' alt='$Lang::tr{'uninstall'}' title='$Lang::tr{'uninstall'}' src='/images/go-next.png' /> | |
340 | </form> | |
341 | </td> | |
342 | <td align='left'> | |
343 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
344 | <input type='hidden' name='ACTION' value='' /> | |
345 | <input type='image' alt='$Lang::tr{'abort'}' title='$Lang::tr{'abort'}' src='/images/dialog-error.png' /> | |
346 | </form> | |
347 | </td> | |
348 | </tr> | |
349 | </table> | |
74693811 | 350 | END |
0f506a13 LAH |
351 | &Header::closebox(); |
352 | &Header::closebigbox(); | |
353 | &Header::closepage(); | |
354 | exit; | |
3ea75603 MT |
355 | } |
356 | ||
4b5d1f30 | 357 | # Show Pakfire main page |
3ea75603 MT |
358 | my %selected=(); |
359 | my %checked=(); | |
360 | ||
f61be862 MT |
361 | $selected{"TREE"} = (); |
362 | $selected{"TREE"}{"stable"} = ""; | |
363 | $selected{"TREE"}{"testing"} = ""; | |
364 | $selected{"TREE"}{"unstable"} = ""; | |
365 | $selected{"TREE"}{$pakfiresettings{"TREE"}} = "selected"; | |
366 | ||
91a08eac | 367 | my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`; |
377560fb MT |
368 | chomp($core_release); |
369 | my $core_update_age = &General::age("/opt/pakfire/db/core/mine"); | |
370 | my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db"); | |
371 | my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db"); | |
372 | my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db"); | |
373 | ||
1bd42c89 MT |
374 | &Header::openbox("100%", "center", "Pakfire"); |
375 | ||
376 | print <<END; | |
219dacef | 377 | <table id="pfmain"> |
337305ef | 378 | END |
324bb888 | 379 | if ( -e "/var/run/need_reboot") { |
219dacef | 380 | print "\t\t<tr><td colspan='2'><a href='/cgi-bin/shutdown.cgi'>$Lang::tr{'needreboot'}!</a></td></tr>\n"; |
337305ef JPT |
381 | } |
382 | print <<END; | |
219dacef LAH |
383 | <tr><td class="heading">$Lang::tr{'pakfire system state'}:</td> |
384 | <td class="heading">$Lang::tr{'available updates'}:</td></tr> | |
385 | ||
386 | <tr><td><strong>$Lang::tr{'pakfire core update level'}: $core_release</strong> | |
387 | <hr> | |
388 | <div class="pflist"> | |
389 | $Lang::tr{'pakfire last update'} $core_update_age $Lang::tr{'pakfire ago'}<br> | |
390 | $Lang::tr{'pakfire last serverlist update'} $server_update_age $Lang::tr{'pakfire ago'}<br> | |
391 | $Lang::tr{'pakfire last core list update'} $corelist_update_age $Lang::tr{'pakfire ago'}<br> | |
1e908471 | 392 | $Lang::tr{'pakfire last package update'} $packages_update_age $Lang::tr{'pakfire ago'} |
219dacef LAH |
393 | </div> |
394 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
395 | <input type='hidden' name='ACTION' value='update' /> | |
396 | <input type='submit' value='$Lang::tr{'calamaris refresh list'}' /> | |
397 | </form> | |
398 | </td> | |
399 | <td> | |
6666b93d | 400 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
219dacef | 401 | <select name="UPDPAKS" class="pflist" size="5" disabled> |
377560fb | 402 | END |
219dacef LAH |
403 | |
404 | &Pakfire::dblist("upgrade", "forweb"); | |
377560fb MT |
405 | print <<END; |
406 | </select> | |
377560fb | 407 | <input type='hidden' name='ACTION' value='upgrade' /> |
f8aa0679 | 408 | <input type='image' alt='$Lang::tr{'upgrade'}' title='$Lang::tr{'upgrade'}' src='/images/document-save.png' /> |
377560fb | 409 | </form> |
219dacef LAH |
410 | </td> |
411 | </tr> | |
412 | <tr><td class="heading">$Lang::tr{'pakfire available addons'}</td> | |
413 | <td class="heading">$Lang::tr{'pakfire installed addons'}</td></tr> | |
fee5c6b7 | 414 | |
b81c77b9 | 415 | <tr><td style="padding:5px 10px 20px 20px" align="center"><p>$Lang::tr{'pakfire install description'}</p> |
219dacef LAH |
416 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
417 | <select name="INSPAKS" class="pflist" size="10" multiple> | |
1bd42c89 | 418 | END |
fee5c6b7 | 419 | |
219dacef LAH |
420 | &Pakfire::dblist("notinstalled", "forweb"); |
421 | print <<END; | |
422 | </select> | |
423 | <input type='hidden' name='ACTION' value='install' /> | |
424 | <input type='image' alt='$Lang::tr{'install'}' title='$Lang::tr{'install'}' src='/images/list-add.png' /> | |
425 | </form> | |
426 | </td> | |
b81c77b9 | 427 | <td style="padding:5px 10px 20px 20px" align="center"><p>$Lang::tr{'pakfire uninstall description'}</p> |
219dacef LAH |
428 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
429 | <select name="DELPAKS" class="pflist" size="10" multiple> | |
957363eb | 430 | END |
5b2a12ff | 431 | |
219dacef LAH |
432 | &Pakfire::dblist("installed", "forweb"); |
433 | print <<END; | |
434 | </select> | |
435 | <input type='hidden' name='ACTION' value='remove' /> | |
436 | <input type='image' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' src='/images/list-remove.png' /> | |
437 | </form> | |
438 | </td> | |
439 | </tr> | |
377560fb | 440 | </table> |
4b122800 MT |
441 | END |
442 | ||
f61be862 MT |
443 | &Header::closebox(); |
444 | &Header::openbox("100%", "center", "$Lang::tr{'settings'}"); | |
445 | ||
446 | print <<END; | |
447 | <form method='POST' action='$ENV{'SCRIPT_NAME'}'> | |
448 | <table width='95%'> | |
449 | <tr> | |
450 | <td align='left' width='45%'>$Lang::tr{'pakfire tree'}</td> | |
451 | <td width="55%" align="left"> | |
452 | <select name="TREE"> | |
453 | <option value="stable" $selected{"TREE"}{"stable"}>$Lang::tr{'pakfire tree stable'}</option> | |
454 | <option value="testing" $selected{"TREE"}{"testing"}>$Lang::tr{'pakfire tree testing'}</option> | |
455 | <option value="unstable" $selected{"TREE"}{"unstable"}>$Lang::tr{'pakfire tree unstable'}</option> | |
456 | </select> | |
457 | </td> | |
458 | </tr> | |
459 | <tr> | |
460 | <td colspan="2"> </td> | |
461 | </tr> | |
462 | <tr> | |
463 | <td colspan="2" align="center"> | |
464 | <input type="submit" name="ACTION" value="$Lang::tr{'save'}" /> | |
465 | </td> | |
466 | </tr> | |
467 | </table> | |
468 | </form> | |
469 | END | |
470 | ||
3ea75603 | 471 | &Header::closebox(); |
3ea75603 | 472 | &Header::closebigbox(); |
3ea75603 | 473 | &Header::closepage(); |
d255e2d1 LAH |
474 | |
475 | ###--- Internal functions ---### | |
476 | ||
477 | # Check if pakfire is already running (extend test here if necessary) | |
478 | sub _is_pakfire_busy { | |
4d70f591 LAH |
479 | # Return immediately if lockfile is present |
480 | if(-e "$Pakfire::lockfile") { | |
481 | return 1; | |
482 | } | |
483 | ||
484 | # Check if a PID of a running pakfire instance is found | |
d255e2d1 LAH |
485 | # (The system backpipe command is safe, because no user input is computed.) |
486 | my $pakfire_pid = `pidof -s /usr/local/bin/pakfire`; | |
487 | chomp($pakfire_pid); | |
488 | ||
4d70f591 LAH |
489 | if($pakfire_pid) { |
490 | return 1; | |
491 | } | |
492 | ||
493 | # Pakfire isn't running | |
494 | return 0; | |
d255e2d1 | 495 | } |
db9ee62e LAH |
496 | |
497 | # Send HTTP headers | |
498 | sub _start_json_output { | |
499 | print "Cache-Control: no-cache, no-store\n"; | |
500 | print "Content-Type: application/json\n"; | |
501 | print "\n"; # End of HTTP headers | |
502 | } | |
85d57084 LAH |
503 | |
504 | # Send HTTP 303 redirect headers to change page mode | |
505 | # GET is always used to display the redirected page, which will remove already processed POST form data. | |
506 | # Note: Custom headers must be sent before the HTML output is started by &Header::showhttpheaders(). | |
507 | # If switch_mode is set to true, the global page mode variable ("$pagemode") is also updated immediately. | |
508 | sub _http_pagemode_redirect { | |
509 | my ($mode, $switch_mode) = @_; | |
510 | $mode //= $PM_DEFAULT; | |
511 | $switch_mode //= 0; | |
512 | ||
513 | # Send HTTP redirect with GET parameter | |
514 | my $location = "https://$ENV{'SERVER_NAME'}:$ENV{'SERVER_PORT'}$ENV{'SCRIPT_NAME'}?mode=${mode}"; | |
515 | print "Status: 303 See Other\n"; | |
516 | print "Location: $location\n"; | |
517 | ||
518 | # Change global page mode | |
519 | if($switch_mode) { | |
520 | $pagemode = $mode; | |
521 | } | |
522 | } |