]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007-2011 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 | ############################################################################### | |
21 | ||
22 | use strict; | |
23 | ||
24 | # enable only the following on debugging purpose | |
25 | #use warnings; | |
26 | #use CGI::Carp 'fatalsToBrowser'; | |
27 | ||
28 | require '/var/ipfire/general-functions.pl'; | |
29 | require "${General::swroot}/lang.pl"; | |
30 | require "${General::swroot}/header.pl"; | |
31 | require "/opt/pakfire/lib/functions.pl"; | |
32 | ||
33 | my %cgiparams=(); | |
34 | my $errormessage = ''; | |
35 | my %color = (); | |
36 | my %pakfiresettings = (); | |
37 | my %mainsettings = (); | |
38 | ||
39 | &Header::showhttpheaders(); | |
40 | ||
41 | $cgiparams{'ACTION'} = ''; | |
42 | $cgiparams{'VALID'} = ''; | |
43 | ||
44 | $cgiparams{'INSPAKS'} = ''; | |
45 | $cgiparams{'DELPAKS'} = ''; | |
46 | ||
47 | sub 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 | ||
49 | &Header::getcgihash(\%cgiparams); | |
50 | ||
51 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
52 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); | |
53 | ||
54 | &Header::openpage($Lang::tr{'pakfire configuration'}, 1); | |
55 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
56 | ||
57 | if (($cgiparams{'ACTION'} eq 'install') && (! -e $Pakfire::lockfile)) { | |
58 | my @pkgs = split(/\|/, $cgiparams{'INSPAKS'}); | |
59 | if ("$cgiparams{'FORCE'}" eq "on") { | |
60 | &General::system_background("/usr/local/bin/pakfire", "install", "--non-interactive", "--no-colors", @pkgs); | |
61 | sleep(1); | |
62 | } else { | |
63 | &Header::openbox("100%", "center", $Lang::tr{'request'}); | |
64 | my @output = &General::system_output("/usr/local/bin/pakfire", "resolvedeps", "--no-colors", @pkgs); | |
65 | print <<END; | |
66 | <table><tr><td colspan='2'>$Lang::tr{'pakfire install package'} @pkgs $Lang::tr{'pakfire possible dependency'} | |
67 | <pre> | |
68 | END | |
69 | foreach (@output) { | |
70 | $_ =~ s/\\e\[[0-1]\;[0-9]+m//g; | |
71 | print "$_\n"; | |
72 | } | |
73 | print <<END; | |
74 | </pre> | |
75 | <tr><td colspan='2'>$Lang::tr{'pakfire accept all'} | |
76 | <tr><td colspan='2'> | |
77 | <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
78 | <input type='hidden' name='INSPAKS' value='$cgiparams{'INSPAKS'}' /> | |
79 | <input type='hidden' name='FORCE' value='on' /> | |
80 | <input type='hidden' name='ACTION' value='install' /> | |
81 | <input type='image' alt='$Lang::tr{'install'}' title='$Lang::tr{'install'}' src='/images/go-next.png' /> | |
82 | </form> | |
83 | <td align='left'> | |
84 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
85 | <input type='hidden' name='ACTION' value='' /> | |
86 | <input type='image' alt='$Lang::tr{'abort'}' title='$Lang::tr{'abort'}' src='/images/dialog-error.png' /> | |
87 | </form> | |
88 | </table> | |
89 | END | |
90 | &Header::closebox(); | |
91 | &Header::closebigbox(); | |
92 | &Header::closepage(); | |
93 | exit; | |
94 | } | |
95 | } elsif (($cgiparams{'ACTION'} eq 'remove') && (! -e $Pakfire::lockfile)) { | |
96 | my @pkgs = split(/\|/, $cgiparams{'DELPAKS'}); | |
97 | if ("$cgiparams{'FORCE'}" eq "on") { | |
98 | &General::system_background("/usr/local/bin/pakfire", "remove", "--non-interactive", "--no-colors", @pkgs); | |
99 | sleep(1); | |
100 | } else { | |
101 | &Header::openbox("100%", "center", $Lang::tr{'request'}); | |
102 | my @output = &General::system_output("/usr/local/bin/pakfire", "resolvedeps", "--no-colors", @pkgs); | |
103 | print <<END; | |
104 | <table><tr><td colspan='2'>$Lang::tr{'pakfire uninstall package'} @pkgs $Lang::tr{'pakfire possible dependency'} | |
105 | <pre> | |
106 | END | |
107 | foreach (@output) { | |
108 | $_ =~ s/\\e\[[0-1]\;[0-9]+m//g; | |
109 | print "$_\n"; | |
110 | } | |
111 | print <<END; | |
112 | </pre> | |
113 | <tr><td colspan='2'>$Lang::tr{'pakfire uninstall all'} | |
114 | <tr><td colspan='2'> | |
115 | <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
116 | <input type='hidden' name='DELPAKS' value='$cgiparams{'DELPAKS'}' /> | |
117 | <input type='hidden' name='FORCE' value='on' /> | |
118 | <input type='hidden' name='ACTION' value='remove' /> | |
119 | <input type='image' alt='$Lang::tr{'uninstall'}' title='$Lang::tr{'uninstall'}' src='/images/go-next.png' /> | |
120 | </form> | |
121 | <td align='left'> | |
122 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
123 | <input type='hidden' name='ACTION' value='' /> | |
124 | <input type='image' alt='$Lang::tr{'abort'}' title='$Lang::tr{'abort'}' src='/images/dialog-error.png' /> | |
125 | </form> | |
126 | </table> | |
127 | END | |
128 | &Header::closebox(); | |
129 | &Header::closebigbox(); | |
130 | &Header::closepage(); | |
131 | exit; | |
132 | } | |
133 | ||
134 | } elsif (($cgiparams{'ACTION'} eq 'update') && (! -e $Pakfire::lockfile)) { | |
135 | &General::system_background("/usr/local/bin/pakfire", "update", "--force", "--no-colors"); | |
136 | sleep(1); | |
137 | } elsif (($cgiparams{'ACTION'} eq 'upgrade') && (!-e $Pakfire::lockfile)) { | |
138 | &General::system_background("/usr/local/bin/pakfire", "upgrade", "-y", "--no-colors"); | |
139 | sleep(1); | |
140 | } elsif ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}") { | |
141 | $pakfiresettings{"TREE"} = $cgiparams{"TREE"}; | |
142 | ||
143 | # Check for valid input | |
144 | if ($pakfiresettings{"TREE"} !~ m/^(stable|testing|unstable)$/) { | |
145 | $errormessage .= $Lang::tr{'pakfire invalid tree'}; | |
146 | } | |
147 | ||
148 | unless ($errormessage) { | |
149 | &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings); | |
150 | ||
151 | # Update lists | |
152 | &General::system_background("/usr/local/bin/pakfire", "update", "--force", "--no-colors"); | |
153 | sleep(1); | |
154 | } | |
155 | } | |
156 | ||
157 | &General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings); | |
158 | ||
159 | my %selected=(); | |
160 | my %checked=(); | |
161 | ||
162 | $selected{"TREE"} = (); | |
163 | $selected{"TREE"}{"stable"} = ""; | |
164 | $selected{"TREE"}{"testing"} = ""; | |
165 | $selected{"TREE"}{"unstable"} = ""; | |
166 | $selected{"TREE"}{$pakfiresettings{"TREE"}} = "selected"; | |
167 | ||
168 | # DPC move error message to top so it is seen! | |
169 | if ($errormessage) { | |
170 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
171 | print "<font class='base'>$errormessage </font>\n"; | |
172 | &Header::closebox(); | |
173 | } | |
174 | ||
175 | # Check if pakfire is already running. | |
176 | # | |
177 | # The system backpipe command is safe, because no user input is computed. | |
178 | my $pid = `pidof pakfire`; | |
179 | ||
180 | if ($pid) { | |
181 | &Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='10;'>" ); | |
182 | print <<END; | |
183 | <table> | |
184 | <tr><td> | |
185 | <img src='/images/indicator.gif' alt='$Lang::tr{'active'}' title='$Lang::tr{'active'}' /> | |
186 | <td> | |
187 | $Lang::tr{'pakfire working'} | |
188 | <tr><td colspan='2' align='center'> | |
189 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
190 | <input type='image' alt='$Lang::tr{'reload'}' title='$Lang::tr{'reload'}' src='/images/view-refresh.png' /> | |
191 | </form> | |
192 | <tr><td colspan='2' align='left'><code> | |
193 | END | |
194 | my @output = `grep pakfire /var/log/messages | tail -20`; | |
195 | foreach (@output) { | |
196 | print "$_<br>"; | |
197 | } | |
198 | print <<END; | |
199 | </code> | |
200 | </table> | |
201 | END | |
202 | &Header::closebox(); | |
203 | &Header::closebigbox(); | |
204 | &Header::closepage(); | |
205 | exit; | |
206 | refreshpage(); | |
207 | } | |
208 | ||
209 | my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`; | |
210 | chomp($core_release); | |
211 | my $core_update_age = &General::age("/opt/pakfire/db/core/mine"); | |
212 | my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db"); | |
213 | my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db"); | |
214 | my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db"); | |
215 | ||
216 | &Header::openbox("100%", "center", "Pakfire"); | |
217 | ||
218 | print <<END; | |
219 | <table width='95%' cellpadding='5'> | |
220 | END | |
221 | if ( -e "/var/run/need_reboot") { | |
222 | print "<tr><td align='center' colspan='2'><font color='red'>$Lang::tr{'needreboot'}!</font></td></tr>"; | |
223 | print "<tr><td colspan='2'> </font></td></tr>" | |
224 | } | |
225 | print <<END; | |
226 | <tr><td width="50%" bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire system state'}:</b> | |
227 | ||
228 | <td width="50%" bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'available updates'}:</b></tr> | |
229 | ||
230 | <tr><td align="center">$Lang::tr{'pakfire core update level'}: $core_release<hr /> | |
231 | $Lang::tr{'pakfire last update'} $core_update_age $Lang::tr{'pakfire ago'}<br /> | |
232 | $Lang::tr{'pakfire last serverlist update'} $server_update_age $Lang::tr{'pakfire ago'}<br /> | |
233 | $Lang::tr{'pakfire last core list update'} $corelist_update_age $Lang::tr{'pakfire ago'}<br /> | |
234 | $Lang::tr{'pakfire last package update'} $packages_update_age $Lang::tr{'pakfire ago'} | |
235 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
236 | <input type='hidden' name='ACTION' value='update' /><br /> | |
237 | <input type='submit' value='$Lang::tr{'calamaris refresh list'}' /><br /> | |
238 | </form> | |
239 | <br /> | |
240 | <td align="center"> | |
241 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
242 | <select name="UPDPAKS" size="5" disabled> | |
243 | END | |
244 | &Pakfire::dblist("upgrade", "forweb"); | |
245 | print <<END; | |
246 | </select> | |
247 | <br /> | |
248 | <input type='hidden' name='ACTION' value='upgrade' /> | |
249 | <input type='image' alt='$Lang::tr{'upgrade'}' title='$Lang::tr{'upgrade'}' src='/images/document-save.png' /> | |
250 | </form> | |
251 | ||
252 | <tr><td colspan="2"><!-- Just an empty line --> | |
253 | <tr><td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire available addons'}</b> | |
254 | <td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire installed addons'}</b> | |
255 | <tr><td style="padding:5px 10px 20px 20px" align="center"> | |
256 | <p>$Lang::tr{'pakfire install description'}</p> | |
257 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
258 | <select name="INSPAKS" size="10" multiple> | |
259 | END | |
260 | &Pakfire::dblist("notinstalled", "forweb"); | |
261 | ||
262 | print <<END; | |
263 | </select> | |
264 | <br /> | |
265 | <input type='hidden' name='ACTION' value='install' /> | |
266 | <input type='image' alt='$Lang::tr{'install'}' title='$Lang::tr{'install'}' src='/images/list-add.png' /> | |
267 | </form> | |
268 | ||
269 | <td style="padding:5px 10px 20px 20px" align="center"> | |
270 | <p>$Lang::tr{'pakfire uninstall description'}</p> | |
271 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
272 | <select name="DELPAKS" size="10" multiple> | |
273 | END | |
274 | ||
275 | &Pakfire::dblist("installed", "forweb"); | |
276 | ||
277 | print <<END; | |
278 | </select> | |
279 | <br /> | |
280 | <input type='hidden' name='ACTION' value='remove' /> | |
281 | <input type='image' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' src='/images/list-remove.png' /> | |
282 | </form> | |
283 | </table> | |
284 | END | |
285 | ||
286 | &Header::closebox(); | |
287 | &Header::openbox("100%", "center", "$Lang::tr{'settings'}"); | |
288 | ||
289 | print <<END; | |
290 | <form method='POST' action='$ENV{'SCRIPT_NAME'}'> | |
291 | <table width='95%'> | |
292 | <tr> | |
293 | <td align='left' width='45%'>$Lang::tr{'pakfire tree'}</td> | |
294 | <td width="55%" align="left"> | |
295 | <select name="TREE"> | |
296 | <option value="stable" $selected{"TREE"}{"stable"}>$Lang::tr{'pakfire tree stable'}</option> | |
297 | <option value="testing" $selected{"TREE"}{"testing"}>$Lang::tr{'pakfire tree testing'}</option> | |
298 | <option value="unstable" $selected{"TREE"}{"unstable"}>$Lang::tr{'pakfire tree unstable'}</option> | |
299 | </select> | |
300 | </td> | |
301 | </tr> | |
302 | <tr> | |
303 | <td colspan="2"> </td> | |
304 | </tr> | |
305 | <tr> | |
306 | <td colspan="2" align="center"> | |
307 | <input type="submit" name="ACTION" value="$Lang::tr{'save'}" /> | |
308 | </td> | |
309 | </tr> | |
310 | </table> | |
311 | </form> | |
312 | END | |
313 | ||
314 | &Header::closebox(); | |
315 | &Header::closebigbox(); | |
316 | &Header::closepage(); |